export loader's public predicates from builtins, handle module resolution from DCGs
This commit is contained in:
@@ -18,9 +18,12 @@ phrase(GRBody, S0) :-
|
||||
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))
|
||||
@@ -30,22 +33,36 @@ phrase_([], S, S).
|
||||
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) :-
|
||||
|
||||
@@ -30,7 +30,7 @@ expand_term(Term, ExpandedTerm) :-
|
||||
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
|
||||
).
|
||||
@@ -38,7 +38,7 @@ expand_term(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 = [_|_] ->
|
||||
|
||||
@@ -1733,11 +1733,12 @@ fn load_module(
|
||||
code_dir: &mut CodeDir,
|
||||
op_dir: &mut OpDir,
|
||||
meta_predicate_dir: &mut MetaPredicateDir,
|
||||
compilation_target: &CompilationTarget,
|
||||
module: &Module,
|
||||
) {
|
||||
import_module_exports(
|
||||
&mut RetractionInfo::new(0),
|
||||
&CompilationTarget::User,
|
||||
&compilation_target,
|
||||
module,
|
||||
code_dir,
|
||||
op_dir,
|
||||
|
||||
@@ -230,6 +230,7 @@ impl Machine {
|
||||
&mut self.indices.code_dir,
|
||||
&mut self.indices.op_dir,
|
||||
&mut self.indices.meta_predicates,
|
||||
&CompilationTarget::User,
|
||||
toplevel,
|
||||
);
|
||||
} else {
|
||||
@@ -337,6 +338,7 @@ impl Machine {
|
||||
&mut wam.indices.code_dir,
|
||||
&mut wam.indices.op_dir,
|
||||
&mut wam.indices.meta_predicates,
|
||||
&CompilationTarget::User,
|
||||
builtins,
|
||||
);
|
||||
} else {
|
||||
@@ -354,13 +356,32 @@ impl Machine {
|
||||
),
|
||||
).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!()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user