add warnings when initialization goals fail (#168)

This commit is contained in:
Mark Thom
2019-10-30 00:25:17 -06:00
parent d34811aa36
commit 4ad62e4606
2 changed files with 14 additions and 8 deletions

View 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 {

View 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) {