|
208 | 208 |
|
209 | 209 | ( memberchk(mfa(CSpace,CName,CArity), VisitedIn) ->
|
210 | 210 | % 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]), |
212 | 212 | VisitedNext = VisitedIn
|
213 | 213 | ; % 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]), |
215 | 215 | % find grandchildren
|
216 | 216 | findall(mfa(GSpace,GName,GArity),
|
217 | 217 | transpiler_depends_on(CSpace, CName, CArity, GSpace, GName, GArity),
|
|
411 | 411 | %must_det_lls(G):- rtrace(G),!.
|
412 | 412 | must_det_lls((A,B)):- !, must_det_lls(A),must_det_lls(B).
|
413 | 413 | 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). |
415 | 415 | must_det_lls(G):- notrace,nortrace,trace,call(G),!.
|
416 | 416 |
|
417 | 417 | extract_constraints(V,VS):- var(V),get_attr(V,vn,Name),get_attr(V,cns,Set),!,extract_constraints(Name,Set,VS),!.
|
|
1061 | 1061 | length(Args,LenArgs),
|
1062 | 1062 | LenArgsPlus1 is LenArgs+1,
|
1063 | 1063 | atomic_list_concat(['mc_',LenArgs,'__',FnName],FnNameWPrefix),
|
| 1064 | + ensure_callee_site(Space,FnName,LenArgsPlus1), |
| 1065 | + remove_stub(Space,FnName,LenArgsPlus1), |
1064 | 1066 | % retract any stubs
|
1065 | 1067 | (transpiler_stub_created(FnName/LenArgsPlus1) ->
|
1066 | 1068 | retract(transpiler_stub_created(FnName/LenArgsPlus1)),
|
|
1137 | 1139 | %format("###########1 ~q",[Converted]),
|
1138 | 1140 | %numbervars(Converted,0,_),
|
1139 | 1141 | %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), |
1141 | 1152 | true
|
1142 | 1153 | )))).
|
1143 | 1154 |
|
|
1564 | 1575 | atom(Fn),
|
1565 | 1576 | compile_flow_control(HeadIs,LazyVars,RetResult,ResultLazy, Convert, Converted),!.
|
1566 | 1577 |
|
| 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 | + |
1567 | 1633 | f2p(HeadIs, LazyVars, RetResult, ResultLazy, Convert, Converted) :- HeadIs\=@=Convert,
|
1568 | 1634 | Convert=[Fn|_], \+ atom(Fn),
|
1569 | 1635 | Args = Convert,
|
|
0 commit comments