Commit | Line | Data |
---|---|---|
c0bdf964 | 1 | module Map = Tiger_map |
35dccbd3 | 2 | module Sym = Tiger_symbol |
c0bdf964 SK |
3 | module Type = Tiger_env_type |
4 | module Value = Tiger_env_value | |
5 | ||
6 | type t = | |
7 | { typs : Type.env | |
8 | ; vals : Value.env | |
35dccbd3 | 9 | ; loop : Sym.t option |
c0bdf964 SK |
10 | } |
11 | ||
12 | let base = | |
13 | { typs = Type.built_in | |
14 | ; vals = Value.built_in | |
35dccbd3 | 15 | ; loop = None |
c0bdf964 SK |
16 | } |
17 | ||
18 | let get_typ {typs; _} k = | |
19 | Map.get typs ~k | |
20 | ||
21 | let get_val {vals; _} k = | |
22 | Map.get vals ~k | |
23 | ||
24 | let set_typ t k v = | |
25 | {t with typs = Map.set t.typs ~k ~v} | |
26 | ||
27 | let set_val t k v = | |
28 | {t with vals = Map.set t.vals ~k ~v} | |
35dccbd3 SK |
29 | |
30 | let 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 | ||
35 | let 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 | ||
44 | let loop_current {loop; _} = | |
45 | loop |