|
1 | 1 | :- dynamic(transpiler_predicate_store/7). |
2 | 2 | :- discontiguous transpiler_predicate_store/7. |
3 | 3 | :- discontiguous transpiler_predicate_nary_store/9. |
| 4 | +:- discontiguous compile_flow_control/8. |
4 | 5 |
|
5 | 6 | from_prolog_args(_,X,X). |
6 | 7 | :-dynamic(pred_uses_fallback/2). |
|
243 | 244 | transpiler_predicate_store(builtin, 'decons-atom', [1], '@doc', '@doc', [x(noeval,eager,[list])], x(noeval,eager,[list])). |
244 | 245 | 'mc__1_1_decons-atom'([A|B],[A,B]). |
245 | 246 |
|
| 247 | +%transpiler_predicate_store(builtin, 'length', [1], '@doc', '@doc', [x(noeval,eager,[list])], x(noeval,eager,[number])). |
| 248 | +%'mc__1_1_length'(L,S) :- length(L,S). |
| 249 | + |
| 250 | +transpiler_predicate_store(builtin, 'size-atom', [1], '@doc', '@doc', [x(noeval,eager,[list])], x(noeval,eager,[number])). |
| 251 | +'mc__1_1_size-atom'(L,S) :- length(L,S). |
| 252 | + |
246 | 253 | %%%%%%%%%%%%%%%%%%%%% set |
247 | 254 |
|
248 | 255 | lazy_member(P,R2) :- as_p1_exec(R2,P). |
|
315 | 322 | % This allows match to supply hits to the correct metta_atom/2 (Rather than sending a variable |
316 | 323 | match_pattern(Space, Pattern):- |
317 | 324 | if_t(compound(Pattern), |
318 | | - (functor(Pattern,F,A,Type), functor(Atom,F,A,Type))), |
319 | | - metta_atom(Space, Atom), |
| 325 | + (functor(Pattern,F,A,Type), functor(Atom,F,A,Type))), |
| 326 | + metta_atom(Space, Atom), |
320 | 327 | %unify_with_occurs_check(Atom,Pattern). % 0.262 secs. |
321 | 328 | Atom=Pattern. % 0.170 secs |
322 | | - %wocf(Atom=Pattern). |
| 329 | + %wocf(Atom=Pattern). |
323 | 330 | %woc(Atom=Pattern). % 2.09 seconds. |
324 | 331 |
|
325 | 332 | transpiler_predicate_store(builtin, match, [3], '@doc', '@doc', [x(doeval,eager,[]), x(noeval,eager,[]), x(doeval,lazy,[])], x(doeval,eager,[])). |
|
351 | 358 | transpiler_predicate_nary_store(builtin, progn, 0, [], 'Atom', 'Atom', [], x(doeval,eager,[]), x(doeval,eager,[])). |
352 | 359 | 'mc_n_0__progn'(List,Ret) :- append(_,[Ret],List). |
353 | 360 |
|
354 | | -transpiler_predicate_nary_store(builtin, 'call-fn!', 1, ['Atom'], 'Atom', 'Atom', [x(doeval,eager,[])], x(doeval,eager,[]), x(doeval,eager,[])). |
| 361 | +transpiler_predicate_nary_store(builtin, 'call-fn!', 1, ['Atom'], 'Atom', 'Atom', [x(noeval,eager,[])], x(noeval,eager,[]), x(doeval,eager,[])). |
355 | 362 | 'mc_n_1__call-fn!'(Fn,List,Ret) :- append(List,[Ret],List2),apply(Fn,List2). |
356 | 363 |
|
| 364 | +transpiler_predicate_nary_store(builtin, 'call-fn', 1, ['Atom'], 'Atom', 'Atom', [x(doeval,eager,[])], x(doeval,eager,[]), x(doeval,eager,[])). |
| 365 | +'mc_n_1__call-fn'(Fn,List,Ret) :- append(List,[Ret],List2),apply(Fn,List2). |
| 366 | + |
357 | 367 | transpiler_predicate_nary_store(builtin, 'call-p!', 1, ['Atom'], 'Atom', 'Atom', [x(doeval,eager,[])], x(doeval,eager,[]), x(doeval,eager,[])). |
358 | 368 | 'mc_n_1__call-p!'(Fn,List,Ret) :- (apply(Fn,List)->Ret='True';Ret='False'). |
359 | 369 |
|
|
540 | 550 | predsort(listing_order,Unsorted,Sorted). |
541 | 551 |
|
542 | 552 |
|
| 553 | +metta_to_metta_macro(HeadIsN, AsBodyFnN, HeadIsC, AsBodyFnOut):- |
| 554 | + must_det_lls(( |
| 555 | + copy_term(AsBodyFnN+HeadIsN,AsBodyFnC+HeadIsC,_), |
| 556 | + number_vars_wo_conficts(AsBodyFnC+HeadIsC,AsBodyFn+HeadIs), |
| 557 | + (AsBodyFnC+HeadIsC=AsBodyFn+HeadIs), |
| 558 | + metta_body_macro(HeadIs, AsBodyFn, AsBodyFnOut),!, |
| 559 | + \+ \+ if_t(AsBodyFn\=@=AsBodyFnOut, |
| 560 | + ( debug_info(metta_macro_in,c(print_tree([=,HeadIs, AsBodyFn]))),!, |
| 561 | + debug_info(metta_macro_out,c(print_tree([=,HeadIs, AsBodyFnOut]))))))),!. |
| 562 | + |
| 563 | +metta_body_macro(HeadIs, AsBodyFn, AsBodyFnOut):- |
| 564 | + must_det_lls((metta_body_macro1(HeadIs, [], AsBodyFn, AsBodyFnE), |
| 565 | + metta_body_macro2(HeadIs, [], AsBodyFnE, AsBodyFnMid), |
| 566 | + (AsBodyFn =@= AsBodyFnMid -> AsBodyFnMid = AsBodyFnOut ; |
| 567 | + metta_body_macro(HeadIs, AsBodyFnMid, AsBodyFnOut)))). |
| 568 | + |
| 569 | +metta_body_macro1(_HeadIs, _, AsBodyFn, AsBodyFn):- \+ compound(AsBodyFn), !. |
| 570 | +metta_body_macro1(_HeadIs, _, AsBodyFn, AsBodyFn):- \+ is_list(AsBodyFn), !. |
| 571 | +metta_body_macro1(HeadIs, Stack, [Op|AsBodyFn], AsBodyFnOut):- fail, \+ is_funcall_op(Op), !, maplist(metta_body_macro1(HeadIs, Stack), [Op|AsBodyFn], AsBodyFnOut),!. |
| 572 | +metta_body_macro1(HeadIs, Stack, [Op|AsBodyFn], AsBodyFnOut):- |
| 573 | + maplist(metta_body_macro1(HeadIs, [Op|Stack]), AsBodyFn, AsBodyFnMid), |
| 574 | + [Op|AsBodyFnMid]=OpAsBodyMid, |
| 575 | + copy_term(OpAsBodyMid,OpAsBodyMidCopy), |
| 576 | + metta_body_macro_final1(HeadIs, Stack, OpAsBodyMid , AsBodyFnOut), |
| 577 | + OpAsBodyMid=@=OpAsBodyMidCopy,!. |
| 578 | + |
| 579 | +metta_body_macro_final1(_HeadIs,_Stack, [NonOp|More], AsBodyFn):- \+ atom(NonOp),!,[NonOp|More]= AsBodyFn. |
| 580 | +metta_body_macro_final1(_HeadIs,_Stack, ['if-unify',Var1,Var2|Rest], [if,['metta-unify',Var1,Var2]|Rest]). |
| 581 | +metta_body_macro_final1(_HeadIs,_Stack, ['if-equal',Var1,Var2|Rest], [if,['metta-equal',Var1,Var2]|Rest]). |
| 582 | +metta_body_macro_final1(_HeadIs,_Stack, ['if-decons-expr',Expr,Head,Tail|Rest],[if,['decons-ht',Expr,Head,Tail]|Rest]). |
| 583 | +metta_body_macro_final1(_HeadIs,_Stack, ['if-decons',Expr,Head,Tail|Rest],[if,['decons-ht',Expr,Head,Tail]|Rest]). |
| 584 | +metta_body_macro_final1(_HeadIs,_Stack, ['chain',[Ceval,Eval],Var|Rest], ['let',Var,Eval|Rest]):- Ceval == eval,!. |
| 585 | +metta_body_macro_final1(_HeadIs,_Stack, ['chain',Eval,Var|Rest], ['let',Var,Eval|Rest]). |
| 586 | +%metta_body_macro_final1(_HeadIs,_Stack, [eval,Next], Next). |
| 587 | +metta_body_macro_final1(_HeadIs,_Stack, AsBodyFnOut, AsBodyFnOut). |
| 588 | + |
| 589 | +metta_body_macro2(_HeadIs, _, AsBodyFn, AsBodyFn):- \+ compound(AsBodyFn), !. |
| 590 | +metta_body_macro2(_HeadIs, _, AsBodyFn, AsBodyFn):- \+ is_list(AsBodyFn), !. |
| 591 | +metta_body_macro2(HeadIs, Stack, OpAsBody, AsBodyFnOutReally):- |
| 592 | + copy_term(OpAsBody,OpAsBodyMidCopy), |
| 593 | + metta_body_macro_final2(HeadIs, Stack, OpAsBody , AsBodyFnOut), |
| 594 | + OpAsBody=@=OpAsBodyMidCopy,!, |
| 595 | + maplist( metta_body_macro2(HeadIs, Stack), AsBodyFnOut,AsBodyFnOutReally). |
| 596 | + |
| 597 | +metta_body_macro_final2(_HeadIs,_Stack, [NonOp|More], AsBodyFn):- \+ atom(NonOp),!,[NonOp|More]= AsBodyFn. |
| 598 | +metta_body_macro_final2(_HeadIs,_Stack, [eval,Next], Next). |
| 599 | +metta_body_macro_final2(_HeadIs,_Stack, AsBodyFnOut, AsBodyFnOut). |
| 600 | + |
543 | 601 |
|
0 commit comments