Преглед изворни кода

Integer bound check now uses Nativeint module so that it works on all platforms

Taddeus Kroes пре 12 година
родитељ
комит
1ba7a9c726
1 измењених фајлова са 4 додато и 4 уклоњено
  1. 4 4
      phases/typecheck.ml

+ 4 - 4
phases/typecheck.ml

@@ -19,9 +19,6 @@ open Types
 open Util
 open Stringify
 
-let min_int = int_of_float (-.(2. ** 31.))
-let max_int = int_of_float (2. ** 31.) - 1
-
 let array_depth = function
     | ArrayDims (_, dims) -> List.length dims
     | _                   -> raise InvalidNode
@@ -191,7 +188,10 @@ let rec typecheck node =
     | Const (BoolVal value, ann) ->
         Const (BoolVal value, Type Bool :: ann)
     | Const (IntVal value, ann) ->
-        if value < min_int || value > max_int then (
+        (* Do a bound check on integers (use Nativeint because default ints in
+         * ocaml are 31- or 64-bit *)
+        let cmpval = Nativeint.of_int value in
+        if cmpval < Nativeint.min_int || cmpval > Nativeint.max_int then (
             raise (NodeError (node, "integer value out of range"))
         );
         Const (IntVal value, Type Int :: ann)