home
/
code
/
tiger.ml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Switch Type.unique implementation from ref to Symbol
[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
a2e719f
..
cef1ff1
100644
(file)
--- a/
compiler/src/lib/tiger/tiger_env_type.ml
+++ b/
compiler/src/lib/tiger/tiger_env_type.ml
@@
-1,12
+1,12
@@
open Printf
open Printf
-module List
= ListLabels
+module List = ListLabels
-module Map
= Tiger_map
-module Sym
bol
= Tiger_symbol
+module Map = Tiger_map
+module Sym = Tiger_symbol
type unique =
type unique =
- unit ref
+ Sym.t
type t =
| Unit
type t =
| Unit
@@
-21,36
+21,33
@@
type t =
{ unique : unique
; ty : t
}
{ unique : unique
; ty : t
}
- | Name of Sym
bol
.t * t option ref
+ | Name of Sym.t * t option ref
and record_fields =
(Tiger_symbol.t * t) list
type env =
and record_fields =
(Tiger_symbol.t * t) list
type env =
- (Sym
bol
.t, t ) Map.t
+ (Sym.t, t ) Map.t
-let new_unique () =
- ref ()
-
-let new_record fields =
+let new_record ~name ~fields =
Record
{ fields
Record
{ fields
- ; unique =
new_unique (
)
+ ; unique =
Sym.unique_of_string (Sym.to_string name
)
}
}
-let new_array ty =
+let new_array
~name ~
ty =
Array
{ ty
Array
{ ty
- ; unique =
new_unique (
)
+ ; unique =
Sym.unique_of_string (Sym.to_string name
)
}
let is_equal t1 t2 =
match t1, t2 with
}
let is_equal t1 t2 =
match t1, t2 with
- | Name (s1, _) , Name (s2, _) -> Sym
bol
.is_equal s1 s2
- | Record {unique=
u1; _}, Record {unique=u2; _} -> u1 == u
2
+ | Name (s1, _) , Name (s2, _) -> Sym.is_equal s1 s2
+ | Record {unique=
s1; _}, Record {unique=s2; _} -> Sym.is_equal s1 s
2
| Record _ , Nil -> true
| Nil , Record _ -> true
| Record _ , Nil -> true
| Nil , Record _ -> true
- | Array {unique=
u1; _}, Array {unique=u2; _} -> u1 == u
2
- | t1 , t2 -> t1 =
t2
+ | Array {unique=
s1; _}, Array {unique=s2; _} -> Sym.is_equal s1 s
2
+ | t1 , t2 -> t1 = t2
(* The above pattern matching is "fragile" and I'm OK with it.
* TODO: Can we ignore the warning locally?
* *)
(* The above pattern matching is "fragile" and I'm OK with it.
* TODO: Can we ignore the warning locally?
* *)
@@
-116,10
+113,10
@@
let to_string = function
| Unit -> "unit"
| Nil -> "nil"
| String -> "string"
| Unit -> "unit"
| Nil -> "nil"
| String -> "string"
- | Record {unique; _} -> sprintf "
record(%d)" (Obj.magic
unique)
- | Array {unique; _} -> sprintf "
array(%d)" (Obj.magic
unique)
+ | Record {unique; _} -> sprintf "
Record[%s]" (Sym.to_string
unique)
+ | Array {unique; _} -> sprintf "
Array[%s]" (Sym.to_string
unique)
| Int -> "int"
| Int -> "int"
- | Name (name, _) -> Sym
bol
.to_string name
+ | Name (name, _) -> Sym.to_string name
let built_in =
[ ("unit" , Unit)
let built_in =
[ ("unit" , Unit)
@@
-127,5
+124,5
@@
let built_in =
; ("int" , Int)
; ("string" , String)
]
; ("int" , Int)
; ("string" , String)
]
- |> List.map ~f:(fun (k, v) -> (Sym
bol
.of_string k, v))
+ |> List.map ~f:(fun (k, v) -> (Sym.of_string k, v))
|> Map.of_list
|> Map.of_list
This page took
0.020346 seconds
and
4
git commands to generate.