From: Mark Thom Date: Mon, 4 May 2020 17:18:13 +0000 (-0600) Subject: test X-Git-Tag: v0.8.123~59 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=8e9273a96a9cc5a3bfd380e2359e37180fdc8170;p=scryer-prolog.git test --- diff --git a/src/prolog/lib/dcgs.pl b/src/prolog/lib/dcgs.pl index 33210f19..5e8e19d5 100644 --- a/src/prolog/lib/dcgs.pl +++ b/src/prolog/lib/dcgs.pl @@ -6,11 +6,6 @@ :- use_module(library(error)). :- use_module(library(lists), [append/3]). -user:term_expansion(Term0, Term) :- - nonvar(Term0), - dcg_rule(Term0, (Head :- Body)), - Term = (Head :- Body). - phrase(GRBody, S0) :- phrase(GRBody, S0, []). @@ -133,3 +128,8 @@ dcg_cbody(\+ GRBody, S0, S, ( \+ phrase(GRBody,S0,_), S0 = S )). dcg_cbody(( GRIf -> GRThen ), S0, S, ( If -> Then )) :- dcg_body(GRIf, S0, S1, If), dcg_body(GRThen, S1, S, Then). + +user:term_expansion(Term0, Term) :- + nonvar(Term0), + dcg_rule(Term0, (Head :- Body)), + Term = (Head :- Body). diff --git a/src/prolog/machine/compile.rs b/src/prolog/machine/compile.rs index 64f56a30..f59c8610 100644 --- a/src/prolog/machine/compile.rs +++ b/src/prolog/machine/compile.rs @@ -350,10 +350,6 @@ fn compile_into_module( match compile_into_module_impl(wam, &mut compiler, module, src, indices) { Ok(()) => EvalSession::EntrySuccess, Err(e) => { - if let Some(module) = compiler.module.take() { - wam.indices.insert_module(module); - } - compiler.drop_expansions(&mut wam.code_repo); EvalSession::from(e) } @@ -370,16 +366,16 @@ fn compile_into_module_impl( setup_module_expansions(wam, &module); let module_name = module.module_decl.name.clone(); - compiler.module = Some(module); + // compiler.module = Some(module); This trips the goal expansion up. Should be possible to 'merge' modules. + // A much better strategy! + wam.indices.insert_module(module); wam.code_repo.compile_hook(CompileTimeHook::TermExpansion)?; wam.code_repo.compile_hook(CompileTimeHook::GoalExpansion)?; - let mut stream = parsing_stream(src)?; - let mut results = compiler.gather_items( wam, - &mut stream, + &mut parsing_stream(src)?, &mut indices, )?; @@ -401,10 +397,11 @@ fn compile_into_module_impl( clause_code_generator.generate_clause_code(&results.dynamic_clause_map, wam)?; let top_level_term_dir = results.top_level_term_dirs.consolidate(); + let module = wam.indices.take_module(module_name).unwrap(); add_module( wam, - compiler.module.take().unwrap(), + module, indices, top_level_term_dir, ); @@ -1109,9 +1106,9 @@ impl ListingCompiler { .entry((name.clone(), arity)) .or_insert(vec![]); - indices.code_dir - .entry((name.clone(), arity)) - .or_insert(CodeIndex::dynamic_undefined(self.get_module_name())); + indices.code_dir + .entry((name.clone(), arity)) + .or_insert(CodeIndex::dynamic_undefined(self.get_module_name())); } &Declaration::Hook(hook, _, ref queue) if self.module.is_none() => worker .term_stream