restore old thread_goals to fix top-level solutions printing bug

This commit is contained in:
Mark Thom
2021-11-23 19:59:35 -07:00
parent 4af57b0dd3
commit 10bb6ab3bb
4 changed files with 37 additions and 64 deletions

View File

@@ -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) :- thread_goals(Goals0, Goals1, Hole, Functor) :-
( var(Goals0) -> ( var(Goals0) ->
Goals1 =.. [Functor, Goals0, Hole] Goals1 =.. [Functor, Goals0, Hole]
@@ -731,7 +722,6 @@ thread_goals(Goals0, Goals1, Hole, Functor) :-
) )
). ).
/*
thread_goals(Goals0, Goals1, Functor) :- thread_goals(Goals0, Goals1, Functor) :-
( var(Goals0) -> ( var(Goals0) ->
Goals0 = Goals1 Goals0 = Goals1
@@ -744,7 +734,6 @@ thread_goals(Goals0, Goals1, Functor) :-
; Goals1 = Goals0 ; Goals1 = Goals0
) )
). ).
*/
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %

View File

@@ -380,13 +380,6 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
LS::evacuate(self) LS::evacuate(self)
} }
/*
#[inline(always)]
pub(crate) fn load_state(&mut self) -> &mut LoadStatePayload<<LS as LoadState<'a>>::TS> {
self.payload.as_mut()
}
*/
fn dequeue_terms(&mut self) -> Result<Option<Declaration>, SessionError> { fn dequeue_terms(&mut self) -> Result<Option<Declaration>, SessionError> {
while !self.payload.term_stream.eof()? { while !self.payload.term_stream.eof()? {
let load_state = &mut self.payload; 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)?; 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) { if !term.is_consistent(&load_state.predicates) {
self.compile_and_submit()?; 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 machine_st = LS::machine_st(&mut self.payload);
let term_addr = machine_st[heap_term_loc]; 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 term_stack = vec![];
let mut iter = stackful_post_order_iter(&mut machine_st.heap, term_addr); let mut iter = stackful_post_order_iter(&mut machine_st.heap, term_addr);

View File

@@ -2495,17 +2495,17 @@ impl MachineState {
&SystemClauseType::HeadIsDynamic => { &SystemClauseType::HeadIsDynamic => {
let module_name = cell_as_atom!(self.store(self.deref(self.registers[1]))); 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])), let (name, arity) = read_heap_cell!(self.store(self.deref(self.registers[2])),
(HeapCellValueTag::Str, s) => { (HeapCellValueTag::Str, s) => {
cell_as_atom_cell!(self.heap[s]).get_name_and_arity() cell_as_atom_cell!(self.heap[s]).get_name_and_arity()
} }
(HeapCellValueTag::Atom, (name, _arity)) => { (HeapCellValueTag::Atom, (name, _arity)) => {
(name, 0) (name, 0)
} }
_ => { _ => {
unreachable!() unreachable!()
} }
); );
self.fail = !indices.is_dynamic_predicate(module_name, (name, arity)); self.fail = !indices.is_dynamic_predicate(module_name, (name, arity));
} }

View File

@@ -155,14 +155,14 @@ instruction_match(Term, VarList) :-
; Term = [Item] -> ; Term = [Item] ->
!, !,
( atom(Item) -> ( atom(Item) ->
( Item == user -> ( Item == user ->
catch(load(user_input), E, print_exception_with_check(E)) catch(load(user_input), E, print_exception_with_check(E))
; ;
submit_query_and_print_results(consult(Item), []) submit_query_and_print_results(consult(Item), [])
) )
; catch(type_error(atom, Item, repl/0), ; catch(type_error(atom, Item, repl/0),
E, E,
print_exception_with_check(E)) print_exception_with_check(E))
) )
; Term = end_of_file -> ; Term = end_of_file ->
halt halt
@@ -184,7 +184,7 @@ submit_query_and_print_results_(_, _) :-
submit_query_and_print_results(Term0, VarList) :- submit_query_and_print_results(Term0, VarList) :-
( functor(Term0, call, _) -> ( functor(Term0, call, _) ->
Term = Term0 % prevent pre-mature expansion of incomplete goal 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) ; expand_goal(Term0, user, Term)
), ),
setup_call_cleanup(bb_put('$first_answer', true), setup_call_cleanup(bb_put('$first_answer', true),
@@ -194,10 +194,10 @@ submit_query_and_print_results(Term0, VarList) :-
needs_bracketing(Value, Op) :- needs_bracketing(Value, Op) :-
catch((functor(Value, F, _), catch((functor(Value, F, _),
current_op(EqPrec, EqSpec, Op), current_op(EqPrec, EqSpec, Op),
current_op(FPrec, _, F)), current_op(FPrec, _, F)),
_, _,
false), false),
( EqPrec < FPrec -> ( EqPrec < FPrec ->
true true
; FPrec > 0, F == Value, graphic_token_char(F) -> ; FPrec > 0, F == Value, graphic_token_char(F) ->
@@ -211,15 +211,15 @@ needs_bracketing(Value, Op) :-
write_goal(G, VarList, MaxDepth) :- write_goal(G, VarList, MaxDepth) :-
( G = (Var = Value) -> ( G = (Var = Value) ->
( var(Value) -> ( var(Value) ->
select((Var = _), VarList, NewVarList) select((Var = _), VarList, NewVarList)
; VarList = NewVarList ; VarList = NewVarList
), ),
write(Var), write(Var),
write(' = '), write(' = '),
( needs_bracketing(Value, (=)) -> ( needs_bracketing(Value, (=)) ->
write('('), write('('),
write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), 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_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)])
) )
; G == [] -> ; G == [] ->
@@ -230,20 +230,20 @@ write_goal(G, VarList, MaxDepth) :-
write_last_goal(G, VarList, MaxDepth) :- write_last_goal(G, VarList, MaxDepth) :-
( G = (Var = Value) -> ( G = (Var = Value) ->
( var(Value) -> ( var(Value) ->
select((Var = _), VarList, NewVarList) select((Var = _), VarList, NewVarList)
; VarList = NewVarList ; VarList = NewVarList
), ),
write(Var), write(Var),
write(' = '), write(' = '),
( needs_bracketing(Value, (=)) -> ( needs_bracketing(Value, (=)) ->
write('('), write('('),
write_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]), 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_term(Value, [quoted(true), variable_names(NewVarList), max_depth(MaxDepth)]),
( trailing_period_is_ambiguous(Value) -> ( trailing_period_is_ambiguous(Value) ->
write(' ') write(' ')
; true ; true
) )
) )
; G == [] -> ; G == [] ->
write('true') write('true')
@@ -301,11 +301,11 @@ write_eqs_and_read_input(B, VarList) :-
), ),
( B0 == B -> ( B0 == B ->
( Goals == [] -> ( Goals == [] ->
write('true.'), nl write('true.'), nl
; loader:thread_goals(Goals, ThreadedGoals, (',')), ; loader:thread_goals(Goals, ThreadedGoals, (',')),
write_eq(ThreadedGoals, NewVarList0, 20), write_eq(ThreadedGoals, NewVarList0, 20),
write('.'), write('.'),
nl nl
) )
; loader:thread_goals(Goals, ThreadedGoals, (',')), ; loader:thread_goals(Goals, ThreadedGoals, (',')),
write_eq(ThreadedGoals, NewVarList0, 20), write_eq(ThreadedGoals, NewVarList0, 20),