]> Repositorios git - scryer-prolog.git/commitdiff
test
authorMark Thom <[email protected]>
Mon, 4 May 2020 17:18:13 +0000 (11:18 -0600)
committerMark Thom <[email protected]>
Mon, 4 May 2020 17:18:13 +0000 (11:18 -0600)
src/prolog/lib/dcgs.pl
src/prolog/machine/compile.rs

index 33210f19da15108b6b793451c8ee1cf7476a5824..5e8e19d5b23d8f4a4c7e8f9b12a1eafe5c4543c3 100644 (file)
@@ -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).
index 64f56a30d53686e09732ba2e4f27ab715a55672c..f59c8610136e2ea24ffb9a717b9057c077d1e431 100644 (file)
@@ -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