Skip to content

Commit 3e918ca

Browse files
committed
metta_lang_interp_72_4 on Nils AI-DSL
1 parent 323e816 commit 3e918ca

16 files changed

+1605
-2322
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11

2-
; The contents of this file are evaluated for each new runner in the runner's top context
2+
; TODO: Let the "importPaths" be modifiable, but I want better string manipulation atoms

prolog/metta_lang/metta_compiler.pl

Lines changed: 11 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,8 @@
7474
:- ensure_loaded(metta_space).
7575
:- ensure_loaded(metta_compiler_print).
7676
:- dynamic(transpiler_clause_store/9).
77-
:- multifile(transpiler_predicate_store/7).
7877
:- dynamic(transpiler_predicate_store/7).
79-
:- dynamic(transpiler_predicate_nary_store/9).
80-
:- discontiguous transpiler_predicate_nary_store/9.
8178
:- discontiguous(compile_flow_control/8).
82-
:- multifile(compile_flow_control/8).
8379
:- ensure_loaded(metta_compiler_lib).
8480
:- ensure_loaded(metta_compiler_lib_stdlib).
8581

@@ -216,7 +212,6 @@
216212
as_p1_exec(ispeEnNC(ERet,ECode,_,_,CCode),ERet) :- !, call(CCode),call(ECode).
217213
as_p1_exec(X,X) :- !.
218214

219-
220215
as_p1_expr(ispu(URet),URet) :- !.
221216
as_p1_expr(ispuU(URet,UCode),URet) :- !, call(UCode).
222217
as_p1_expr(ispeEn(_,_,NRet),NRet).
@@ -357,7 +352,7 @@
357352
invert_curried_structure(F,LenArgs,ArgsFirst,Result).
358353

359354

360-
recompile_from_depends(FnName,LenArgs) :- skip_redef_fa(FnName,LenArgs),!,debug_info(recompile_code_from_depends,skip_redef_fa(FnName,LenArgs)),!.
355+
recompile_from_depends(FnName,LenArgs) :- skip_redef_fa(FnName,LenArgs),!,debug_info(recompile_from_depends,skip_redef_fa(FnName,LenArgs)),!.
361356
recompile_from_depends(FnName,LenArgs) :-
362357
transpiler_debug(2,(format_e("recompile_from_depends ~w/~w\n",[FnName,LenArgs]))),
363358
%LenArgs is LenArgsPlus1-1,
@@ -773,11 +768,6 @@
773768
f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, T, Converted, ConvertedN) :- compound(T),T=exec(X),!,
774769
f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, [eval,X], Converted, ConvertedN).
775770

776-
f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, Convert, Converted, ConvertedN) :- fail,
777-
atom(Convert), nb_bound(Convert,_),!, % TODO might need to look this up at evaluation time instead
778-
atom_string(Convert,SConvert),
779-
f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, ['eval-string',SConvert], Converted, ConvertedN),!.
780-
781771
f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, Convert, Converted, ConvertedN) :-
782772
nb_bound(Convert,X),!, % TODO might need to look this up at evaluation time instead
783773
f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, X, Converted, ConvertedN).
@@ -827,8 +817,7 @@
827817
828818
% If Convert is a number or an atomic, it is considered as already converted.
829819
f2p(_HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- % HeadIs\=@=Convert,
830-
once(number(Convert); atom(Convert); atomic(Convert) %; data_term(Convert)
831-
), % Check if Convert is a number or an atom
820+
once(number(Convert); atom(Convert); atomic(Convert) /*; data_term(Convert)*/ ), % Check if Convert is a number or an atom
832821
(ResultLazy=x(_,eager,_) -> C2=Convert ; C2=[ispu,Convert]),
833822
Converted=[[assign,RetResult,C2]],
834823
% For OVER-REACHING categorization of dataobjs %
@@ -1730,7 +1719,6 @@
17301719
%must_det_lls(G):- rtrace(G),!.
17311720
%user:numbervars(Term):- varnumbers:numbervars(Term).
17321721

1733-
must_det_lls(G):- is_nodebug,!,call(G). % is_mettalog_rt or is_user_repl
17341722
must_det_lls(G):- tracing,!,call(G). % already tracing
17351723
must_det_lls((A,B)):- !, must_det_lls(A),must_det_lls(B).
17361724
%must_det_lls(G):- call(G). % already tracing
@@ -1742,7 +1730,6 @@
17421730
must_det_lls(G):- ignore((notrace,nortrace,trace_break(must_det_lls(G)))),rtrace(G),!.
17431731

17441732
extract_constraints(V,VS):- var(V),get_attr(V,cns,_Self=Set),!,extract_constraints(_Name,Set,VS),!.
1745-
extract_constraints(V,VS):- var(V),VS=[],!.
17461733
extract_constraints(V,VS):- var(V),!,ignore(get_types_of(V,Types)),extract_constraints(V,Types,VS),!.
17471734
extract_constraints(Converted,VSS):- term_variables(Converted,Vars),
17481735
% assign_vns(0,Vars,_),
@@ -2117,15 +2104,15 @@
21172104
remove_stub(Space,Fn,Arity):- retract(transpiler_stub_created(Space,Fn,Arity)),!,
21182105
transpile_impl_prefix(Fn,Arity,IFn),abolish(IFn/Arity),!.
21192106

2120-
% !(listing!! cdr-atom)
2121-
transpiler_predicate_store(builtin, 'listing!', [1], [], '', [x(doeval,eager,[])], x(doeval,eager,[])).
2122-
'mc__1_1_listing!'(S,RetVal):-
2107+
% !(compiled-info! cdr-atom)
2108+
transpiler_predicate_store(builtin, 'compiled-info', [1], [], '', [x(doeval,eager,[])], x(doeval,eager,[])).
2109+
'mc__1_1_compiled-info'(S,RetVal):-
21232110
find_compiled_refs(S, Refs),
2124-
locally(nb_setval(focal_symbol,S),print_refs(Refs)),!,
2111+
print_refs(Refs),!,
21252112
length(Refs,RetVal).
21262113

21272114
'compiled_info'(S):-
2128-
'mc__1_1_listing!'(S,_RetVal).
2115+
'mc__1_1_compiled-info'(S,_RetVal).
21292116

21302117
print_refs(Refs):- is_list(Refs),!,maplist(print_refs,Refs).
21312118
print_refs(Refs):- atomic(Refs),clause(M:H,B,Refs),!,print_itree(((M:H):-B)).
@@ -2138,13 +2125,8 @@
21382125

21392126
nl_print_tree(PT):-
21402127
stream_property(Err, file_no(2)),
2141-
mesg_color(PT, Color),
2142-
maybe_subcolor(PT,CPT),
2143-
with_output_to(Err,(format('~N'),ansicall(Color,ppt(CPT)),format('~N'))).
2128+
with_output_to(Err,(format('~N'),ppt(PT),format('~N'))).
21442129

2145-
maybe_subcolor(PT,CPT):- fail, nb_current(focal_symbol,S), mesg_color(PT, Color), wots(Str,ansicall(Color,ppt1(S))),
2146-
subst001(PT,S,Str,CPT),!.
2147-
maybe_subcolor(PT,PT).
21482130

21492131
find_compiled_refs(S, Refs):-
21502132
atom_concat('_',S,Dashed),
@@ -2162,17 +2144,9 @@
21622144
\+ \+ predicate_property(M:P,_), \+ predicate_property(M:P,imported_from(_)),
21632145
clause(M:P,_,Ref)),Refs).
21642146

2165-
compiled_refs(Symbol,F,A,Info):- functor(P,F,A),clause(P,B,Ref), (\+ compiler_data_no_call(F/A) -> call(B)), symbol_in(2,Symbol,P),
2147+
compiled_refs(Symbol,F,A,Info):- functor(P,F,A),clause(P,B,Ref),call(B), \+ \+ (arg(_,P,S),S==Symbol),
21662148
(B==true->Info=Ref;Info=P).
21672149

2168-
2169-
symbol_in(_, Symbol, P):-Symbol=@=P,!.
2170-
symbol_in(N, Symbol, P):- N>0, compound(P), N2 is N-1, symbol_in_sub(N2, Symbol, P).
2171-
symbol_in_sub(N, Symbol, P):- is_list(P),P=[S1,S2,_|_],!,symbol_in_sub(N, Symbol, [S1,S2]).
2172-
symbol_in_sub(N, Symbol, P):- is_list(P),!,member(S,P),symbol_in(N, Symbol, S).
2173-
symbol_in_sub(N, Symbol, P):- arg(_,P,S),symbol_in(N, Symbol, S).
2174-
2175-
21762150
compiler_data(metta_compiled_predicate/3).
21772151
compiler_data(is_transpile_call_prefix/3).
21782152
compiler_data(is_transpile_impl_prefix/3).
@@ -2185,11 +2159,6 @@
21852159
compiler_data(metta_atom/2).
21862160
compiler_data(metta_type/3).
21872161
compiler_data(metta_defn/3).
2188-
compiler_data(eval_20/6).
2189-
compiler_data_no_call(eval_20/6).
2190-
2191-
%compiler_data(metta_atom_asserted/2).
2192-
21932162
%compiler_data(metta_file_buffer/7).
21942163

21952164
ensure_callee_site(Space,Fn,Arity):- check_supporting_predicates(Space,Fn/Arity),!.
@@ -2315,9 +2284,7 @@
23152284
stream_property(Err, file_no(2)),
23162285
current_output(Cur), Cur\=@=Err,!,
23172286
with_output_to(Err, trace_break(G)).
2318-
trace_break(G):- notrace, nl, writeq(call(G)),nl,nl, current_prolog_flag(noninteractive,true), format('~nTRACE_BREAK_CALLED~n',[]),
2319-
once(bt), writeq(call(G)),throw('aborted').
2320-
trace_break(G):- notrace,nl, writeq(call(G)),nl,nl,format('~nTRACE_BREAK_CALLED~n',[]), nl, trace, \+ current_prolog_flag(noninteractive,true), break.
2287+
trace_break(G):- nl, writeq(call(G)), trace,break.
23212288
% :- set_prolog_flag(gc,false).
23222289

23232290
:- if(debugging(metta(compiler_bugs))).
@@ -2327,7 +2294,6 @@
23272294
call_fr(G,Result,FA):- current_predicate(FA),!,call(G,Result).
23282295
call_fr(G,Result,_):- Result=G.
23292296

2330-
transpile_eval(Convert,Converted) :- nb_current('eval_in_only', interp),!, eval(Convert,Converted).
23312297
transpile_eval(Convert,Converted) :-
23322298
transpile_eval(Convert,Converted,PrologCode),!,
23332299
call(PrologCode).
@@ -2339,15 +2305,13 @@
23392305
% PrologCode=PrologCode0,
23402306
% LiConverted=Converted0
23412307
%;
2342-
metta_to_metta_body_macro_recurse('transpile_eval',Convert,ConvertMacr),
2343-
f2p(null,[],Converted,_,LE,ConvertMacr,Code1,_),
2308+
f2p(null,[],Converted,_,LE,Convert,Code1,_),
23442309
lazy_impedance_match(LE,x(doeval,eager,_),Converted,Code1,Converted,Code1,LiConverted,Code),
23452310
ast_to_prolog(no_caller,[],Code,PrologCode),
23462311
compiler_assertz(transpiler_stored_eval(Convert,PrologCode,LiConverted))
23472312
%)
23482313
.
23492314

2350-
transpile_eval_nocache(Convert,Converted,true) :- nb_current('eval_in_only', interp),!, eval(Convert,Converted).
23512315
transpile_eval_nocache(Convert0,LiConverted,PrologCode) :-
23522316
%leash(-all),trace,
23532317
subst_varnames(Convert0,Convert),
@@ -4080,4 +4044,3 @@
40804044

40814045

40824046

4083-

0 commit comments

Comments
 (0)