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
/
CMPLIB
/
CMPLIB_SRC
/
$compile1.P
< prev
next >
Wrap
Text File
|
1991-08-10
|
8KB
|
221 lines
/* *****************************************************************
* *
* 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.
------------------------------------------------------------------ */
/* This Prolog program is a first attempt to take an input Prolog program in
a simple syntax, relatively close to standard Prolog, and to output an
annotated term, with pragmas attached, so that the pilgen translator can
generate correct intermediate code.
The input clauses will be read (using Prolog's read command) one at a time
from standard input (for now), until end-of-file is reached.
During the translation of a clause, a Symbol Table (St) is constructed. It
contains information on each occurrence of a variable in the clause, as
follows. It is a record st(Clist,Vlist); where Clist is the list of records
c(Litno,Npars,Pragma) where Litno is the number of the literal on the rhs of
the rule, Npars is the number of arguments to that literal, and Pragma is
the pragma associated with the _call record for that literal in the clause;
Vlist is a list of records, v(id,Occlist), one for each variable; where id
the unique identifier for the variable, and Occlist is a list of occurrence
records, o(Occno,Litno,Argno,Context,Pragma), one for each occurrence of the
variable in the clause; where Occno uniquely determines the occurrence of
this variable; Litno is the number of the literal (0=head, 1=first on
rhs,...); Argno is the number of the argument in which it appears (starting
with 1) Context is `s' if it is in a structure and `t' if it is at the top
level; and Pragma is the list that is the Pragma for the occurrence of the
variable in the code.
*/
$compile_export([$compile/0,$compile/1,$compile/2,$compile/3,$compile/4]).
$compile_use($name,[$name/2,_]).
$compile_use($blist,[$append/3,$member/2,$member1/2]).
$compile_use($bio,[$writename/1,$writeqname/1,$put/1,$nl/0,$tab/1,$tell/1,
$telling/1,$told/0,$get/1,$get0/1,$see/1,$seeing/1,$seen/0]).
$compile_use($bmeta,[$atom/1,$atomic/1,$integer/1,$number/1,$structure/1,
$functor0/2,$bldstr/3,$arg/3,$arity/2,$real/1,$floor/2]).
$compile_use($prag,[$get_prag/2]).
$compile_use($osys,[$cputime/1,_,_,_]).
$compile_use($compare,['$=='/2,_,_,_,_,_,_]).
/* **********************************************************************
$compile_use($aux1,[$roundtosq/2,$get_compiletime/2,$message1/1,
$output_msg/3,$umsg/1,$name_aslfile/2,_,_,_]).
$compile_use($translate1,[$translateasm/3,$translate/3]).
********************************************************************** */
$compile :- $writename('compile: Usage: compile(<inputfile> [,<outputfile>, [,<option>] ])'), $nl.
$compile(InFile) :-
$atomic(InFile) ->
($name(InFile,Fname),
$append(Fname,".out",OFname),
$name(OutFile,OFname),
$compile_default_opts(Options),
$compile0(InFile,OutFile,Options,_)
) ;
($writename('*** Error: filenames must be atomic! ***'),
$nl,
abort
).
$compile(InFile,Opt2) :-
$atomic(InFile) ->
($atomic(Opt2), !, /* Opt2 is filename */
$compile_default_opts(Options),
$compile0(InFile,Opt2,Options,_)
) ;
($writename('*** Error: input filename must be atomic! ***'),
$nl,
abort
).
$compile(InFile,Opt2) :- /* Opt2 is Options */
$atomic(InFile) ->
($name(InFile,Fname),
$append(Fname,".out",OFname),
$name(OutFile,OFname),
$compile0(InFile,OutFile,Opt2,_)
) ;
($writename('*** Error: input filename must be atomic! ***'),
$nl,
abort
).
$compile(InFile, Opt1, Opt2) :-
$atomic(Opt1), !, /* Opt1 is filename */
$compile0(InFile,Opt1,Opt2,_).
$compile(InFile, Opt1, Opt2) :-
$atomic(Opt2), !, /* Opt2 is filename */
$compile0(InFile,Opt2,Opt1,_).
$compile(InFile, Opt1, Opt2) :-
$writename('*** Error: output filename must be atomic! ***'),
$nl,
abort.
$compile(InFile, Opt1, Opt2,PredList) :-
$atomic(Opt1), !, /* Opt1 is filename */
$compile0(InFile,Opt1,Opt2,PredList).
$compile(InFile, Opt1, Opt2,PredList) :-
$atomic(Opt2), !, /* Opt2 is filename */
$compile0(InFile,Opt2,Opt1,PredList).
$compile(InFile, Opt1, Opt2,_) :-
$writename('*** Error: output filename must be atomic! ***'),
$nl,
abort.
/* default_opts([v]). */
$compile_default_opts([]).
/* translate */
$compile0(InFile, OutFile, Options, PredList) :-
$exists(InFile) -> $compile1(InFile,OutFile,Options,PredList) ;
$umsg(['*** No such file:',InFile]).
$compile1(InFile, OutFile, Options, PredList) :-
$cputime(X1),
(
($member(a,Options),!, /* create intermediate .asl file */
$message1(Options),
$name_aslfile(InFile, OutFile1),
$compile_gen_PIL(InFile,OutFile1,Options,PredList),
$asm(OutFile1,OutFile,Options)
) ;
$compile_gen_BC(InFile,OutFile,Options,PredList)
),
$tell(user),
$cputime(X2),
CTime is X2 - X1, $get_compiletime(CTime,Time),
$writename('compilation complete -- '),
$writename(Time),$writename(' secs'),$nl.
$compile_gen_PIL(InFile, OutFile1, Options,PredList) :-
$getclauses(InFile,Prog,PredList),
$compile_getprag(InFile,Options,Prag),
$compile_getmodes(Prog,Options,Prag,PredList,NProg0,NProg1,Modes),
$compile_getfunc(NProg1,Options,Modes,PredList,FPreds),
/* ********************
$compile_factor(Prog,IndexArg,Modes,Prog1),
******************** */
Prog = Prog1,
$tell(OutFile1),
!,
$compile_transl_preds(Prog1,Options,Prag),
$told.
$compile_transl_preds(ClauseList,Options,Prag) :-
$member(PredDef, ClauseList),
PredDef = pred(P,N,_,_,_),
$output_msg(P,N,Options),
$translate(PredDef,Options,Prag),
fail.
$compile_transl_preds(_,_,_).
$compile_gen_BC(InFile, OutFile, Options,PredList) :-
$getclauses(InFile,Prog,PredList),
$compile_getprag(InFile,Options,Prag),
$compile_getmodes(Prog,Options,Prag,PredList,NProg0,NProg1,Modes),
$compile_getfunc(NProg1,Options,Modes,PredList,FPreds),
/* ********************
$compile_factor(Prog,IndexArg,Modes,Prog1),
******************** */
Prog = Prog1,
$tell(OutFile),
$compile_translasm_preds(Prog1,Options,Prag),
$told.
$compile_translasm_preds(ClauseList,Options,Prag) :-
$member(PredDef, ClauseList),
PredDef = pred(P,N,_,_,_),
$output_msg(P,N,Options),
$translateasm(PredDef,Options,Prag),
fail.
$compile_translasm_preds(_,_,_).
$compile_pragma_reqd(Options) :- $member1(m,Options).
$compile_pragma_reqd(Options) :- $member1(i,Options).
$compile_pragma_reqd(Options) :- $member1(f,Options).
$compile_getprag(InFile,Options,Prag) :-
$compile_pragma_reqd(Options) ->
$get_prag(InFile,Prag) ;
Prag = [].
$compile_getmodes(Prog,Options,Prag,PredList,NProg0,NProg1,Modes) :-
($member1(m,Options) ; $member1(f,Options)) ->
($transform(Prog,NProg0,NProg1,AffList),
$mode_inf(NProg0,Options,Prag,AffList,PredList,Modes)
) ;
(Modes = [], NProg = Prog).
$compile_getfunc(Prog,Options,Modes,PredList,FPreds) :-
($member1(f, Options) ->
func_inf(Prog,Options,Modes,PredList,FPreds) ;
FPreds = []).
/* ---------------------------- $compile1.P ---------------------------- */