X-Git-Url: https://git.xandkar.net/?a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_env.ml;h=504e9bde71f5d3c9bb5f76b0a1fc20f20d1a64b8;hb=fd2204fa98928a900f303209818dce7f2bae3c8a;hp=f698f89563175a094cdcc27f02e17cf85cc0b076;hpb=c0bdf964d389a2b9465fad44aa1f1f849c72140f;p=tiger.ml.git diff --git a/compiler/src/lib/tiger/tiger_env.ml b/compiler/src/lib/tiger/tiger_env.ml index f698f89..504e9bd 100644 --- a/compiler/src/lib/tiger/tiger_env.ml +++ b/compiler/src/lib/tiger/tiger_env.ml @@ -1,15 +1,18 @@ module Map = Tiger_map +module Sym = Tiger_symbol module Type = Tiger_env_type module Value = Tiger_env_value type t = { typs : Type.env ; vals : Value.env + ; loop : Sym.t option } let base = { typs = Type.built_in ; vals = Value.built_in + ; loop = None } let get_typ {typs; _} k = @@ -23,3 +26,20 @@ let set_typ t k v = let set_val t k v = {t with vals = Map.set t.vals ~k ~v} + +let loop_begin t = + let loop = Sym.unique_of_string "loop" in + let t = {t with loop = Some loop} in + (loop, t) + +let loop_end t given = + match t.loop with + | None -> + assert false + | Some current when (not (Sym.is_equal current given)) -> + assert false + | Some _ -> + {t with loop = None} + +let loop_current {loop; _} = + loop