X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_env_type.ml;h=a2e719f37d5d8e315a63e4ce715ba18596d10e69;hb=80c3c410b1bdc70e7c13a76c77717c509353bb96;hp=bb8cdd605f54499df41f01d4dc3a08ef34446ce0;hpb=523e2b063b9ba20329af61e18dc9a5ccbaca06a0;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_env_type.ml b/compiler/src/lib/tiger/tiger_env_type.ml index bb8cdd6..a2e719f 100644 --- a/compiler/src/lib/tiger/tiger_env_type.ml +++ b/compiler/src/lib/tiger/tiger_env_type.ml @@ -45,7 +45,10 @@ let new_array ty = let is_equal t1 t2 = match t1, t2 with + | Name (s1, _) , Name (s2, _) -> Symbol.is_equal s1 s2 | Record {unique=u1; _}, Record {unique=u2; _} -> u1 == u2 + | Record _ , Nil -> true + | Nil , Record _ -> true | Array {unique=u1; _}, Array {unique=u2; _} -> u1 == u2 | t1 , t2 -> t1 = t2 (* The above pattern matching is "fragile" and I'm OK with it. @@ -97,6 +100,18 @@ let if_record t ~f ~otherwise = | Array _ -> otherwise () +let if_array t ~f ~otherwise = + match t with + | Array {ty=t; _} -> + f t + | Unit + | Int + | String + | Name _ + | Nil + | Record _ -> + otherwise () + let to_string = function | Unit -> "unit" | Nil -> "nil"