IPInterpreter.mesa
Copyright © 1984 Xerox Corporation. All rights reserved.
Doug Wyatt, November 13, 1984 6:57:47 pm PST
Basic types for the Interpress interpreter.
DIRECTORY
Basics USING [HighHalf, LowHalf],
Imager USING [Context],
ImagerColor USING [Color],
ImagerPath USING [Trajectory],
ImagerPixelArray USING [PixelArray],
ImagerTransformation USING [Transformation],
IO USING [STREAM],
IPMaster USING [Body, Op, Skeleton, TypeCode],
PrincOps USING [zBNDCK, zLIW],
Rope USING [ROPE],
Vector2 USING [VEC];
IPInterpreter: CEDAR DEFINITIONS IMPORTS Basics
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Op: TYPE ~ IPMaster.Op;
TypeCode: TYPE ~ IPMaster.TypeCode;
maxInteger: INT ~ 77777777B; -- 2^24 - 1 = 16777215
maxIdLength: NAT ~ 100; -- a test for credibility, not an intrinsic limit
maxStackLength: NAT ~ 1000; -- a test for credibility, not an intrinsic limit
maxVecSize: NAT ~ NAT.LAST; -- for a Vector made by MAKEVEC or MAKEVECLU
topFrameSize: NAT ~ 50;
Any: TYPE ~ REF ANY;
Integer: TYPE ~ INT--[0..maxInteger]--;
CheckInteger: PROC[i: INT] RETURNS[Integer] ~
TRUSTED MACHINE CODE { PrincOps.zLIW, 1, 0; PrincOps.zBNDCK };
RETURN[IF i IN[0..2^24) THEN i ELSE ERROR RuntimeError.BoundsFault]
IsInteger: PROC[i: INT] RETURNS[BOOL] ~
INLINE { RETURN[Basics.HighHalf[LOOPHOLE[i]]<400B] };
RETURN[i IN[0..2^24)]
Even: PROC[i: Integer] RETURNS[BOOL] ~
INLINE { RETURN[(Basics.LowHalf[LOOPHOLE[i]] MOD 2)=0] };
RETURN[(i MOD 2)=0]
Number: TYPE ~ REF NumberRep;
NumberRep: TYPE ~ RECORD[SELECT tag: * FROM
int => [int: INT], real => [real: REAL], ENDCASE
];
Identifier: TYPE ~ REF IdentifierRep;
IdentifierRep: TYPE ~ RECORD[atom: ATOM, rope: ROPE];
Marker: TYPE ~ LONG CARDINAL; -- a unique mark value associated with a context
nullMarker: Marker ~ 0;
VectorShape: TYPE ~ RECORD[
l: Integer, -- lower bound
n: Integer -- number of elements (upper bound "u" = l+n-1)
];
Vector: TYPE ~ REF VectorRep;
VectorRep: TYPE ~ RECORD[class: VectorClass, data: REF];
VectorClass: TYPE ~ REF VectorClassRep;
VectorClassRep: TYPE ~ RECORD[
type: ATOM, -- $Array, $Merged, $Font, $String, ...
shape: PROC[v: Vector] RETURNS[VectorShape],
get: PROC[v: Vector, j: Integer] RETURNS[Any],
getProp: PROC[v: Vector, propName: Any] RETURNS[found: BOOL, value: Any] ← NIL
];
Body: TYPE ~ IPMaster.Body;
Operator: TYPE ~ REF OperatorRep;
OperatorRep: TYPE ~ RECORD[class: OperatorClass, data: REF];
OperatorClass: TYPE ~ REF OperatorClassRep;
OperatorClassRep: TYPE ~ RECORD[
type: ATOM, -- $Composed, $Pool, $Char, $Decompressor, $ColorOperator, ...
do: PROC[op: Operator, state: State]
];
VEC: TYPE ~ Vector2.VEC;
Transformation: TYPE ~ ImagerTransformation.Transformation;
PixelArray: TYPE ~ ImagerPixelArray.PixelArray;
Color: TYPE ~ ImagerColor.Color;
Trajectory: TYPE ~ ImagerPath.Trajectory;
Outline: TYPE ~ REF OutlineRep;
OutlineRep: TYPE ~ RECORD[SEQUENCE size: NAT OF Trajectory];
Array: TYPE ~ REF ArrayRep; -- a mutable array of values, such as a frame or pool
ArrayRep: TYPE ~ RECORD[
l: Integer, -- lower bound
array: SEQUENCE n: [0..maxVecSize] OF Any
];
Pool: TYPE ~ REF PoolRep; -- a pool operator, from MAKEPOOL or NOPOOL
PoolRep: TYPE ~ RECORD[
persistent: BOOL,
level: NAT ← 0,
array: Array
];
Context: TYPE ~ REF ContextRep; -- an execution context
ContextRep: TYPE ~ RECORD[
caller: Context, -- caller's context
marker: Marker, -- unique mark for this context
index: INT, -- index of token currently being executed
initialFrame: Vector, -- initial frame
frame: Array, -- current frame (NIL if unchanged from initial frame)
pool: Pool, -- shared pool
env: Vector -- environment
];
Stack: TYPE ~ REF StackRep; -- the stack
StackRep: TYPE; -- see IPStackImpl
State: TYPE ~ REF StateRep; -- the state of an Interpress interpreter
StateRep: TYPE ~ RECORD[
stream: STREAMNIL, -- input stream on the master being interpreted
buffer: REF TEXTNIL, -- a buffer for reading strings from the master
skeleton: IPMaster.Skeleton ← NIL, -- skeleton structure of the master
topFrame: Vector ← NIL, -- initial frame for the top level block
topEnv: Vector ← NIL, -- environment for the top level block
lastMarker: Marker ← nullMarker, -- last mark value used
context: Context ← NIL, -- the current context
stack: Stack ← NIL, -- the stack
imager: Imager.Context ← NIL, -- imager state
showVec: Vector ← NIL, -- current showVec
log: STREAMNIL -- output stream for logging errors
];
Error: ERROR;
Bug: ERROR;
ErrorClass: TYPE ~ {
masterError,
masterWarning,
appearanceError,
appearanceWarning,
comment
};
AddState: PROC[state: State, inner: PROC];
Uses ProcessProps to add an $InterpressState property for the duration of the call of inner.
GetState: PROC RETURNS[State];
Returns the current value of the $InterpressState property, NIL if none found.
LogError: PROC[class: ErrorClass, code: ATOM, explanation: ROPE];
MasterErrorType: TYPE ~ {
bug,
unimplemented,
boundsFault,
nilFault,
invalidArgs,
limitExceeded,
markMismatch,
missingBody,
notInteger,
stackOverflow,
stackUnderflow,
undefinedOperation,
undefinedProperty,
unmarkFailed,
wrongType
};
MasterError: PROC[type: MasterErrorType, explanation: ROPE ←];
MasterWarningType: TYPE ~ {
bug,
unimplemented,
unknownToken,
nullValue,
illegalIdentifier,
illegalString
};
MasterWarning: PROC[type: MasterWarningType, explanation: ROPE ←];
NumberFromInteger: PROC[Integer] RETURNS[Number];
NumberFromInt: PROC[INT] RETURNS[Number];
NumberFromReal: PROC[REAL] RETURNS[Number];
IntegerFromInt: PROC[INT] RETURNS[Integer];
IntegerFromReal: PROC[REAL] RETURNS[Integer];
IntegerFromAny: PROC[Any] RETURNS[Integer];
IntFromReal: PROC[REAL] RETURNS[INT];
IntFromAny: PROC[Any] RETURNS[INT];
RealFromAny: PROC[Any] RETURNS[REAL];
NumberFromAny: PROC[Any] RETURNS[Number];
IdentifierFromAny: PROC[Any] RETURNS[Identifier];
VectorFromAny: PROC[Any] RETURNS[Vector];
OperatorFromAny: PROC[Any] RETURNS[Operator];
TransformationFromAny: PROC[Any] RETURNS[Transformation];
PixelArrayFromAny: PROC[Any] RETURNS[PixelArray];
ColorFromAny: PROC[Any] RETURNS[Color];
TrajectoryFromAny: PROC[Any] RETURNS[Trajectory];
OutlineFromAny: PROC[Any] RETURNS[Outline];
Eq: PROC[a, b: Any] RETURNS[BOOL];
EqName: PROC[a, b: Any] RETURNS[BOOL];
Type: PROC[a: Any] RETURNS[TypeCode];
IdentifierFromRope: PROC[ROPE] RETURNS[Identifier];
RopeFromIdentifier: PROC[Identifier] RETURNS[ROPE];
Get: PROC[v: Vector, j: Integer] RETURNS[Any];
GetInteger: PROC[v: Vector, j: Integer] RETURNS[Integer];
GetReal: PROC[v: Vector, j: Integer] RETURNS[REAL];
Shape: PROC[v: Vector] RETURNS[VectorShape];
MergeProp: PROC[v1, v2: Vector] RETURNS[Vector];
GetProp: PROC[v: Vector, propName: Any] RETURNS[found: BOOL, value: Any];
GetP: PROC[v: Vector, propName: Any] RETURNS[Any];
RunSize: PROC[r: Vector] RETURNS[Integer];
RunGet: PROC[r: Vector, i: Integer] RETURNS[Any];
MakeVec: PROC[shape: VectorShape, pop: PROC RETURNS[Any]] RETURNS[Vector];
Creates a Vector with the specified shape.
Calls pop shape.n times to get the elements, last element first.
VectorFromArray: PROC[Array] RETURNS[Vector];
Creates a Vector with the same shape and elements as the Array.
The result contains a copy of the Array; it does not share the original.
ArrayFromVector: PROC[Vector] RETURNS[Array];
Creates an Array with the same shape and elements as the Vector.
The result is a new, mutable copy; it shares nothing with the Vector.
VectorFromString: PROC[ROPE] RETURNS[Vector];
StringFromVector: PROC[Vector] RETURNS[ROPE];
A "String" uses the encoding scheme in the Xerox Character Code Standard.
VectorFromString interprets '\377 as an escape code.
StringFromVector tries to encode the Integer vector elements as tightly as possible.
RopeFromVector: PROC[Vector] RETURNS[ROPE];
Converts each element of the vector to an Ascii character.
NewStack: PROC[maxLength: Integer] RETURNS[Stack];
PushAny: PROC[self: State, x: Any];
PushBool: PROC[self: State, b: BOOL];
PushInteger: PROC[self: State, i: Integer];
PushInt: PROC[self: State, i: INT];
PushReal: PROC[self: State, r: REAL];
PushVec: PROC[self: State, p: VEC];
PushIdentifier: PROC[self: State, x: Identifier];
PushVector: PROC[self: State, x: Vector];
PushOperator: PROC[self: State, x: Operator];
PushTransformation: PROC[self: State, x: Transformation];
PushPixelArray: PROC[self: State, x: PixelArray];
PushColor: PROC[self: State, x: Color];
PushTrajectory: PROC[self: State, x: Trajectory];
PushOutline: PROC[self: State, x: Outline];
PopAny: PROC[self: State] RETURNS[Any];
PopBool: PROC[self: State] RETURNS[BOOL];
PopInteger: PROC[self: State] RETURNS[Integer];
PopInt: PROC[self: State] RETURNS[INT];
PopReal: PROC[self: State] RETURNS[REAL];
PopVec: PROC[self: State] RETURNS[VEC];
PopIdentifier: PROC[self: State] RETURNS[Identifier];
PopVector: PROC[self: State] RETURNS[Vector];
PopOperator: PROC[self: State] RETURNS[Operator];
PopTransformation: PROC[self: State] RETURNS[Transformation];
PopPixelArray: PROC[self: State] RETURNS[PixelArray];
PopColor: PROC[self: State] RETURNS[Color];
PopTrajectory: PROC[self: State] RETURNS[Trajectory];
PopOutline: PROC[self: State] RETURNS[Outline];
TopType: PROC[self: State] RETURNS[TypeCode];
Pop: PROC[self: State];
Copy: PROC[self: State, depth: Integer];
Roll: PROC[self: State, depth, moveFirst: Integer];
Mark: PROC[self: State, n: Integer];
Unmark: PROC[self: State, n: Integer];
Unmark0: PROC[self: State];
Count: PROC[self: State] RETURNS[Integer];
PopToMark: PROC[self: State] RETURNS[Marker];
RemoveMark: PROC[self: State, marker: Marker];
Frame: PROC[self: State] RETURNS[Vector];
FGet: PROC[self: State, j: Integer] RETURNS[Any];
FSet: PROC[self: State, x: Any, j: Integer];
PoolOp: PROC[self: State] RETURNS[Pool];
PGet: PROC[self: State, j: Integer] RETURNS[Any];
PSet: PROC[self: State, x: Any, j: Integer];
Env: PROC[self: State] RETURNS[Vector];
MakePool: PROC[v: Vector, persistent: BOOL] RETURNS[Pool];
NoPool: PROC RETURNS[Pool];
PoolFromOperator: PROC[Operator] RETURNS[Pool];
OperatorFromPool: PROC[Pool] RETURNS[Operator];
VectorFromPool: PROC[Pool] RETURNS[Vector];
MakeCO: PROC[frame: Vector, pool: Pool, env: Vector, body: Body] RETURNS[Operator];
MakeCompiledImage: PROC[frame: Vector, env: Vector, body: Body] RETURNS[Operator];
Apply: PROC[self: State, op: Op];
Executes a primitive.
Do: PROC[self: State, op: Operator];
Executes an Operator.
DoSave: PROC[self: State, action: PROC];
Executes the action, then restores non-persistent pools.
DoSaveAll: PROC[self: State, action: PROC];
Executes the action, then restores all pools.
DoProtected: PROC[self: State, action: PROC];
Executes the action with mark protection: 0 MARK <action> UNMARK0.
Call: PROC[self: State, action: PROC, frame: Vector, pool: Pool, env: Vector];
Executes the action in a new context with specified frame, pool, and environment.
SkipInlineBody: PROC[self: State];
Skips over a body in the master.
GetInlineBody: PROC[self: State] RETURNS[Body];
Reads a body from the master, recording it for later use.
CallInlineBody: PROC[self: State, frame: Vector ← NIL, pool: Pool ← NIL, env: Vector ← NIL];
Executes a body in a new context. Defaults are Frame[self], NoPool[], and Env[self].
END.