%query: analyze_all(i,o). %------------------------------------------------------------------------------ % Benchmark Program - Simplified Clause Annotator % % by Manuel Hermenegildo, R. Warren, and M. Muthukumar % Date: October 1989 % % Query: go(N) - N times for clauses in data/1 to be repeated % %------------------------------------------------------------------------------ %:- module(annotate, [go/1]). %:- entry(analyze_all(X,Y),[share([[X],[Y]]),free([Y])]). :- op(1150,fx,[(imode),(omode)]). analyze_all([X|Y],[X1|Y1]) :- analyze(X,X1), analyze_all(Y,Y1). analyze_all([],[]). analyze( Source, NewSource ) :- Source = clause(_X,Body), ( Body = true,!, NewSource = Source ; I = [], G = [], rewrite_3(Source,New_Source,I,G,_Y), un_number_vars(New_Source,NewSource,others),! ). rewrite_3(clause(H,B),clause(H,P),I,G,Info):- check_if_cge(B,Result), ( Result = 0, P = B ; rewrite(clause(H,B),clause(H,P),I,G,Info) ). rewrite( clause(H,B), clause(H,P),I,G,Info) :- numbervars_2(H,0,Lhv), collect_info(B,Info,Lhv,_X,_Y), add_annotations(Info,P,I,G),!. add_annotations([],[],_,_). add_annotations([I|Is],[P|Ps],Indep,Gnd) :- !, add_annotations(I,P,Indep,Gnd), add_annotations(Is,Ps,Indep,Gnd). add_annotations(Info,Phrase,I,G) :- !, para_phrase( Info,Code,Type,Vars,I,G), make_CGE_phrase( Type,Code,Vars,PCode,I,G), ( var(Code),!, Phrase = PCode ; Vars = [],!, Phrase = Code ; Phrase = (PCode,Code) ). collect_info( (A;B),([],sequential,(A;B)),Cin,Cout,_X) :- !, collect_info(A,_Y,Cin,C,_Z), collect_info(B,_N,C,Cout,_M). collect_info( (A,B), and(Ia,Ib),Cin,Cout,_X) :- !, collect_info(A,Ia,Cin,C,_Y), collect_info(B,Ib,C,Cout,_Z). collect_info( A,(NewVars,CInfo,A),In,Out,_R) :- find_vars(A,NewVars,In,Out), ( functor(A,F,Arity), builtin(F/Arity),!, CInfo = sequential ; NewVars \== [],!, CInfo = suspect ; true ),!. para_phrase( and( X,Y ), Conjuncts, Type, BagofVars,I,G) :- !, para_phrase(X, Xcode, Xtype, XVars,I,G), para_phrase(Y, Ycode, Ytype, YVars,I,G), ( Xtype = sequential,!, make_CGE_phrase( Ytype, Ycode, YVars, CGE,I,G), ( var(Ycode),!, Conjuncts = (Xcode,CGE) ; YVars = [],!, Conjuncts = (Xcode,Ycode) ; Conjuncts = (Xcode,(CGE,Ycode)) ), BagofVars = [], Type = sequential ; Ytype = sequential,!, Conjuncts = Ycode, BagofVars = XVars, Type = Xtype ; Conjuncts = Ycode, append( XVars,YVars, BagofVars), Type = Xtype ).
content may be truncated. 'popout' for larger text window.