home
/
code
/
tiger.ml.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix Symbol.new_of_string - it should not save
[tiger.ml.git]
/
compiler
/
src
/
lib
/
tiger
/
tiger_symbol.ml
diff --git
a/compiler/src/lib/tiger/tiger_symbol.ml
b/compiler/src/lib/tiger/tiger_symbol.ml
index
f1dc51a
..
747cb03
100644
(file)
--- a/
compiler/src/lib/tiger/tiger_symbol.ml
+++ b/
compiler/src/lib/tiger/tiger_symbol.ml
@@
-5,22
+5,29
@@
type t =
; symbol : int
}
; symbol : int
}
-let
nextsym
= ref 0
+let
counter
= ref 0
let symbols = H.create 16
let symbols = H.create 16
+let unique_of_string name =
+ incr counter;
+ let symbol = !counter in
+ {name; symbol}
+
let of_string name =
match H.find_opt symbols name with
| Some symbol ->
{name; symbol}
| None ->
let of_string name =
match H.find_opt symbols name with
| Some symbol ->
{name; symbol}
| None ->
- incr nextsym;
- let symbol = !nextsym in
- H.replace symbols ~key:name ~data:symbol;
- {name; symbol}
+ let t = unique_of_string name in
+ H.replace symbols ~key:t.name ~data:t.symbol;
+ t
let to_string {name; _} =
name
let is_equal {symbol=s1; _} {symbol=s2; _} =
s1 = s2
let to_string {name; _} =
name
let is_equal {symbol=s1; _} {symbol=s2; _} =
s1 = s2
+
+let show {name; symbol} =
+ Printf.sprintf "Symbol[%S, %d]" name symbol
This page took
0.033646 seconds
and
4
git commands to generate.