home
/
code
/
tiger.ml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
WIP type-checking
[tiger.ml.git]
/
compiler
/
src
/
lib
/
tiger
/
tiger_env_type.ml
diff --git
a/compiler/src/lib/tiger/tiger_env_type.ml
b/compiler/src/lib/tiger/tiger_env_type.ml
index
041d421
..
bb8cdd6
100644
(file)
--- a/
compiler/src/lib/tiger/tiger_env_type.ml
+++ b/
compiler/src/lib/tiger/tiger_env_type.ml
@@
-15,13
+15,15
@@
type t =
| String
| Record of
{ unique : unique
| String
| Record of
{ unique : unique
- ; fields :
(Symbol.t * t) list
+ ; fields :
record_fields
}
| Array of
{ unique : unique
; ty : t
}
| Name of Symbol.t * t option ref
}
| Array of
{ unique : unique
; ty : t
}
| Name of Symbol.t * t option ref
+and record_fields =
+ (Tiger_symbol.t * t) list
type env =
(Symbol.t, t ) Map.t
type env =
(Symbol.t, t ) Map.t
@@
-50,23
+52,29
@@
let is_equal t1 t2 =
* TODO: Can we ignore the warning locally?
* *)
* TODO: Can we ignore the warning locally?
* *)
-let is_record = function
+let is_int t =
+ t = Int
+
+let is_string t =
+ t = String
+
+let is_array = function
| Unit
| Int
| String
| Name _
| Unit
| Int
| String
| Name _
- |
Array _ -> false
- |
Nil (* nil belongs to ANY record *)
- |
Record
_ -> true
+ |
Nil
+ |
Record _ -> false
+ |
Array
_ -> true
-let is_
int
= function
+let is_
record
= function
| Unit
| Unit
- |
Nil
+ |
Int
| String
| Name _
| String
| Name _
- |
Record _
+ |
Nil
| Array _ -> false
| Array _ -> false
- |
Int
-> true
+ |
Record _
-> true
let is_name = function
| Unit
let is_name = function
| Unit
@@
-77,6
+85,18
@@
let is_name = function
| Array _ -> false
| Name _ -> true
| Array _ -> false
| Name _ -> true
+let if_record t ~f ~otherwise =
+ match t with
+ | Record {fields; _} ->
+ f fields
+ | Unit
+ | Int
+ | String
+ | Name _
+ | Nil
+ | Array _ ->
+ otherwise ()
+
let to_string = function
| Unit -> "unit"
| Nil -> "nil"
let to_string = function
| Unit -> "unit"
| Nil -> "nil"
This page took
0.027741 seconds
and
4
git commands to generate.