DIRECTORY JaM USING [Any, Begin, Command, CommandRep, Def, Dict, NewDict, NewStack, Put, ROPE, RopeToAtom, State, StateRep, STREAM, TryToLoad, TryToGet, PopRope, Error], JaMPrimitives --USING everything--; JaMControlImpl: CEDAR PROGRAM IMPORTS JaM, JaMPrimitives EXPORTS JaM = BEGIN OPEN JaMPrimitives, JaM; sysDict: PUBLIC Dict _ NewDict[200]; Create: PUBLIC PROC[out: STREAM] RETURNS[State] = { self: State = NEW[StateRep _ [stack: NewStack[], dictstk: NIL, out: out]]; Begin[self, sysDict]; RETURN[self]; }; RegisterInit: PUBLIC PROC[name: ROPE, init: PROC[State]] = { atom: ATOM = RopeToAtom[name]; found: BOOL; val: Any; initProcs: Dict _ GetInitProcs[]; [found, val] _ TryToGet[initProcs, atom]; IF found THEN WITH val SELECT FROM x: Command => x.proc _ init; ENDCASE ELSE Put[dict: initProcs, key: atom, val: NEW[CommandRep _ [proc: init, name: atom]]]; }; GetInitProcs: PROC RETURNS[Dict] = { found: BOOL; val: Any; [found, val] _ TryToGet[sysDict, RopeToAtom[".initprocs"]]; IF ~found THEN ERROR; RETURN[NARROW[val]]; }; CallInit: PROC[state: State] = { atom: ATOM _ RopeToAtom[PopRope[state]]; initProcs: Dict _ GetInitProcs[]; found: BOOL; val: Any; [found, val] _ TryToGet[initProcs, atom]; IF found THEN WITH val SELECT FROM x: Command => x.proc[state]; ENDCASE => Error[WrongType] ELSE Error[UndefinedKey, "initialization procedure not found"]; }; Register: PUBLIC PROC[self: State, name: ROPE, proc: PROC[State]] = { found: BOOL; val: Any; atom: ATOM = RopeToAtom[name]; [found, val] _ TryToLoad[self, atom]; IF found THEN WITH val SELECT FROM x: Command => { x.proc _ proc; RETURN }; ENDCASE; Def[self, atom, NEW[CommandRep _ [atom, proc]]]; }; Object: PROC[name: ROPE, x: Any] = { Put[sysDict, RopeToAtom[name], x]; }; Primitive: PROC[name: ROPE, proc: PROC[State]] = { atom: ATOM = RopeToAtom[name]; Put[sysDict, atom, NEW[CommandRep _ [atom, proc]]]; }; Primitive[".array", ApplyArray]; Primitive[".aget", ApplyAGet]; Primitive[".aput", ApplyAPut]; Primitive[".subarray", ApplySubArray]; Primitive[".arrayforall", ApplyArrayForAll]; Primitive[".astore", ApplyAStore]; Primitive[".aload", ApplyALoad]; Primitive[".abind", ApplyABind]; Primitive[".afind", ApplyAFind]; Primitive[".dict", ApplyDict]; Primitive[".known", ApplyKnown]; Primitive[".where", ApplyWhere]; Primitive[".get", ApplyGet]; Primitive[".put", ApplyPut]; Primitive[".def", ApplyDef]; Primitive[".load", ApplyLoad]; Primitive[".store", ApplyStore]; Primitive[".del", ApplyDel]; Primitive[".begin", ApplyBegin]; Primitive[".end", ApplyEnd]; Primitive[".dictforall", ApplyDictForall]; Primitive[".curdict", ApplyCurDict]; Primitive[".attachdict", ApplyAttachDict]; Primitive[".detachdict", ApplyDetachDict]; Primitive[".attachedforall", ApplyAttachedForall]; Primitive[".detachall", ApplyDetachAll]; Primitive[".if", ApplyIf]; Primitive[".ifelse", ApplyIfElse]; Primitive[".rept", ApplyRept]; Primitive[".for", ApplyFor]; Primitive[".loop", ApplyLoop]; Primitive[".exit", ApplyExit]; Primitive[".stop", ApplyStop]; Primitive[".exec", ApplyExec]; Primitive[".run", ApplyRun]; Primitive[".stream", ApplyStream]; Primitive[".readitem", ApplyReadItem]; Primitive[".writeitem", ApplyWriteItem]; Primitive[".writebytes", ApplyWriteBytes]; Primitive[".killstream", ApplyKillStream]; Primitive[".print", ApplyPrint]; Primitive[".loadbcd", ApplyLoadBCD]; Object[".searchrules", NIL]; Primitive[".iochar", ApplyIOChar]; Primitive[".iobool", ApplyIOBool]; Primitive[".ioint", ApplyIOInt]; Primitive[".ioreal", ApplyIOReal]; Primitive[".ioline", ApplyIOLine]; Primitive[".iotoken", ApplyIOToken]; Primitive[".iocedartoken", ApplyIOCedarToken]; Primitive[".ioclose", ApplyIOClose]; Primitive[".add", ApplyAdd]; Primitive[".sub", ApplySub]; Primitive[".mul", ApplyMul]; Primitive[".div", ApplyDiv]; Primitive[".idiv", ApplyIDiv]; Primitive[".neg", ApplyNeg]; Primitive[".sin", ApplySin]; Primitive[".cos", ApplyCos]; Primitive[".atan", ApplyATan]; Primitive[".exp", ApplyExp]; Primitive[".log", ApplyLog]; Primitive[".sqrt", ApplySqRt]; Primitive[".eq", ApplyEq]; Primitive[".lt", ApplyLt]; Primitive[".gt", ApplyGt]; Primitive[".not", ApplyNot]; Primitive[".and", ApplyAnd]; Primitive[".or", ApplyOr]; Primitive[".xor", ApplyXor]; Primitive[".bitnot", ApplyBitNot]; Primitive[".bitand", ApplyBitAnd]; Primitive[".bitor", ApplyBitOr]; Primitive[".bitxor", ApplyBitXor]; Primitive[".bitshift", ApplyBitShift]; Primitive[".type", ApplyType]; Primitive[".length", ApplyLength]; Primitive[".cvlit", ApplyCvLit]; Primitive[".cvx", ApplyCvX]; Primitive[".cvi", ApplyCvI]; Primitive[".cvr", ApplyCvR]; Primitive[".commandname", ApplyCommandName]; Primitive[".nice", ApplyNicePriority]; Primitive[".ropeconcat", ApplyConcat]; Primitive[".substring", ApplySubstr]; Primitive[".sget", ApplySGet]; Primitive[".search", ApplySearch]; Primitive[".asearch", ApplyASearch]; Primitive[".cvs", ApplyConvertToString]; --converts any value to a string Primitive[".pop", ApplyPop]; Primitive[".copy", ApplyCopy]; Primitive[".dup", ApplyDup]; Primitive[".roll", ApplyRoll]; Primitive[".exch", ApplyExch]; Primitive[".count", ApplyCount]; Primitive[".index", ApplyIndex]; Primitive[".mark", ApplyMark]; Primitive[".cnttomrk", ApplyCountToMark]; Object[".sysdict", sysDict]; Object[".true", NEW[INT _ 1]]; Object[".false", NEW[INT _ 0]]; Primitive[".undefkey", ApplyPop]; Object[".initprocs", NewDict[100]]; Primitive[".callinit", CallInit]; END. 8JaMControlImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Maureen Stone, February 14, 1985 7:32:14 pm PST Doug Wyatt, March 18, 1985 3:33:58 pm PST Array Dict Exec IO Math Misc Rope Primitive[".cvrs", ApplyConvertToRadixString]; Primitive[".cvos", ApplyConvertOctalString]; Stack Κ˜codešœ™Kšœ Οmœ1™