]> Repositorios git - scryer-prolog.git/commitdiff
add warnings when initialization goals fail (#168)
authorMark Thom <[email protected]>
Wed, 30 Oct 2019 06:25:17 +0000 (00:25 -0600)
committerMark Thom <[email protected]>
Wed, 30 Oct 2019 06:25:17 +0000 (00:25 -0600)
src/prolog/machine/compile.rs
src/prolog/machine/mod.rs

index 332111614e0c18c843b419b32381e22cd75a6272..25ab171a49d47bd4631ecf769c1168333cc32186 100644 (file)
@@ -301,7 +301,7 @@ fn setup_module_expansions(wam: &mut Machine, module: &Module) {
         CompileTimeHook::TermExpansion,
         term_expansions,
     );
-    
+
     add_hooks_to_mockup(
         &mut wam.code_repo,
         CompileTimeHook::GoalExpansion,
@@ -330,7 +330,7 @@ pub(super) fn compile_into_module<R: Read>(
             if let Some(module) = compiler.module.take() {
                 wam.indices.insert_module(module);
             }
-            
+
             compiler.drop_expansions(wam.machine_flags(), &mut wam.code_repo);
             EvalSession::from(e)
         }
@@ -349,7 +349,7 @@ fn compile_into_module_impl<R: Read>(
     let module_name = module.module_decl.name.clone();
     compiler.module = Some(module);
 
-    let flags = wam.machine_flags();    
+    let flags = wam.machine_flags();
 
     wam.code_repo.compile_hook(CompileTimeHook::TermExpansion, flags)?;
     wam.code_repo.compile_hook(CompileTimeHook::GoalExpansion, flags)?;
@@ -360,7 +360,7 @@ fn compile_into_module_impl<R: Read>(
 
     let mut clause_code_generator = ClauseCodeGenerator::new(module_code.len(), module_name.clone());
 
-    clause_code_generator.generate_clause_code(&results.dynamic_clause_map, wam)?;   
+    clause_code_generator.generate_clause_code(&results.dynamic_clause_map, wam)?;
     add_module_code(wam, compiler.module.take().unwrap(), module_code, indices);
     clause_code_generator.add_clause_code(wam, results.dynamic_clause_map);
 
@@ -997,9 +997,9 @@ fn compile_work_impl(
 
         if module.is_impromptu_module {
             add_module_code(wam, module, module_code, indices);
-            
+
             let module = wam.indices.take_module(compiler.listing_src.clone()).unwrap();
-            
+
             wam.indices.use_module(&mut wam.code_repo, wam.machine_st.flags, &module)?;
             wam.indices.insert_module(module);
         } else {
@@ -1022,7 +1022,10 @@ fn compile_work_impl(
     )?;
 
     if init_goal_code.len() > 0 {
-       wam.run_init_code(init_goal_code);
+       if !wam.run_init_code(init_goal_code) {
+            println!("Warning: initialization goal for {} failed",
+                     compiler.listing_src);
+        }
     }
 
     if !compiler.suppress_warnings {
index 7a6823a05df317f34badf0f4792c5b62a60fc439..ecf15caaa7b9b11a85c0f8f3932f054c0c5a0acd 100644 (file)
@@ -230,14 +230,17 @@ impl Machine {
         self.machine_st.reset();
     }
 
-    pub fn run_init_code(&mut self, code: Code) {
+    pub fn run_init_code(&mut self, code: Code) -> bool {
        let old_machine_st = self.sink_to_snapshot();
        self.machine_st.reset();
 
        self.code_repo.cached_query = code;
        self.run_query(&AllocVarDict::new());
 
+        let result = self.machine_st.fail;
        self.absorb_snapshot(old_machine_st);
+        
+        !result
     }
 
     pub fn run_top_level(&mut self) {