use new heap term representation

This commit is contained in:
Mark Thom
2021-11-14 13:39:56 -07:00
parent d0b74a95f4
commit 0404c3bd94
72 changed files with 26285 additions and 17019 deletions

View File

@@ -4,6 +4,7 @@
:- use_module(library(charsio)).
:- use_module(library(files)).
:- use_module(library(iso_ext)).
:- use_module(library(lambda)).
:- use_module(library(lists)).
:- use_module(library(si)).
@@ -17,7 +18,7 @@ load_scryerrc :-
append(HomeDir, "/.scryerrc", ScryerrcFile),
( file_exists(ScryerrcFile) ->
atom_chars(ScryerrcFileAtom, ScryerrcFile),
catch(consult(ScryerrcFileAtom), E, print_exception(E))
catch(use_module(ScryerrcFileAtom), E, print_exception(E))
; true
)
; true
@@ -166,7 +167,7 @@ instruction_match(Term, VarList) :-
; Term = end_of_file ->
halt
;
submit_query_and_print_results(Term, VarList)
submit_query_and_print_results(Term, VarList)
).
@@ -193,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) ->
@@ -210,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 == [] ->
@@ -229,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')
@@ -272,8 +273,13 @@ trailing_period_is_ambiguous(Value) :-
ValueChars \== ['.'],
graphic_token_char(Char).
term_variables_under_max_depth(Term, MaxDepth, Vars) :-
'$term_variables_under_max_depth'(Term, MaxDepth, Vars).
write_eqs_and_read_input(B, VarList) :-
term_variables(VarList, Vars0),
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),
@@ -281,12 +287,13 @@ write_eqs_and_read_input(B, VarList) :-
append([Vars0, AttrGoalVars, AttrVars], Vars),
charsio:extend_var_list(Vars, VarList, NewVarList, fabricated),
'$get_b_value'(B0),
gather_query_vars(VarList, OrigVars),
gather_equations(NewVarList, OrigVars, Equations),
append(Equations, AttrGoals, Goals),
term_variables(Equations, EquationVars),
append([AttrGoalVars, EquationVars], Vars1),
charsio:extend_var_list(Vars1, VarList, NewVarList0, fabricated),
% one layer of depth added for (=/2) functor
maplist(\Term^Vs^term_variables_under_max_depth(Term, 22, Vs), Equations, EquationVars),
append([AttrGoalVars | EquationVars], Vars1),
sort(Vars1, Vars2),
charsio:extend_var_list(Vars2, VarList, NewVarList0, fabricated),
( bb_get('$first_answer', true) ->
write(' '),
bb_put('$first_answer', false)
@@ -294,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),
@@ -340,7 +347,7 @@ gather_query_vars([_ = Var | Vars], QueryVars) :-
QueryVars = [Var | QueryVars0],
gather_query_vars(Vars, QueryVars0)
;
gather_query_vars(Vars, QueryVars)
gather_query_vars(Vars, QueryVars)
).
gather_query_vars([], []).
@@ -358,8 +365,8 @@ select_all([OtherVar = OtherValue | Pairs], Var, Value, Vars, NewPairs) :-
Vars = [OtherVar = OtherValue | Vars0],
select_all(Pairs, Var, Value, Vars0, NewPairs)
;
NewPairs = [OtherVar = OtherValue | NewPairs0],
select_all(Pairs, Var, Value, Vars, NewPairs0)
NewPairs = [OtherVar = OtherValue | NewPairs0],
select_all(Pairs, Var, Value, Vars, NewPairs0)
).
gather_equations([], _, []).
@@ -370,11 +377,11 @@ gather_equations([Var = Value | Pairs], OrigVarList, Goals) :-
append([Var = Value | VarEqs], Goals0, Goals),
gather_equations(NewPairs, OrigVarList, Goals0)
;
gather_equations(Pairs, OrigVarList, Goals)
gather_equations(Pairs, OrigVarList, Goals)
)
;
Goals = [Var = Value | Goals0],
gather_equations(Pairs, OrigVarList, Goals0)
Goals = [Var = Value | Goals0],
gather_equations(Pairs, OrigVarList, Goals0)
).
print_exception(E) :-