Add option iter
[tiger.ml.git] / compiler / src / lib / tiger / tiger_env.ml
CommitLineData
c0bdf964 1module Map = Tiger_map
35dccbd3 2module Sym = Tiger_symbol
c0bdf964
SK
3module Type = Tiger_env_type
4module Value = Tiger_env_value
5
6type t =
7 { typs : Type.env
8 ; vals : Value.env
35dccbd3 9 ; loop : Sym.t option
c0bdf964
SK
10 }
11
12let base =
13 { typs = Type.built_in
14 ; vals = Value.built_in
35dccbd3 15 ; loop = None
c0bdf964
SK
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}
35dccbd3
SK
29
30let loop_begin t =
fd2204fa 31 let loop = Sym.unique_of_string "loop" in
35dccbd3
SK
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.029607 seconds and 4 git commands to generate.