IP.mesa
Declarations and operations for the Interpress interpreter.
Last edited by:
Doug Wyatt, March 9, 1984 1:26:16 pm PST
DIRECTORY
Imager USING [Color, Context, Outline, Pair, PixelArray, Trajectory, Transformation],
IO USING [STREAM],
IPBasic USING [ImagerVariable, Op, Primitive, TypeCode],
IPReader USING [Block, BlockNode, BodyNode, Index, Node, nullIndex, Reader],
Rope USING [ROPE];
IP: CEDAR DEFINITIONS
~ BEGIN
Types
Common Cedar types
ROPE: TYPE ~ Rope.ROPE;
STREAM: TYPE ~ IO.STREAM;
Primitives and symbols
Op: TYPE ~ IPBasic.Op;
Primitive: TYPE ~ IPBasic.Primitive;
Global structure
Index: TYPE ~ IPReader.Index;
nullIndex: Index ~ IPReader.nullIndex;
Node: TYPE ~ IPReader.Node;
BodyNode: TYPE ~ IPReader.BodyNode;
BlockNode: TYPE ~ IPReader.BlockNode;
Block: TYPE ~ IPReader.Block;
Basic types
TypeCode: TYPE ~ IPBasic.TypeCode;
Any: TYPE ~ REF ANY;
maxInteger: INT ~ 16777215; -- 2^24 - 1
Integer: TYPE ~ INT--[0..maxInteger]--;
Number: TYPE ~ REF NumberRep;
NumberRep: TYPE ~ RECORD[value: REAL];
Identifier: TYPE ~ ATOM;
Marker: TYPE ~ INT; -- a unique mark value associated with a context
nullMarker: Marker ~ 0;
VectorShape: TYPE ~ RECORD[l, n: Integer]; -- lower bound l, upper bound u=l+n-1
Vector: TYPE ~ REF VectorRep;
VectorRep: TYPE ~ RECORD[
class: ATOM, -- $Array, $Merged, $Font, $String, ...
shape: PROC[data: REF] RETURNS[VectorShape],
get: PROC[data: REF, j: Integer] RETURNS[Any],
getInteger: PROC[data: REF, j: Integer] RETURNS[Integer] ← NIL,
getStream: PROC[data: REF, bytesPerElement: NAT] RETURNS[STREAM] ← NIL,
getProp: PROC[data: REF, propName: Any] RETURNS[value: Any, found: BOOL] ← NIL,
data: REF
];
Operator: TYPE ~ REF OperatorRep;
OperatorRep: TYPE ~ RECORD[
class: ATOM, -- $Composed, $Pool, ...
do: PROC[self: State, data: REF],
data: REF
];
Array: TYPE ~ REF ArrayRep; -- a mutable array of values, such as a frame or pool
ArrayRep: TYPE ~ RECORD[
shape: VectorShape,
array: SEQUENCE size: NAT OF Any
];
Pool: TYPE ~ REF PoolRep; -- a pool operator, from MAKEPOOL or NOPOOL
PoolRep: TYPE ~ RECORD[
persistent: BOOL,
level: NAT ← 0,
array: Array
];
Imager types
ImagerVariable: TYPE ~ IPBasic.ImagerVariable;
Pair: TYPE ~ Imager.Pair; -- RECORD[x, y: REAL]
Transformation: TYPE ~ Imager.Transformation;
PixelArray: TYPE ~ Imager.PixelArray;
Color: TYPE ~ Imager.Color;
Trajectory: TYPE ~ Imager.Trajectory;
Outline: TYPE ~ Imager.Outline;
Interpreter state
Element: TYPE ~ REF ElementRep; -- an element on the stack
ElementRep: TYPE ~ RECORD[
below: Element ← NIL, -- element below this one on the stack
above: Element ← NIL, -- element above this one on the stack
type: {ref, int, real} ← $ref, -- what type of element
ref: REFNIL, -- value, if type=$ref
int: INT ← 0, -- value, if type=$int
real: REAL ← 0 -- value, if type=$real
];
MarkItem: TYPE ~ REF MarkItemRep; -- a mark on the stack
MarkItemRep: TYPE ~ RECORD[
below: MarkItem ← NIL, -- mark below this one on the stack
marker: Marker ← nullMarker, -- marker for context that pushed the mark
under: INT ← 0 -- number of stack elements hidden by this mark
];
Context: TYPE ~ REF ContextRep; -- an execution context
ContextRep: TYPE ~ RECORD[
caller: Context, -- caller's context
marker: Marker, -- unique mark for this context
initialFrame: Vector, -- initial frame
frame: Array, -- current frame (NIL if unchanged from initial frame)
pool: Pool, -- shared pool
env: Vector -- environment
];
State: TYPE ~ REF StateRep; -- the state of an Interpress interpreter
StateRep: TYPE ~ RECORD[
master: IPReader.Reader ← NIL, -- the master being interpreted
skeleton: Block ← NIL, -- the structure of the master
topEnv: Vector ← NIL, -- environment for the top level block
topFrame: Vector ← NIL, -- initial frame for the top level block
lastMarker: Marker ← nullMarker, -- last mark value used
context: Context ← NIL, -- the current context
stack: Element ← NIL, -- the top element on the stack
count: Integer ← 0, -- number of stack elements above the top mark
maxCount: Integer ← 0, -- maximum count permitted above the top mark
mark: MarkItem ← NIL, -- the top mark on the stack
string: REF TEXTNIL, -- a buffer for strings
imager: Imager.Context ← NIL, -- imager state
log: IO.STREAMNIL -- an output stream for logging errors
];
Operations
Errors
MasterErrorType: TYPE ~ {
bug,
unimplemented,
boundsFault,
nilFault,
invalidArgs,
limitExceeded,
markMismatch,
missingBody,
notInteger,
stackOverflow,
stackUnderflow,
undefinedOperation,
undefinedProperty,
unmarkFailed,
wrongType
};
MasterWarningType: TYPE ~ {
bug,
unimplemented,
nullValue,
illegalIdentifier,
illegalString
};
MasterError: PROC[type: MasterErrorType, explanation: ROPE ←, raiseError: BOOLTRUE];
MasterWarning: PROC[type: MasterWarningType, explanation: ROPE ←];
AppearanceError: PROC[code: ATOM, explanation: ROPE ←];
AppearanceWarning: PROC[code: ATOM, explanation: ROPE ←];
Error: ERROR;
CallWithStateOnPropList: PROC[self: State, inner: PROC];
Type conversion
IntegerFromInt: PROC[INT] RETURNS[Integer];
IntegerFromReal: PROC[REAL] RETURNS[Integer];
IntegerFromAny: PROC[Any] RETURNS[Integer];
RealFromInteger: PROC[i: Integer] RETURNS[REAL] ~ INLINE { RETURN[REAL[i]] };
RealFromInt: PROC[i: INT] RETURNS[REAL] ~ INLINE { RETURN[REAL[i]] };
RealFromAny: PROC[Any] RETURNS[REAL];
AnyFromInteger: PROC[Integer] RETURNS[Any];
AnyFromInt: PROC[INT] RETURNS[Any];
AnyFromReal: PROC[REAL] RETURNS[Any];
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];
PrivateCheckInteger: PROC[Integer] RETURNS[Integer];
CheckInteger: PROC[i: Integer] RETURNS[Integer] ~ INLINE { -- ensure i IN[0..maxInteger]
RETURN[IF i IN[0..maxInteger] THEN i ELSE PrivateCheckInteger[i]] };
PrivateCheckAny: PROC[Any] RETURNS[Any];
CheckAny: PROC[x: Any] RETURNS[Any] ~ INLINE { -- ensure x#NIL
RETURN[IF x#NIL THEN x ELSE PrivateCheckAny[x]] };
RopeFromType: PROC[TypeCode] RETURNS[ROPE];
Identifiers and Names
IdentifierFromRope: PROC[ROPE] RETURNS[Identifier];
RopeFromIdentifier: PROC[Identifier] RETURNS[ROPE];
NameFromVector: PROC[Vector] RETURNS[ROPE];
VectorFromName: PROC[ROPE] RETURNS[Vector];
Vectors and Arrays
NullVector: PROC[shape: VectorShape] RETURNS[Vector];
Shape: PROC[v: Vector] RETURNS[VectorShape];
Get: PROC[v: Vector, j: Integer] RETURNS[Any];
GetProp: PROC[v: Vector, propName: Any] RETURNS[value: Any, found: BOOL];
GetP: PROC[v: Vector, propName: Any] RETURNS[Any];
GetInteger: PROC[v: Vector, j: Integer] RETURNS[Integer];
GetStream: PROC[v: Vector, bytesPerElement: NAT] RETURNS[STREAM];
RunSize: PROC[r: Vector] RETURNS[Integer];
RunGet: PROC[r: Vector, i: Integer] RETURNS[Any];
AShape: PROC[a: Array] RETURNS[VectorShape] ~ INLINE { RETURN[a.shape] };
AGet: PROC[a: Array, n: Integer] RETURNS[Any];
ASet: PROC[a: Array, x: Any, n: Integer];
VectorFromArray: PROC[Array] RETURNS[Vector];
ArrayFromVector: PROC[Vector] RETURNS[Array];
VectorFromString: PROC[REF TEXT] RETURNS[Vector];
Contexts
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];
Call: PROC[self: State, action: PROC[State], frame: Vector, pool: Pool, env: Vector];
GetMarker: PROC[self: State] RETURNS[Marker];
Pools
MakePool: PROC[v: Vector, persistent: BOOL] RETURNS[Pool];
NoPool: PROC RETURNS[Pool];
CurrentPool: PROC[Pool] RETURNS[Vector];
OperatorFromPool: PROC[Pool] RETURNS[Operator];
PoolFromOperator: PROC[Operator] RETURNS[Pool];
SaveEffect: TYPE ~ {nil, save, saveAll};
DoWithSaveEffect: PROC[self: State, action: PROC, saveEffect: SaveEffect];
Operators
MakeCO: PROC[self: State, pool: Pool, f: Vector] RETURNS[Operator];
MakeSimpleCO: PROC[self: State] RETURNS[Operator];
MakeCompiledImage: PROC[self: State, f: Vector] RETURNS[Operator];
Do: PROC[self: State, o: Operator, saveEffect: SaveEffect ← $nil];
DoBody: PROC[self: State, pool: Pool, f: Vector, saveEffect: SaveEffect ← $nil];
DoSimpleBody: PROC[self: State, saveEffect: SaveEffect ← $nil];
Apply: PROC[self: State, op: Op];
ExecuteBody: PROC[self: State, body: Index];
ExecuteNextBody: PROC[self: State];
ReadNextBody: PROC[self: State] RETURNS[Index];
SkipNextBody: PROC[self: State] ~ INLINE { [] ← ReadNextBody[self] };
GetIndex: PROC[self: State] RETURNS[Index];
SetIndex: PROC[self: State, index: Index];
DoWithMarkProtection: PROC[self: State, action: PROC[State]] RETURNS[BOOL];
Stack
InitializeStack: PROC[self: State, maxLength: Integer];
Push: PROC[self: State, x: Any];
PushInt: PROC[self: State, i: INT];
PushInteger: PROC[self: State, i: Integer];
PushBool: PROC[self: State, b: BOOL] ~ INLINE { PushInteger[self, IF b THEN 1 ELSE 0] };
PushReal: PROC[self: State, r: REAL];
PushPair: PROC[self: State, p: Pair];
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];
Pop: PROC[self: State] RETURNS[Any];
PopInteger: PROC[self: State] RETURNS[Integer];
PopBool: PROC[self: State] RETURNS[BOOL] ~ INLINE { RETURN[PopInteger[self]#0] };
PopReal: PROC[self: State] RETURNS[REAL];
PopPair: PROC[self: State] RETURNS[Pair];
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];
Discard: PROC[self: State];
Copy: PROC[self: State, depth: Integer];
Dup: PROC[self: State];
Roll: PROC[self: State, depth, moveFirst: Integer];
Exch: PROC[self: State];
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];
Test
Eq: PROC[a, b: Any] RETURNS[BOOL];
EqName: PROC[a, b: Any] RETURNS[BOOL];
Type: PROC[a: Any] RETURNS[TypeCode];
END.