JaMControlImpl.mesa
Copyright © 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
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]]];
};
Array
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];
Dict
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];
Exec
Primitive[".if", ApplyIf];
Primitive[".ifelse", ApplyIfElse];
Primitive[".rept", ApplyRept];
Primitive[".for", ApplyFor];
Primitive[".loop", ApplyLoop];
Primitive[".exit", ApplyExit];
Primitive[".stop", ApplyStop];
Primitive[".exec", ApplyExec];
IO
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];
Math
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];
Misc
Primitive[".type", ApplyType];
Primitive[".length", ApplyLength];
Primitive[".cvlit", ApplyCvLit];
Primitive[".cvx", ApplyCvX];
Primitive[".cvi", ApplyCvI];
Primitive[".cvr", ApplyCvR];
Primitive[".commandname", ApplyCommandName];
Primitive[".nice", ApplyNicePriority];
Rope
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[".cvrs", ApplyConvertToRadixString];
Primitive[".cvos", ApplyConvertOctalString];
Stack
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.