|
1053 | 1053 |
|
1054 | 1054 | % !(compile-for-assert (plus1 $x) (+ 1 $x) )
|
1055 | 1055 | compile_for_assert(HeadIs, AsBodyFn, Converted) :-
|
| 1056 | + must_det_lls(( |
| 1057 | + current_self(Space), |
| 1058 | + %subst_varnames(HeadIsIn+AsBodyFnIn,HeadIs+AsBodyFn), |
1056 | 1059 | %leash(-all),trace,
|
1057 | 1060 | HeadIs=[FnName|Args],
|
1058 | 1061 | length(Args,LenArgs),
|
1059 | 1062 | LenArgsPlus1 is LenArgs+1,
|
| 1063 | + atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix), |
1060 | 1064 | % retract any stubs
|
1061 | 1065 | (transpiler_stub_created(FnName/LenArgsPlus1) ->
|
1062 | 1066 | retract(transpiler_stub_created(FnName/LenArgsPlus1)),
|
1063 |
| - atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix), |
1064 | 1067 | findall(Atom0, (between(1, LenArgsPlus1, I0) ,Atom0='$VAR'(I0)), AtomList0),
|
1065 | 1068 | H=..[FnNameWPrefix|AtomList0],
|
1066 | 1069 | (transpiler_show_debug_messages -> format("Retracting stub: ~q\n",[H]) ; true),
|
|
1089 | 1092 | compiler_assertz(transpiler_clause_store(FnName,LenArgsPlus1,ClauseId,Types0,RetType0,FinalLazyArgs,FinalLazyRet,HeadIs,AsBodyFn)),
|
1090 | 1093 | maplist(arrange_lazy_args,Args,FinalLazyArgs,LazyArgsList),
|
1091 | 1094 | get_property_lazy(FinalLazyRet,FinalLazyOnlyRet),
|
| 1095 | + |
| 1096 | + %precompute_typeinfo(HResult,HeadIs,AsBodyFn,Ast,TypeInfo), |
| 1097 | + |
| 1098 | + OldExpr = [defn,HeadIs,AsBodyFn], |
| 1099 | + |
| 1100 | + combine_transform_and_collect(OldExpr, Assignments, _NewExpr, VarMappings), |
| 1101 | + |
| 1102 | + %writeln("=== Original Expression ==="), print_ast(OldExpr), |
| 1103 | + %writeln("=== Assignments (subcalls replaced) ==="), print_ast(Assignments), |
| 1104 | + %writeln("=== New Expression ==="), print_ast(NewExpr), |
| 1105 | + writeln("=== Assignments / Var Mappings (underscore variables) ==="), |
| 1106 | + append(Assignments,VarMappings,SM),sort(SM,S), |
| 1107 | + group_pair_by_key(S,SK), |
| 1108 | + print_ast(magenta, SK), |
| 1109 | + |
| 1110 | + |
| 1111 | + %output_prolog(magenta,TypeInfo), |
| 1112 | + %print_ast( green, Ast), |
| 1113 | + |
1092 | 1114 | f2p(HeadIs,LazyArgsList,HResult,FinalLazyOnlyRet,AsBodyFn,NextBody),
|
1093 | 1115 |
|
1094 | 1116 |
|
|
1117 | 1139 | %format("###########2 ~q",[Converted]),
|
1118 | 1140 | output_language(prolog, (print_pl_source(Converted))),
|
1119 | 1141 | true
|
1120 |
| - )). |
| 1142 | + )))). |
| 1143 | + |
| 1144 | + |
1121 | 1145 |
|
1122 | 1146 | no_conflict_numbervars(Term):-
|
1123 | 1147 | findall(N,(sub_term(E,Term),compound(E), '$VAR'(N)=E, integer(N)),NL),!,
|
|
1328 | 1352 | maplist(ast_to_prolog_aux(Caller,DontStub),Args0,Args1),
|
1329 | 1353 | length(Args0,LArgs),
|
1330 | 1354 | atomic_list_concat(['mc_',LArgs,'__',F],Fp),
|
| 1355 | + label_arg_types(F,0,[A|Args1]), |
1331 | 1356 | LArgs1 is LArgs+1,
|
1332 | 1357 | append(Args1,[A],Args2),
|
1333 | 1358 | R=..[Fp|Args2],
|
|
1338 | 1363 | ((current_predicate(Fp/LArgs1);member(F/LArgs1,DontStub)) ->
|
1339 | 1364 | true
|
1340 | 1365 | ; check_supporting_predicates('&self',F/LArgs1)).
|
1341 |
| -ast_to_prolog_aux(Caller,DontStub,[assign,A,X0],(A=X1)) :- ast_to_prolog_aux(Caller,DontStub,X0,X1),!. |
| 1366 | +ast_to_prolog_aux(Caller,DontStub,[assign,A,X0],(A=X1)) :- must_det_lls(label_type_assignment(A,X0)), ast_to_prolog_aux(Caller,DontStub,X0,X1),label_type_assignment(A,X1),!. |
1342 | 1367 | ast_to_prolog_aux(Caller,DontStub,[prolog_match,A,X0],(A=X1)) :- ast_to_prolog_aux(Caller,DontStub,X0,X1),!.
|
| 1368 | + |
| 1369 | +ast_to_prolog_aux(Caller,DontStub,[prolog_catch,Catch,Ex,Catcher],R) :- ast_to_prolog(Caller,DontStub,Catch,Catch2), R= catch(Catch2,Ex,Catcher). |
| 1370 | +ast_to_prolog_aux(_Caller,_DontStub,[prolog_inline,Prolog],R) :- !, R= Prolog. |
| 1371 | +ast_to_prolog_aux(Caller, DontStub, if_or_else(If,Else),R):- |
| 1372 | + ast_to_prolog_aux(Caller, DontStub, (If*->true;Else),R). |
| 1373 | +ast_to_prolog_aux(Caller, DontStub, Smack,R):- |
| 1374 | + compound(Smack), |
| 1375 | + Smack=..[NSF, _,_AnyRet, Six66,_Self, FArgs,Ret], |
| 1376 | + (NSF = eval_args;NSF = eval_20), |
| 1377 | + \+ atom_concat(find,_,NSF), |
| 1378 | + \+ atom_concat(_,e,NSF), |
| 1379 | + Six66 == 666, |
| 1380 | + ast_to_prolog_aux(Caller,DontStub,eval(FArgs,Ret),R). |
| 1381 | +ast_to_prolog_aux(Caller,DontStub, eval([F|Args],Ret),R):- atom(F),is_list(Args), |
| 1382 | + ast_to_prolog_aux(Caller,DontStub,[assign,Ret,[call(F),Args]],R), !. |
| 1383 | + |
1343 | 1384 | ast_to_prolog_aux(_,_,'#\\'(A),A).
|
| 1385 | + |
| 1386 | +%ast_to_prolog_aux(_,_,A=B,A=B):- must_det_lls(label_type_assignment(A,B)). |
| 1387 | + |
| 1388 | + |
| 1389 | + |
| 1390 | +ast_to_prolog_aux(Caller,DontStub,(True,T),R) :- True == true, ast_to_prolog_aux(Caller,DontStub,T,R). |
| 1391 | +ast_to_prolog_aux(Caller,DontStub,(T,True),R) :- True == true, ast_to_prolog_aux(Caller,DontStub,T,R). |
| 1392 | +ast_to_prolog_aux(Caller,DontStub,(H;T),(HH;TT)) :- ast_to_prolog_aux(Caller,DontStub,H,HH),ast_to_prolog_aux(Caller,DontStub,T,TT). |
| 1393 | +ast_to_prolog_aux(Caller,DontStub,(H,T),(HH,TT)) :- ast_to_prolog_aux(Caller,DontStub,H,HH),ast_to_prolog_aux(Caller,DontStub,T,TT). |
| 1394 | +ast_to_prolog_aux(Caller,DontStub,do_metta_runtime(T,G),do_metta_runtime(T,GGG)) :- !, ast_to_prolog_aux(Caller,DontStub,G,GG),combine_code(GG,GGG). |
| 1395 | +ast_to_prolog_aux(Caller,DontStub,loonit_assert_source_tf(T,G),loonit_assert_source_tf(T,GG)) :- !, ast_to_prolog_aux(Caller,DontStub,G,GG). |
| 1396 | +ast_to_prolog_aux(Caller,DontStub,findall(T,G,L),findall(T,GG,L)) :- !, ast_to_prolog_aux(Caller,DontStub,G,GG). |
| 1397 | +ast_to_prolog_aux(Caller,DontStub,FArgs,NewFArgs):- |
| 1398 | + \+ is_list(FArgs), |
| 1399 | + compound(FArgs),!, |
| 1400 | + compound_name_arguments(FArgs, Name, Args), |
| 1401 | + maplist(ast_to_prolog_aux(Caller,DontStub),Args,NewArgs), |
| 1402 | + compound_name_arguments(NewCompound, Name, NewArgs),NewFArgs=NewCompound. |
| 1403 | + |
| 1404 | + |
| 1405 | +%ast_to_prolog_aux(Caller,DontStub,[H],HH) :- ast_to_prolog_aux(Caller,DontStub,H,HH). |
| 1406 | +%ast_to_prolog_aux(Caller,DontStub,[H|T],(HH,TT)) :- ast_to_prolog_aux(Caller,DontStub,H,HH),ast_to_prolog_aux(Caller,DontStub,T,TT). |
| 1407 | + |
1344 | 1408 | ast_to_prolog_aux(_,_,A,A).
|
1345 | 1409 |
|
1346 | 1410 | combine_code_list(A,R) :- !,
|
|
0 commit comments