(* Copyright (C) 1989, Digital Equipment Corporation *) (* All rights reserved. *) (* See the file COPYRIGHT for a full description. *) (* File: Ceiling.m3 *) (* Last Modified On Tue Mar 20 03:06:30 1990 By muller *) (* Modified On Fri Jul 14 17:03:02 1989 By kalsow *) MODULE Ceiling; IMPORT CallExpr, Expr, Type, Procedure, Int, Reel, Longreal, Text; IMPORT Emit, Error, RealExpr, LongrealExpr, IntegerExpr, Temp; VAR Z: CallExpr.MethodList; PROCEDURE Bind (<*UNUSED*> proc: Expr.T; <*UNUSED*> args: Expr.List): Type.T = BEGIN RETURN Int.T; END Bind; PROCEDURE Check (<*UNUSED*> proc: Expr.T; VAR args: Expr.List) = BEGIN DoCheck ("CEILING", args); END Check; PROCEDURE DoCheck (name: Text.T; args: Expr.List) = VAR t: Type.T; BEGIN t := Type.Base (Expr.TypeOf (args[0])); IF (t # Reel.T) AND (t # Longreal.T) THEN Error.ID (name, "wrong argument type"); END; END DoCheck; PROCEDURE Compile (<*UNUSED*> proc: Expr.T; args: Expr.List): Temp.T = VAR t1, t2: Temp.T; BEGIN t1 := Expr.Compile (args[0]); t2 := Temp.AllocEmpty (Int.T); Emit.OpTT ("@ = CEILING (@);\n", t2, t1); Temp.Free (t1); RETURN t2; END Compile; PROCEDURE Fold (<*UNUSED*> proc: Expr.T; args: Expr.List): Expr.T = VAR i: INTEGER; x: LONGREAL; e: Expr.T; BEGIN e := Expr.ConstValue (args[0]); IF (e = NIL) OR NOT (RealExpr.Split (e, x) OR LongrealExpr.Split (e, x)) THEN RETURN NIL; END; i := TRUNC (x); IF (x > 0.0d+0) AND (LONGFLOAT (i) # x) THEN INC (i) END; RETURN IntegerExpr.New (i); END Fold; PROCEDURE Initialize () = BEGIN Z := CallExpr.NewMethodList (1, 1, TRUE, Bind, Check, Compile, Fold, CallExpr.IsNever, (* writable *) CallExpr.IsNever(* designator *)); Procedure.Define ("CEILING", Z); END Initialize; BEGIN END Ceiling.