JaMMathImpl.mesa
Copyright Ó 1985, 1992 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 18, 1985 3:26:28 pm PST
Bier, September 15, 1992 4:20 pm PDT
DIRECTORY
Basics USING [BITAND, BITNOT, BITOR, BITSHIFT, BITXOR],
PBasics USING [BITAND, BITNOT, BITOR, BITSHIFT, BITXOR],
JaM USING [Eq, Error, Pop, PopBool, PopInt, PopReal, PushBool, PushInt, PushReal, State],
JaMPrimitives USING [],
RealFns USING [ArcTanDeg, CosDeg, Log, Power, SinDeg, SqRt];
JaMMathImpl: CEDAR PROGRAM
IMPORTS JaM, Basics, RealFns
EXPORTS JaMPrimitives
= BEGIN OPEN JaM;
ApplyAdd:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushReal[self, a+b];
};
ApplySub:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushReal[self, a-b];
};
ApplyMul:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushReal[self, a*b];
};
ApplyDiv:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushReal[self, a/b];
};
ApplyIDiv:
PUBLIC
PROC[self: State] = {
b: INT = PopInt[self];
a: INT = PopInt[self];
PushInt[self, a/b];
};
ApplyNeg:
PUBLIC
PROC[self: State] = {
a: REAL = PopReal[self];
PushReal[self, -a];
};
ApplySin:
PUBLIC
PROC[self: State] = {
a: REAL = PopReal[self];
PushReal[self, RealFns.SinDeg[a]];
};
ApplyCos:
PUBLIC
PROC[self: State] = {
a: REAL = PopReal[self];
PushReal[self, RealFns.CosDeg[a]];
};
ApplyATan:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushReal[self, RealFns.ArcTanDeg[a, b ! ANY => GOTO Fail]];
EXITS Fail => ERROR Error[NumericOverflow];
};
ApplyExp:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushReal[self, RealFns.Power[a, b ! ANY => GOTO Fail]];
EXITS Fail => ERROR Error[NumericOverflow];
};
ApplyLog:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushReal[self, RealFns.Log[a, b ! ANY => GOTO Fail]]
EXITS Fail => ERROR Error[NumericOverflow];
};
ApplySqRt:
PUBLIC
PROC[self: State] = {
a: REAL = PopReal[self];
PushReal[self, RealFns.SqRt[a ! ANY => GOTO Fail]]
EXITS Fail => ERROR Error[NumericOverflow];
};
ApplyEq:
PUBLIC
PROC[self: State] = {
b: REF = Pop[self];
a: REF = Pop[self];
PushBool[self, Eq[a,b]];
};
ApplyLt:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushBool[self, a<b];
};
ApplyGt:
PUBLIC
PROC[self: State] = {
b: REAL = PopReal[self];
a: REAL = PopReal[self];
PushBool[self, a>b];
};
ApplyNot:
PUBLIC
PROC[self: State] = {
a: BOOL = PopBool[self];
PushBool[self, NOT a];
};
ApplyAnd:
PUBLIC
PROC[self: State] = {
b: BOOL = PopBool[self];
a: BOOL = PopBool[self];
PushBool[self, a AND b];
};
ApplyOr:
PUBLIC
PROC[self: State] = {
b: BOOL = PopBool[self];
a: BOOL = PopBool[self];
PushBool[self, a OR b];
};
ApplyXor:
PUBLIC
PROC[self: State] = {
b: BOOL = PopBool[self];
a: BOOL = PopBool[self];
PushBool[self, a # b];
};
ApplyBitNot:
PUBLIC
PROC[self: State] = {
a: INT = PopInt[self];
PushInt[self, Basics.DoubleNot[[li[a]]].li];
PushInt[self, Basics.BITNOT[a]];
};
ApplyBitAnd:
PUBLIC
PROC[self: State] = {
b: INT = PopInt[self];
a: INT = PopInt[self];
PushInt[self, Basics.DoubleAnd[[li[a]], [li[b]]].li];
PushInt[self, Basics.BITAND[a,b]];
};
ApplyBitOr:
PUBLIC
PROC[self: State] = {
b: INT = PopInt[self];
a: INT = PopInt[self];
PushInt[self, Basics.DoubleOr[[li[a]], [li[b]]].li];
PushInt[self, Basics.BITOR[a,b]];
};
ApplyBitXor:
PUBLIC
PROC[self: State] = {
b: INT = PopInt[self];
a: INT = PopInt[self];
PushInt[self, Basics.DoubleXor[[li[a]], [li[b]]].li];
PushInt[self, Basics.BITXOR[a,b]];
};
ApplyBitShift:
PUBLIC
PROC[self: State] = {
b: INT = PopInt[self];
a: INT = PopInt[self];
PushInt[self, Basics.DoubleShift[[li[a]], b].li];
PushInt[self, Basics.BITSHIFT[a,b]];
};
END.