INTERFACEJunoAssemble ; IMPORT JunoRT, JunoScope, JunoCompileRep; TYPE CmdType = { Pred, Func, Proc }; PROCEDURE Cmd( cmd: JunoCompileRep.Result; scp: JunoScope.T; temp_cnt: CARDINAL; type: CmdType): JunoRT.ByteStream;
Returns the byte-code program produced by assembling the compilation resultcmd
under the scopescp
. The first instruction in the resulting stream increments the stack pointer bytemp_cnt
locations in order to make space for temporary (local) variables.The
type
reflects the kind of declaration in which this command is being compiled. Each type makes certain assumptions about the input commandcmd
, and handles run-time errors and the state of the machine on return differently. In particular:
type = CmdType.Pred
ORtype = CmdType.Func
=>Cmd
may be a partial command, but it is required not to abort. Execution of the resulting bytestream is guaranteed to terminate with the machine's condition bit set iffGrd(cmd) # FALSE
.
type = CmdType.Proc
, => Requires thatcmd
be a total command. Ifcmd
aborts, the resulting bytestream will execute the run-time bytecodeJunoByteCode.ERROR
with the appropriate argument (encounteredABORT
,IF..FI
failure, or undefined term).This procedure has the side-effect of setting the
start
andend
fields of every AST node of the ASTcmd.cmd
. Each noden
is annotated such that the half-open interval[n.start, n.end)
is the largest interval containing the PC locations corresponding the assembly instructions forn
.
END JunoAssemble.