DIRECTORY IP USING [Any, CheckAny, Color, Discard, Get, Identifier, Integer, Number, Operator, Outline, PixelArray, Pop, PopBool, PopReal, PushBool, PushInteger, PushReal, Shape, State, TopType, Trajectory, Transformation, TypeCode, Vector, VectorShape], IPBase USING [], IPReal USING [Ceiling, Floor, Mod, Rem, Round, Trunc], Real USING [SqRt], RealFns USING [ArcTanDeg, CosDeg, Log, Power, SinDeg]; IPMathImpl: CEDAR PROGRAM IMPORTS IP, IPReal, Real, RealFns EXPORTS IP, IPBase ~ BEGIN OPEN IP; EqNumber: PROC[a, b: Number] RETURNS[BOOL] ~ INLINE { RETURN[a.value=b.value] }; EqIdentifier: PROC[a, b: ATOM] RETURNS[BOOL] ~ INLINE { RETURN[a=b] }; Eq: PUBLIC PROC[a, b: Any] RETURNS[BOOL] ~ { a _ CheckAny[a]; b _ CheckAny[b]; -- ensure that neither is NIL WITH a SELECT FROM a: Number => WITH b SELECT FROM b: Number => RETURN[EqNumber[a, b]]; ENDCASE; a: Identifier => WITH b SELECT FROM b: Identifier => RETURN[EqIdentifier[a, b]]; ENDCASE; ENDCASE; RETURN[FALSE]; }; EqVector: PROC[a, b: Vector] RETURNS[BOOL] ~ { shape: VectorShape ~ Shape[a]; IF Shape[b]#shape THEN RETURN[FALSE]; FOR i: Integer IN[shape.l..shape.l+shape.n) DO IF NOT Eq[Get[a, i], Get[b, i]] THEN RETURN[FALSE]; ENDLOOP; RETURN[TRUE]; }; EqName: PUBLIC PROC[a, b: Any] RETURNS[BOOL] ~ { a _ CheckAny[a]; b _ CheckAny[b]; -- ensure that neither is NIL IF Eq[a, b] THEN RETURN[TRUE]; WITH a SELECT FROM a: Vector => WITH b SELECT FROM b: Vector => RETURN[EqVector[a, b]]; ENDCASE; ENDCASE; RETURN[FALSE]; }; Type: PUBLIC PROC[a: Any] RETURNS[TypeCode] ~ { RETURN[WITH CheckAny[a] SELECT FROM x: Number => $Number, x: Identifier => $Identifier, x: Vector => $Vector, x: Operator => $Operator, x: Transformation => $Transformation, x: PixelArray => $PixelArray, x: Color => $Color, x: Trajectory => $Trajectory, x: Outline => $Outline, ENDCASE => $Other]; }; ApplyEQ: PUBLIC PROC[self: State] ~ { b: Any ~ Pop[self]; a: Any ~ Pop[self]; PushBool[self, Eq[a, b]]; }; ApplyEQNAME: PUBLIC PROC[self: State] ~ { b: Any ~ Pop[self]; a: Any ~ Pop[self]; PushBool[self, EqName[a, b]]; }; ApplyGT: PUBLIC PROC[self: State] ~ { b: REAL ~ PopReal[self]; a: REAL ~ PopReal[self]; PushBool[self, a>b]; }; ApplyGE: PUBLIC PROC[self: State] ~ { b: REAL ~ PopReal[self]; a: REAL ~ PopReal[self]; PushBool[self, a>=b]; }; 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]; }; ApplyNOT: PUBLIC PROC[self: State] ~ { b: BOOL ~ PopBool[self]; PushBool[self, NOT b]; }; ApplyTYPE: PUBLIC PROC[self: State] ~ { code: TypeCode ~ TopType[self]; Discard[self]; PushInteger[self, code.ORD]; }; 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]; }; ApplyNEG: PUBLIC PROC[self: State] ~ { a: REAL ~ PopReal[self]; PushReal[self, -a]; }; ApplyABS: PUBLIC PROC[self: State] ~ { a: REAL ~ PopReal[self]; PushReal[self, ABS[a]]; }; ApplyFLOOR: PUBLIC PROC[self: State] ~ { a: REAL ~ PopReal[self]; PushReal[self, IPReal.Floor[a]]; }; ApplyCEILING: PUBLIC PROC[self: State] ~ { a: REAL ~ PopReal[self]; PushReal[self, IPReal.Ceiling[a]]; }; ApplyTRUNC: PUBLIC PROC[self: State] ~ { a: REAL ~ PopReal[self]; PushReal[self, IPReal.Trunc[a]]; }; ApplyROUND: PUBLIC PROC[self: State] ~ { a: REAL ~ PopReal[self]; PushReal[self, IPReal.Round[a]]; }; 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]; }; ApplyMOD: PUBLIC PROC[self: State] ~ { b: REAL ~ PopReal[self]; a: REAL ~ PopReal[self]; PushReal[self, IPReal.Mod[a, b]]; }; ApplyREM: PUBLIC PROC[self: State] ~ { b: REAL ~ PopReal[self]; a: REAL ~ PopReal[self]; PushReal[self, IPReal.Rem[a, b]]; }; ApplyMAX: PUBLIC PROC[self: State] ~ { b: REAL ~ PopReal[self]; a: REAL ~ PopReal[self]; PushReal[self, MAX[a, b]]; }; ApplyMIN: PUBLIC PROC[self: State] ~ { b: REAL ~ PopReal[self]; a: REAL ~ PopReal[self]; PushReal[self, MIN[a, b]]; }; ApplySQRT: PUBLIC PROC[self: State] ~ { a: REAL ~ PopReal[self]; PushReal[self, Real.SqRt[a]]; }; ApplyEXP: PUBLIC PROC[self: State] ~ { e: REAL ~ PopReal[self]; b: REAL ~ PopReal[self]; PushReal[self, RealFns.Power[b, e]]; }; ApplyLOG: PUBLIC PROC[self: State] ~ { v: REAL ~ PopReal[self]; b: REAL ~ PopReal[self]; PushReal[self, RealFns.Log[b, v]]; }; 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] ~ { x: REAL ~ PopReal[self]; y: REAL ~ PopReal[self]; PushReal[self, RealFns.ArcTanDeg[y, x]]; }; END. ˛IPMathImpl.mesa Last edited by: Doug Wyatt, March 2, 1984 11:13:29 am PST This takes ATOM arguments: want to be sure to change it if the Identifier type ever changes! Ę]˜Jšœ™J™™J™)—J™šĎk ˜ Jšœœě˜ôJšœœ˜Jšœœ*˜6Jšœœ˜Jšœœ)˜6J˜—Jšœ œ˜Jšœœ˜!Jšœœ˜Jšœœœœ˜J™š Ďnœœœœœœ˜PJ˜—šž œœœœœœœ˜FJšœ œM™\J˜—š žœœœ œœ˜,Jšœ"Ďc˜?šœœ˜šœ œœ˜Jšœ œ˜$Jšœ˜—šœœœ˜#Jšœœ˜,Jšœ˜—Jšœ˜—Jšœœ˜J˜J˜—šžœœœœ˜.J˜Jšœœœœ˜%šœ œ˜.Jš œœœœœ˜3Jšœ˜—Jšœœ˜ J˜J˜—š žœœœ œœ˜0Jšœ"Ÿ˜?Jšœ œœœ˜šœœ˜šœ œœ˜Jšœ œ˜$Jšœ˜—Jšœ˜—Jšœœ˜J˜J˜—šžœœœ œ˜/šœœ œ˜#Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ%˜%Jšœ˜Jšœ˜Jšœ˜Jšœ˜Jšœ ˜—J˜J˜—šžœœœ˜%J˜J˜Jšœ˜J˜J˜—šž œœœ˜)J˜J˜Jšœ˜J˜J˜—šžœœœ˜%Jšœœ˜Jšœœ˜Jšœ˜J˜J˜—šžœœœ˜%Jšœœ˜Jšœœ˜Jšœ˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜Jšœœ˜J˜J˜—šžœœœ˜%Jšœœ˜Jšœœ˜Jšœœ˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜J˜J˜—J˜šž œœœ˜'J˜.Jšœœ˜J˜J˜—J™šžœœœ˜&Jšœœ˜Jšœœ˜J˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜J˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœ˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜J˜J˜—šž œœœ˜(Jšœœ˜Jšœ ˜ J˜J˜—šž œœœ˜*Jšœœ˜Jšœ"˜"J˜J˜—šž œœœ˜(Jšœœ˜Jšœ ˜ J˜J˜—šž œœœ˜(Jšœœ˜Jšœ ˜ J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜J˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜J˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜Jšœ!˜!J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜Jšœ!˜!J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜Jšœœ˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜Jšœœ˜J˜J˜—šž œœœ˜'Jšœœ˜Jšœ˜J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜Jšœ$˜$J˜J˜—šžœœœ˜&Jšœœ˜Jšœœ˜Jšœ"˜"J˜J˜—šžœœœ˜&Jšœœ˜Jšœ"˜"J˜J˜—šžœœœ˜&Jšœœ˜Jšœ"˜"J˜J˜—šž œœœ˜'Jšœœ˜Jšœœ˜Jšœ(˜(J˜J˜—J˜Jšœ˜—…—z‰