MODULE*************************************************************************** Setup procedures ***************************************************************************; IMPORT ObAux, ObCommand, ObLib, ObValue, Obliq, SynLocation, Time; CONST pkgname = "Time"; ObTime
PROCEDURE*************************************************************************** Execution machinery ***************************************************************************SetupPackage () = PROCEDURE NewOpCode (name: TEXT; arity: INTEGER; code: Code) : OpCode = BEGIN RETURN NEW (OpCode, name := name, arity := arity, code := code); END NewOpCode; TYPE OpCodes = ARRAY OF ObLib.OpCode; VAR opCodes: REF OpCodes; BEGIN opCodes := NEW (REF OpCodes, NUMBER (Code)); opCodes^ := OpCodes {NewOpCode ("Now", 0, Code.Now)}; ObLib.Register (NEW (Package, name := pkgname, opCodes := opCodes)); ObLib.RegisterHelp (pkgname, Help); END SetupPackage;
TYPE Code = {Now}; OpCode = ObLib.OpCode OBJECT code: Code; END; Package = ObLib.T OBJECT OVERRIDES Eval := DoEval; END; PROCEDURE*************************************************************************** Help ***************************************************************************DoEval (<* UNUSED *> self : Package; opCode : ObLib.OpCode; <* UNUSED *> arity : ObLib.OpArity; <* UNUSED *> READONLY args: ObValue.ArgArray; <* UNUSED *> temp : BOOLEAN; <* UNUSED *> loc : SynLocation.T) : ObValue.Val = BEGIN CASE NARROW (opCode, OpCode).code OF | Code.Now => RETURN Obliq.NewReal (Time.Now ()); END; END DoEval;
PROCEDUREHelp (self : ObCommand.T; arg : TEXT; <* UNUSED *> data : REFANY) = BEGIN ObAux.Help (self, arg, pkgname); END Help; BEGIN END ObTime.