From: Mark Thom Date: Sun, 19 Apr 2020 02:10:53 +0000 (-0600) Subject: remove SCCCutPolicy panic, revise (;)/2 so that comma'ed cuts are handled properly... X-Git-Tag: v0.8.123~128 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=9daf2904320da2d41d3005e8ed14a162ea657fd4;p=scryer-prolog.git remove SCCCutPolicy panic, revise (;)/2 so that comma'ed cuts are handled properly (#361) --- diff --git a/src/prolog/lib/builtins.pl b/src/prolog/lib/builtins.pl index 17235d3b..7a1a7061 100644 --- a/src/prolog/lib/builtins.pl +++ b/src/prolog/lib/builtins.pl @@ -213,18 +213,36 @@ comma_errors(G1, G2, B) :- '$call_with_default_policy'(','(G1, G2, B)). ;(G1, G2) :- '$get_b_value'(B), ;(G1, G2, B). +:- non_counted_backtracking semicolon_compound_selector/3. +semicolon_compound_selector(->(G2, G3), G4, B) :- + ( call(G2) -> + call(G3) + ; '$set_cp'(B), + call(G4) + ). +semicolon_compound_selector(','(G2, G3), G4, B) :- + ( ','(G2, G3, B) + ; '$set_cp'(B), + call(G4) + ). +semicolon_compound_selector(';'(G2, G3), G4, B) :- + ( ';'(G2, G3, B) + ; '$set_cp'(B), + call(G4) + ). + :- non_counted_backtracking (;)/3. -;(G1, G4, B) :- compound(G1), - '$call_with_default_policy'(G1 = ->(G2, G3)), - !, - ( call(G2) -> call(G3) - ; '$set_cp'(B), - call(G4) - ). -;(G1, G2, B) :- G1 == !, '$set_cp'(B), call(G2). -;(G1, G2, B) :- G2 == !, call(G1), '$set_cp'(B). -;(G, _, _) :- call(G). -;(_, G, _) :- call(G). +;(G1, G4, B) :- + compound(G1), + semicolon_compound_selector(G1, G4, B). +;(G1, G2, B) :- + G1 == !, '$set_cp'(B), call(G2). +;(G1, G2, B) :- + G2 == !, call(G1), '$set_cp'(B). +;(G, _, _) :- + call(G). +;(_, G, _) :- + call(G). G1 -> G2 :- '$get_b_value'(B), '$call_with_default_policy'(->(G1, G2, B)). diff --git a/src/prolog/lib/iso_ext.pl b/src/prolog/lib/iso_ext.pl index 012b6654..a1944d13 100644 --- a/src/prolog/lib/iso_ext.pl +++ b/src/prolog/lib/iso_ext.pl @@ -68,7 +68,8 @@ scc_helper(C, G, Bb) :- ; '$reset_block'(NBb), '$fail'). scc_helper(_, _, Bb) :- - '$reset_block'(Bb), '$get_ball'(Ball), + '$reset_block'(Bb), + '$get_ball'(Ball), '$call_with_default_policy'(run_cleaners_with_handling), '$erase_ball', '$call_with_default_policy'(throw(Ball)). diff --git a/src/prolog/machine/code_repo.rs b/src/prolog/machine/code_repo.rs index 4d6951fc..e56a3571 100644 --- a/src/prolog/machine/code_repo.rs +++ b/src/prolog/machine/code_repo.rs @@ -60,7 +60,8 @@ impl CodeRepo { .unwrap_or((Predicate::new(), VecDeque::from(vec![]))) } - pub(crate) fn add_in_situ_result( + pub(crate) + fn add_in_situ_result( &mut self, result: &CompiledResult, in_situ_code_dir: &mut InSituCodeDir, @@ -100,16 +101,19 @@ impl CodeRepo { } #[inline] - pub(super) fn size_of_cached_query(&self) -> usize { + pub(super) + fn size_of_cached_query(&self) -> usize { self.cached_query.len() } #[inline] - pub(super) fn take_in_situ_code(&mut self) -> Code { + pub(super) + fn take_in_situ_code(&mut self) -> Code { mem::replace(&mut self.in_situ_code, Code::new()) } - pub(super) fn lookup_instr<'a>( + pub(super) + fn lookup_instr<'a>( &'a self, last_call: bool, p: &CodePtr, diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index e2cad96a..ec1ef49a 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -2280,7 +2280,8 @@ impl MachineState { } } } - None => panic!("expected SCCCutPolicy trait object."), + None => { + } }; self.fail = true; diff --git a/src/prolog/machine/toplevel.rs b/src/prolog/machine/toplevel.rs index 7cb56cc6..e4198a68 100644 --- a/src/prolog/machine/toplevel.rs +++ b/src/prolog/machine/toplevel.rs @@ -934,7 +934,7 @@ impl RelationWorker { let mut term = *term; if let Term::Clause(cell, name, terms, op_spec) = term { - if name.as_str() == "," { + if name.as_str() == "," && terms.len() == 2 { let term = Term::Clause(cell, name, terms, op_spec); let mut subterms = unfold_by_str(term, ","); diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 139a7a25..fd143fc7 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -1,14 +1,14 @@ -:- module('$toplevel', [repl/1, consult/1, use_module/1, use_module/2]). +:- module('$toplevel', ['$repl'/1, consult/1, use_module/1, use_module/2]). :- use_module(library(charsio)). :- use_module(library(lists)). :- use_module(library(si)). -repl([_|Args]) :- +'$repl'([_|Args]) :- maplist(use_list_of_modules, Args), false. -repl(_) :- repl. +'$repl'(_) :- repl. use_list_of_modules(Mod0) :- atom_chars(Mod, Mod0),