From 10bb6ab3bbea5eec67a4fe053620081a818cff54 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Tue, 23 Nov 2021 19:59:35 -0700 Subject: [PATCH] restore old thread_goals to fix top-level solutions printing bug --- src/loader.pl | 11 -------- src/machine/loader.rs | 16 ----------- src/machine/system_calls.rs | 18 ++++++------ src/toplevel.pl | 56 ++++++++++++++++++------------------- 4 files changed, 37 insertions(+), 64 deletions(-) diff --git a/src/loader.pl b/src/loader.pl index fb5d8ab1..720e534a 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -709,15 +709,6 @@ expand_goal(UnexpandedGoals, Module, ExpandedGoals, HeadVars) :- ) ). -thread_goals([SG|SGs], G, F) :- - ( SGs \== [], functor(G, F, 2) -> - arg(1, G, SG), - arg(2, G, Gs1), - thread_goals(SGs, Gs1, F) - ; SG = G, - SGs = [] - ). - thread_goals(Goals0, Goals1, Hole, Functor) :- ( var(Goals0) -> Goals1 =.. [Functor, Goals0, Hole] @@ -731,7 +722,6 @@ thread_goals(Goals0, Goals1, Hole, Functor) :- ) ). -/* thread_goals(Goals0, Goals1, Functor) :- ( var(Goals0) -> Goals0 = Goals1 @@ -744,7 +734,6 @@ thread_goals(Goals0, Goals1, Functor) :- ; Goals1 = Goals0 ) ). -*/ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % diff --git a/src/machine/loader.rs b/src/machine/loader.rs index b2f43e54..d7ed073e 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -380,13 +380,6 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> { LS::evacuate(self) } - /* - #[inline(always)] - pub(crate) fn load_state(&mut self) -> &mut LoadStatePayload<>::TS> { - self.payload.as_mut() - } - */ - fn dequeue_terms(&mut self) -> Result, SessionError> { while !self.payload.term_stream.eof()? { let load_state = &mut self.payload; @@ -395,7 +388,6 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> { let term = load_state.term_stream.next(&composite_op_dir)?; - // if is_consistent is false, self.predicates is not empty. if !term.is_consistent(&load_state.predicates) { self.compile_and_submit()?; } @@ -450,14 +442,6 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> { let machine_st = LS::machine_st(&mut self.payload); let term_addr = machine_st[heap_term_loc]; - /* - if let Ok(lit) = Literal::try_from(term_addr) { - return Ok(Term::Literal(Cell::default(), lit)); - } else if machine_st.is_cyclic_term(term_addr) { - return Err(SessionError::from(CompilationError::CannotParseCyclicTerm)); - } - */ - let mut term_stack = vec![]; let mut iter = stackful_post_order_iter(&mut machine_st.heap, term_addr); diff --git a/src/machine/system_calls.rs b/src/machine/system_calls.rs index 5bc6a915..eedb127b 100644 --- a/src/machine/system_calls.rs +++ b/src/machine/system_calls.rs @@ -2495,17 +2495,17 @@ impl MachineState { &SystemClauseType::HeadIsDynamic => { let module_name = cell_as_atom!(self.store(self.deref(self.registers[1]))); - let (name, arity) = read_heap_cell!(self.store(self.deref(self.registers[2])), - (HeapCellValueTag::Str, s) => { - cell_as_atom_cell!(self.heap[s]).get_name_and_arity() - } + let (name, arity) = read_heap_cell!(self.store(self.deref(self.registers[2])), + (HeapCellValueTag::Str, s) => { + cell_as_atom_cell!(self.heap[s]).get_name_and_arity() + } (HeapCellValueTag::Atom, (name, _arity)) => { - (name, 0) - } + (name, 0) + } _ => { - unreachable!() - } - ); + unreachable!() + } + ); self.fail = !indices.is_dynamic_predicate(module_name, (name, arity)); } diff --git a/src/toplevel.pl b/src/toplevel.pl index 492fef83..18a6f3e8 100644 --- a/src/toplevel.pl +++ b/src/toplevel.pl @@ -155,14 +155,14 @@ instruction_match(Term, VarList) :- ; Term = [Item] -> !, ( atom(Item) -> - ( Item == user -> - catch(load(user_input), E, print_exception_with_check(E)) - ; - submit_query_and_print_results(consult(Item), []) - ) + ( Item == user -> + catch(load(user_input), E, print_exception_with_check(E)) + ; + submit_query_and_print_results(consult(Item), []) + ) ; catch(type_error(atom, Item, repl/0), - E, - print_exception_with_check(E)) + E, + print_exception_with_check(E)) ) ; Term = end_of_file -> halt @@ -184,7 +184,7 @@ submit_query_and_print_results_(_, _) :- submit_query_and_print_results(Term0, VarList) :- ( functor(Term0, call, _) -> Term = Term0 % prevent pre-mature expansion of incomplete goal - % in the first argument, which is done by call/N + % in the first argument, which is done by call/N ; expand_goal(Term0, user, Term) ), setup_call_cleanup(bb_put('$first_answer', true), @@ -194,10 +194,10 @@ submit_query_and_print_results(Term0, VarList) :- needs_bracketing(Value, Op) :- catch((functor(Value, F, _), - current_op(EqPrec, EqSpec, Op), - current_op(FPrec, _, F)), - _, - false), + current_op(EqPrec, EqSpec, Op), + current_op(FPrec, _, F)), + _, + false), ( EqPrec < FPrec -> true ; FPrec > 0, F == Value, graphic_token_char(F) -> @@ -211,15 +211,15 @@ needs_bracketing(Value, Op) :- write_goal(G, VarList, MaxDepth) :- ( G = (Var = Value) -> ( var(Value) -> - select((Var = _), VarList, NewVarList) + select((Var = _), VarList, NewVarList) ; VarList = NewVarList ), write(Var), write(' = '), ( needs_bracketing(Value, (=)) -> - write('('), - write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), - write(')') + write('('), + write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), + write(')') ; write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]) ) ; G == [] -> @@ -230,20 +230,20 @@ write_goal(G, VarList, MaxDepth) :- write_last_goal(G, VarList, MaxDepth) :- ( G = (Var = Value) -> ( var(Value) -> - select((Var = _), VarList, NewVarList) + select((Var = _), VarList, NewVarList) ; VarList = NewVarList ), write(Var), write(' = '), ( needs_bracketing(Value, (=)) -> - write('('), - write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), - write(')') + write('('), + write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), + write(')') ; write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), - ( trailing_period_is_ambiguous(Value) -> - write(' ') - ; true - ) + ( trailing_period_is_ambiguous(Value) -> + write(' ') + ; true + ) ) ; G == [] -> write('true') @@ -301,11 +301,11 @@ write_eqs_and_read_input(B, VarList) :- ), ( B0 == B -> ( Goals == [] -> - write('true.'), nl + write('true.'), nl ; loader:thread_goals(Goals, ThreadedGoals, (',')), - write_eq(ThreadedGoals, NewVarList0, 20), - write('.'), - nl + write_eq(ThreadedGoals, NewVarList0, 20), + write('.'), + nl ) ; loader:thread_goals(Goals, ThreadedGoals, (',')), write_eq(ThreadedGoals, NewVarList0, 20), -- 2.54.0