INTERFACECompile Juno expressions, predicates, functions, and procedures.JunoCompile ;
Each of the compilation procedures in this interface takes a JunoAST.T to
compile and a JunoScope.T scope
that is used to resolve free variables.
Each has the side-effect of decorating its argument AST, and each raises
Error
in the event of a compilation error.
Compiling a Juno predicate, function, or procedure is a two-step process.
Clients must first call NewPred
, NewFunc
, or NewProc
to transform the
declaration AST into a JunoScope.Entity
. They should then pass that
entity to PredDecl
, FuncDecl
, or ProcDecl
, respectively, to install a
bytestream in the run-time code table.
These procedures are re-entrant; they use an internal mutex to guarantee serialization.
IMPORT JunoAST, JunoScope, JunoRT; FROM JunoCompileErr IMPORT Error; IMPORT Wr, Rd; PROCEDURE Expr( expr: JunoAST.Expr; scp: JunoScope.T; nm: JunoAST.Id; VAR (*OUT*) val_slot: CARDINAL; pure := FALSE): JunoRT.ByteStream RAISES {Error};
Setsval_slot
and returns the bytestream of a command compiled underscp
that, when executed, stores the value of the expressionexpr
inJunoRT.value_tbl[val_slot]
.nm
is printed in debugging output for this compilation. Ifpure
isTRUE
andexpr
references a global variable or procedure, then raisesError
.
PROCEDURE PredDecl(nm: JunoAST.Id; pred: JunoScope.Pred; scp: JunoScope.T) RAISES {Error};
Compile the predicate with signature and body determined frompred
usingscp
to resolve all its free variables, and place the resulting code inJunoRT.code_tbl[pred.index]
.nm
is printed in debugging output for this compilation.By
compiling a predicate
, we mean: 1) installing the normal form for the predicate body in theJunoScope.Pred
entity corresponding tonm
inscp
, and 2) compiling the query(body)?()
-- wherebody
is the predicate body -- with all IN arguments to the predicate assumed to be known variables.
PROCEDURE FuncDecl(nm: JunoAST.Id; func: JunoScope.Func; scp: JunoScope.T) RAISES {Error};
Compile the function with signature and body determined fromfunc
usingscp
to resolve all its free variables, and place the resulting code inJunoRT.code_tbl[func.index]
.nm
is printed in debugging output for this compilation.By
compiling a function
, we mean: 1) installing the normal form for the function body in theJunoScope.Func
entity corresponding tonm
inscp
, and 2) compiling the query(body)?(res)
-- wherebody
is the function body andres
is its single OUT parameter -- with all IN arguments to the function assumed to be known variables.
PROCEDURE ProcDecl(nm: JunoAST.Id; proc: JunoScope.Proc; scp: JunoScope.T): JunoAST.Cmd RAISES {Error};
Compile the procedure with signature and body determined fromproc
usingscp
to resolve all its free variables, and place the resulting code inJunoRT.code_tbl[proc.index]
.nm
is printed in debugging output for this compilation. Return the command produced by the front-end of the compiler that is to be fed into the back-end (assembler).
PROCEDURE SaveSlots(wr: Wr.T);
Write towr
the indexes of any internalJunoRT
slots that are stored in the compiler or assembler.
PROCEDURE RestoreSlots(rd: Rd.T);
Read fromwr
the indexs stored bySaveSlots
, and set the internal slots to the values read.
END JunoCompile.