Skip to content

Commit 2435ff6

Browse files
committed
429 | 12 | 97% | Total for before_commit
1 parent 9dd42dc commit 2435ff6

File tree

4 files changed

+55
-31
lines changed

4 files changed

+55
-31
lines changed

mettalog

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env bash
22

3-
debug_this_script=false
3+
debug_this_script=true
44

55
generate_junit_report=0
66
ADD_COMPILE_ARG=()
@@ -903,8 +903,9 @@ function handle_args {
903903
--test=unit)
904904
handle_args "${UNIT_TESTING_OPTS}"
905905
add_to_list "--no-regen" RC_OPTIONS
906-
add_to_list "$arg" PRE_METTALOG_OPTIONS
907-
add_to_list "$arg" ADD_COMPILE_ARG
906+
#add_to_list "$arg" PRE_METTALOG_OPTIONS
907+
#add_to_list "$arg" ADD_COMPILE_ARG
908+
use_test_script=1
908909
continue
909910
;;
910911

prolog/metta_lang/metta_debug.pl

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@
659659
% By default spawned threads would need nodebug=false
660660
is_nodebug :- is_mettalog_rt, !.
661661
is_nodebug :- is_mettalog_release, !.
662-
is_nodebug :- is_user_repl, !.
662+
%is_nodebug :- is_user_repl, !.
663663
is_nodebug :- thread_self(Self), Self \== main, Self \== 0.
664664
is_nodebug :-
665665
% Check if the option 'nodebug' is set to true.
@@ -802,8 +802,8 @@
802802
is_extreme_debug(G):- is_douglas, !, call(G).
803803
is_extreme_debug(_).
804804

805-
sub_var_safely(Sub,Source):- assertion(acyclic_term(Source)),!,sub_var(Sub,Source).
806-
sub_term_safely(Sub,Source):- assertion(acyclic_term(Source)),!,sub_term(Sub,Source).
805+
sub_var_safely(Sub,Source):- woct(sub_var(Sub,Source)).
806+
sub_term_safely(Sub,Source):- woct(sub_term(Sub,Source)).
807807

808808
maybe_abort_trace:- \+ is_flag(abort_trace), !.
809809
maybe_abort_trace:- abort_trace.
@@ -1392,7 +1392,10 @@
13921392
% ?- trace_eval(my_predicate, trace_type, 1, self, input, output).
13931393
%
13941394

1395-
trace_eval(P4, _, D1, Self, X, Y) :- is_nodebug, !, call(P4, D1, Self, X, Y).
1395+
trace_eval(P4, _, D1, Self, X, Y) :-
1396+
\+ is_debugging(e),
1397+
\+ is_debugging(eval), !,
1398+
call(P4, D1, Self, X, Y).
13961399

13971400

13981401
trace_eval(P4, ReasonsToTrace, D1, Self, X, Y) :- !,
@@ -1404,7 +1407,7 @@
14041407
TraceLen is EX0 mod 500, % Calculate TraceLen modulo 500.
14051408
DR is 99 - (D1 mod 100), % Calculate DR based on depth.
14061409
PrintRet = _, % Initialize PrintRet.
1407-
option_else('trace-length', MaxTraceLen, 500), % Get trace-length option.
1410+
option_else('trace-length', MaxTraceLen, 5000), % Get trace-length option.
14081411
%option_else('trace-depth', MaxTraceDepth, 30), % Get trace-depth option.
14091412
!
14101413
)),
@@ -1413,9 +1416,10 @@
14131416

14141417
quietly((
14151418
if_t((nop(stop_rtrace), TraceLen > MaxTraceLen), (
1416-
set_debug(eval, false),
1419+
set_option_value_interp(eval, notrace),
1420+
set_option_value_interp(e, notrace),
14171421
MaxP1 is MaxTraceLen + 1,
1418-
nop(format('; Switched off tracing. For a longer trace: !(pragma! trace-length ~w)', [MaxP1])),
1422+
(format(user_error,'; Switched off tracing. For a longer trace: !(pragma! trace-length ~w)', [MaxP1])),
14191423
TraceTooLong = 1,
14201424
nop((start_rtrace, rtrace))
14211425
))
@@ -1427,7 +1431,7 @@
14271431

14281432
if_t(D1<0, (set_debug(devel,true))),
14291433

1430-
(\+ \+ if_trace((eval; ReasonsToTrace), (
1434+
( if_trace((e;eval;ReasonsToTrace), (
14311435
PrintRet = 1,
14321436
if_t( TraceTooLong \== 1, indentq(DR, TraceLen, '-->', [Why, X]))
14331437
))),
@@ -1440,7 +1444,7 @@
14401444
flag(eval_num, EX1, EX1 + 1),
14411445
PrintRet == 1,
14421446
TraceTooLong \== 1,
1443-
((Ret \=@= retval(fail), nonvar(Y))
1447+
((Ret \=@= retval(fail), nop(nonvar(Y)))
14441448
-> indentq(DR, EX1, '<--', [Why, Y])
14451449
; indentq(DR, EX1, '<--', [Why, Ret])
14461450
)
@@ -1456,7 +1460,7 @@
14561460

14571461
Ret \=@= retval(fail).
14581462

1459-
1463+
/*
14601464
trace_eval(P4, ReasonsToTrace, D1, Self, X, Y) :-
14611465
must_det_ll((
14621466
notrace((
@@ -1496,6 +1500,7 @@
14961500
(notrace(ignore((( % Y\=@=X,
14971501
if_t(DR<MaxTraceDepth,if_trace((eval;Why),one_shot(Display))))))))))),
14981502
Ret \=@= retval(fail).
1503+
*/
14991504

15001505
% (Ret\=@=retval(fail)->true;(fail,trace,(call(P4,D1,Self,X,Y)),fail)).
15011506
one_shot(Display):- ignore(once(Display)),setarg(1,Display,true).

prolog/metta_lang/metta_eval.pl

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,7 @@
267267

268268
%:- set_prolog_flag(optimise, false).
269269
%:- set_prolog_flag(access_level, system).
270-
check_term_depth(X,Y):- find_term_cycles(X), X=Y.
271-
check_term_depth(X,Y):- find_term_cycles(Y), X=Y.
270+
check_term_depth(X,Y):- fail, (find_term_cycles(X);find_term_cycles(Y)), X=Y.
272271
find_term_cycles(X):- find_term_cycles(100,X).
273272
find_term_cycles(_,X):- \+ acyclic_term_nat(X), notrace, nl,nl, writeq(X), nl,nl, break.
274273
find_term_cycles(N,X):- term_depth(X,Deep), Deep>N, notrace, nl,nl, writeq(X), nl,nl, break.
@@ -537,6 +536,11 @@
537536
((copy_term(X+Y,YC), YC = YY) -> (debug(metta(todo),'no_repeat in ~w: ~q',[ThisNth,X->Y])) ; (debug(metta(todo),'repeats in ~w: ~q',[ThisNth,X->Y]),fail))),
538537
nb_setval(previous_nths,NthL)).
539538

539+
540+
depth_overflow:- fail, notrace,ignore(nortrace),
541+
trace,dumpST,break,throw(depth_limit_exceeded).
542+
543+
maybe_bt(Why):- Why == depth, depth_overflow,fail.
540544
maybe_bt(Why):- maybe_trace(bt(Why)),!.
541545
% maybe_bt:- notrace,maybe_trace(depth),bt.
542546
/*
@@ -551,6 +555,7 @@
551555

552556
eval_10(_Eq,_RetType,_Dpth,_Self,X,_YO):- X==[empty],!,fail.
553557
eval_10(_Eq,_RetType,_Dpth,_Self,X,_YO):- X==['Empty'],!,fail.
558+
eval_10(_Eq,_RetType,_Dpth,_Self,X,Y):- X=@=['runreduction',_],!,Y=X.
554559
eval_10(_Eq,_RetType,Depth,_Self,X,Y):- overflow_depth(Depth),maybe_bt(depth),!,unify_woc(X,Y).
555560
eval_10(Eq,RetType,Depth,Self,X,Y):- var(X), !, % sanity_check_eval(eval_10_var,X),
556561
eval_20(Eq,RetType,Depth,Self,X,Y).
@@ -2711,9 +2716,19 @@
27112716
pop_scope_item(N,V):- ppp_default_value(N,V),!.
27122717

27132718

2719+
2720+
eval_10(Eq,RetType,Depth,Self,['with-pragma!',List,X],Y):- !,
2721+
setup_call_cleanup(maplist(undoable_set_pragma(Self),List,Restore),
2722+
eval_args(Eq,RetType,Depth,Self,X,Y),
2723+
maplist(set_pragma(Self),Restore)).
2724+
2725+
% @TODO so someting with Self
2726+
set_pragma(_Self,[N,V]):- set_option_value_interp(N,V),!.
2727+
undoable_set_pragma(Self,[N,V],[N,Was]):- (option_value(N,Was)->true;Was='Empty'), set_pragma(Self,[N,V]),!.
2728+
27142729
eval_20(Eq,RetType,Depth,Self,['pragma!',Other,Expr],RetVal):- !,
27152730
must_det_lls((into_name(Self,Other,Name),nd_ignore((eval_args(Eq,RetType,Depth,Self,Expr,Value),
2716-
set_option_value_interp(Name,Value))), make_nop(RetType,Value,RetVal),
2731+
set_pragma(Self,[Name,Value]))), make_nop(RetType,Value,RetVal),
27172732
check_returnval(Eq,RetType,RetVal))).
27182733
eval_20(Eq,RetType,_Dpth,Self,['transfer!',File],RetVal):- !, must((include_metta(Self,File),
27192734
make_nop(RetType,Self,RetVal),check_returnval(Eq,RetType,RetVal))).
@@ -3632,13 +3647,13 @@
36323647
maybe_non_eval(AE,Len,N,Type):- assert(arg_type_n(AE,Len,N,eval(Type))),!.
36333648

36343649

3635-
do_each_arg(_Eq, _RetType, _ResIn, _Depth, _Self, _AE, _Len, _N, [], []):-!.
3636-
do_each_arg(_Eq, _RetType, _ResIn, _Depth, _Self, _AE, Len, N, _, []) :- N > Len, !.
3650+
do_each_arg(_Eq, _RetType, _ResIn, _Depth, _Self, _AE, _Len, _N, [], Out):- !, Out=[].
3651+
do_each_arg(_Eq, _RetType, _ResIn, _Depth, _Self, _AE, Len, N, _, Out) :- N > Len, !, Out=[].
36373652
do_each_arg(Eq, RetType, ResIn, Depth, Self, AE, Len, N, [In|More], [Out|Adjusted]) :-
36383653
do_arg(Eq, RetType, ResIn, Depth, Self, AE, Len, N, In, Out), succ(N, Np1),
36393654
do_each_arg(Eq, RetType, ResIn, Depth, Self, AE, Len, Np1, More, Adjusted).
36403655

3641-
do_arg(_Eq, _RetType, _RsIn, _Dpth, _Slf, AE, Len, N, InOut, InOut) :- nonvar(AE), arg_type_n(AE, Len, N, no_eval(_)), !.
3656+
do_arg(_Eq, _RetType, _RsIn, _Dpth, _Slf, AE, Len, N, InOut, InOut) :- nonvar(AE), arg_type_n(AE, Len, N, non_eval(_)), !.
36423657
do_arg( Eq, _RetType, _RsIn, Depth, Self, _AE, _Len, _N, In, Out) :-
36433658
eval_args(Eq, _, Depth, Self, In, Out).
36443659

@@ -4126,7 +4141,7 @@
41264141
BL\==[],!,
41274142
must_or_die((
41284143
member(H->B0,BL),%nl,
4129-
print_templates(Depth,HC,rule(H,B0,_Nth,_Types)),
4144+
if_trace((e;eval;defn),print_templates(Depth,HC,rule(H,B0,_Nth,_Types))),
41304145
eval_args(Eq,RetType,Depth,Self,B0,BO))).
41314146

41324147

@@ -4158,9 +4173,9 @@
41584173
variable_count(B0,Bc1),variable_count(XX,Xc1),
41594174
if_trace(e,color_g_mesg('#773700',indentq2(Depth,defs_used(XX-->B0,def(USED))))),
41604175
if_trace(e,color_g_mesg('#993700',indentq2(Depth,variable_count(xc0=Xc0,wc1=Xc1,bc0=Bc0,bc1=Bc1)))),
4161-
if_trace(e,((
4176+
nop((if_trace(e,((
41624177
ignore(show_tf((Bc0*2>=Bc1))),
4163-
ignore(show_tf((Xc0==Bc1)))))),
4178+
ignore(show_tf((Xc0==Bc1)))))))),
41644179
if_trace(occurs,((ignore(find_term_cycles(300,X))))),
41654180
maybe_trace(eval_defn_success).
41664181
/*
@@ -4297,20 +4312,24 @@
42974312

42984313

42994314

4300-
eval_30(Eq,RetType,Depth,Self,X,Y):- \+ old_sys, !, must_or_die((mapl_eval_args(Eq,RetType,Depth,Self,X,Y))).
4301-
eval_30(Eq,RetType,Depth,Self,X,Y):-
4302-
subst_args_here(Eq,RetType,Depth,Self,X,Y).
4303-
4315+
%eval_30(Eq,RetType,Depth,Self,X,Y):- \+ old_sys, !, must_or_die((mapl_eval_args(Eq,RetType,Depth,Self,X,Y))).
4316+
%eval_30(Eq,RetType,Depth,Self,X,Y):- subst_args_here(Eq,RetType,Depth,Self,X,Y).
4317+
eval_30(_Eq,_RetType,_Depth,_Self,X,Y):- unify_woc(X,Y).
43044318

43054319
% functs_to_preds([Eq, H, B], Preds)
43064320
eval_40_disabled(_Eq,_RetType,_Dpth,_Slf,[H|PredDecl],Res):- fail,
43074321
is_rust_operation([H|PredDecl]),!, % run
43084322
must_det_ll((rust_metta_run(exec([H|PredDecl]),Res),
43094323
nop(write_src(res(Res))))).
43104324

4311-
eval_40(Eq,RetType,Depth,Self,X,Y):- \+ old_sys, !, mapl_eval_args(Eq,RetType,Depth,Self,X,Y).
4325+
eval_40(Eq,_RetType,Depth,Self,[AIn|More],[AE|More]):- nonvar(AE),!,
4326+
(eval_args(Eq, _, Depth, Self, AIn, AE) *-> true ; AIn=AE).
4327+
4328+
eval_40(_Eq,_RetType,_Depth,_Self,X,Y):- unify_woc(X,Y).
4329+
4330+
eval_40_disabled(Eq,RetType,Depth,Self,X,Y):- \+ old_sys, !, mapl_eval_args(Eq,RetType,Depth,Self,X,Y).
43124331

4313-
eval_40(Eq,RetType,Depth,Self,[H|PredDecl],Res):-
4332+
eval_40_disabled(Eq,RetType,Depth,Self,[H|PredDecl],Res):-
43144333
eval_args(Eq,_,Depth,Self,H,HH),
43154334
% maybe_eval_subst ?
43164335
subst_args_here(Eq,RetType,Depth,Self,[HH|PredDecl],Res).

prolog/metta_lang/metta_interp.pl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,6 @@
15671567

15681568
on_set_value(_Note,noninteractive,true):- nocut, ignore(noninteractive),!.
15691569
on_set_value(_Note,abort_trace,true):- nocut, ignore(abort_trace),!.
1570-
on_set_value(_Note,abolish_trace,true):- nocut, ignore(abolish_trace),!.
15711570

15721571
on_set_value(_Note,show, Value):-
15731572
if_t( \+ prolog_debug:debugging(filter_default,_,_), set_debug(default,false)),
@@ -4152,7 +4151,7 @@
41524151

41534152
% load_hook1(_Load, '&corelib', _Eq, _H, _B) :- !.
41544153

4155-
load_hook1(_Load, Self, [Eq,H,B]) :-
4154+
load_hook1(_Load, Self, [Eq,H,B]) :-
41564155
Eq == '=', assertz_if_new(metta_function_asserted(Self,H,B)),fail.
41574156

41584157

@@ -4460,7 +4459,7 @@
44604459
dont_bother(Atom):- Atom = [V1, [Colon, Thing, V2], V3], Colon==':', nonvar(Thing),maplist(var,[V1,V2,V3]).
44614460

44624461
metta_atom_added(_KB, Atom) :- dont_bother(Atom),!,fail.
4463-
metta_atom_added(X, [Eq,A,B]) :- Eq =='=', !,
4462+
metta_atom_added(X, [Eq,A,B]) :- Eq =='=', !,
44644463
woct(metta_function_asserted(X,A,B)).
44654464

44664465
metta_atom_added(X, Y) :- nocut,

0 commit comments

Comments
 (0)