<> <> <> <> <> <> DIRECTORY Basics USING [BITAND, BITNOT, BITOR, BITSHIFT, BITXOR, DoubleAnd, DoubleNot, DoubleOr, DoubleShift, DoubleXor], 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 Basics, JaM, 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, ab]; }; 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]; }; ApplyBitAnd: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, Basics.DoubleAnd[[li[a]], [li[b]]].li]; }; ApplyBitOr: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, Basics.DoubleOr[[li[a]], [li[b]]].li]; }; ApplyBitXor: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, Basics.DoubleXor[[li[a]], [li[b]]].li]; }; ApplyBitShift: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, Basics.DoubleShift[[li[a]], b].li]; }; END.