home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / pd3.lzh / SBPROLOG2.2 / MODLIB / MODLIB_SRC / $defint.P < prev    next >
Text File  |  1991-08-10  |  5KB  |  126 lines

  1. /************************************************************************
  2. *                                    *
  3. *    The SB-Prolog System                        *
  4. *    Copyright SUNY at Stony Brook, 1986                *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25.  
  26. $defint_export([$defint_call/4]).
  27.  
  28. /* $defint_use($bmeta,[$atom/1,$atomic/1,$integer/1,$number/1,$structure/1,
  29.     $functor0/2,$bldstr/3,$arg/3,$arity/2,$real/1,$floor/2]).
  30.    $defint_use($buff,
  31.     [$alloc_perm/2,$alloc_heap/2,$trimbuff/3,$buff_code/4,$symtype/2,
  32.         $substring/6,$subnumber/6,$subdelim/6,$conlength/2,
  33.         $pred_undefined/1, $hashval/3]).
  34. */
  35.  
  36. $defint_call(Predterm,Arity,Genclfact,Introutine) :- 
  37.     $arity(Genclfact,Arity1),
  38.     (Arity=:=Arity1,
  39.         $defint_ercept(Predterm,Arity,Genclfact,Introutine)
  40.     ;
  41.      Arity=\=Arity1,
  42.         $defint_erpret(Predterm,Arity,Genclfact,Introutine)
  43.     ).
  44.  
  45. $defint_erpret(Predterm,Arity,Genclfact,'_$interp'(_,_)) :- !,
  46.     /* for Predterm = p(X,Y) , 
  47.        and Genclfact = cl$p(_,_,_),
  48.        generate code for:
  49.         p(A1,A2) :- _$savecp(CP),cl$p(A1,A2,B),_$interp(B,CP).
  50.     */
  51.     Arity1 is Arity+1,    /* no-op if not! */
  52.     $arity(Genclfact,Arity1),
  53.     $alloc_perm(34,Buff),
  54.     $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */
  55.     $defint_code_list([233,0,        /* allocate        */
  56.             166,2,         /* getpbreg(2)        */
  57.             16,0,3,Arity1,    /* putpvar(3,Arity+1)    */
  58.             232,4         /* call cl$??,4        */
  59.             ],Buff,4),
  60.     $buff_code(Buff,14,0 /*ppsc*/ ,Genclfact),
  61.     $defint_code_list([225,0,3,1,    /* putuval(3,1)        */
  62.             225,0,2,2,    /* putuval(2,2)        */
  63.             234,0,        /* deallocate        */
  64.             236,0        /* execute(_$interp)    */
  65.             ],Buff,18),
  66.     $buff_code(Buff,30,0 /*ppsc*/ ,'_$interp'(_,_)),
  67.     $buff_code(Predterm,0,9 /*pep*/ ,Buff).
  68.  
  69. $defint_erpret(Predterm,Arity,Genclfact,'_$call'(_)) :- !,
  70.     /* for Predterm = p(X,Y) , 
  71.        and Genclfact = cl$p(_,_,_),
  72.        generate code for:
  73.         p(A1,A2) :- cl$p(A1,A2,B),_$call(B).
  74.     */
  75.     $arity(Genclfact,Arity1),
  76.     Arity1 is Arity+1, /* no-op if not! */
  77.     $alloc_perm(28,Buff),
  78.     $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */
  79.     $defint_code_list([233,0,        /* allocate        */
  80.             16,0,2,Arity1,    /* putpvar(2,Arity+1)    */
  81.             232,3         /* call cl$??,3        */
  82.             ],Buff,4),
  83.     $buff_code(Buff,12,0 /*ppsc*/ ,Genclfact),
  84.     $defint_code_list([225,0,2,1,    /* putuval(2,1)        */
  85.             234,0,        /* deallocate        */
  86.             236,0        /* execute(_$call)    */
  87.             ],Buff,16),
  88.     $buff_code(Buff,24,0 /*ppsc*/ ,'_$call'(_)),
  89.     $buff_code(Predterm,0,9 /*pep*/ ,Buff).
  90.  
  91. $defint_erpret(Predterm,Arity,Genclfact,Interprout) :- 
  92.     /* for Predterm = p(X,Y) , 
  93.        and Genclfact = cl$p(_,_,_),
  94.        and Interprout = _$interpgoal(_,_)
  95.        generate instruction: unexeci cl$p,_$interpgoal
  96.     */
  97.     $arity(Genclfact,Arity1),
  98.     Arity1 is Arity+1, /* fail if not! */
  99.     $alloc_perm(14,Buff),
  100.     $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */
  101.     $defint_code_list([237 /*unexeci*/ ,0],Buff,4),
  102.     $buff_code(Buff,6,0 /*ppsc*/ ,Genclfact),
  103.     $buff_code(Buff,10,0 /*ppsc*/ ,Interprout),
  104.     $buff_code(Predterm,0,9 /*pep*/ ,Buff).
  105.  
  106. $defint_ercept(Predterm,Arity,Genclfact,Interprout) :-
  107.     /* for Predterm = p(X,Y) , 
  108.        and Genclfact = code$p(_,_),
  109.        and Interprout = _$traceintercept(_)
  110.        defines p(X,Y) :- _$traceintercept(code$p(X,Y)) by
  111.             generating instruction: unexec code$p,_$traceintercept
  112.     */
  113.     $arity(Genclfact,Arity),    /* error if not same arity */
  114.     $alloc_perm(14,Buff),
  115.     $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */
  116.     $defint_code_list([231 /*unexec*/ ,0],Buff,4),
  117.     $buff_code(Buff,6,0 /*ppsc*/ ,Genclfact),
  118.     $buff_code(Buff,10,0 /*ppsc*/ ,Interprout),
  119.     $buff_code(Predterm,0,9 /*pep*/ ,Buff).
  120.  
  121. $defint_code_list([],_,_).
  122. $defint_code_list([Byte|Rest],Buff,Loc) :-
  123.     $buff_code(Buff,Loc,3 /*pb*/ ,Byte),
  124.     Nextloc is Loc+1,
  125.     $defint_code_list(Rest,Buff,Nextloc).
  126.