From 1d41489381d01b55d0b293591afde3e873cc2a33 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sat, 12 Oct 2019 19:14:33 -0600 Subject: [PATCH] correct off by 1 error in verify_attrs_interrupt, revert to previous lists.pl --- Cargo.toml | 2 +- src/prolog/instructions.rs | 1 - src/prolog/lib/lists.pl | 78 ++++++++++++------------------ src/prolog/machine/mod.rs | 6 +-- src/prolog/machine/system_calls.rs | 6 +-- src/prolog/write.rs | 15 ++++++ 6 files changed, 53 insertions(+), 55 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d435e6a8..c9f70a8b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scryer-prolog" -version = "0.8.106" +version = "0.8.107" authors = ["Mark Thom "] build = "build.rs" repository = "https://github.com/mthom/scryer-prolog" diff --git a/src/prolog/instructions.rs b/src/prolog/instructions.rs index 4a5fc0c8..e71351bc 100644 --- a/src/prolog/instructions.rs +++ b/src/prolog/instructions.rs @@ -151,7 +151,6 @@ impl Line { &Line::Cut(_) => true, &Line::Fact(_) => true, &Line::Query(_) => true, - &Line::Control(ControlInstruction::Proceed) => true, _ => false, } } diff --git a/src/prolog/lib/lists.pl b/src/prolog/lib/lists.pl index 5d130841..c7d8e6a3 100644 --- a/src/prolog/lib/lists.pl +++ b/src/prolog/lib/lists.pl @@ -50,58 +50,42 @@ reverse([], [], YsRev, YsRev). reverse([X1|Xs], [Y1|Ys], YsPreludeRev, Xss) :- reverse(Xs, Ys, [Y1|YsPreludeRev], Xss). -maplist_([], _). -maplist_([E1|E1s], Cont) :- - call(Cont, E1), - maplist_(E1s, Cont). - -maplist(Cont, Es) :- maplist_(Es, Cont). - -maplist_([], _, []). -maplist_([E1|E1s], Cont, [E2|E2s]) :- - call(Cont, E1, E2), - maplist_(E1s, Cont, E2s). - -maplist(Cont, Es1, Es2) :- maplist_(Es1, Cont, Es2). - -maplist_([], Cont, [], []). -maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s]) :- - call(Cont, E1, E2, E3), - maplist_(E1s, Cont, E2s, E3s). - -maplist(Cont, Es1, Es2, Es3) :- maplist_(Es1, Cont, Es2, Es3). - -maplist_([], _, [], [], []). -maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s]) :- +maplist(_, []). +maplist(Cont1, [E1|E1s]) :- + call(Cont1, E1), + maplist(Cont1, E1s). + +maplist(_, [], []). +maplist(Cont2, [E1|E1s], [E2|E2s]) :- + call(Cont2, E1, E2), + maplist(Cont2, E1s, E2s). + +maplist(_, [], [], []). +maplist(Cont3, [E1|E1s], [E2|E2s], [E3|E3s]) :- + call(Cont3, E1, E2, E3), + maplist(Cont3, E1s, E2s, E3s). + +maplist(_, [], [], [], []). +maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s]) :- call(Cont, E1, E2, E3, E4), - maplist_(E1s, Cont, E2s, E3s, E4s). + maplist(Cont, E1s, E2s, E3s, E4s). -maplist(Cont, Es1, Es2, Es3, Es4) :- maplist_(Es1, Cont, Es2, Es3, Es4). - -maplist_([], _, [], [], [], []). -maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s]) :- +maplist(_, [], [], [], [], []). +maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s]) :- call(Cont, E1, E2, E3, E4, E5), - maplist_(E1s, Cont, E2s, E3s, E4s, E5s). - -maplist(Cont, Es1, Es2, Es3, Es4, Es5) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es5). + maplist(Cont, E1s, E2s, E3s, E4s, E5s). -maplist_([], _, [], [], [], [], []). -maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s]) :- +maplist(_, [], [], [], [], [], []). +maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s]) :- call(Cont, E1, E2, E3, E4, E5, E6), - maplist_(E1s, Cont, E2s, E3s, E4s, E5s, E6s). - -maplist(Cont, Es1, Es2, Es3, Es4, Es5, Es6) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es6, Es6). + maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s). -maplist_([], _, [], [], [], [], [], []). -maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s]) :- +maplist(_, [], [], [], [], [], [], []). +maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s]) :- call(Cont, E1, E2, E3, E4, E5, E6, E7), - maplist_(E1s, Cont, E2s, E3s, E4s, E5s, E6s, E7s). + maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s). -maplist(Cont, Es1, Es2, Es3, Es4, Es5, Es6, Es7) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es6, Es6, Es7). - -maplist_([], _, [], [], [], [], [], [], []). -maplist_([E1|E1s], Cont, [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s], [E8|E8s]) :- - call(Cont, E1, E2, E3, E4, E5, E6, E7, E8), - maplist_(E1s, Cont, E2s, E3s, E4s, E5s, E6s, E7s, E8s). - -maplist(Cont, Es1, Es2, Es3, Es4, Es5, Es6, Es7, Es8) :- maplist_(Es1, Cont, Es2, Es3, Es4, Es6, Es6, Es7, Es8). +maplist(_, [], [], [], [], [], [], [], []). +maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s], [E8|E8s]) :- + call(Cont, E1, E2, E3, E4, E5, E6, E7), + maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s, E8s). diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index d5ae71ec..32cfd9c5 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -383,7 +383,7 @@ impl Machine { fn throw_session_error(&mut self, err: SessionError, key: PredicateKey) { let h = self.machine_st.heap.h; - + let err = MachineError::session_error(h, err); let stub = MachineError::functor_stub(key.0, key.1); let err = self.machine_st.error_form(err, stub); @@ -600,7 +600,7 @@ impl Machine { self.machine_st.absorb_snapshot(snapshot); self.machine_st.ball = ball; - let h = self.machine_st.heap.h; + let h = self.machine_st.heap.h; let stub = self.machine_st.ball.copy_and_align(h); self.machine_st.throw_exception(stub); @@ -1046,7 +1046,7 @@ impl MachineState { match self.p { CodePtr::VerifyAttrInterrupt(_) => { - self.p = CodePtr::Local(self.attr_var_init.cp + 1); + self.p = CodePtr::Local(self.attr_var_init.cp);// + 1); if !self.verify_attr_stepper(indices, policies, code_repo, prolog_stream) { if self.fail { diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 14730e90..eab3ba47 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -1617,10 +1617,10 @@ impl MachineState { if let &Addr::Con(Constant::Usize(num_of_args)) = &self.and_stack[e][frame_len] { self.num_of_args = num_of_args; } - - self.p = CodePtr::Local(self.and_stack[e].interrupt_cp); + self.deallocate(); - + self.p = CodePtr::Local(self.and_stack[e].interrupt_cp); + return Ok(()); } &SystemClauseType::RestoreCutPolicy => { diff --git a/src/prolog/write.rs b/src/prolog/write.rs index a4d6706c..423e17e3 100644 --- a/src/prolog/write.rs +++ b/src/prolog/write.rs @@ -283,6 +283,21 @@ impl fmt::Display for SessionError { } } +impl fmt::Display for Line { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match self { + &Line::Arithmetic(ref arith_instr) => write!(f, "{}", arith_instr), + &Line::Choice(ref choice_instr) => write!(f, "{}", choice_instr), + &Line::Control(ref control_instr) => write!(f, "{}", control_instr), + &Line::Cut(ref cut_instr) => write!(f, "{}", cut_instr), + &Line::Fact(ref fact_instr) => write!(f, "{}", fact_instr), + &Line::Indexing(ref indexing_instr) => write!(f, "{}", indexing_instr), + &Line::IndexedChoice(ref indexed_choice_instr) => write!(f, "{}", indexed_choice_instr), + &Line::Query(ref query_instr) => write!(f, "{}", query_instr), + } + } +} + impl fmt::Display for Number { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { -- 2.54.0