3 module List = ListLabels
6 module Symbol = Tiger_symbol
18 ; fields : record_fields
24 | Name of Symbol.t * t option ref
26 (Tiger_symbol.t * t) list
34 let new_record fields =
37 ; unique = new_unique ()
43 ; unique = new_unique ()
48 | Record {unique=u1; _}, Record {unique=u2; _} -> u1 == u2
49 | Array {unique=u1; _}, Array {unique=u2; _} -> u1 == u2
51 (* The above pattern matching is "fragile" and I'm OK with it.
52 * TODO: Can we ignore the warning locally?
61 let is_array = function
70 let is_record = function
79 let is_name = function
88 let if_record t ~f ~otherwise =
90 | Record {fields; _} ->
100 let if_array t ~f ~otherwise =
112 let to_string = function
116 | Record {unique; _} -> sprintf "record(%d)" (Obj.magic unique)
117 | Array {unique; _} -> sprintf "array(%d)" (Obj.magic unique)
119 | Name (name, _) -> Symbol.to_string name
125 ; ("string" , String)
127 |> List.map ~f:(fun (k, v) -> (Symbol.of_string k, v))