Skip to content

Commit 5c2d29d

Browse files
committed
compiler merge shows depandancy tree and recompilation
1 parent 49e3add commit 5c2d29d

File tree

2 files changed

+74
-9
lines changed

2 files changed

+74
-9
lines changed

prolog/metta_lang/metta_compiler.pl

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@
208208

209209
( memberchk(mfa(CSpace,CName,CArity), VisitedIn) ->
210210
% cycle
211-
format("~q~q(*) ~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
211+
format("~w~w(*) ~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
212212
VisitedNext = VisitedIn
213213
; % normal
214-
format("~q~q~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
214+
format("~w~w~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
215215
% find grandchildren
216216
findall(mfa(GSpace,GName,GArity),
217217
transpiler_depends_on(CSpace, CName, CArity, GSpace, GName, GArity),
@@ -411,7 +411,7 @@
411411
%must_det_lls(G):- rtrace(G),!.
412412
must_det_lls((A,B)):- !, must_det_lls(A),must_det_lls(B).
413413
must_det_lls(G):- catch(G,E,(wdmsg(E),fail)),!.
414-
%must_det_lls(G):- must_det_lls(G).
414+
%must_det_lls(G):- must_det_ll(G).
415415
must_det_lls(G):- notrace,nortrace,trace,call(G),!.
416416

417417
extract_constraints(V,VS):- var(V),get_attr(V,vn,Name),get_attr(V,cns,Set),!,extract_constraints(Name,Set,VS),!.
@@ -1061,6 +1061,8 @@
10611061
length(Args,LenArgs),
10621062
LenArgsPlus1 is LenArgs+1,
10631063
atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix),
1064+
ensure_callee_site(Space,FnName,LenArgsPlus1),
1065+
remove_stub(Space,FnName,LenArgsPlus1),
10641066
% retract any stubs
10651067
(transpiler_stub_created(FnName/LenArgsPlus1) ->
10661068
retract(transpiler_stub_created(FnName/LenArgsPlus1)),
@@ -1137,7 +1139,16 @@
11371139
%format("###########1 ~q",[Converted]),
11381140
%numbervars(Converted,0,_),
11391141
%format("###########2 ~q",[Converted]),
1140-
output_language(prolog, (print_pl_source(Converted))),
1142+
extract_constraints(Converted,EC),
1143+
optimize_prolog([],Converted,Optimized),
1144+
output_prolog('#F08080',[EC]),!,
1145+
output_prolog('#ADD8E6',[Converted]),!,
1146+
if_t(Optimized\=@=Converted,
1147+
output_prolog(green,Optimized)),
1148+
1149+
tree_deps(Space,FnName,LenArgsPlus1),
1150+
1151+
show_recompile(Space,FnName,LenArgsPlus1),
11411152
true
11421153
)))).
11431154

@@ -1564,6 +1575,61 @@
15641575
atom(Fn),
15651576
compile_flow_control(HeadIs,LazyVars,RetResult,ResultLazy, Convert, Converted),!.
15661577

1578+
% !(compile-body! (call-fn! compile_body (call-p writeln "666"))
1579+
f2p(HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
1580+
Convert=[Fn,Native|Args],atom(Fn),unshebang(Fn,'call-p'),!,
1581+
must_det_lls((
1582+
compile_maplist_p2(as_prolog,Args,NewArgs,PreCode),
1583+
%RetResult = 'True',
1584+
compile_maplist_p2(from_prolog_args(ResultLazy),NewArgs,Args,PostCode),
1585+
append([PreCode,[[native(Native),NewArgs],[assign,RetResult,'True']],PostCode],Converted))).
1586+
unshebang(S,US):- symbol(S),(symbol_concat(US,'!',S)->true;US=S).
1587+
1588+
compile_maplist_p2(_,[],[],[]).
1589+
compile_maplist_p2(P2,[Var|Args],[Res|NewArgs],PreCode):- \+ fullvar(Var), call(P2,Var,Res), !,
1590+
compile_maplist_p2(P2,Args,NewArgs,PreCode).
1591+
compile_maplist_p2(P2,[Var|Args],[Res|NewArgs],TheCode):-
1592+
compile_maplist_p2(P2,Args,NewArgs,PreCode),
1593+
append([[native(P2),Var,Res]],PreCode,TheCode).
1594+
1595+
% !(compile-body! (call-fn length $list))
1596+
f2p(HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
1597+
Convert=[Fn,Native|Args],atom(Fn),unshebang(Fn,'call-fn'),!,
1598+
compile_maplist_p2(as_prolog,Args,NewArgs,PreCode),
1599+
append(NewArgs,[Result],CallArgs),
1600+
compile_maplist_p2(from_prolog_args(maybe(ResultLazy)),[Result],[RetResult],PostCode),
1601+
append([PreCode,[[native(Native),CallArgs]],PostCode],Converted).
1602+
1603+
% !(compile-body! (call-fn-nth 0 wots version))
1604+
f2p(HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
1605+
Convert=[Fn,Nth,Native|SIn],atom(Fn),unshebang(Fn,'call-fn-nth'),integer(Nth),!,
1606+
compile_maplist_p2(as_prolog,SIn,S,PreCode),
1607+
length(Left,Nth),
1608+
append(Left,Right,S),
1609+
append(Left,[R|Right],Args),!,
1610+
compile_maplist_p2(from_prolog_args(maybe(ResultLazy)),[R],[RetResult],PostCode),
1611+
append([PreCode,[[native(Native),Args]],PostCode],Converted).
1612+
1613+
% !(compile-body! (length-p (a b c d) 4))
1614+
% !(compile-body! (format! "~q ~q ~q" (a b c)))
1615+
f2p(HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
1616+
is_host_predicate(Convert,Native,_Len),!,Convert=[_|Args],
1617+
compile_maplist_p2(as_prolog,Args,NewArgs,PreCode),
1618+
%RetResult = 'True',
1619+
compile_maplist_p2(from_prolog_args(maybe(ResultLazy)),NewArgs,Args,PostCode),
1620+
append([PreCode,[[native(Native),NewArgs],[assign,RetResult,'True']],PostCode],Converted).
1621+
1622+
1623+
% !(compile-body! (length-fn (a b c d)))
1624+
f2p(HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
1625+
Convert=[Fn|Args],
1626+
is_host_function([Fn|Args],Native,_Len),!,
1627+
compile_maplist_p2(as_prolog,Args,NewArgs,PreCode),
1628+
append(NewArgs,[Result],CallArgs),
1629+
compile_maplist_p2(from_prolog_args(maybe(ResultLazy)),[Result],[RetResult],PostCode),
1630+
append([PreCode,[[native(Native),CallArgs]],PostCode],Converted).
1631+
1632+
15671633
f2p(HeadIs, LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
15681634
Convert=[Fn|_], \+ atom(Fn),
15691635
Args = Convert,

prolog/metta_lang/metta_compiler_douglas.pl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@
208208

209209
( memberchk(mfa(CSpace,CName,CArity), VisitedIn) ->
210210
% cycle
211-
format("~q~q(*) ~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
211+
format("~w~w(*) ~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
212212
VisitedNext = VisitedIn
213213
; % normal
214-
format("~q~q~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
214+
format("~w~w~q:~q/~q~n",[Prefix, BranchSym, CSpace, CName, CArity]),
215215
% find grandchildren
216216
findall(mfa(GSpace,GName,GArity),
217217
transpiler_depends_on(CSpace, CName, CArity, GSpace, GName, GArity),
@@ -1061,7 +1061,7 @@
10611061
length(Args,LenArgs),
10621062
LenArgsPlus1 is LenArgs+1,
10631063
atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix),
1064-
ensure_callee_site(_Space,FnName,LenArgsPlus1),
1064+
ensure_callee_site(Space,FnName,LenArgsPlus1),
10651065
remove_stub(Space,FnName,LenArgsPlus1),
10661066
% retract any stubs
10671067
(transpiler_stub_created(FnName/LenArgsPlus1) ->
@@ -1138,7 +1138,6 @@
11381138

11391139

11401140
ast_to_prolog(caller(FnName,LenArgsPlus1),[FnName/LenArgsPlus1],NextBody,NextBodyC),
1141-
11421141
%format("###########1 ~q",[Converted]),
11431142
%numbervars(Converted,0,_),
11441143
%format("###########2 ~q",[Converted]),
@@ -1688,7 +1687,7 @@
16881687

16891688
% !(compile-body! (length-p (a b c d) 4))
16901689
% !(compile-body! (format! "~q ~q ~q" (a b c)))
1691-
f2p(HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
1690+
f2p(HeadIs, _LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
16921691
is_host_predicate(Convert,Native,_Len),!,Convert=[_|Args],
16931692
compile_maplist_p2(as_prolog,Args,NewArgs,PreCode),
16941693
%RetResult = 'True',

0 commit comments

Comments
 (0)