Skip to content

Commit 49e3add

Browse files
committed
compiler merge still missing the shouting too
1 parent 16f32a8 commit 49e3add

File tree

2 files changed

+71
-9
lines changed

2 files changed

+71
-9
lines changed

prolog/metta_lang/metta_compiler.pl

Lines changed: 67 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,14 +1053,17 @@
10531053

10541054
% !(compile-for-assert (plus1 $x) (+ 1 $x) )
10551055
compile_for_assert(HeadIs, AsBodyFn, Converted) :-
1056+
must_det_lls((
1057+
current_self(Space),
1058+
%subst_varnames(HeadIsIn+AsBodyFnIn,HeadIs+AsBodyFn),
10561059
%leash(-all),trace,
10571060
HeadIs=[FnName|Args],
10581061
length(Args,LenArgs),
10591062
LenArgsPlus1 is LenArgs+1,
1063+
atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix),
10601064
% retract any stubs
10611065
(transpiler_stub_created(FnName/LenArgsPlus1) ->
10621066
retract(transpiler_stub_created(FnName/LenArgsPlus1)),
1063-
atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix),
10641067
findall(Atom0, (between(1, LenArgsPlus1, I0) ,Atom0='$VAR'(I0)), AtomList0),
10651068
H=..[FnNameWPrefix|AtomList0],
10661069
(transpiler_show_debug_messages -> format("Retracting stub: ~q\n",[H]) ; true),
@@ -1089,6 +1092,25 @@
10891092
compiler_assertz(transpiler_clause_store(FnName,LenArgsPlus1,ClauseId,Types0,RetType0,FinalLazyArgs,FinalLazyRet,HeadIs,AsBodyFn)),
10901093
maplist(arrange_lazy_args,Args,FinalLazyArgs,LazyArgsList),
10911094
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+
10921114
f2p(HeadIs,LazyArgsList,HResult,FinalLazyOnlyRet,AsBodyFn,NextBody),
10931115

10941116

@@ -1117,7 +1139,9 @@
11171139
%format("###########2 ~q",[Converted]),
11181140
output_language(prolog, (print_pl_source(Converted))),
11191141
true
1120-
)).
1142+
)))).
1143+
1144+
11211145

11221146
no_conflict_numbervars(Term):-
11231147
findall(N,(sub_term(E,Term),compound(E), '$VAR'(N)=E, integer(N)),NL),!,
@@ -1328,6 +1352,7 @@
13281352
maplist(ast_to_prolog_aux(Caller,DontStub),Args0,Args1),
13291353
length(Args0,LArgs),
13301354
atomic_list_concat(['mc_',LArgs,'__',F],Fp),
1355+
label_arg_types(F,0,[A|Args1]),
13311356
LArgs1 is LArgs+1,
13321357
append(Args1,[A],Args2),
13331358
R=..[Fp|Args2],
@@ -1338,9 +1363,48 @@
13381363
((current_predicate(Fp/LArgs1);member(F/LArgs1,DontStub)) ->
13391364
true
13401365
; 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),!.
13421367
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+
13431384
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+
13441408
ast_to_prolog_aux(_,_,A,A).
13451409

13461410
combine_code_list(A,R) :- !,

prolog/metta_lang/metta_compiler_douglas.pl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,10 +1052,10 @@
10521052
).
10531053

10541054
% !(compile-for-assert (plus1 $x) (+ 1 $x) )
1055-
compile_for_assert(HeadIsIn, AsBodyFnIn, Optimized) :-
1055+
compile_for_assert(HeadIs, AsBodyFn, Converted) :-
10561056
must_det_lls((
10571057
current_self(Space),
1058-
subst_varnames(HeadIsIn+AsBodyFnIn,HeadIs+AsBodyFn),
1058+
%subst_varnames(HeadIsIn+AsBodyFnIn,HeadIs+AsBodyFn),
10591059
%leash(-all),trace,
10601060
HeadIs=[FnName|Args],
10611061
length(Args,LenArgs),
@@ -1066,7 +1066,6 @@
10661066
% retract any stubs
10671067
(transpiler_stub_created(FnName/LenArgsPlus1) ->
10681068
retract(transpiler_stub_created(FnName/LenArgsPlus1)),
1069-
atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix),
10701069
findall(Atom0, (between(1, LenArgsPlus1, I0) ,Atom0='$VAR'(I0)), AtomList0),
10711070
H=..[FnNameWPrefix|AtomList0],
10721071
(transpiler_show_debug_messages -> format("Retracting stub: ~q\n",[H]) ; true),
@@ -1360,6 +1359,8 @@
13601359
ast_to_prolog(Caller,DontStub,Then,Then2),
13611360
ast_to_prolog(Caller,DontStub,Else,Else2),
13621361
R=((If2) *-> (Then2);(Else2)).
1362+
ast_to_prolog_aux(Caller,DontStub,[is_p1,Code0,R],is_p1(Code1,R)) :- !,ast_to_prolog(Caller,DontStub,Code0,Code1).
1363+
ast_to_prolog_aux(Caller,DontStub,[is_p1,Type,Src,Code0,R],is_p1(Type,Src,Code1,R)) :- !,ast_to_prolog(Caller,DontStub,Code0,Code1).
13631364
ast_to_prolog_aux(Caller,DontStub,[native(FIn)|ArgsIn],A) :- !,
13641365
must_det_lls((
13651366
FIn=..[F|Pre], % allow compound natives
@@ -1369,9 +1370,6 @@
13691370
label_arg_types(F,1,Args1),
13701371
A=..[F|Args1],
13711372
notice_callee(Caller,A))).
1372-
1373-
ast_to_prolog_aux(Caller,DontStub,[is_p1,Code0,R],is_p1(Code1,R)) :- !,ast_to_prolog(Caller,DontStub,Code0,Code1).
1374-
ast_to_prolog_aux(Caller,DontStub,[is_p1,Type,Src,Code0,R],is_p1(Type,Src,Code1,R)) :- !,ast_to_prolog(Caller,DontStub,Code0,Code1).
13751373
ast_to_prolog_aux(Caller,DontStub,[assign,A,[call(FIn)|ArgsIn]],R) :- (fullvar(A); \+ compound(A)),callable(FIn),!,
13761374
must_det_lls((
13771375
FIn=..[F|Pre], % allow compound natives

0 commit comments

Comments
 (0)