DIRECTORY Basics USING [BITAND, BITNOT, BITOR, BITSHIFT, BITXOR, LongNumber], 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]; }; Long: TYPE = Basics.LongNumber; LongBITNOT: PROC[a: Long] RETURNS[Long] = { RETURN[[num[highbits: Basics.BITNOT[a.highbits], lowbits: Basics.BITNOT[a.lowbits]]]]; }; LongBITOR: PROC[a, b: Long] RETURNS[Long] = { RETURN[[num[highbits: Basics.BITOR[a.highbits, b.highbits], lowbits: Basics.BITOR[a.lowbits, b.lowbits]]]]; }; LongBITAND: PROC[a, b: Long] RETURNS[Long] = { RETURN[[num[highbits: Basics.BITAND[a.highbits, b.highbits], lowbits: Basics.BITAND[a.lowbits, b.lowbits]]]]; }; LongBITXOR: PROC[a, b: Long] RETURNS[Long] = { RETURN[[num[highbits: Basics.BITXOR[a.highbits, b.highbits], lowbits: Basics.BITXOR[a.lowbits, b.lowbits]]]]; }; LongBITSHIFT: PROC[a: Long, b: INT] RETURNS[Long] = { SELECT b FROM <-31 => RETURN[[num[highbits: 0, lowbits: 0]]]; <-15 => RETURN[[num[ highbits: 0, lowbits: Basics.BITSHIFT[a.highbits, b+16]]]]; <0 => RETURN[[num[ highbits: Basics.BITSHIFT[a.highbits, b], lowbits: Basics.BITOR[Basics.BITSHIFT[a.lowbits, b], Basics.BITSHIFT[a.highbits, b+16]]]]]; <16 => RETURN[[num[ highbits: Basics.BITOR[Basics.BITSHIFT[a.highbits, b], Basics.BITSHIFT[a.lowbits, b-16]], lowbits: Basics.BITSHIFT[a.lowbits, b]]]]; <32 => RETURN[[num[ highbits: Basics.BITSHIFT[a.lowbits, b-16], lowbits: 0]]]; ENDCASE => RETURN[[num[highbits: 0, lowbits: 0]]]; }; ApplyBitNot: PUBLIC PROC[self: State] = { a: INT = PopInt[self]; PushInt[self, LongBITNOT[[li[a]]].li]; }; ApplyBitAnd: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, LongBITAND[[li[a]], [li[b]]].li]; }; ApplyBitOr: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, LongBITOR[[li[a]], [li[b]]].li]; }; ApplyBitXor: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, LongBITXOR[[li[a]], [li[b]]].li]; }; ApplyBitShift: PUBLIC PROC[self: State] = { b: INT = PopInt[self]; a: INT = PopInt[self]; PushInt[self, LongBITSHIFT[[li[a]], b].li]; }; END. ÐJaMMathImpl.mesa Last edited by: 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, November 21, 1983 1:26 pm Ê$˜Jšœ™J™™Jšœ3™3Jšœ'™'Jšœ%™%Jšœ%™%—J˜šÏk ˜ Jš œœœœœœœ˜CJšœœP˜YJšœœ˜Jšœœ/˜