TJaMMathImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Original version by John Warnock, February 27, 1979
Bill Paxton, December 19, 1980 9:35 AM
McGregor, September 10, 1982 11:17 am
Doug Wyatt, March 25, 1985 4:44:33 pm PST
DIRECTORY
TJaM,
RealFns USING [ArcTanDeg, CosDeg, Log, Power, SinDeg, SqRt];
TJaMMathImpl: CEDAR PROGRAM
IMPORTS TJaM, RealFns
= BEGIN OPEN TJaM;
ApplyAdd: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushReal[frame, a+b];
};
ApplySub: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushReal[frame, a-b];
};
ApplyMul: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushReal[frame, a*b];
};
ApplyDiv: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushReal[frame, a/b];
};
ApplyIDiv: PUBLIC PROC[frame: Frame] ~ {
b: INT ~ PopInt[frame];
a: INT ~ PopInt[frame];
PushInt[frame, a/b];
};
ApplyNeg: PUBLIC PROC[frame: Frame] ~ {
a: REAL ~ PopReal[frame];
PushReal[frame, -a];
};
ApplySin: PUBLIC PROC[frame: Frame] ~ {
a: REAL ~ PopReal[frame];
PushReal[frame, RealFns.SinDeg[a]];
};
ApplyCos: PUBLIC PROC[frame: Frame] ~ {
a: REAL ~ PopReal[frame];
PushReal[frame, RealFns.CosDeg[a]];
};
ApplyATan: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushReal[frame, RealFns.ArcTanDeg[a, b ! ANY => GOTO Fail]];
EXITS Fail => ProduceError[numericOverflow];
};
ApplyExp: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushReal[frame, RealFns.Power[a, b ! ANY => GOTO Fail]];
EXITS Fail => ProduceError[numericOverflow];
};
ApplyLog: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushReal[frame, RealFns.Log[a, b ! ANY => GOTO Fail]]
EXITS Fail => ProduceError[numericOverflow];
};
ApplySqRt: PUBLIC PROC[frame: Frame] ~ {
a: REAL ~ PopReal[frame];
PushReal[frame, RealFns.SqRt[a ! ANY => GOTO Fail]]
EXITS Fail => ProduceError[numericOverflow];
};
ApplyEq: PUBLIC PROC[frame: Frame] ~ {
b: REF ~ Pop[frame];
a: REF ~ Pop[frame];
PushBool[frame, Equal[a,b]];
};
ApplyLt: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushBool[frame, a<b];
};
ApplyGt: PUBLIC PROC[frame: Frame] ~ {
b: REAL ~ PopReal[frame];
a: REAL ~ PopReal[frame];
PushBool[frame, a>b];
};
ApplyNot: PUBLIC PROC[frame: Frame] ~ {
a: BOOL ~ PopBool[frame];
PushBool[frame, NOT a];
};
ApplyAnd: PUBLIC PROC[frame: Frame] ~ {
b: BOOL ~ PopBool[frame];
a: BOOL ~ PopBool[frame];
PushBool[frame, a AND b];
};
ApplyOr: PUBLIC PROC[frame: Frame] ~ {
b: BOOL ~ PopBool[frame];
a: BOOL ~ PopBool[frame];
PushBool[frame, a OR b];
};
ApplyXor: PUBLIC PROC[frame: Frame] ~ {
b: BOOL ~ PopBool[frame];
a: BOOL ~ PopBool[frame];
PushBool[frame, a # b];
};
ApplyBitNot: PUBLIC PROC[frame: Frame] ~ {
a: INT ~ PopInt[frame];
PushInt[frame, Basics.DoubleNot[[li[a]]].li];
};
ApplyBitAnd: PUBLIC PROC[frame: Frame] ~ {
b: INT ~ PopInt[frame];
a: INT ~ PopInt[frame];
PushInt[frame, Basics.DoubleAnd[[li[a]], [li[b]]].li];
};
ApplyBitOr: PUBLIC PROC[frame: Frame] ~ {
b: INT ~ PopInt[frame];
a: INT ~ PopInt[frame];
PushInt[frame, Basics.DoubleOr[[li[a]], [li[b]]].li];
};
ApplyBitXor: PUBLIC PROC[frame: Frame] ~ {
b: INT ~ PopInt[frame];
a: INT ~ PopInt[frame];
PushInt[frame, Basics.DoubleXor[[li[a]], [li[b]]].li];
};
ApplyBitShift: PUBLIC PROC[frame: Frame] ~ {
b: INT ~ PopInt[frame];
a: INT ~ PopInt[frame];
PushInt[frame, Basics.DoubleShift[[li[a]], b].li];
};
RegisterPrimitive[".add", ApplyAdd];
RegisterPrimitive[".sub", ApplySub];
RegisterPrimitive[".mul", ApplyMul];
RegisterPrimitive[".div", ApplyDiv];
RegisterPrimitive[".idiv", ApplyIDiv];
RegisterPrimitive[".neg", ApplyNeg];
RegisterPrimitive[".sin", ApplySin];
RegisterPrimitive[".cos", ApplyCos];
RegisterPrimitive[".atan", ApplyATan];
RegisterPrimitive[".exp", ApplyExp];
RegisterPrimitive[".log", ApplyLog];
RegisterPrimitive[".sqrt", ApplySqRt];
RegisterPrimitive[".eq", ApplyEq];
RegisterPrimitive[".lt", ApplyLt];
RegisterPrimitive[".gt", ApplyGt];
RegisterPrimitive[".not", ApplyNot];
RegisterPrimitive[".and", ApplyAnd];
RegisterPrimitive[".or", ApplyOr];
RegisterPrimitive[".xor", ApplyXor];
RegisterPrimitive[".bitnot", ApplyBitNot];
RegisterPrimitive[".bitand", ApplyBitAnd];
RegisterPrimitive[".bitor", ApplyBitOr];
RegisterPrimitive[".bitxor", ApplyBitXor];
RegisterPrimitive[".bitshift", ApplyBitShift];
END.