From: Mark Thom Date: Fri, 2 Feb 2018 06:39:03 +0000 (-0700) Subject: fix setup_call_cleanup bug X-Git-Tag: v0.8.110~586 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=9c2e8dfd726a805a32b330d827ba98ddffe66fb9;p=scryer-prolog.git fix setup_call_cleanup bug --- diff --git a/src/prolog/builtins.rs b/src/prolog/builtins.rs index 7cae5c8c..aa644bdd 100644 --- a/src/prolog/builtins.rs +++ b/src/prolog/builtins.rs @@ -484,13 +484,16 @@ fn get_builtins(atom_tbl: TabledData) -> Code { reset_block!(), query![put_var!(perm_v!(1), 1)], get_ball!(), - goto_call!(337, 0), // goto run_cleaners_with_handling/0, 337. + goto_call!(340, 0), // goto run_cleaners_with_handling/0, 340. query![put_value!(perm_v!(1), 1)], deallocate!(), goto_execute!(59, 1), trust_me!(), - goto_execute!(349, 0), // goto run_cleaners_without_handling/0, 349. - try_me_else!(10), // run_cleaners_with_handling/0, 337. + allocate!(0), + goto_call!(352, 0), // goto run_cleaners_without_handling/0, 352. + fail!(), + deallocate!(), + try_me_else!(10), // run_cleaners_with_handling/0, 340. allocate!(2), get_level!(perm_v!(1)), query![put_var!(perm_v!(2), 1)], @@ -501,10 +504,10 @@ fn get_builtins(atom_tbl: TabledData) -> Code { goto_call!(5, 3), // goto catch/3, 5. cut!(perm_v!(1)), deallocate!(), - goto_execute!(337, 0), // goto run_cleaners_with_handling/0, 337. + goto_execute!(340, 0), // goto run_cleaners_with_handling/0, 340. trust_me!(), proceed!(), - try_me_else!(10), // run_cleaners_without_handling/1, 349. + try_me_else!(10), // run_cleaners_without_handling/1, 352. allocate!(2), get_level!(perm_v!(1)), query![put_var!(perm_v!(2), 1)], @@ -513,10 +516,10 @@ fn get_builtins(atom_tbl: TabledData) -> Code { call_n!(1), cut!(perm_v!(1)), deallocate!(), - goto_execute!(349, 0), // goto run_cleaners_without_handling/1, 349. + goto_execute!(352, 0), // goto run_cleaners_without_handling/0, 352. trust_me!(), proceed!(), - allocate!(1), // sgc_on_success/2, 361. + allocate!(1), // sgc_on_success/2, 364. fact![get_var_in_fact!(perm_v!(1), 2)], reset_block!(), cut!(perm_v!(1)), diff --git a/src/prolog/codegen.rs b/src/prolog/codegen.rs index 5e6e416a..ac6ce83e 100644 --- a/src/prolog/codegen.rs +++ b/src/prolog/codegen.rs @@ -246,7 +246,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker> { match qt { &QueryTerm::SetupCallCleanup(_) => - code.push(goto_call!(294, 3)), + code.push(goto_call!(294, 3)), &QueryTerm::Arg(_) => { let call = ControlInstruction::ArgCall; code.push(Line::Control(call)); @@ -495,7 +495,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker> let mut code = Vec::new(); if let &QueryTerm::Term(ref term) = p0 { - self.marker.reset_arg(term.arity()); + self.marker.reset_arg(term.arity()); self.compile_seq_prelude(&conjunct_info, &mut code); if let &Term::Clause(..) = term { @@ -508,7 +508,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker> } self.marker.reset_arg_at_head(term); - + let iter = ChunkedIterator::from_rule_body(p1, clauses); try!(self.compile_seq(iter, &conjunct_info, &mut code, false)); diff --git a/src/prolog/io.rs b/src/prolog/io.rs index 5d467db6..1e7f1113 100644 --- a/src/prolog/io.rs +++ b/src/prolog/io.rs @@ -494,6 +494,8 @@ fn compile_decl<'a, 'b: 'a>(wam: &'a mut Machine, tl: &'b TopLevel, queue: &'b V return EvalSession::from(e); }; + print_code(&code); + if !code.is_empty() { if let Some(name) = tl.name() { wam.add_user_code(name, tl.arity(), code) diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index caea4b3d..a6142676 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -1466,7 +1466,7 @@ impl MachineState { _ => { self.num_of_args = 2; self.b0 = self.b; - self.p = CodePtr::DirEntry(361); // goto sgc_on_success/2, 361. + self.p = CodePtr::DirEntry(364); // goto sgc_on_success/2, 364. } }; }, @@ -1797,7 +1797,7 @@ impl MachineState { self.cp = self.p; self.num_of_args = 0; self.b0 = self.b; - self.p = CodePtr::DirEntry(349); // goto_call run_cleaners_without_handling/0. + self.p = CodePtr::DirEntry(352); // goto_call run_cleaners_without_handling/0. } } }