|
@@ -1,8 +1,3 @@
|
|
|
-open Printf
|
|
|
|
|
-open Types
|
|
|
|
|
-open Util
|
|
|
|
|
-open Stringify
|
|
|
|
|
-
|
|
|
|
|
(*
|
|
(*
|
|
|
* Do a number of checks:
|
|
* Do a number of checks:
|
|
|
* - A void function must not return a value.
|
|
* - A void function must not return a value.
|
|
@@ -19,6 +14,13 @@ open Stringify
|
|
|
* a boolean.
|
|
* a boolean.
|
|
|
* - Only values having a basic type can be type cast.
|
|
* - Only values having a basic type can be type cast.
|
|
|
*)
|
|
*)
|
|
|
|
|
+open Printf
|
|
|
|
|
+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
|
|
let array_depth = function
|
|
|
| ArrayDims (_, dims) -> List.length dims
|
|
| ArrayDims (_, dims) -> List.length dims
|
|
@@ -181,9 +183,15 @@ let rec typecheck node =
|
|
|
DoWhile (check_trav Bool cond, typecheck body, ann)
|
|
DoWhile (check_trav Bool cond, typecheck body, ann)
|
|
|
|
|
|
|
|
(* Constants *)
|
|
(* Constants *)
|
|
|
- | Const (BoolVal value, ann) -> Const (BoolVal value, Type Bool :: ann)
|
|
|
|
|
- | Const (IntVal value, ann) -> Const (IntVal value, Type Int :: ann)
|
|
|
|
|
- | Const (FloatVal value, ann) -> Const (FloatVal value, Type Float :: ann)
|
|
|
|
|
|
|
+ | Const (BoolVal value, ann) ->
|
|
|
|
|
+ Const (BoolVal value, Type Bool :: ann)
|
|
|
|
|
+ | Const (IntVal value, ann) ->
|
|
|
|
|
+ if value < min_int || value > max_int then (
|
|
|
|
|
+ raise (NodeError (node, "integer value out of range"))
|
|
|
|
|
+ );
|
|
|
|
|
+ Const (IntVal value, Type Int :: ann)
|
|
|
|
|
+ | Const (FloatVal value, ann) ->
|
|
|
|
|
+ Const (FloatVal value, Type Float :: ann)
|
|
|
|
|
|
|
|
(* Variables inherit the type of their declaration *)
|
|
(* Variables inherit the type of their declaration *)
|
|
|
| VarUse (dec, None, ann) ->
|
|
| VarUse (dec, None, ann) ->
|