<<>> <> <> <> DIRECTORY Rope USING [ROPE], Scheme; SchemePrivate: CEDAR DEFINITIONS ~ BEGIN OPEN Scheme; <> PairSeq: TYPE ~ REF PairSeqRep; PairSeqRep: TYPE ~ RECORD [pairs: SEQUENCE length: NAT OF Pair]; Readable: TYPE ~ REF ANY; -- A ROPE, REF TEXT, String or ATOM, to coerce into a symbol. LookupCell: PROC [env: Environment, name: Any] RETURNS [Pair]; CloseProcedure: PROC [p: Any, env: Environment] RETURNS [TidbitProcedure]; <

> ReadRopeVector: PROC [rope: Rope.ROPE] RETURNS [SimpleVector]; SV1: PROC [Any] RETURNS [SimpleVector]; SV2: PROC [Any, Any] RETURNS [SimpleVector]; SV3: PROC [Any, Any, Any] RETURNS [SimpleVector]; SV4: PROC [Any, Any, Any, Any] RETURNS [SimpleVector]; SV5: PROC [Any, Any, Any, Any, Any] RETURNS [SimpleVector]; SV6: PROC [Any, Any, Any, Any, Any, Any] RETURNS [SimpleVector]; SV7: PROC [Any, Any, Any, Any, Any, Any, Any] RETURNS [SimpleVector]; MakeTidbitCode: PROC [ identifiers: Rope.ROPE, -- name, followed by 2 lists in read form: local names, then global names env: Environment, -- global environment nArgs: INTEGER, -- number of arguments, including rest; negative if dotted. proc: TidbitCodeProc, -- the implementation procedure literals: Any, -- A SimpleVector or a LIST OF REF; use SV*, above initialPC: INTEGER, -- the initial pc for this procedure doc: Rope.ROPE, -- documentation ext: REF ¬ NIL -- for extensions (such as debugging info) ] RETURNS [TidbitCode]; DefineProcedure: PROC [name: Rope.ROPE, nArgs: NAT, envNames: LIST OF REF, dotted: BOOL, proc: TidbitCodeProc, doc: Rope.ROPE, env: Environment, lexicalEnv: Environment ¬ NIL, initialPC: INTEGER ¬ 0, globalNames: LIST OF REF ¬ NIL, literals: SimpleVector ¬ NIL, optional: NAT ¬ 0]; <> TidbitProcedure: TYPE ~ REF TidbitProcedureRep; TidbitProcedureRep: TYPE ~ RECORD [ code: TidbitCode, env: Environment -- The procedure's enclosing environment ]; TidbitCode: TYPE ~ REF TidbitCodeRep; TidbitCodeRep: TYPE ~ RECORD [ name: Any, -- for debugging purposes envNames: SimpleVector, -- of Symbols dotted: BOOL, -- if TRUE, allow extra args minArgs: NAT, -- minimum number of args maxArgs: NAT, -- max. number of args, not including rest proc: TidbitCodeProc, -- the implementation procedure globalBindings: PairSeq, -- The global bindings referred to by this procedure literals: SimpleVector, -- The random constants referred to by this procedure initialPC: INTEGER, -- the initial pc for this procedure doc: Rope.ROPE, -- documentation ext: REF -- for extensions (such as debugging info) ]; TidbitCodeProc: TYPE ~ PROC [a: Activation]; <> <> <> <> <> <> <> <> < 0, then a.s[a.bottom] contains a procedure to be applied to the arguments in a.s[a.bottom+1] ... a.s[a.bottom+a.n-1]>> < 0, this is a tail call.>> <> <=smallActivationSize.>> smallActivationSize: NAT ~ 20; Stack: TYPE ~ REF StackRep; StackRep: TYPE ~ ARRAY [0..smallActivationSize) OF Any; Activation: TYPE ~ REF ActivationRep; ActivationRep: TYPE ~ RECORD [ link: Activation, -- For linking these together env: Environment, -- This procedure's local environment (not the one it is closed in) fluidBindings: Any, -- The fluid variable environment code: TidbitCode, -- self shared: BOOL ¬ FALSE, -- if TRUE, copy-on-write bottom: NAT, -- Index into s of proc & args n: NAT, -- Number of things to Apply (including proc); zero => don't apply pc: INTEGER, -- program counter used by SELECT in TidbitCodeProc; -1 => don't continue s: Stack, -- stack for evaluated arguments sEx: SimpleVector ¬ NIL -- stack extension for overflow from s ]; <> <> <> <> <> Opcode: TYPE ~ MACHINE DEPENDENT { enterB, enterH, <> <> call0, call1, call2, call3, callB, callH, <> < result>> <> tailCall0, tailCall1, tailCall2, tailCall3, tailCallB, tailCallH, <> <> jumpB, jumpH, <> <> tJumpB, tJumpH, <> <>> <> fJumpB, fJumpH, <> <>> <> pushLiteral1, pushLiteral2, pushLiteral3, pushLiteral4, pushLiteralB, pushLiteralH, <> <<=> val>> <> pushGlobal0, pushGlobal1, pushGlobal2, pushGlobal3, pushGlobalB, pushGlobalH, <> <<=> val>> <> pushLocal0B, pushLocalBB, pushLocalBH, <> <<=> val>> <> pop, <> <>> <> popGlobalB, popGlobalH, <> <>> <> popLocalBB, popLocalBH, <> <>> <> closeB, closeH, <> <<=> fn>> <> return <> <> }; ByteCodes: TYPE ~ REF ByteCodesRep; ByteCodesRep: TYPE ~ RECORD [PACKED SEQUENCE size: NAT OF BYTE]; ByteCodeTemplate: TYPE ~ REF ByteCodeTemplateRep; <> ByteCodeTemplateRep: TYPE ~ RECORD [ name: Any, -- for debugging purposes envNames: SimpleVector, -- of symbols dotted: BOOL, -- if TRUE, allow extra args minArgs: NAT, -- minimum number of args maxArgs: NAT, -- max. number of args, not including rest globalNames: ProperList, -- list of symbols, the globals referenced in this procedure literals: ProperList, -- literals[0] should be a ByteCodes object, the code itself. The other literals may include other ByteCodeTemplates representing nested procedures. doc: Rope.ROPE, -- documentation ext: Any -- for extensions (such as debugging info) ]; ProcedureFromByteCodeTemplate: PROC [template: ByteCodeTemplate, env: Environment] RETURNS [Procedure]; END.