<> <<>> <> <<>> <> <> 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 <> <> ROPE: TYPE ~ Rope.ROPE; STREAM: TYPE ~ IO.STREAM; <> Op: TYPE ~ IPBasic.Op; Primitive: TYPE ~ IPBasic.Primitive; <> Index: TYPE ~ IPReader.Index; nullIndex: Index ~ IPReader.nullIndex; Node: TYPE ~ IPReader.Node; BodyNode: TYPE ~ IPReader.BodyNode; BlockNode: TYPE ~ IPReader.BlockNode; Block: TYPE ~ IPReader.Block; <> 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 ]; <> 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; <> 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: REF _ NIL, -- 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 TEXT _ NIL, -- a buffer for strings imager: Imager.Context _ NIL, -- imager state log: IO.STREAM _ NIL -- an output stream for logging 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: BOOL _ TRUE]; 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]; <> 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]; <> IdentifierFromRope: PROC[ROPE] RETURNS[Identifier]; RopeFromIdentifier: PROC[Identifier] RETURNS[ROPE]; NameFromVector: PROC[Vector] RETURNS[ROPE]; VectorFromName: PROC[ROPE] RETURNS[Vector]; <> 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]; <> 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]; <> 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]; <> 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]; <> 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]; <> Eq: PROC[a, b: Any] RETURNS[BOOL]; EqName: PROC[a, b: Any] RETURNS[BOOL]; Type: PROC[a: Any] RETURNS[TypeCode]; END.