]> Repositorios git - scryer-prolog.git/commitdiff
Switch back to run_input_once and use duplicated write_eqs/2 without any input handling
authorNicolas Luck <[email protected]>
Wed, 2 Aug 2023 12:52:49 +0000 (14:52 +0200)
committerNicolas Luck <[email protected]>
Wed, 2 Aug 2023 12:52:49 +0000 (14:52 +0200)
src/lib_toplevel.pl
src/machine/lib_machine.rs

index 4eccbafe39c8ee0b5861167aae5ecdc60a382b1d..091d15cda159eeecedc3940bc18325b055e49388 100644 (file)
@@ -231,9 +231,9 @@ read_and_match_all_results :-
 submit_query_and_print_all_results(Term, VarList) :-
     '$get_b_value'(B),
     bb_put('$report_all', true),
-    bb_put('$report_n_more', 0),
+    bb_put('$report_n_more', 100),
     call(user:Term),
-    write_eqs_and_read_input(B, VarList),
+    write_eqs(B, VarList),
     !.
 submit_query_and_print_all_results(_, _) :-
     (   bb_get('$answer_count', 0) ->
@@ -243,6 +243,46 @@ submit_query_and_print_all_results(_, _) :-
     write('false.'),
     nl.
 
+write_eqs(B, VarList) :-
+    gather_query_vars(VarList, OrigVars),
+    % one layer of depth added for (=/2) functor
+    '$term_variables_under_max_depth'(OrigVars, 22, Vars0),
+    '$term_attributed_variables'(VarList, AttrVars),
+    '$project_atts':project_attributes(Vars0, AttrVars),
+    copy_term(AttrVars, AttrVars, AttrGoals),
+    term_variables(AttrGoals, AttrGoalVars),
+    append([Vars0, AttrGoalVars, AttrVars], Vars),
+    charsio:extend_var_list(Vars, VarList, NewVarList, fabricated),
+    '$get_b_value'(B0),
+    gather_equations(NewVarList, OrigVars, Equations),
+    append(Equations, AttrGoals, Goals),
+    % one layer of depth added for (=/2) functor
+    maplist(\Term^Vs^term_variables_under_max_depth(Term, 22, Vs), Equations, EquationVars),
+    % maplist(term_variables_under_max_depth(22), Equations, EquationVars),
+    append([AttrGoalVars | EquationVars], Vars1),
+    term_variables(Vars1, Vars2), % deduplicate vars of Vars1 but preserve their order.
+    charsio:extend_var_list(Vars2, VarList, NewVarList0, fabricated),
+    bb_get('$answer_count', Count),
+    (   Count =:= 0 ->
+        write('   ')
+    ;   true
+    ),
+    Count1 is Count + 1,
+    bb_put('$answer_count', Count1),
+    (  B0 == B ->
+       (  Goals == [] ->
+          write('true.'), nl
+       ;  loader:thread_goals(Goals, ThreadedGoals, (',')),
+          write_eq(ThreadedGoals, NewVarList0, 200000),
+          write('.'),
+          nl
+       )
+    ;  loader:thread_goals(Goals, ThreadedGoals, (',')),
+       write_eq(ThreadedGoals, NewVarList0, 200000),
+       write(';'), nl, false
+    ).
+
+
 
 
 toplevel :-
index 194434c33c4af3c15758f60a6c068bc60de20649..bec03a768cad76439b3e3f50ee623d1ca12a21c1 100644 (file)
@@ -28,7 +28,7 @@ impl Machine {
         let input = format!("{}", query);
         println!("Running query: {}", input);
         self.set_user_input(input);
-        self.run_top_level(atom!("$toplevel"), (atom!("toplevel"), 0));
+        self.run_top_level(atom!("$toplevel"), (atom!("run_input_once"), 0));
         self.parse_output()
     }