diff --git a/.Attic/metta_lang/metta_eval.pl b/.Attic/metta_lang/metta_eval.pl index 37acd3a329a..2ece7483e4a 100755 --- a/.Attic/metta_lang/metta_eval.pl +++ b/.Attic/metta_lang/metta_eval.pl @@ -560,7 +560,9 @@ with_output_to(S,(format('~N'), write_src(AA),format('~N'))))). eval_20(Eq,RetType,Depth,Self,['trace',Cond],Res):- !, with_debug(eval_args,eval_args(Eq,RetType,Depth,Self,Cond,Res)). eval_20(Eq,RetType,Depth,Self,['profile!',Cond],Res):- !, time_eval(profile(Cond),profile(eval_args(Eq,RetType,Depth,Self,Cond,Res))). -eval_20(Eq,RetType,Depth,Self,['time!',Cond],Res):- !, time_eval(eval_args(Cond),eval_args(Eq,RetType,Depth,Self,Cond,Res)). +eval_20(Eq,RetType,Depth,Self,['cpu-time',Cond],Res):- !, ctime_eval(eval_args(Cond),eval_args(Eq,RetType,Depth,Self,Cond,Res)). +eval_20(Eq,RetType,Depth,Self,['wall-time',Cond],Res):- !, wtime_eval(eval_args(Cond),eval_args(Eq,RetType,Depth,Self,Cond,Res)). +eval_20(Eq,RetType,Depth,Self,['time',Cond],Res):- !, wtime_eval(eval_args(Cond),eval_args(Eq,RetType,Depth,Self,Cond,Res)). eval_20(Eq,RetType,Depth,Self,['print',Cond],Res):- !, eval_args(Eq,RetType,Depth,Self,Cond,Res),format('~N'),print(Res),format('~N'). % !(print! $1) eval_20(Eq,RetType,Depth,Self,['princ!'|Cond],Res):- !, @@ -573,13 +575,14 @@ maplist(println_impl,Out), make_nop(RetType,[],Res),check_returnval(Eq,RetType,Res). -println_impl(X):- format("~N~@~N",[write_sln(X)]),!. -println_impl(X):- user_io((ansi_format(fg('#c7ea46'),"~N~@~N",[write_sln(X)]))). +println_impl(X):- format("~N~@~N",[write_sln(X)]),!,flush_output. +%println_impl(X):- user_io((ansi_format(fg('#c7ea46'),"~N~@~N",[write_sln(X)]))),flush_output. +%println_impl(X):- ((ansi_format(fg('#c7ea46'),"~N~@~N",[write_sln(X)]))),flush_output. -princ_impl(X):- format("~@",[write_sln(X)]),!. +princ_impl(X):- format("~@",[write_sln(X)]),!,flush_output. -write_sln(X):- string(X), !, write(X). -write_sln(X):- write_src_woi(X). +write_sln(X):- string(X), !, write(X),flush_output. +write_sln(X):- write_src_woi(X),flush_output. with_output_to_str( Sxx , Goal ):- wots( Sxx , Goal ). @@ -2596,8 +2599,22 @@ cwdl(DL,Goal):- call_with_depth_limit(Goal,DL,R), (R==depth_limit_exceeded->(!,fail);true). -cwtl(DL,Goal):- catch(call_with_time_limit(DL,Goal),time_limit_exceeded(_),fail). +%cwtl(DL,Goal):- catch(call_with_time_limit(DL,Goal),time_limit_exceeded,fail). +cwtl(Time, Goal) :- + Time>0, + !, + setup_call_cleanup(alarm(Time, + throw(time_limit_exceeded), + Id, + [install(false)]), + cwtl_goal(Id, Goal), + time:remove_alarm_notrace(Id)). + +cwtl_goal(AlarmID, Goal) :- + install_alarm(AlarmID), + call(Goal). + %findall_eval(Eq,RetType,Depth,Self,X,L):- findall_eval(Eq,RetType,_RT,Depth,Self,X,L). %findall_eval(Eq,RetType,Depth,Self,X,S):- findall(E,eval_ne(Eq,RetType,Depth,Self,X,E),S)*->true;S=[]. diff --git a/.Attic/metta_lang/metta_interp.pl b/.Attic/metta_lang/metta_interp.pl index e485a0a2a73..e300f65eb0a 100755 --- a/.Attic/metta_lang/metta_interp.pl +++ b/.Attic/metta_lang/metta_interp.pl @@ -458,7 +458,7 @@ null_io(G):- null_user_output(Out), !, with_output_to(Out,G). -user_io(G):- original_user_output(Out), !, with_output_to(Out,G). +user_io(G):- original_user_output(Out), ttyflush, !, with_output_to(Out,G), flush_output(Out), ttyflush. user_err(G):- original_user_error(Out), !, with_output_to(Out,G). with_output_to_s(Out,G):- current_output(COut), redo_call_cleanup(set_prolog_IO(user_input, Out,user_error), G, @@ -1415,9 +1415,9 @@ give_up(Why),pp_m(red,gave_up(Why)))),!. -o_s(['assertEqual'|O],S):- o_s(O,S). -o_s(['assertEqualToResult'|O],S):- o_s(O,S). -o_s([O|_],S):- !, o_s(O,S). +o_s(['assertEqual'|O],S):- nonvar(O), o_s(O,S). +o_s(['assertEqualToResult'|O],S):- nonvar(O), o_s(O,S). +o_s([O|_],S):- nonvar(O), !, o_s(O,S). o_s(S,S). into_simple_op(Load,[Op|O],op(Load,Op,S)):- o_s(O,S),!. @@ -1552,12 +1552,21 @@ % ; Evaluation took 123.45 ms. % ; Evaluation took 0.012 ms. (12.33 microseconds) % -time_eval(Goal):- - time_eval('Evaluation',Goal). +time_eval(Goal):- time_eval('Evaluation',Goal). time_eval(What,Goal) :- timed_call(Goal,Seconds), give_time(What,Seconds). +ctime_eval(Goal):- ctime_eval('Evaluation',Goal). +ctime_eval(What,Goal) :- + ctimed_call(Goal,Seconds), + give_time(What,Seconds). + +wtime_eval(Goal):- wtime_eval('Evaluation',Goal). +wtime_eval(What,Goal) :- + wtimed_call(Goal,Seconds), + give_time(What,Seconds). + %give_time(_What,_Seconds):- is_compatio,!. give_time(What,Seconds):- Milliseconds is Seconds * 1_000, @@ -1568,12 +1577,21 @@ ;( Micro is Milliseconds * 1_000, format('~N; ~w took ~6f secs. (~2f microseconds) ~n~n', [What, Seconds, Micro])))). -timed_call(Goal,Seconds):- +timed_call(Goal,Seconds):- ctimed_call(Goal,Seconds). + +ctimed_call(Goal,Seconds):- statistics(cputime, Start), ( \+ rtrace_this(Goal)->rtrace_on_error(Goal);rtrace(Goal)), statistics(cputime, End), Seconds is End - Start. +wtimed_call(Goal,Seconds):- + statistics(walltime, [Start,_]), + ( \+ rtrace_this(Goal)->rtrace_on_error(Goal);rtrace(Goal)), + statistics(walltime, [End,_]), + Seconds is (End - Start)/1000. + + rtrace_this(eval_H(_, _, P , _)):- compound(P), !, rtrace_this(P). rtrace_this([P|_]):- P == 'pragma!',!,fail. rtrace_this([P|_]):- P == 'import!',!,fail.