IPBaseImpl.mesa
Copyright © 1984, 1985 by Xerox Corporation. All rights reserved.
Doug Wyatt, November 21, 1985 5:38:20 pm PST
DIRECTORY
IPBase USING [],
IPInterpreter USING [Any, Body, CallInlineBody, Cardinal, Copy, Count, Do, DoSave, DoSaveAll, Env, Eq, FGet, Frame, FSet, Get, GetInlineBody, GetP, GetProp, MakeCO, MakeVec, MakeVecLU, Mark, MasterError, MasterWarning, MergeProp, Operator, Pop, PopAny, PopBool, PopCardinal, PopOperator, PopReal, PopVector, PushAny, PushBool, PushCardinal, PushOperator, PushReal, PushVector, Ref, ReportError, Roll, RopeFromVector, Shape, SkipInlineBody, TopType, TypeCode, Unmark, Vector, VectorShape],
IPReal USING [Ceiling, Floor, Mod, Rem, Round, Trunc];
IPBaseImpl: CEDAR PROGRAM
IMPORTS IPInterpreter, IPReal
EXPORTS IPBase
~ BEGIN OPEN IPInterpreter;
Vector operators (2.4.3)
ApplyGET: PUBLIC PROC [self: Ref] ~ {
j: Cardinal ~ PopCardinal[self];
v: Vector ~ PopVector[self];
PushAny[self, Get[v, j]];
};
ApplyMAKEVECLU: PUBLIC PROC [self: Ref] ~ {
u: Cardinal ~ PopCardinal[self];
l: Cardinal ~ PopCardinal[self];
pop: PROC RETURNS [Any] ~ { RETURN[PopAny[self]] };
v: Vector ~ MakeVecLU[l, u, pop];
PushVector[self, v];
};
ApplyMAKEVEC: PUBLIC PROC [self: Ref] ~ {
n: Cardinal ~ PopCardinal[self];
pop: PROC RETURNS [Any] ~ { RETURN[PopAny[self]] };
v: Vector ~ MakeVec[n, pop];
PushVector[self, v];
};
ApplySHAPE: PUBLIC PROC [self: Ref] ~ {
v: Vector ~ PopVector[self];
shape: VectorShape ~ Shape[v];
PushCardinal[self, shape.lowerBound]; PushCardinal[self, shape.size];
};
ApplyGETPROP: PUBLIC PROC [self: Ref] ~ {
propName: Any ~ PopAny[self];
v: Vector ~ PopVector[self];
found: BOOL; value: Any;
[found, value] ← GetProp[v, propName];
IF found THEN PushAny[self, value];
PushBool[self, found];
};
ApplyGETP: PUBLIC PROC [self: Ref] ~ {
propName: Any ~ PopAny[self];
v: Vector ~ PopVector[self];
PushAny[self, GetP[v, propName]];
};
ApplyMERGEPROP: PUBLIC PROC [self: Ref] ~ {
v2: Vector ~ PopVector[self];
v1: Vector ~ PopVector[self];
PushVector[self, MergeProp[v1, v2]];
};
Frame operators (2.4.4)
ApplyFGET: PUBLIC PROC [self: Ref] ~ {
j: Cardinal ~ PopCardinal[self];
PushAny[self, FGet[self, j]];
};
ApplyFSET: PUBLIC PROC [self: Ref] ~ {
j: Cardinal ~ PopCardinal[self];
x: Any ~ PopAny[self];
FSet[self, x, j];
};
Operator operators (2.4.5)
ApplyMAKESIMPLECO: PUBLIC PROC [self: Ref] ~ {
b: Body ~ GetInlineBody[self];
PushOperator[self, MakeCO[frame: Frame[self], env: Env[self], body: b]];
};
ApplyDO: PUBLIC PROC [self: Ref] ~ {
op: Operator ~ PopOperator[self];
Do[self, op];
};
ApplyDOSAVE: PUBLIC PROC [self: Ref] ~ {
op: Operator ~ PopOperator[self];
action: PROC ~ { Do[self, op] };
DoSave[self, action];
};
ApplyDOSAVEALL: PUBLIC PROC [self: Ref] ~ {
op: Operator ~ PopOperator[self];
action: PROC ~ { Do[self, op] };
DoSaveAll[self, action];
};
ApplyDOSAVESIMPLEBODY: PUBLIC PROC [self: Ref] ~ {
frame: Vector ~ Frame[self];
env: Vector ~ Env[self];
action: PROC ~ { CallInlineBody[self: self, frame: frame, env: env] };
DoSave[self, action];
};
ApplyFINDOPERATOR: PUBLIC PROC [self: Ref] ~ {
v: Vector ~ PopVector[self];
MasterError[$unimplemented, "Not implemented: FINDOPERATOR"];
};
Stack operators (2.4.6)
ApplyPOP: PUBLIC PROC [self: Ref] ~ {
Pop[self];
};
ApplyCOPY: PUBLIC PROC [self: Ref] ~ {
n: Cardinal ~ PopCardinal[self];
Copy[self: self, depth: n];
};
ApplyDUP: PUBLIC PROC [self: Ref] ~ {
Copy[self: self, depth: 1];
};
ApplyROLL: PUBLIC PROC [self: Ref] ~ {
moveFirst: Cardinal ~ PopCardinal[self];
depth: Cardinal ~ PopCardinal[self];
Roll[self: self, depth: depth, moveFirst: moveFirst];
};
ApplyEXCH: PUBLIC PROC [self: Ref] ~ {
Roll[self: self, depth: 2, moveFirst: 1];
};
ApplyMARK: PUBLIC PROC [self: Ref] ~ {
n: Cardinal ~ PopCardinal[self];
Mark[self, n];
};
ApplyUNMARK: PUBLIC PROC [self: Ref] ~ {
n: Cardinal ~ PopCardinal[self];
Unmark[self, n];
};
ApplyUNMARK0: PUBLIC PROC [self: Ref] ~ {
Unmark[self, 0];
};
ApplyCOUNT: PUBLIC PROC [self: Ref] ~ {
PushCardinal[self, Count[self]];
};
ApplyNOP: PUBLIC PROC [self: Ref] ~ {
};
ApplyERROR: PUBLIC PROC [self: Ref] ~ {
code: Cardinal ~ PopCardinal[self];
message: Vector ~ PopVector[self];
ReportError[code, $ERROR, RopeFromVector[message]];
};
Control operators (2.4.7)
ApplyIF: PUBLIC PROC [self: Ref] ~ {
bool: BOOL ~ PopBool[self];
IF bool THEN CallInlineBody[self: self, frame: Frame[self], env: Env[self]]
ELSE SkipInlineBody[self];
};
ApplyIFELSE: PUBLIC PROC [self: Ref] ~ {
bool: BOOL ~ PopBool[self];
IF bool THEN CallInlineBody[self: self, frame: Frame[self], env: Env[self]]
ELSE SkipInlineBody[self];
PushBool[self, NOT bool];
};
ApplyIFCOPY: PUBLIC PROC [self: Ref] ~ {
testCopy: Operator ~ PopOperator[self];
MasterWarning[$unimplemented, "Not implemented: IFCOPY"];
SkipInlineBody[self];
};
Test operators (2.4.8)
ApplyEQ: PUBLIC PROC [self: Ref] ~ {
b: Any ~ PopAny[self];
a: Any ~ PopAny[self];
PushBool[self, Eq[a, b]];
};
ApplyGT: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushBool[self, a>b];
};
ApplyGE: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushBool[self, a>=b];
};
ApplyAND: PUBLIC PROC [self: Ref] ~ {
b: BOOL ~ PopBool[self];
a: BOOL ~ PopBool[self];
PushBool[self, a AND b];
};
ApplyOR: PUBLIC PROC [self: Ref] ~ {
b: BOOL ~ PopBool[self];
a: BOOL ~ PopBool[self];
PushBool[self, a OR b];
};
ApplyNOT: PUBLIC PROC [self: Ref] ~ {
b: BOOL ~ PopBool[self];
PushBool[self, NOT b];
};
ApplyTYPE: PUBLIC PROC [self: Ref] ~ {
code: TypeCode ~ TopType[self];
Pop[self]; PushCardinal[self, ORD[code]];
};
Arithmetic operators (2.4.9)
ApplyADD: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, a+b];
};
ApplySUB: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, a-b];
};
ApplyNEG: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, -a];
};
ApplyABS: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, ABS[a]];
};
ApplyFLOOR: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, IPReal.Floor[a]];
};
ApplyCEILING: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, IPReal.Ceiling[a]];
};
ApplyTRUNC: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, IPReal.Trunc[a]];
};
ApplyROUND: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, IPReal.Round[a]];
};
ApplyMUL: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, a*b];
};
ApplyDIV: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, a/b];
};
ApplyMOD: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, IPReal.Mod[a, b]];
};
ApplyREM: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, IPReal.Rem[a, b]];
};
Extra operators for Full Interpress
ApplyOPENVEC: PUBLIC PROC [self: Ref] ~ {
v: Vector ~ PopVector[self];
shape: VectorShape ~ Shape[v];
FOR i: Cardinal IN[shape.lowerBound..shape.lowerBound+shape.size) DO
PushAny[self, Get[v, i]];
ENDLOOP;
};
ApplyFRAME: PUBLIC PROC [self: Ref] ~ {
PushVector[self, Frame[self]];
};
ApplyPOOLOP: PUBLIC PROC [self: Ref] ~ {
PushOperator[self, OperatorFromPool[PoolOp[self]]];
};
ApplyPOOL: PUBLIC PROC [self: Ref] ~ {
PushVector[self, VectorFromPool[PoolOp[self]]];
};
ApplyPGET: PUBLIC PROC [self: Ref] ~ {
j: Cardinal ~ PopCardinal[self];
PushAny[self, PGet[self, j]];
};
ApplyPSET: PUBLIC PROC [self: Ref] ~ {
j: Cardinal ~ PopCardinal[self];
x: Any ~ PopAny[self];
PSet[self, x, j];
};
ApplyENV: PUBLIC PROC [self: Ref] ~ {
PushVector[self, Env[self]];
};
ApplyMAKEPOOL: PUBLIC PROC [self: Ref] ~ {
persistent: BOOL ~ PopBool[self];
v: Vector ~ PopVector[self];
PushOperator[self, OperatorFromPool[MakePool[v, persistent]]];
};
ApplyNOPOOL: PUBLIC PROC [self: Ref] ~ {
PushOperator[self, OperatorFromPool[NoPool[]]];
};
ApplyMAKECO: PUBLIC PROC [self: Ref] ~ {
b: Body ~ GetInlineBody[self];
f: Vector ~ PopVector[self];
PushOperator[self, MakeCO[frame: f, env: Env[self], body: b]];
};
ApplyDOBODY: PUBLIC PROC [self: Ref] ~ {
frame: Vector ~ PopVector[self];
env: Vector ~ Env[self];
CallInlineBody[self: self, frame: frame, env: env];
};
ApplyDOSAVEBODY: PUBLIC PROC [self: Ref] ~ {
frame: Vector ~ PopVector[self];
env: Vector ~ Env[self];
action: PROC ~ { CallInlineBody[self: self, frame: frame, env: env] };
DoSave[self, action];
};
ApplyDOSAVEALLBODY: PUBLIC PROC [self: Ref] ~ {
frame: Vector ~ PopVector[self];
env: Vector ~ Env[self];
action: PROC ~ { CallInlineBody[self: self, frame: frame, env: env] };
DoSaveAll[self, action];
};
ApplyMAKECOMPILEDIMAGE: PUBLIC PROC [self: Ref] ~ {
body: Body ~ GetInlineBody[self];
frame: Vector ~ PopVector[self];
env: Vector ~ Env[self];
PushOperator[self, MakeCompiledImage[frame: frame, env: env, body: body]];
};
ApplyLOOP: PUBLIC PROC [self: Ref] ~ {
body: Body ~ GetInlineBody[self];
op: Operator ~ MakeCO[frame: Frame[self], env: Env[self], body: body];
DO Do[self, op]; IF NOT PopBool[self] THEN EXIT ENDLOOP;
};
ApplyEQNAME: PUBLIC PROC [self: Ref] ~ {
b: Any ~ PopAny[self];
a: Any ~ PopAny[self];
PushBool[self, EqName[a, b]];
};
ApplyMAX: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, MAX[a, b]];
};
ApplyMIN: PUBLIC PROC [self: Ref] ~ {
b: REAL ~ PopReal[self];
a: REAL ~ PopReal[self];
PushReal[self, MIN[a, b]];
};
ApplySQRT: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, RealFns.SqRt[a]];
};
ApplyEXP: PUBLIC PROC [self: Ref] ~ {
e: REAL ~ PopReal[self];
b: REAL ~ PopReal[self];
PushReal[self, RealFns.Power[b, e]];
};
ApplyLOG: PUBLIC PROC [self: Ref] ~ {
v: REAL ~ PopReal[self];
b: REAL ~ PopReal[self];
PushReal[self, RealFns.Log[b, v]];
};
ApplySIN: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, RealFns.SinDeg[a]];
};
ApplyCOS: PUBLIC PROC [self: Ref] ~ {
a: REAL ~ PopReal[self];
PushReal[self, RealFns.CosDeg[a]];
};
ApplyATAN: PUBLIC PROC [self: Ref] ~ {
x: REAL ~ PopReal[self];
y: REAL ~ PopReal[self];
PushReal[self, RealFns.ArcTanDeg[y, x]];
};
END.