Skip to content

Commit 3c484a7

Browse files
committed
assertNotAlphaEqual + show_tf
1 parent 1783d2d commit 3c484a7

14 files changed

+446
-164
lines changed

prolog/metta_lang/metta_compiler_lib.pl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,14 @@
442442
'mc__1_1_collapse'(B,BB)),
443443
equal_enough_for_test_renumbered_l(alpha_equ,AA,BB), C).
444444

445+
transpiler_predicate_store(builtin, 'assertNotAlphaEqual', [2], '@doc', '@doc', [x(doeval,lazy,[]),x(noeval,lazy,[])], x(doeval,eager,[])).
446+
'mc__1_2_assertNotAlphaEqual'(A,B,C) :-
447+
loonit_assert_source_tf_empty(
448+
['assertNotAlphaEqual',A,B],AA,BB,
449+
('mc__1_1_collapse'(A,AA),
450+
'mc__1_1_collapse'(B,BB)),
451+
equal_enough_for_test_renumbered_l(not_alpha_equ,AA,BB), C).
452+
445453
transpiler_predicate_store(builtin, 'quote', [1], '@doc', '@doc', [x(noeval,eager,[])], x(noeval,eager,[])).
446454
'mc__1_1_quote'(A,['quote',A]).
447455
compile_flow_control(HeadIs,LazyVars,RetResult,RetResultN,LazyRetQuoted,Convert, QuotedCode1a, QuotedCode1N) :-
@@ -740,6 +748,7 @@
740748
%metta_body_macro_pass(bu,[eval,Next], Next).
741749

742750
% metta_body_macro_pass(td,[eval,Eval], Eval).
751+
metta_body_macro_pass(td1,['capture',Eval], Eval).
743752

744753
metta_body_macro_pass(td2,['unique',Eval],
745754
['let',Var,['call-fn!','no_repeats_var'],

prolog/metta_lang/metta_debug.pl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216

217217
ss_unify(W,T):- copy_term(T,TT),W=T,T=@=TT.
218218

219-
indentq2(Depth, Term) :- fail, ss_unify(defs_used(X-->Y,R),Term),
219+
indentq2(Depth, Term) :- ss_unify(defs_used(X-->Y,R),Term),
220220
indentq2(Depth, lhs(X)),
221221
indentq2(Depth, rhs(Y)),
222222
indentq2(Depth, R),!.
@@ -860,9 +860,10 @@
860860
set_prolog_flag(occurs_check,Was)).
861861

862862
woc(TFE,Goal):- current_prolog_flag(occurs_check,TFE),!,call(Goal).
863-
woc(TFE,Goal):- current_prolog_flag(occurs_check,TFE),!,precopy_term(Goal,CGoal),!,call(CGoal),uncopy_term(Goal,CGoal).
863+
%woc(TFE,Goal):- current_prolog_flag(occurs_check,TFE),!,precopy_term(Goal,CGoal),!,call(CGoal),uncopy_term(Goal,CGoal).
864864
woc(TFE,Goal):- current_prolog_flag(occurs_check,Was),redo_call_cleanup(set_prolog_flag(occurs_check,TFE),Goal,set_prolog_flag(occurs_check,Was)).
865865

866+
catch_oce(CGoal):- !, call(CGoal).
866867
catch_oce(CGoal):-
867868
Error = error(occurs_check(_,_),_),
868869
precopy_term(CGoal,Goal), catch(Goal,Error,(rtrace(Goal),maybe_rethrow(Error))), uncopy_term(CGoal,Goal).

prolog/metta_lang/metta_eval.pl

Lines changed: 203 additions & 69 deletions
Large diffs are not rendered by default.

prolog/metta_lang/metta_improve.pl

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66

77
:- dynamic use_evaluator/3.
88

9+
use_evaluator(fa(Fn,_), compiler, disabled):- nb_current(disable_compiler,Was), member(Fn,Was),!.
10+
use_evaluator(fa(Fn,_), interp, disabled):- nb_current(disable_interp,Was), member(Fn,Was),!.
911
use_evaluator(FA, Type, only):- nonvar(Type),
1012
use_evaluator(FA, Other, disabled), Type\==Other.
1113
use_evaluator(FA, Type, enabled):- use_evaluator(FA, Type, only).
1214

1315
use_evaluator(fa('help!', 1), compiler, disabled).
1416
use_evaluator(fa('help!', 0), compiler, disabled).
17+
use_evaluator(fa('listing!', 1), interp, disabled).
1518
use_evaluator(fa('compiled-info', 1), interp, disabled).
1619

1720
some_evaluator(interp).
@@ -43,6 +46,15 @@
4346
must(assumed_functor(X, FA)), !,
4447
use_right_thing(FA, Eq, RetType, Depth, Self, X, Y).
4548

49+
use_right_thing(_FA, Eq,RetType,Depth,Self,X,Y):-
50+
nb_current('eval_in_only', interp), !,
51+
eval_09(Eq,RetType,Depth,Self,X,Y).
52+
use_right_thing(_FA, Eq,RetType,Depth,Self,X,Y):-
53+
nb_current('eval_in_only', compiler), !,
54+
with_scope(Eq, RetType, Depth, Self, transpile_eval(X,Y)).
55+
use_right_thing(_FA, Eq,RetType,Depth,Self,X,Y):-
56+
nb_current('eval_in_only', rust), !,
57+
with_scope(Eq, RetType, Depth, Self, rust_metta_run(exec(X),Y)).
4658
use_right_thing(FA, Eq, RetType, Depth, Self, X, Y):-
4759
with_scope(Eq, RetType, Depth, Self, use_right_thing(FA, X, Y)).
4860

@@ -56,10 +68,23 @@
5668
findall(Use=Status, (some_evaluator(Use),use_evaluator(FA, Use, Status)), Info),
5769
(nb_current('eval_in_only', OnlyIn)->true;OnlyIn=[]),
5870
(nb_current('eval_fallback', FallBack)->true;FallBack=[]),
59-
ppt(use_right_thing(onlyIn=OnlyIn,fallBack=FallBack,FA=Info)),
71+
(nb_current('disable_compiler', DC)->true;DC=[]),
72+
(nb_current('disable_interp', DI)->true;DI=[]),
73+
ppt(use_right_thing(onlyIn=OnlyIn,fallBack=FallBack,dC=DC,dI=DI,FA=Info)),
6074
fail.
6175

62-
use_right_thing(FA, X, Y) :-
76+
77+
use_right_thing(_FA, X,Y):-
78+
nb_current('eval_in_only', interp), !,
79+
peek_scope(Eq,RetType,Depth,Self),!,
80+
eval_09(Eq,RetType,Depth,Self,X,Y).
81+
use_right_thing(_FA, X,Y):-
82+
nb_current('eval_in_only', compiler), !,
83+
transpile_eval(X,Y).
84+
use_right_thing(_FA, X,Y):-
85+
nb_current('eval_in_only', rust), !,
86+
rust_metta_run(exec(X),Y).
87+
use_right_thing( FA, X, Y) :-
6388
use_evaluator(FA, compiler, disabled), !,
6489
eval_in_only(interp, X, Y).
6590

@@ -151,14 +176,18 @@
151176
).
152177

153178

154-
eval_in_only(OnlyIn, X, Y):-
179+
eval_in_only(OnlyIn, Goal):-
155180
locally(nb_setval('eval_in_only', OnlyIn),
181+
Goal).
182+
183+
eval_in_only(OnlyIn, X, Y):-
184+
eval_in_only(OnlyIn,
156185
eval_in(OnlyIn, X, Y)).
157186

158187
eval_in(interp, X, Y):-
159188
peek_scope(Eq, RetType, Depth, Self),
160-
woc(eval_10(Eq, RetType, Depth, Self, X, Y)).
161-
189+
eval_09(Eq, RetType, Depth, Self, X, Y).
162190
eval_in(compiler, X, Y):-
163191
transpile_eval(X, Y).
164-
192+
eval_in(rust, X, Y):-
193+
rust_metta_run(exec(X),Y).

prolog/metta_lang/metta_interp.pl

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,9 @@
15641564
on_set_value(Note,N,true). % true
15651565
on_set_value(Note,N,'False'):- nocut,
15661566
on_set_value(Note,N,false). % false
1567+
1568+
on_set_value(_Note,noninteractive,true):- nocut, ignore(noninteractive),!.
1569+
on_set_value(_Note,abort_trace,true):- nocut, ignore(abort_trace),!.
15671570
on_set_value(_Note,abolish_trace,true):- nocut, ignore(abolish_trace),!.
15681571

15691572
on_set_value(_Note,show, Value):-
@@ -2722,7 +2725,7 @@
27222725
% Mark that the prescan has been executed.
27232726
assert(has_run_cmd_args),
27242727
% Perform the prescan using `do_cmdline_load_metta/1`.
2725-
do_cmdline_load_metta(prescan).
2728+
do_cmdline_load_metta(prescan), setup_show_hide_debug.
27262729

27272730
%! run_cmd_args is det.
27282731
%
@@ -3110,23 +3113,26 @@
31103113
if_phase(Phase, execute, catch_abort(['-G', Str], ignore(call_sexpr('!', Self, Str, _S, _Out)))), !,
31113114
cmdline_load_metta(Phase, Self, Rest).
31123115

3113-
% Handle file loading when the argument does not start with `-`.
3114-
cmdline_load_metta(Phase, Self, [Filemask | Rest]) :-
3115-
symbol(Filemask),
3116-
\+ symbol_concat('-', _, Filemask), !,
3117-
if_phase(Phase, execute, cmdline_load_file(Self, Filemask)), !,
3118-
cmdline_load_metta(Phase, Self, Rest).
31193116
% Handle command-line options by setting their corresponding values.
31203117

31213118
cmdline_load_metta(Phase, Self, [Skip, _ | Rest]) :- skip_cmdarg(Skip), !,
31223119
cmdline_load_metta(Phase, Self, Rest).
31233120

3121+
% forces whatver is after -D to bve treated as flag-like
31243122
cmdline_load_metta(Phase, Self, ['-D', M | Rest]) :- !,
3125-
process_flag(M), !,
3123+
process_as_flag(M), !,
31263124
cmdline_load_metta(Phase, Self, Rest).
3125+
3126+
% picks up on name=value
31273127
cmdline_load_metta(Phase, Self, [M | Rest]) :-
31283128
process_flag(M), !,
31293129
cmdline_load_metta(Phase, Self, Rest).
3130+
% Handle file loading when the argument does not start with `-`.
3131+
cmdline_load_metta(Phase, Self, [Filemask | Rest]) :-
3132+
symbol(Filemask),
3133+
\+ symbol_concat('-', _, Filemask), !,
3134+
if_phase(Phase, execute, cmdline_load_file(Self, Filemask)), !,
3135+
cmdline_load_metta(Phase, Self, Rest).
31303136
% Handle unrecognized command-line options by logging a warning.
31313137
cmdline_load_metta(Phase, Self, [M | Rest]) :-
31323138
format('~N'),
@@ -3965,6 +3971,8 @@
39653971
% % Execute a goal and trace errors:
39663972
% ?- rtrace_on_error(writeln('Hello, World!')).
39673973
%
3974+
3975+
rtrace_on_error(G):- is_user_repl, !, call(G).
39683976
rtrace_on_error(G):- !, call(G).
39693977
%rtrace_on_error(G):- catch(G,_,fail).
39703978
rtrace_on_error(G):-
@@ -4440,7 +4448,7 @@
44404448
%
44414449
metta_atom_added(X, Y) :- nocut,
44424450
% Check if the atom was explicitly asserted.
4443-
metta_atom_asserted(X, Y).
4451+
metta_atom_asserted_ocw(X, Y).
44444452
metta_atom_added(X, Y) :- nocut,
44454453
% Check if the atom is associated with a file.
44464454
metta_atom_in_file(X, Y).
@@ -4452,6 +4460,11 @@
44524460
% Check if the atom was recently asserted.
44534461
metta_atom_asserted_last(X, Y).
44544462

4463+
4464+
metta_atom_asserted_ocw(X, Y):-
4465+
woct(metta_atom_asserted(X, Y)).
4466+
%clause_occurs_warning(metta_atom_asserted(X, Y)).
4467+
44554468
%! metta_atom(+Space, -Atom) is nondet.
44564469
%
44574470
% Retrieves atoms associated with a given space or knowledge base (`Space`).
@@ -4490,7 +4503,7 @@
44904503
metta_atom0(Inherit,X, Y) :- maybe_into_top_self(X, TopSelf), !, metta_atom0(Inherit,TopSelf, Y).
44914504

44924505

4493-
metta_atom0(_Inherit,KB, Atom) :- metta_atom_added(KB, Atom).
4506+
metta_atom0(_Inherit,KB, Atom) :- woce(metta_atom_added(KB, Atom)).
44944507

44954508

44964509

@@ -6056,9 +6069,16 @@
60566069
eval_H(_StackMax, _Self, Term, Term) :-
60576070
% If the `compile` option is set to `save`, return the term unchanged.
60586071
fast_option_value(compile, save), !.
6059-
eval_H(StackMax, Self, Term, X) :-
6072+
eval_H(StackMax, Self, Term, XO) :-
6073+
copy_term(Term+X,CTerm+CX),
60606074
% Otherwise, perform evaluation with error handling, passing the stack limit.
6061-
woc(catch_metta_return(eval_args('=', _, StackMax, Self, Term, X), X)).
6075+
woc(catch_metta_return(eval_args_stack_max('=', _, StackMax, Self, CTerm, CX), CX)),
6076+
CX\=='Empty',
6077+
CTerm=Term,CX=X,
6078+
XO=CX.
6079+
6080+
eval_args_stack_max('=', _, StackMax, Self, Term, X):-
6081+
eval_args('=', _, StackMax, Self, Term, X).
60626082
/*
60636083
eval_H(StackMax,Self,Term,X).
60646084
@@ -7198,7 +7218,7 @@
71987218
% is allowed, it handles modifications to `system:notrace/1` to customize its behavior.
71997219
%
72007220

7201-
nts1 :- !. % Disable redefinition by cutting execution.
7221+
%nts1 :- !. % Disable redefinition by cutting execution.
72027222
%nts1 :- is_flag(notrace),!.
72037223
nts1 :- no_interupts(nts1r).
72047224
nts1r :-
@@ -7213,7 +7233,8 @@
72137233
meta_predicate(system:notrace(0)),
72147234
% Define the new behavior for `system:notrace/1`.
72157235
% The redefined version executes the goal (`G`) with `once/1` and succeeds deterministically.
7216-
asserta(( system:notrace(G) :- (!, unotrace(G),! ))).
7236+
asserta(( system:notrace(G) :- (!, once(G),! ))).
7237+
%asserta(( system:notrace(G) :- (!, unotrace(G),! )))
72177238
nts1r :-
72187239
% Ensure that further redefinitions of `nts1` are not allowed after the first.
72197240
!.

prolog/metta_lang/metta_loader.pl

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@
898898
exists_file(RelFilename),!,
899899
% Convert the relative filename to an absolute path.
900900
afn_from(RelFilename, Filename),
901+
set_exec_num(Filename, 0),
901902
% Generate a temporary file if necessary, based on the absolute filename.
902903
gen_tmp_file(false, Filename),
903904
% Extract the directory path from the filename.
@@ -912,6 +913,25 @@
912913
pfcAdd_Now(user:loaded_into_kb(Self, Filename)),
913914
nop(listing(user:loaded_into_kb/2)).
914915

916+
917+
test_file(Filename):- test_file([], Filename).
918+
test_file(Self, Filename) :- maybe_into_top_self(Self, TopSelf), !, test_file(TopSelf, Filename).
919+
test_file(Self, Filename):-
920+
% Use without_circular_error/2 to handle circular dependencies for including files.
921+
without_circular_error(test_file1(Self, Filename),
922+
missing_exception(test_file(Self, Filename))).
923+
924+
handle_pragmas(Self,[N,V|More]):- symbol(N), !, set_option_value_interp(N,V),handle_pragmas(Self,More).
925+
handle_pragmas(Self,[H|T]):- is_list(T), !,handle_pragmas(Self,H),handle_pragmas(Self,T).
926+
handle_pragmas(_,_).
927+
928+
test_file1(Self, Filename):-
929+
if_t(is_list(Self), handle_pragmas('&self',Self)),
930+
loonit_reset,
931+
user_io(format(';=== !(test-file! ~w ~w) ===;',[Self, Filename])),
932+
include_metta1('&self', Filename),!,
933+
loonit_reset,!.
934+
915935
%! count_lines_up_to(+TwoK, +Filename, -Count) is det.
916936
%
917937
% Counts lines in a file up to a specified limit.
@@ -2077,7 +2097,7 @@
20772097
(must_det_lls(maybe_name_vars(NamedVarsList)),
20782098
(must_det_lls(do_metta(file(Filename), Mode, Self, Expr, _O)) -> true
20792099
; (ignore(rtrace(do_metta(file(Filename), Mode, Self, Expr, _O2))),
2080-
trace, epp_m(unknown_do_metta(file(Filename), Mode, Self, Expr))))))).
2100+
trace, pp_m(unknown_do_metta(file(Filename), Mode, Self, Expr))))))).
20812101

20822102

20832103
%! is_file_stream_and_size(+Stream, -Size) is nondet.
@@ -3033,12 +3053,14 @@
30333053
% calling `really_use_corelib_file/0`. It uses a dynamic flag `using_corelib_file` to track
30343054
% whether the core library has been loaded.
30353055
%
3036-
use_corelib_file :- using_corelib_file, !.
3037-
use_corelib_file :-
3056+
3057+
use_corelib_file:- use_corelib_file_now, nb_setval(debug_context, 'running').
3058+
use_corelib_file_now :- using_corelib_file, !.
3059+
use_corelib_file_now :-
30383060
% Mark core library as in use and attempt to load it.
30393061
asserta(using_corelib_file), fail.
3040-
use_corelib_file :- really_use_corelib_file, !.
3041-
use_corelib_file :- !.
3062+
use_corelib_file_now :- really_use_corelib_file, !.
3063+
use_corelib_file_now :- !.
30423064
%use_corelib_file :- really_use_corelib_file, !.
30433065

30443066
%! really_use_corelib_file is det.

prolog/metta_lang/metta_pfc_support.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@
736736
uses_call_only(H), !.
737737
clause_match(H, B, Ref) :-
738738
% Match an asserted clause for head 'H' and body 'B', retrieving 'Ref' as the clause reference.
739-
clause_asserted(H, B, Ref), !.
739+
locally_clause_asserted(H, B, Ref), !.
740740
clause_match(H, B, Ref) :-
741741
% Copy the head 'H' to a temporary variable 'HH' and check for clause matching.
742742
% Ensure that 'H' is structurally equal to 'HH' (using '=@=') and that the body is not reserved.

0 commit comments

Comments
 (0)