From fd2204fa98928a900f303209818dce7f2bae3c8a Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Tue, 18 Sep 2018 16:55:25 -0400 Subject: [PATCH] Fix Symbol.new_of_string - it should not save also rename it to unique_of_string to clarify the main idea --- compiler/src/lib/tiger/tiger_env.ml | 2 +- compiler/src/lib/tiger/tiger_symbol.ml | 15 +++++++-------- compiler/src/lib/tiger/tiger_symbol.mli | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/compiler/src/lib/tiger/tiger_env.ml b/compiler/src/lib/tiger/tiger_env.ml index 1e4cd1d..504e9bd 100644 --- a/compiler/src/lib/tiger/tiger_env.ml +++ b/compiler/src/lib/tiger/tiger_env.ml @@ -28,7 +28,7 @@ let set_val t k v = {t with vals = Map.set t.vals ~k ~v} let loop_begin t = - let loop = Sym.new_of_string "loop" in + let loop = Sym.unique_of_string "loop" in let t = {t with loop = Some loop} in (loop, t) diff --git a/compiler/src/lib/tiger/tiger_symbol.ml b/compiler/src/lib/tiger/tiger_symbol.ml index b5d895b..747cb03 100644 --- a/compiler/src/lib/tiger/tiger_symbol.ml +++ b/compiler/src/lib/tiger/tiger_symbol.ml @@ -9,20 +9,19 @@ let counter = ref 0 let symbols = H.create 16 -let next name = +let unique_of_string name = incr counter; let symbol = !counter in {name; symbol} -let new_of_string name = - let t = next name in - H.replace symbols ~key:t.name ~data:t.symbol; - t - let of_string name = match H.find_opt symbols name with - | Some s -> {name; symbol=s} - | None -> new_of_string name + | Some symbol -> + {name; symbol} + | None -> + let t = unique_of_string name in + H.replace symbols ~key:t.name ~data:t.symbol; + t let to_string {name; _} = name diff --git a/compiler/src/lib/tiger/tiger_symbol.mli b/compiler/src/lib/tiger/tiger_symbol.mli index 1dd5acc..8b3f8ec 100644 --- a/compiler/src/lib/tiger/tiger_symbol.mli +++ b/compiler/src/lib/tiger/tiger_symbol.mli @@ -1,6 +1,6 @@ type t -val new_of_string : string -> t +val unique_of_string : string -> t val of_string : string -> t -- 2.20.1