Project goals of query variables (#362)

This commit is contained in:
Mark Thom
2020-05-02 22:27:32 -06:00
parent 989bed88fe
commit 848425418b
4 changed files with 100 additions and 59 deletions

View File

@@ -44,8 +44,7 @@ make_new_var_name(VarType, V, VarName, N, N1, VarList) :-
N1 is N + 1 N1 is N + 1
). ).
extend_var_list(Value, VarList, NewVarList, VarType) :- extend_var_list(Vars, VarList, NewVarList, VarType) :-
term_variables(Value, Vars),
extend_var_list_(Vars, 0, VarList, NewVarList0, VarType), extend_var_list_(Vars, 0, VarList, NewVarList0, VarType),
append(VarList, NewVarList0, NewVarList). append(VarList, NewVarList0, NewVarList).
@@ -140,5 +139,6 @@ write_term_to_chars(Term, Options, Chars) :-
builtins:inst_member_or(Options, quoted(Quoted), quoted(false)), builtins:inst_member_or(Options, quoted(Quoted), quoted(false)),
builtins:inst_member_or(Options, variable_names(VarNames), variable_names([])), builtins:inst_member_or(Options, variable_names(VarNames), variable_names([])),
builtins:inst_member_or(Options, max_depth(MaxDepth), max_depth(0)), builtins:inst_member_or(Options, max_depth(MaxDepth), max_depth(0)),
extend_var_list(Term, VarNames, NewVarNames, numbervars), term_variables(Term, Vars),
extend_var_list(Vars, VarNames, NewVarNames, numbervars),
'$write_term_to_chars'(Term, IgnoreOps, NumberVars, Quoted, NewVarNames, MaxDepth, Chars). '$write_term_to_chars'(Term, IgnoreOps, NumberVars, Quoted, NewVarNames, MaxDepth, Chars).

View File

@@ -436,7 +436,6 @@ impl Machine {
) )
); );
compile_user_module(&mut wam, compile_user_module(&mut wam,
Stream::from(CHARSIO), Stream::from(CHARSIO),
true, true,
@@ -446,6 +445,15 @@ impl Machine {
) )
); );
compile_user_module(&mut wam,
Stream::from(ORDSETS),
true,
ListingSource::from_file_and_path(
clause_name!("si"),
lib_path.clone(),
)
);
if wam.compile_top_level().is_err() { if wam.compile_top_level().is_err() {
panic!("Loading '$toplevel' module failed"); panic!("Loading '$toplevel' module failed");
} }

View File

@@ -101,7 +101,7 @@ call_attribute_goals_with_module_prefix([Module | Modules], GoalCaller, AttrVars
call_attribute_goals_with_module_prefix(Modules, GoalCaller, AttrVars, Gs). call_attribute_goals_with_module_prefix(Modules, GoalCaller, AttrVars, Gs).
copy_term(Source, Dest, Goals) :- copy_term(Source, Dest, Goals) :-
term_variables(Source, Vars), '$term_attributed_variables'(Source, Vars),
gather_modules(Vars, Modules0, _), gather_modules(Vars, Modules0, _),
sort(Modules0, Modules), sort(Modules0, Modules),
call_attribute_goals_with_module_prefix(Modules, call_query_var_goals, Vars, Goals0), call_attribute_goals_with_module_prefix(Modules, call_query_var_goals, Vars, Goals0),

View File

@@ -1,9 +1,9 @@
:- module('$toplevel', ['$repl'/1, consult/1, use_module/1, use_module/2, :- module('$toplevel', ['$repl'/1, consult/1, use_module/1, use_module/2,
argv/1]). argv/1]).
:- use_module(library(charsio)). :- use_module(library(charsio)).
:- use_module(library(lists)). :- use_module(library(lists)).
:- use_module(library(ordsets)).
:- use_module(library(si)). :- use_module(library(si)).
:- dynamic(argv/1). :- dynamic(argv/1).
@@ -229,9 +229,12 @@ trailing_period_is_ambiguous(Value) :-
graphic_token_char(Char). graphic_token_char(Char).
write_eqs_and_read_input(B, VarList) :- write_eqs_and_read_input(B, VarList) :-
charsio:extend_var_list(VarList, VarList, NewVarList, fabricated), term_variables(VarList, Vars0),
'$term_attributed_variables'(VarList, AttrVars),
append(Vars0, AttrVars, Vars),
charsio:extend_var_list(Vars, VarList, NewVarList, fabricated),
'$get_b_value'(B0), '$get_b_value'(B0),
gather_goals(NewVarList, NewVarList, Goals), gather_goals(NewVarList, NewVarList, VarList, Goals),
( bb_get('$first_answer', true) -> ( bb_get('$first_answer', true) ->
write(' '), write(' '),
bb_put('$first_answer', false) bb_put('$first_answer', false)
@@ -293,18 +296,48 @@ is_a_different_variable([_ = Binding | Pairs], Value) :-
; is_a_different_variable(Pairs, Value) ; is_a_different_variable(Pairs, Value)
). ).
gather_goals([], VarList, Goals) :- filter_goals([Goal|Goals], FGoals, QueryVars) :-
gather_query_vars(VarList, QueryVars), term_variables(Goal, GoalVars0),
copy_term(QueryVars, QueryVars, Goals). sort(GoalVars0, GoalVars),
gather_goals([Var = Value | Pairs], VarList, Goals) :- ( ord_intersect(GoalVars, QueryVars) ->
append(GoalVars, QueryVars, QueryVars0),
sort(QueryVars0, QueryVars1),
FGoals = [Goal | FGoals0],
filter_goals(Goals, FGoals0, QueryVars1)
;
filter_goals(Goals, FGoals, QueryVars)
).
filter_goals([], [], _).
gather_goals([], VarList, QueryVarList, Goals) :-
gather_query_vars(VarList, Vars),
term_variables(QueryVarList, QueryVars),
copy_term(Vars, Vars, Goals0),
filter_goals(Goals0, Goals, QueryVars).
gather_goals([Var = Value | Pairs], VarList, QueryVarList, Goals) :-
( ( nonvar(Value) ( ( nonvar(Value)
; is_a_different_variable(Pairs, Value) ; is_a_different_variable(Pairs, Value)
) -> ) ->
Goals = [Var = Value | Goals0], Goals = [Var = Value | Goals0],
gather_goals(Pairs, VarList, Goals0) gather_goals(Pairs, VarList, QueryVarList, Goals0)
; gather_goals(Pairs, VarList, Goals) ; gather_goals(Pairs, VarList, QueryVarList, Goals)
). ).
/*
gather_goals([], VarList, QueryVarList, Goals) :-
gather_query_vars(VarList, Vars),
copy_term(Vars, Vars, Goals).
% filter_goals(Goals0, Goals, Vars).
gather_goals([Var = Value | Pairs], VarList, QueryVarList, Goals) :-
( ( nonvar(Value)
; is_a_different_variable(Pairs, Value)
) ->
Goals = [Var = Value | Goals0],
gather_goals(Pairs, VarList, QueryVarList, Goals0)
; gather_goals(Pairs, VarList, QueryVarList, Goals)
).
*/
print_exception(E) :- print_exception(E) :-
( E == error('$interrupt_thrown', repl) -> nl % print the ( E == error('$interrupt_thrown', repl) -> nl % print the
% exception on a % exception on a