MODULE*************************************************************************** Wrapper for ProxiedObj.T ***************************************************************************; IMPORT ObAux, ObCommand, ObLib, ObProtoLoader, ObValue, Obliq, ProxiedObj, SynLocation; CONST pkgname = "ProxiedObj"; ObProxiedObj
REVEAL T = Public BRANDED "ObProxiedObj.T" OBJECT OVERRIDES Is := IsT; END; PROCEDURE*************************************************************************** Setup procedures ***************************************************************************IsT (self: T; other: ObValue.ValAnything): BOOLEAN = BEGIN TYPECASE other OF T (oth) => RETURN self.po = oth.po; ELSE RETURN FALSE END; END IsT; PROCEDUREGetArg (args : ObValue.ArgArray; idx : INTEGER; package : ObLib.T; opCode : ObLib.OpCode; loc : SynLocation.T) : ProxiedObj.T RAISES {ObValue.Error, ObValue.Exception} = BEGIN WITH raw = Obliq.ObjectSelect (args[idx], "raw") DO TYPECASE raw OF | T (node) => RETURN node.po; ELSE ObValue.BadArgType (idx, pkgname, package.name, opCode.name, loc); RETURN NIL; (* ... only to suppress compiler warning *) END; END; END GetArg;
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 ("Extend", 2, Code.Extend) }; ObLib.Register (NEW (Package, name := pkgname, opCodes := opCodes)); ObLib.RegisterHelp (pkgname, Help); END SetupPackage; PROCEDURESetupModule (loader : ObProtoLoader.T) = BEGIN loader.load ("ProxiedObj.obl"); END SetupModule;
TYPE Code = {Extend}; OpCode = ObLib.OpCode OBJECT code: Code; END; Package = ObLib.T OBJECT OVERRIDES Eval := DoEval; END; PROCEDURE*************************************************************************** Help ***************************************************************************DoEval (self : Package; opCode : ObLib.OpCode; <* UNUSED *> arity : ObLib.OpArity; READONLY args: ObValue.ArgArray; <* UNUSED *> temp : BOOLEAN; loc : SynLocation.T) : ObValue.Val RAISES {ObValue.Error, ObValue.Exception} = BEGIN CASE NARROW (opCode, OpCode).code OF | Code.Extend => WITH po = GetArg (args, 1, self, opCode, loc), proxy = po.proxy DO proxy.obj := Obliq.ObjectClone (Obliq.Vals {proxy.obj, args[2]}); RETURN proxy.obj; END; END; END DoEval;
PROCEDUREHelp (self : ObCommand.T; arg : TEXT; <* UNUSED *> data : REFANY) = BEGIN ObAux.Help (self, arg, pkgname); END Help; BEGIN END ObProxiedObj.