IPOperatorImpl.mesa
Last edited by:
Doug Wyatt, March 3, 1984 5:09:17 pm PST
DIRECTORY
IP USING [Call, DoWithSaveEffect, Env, ExecuteBody, ExecuteNextBody, Frame, Index, Integer, MasterWarning, NoPool, Operator, OperatorRep, Pool, PoolFromOperator, PoolOp, PopBool, PopInteger, PopOperator, PopVector, PushBool, PushOperator, ReadNextBody, SaveEffect, SkipNextBody, State, Vector],
IPBase USING [];
IPOperatorImpl: CEDAR PROGRAM
IMPORTS IP
EXPORTS IP, IPBase
~ BEGIN OPEN IP;
ComposedOp: TYPE ~ REF ComposedOpRep;
ComposedOpRep:
TYPE ~
RECORD[
frame: Vector, -- initial frame
pool: Pool, -- shared pool
env: Vector, -- environment
body: Index -- starting index of body
];
ComposedDo:
PROC[self: State, data:
REF] ~ {
op: ComposedOp ~ NARROW[data];
ExecuteOpBody: PROC[self: State] ~ { ExecuteBody[self, op.body] };
Call[self: self, action: ExecuteOpBody, frame: op.frame, pool: op.pool, env: op.env];
};
MakeCO:
PUBLIC
PROC[self: State, pool: Pool, f: Vector]
RETURNS[Operator] ~ {
body: Index ~ ReadNextBody[self];
op: ComposedOp ~ NEW[ComposedOpRep ← [frame: f, pool: pool, env: Env[self], body: body]];
RETURN[NEW[OperatorRep ← [class: $Composed, do: ComposedDo, data: op]]];
};
MakeSimpleCO:
PUBLIC
PROC[self: State]
RETURNS[Operator] ~ {
RETURN[MakeCO[self: self, pool: NoPool[], f: Frame[self]]];
};
CompiledImageOp: TYPE ~ REF CompiledImageOpRep;
CompiledImageOpRep:
TYPE ~
RECORD[f: Vector, env: Vector, body: Index];
CompiledDo:
PROC[self: State, data:
REF] ~ {
op: CompiledImageOp ~ NARROW[data];
MasterWarning[$unimplemented, "Can't DO a result of MAKECOMPILEDIMAGE."];
};
MakeCompiledImage:
PUBLIC
PROC[self: State, f: Vector]
RETURNS[Operator] ~ {
body: Index ~ ReadNextBody[self];
op: CompiledImageOp ~ NEW[CompiledImageOpRep ← [f: f, env: Env[self], body: body]];
RETURN[NEW[OperatorRep ← [class: $Compiled, do: CompiledDo, data: op]]];
};
Do:
PUBLIC
PROC[self: State, o: Operator, saveEffect: SaveEffect ← $nil] ~ {
DoAction: PROC ~ { o.do[self, o.data] };
DoWithSaveEffect[self, DoAction, saveEffect];
};
DoBody:
PUBLIC
PROC[self: State, pool: Pool, f: Vector, saveEffect: SaveEffect ← $nil] ~ {
DoBodyAction:
PROC ~ {
Call[self: self, action: ExecuteNextBody, frame: f, pool: pool, env: Env[self]];
};
DoWithSaveEffect[self, DoBodyAction, saveEffect];
};
DoSimpleBody:
PUBLIC
PROC[self: State, saveEffect: SaveEffect ← $nil] ~ {
DoBody[self, NoPool[], Frame[self], saveEffect];
};
ApplyMAKECO:
PUBLIC
PROC[self: State] ~ {
f: Vector ~ PopVector[self];
pool: Pool ~ PoolFromOperator[PopOperator[self]];
PushOperator[self, MakeCO[self, pool, f]];
};
ApplyMAKESIMPLECO:
PUBLIC
PROC[self: State] ~ {
PushOperator[self, MakeSimpleCO[self]];
};
ApplyDO:
PUBLIC
PROC[self: State] ~ {
o: Operator ~ PopOperator[self];
Do[self, o];
};
ApplyDOSAVE:
PUBLIC
PROC[self: State] ~ {
o: Operator ~ PopOperator[self];
Do[self, o, $save];
};
ApplyDOSAVEALL:
PUBLIC
PROC[self: State] ~ {
o: Operator ~ PopOperator[self];
Do[self, o, $saveAll];
};
ApplyDOBODY:
PUBLIC
PROC[self: State] ~ {
f: Vector ~ PopVector[self];
DoBody[self, PoolOp[self], f];
};
ApplyDOSAVEBODY:
PUBLIC
PROC[self: State] ~ {
f: Vector ~ PopVector[self];
DoBody[self, PoolOp[self], f, $save];
};
ApplyDOSAVEALLBODY:
PUBLIC
PROC[self: State] ~ {
f: Vector ~ PopVector[self];
DoBody[self, PoolOp[self], f, $saveAll];
};
ApplyDOSAVESIMPLEBODY:
PUBLIC
PROC[self: State] ~ {
DoSimpleBody[self, $save];
};
ApplyMAKECOMPILEDIMAGE:
PUBLIC
PROC[self: State] ~ {
f: Vector ~ PopVector[self];
PushOperator[self, MakeCompiledImage[self, f]];
};
ApplyIF:
PUBLIC
PROC[self: State] ~ {
b: BOOL ~ PopBool[self];
IF b THEN DoSimpleBody[self] ELSE SkipNextBody[self];
};
ApplyIFELSE:
PUBLIC
PROC[self: State] ~ {
b: BOOL ~ PopBool[self];
IF b THEN DoSimpleBody[self] ELSE SkipNextBody[self];
PushBool[self, NOT b];
};
ApplyIFCOPY:
PUBLIC
PROC[self: State] ~ {
testCopy: Operator ~ PopOperator[self];
MasterWarning[$unimplemented, "IFCOPY is not implemented."];
SkipNextBody[self];
};
ApplyLOOP:
PUBLIC
PROC[self: State] ~ {
op: Operator ~ MakeCO[self, PoolOp[self], Frame[self]];
DO Do[self, op]; IF NOT PopBool[self] THEN EXIT ENDLOOP;
};
END.