|
74 | 74 | :- ensure_loaded(metta_space). |
75 | 75 | :- ensure_loaded(metta_compiler_print). |
76 | 76 | :- dynamic(transpiler_clause_store/9). |
77 | | -:- multifile(transpiler_predicate_store/7). |
78 | 77 | :- dynamic(transpiler_predicate_store/7). |
79 | | -:- dynamic(transpiler_predicate_nary_store/9). |
80 | | -:- discontiguous transpiler_predicate_nary_store/9. |
81 | 78 | :- discontiguous(compile_flow_control/8). |
82 | | -:- multifile(compile_flow_control/8). |
83 | 79 | :- ensure_loaded(metta_compiler_lib). |
84 | 80 | :- ensure_loaded(metta_compiler_lib_stdlib). |
85 | 81 |
|
|
216 | 212 | as_p1_exec(ispeEnNC(ERet,ECode,_,_,CCode),ERet) :- !, call(CCode),call(ECode). |
217 | 213 | as_p1_exec(X,X) :- !. |
218 | 214 |
|
219 | | - |
220 | 215 | as_p1_expr(ispu(URet),URet) :- !. |
221 | 216 | as_p1_expr(ispuU(URet,UCode),URet) :- !, call(UCode). |
222 | 217 | as_p1_expr(ispeEn(_,_,NRet),NRet). |
|
357 | 352 | invert_curried_structure(F,LenArgs,ArgsFirst,Result). |
358 | 353 |
|
359 | 354 |
|
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)),!. |
361 | 356 | recompile_from_depends(FnName,LenArgs) :- |
362 | 357 | transpiler_debug(2,(format_e("recompile_from_depends ~w/~w\n",[FnName,LenArgs]))), |
363 | 358 | %LenArgs is LenArgsPlus1-1, |
|
773 | 768 | f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, T, Converted, ConvertedN) :- compound(T),T=exec(X),!, |
774 | 769 | f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, [eval,X], Converted, ConvertedN). |
775 | 770 |
|
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 | | - |
781 | 771 | f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, Convert, Converted, ConvertedN) :- |
782 | 772 | nb_bound(Convert,X),!, % TODO might need to look this up at evaluation time instead |
783 | 773 | f2p(HeadIs, LazyVars, RetResult, RetResultN, ResultLazy, X, Converted, ConvertedN). |
|
827 | 817 |
|
828 | 818 | % If Convert is a number or an atomic, it is considered as already converted. |
829 | 819 | 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 |
832 | 821 | (ResultLazy=x(_,eager,_) -> C2=Convert ; C2=[ispu,Convert]), |
833 | 822 | Converted=[[assign,RetResult,C2]], |
834 | 823 | % For OVER-REACHING categorization of dataobjs % |
|
1730 | 1719 | %must_det_lls(G):- rtrace(G),!. |
1731 | 1720 | %user:numbervars(Term):- varnumbers:numbervars(Term). |
1732 | 1721 |
|
1733 | | -must_det_lls(G):- is_nodebug,!,call(G). % is_mettalog_rt or is_user_repl |
1734 | 1722 | must_det_lls(G):- tracing,!,call(G). % already tracing |
1735 | 1723 | must_det_lls((A,B)):- !, must_det_lls(A),must_det_lls(B). |
1736 | 1724 | %must_det_lls(G):- call(G). % already tracing |
|
1742 | 1730 | must_det_lls(G):- ignore((notrace,nortrace,trace_break(must_det_lls(G)))),rtrace(G),!. |
1743 | 1731 |
|
1744 | 1732 | 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=[],!. |
1746 | 1733 | extract_constraints(V,VS):- var(V),!,ignore(get_types_of(V,Types)),extract_constraints(V,Types,VS),!. |
1747 | 1734 | extract_constraints(Converted,VSS):- term_variables(Converted,Vars), |
1748 | 1735 | % assign_vns(0,Vars,_), |
|
2117 | 2104 | remove_stub(Space,Fn,Arity):- retract(transpiler_stub_created(Space,Fn,Arity)),!, |
2118 | 2105 | transpile_impl_prefix(Fn,Arity,IFn),abolish(IFn/Arity),!. |
2119 | 2106 |
|
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):- |
2123 | 2110 | find_compiled_refs(S, Refs), |
2124 | | - locally(nb_setval(focal_symbol,S),print_refs(Refs)),!, |
| 2111 | + print_refs(Refs),!, |
2125 | 2112 | length(Refs,RetVal). |
2126 | 2113 |
|
2127 | 2114 | 'compiled_info'(S):- |
2128 | | - 'mc__1_1_listing!'(S,_RetVal). |
| 2115 | + 'mc__1_1_compiled-info'(S,_RetVal). |
2129 | 2116 |
|
2130 | 2117 | print_refs(Refs):- is_list(Refs),!,maplist(print_refs,Refs). |
2131 | 2118 | print_refs(Refs):- atomic(Refs),clause(M:H,B,Refs),!,print_itree(((M:H):-B)). |
|
2138 | 2125 |
|
2139 | 2126 | nl_print_tree(PT):- |
2140 | 2127 | 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'))). |
2144 | 2129 |
|
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). |
2148 | 2130 |
|
2149 | 2131 | find_compiled_refs(S, Refs):- |
2150 | 2132 | atom_concat('_',S,Dashed), |
|
2162 | 2144 | \+ \+ predicate_property(M:P,_), \+ predicate_property(M:P,imported_from(_)), |
2163 | 2145 | clause(M:P,_,Ref)),Refs). |
2164 | 2146 |
|
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), |
2166 | 2148 | (B==true->Info=Ref;Info=P). |
2167 | 2149 |
|
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 | | - |
2176 | 2150 | compiler_data(metta_compiled_predicate/3). |
2177 | 2151 | compiler_data(is_transpile_call_prefix/3). |
2178 | 2152 | compiler_data(is_transpile_impl_prefix/3). |
|
2185 | 2159 | compiler_data(metta_atom/2). |
2186 | 2160 | compiler_data(metta_type/3). |
2187 | 2161 | 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 | | - |
2193 | 2162 | %compiler_data(metta_file_buffer/7). |
2194 | 2163 |
|
2195 | 2164 | ensure_callee_site(Space,Fn,Arity):- check_supporting_predicates(Space,Fn/Arity),!. |
|
2315 | 2284 | stream_property(Err, file_no(2)), |
2316 | 2285 | current_output(Cur), Cur\=@=Err,!, |
2317 | 2286 | 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. |
2321 | 2288 | % :- set_prolog_flag(gc,false). |
2322 | 2289 |
|
2323 | 2290 | :- if(debugging(metta(compiler_bugs))). |
|
2327 | 2294 | call_fr(G,Result,FA):- current_predicate(FA),!,call(G,Result). |
2328 | 2295 | call_fr(G,Result,_):- Result=G. |
2329 | 2296 |
|
2330 | | -transpile_eval(Convert,Converted) :- nb_current('eval_in_only', interp),!, eval(Convert,Converted). |
2331 | 2297 | transpile_eval(Convert,Converted) :- |
2332 | 2298 | transpile_eval(Convert,Converted,PrologCode),!, |
2333 | 2299 | call(PrologCode). |
|
2339 | 2305 | % PrologCode=PrologCode0, |
2340 | 2306 | % LiConverted=Converted0 |
2341 | 2307 | %; |
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,_), |
2344 | 2309 | lazy_impedance_match(LE,x(doeval,eager,_),Converted,Code1,Converted,Code1,LiConverted,Code), |
2345 | 2310 | ast_to_prolog(no_caller,[],Code,PrologCode), |
2346 | 2311 | compiler_assertz(transpiler_stored_eval(Convert,PrologCode,LiConverted)) |
2347 | 2312 | %) |
2348 | 2313 | . |
2349 | 2314 |
|
2350 | | -transpile_eval_nocache(Convert,Converted,true) :- nb_current('eval_in_only', interp),!, eval(Convert,Converted). |
2351 | 2315 | transpile_eval_nocache(Convert0,LiConverted,PrologCode) :- |
2352 | 2316 | %leash(-all),trace, |
2353 | 2317 | subst_varnames(Convert0,Convert), |
|
4080 | 4044 |
|
4081 | 4045 |
|
4082 | 4046 |
|
4083 | | - |
0 commit comments