/************************************************************************ * * * The SB-Prolog System * * Copyright SUNY at Stony Brook, 1986 * * * ************************************************************************/ /*----------------------------------------------------------------- SB-Prolog is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. No author or distributor accepts responsibility to anyone for the consequences of using it or for whether it serves any particular purpose or works at all, unless he says so in writing. Refer to the SB-Prolog General Public License for full details. Everyone is granted permission to copy, modify and redistribute SB-Prolog, but only under the conditions described in the SB-Prolog General Public License. A copy of this license is supposed to have been given to you along with SB-Prolog so you can know your rights and responsibilities. It should be in a file named COPYING. Among other things, the copyright notice and this notice must be preserved on all copies. ------------------------------------------------------------------ */ $defint_export([$defint_call/4]). /* $defint_use($bmeta,[$atom/1,$atomic/1,$integer/1,$number/1,$structure/1, $functor0/2,$bldstr/3,$arg/3,$arity/2,$real/1,$floor/2]). $defint_use($buff, [$alloc_perm/2,$alloc_heap/2,$trimbuff/3,$buff_code/4,$symtype/2, $substring/6,$subnumber/6,$subdelim/6,$conlength/2, $pred_undefined/1, $hashval/3]). */ $defint_call(Predterm,Arity,Genclfact,Introutine) :- $arity(Genclfact,Arity1), (Arity=:=Arity1, $defint_ercept(Predterm,Arity,Genclfact,Introutine) ; Arity=\=Arity1, $defint_erpret(Predterm,Arity,Genclfact,Introutine) ). $defint_erpret(Predterm,Arity,Genclfact,'_$interp'(_,_)) :- !, /* for Predterm = p(X,Y) , and Genclfact = cl$p(_,_,_), generate code for: p(A1,A2) :- _$savecp(CP),cl$p(A1,A2,B),_$interp(B,CP). */ Arity1 is Arity+1, /* no-op if not! */ $arity(Genclfact,Arity1), $alloc_perm(34,Buff), $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */ $defint_code_list([233,0, /* allocate */ 166,2, /* getpbreg(2) */ 16,0,3,Arity1, /* putpvar(3,Arity+1) */ 232,4 /* call cl$??,4 */ ],Buff,4), $buff_code(Buff,14,0 /*ppsc*/ ,Genclfact), $defint_code_list([225,0,3,1, /* putuval(3,1) */ 225,0,2,2, /* putuval(2,2) */ 234,0, /* deallocate */ 236,0 /* execute(_$interp) */ ],Buff,18), $buff_code(Buff,30,0 /*ppsc*/ ,'_$interp'(_,_)), $buff_code(Predterm,0,9 /*pep*/ ,Buff). $defint_erpret(Predterm,Arity,Genclfact,'_$call'(_)) :- !, /* for Predterm = p(X,Y) , and Genclfact = cl$p(_,_,_), generate code for: p(A1,A2) :- cl$p(A1,A2,B),_$call(B). */ $arity(Genclfact,Arity1), Arity1 is Arity+1, /* no-op if not! */ $alloc_perm(28,Buff), $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */ $defint_code_list([233,0, /* allocate */ 16,0,2,Arity1, /* putpvar(2,Arity+1) */ 232,3 /* call cl$??,3 */ ],Buff,4), $buff_code(Buff,12,0 /*ppsc*/ ,Genclfact), $defint_code_list([225,0,2,1, /* putuval(2,1) */ 234,0, /* deallocate */ 236,0 /* execute(_$call) */ ],Buff,16), $buff_code(Buff,24,0 /*ppsc*/ ,'_$call'(_)), $buff_code(Predterm,0,9 /*pep*/ ,Buff). $defint_erpret(Predterm,Arity,Genclfact,Interprout) :- /* for Predterm = p(X,Y) , and Genclfact = cl$p(_,_,_), and Interprout = _$interpgoal(_,_) generate instruction: unexeci cl$p,_$interpgoal */ $arity(Genclfact,Arity1), Arity1 is Arity+1, /* fail if not! */ $alloc_perm(14,Buff), $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */ $defint_code_list([237 /*unexeci*/ ,0],Buff,4), $buff_code(Buff,6,0 /*ppsc*/ ,Genclfact), $buff_code(Buff,10,0 /*ppsc*/ ,Interprout), $buff_code(Predterm,0,9 /*pep*/ ,Buff). $defint_ercept(Predterm,Arity,Genclfact,Interprout) :- /* for Predterm = p(X,Y) , and Genclfact = code$p(_,_), and Interprout = _$traceintercept(_) defines p(X,Y) :- _$traceintercept(code$p(X,Y)) by generating instruction: unexec code$p,_$traceintercept */ $arity(Genclfact,Arity), /* error if not same arity */ $alloc_perm(14,Buff), $buff_code(Buff,0,14 /*ptv*/ ,Buff), /* set back-ptr */ $defint_code_list([231 /*unexec*/ ,0],Buff,4), $buff_code(Buff,6,0 /*ppsc*/ ,Genclfact), $buff_code(Buff,10,0 /*ppsc*/ ,Interprout), $buff_code(Predterm,0,9 /*pep*/ ,Buff). $defint_code_list([],_,_). $defint_code_list([Byte|Rest],Buff,Loc) :- $buff_code(Buff,Loc,3 /*pb*/ ,Byte), Nextloc is Loc+1, $defint_code_list(Rest,Buff,Nextloc).