From: Mark Thom Date: Mon, 28 Oct 2019 01:23:35 +0000 (-0600) Subject: finish #214, add needed ambiguity checks if 0 is the final character X-Git-Tag: v0.8.116~8 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=e594ade84d12c9a45a317ccc0dfba592aba9af3b;p=scryer-prolog.git finish #214, add needed ambiguity checks if 0 is the final character --- diff --git a/src/prolog/heap_print.rs b/src/prolog/heap_print.rs index 0f9f7985..2e79f261 100644 --- a/src/prolog/heap_print.rs +++ b/src/prolog/heap_print.rs @@ -329,8 +329,7 @@ pub fn requires_space(atom: &str, op: &str) -> bool { .next() .map(|oc| { if ac == '0' { - oc == 'b' || oc == 'x' || oc == 'o' || oc == '\'' - || oc == '(' || alpha_numeric_char!(oc) + oc == '\'' || oc == '(' || alpha_numeric_char!(oc) } else if alpha_numeric_char!(ac) { oc == '(' || alpha_numeric_char!(oc) } else if graphic_token_char!(ac) { diff --git a/src/prolog/machine/compile.rs b/src/prolog/machine/compile.rs index 07569ef3..2881c21c 100644 --- a/src/prolog/machine/compile.rs +++ b/src/prolog/machine/compile.rs @@ -1015,8 +1015,8 @@ fn compile_work_impl( if let Some(mut module) = compiler.module.take() { if module.is_impromptu_module { module.module_decl.exports = indices.code_dir.keys().cloned() - .filter(|(name, _)| name.owning_module().as_str() != "builtins") - .collect(); + .filter(|(name, _)| name.owning_module().as_str() != "builtins") + .collect(); } let mut clause_code_generator = @@ -1030,9 +1030,18 @@ fn compile_work_impl( wam.indices.remove_module(clause_name!("user"), module); } - add_module_code(wam, module, module_code, indices); - add_toplevel_code(wam, toplvl_code, results.toplevel_indices); + 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 { + add_module_code(wam, module, module_code, indices); + } + add_toplevel_code(wam, toplvl_code, results.toplevel_indices); clause_code_generator.add_clause_code(wam, results.dynamic_clause_map); } else { add_non_module_code( diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index c24e82e8..50aba7f6 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -456,14 +456,15 @@ impl Machine { }; let result = load_result.and_then(|name| { - let module = self.indices.take_module(name.clone()).unwrap(); - - self.indices.use_module(&mut self.code_repo, self.machine_st.flags, - &module)?; + let module = self.indices.take_module(name.clone()).unwrap(); - Ok(self.indices.insert_module(module)) + if !module.is_impromptu_module { + self.indices.use_module(&mut self.code_repo, self.machine_st.flags, &module)?; + } + + Ok(self.indices.insert_module(module)) }); - + self.code_repo.cached_query = cached_query; if let Err(e) = result { @@ -502,10 +503,12 @@ impl Machine { let result = load_result.and_then(|name| { let module = self.indices.take_module(name.clone()).unwrap(); - self.indices.use_qualified_module(&mut self.code_repo, - self.machine_st.flags, - &module, - &exports)?; + if !module.is_impromptu_module { + self.indices.use_qualified_module(&mut self.code_repo, + self.machine_st.flags, + &module, + &exports)?; + } Ok(self.indices.insert_module(module)) }); diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 9a29d7af..26b5a862 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -28,9 +28,8 @@ '$$compile_batch' :- '$compile_batch'. '$instruction_match'([Item], []) :- - ( atom(Item) -> + ( atom(Item) -> !, ( Item == user -> - !, catch('$$compile_batch', E, '$print_exception_with_check'(E)) ; consult(Item) )