IPContextImpl.mesa
Last edited by:
Doug Wyatt, March 3, 1984 5:18:25 pm PST
DIRECTORY
IP USING [AGet, Any, Array, ArrayFromVector, ASet, Context, ContextRep, CurrentPool, Get, Integer, Marker, MasterError, nullMarker, Operator, OperatorFromPool, Pool, Pop, PopInteger, Push, PushOperator, PushVector, State, Vector, VectorFromArray],
IPBase USING [];
IPContextImpl: CEDAR PROGRAM
IMPORTS IP
EXPORTS IP, IPBase
~ BEGIN OPEN IP;
NewMarker: PROC[self: State] RETURNS[Marker] ~ {
last: Marker ~ self.lastMarker;
IF last<Marker.LAST THEN RETURN[self.lastMarker ← last+1]
ELSE { MasterError[$bug, "Ran out of Marker values!"]; ERROR };
};
Call: PUBLIC PROC[self: State, action: PROC[State], frame: Vector, pool: Pool, env: Vector] ~ {
caller: Context ~ self.context;
marker: Marker ~ NewMarker[self]; -- generate a unique mark
context: Context ~ NEW[ContextRep ← [ -- create a new context
caller: caller, marker: marker,
initialFrame: frame, frame: NIL, pool: pool, env: env
]];
self.context ← context;
action[self ! UNWIND => self.context ← caller];
self.context ← caller;
};
GetMarker: PUBLIC PROC[self: State] RETURNS[Marker] ~ {
context: Context ~ self.context;
IF context=NIL THEN RETURN[nullMarker]
ELSE RETURN[context.marker];
};
Frame: PUBLIC PROC[self: State] RETURNS[Vector] ~ {
context: Context ~ self.context;
IF context.frame=NIL THEN RETURN[context.initialFrame]
ELSE RETURN[VectorFromArray[context.frame]];
};
FGet: PUBLIC PROC[self: State, j: Integer] RETURNS[Any] ~ {
context: Context ~ self.context;
IF context.frame=NIL THEN RETURN[Get[context.initialFrame, j]]
ELSE RETURN[AGet[context.frame, j]]
};
FSet: PUBLIC PROC[self: State, x: Any, j: Integer] ~ {
context: Context ~ self.context;
IF context.frame=NIL THEN context.frame ← ArrayFromVector[context.initialFrame];
ASet[context.frame, x, j];
};
PoolOp: PUBLIC PROC[self: State] RETURNS[Pool] ~ { RETURN[self.context.pool] };
PGet: PUBLIC PROC[self: State, j: Integer] RETURNS[Any] ~ {
pool: Pool ~ self.context.pool;
RETURN[AGet[pool.array, j]];
};
PSet: PUBLIC PROC[self: State, x: Any, j: Integer] ~ {
pool: Pool ~ self.context.pool;
-- SavePool[self, pool, ...]; --
ASet[pool.array, x, j];
};
Env: PUBLIC PROC[self: State] RETURNS[Vector] ~ {
RETURN[self.context.env];
};
ApplyFRAME: PUBLIC PROC[self: State] ~ {
PushVector[self, Frame[self]];
};
ApplyFGET: PUBLIC PROC[self: State] ~ {
j: Integer ~ PopInteger[self];
Push[self, FGet[self, j]];
};
ApplyFSET: PUBLIC PROC[self: State] ~ {
j: Integer ~ PopInteger[self];
x: Any ~ Pop[self];
FSet[self, x, j];
};
ApplyPOOLOP: PUBLIC PROC[self: State] ~ {
PushOperator[self, OperatorFromPool[PoolOp[self]]];
};
ApplyPOOL: PUBLIC PROC[self: State] ~ {
PushVector[self, CurrentPool[PoolOp[self]]];
};
ApplyPGET: PUBLIC PROC[self: State] ~ {
j: Integer ~ PopInteger[self];
Push[self, PGet[self, j]];
};
ApplyPSET: PUBLIC PROC[self: State] ~ {
j: Integer ~ PopInteger[self];
x: Any ~ Pop[self];
PSet[self, x, j];
};
ApplyENV: PUBLIC PROC[self: State] ~ {
PushVector[self, Env[self]];
};
END.