<> <> <> <> <> <> 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, ab]; }; 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]; }; <> <> <> <<};>> <<>> <> <> <> <> <<};>> <<>> <> <> <> <> <<};>> <<>> <> <> <> <> <<};>> <<>> <> <> <> <> <<};>> <<>> 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]; <<>> <> <> <> <> <> END.