TJaMOps.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Last changed by Wyatt, 24-Oct-81 15:18:05
Last changed by Paxton, 30-Jan-82 8:49:44
Michael Plass, February 14, 1985 12:24:11 pm PST
DIRECTORY
TJaMBasic USING [Object, Root, StringLength, Tag],
TJaMInternal USING [Cache, Frame, Locals, Node, Stack],
TJaMStreamDefs USING [StreamHandle];
TJaMOps: DEFINITIONS = {
Types and Constants
StreamHandle: TYPE = TJaMStreamDefs.StreamHandle;
Text: TYPE = LONG STRING;
nullOb: TJaMBasic.Object = [X,null[]];
Signals and Errors
Error: ERROR[error: TJaMBasic.Object];
StackOverflow: ERROR[stack: TJaMInternal.Stack];
Bug: ERROR;
Assert: PROC[pred: BOOLEAN] = INLINE { IF NOT pred THEN ERROR Bug };
Commonly-used error names
rangechk,typechk,undefname,limitchk: name TJaMBasic.Object;
Stack operations
Top: PROC[stack: TJaMInternal.Stack] RETURNS[TJaMBasic.Object] = INLINE {
node: TJaMInternal.Node ← stack.head; IF node=NIL THEN Underflow[stack];
RETURN[node.ob]
};
Pop: PROC[stack: TJaMInternal.Stack] RETURNS[TJaMBasic.Object] = INLINE {
node: TJaMInternal.Node ← stack.head; IF node=NIL THEN Underflow[stack];
stack.head ← node.next; node.next ← stack.free;
stack.free ← node; RETURN[node.ob]
};
Push: PROC[stack: TJaMInternal.Stack, ob: TJaMBasic.Object] = INLINE {
node: TJaMInternal.Node ← stack.free; IF node=NIL THEN Overflow[stack];
stack.free ← node.next; node.next ← stack.head;
stack.head ← node; node.ob ← ob
};
Underflow,Overflow: PROC[stack: TJaMInternal.Stack]; -- these never return
Empty: PROC[stack: TJaMInternal.Stack] RETURNS[BOOLEAN] = INLINE { RETURN[stack.head=NIL] };
Full: PROC[stack: TJaMInternal.Stack] RETURNS[BOOLEAN] = INLINE { RETURN[stack.free=NIL] };
GetMark: PROC[stack: TJaMInternal.Stack] RETURNS[TJaMInternal.Node] = INLINE { RETURN[stack.free] };
Restore: PROC[stack: TJaMInternal.Stack, mark: TJaMInternal.Node];
Copy: PROC[stack: TJaMInternal.Stack, n: CARDINAL];
Dup: PROC[stack: TJaMInternal.Stack] = INLINE { Copy[stack,1] };
Exch: PROC[stack: TJaMInternal.Stack];
Roll: PROC[stack: TJaMInternal.Stack, n,k: CARDINAL];
ClearStack: PROC[stack: TJaMInternal.Stack];
CountStack: PROC[stack: TJaMInternal.Stack, max: CARDINALLAST[CARDINAL]] RETURNS[CARDINAL];
CountToMark: PROC[stack: TJaMInternal.Stack] RETURNS[CARDINAL];
ClearToMark: PROC[stack: TJaMInternal.Stack];
Index: PROC[stack: TJaMInternal.Stack, i: CARDINAL] RETURNS[TJaMBasic.Object];
StackForAll: PROC[stack: TJaMInternal.Stack, proc: PROC[TJaMBasic.Object] RETURNS[BOOLEAN],
unwind: BOOLEANFALSE] RETURNS[BOOLEAN];
ArrayFromStack: PROC[stack: TJaMInternal.Stack] RETURNS[array TJaMBasic.Object];
NewStack: PROC[CARDINAL] RETURNS[TJaMInternal.Stack];
FreeStack: PROC[TJaMInternal.Stack];
Type-specific stack operations
PushCardinal: PROC[stack: TJaMInternal.Stack, c: CARDINAL] = INLINE { Push[stack,[L,integer[c]]] };
PushInteger: PROC[stack: TJaMInternal.Stack, i: LONG INTEGER] = INLINE { Push[stack,[L,integer[i]]] };
PushReal: PROC[stack: TJaMInternal.Stack, r: REAL] = INLINE { Push[stack,[L,real[r]]] };
PushBoolean: PROC[stack: TJaMInternal.Stack, b: BOOLEAN] = INLINE { Push[stack,[L,boolean[b]]] };
PopCardinal: PROC[stack: TJaMInternal.Stack, limit: CARDINAL ← 0] RETURNS[CARDINAL];
PopInteger: PROC[stack: TJaMInternal.Stack] RETURNS[LONG INTEGER];
PopReal: PROC[stack: TJaMInternal.Stack] RETURNS[REAL];
PopBoolean: PROC[stack: TJaMInternal.Stack] RETURNS[BOOLEAN];
PopString: PROC[stack: TJaMInternal.Stack] RETURNS[string TJaMBasic.Object];
PopArray: PROC[stack: TJaMInternal.Stack] RETURNS[array TJaMBasic.Object];
PopDict: PROC[stack: TJaMInternal.Stack] RETURNS[dict TJaMBasic.Object];
PopCommand: PROC[stack: TJaMInternal.Stack] RETURNS[command TJaMBasic.Object];
PopStream: PROC[stack: TJaMInternal.Stack] RETURNS[stream TJaMBasic.Object];
TopInteger: PROC[stack: TJaMInternal.Stack] RETURNS[LONG INTEGER];
TopDict: PROC[stack: TJaMInternal.Stack] RETURNS[dict TJaMBasic.Object];
Array operations
Array: PROC[length: CARDINAL] RETURNS[array TJaMBasic.Object];
ACopy: PROC[array: array TJaMBasic.Object, expand: CARDINAL ← 0] RETURNS[array TJaMBasic.Object];
SubArray: PROC[array: array TJaMBasic.Object, beg,len: CARDINAL] RETURNS[array TJaMBasic.Object];
PutArray: PROC[from: array TJaMBasic.Object, beg: CARDINAL, into: array TJaMBasic.Object];
APut: PROC[array: array TJaMBasic.Object, i: CARDINAL, ob: TJaMBasic.Object];
AGet: PROC[array: array TJaMBasic.Object, i: CARDINAL] RETURNS[TJaMBasic.Object];
AStore: PROC[stack: TJaMInternal.Stack, array: array TJaMBasic.Object];
ALoad: PROC[stack: TJaMInternal.Stack, array: array TJaMBasic.Object];
AFind: PROC[array: array TJaMBasic.Object, ob: TJaMBasic.Object] RETURNS[BOOLEAN,CARDINAL];
AAtom: PROC[array: array TJaMBasic.Object]
RETURNS[found: BOOLEAN, atom: TJaMBasic.Object, rem: array TJaMBasic.Object];
ABind: PROC[array: array TJaMBasic.Object, dict: dict TJaMBasic.Object];
ArrayForAll: PROC[array: array TJaMBasic.Object, proc: PROC[TJaMBasic.Object] RETURNS[BOOLEAN]]
RETURNS[BOOLEAN];
Dictionary operations
Dict: PROC[maxlen: CARDINAL] RETURNS[dict TJaMBasic.Object];
DictLength: PROC[dict: dict TJaMBasic.Object] RETURNS[CARDINAL];
Where: PROC[frame: TJaMInternal.Frame, key: TJaMBasic.Object] RETURNS[BOOLEAN,dict TJaMBasic.Object];
Get: PROC[dict: dict TJaMBasic.Object, key: TJaMBasic.Object] RETURNS[TJaMBasic.Object];
TryToGet: PROC[dict: dict TJaMBasic.Object, key: TJaMBasic.Object] RETURNS[BOOLEAN,TJaMBasic.Object];
Put: PROC[dict: dict TJaMBasic.Object, key, value: TJaMBasic.Object];
Def: PROC[frame: TJaMInternal.Frame, key, value: TJaMBasic.Object];
Load: PROC[frame: TJaMInternal.Frame, key: TJaMBasic.Object] RETURNS[TJaMBasic.Object];
TryToLoad: PROC[frame: TJaMInternal.Frame, key: TJaMBasic.Object] RETURNS[BOOLEAN,TJaMBasic.Object];
Store: PROC[frame: TJaMInternal.Frame, key, value: TJaMBasic.Object];
Del: PROC[dict: dict TJaMBasic.Object, key: TJaMBasic.Object];
ClrDict: PROC[dict: dict TJaMBasic.Object];
AttachDict: PROC[dict, adict: dict TJaMBasic.Object];
DetachDict: PROC[dict, adict: dict TJaMBasic.Object];
DetachAll: PROC[dict: dict TJaMBasic.Object];
Begin: PROC[frame: TJaMInternal.Frame, dict: dict TJaMBasic.Object];
End: PROC[frame: TJaMInternal.Frame];
NewCache: PROC RETURNS[TJaMInternal.Cache];
FreeCache: PROC[TJaMInternal.Cache];
Locals
GetLocalsTop: PROC[frame: TJaMInternal.Frame] RETURNS[CARDINAL] = INLINE {
RETURN[frame.locals.curlen]
};
SetLocalsTop: PROC[frame: TJaMInternal.Frame, top: CARDINAL] = INLINE {
frame.locals.curlen ← MIN[frame.locals.curlen,top]
};
DefineLocal: PROC[frame: TJaMInternal.Frame, key,value: TJaMBasic.Object];
LoadLocal: PROC[frame: TJaMInternal.Frame, key: TJaMBasic.Object] RETURNS[TJaMBasic.Object];
TryToLoadLocal: PROC[frame: TJaMInternal.Frame, key: TJaMBasic.Object] RETURNS[BOOLEAN,TJaMBasic.Object];
StoreLocal: PROC[frame: TJaMInternal.Frame, key,value: TJaMBasic.Object];
NewLocals: PROC RETURNS[TJaMInternal.Locals];
FreeLocals: PROC[TJaMInternal.Locals];
Key comparison
KeyName: PROC[key: TJaMBasic.Object] RETURNS[TJaMBasic.Object] = INLINE {
RETURN[WITH k:key SELECT FROM string => StringToName[k], ENDCASE => key]
};
Equality: TYPE = {nil,F,T}; -- nil (if incompatible types), False, or True
Compare: PROC[a,b: TJaMBasic.Object] RETURNS[Equality];
Equal: PROC[a,b: TJaMBasic.Object] RETURNS[BOOLEAN] = INLINE {
WITH a:a SELECT FROM name => WITH b:b SELECT FROM name => RETURN[a.id=b.id];
ENDCASE; ENDCASE; RETURN[Compare[a,b]=T]
};
Execution
Execute: PROC[TJaMInternal.Frame,TJaMBasic.Object];
Stop: PROC[TJaMInternal.Frame];
GetAbort: PROC[TJaMInternal.Frame] RETURNS[BOOLEAN];
SetAbort: PROC[TJaMInternal.Frame,BOOLEAN];
MarkLoop: PROC[frame: TJaMInternal.Frame];
UnmarkLoop: PROC[frame: TJaMInternal.Frame];
Names
NameToString: PROC[name TJaMBasic.Object] RETURNS[string TJaMBasic.Object];
StringToName: PROC[string TJaMBasic.Object,Text ← NIL] RETURNS[name TJaMBasic.Object];
CreateName: PROC[text: Text, tag: TJaMBasic.Tag ← X] RETURNS[name: name TJaMBasic.Object, known: BOOLEAN];
boolean is true if name already existed, false if was just created
MakeName: PROC[text: Text, tag: TJaMBasic.Tag ← X] RETURNS[name TJaMBasic.Object] = INLINE {
RETURN [CreateName[text,tag].name]
};
Strings
String: PROC[length: TJaMBasic.StringLength] RETURNS[string TJaMBasic.Object];
SCopy: PROC[string: string TJaMBasic.Object, expand: CARDINAL ← 0] RETURNS[string TJaMBasic.Object];
SubString: PROC[s: string TJaMBasic.Object, beg,len: CARDINAL] RETURNS[string TJaMBasic.Object];
PutString: PROC[from: string TJaMBasic.Object, beg: CARDINAL, into: string TJaMBasic.Object];
StringCompare: PROC[a,b: string TJaMBasic.Object] RETURNS[INTEGER];
MakeString: PROC[Text,TJaMBasic.Tag ← L] RETURNS[string TJaMBasic.Object];
StringText: PROC[string TJaMBasic.Object, Text];
StringForAll: PROC[string TJaMBasic.Object, PROC[CHARACTER] RETURNS[BOOLEAN]];
Scanning
StreamToken: PROC[frame: TJaMInternal.Frame, stream: StreamHandle]
RETURNS[found,error: BOOLEAN, token: TJaMBasic.Object];
StringToken: PROC[frame: TJaMInternal.Frame, ob: string TJaMBasic.Object]
RETURNS[found,error: BOOLEAN, token: TJaMBasic.Object, rem: string TJaMBasic.Object];
LineComplete: PROC[text: Text] RETURNS[BOOLEAN];
Streams
MakeStream: PROC[StreamHandle, TJaMBasic.Tag ← L] RETURNS[stream TJaMBasic.Object];
GetStream: PROC[stream TJaMBasic.Object] RETURNS[StreamHandle];
KillStream: PROC[stream TJaMBasic.Object];
Registration and control
root: READONLY LONG POINTER TO TJaMBasic.Root;
defaultFrame: READONLY TJaMInternal.Frame;
RegisterExplicit: PROC[frame: TJaMInternal.Frame, text: Text, proc: PROC[TJaMInternal.Frame]];
RegisterImplicit: PROC[frame: TJaMInternal.Frame, text: Text, proc: PROC[]];
RegisterInternal: PROC[text: Text, proc: PROC[TJaMInternal.Frame]] RETURNS[command TJaMBasic.Object];
ForEachFrame: PROC[PROC[TJaMInternal.Frame]];
ForEachFrameExcept: PROC[TJaMInternal.Frame,PROC[TJaMInternal.Frame]];
NewFrame: PROC RETURNS[TJaMInternal.Frame];
FreeFrame: PROC[TJaMInternal.Frame];
DoCommand: PROC[frame: TJaMInternal.Frame, ob: command TJaMBasic.Object];
Installation
InstallReason: TYPE = {init,free,register};
InstallProc: TYPE = PROC[InstallReason,TJaMInternal.Frame];
Install: PROC[InstallProc];
ForEachInstalled: InstallProc;
StartTJaM: PROC;
}.