/* ***************************************************************** * * * 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 prococc1.P **********************************************/ /* ********************************************************************** $prococc1_export([$proc_occ/2]). $prococc1_use($blist,[_,_,$member1/2]). $prococc1_use($procarglist1,[$proc_arg_list1/9]). $prococc1_use($prococcbody1,[$proc_occ_body/9,$list_pvars/2,_]). $prococc1_use($normvarocc1,[$normalize_var_occ/7]). $prococc1_use($listutil1,[_,_,_,_,_,_,_,$closetail/1]). $prococc1_use($glob,[_,$gennum/1,_]). $prococc1_use($procclp1,[_,$getnumlits/3]). ********************************************************************** */ /* "$proc_occ" and predicates it calls fills in pragma information about occurrences of variables (first/subsequent). */ $proc_occ([], []) :- !. $proc_occ([preddef(P, N, ClList, Prag)|RestPred], [preddef(P, N, NClList, Prag)|NRestPred]) :- $proc_occ1(P,N,ClList, NClList), $proc_occ(RestPred, NRestPred). $proc_occ1(_,_,[], []). $proc_occ1(Pred,Arity,[clause(Args, Body, P)|RestClause], [clause(Nargs, NBody, P)|NRestClause]) :- $member1(st(Clist,Vlist), P), $proc_arg_list(Args, Vlist, Seen, Nargs,[],Encs1,1,NP1,[]), $list_pvars(Args,Pvars_head), (($member1(c(1,_,ClP),Clist), $prococc_norm_clause(ClP), $normalize_var_occ(Body,Body2,Pvars_head,[],_,_,_)) ; Body2 = Body), $proc_mark_lastlits(Body2), $proc_occ_body(Body2,Vlist,Seen,_,NBody,Encs1,_,NP1,Npvars), $proc_clause(Pred, Arity,P,Npvars), $proc_occ1(Pred,Arity,RestClause, NRestClause). $prococc_norm_clause(ClPrag) :- $member1(normalize(NFlag),ClPrag), !, NFlag =:= 1. $prococc_alloc_clause(ClPrag) :- $member1(alloc(AFlag),ClPrag), !, AFlag =:= 1. /* "$proc_mark_lastlits" adds the pragma 'lastlit' to the last literal(s) of a clause. This is used to generate mark permanent variables as k(d) rather than k(p), for dereferencing values. */ $proc_mark_lastlits(nil). $proc_mark_lastlits(and(C1,P,C2)) :- $proc_mark_lastlits(C2). $proc_mark_lastlits(or(C1,P,C2)) :- $proc_mark_lastlits(C1), $proc_mark_lastlits(C2). $proc_mark_lastlits(if_then_else(T,P,C1,C2)) :- $proc_mark_lastlits(C1), $proc_mark_lastlits(C2). $proc_mark_lastlits('_call'(Pred,Args,Prag)) :- $member1(lastlit,Prag), $closetail(Prag). $proc_clause(Pred,Arity,Prag,NPvars) :- $member1(st(Clist,_),Prag), $getnumlits(Clist,0,Numlits), $gennum(N), $member1(label((Pred,Arity,N)),Prag), $proc_clause1(Prag,Numlits,NPvars), $closetail(Prag), !. $proc_clause1(Prag,Numlits,NPvars) :- $member1(st(Clist,_),Prag),$member1(c(_,_,ClPrag),Clist), (Numlits >= 2 ; NPvars > 2 ; $prococc_alloc_clause(ClPrag)), !, ARSize is NPvars + 1, $mark_arsize(Clist,ARSize), $member1(all(y),Prag). $proc_clause1(Prag,Numlits,NPvars) :- $member1(all(n),Prag). $mark_arsize([],_). $mark_arsize([c(_,_,ClPrag)|CRest],N) :- $member1(nv(N),ClPrag), $mark_arsize(CRest,N). /* end prococc1.P *************************************************/