Debian Codegraph @

lib/mlrisc-lib/MLRISC/Tools/SourceMap/symbol.sml

raw
1 structure UniqueSymbol :> UNIQUE_SYMBOL =
2 struct
3
4 structure H = HashTable
5
6 datatype symbol = SYMBOL of string ref * word
7
8 fun equal(SYMBOL(a,_),SYMBOL(b,_)) = a = b
9 fun compare(SYMBOL(a,_),SYMBOL(b,_)) = String.compare(!a,!b)
10 fun hash(SYMBOL(_,w)) = w
11 fun toString(SYMBOL(s,_)) = !s
12
13 exception NotThere
14
15 fun hashIt(SYMBOL(ref s,_)) = HashString.hashString s
16 fun eq(SYMBOL(ref x,a),SYMBOL(ref y,b)) = a = b andalso x = y
17
18 val table = H.mkTable (hashIt,eq) (117,NotThere)
19 : (symbol,symbol) H.hash_table
20
21 val lookup = H.lookup table
22 val insert = H.insert table
23
24 fun fromString name =
25 let val s = SYMBOL(ref name,HashString.hashString name)
26 in lookup s handle _ => (insert(s,s); s) end
27 end