/* ***************************************************************** * * * SB-Prolog * * 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. ------------------------------------------------------------------ */ /* begin tcond1.P *******************************************/ /* "tcond" generates code for the test for the if_then_else. */ /* ********************************************************************** $tcond1_export([$tcond/7,$cond_branch/8]). $tcond1_use($eval1,[$eval_exp/7,$eval_arithreloptab/4,$arithrelop/1]). $tcond1_use($blist,[_,_,$member1/2]). $tcond1_use($aux1,[_,_,_,_,$umsg/1,_,$disj_targ_label/2,_,_]). $tcond1_use($computil1,[_,$hold/3,_,$getreg/2,_,_,_,_,_,_,_,_,$type/2, $occ/2,$loc/2,_,_,$alloc_reg/3,$release_if_done/6,$release_if_done0/5]). $tcond1_use($inst1,[$varinst/8,_,_,_,_]). $tcond1_use($glob,[_,$gennum/1,_]). ********************************************************************** */ $tcond(and(Goal,_,Goals),SuccLab,FailLab,Pil,Pilr,Tin,Tout,HoldRegs) :- !, $gennum(LabId), $disj_targ_label(LabId,CLabel), IntSuccLab = label((CLabel,-1,LabId)), $tcond(Goal,IntSuccLab,FailLab,Pil,[IntSuccLab|Pilm],Tin,Tmid,HoldRegs), $tcond(Goals,SuccLab,FailLab,Pilm,Pilr,Tmid,Tout,HoldRegs). $tcond(or(Goal,_,Goals),SuccLab,FailLab,Pil,Pilr,Tin,Tout,HoldRegs) :- !, $gennum(LabId), $disj_targ_label(LabId,CLabel), IntFailLab = label((CLabel,-1,LabId)), $tcond(Goal,SuccLab,IntFailLab,Pil, [IntFailLab|Pilm],Tin,Tmid,HoldRegs), $tcond(Goals,Succlab,FailLab,Pilm,Pilr,Tmid,Tout,HoldRegs). $tcond('_call'(Op,[Arg1,Arg2],_),SLabel,FLabel,Pil,Pilr,Tin,Tout,HoldRegs) :- $arithrelop(Op), !, $tcond_relop(Op,Arg1,Arg2,SLabel,FLabel,Pil,Pilr,Tin,Tout,HoldRegs). $tcond('_call'(Op,[Arg],_),SLabel,FLabel,Pil,Pilr,Tin,Tout,HoldRegs) :- (Op = var ; Op = nonvar), !, $tcond_sot(Op,Arg,SLabel,FLabel,Pil,Pilr,Tin,Tout,HoldRegs). $tcond('_call'(Op,_,_),_,_,Pil,Pil,T,T,_) :- $umsg(['*** warning: Unknown operator',Op,'in If-Then-Else ***']). $tcond_relop(Op,Arg1,Arg2,SLabel,FLabel,Pil,Pilr,Tin,Tout,HoldRegs) :- SLabel = label(SL0), FLabel = label(FL0), $eval_exp(Arg1,R1,Pil,Pilm,HoldRegs,Tin,Tmid), $eval_exp(Arg2,R2,Pilm, [subreg(R2,R1),Jumpinst,jump(SL0)|Pilr],HoldRegs,Tmid,Tout1), $eval_arithreloptab(R1,Op,FL0,Jumpinst), $release_if_done0(Arg1,R1,HoldRegs,Tout1,Tout2), $release_if_done0(Arg2,R2,HoldRegs,Tout2,Tout). $tcond_sot(Op,v(Vid,Prag),SLabel,FLabel,Pil,Pilr,Tin,Tout,HoldRegs) :- $alloc_reg(Prag,Tin,Tmid), (($type(Prag,t), $loc(Prag,L), R = L, Tmid = Tmid1) ; ($getreg(Tmid,R),$hold(R,Tmid,Tmid1)) ), $occ(Prag,Oc), $type(Prag,T), $loc(Prag,Loc), $varinst(b,Oc,T,Loc,R,Pil,Pilm,Tmid1), SLabel = label(SL0), FLabel = label(FL0), ((Op = var, Pilm = [switchonterm(R,FL0,FL0)|Pilr]) ; (Op = nonvar, Pilm = [switchonterm(R,SL0,SL0),jump(FL0)|Pilr] ) ), $release_if_done(Vid,R,Prag,HoldRegs,Tmid1,Tout). $tcond_sot(Op,Arg,SLabel,FLabel,Pil,Pilr,Tin,Tout,HoldRegs) :- $umsg(['*** warning: argument to ',Op,' is not a variable ***']), ((Op = var, Pil = [fail|Pilr]) ; (Op = nonvar, Pil = Pilr) ), told, tell(X). $cond_branch(Pil1,Pil2,FLabel,[FLabel|Pil1],Pil2,Meet,Depth,Depth) :- var(Meet), !. $cond_branch(Pil1,Pil2,FLabel,NPil1,NPil2,meet(After),0,1) :- NPil1 = [jump(After),FLabel|Pil1], NPil2 = [label(After)|Pil2]. $cond_branch(Pil1,Pil2,FLabel,NPil1,Pil2,meet(After),1,1) :- NPil1 = [jump(After),FLabel|Pil1]. /* end $tcond1.P **********************************************/