phrase(GRBody, S0, S) :-
( var(GRBody) ->
throw(error(instantiation_error, phrase/3))
- ; strip_module(GRBody, _, GRBody0),
- dcg_constr(GRBody0) ->
- phrase_(GRBody0, S0, S)
+ ; strip_module(GRBody, Module, GRBody0),
+ dcg_constr(GRBody0),
+ ( var(Module) ->
+ phrase_(GRBody0, S0, S)
+ ; phrase_(Module:GRBody0, S0, S)
+ )
; functor(GRBody, _, _) ->
call(GRBody, S0, S)
; throw(error(type_error(callable, GRBody), phrase/3))
phrase_(!, S, S).
phrase_((A, B), S0, S) :-
phrase(A, S0, S1), phrase(B, S1, S).
+phrase_(M:(A, B), S0, S) :-
+ phrase(M:A, S0, S1), phrase(M:B, S1, S).
phrase_((A -> B ; C), S0, S) :-
!,
( phrase(A, S0, S1) ->
phrase(B, S1, S)
; phrase(C, S0, S)
).
+phrase_(M:(A -> B ; C), S0, S) :-
+ !,
+ ( phrase(M:A, S0, S1) ->
+ phrase(M:B, S1, S)
+ ; phrase(M:C, S0, S)
+ ).
phrase_((A ; B), S0, S) :-
( phrase(A, S0, S) ; phrase(B, S0, S) ).
+phrase_(M:(A ; B), S0, S) :-
+ ( phrase(M:A, S0, S) ; phrase(M:B, S0, S) ).
phrase_((A | B), S0, S) :-
( phrase(A, S0, S) ; phrase(B, S0, S) ).
+phrase_(M:(A | B), S0, S) :-
+ ( phrase(M:A, S0, S) ; phrase(M:B, S0, S) ).
phrase_({G}, S0, S) :-
( call(G), S0 = S ).
phrase_(call(G), S0, S) :-
call(G, S0, S).
phrase_((A -> B), S0, S) :-
phrase((A -> B ; fail), S0, S).
+phrase_(M:(A -> B), S0, S) :-
+ phrase((M:A -> M:B ; fail), S0, S).
phrase_(phrase(NonTerminal), S0, S) :-
phrase(NonTerminal, S0, S).
phrase_([T|Ts], S0, S) :-
error:instantiation_error(term_expansion/2)
; ExpandedTerm0 = [_|_] ->
term_expansion_list(ExpandedTerm0, ExpandedTerm, [])
- ; expand_term(ExpandedTerm0, ExpandedTerm) % term_expansion(ExpandedTerm0, ExpandedTerm)
+ ; expand_term(ExpandedTerm0, ExpandedTerm)
)
; Term = ExpandedTerm
).
term_expansion_list([], ExpandedTerms, ExpandedTerms).
term_expansion_list([Term|Terms], ExpandedTermsHead, ExpandedTermsTail) :-
- expand_term(Term, ExpandedTerm0), % term_expansion(Term, ExpandedTerm0),
+ expand_term(Term, ExpandedTerm0),
( var(ExpandedTerm0) ->
error:instantiation_error(term_expansion/2)
; ExpandedTerm0 = [_|_] ->
&mut self.indices.code_dir,
&mut self.indices.op_dir,
&mut self.indices.meta_predicates,
+ &CompilationTarget::User,
toplevel,
);
} else {
&mut wam.indices.code_dir,
&mut wam.indices.op_dir,
&mut wam.indices.meta_predicates,
+ &CompilationTarget::User,
builtins,
);
} else {
),
).unwrap();
- if let Some(loader) = wam.indices.modules.get(&clause_name!("loader")) {
+ if let Some(loader) = wam.indices.modules.swap_remove(&clause_name!("loader")) {
+ if let Some(builtins) = wam.indices.modules.get_mut(&clause_name!("builtins")) {
+ // Import loader's exports into the builtins module so they will be
+ // implicitly included every further module.
+ load_module(
+ &mut builtins.code_dir,
+ &mut builtins.op_dir,
+ &mut builtins.meta_predicates,
+ &CompilationTarget::Module(clause_name!("builtins")),
+ &loader,
+ );
+
+ for export in &loader.module_decl.exports {
+ builtins.module_decl.exports.push(export.clone());
+ }
+ }
+
load_module(
&mut wam.indices.code_dir,
&mut wam.indices.op_dir,
&mut wam.indices.meta_predicates,
- loader,
+ &CompilationTarget::User,
+ &loader,
);
+
+ wam.indices.modules.insert(clause_name!("loader"), loader);
} else {
unreachable!()
}