Add option iter
[tiger.ml.git] / compiler / src / lib / tiger / tiger_env.ml
... / ...
CommitLineData
1module Map = Tiger_map
2module Sym = Tiger_symbol
3module Type = Tiger_env_type
4module Value = Tiger_env_value
5
6type t =
7 { typs : Type.env
8 ; vals : Value.env
9 ; loop : Sym.t option
10 }
11
12let base =
13 { typs = Type.built_in
14 ; vals = Value.built_in
15 ; loop = None
16 }
17
18let get_typ {typs; _} k =
19 Map.get typs ~k
20
21let get_val {vals; _} k =
22 Map.get vals ~k
23
24let set_typ t k v =
25 {t with typs = Map.set t.typs ~k ~v}
26
27let set_val t k v =
28 {t with vals = Map.set t.vals ~k ~v}
29
30let loop_begin t =
31 let loop = Sym.unique_of_string "loop" in
32 let t = {t with loop = Some loop} in
33 (loop, t)
34
35let loop_end t given =
36 match t.loop with
37 | None ->
38 assert false
39 | Some current when (not (Sym.is_equal current given)) ->
40 assert false
41 | Some _ ->
42 {t with loop = None}
43
44let loop_current {loop; _} =
45 loop
This page took 0.027857 seconds and 4 git commands to generate.