flatten bracketed commas in dcgs
This commit is contained in:
@@ -193,13 +193,14 @@ impl ListingCompiler {
|
||||
{
|
||||
let mod_name = self.get_module_name();
|
||||
|
||||
if let Some(submodule) = wam_indices.take_module(submodule) {
|
||||
if let Some(mut submodule) = wam_indices.take_module(submodule) {
|
||||
indices.use_module(code_repo, flags, &submodule)?;
|
||||
|
||||
if let &mut Some(ref mut module) = &mut self.module {
|
||||
module.remove_module(mod_name, &submodule);
|
||||
module.use_module(code_repo, flags, &submodule)?;
|
||||
} else {
|
||||
submodule.inserted_expansions = true;
|
||||
wam_indices.remove_module(clause_name!("user"), &submodule);
|
||||
}
|
||||
|
||||
@@ -216,13 +217,14 @@ impl ListingCompiler {
|
||||
{
|
||||
let mod_name = self.get_module_name();
|
||||
|
||||
if let Some(submodule) = wam_indices.take_module(submodule) {
|
||||
if let Some(mut submodule) = wam_indices.take_module(submodule) {
|
||||
indices.use_qualified_module(code_repo, flags, &submodule, exports)?;
|
||||
|
||||
if let &mut Some(ref mut module) = &mut self.module {
|
||||
module.remove_module(mod_name, &submodule);
|
||||
module.use_qualified_module(code_repo, flags, &submodule, exports)?;
|
||||
} else {
|
||||
submodule.inserted_expansions = true;
|
||||
wam_indices.remove_module(clause_name!("user"), &submodule);
|
||||
}
|
||||
|
||||
@@ -346,7 +348,7 @@ impl ListingCompiler {
|
||||
Ok(self.add_non_counted_bt_flag(name, arity)),
|
||||
Declaration::Op(op_decl) =>
|
||||
op_decl.submit(self.get_module_name(), &mut indices.op_dir),
|
||||
Declaration::UseModule(name) =>
|
||||
Declaration::UseModule(name) =>
|
||||
self.use_module(name, code_repo, flags, wam_indices, indices),
|
||||
Declaration::UseQualifiedModule(name, exports) =>
|
||||
self.use_qualified_module(name, code_repo, flags, &exports, wam_indices, indices),
|
||||
|
||||
@@ -232,6 +232,7 @@ pub struct Module {
|
||||
pub op_dir: OpDir,
|
||||
pub term_expansions: (Predicate, VecDeque<TopLevel>),
|
||||
pub goal_expansions: (Predicate, VecDeque<TopLevel>),
|
||||
pub inserted_expansions: bool // has the module been successfully inserted into toplevel??
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
@@ -1103,7 +1104,8 @@ impl Module {
|
||||
term_expansions: (Predicate::new(), VecDeque::from(vec![])),
|
||||
goal_expansions: (Predicate::new(), VecDeque::from(vec![])),
|
||||
code_dir: ModuleCodeDir::new(),
|
||||
op_dir: default_op_dir() }
|
||||
op_dir: default_op_dir(),
|
||||
inserted_expansions: false }
|
||||
}
|
||||
|
||||
pub fn dump_expansions(&self, code_repo: &mut CodeRepo, flags: MachineFlags)
|
||||
|
||||
@@ -45,15 +45,27 @@ expand_dcgs(Term0, N, (ModHead :- ModBody)) :-
|
||||
nonvar(Body),
|
||||
expand_body(Body, ModBody, N, N1).
|
||||
|
||||
expand_body(Term0, (ModTerm, ModTerms), N0, N) :-
|
||||
expand_body(Term0, ModTerms, N0, N) :-
|
||||
nonvar(Term0), Term0 = (Term, Terms), !,
|
||||
nonvar(Term),
|
||||
expand_body_term(Term, ModTerm, N0, N1),
|
||||
expand_body(Terms, ModTerms, N1, N).
|
||||
unfurl_commas(ModTerm, ModTerms, ModTerms1),
|
||||
expand_body(Terms, ModTerms1, N1, N).
|
||||
expand_body(Term0, ModTerm, N0, N) :-
|
||||
nonvar(Term0),
|
||||
expand_body_term(Term0, ModTerm, N0, N).
|
||||
|
||||
/* unfurl_commas(?ModTerm, -ModTerms, -ModTerms1) :
|
||||
sets ModTerms = (ModTermI0, ModTermI1, ..., ModTermIN, ModTerms1)
|
||||
where ModTerm = (ModTermI0, ModTermI1, ..., ModTermIN) */
|
||||
unfurl_commas(ModTerm, ModTerms, ModTerms1) :-
|
||||
nonvar(ModTerm),
|
||||
ModTerm = (ModTermI0, ModTermIs),
|
||||
!,
|
||||
ModTerms = (ModTermI0, ModTerms2),
|
||||
unfurl_commas(ModTermIs, ModTerms2, ModTerms1).
|
||||
unfurl_commas(ModTermIN, (ModTermIN, ModTerms1), ModTerms1).
|
||||
|
||||
expand_body_term([], true, N, N) :- !.
|
||||
expand_body_term([Arg|Args], ModTerm, N0, N) :-
|
||||
!, N is N0 + 1,
|
||||
|
||||
@@ -299,7 +299,12 @@ impl SubModuleUser for IndexStore {
|
||||
-> Result<(), SessionError>
|
||||
{
|
||||
use_module(self, submodule)?;
|
||||
submodule.dump_expansions(code_repo, flags).map_err(SessionError::from)
|
||||
|
||||
if !submodule.inserted_expansions {
|
||||
submodule.dump_expansions(code_repo, flags).map_err(SessionError::from)
|
||||
} else {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user