MODULE*************************************************************************** Wrapper for AnimHandle.T ***************************************************************************; IMPORT AnimHandle, AnimHandleProxy, ObAux, ObCommand, ObLib, ObProtoLoader, ObProxiedObj, ObValue, Obliq, ProxiedObj, SynLocation; CONST pkgname = "AnimHandle"; ObAnimHandle
TYPE T = ObProxiedObj.T BRANDED OBJECT END; PROCEDURE*************************************************************************** Setup procedures ***************************************************************************AddTObj (ah : AnimHandle.T) = <* FATAL ObValue.Error, ObValue.Exception *> BEGIN WITH obj = Obliq.ObjectClone (Obliq.Vals {TProto}), raw = NEW (T, what := "<an AnimHandle.T>", po := ah) DO Obliq.ObjectUpdate (obj, "raw", raw); ah.proxy := NEW (ProxiedObj.Proxy, obj := obj); END; END AddTObj; PROCEDUREGetT (args : ObValue.ArgArray; idx : INTEGER; package : ObLib.T; opCode : ObLib.OpCode; loc : SynLocation.T) : AnimHandle.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 GetT;
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 := NEW (REF OpCodes, NUMBER (Code)); BEGIN opCodes^ := OpCodes { NewOpCode ("New", 0, Code.New), NewOpCode ("Animate", 1, Code.Animate) }; ObLib.Register (NEW (Package, name := pkgname, opCodes := opCodes)); ObLib.RegisterHelp (pkgname, Help); END SetupPackage; VAR TProto : ObValue.Val; PROCEDURESetupModule (loader : ObProtoLoader.T) = BEGIN (*** retrieve the prototype ***) loader.load ("AnimHandle.obl"); TProto := loader.get ("AnimHandle_TProto"); (*** Register the proxy makers ***) AnimHandleProxy.MkProxyT := AddTObj; END SetupModule;
TYPE Code = {New, Animate}; OpCode = ObLib.OpCode BRANDED OBJECT code: Code; END; Package = ObLib.T BRANDED 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.New => WITH val = AnimHandle.New () DO RETURN val.proxy.obj; END; | Code.Animate => WITH ah = GetT (args, 1, self, opCode, loc) DO ah.animate (); RETURN ObValue.valOk; END; END; END DoEval;
PROCEDUREHelp (self : ObCommand.T; arg : TEXT; <* UNUSED *> data : REFANY) = BEGIN ObAux.Help (self, arg, pkgname); END Help; BEGIN END ObAnimHandle.