Import Upstream version 20180207
[hcoop/debian/mlton.git] / mlton / atoms / symbol.fun
1 (* Copyright (C) 2004-2006 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 *)
7
8 functor Symbol (S: SYMBOL_STRUCTS): SYMBOL =
9 struct
10
11 open S
12
13 datatype t = T of {hash: word,
14 name: string,
15 plist: PropertyList.t}
16
17 local
18 fun make f (T r) = f r
19 in
20 val hash = make #hash
21 val plist = make #plist
22 val name = make #name
23 end
24
25 val table: t HashSet.t = HashSet.new {hash = hash}
26
27 fun fromString s =
28 let
29 val hash = String.hash s
30 in
31 HashSet.lookupOrInsert
32 (table, hash, fn T {name, ...} => s = name,
33 fn () => T {hash = hash,
34 name = s,
35 plist = PropertyList.new ()})
36 end
37
38 fun foreach f = HashSet.foreach (table, f)
39
40 val toString = name
41
42 val layout = Layout.str o toString
43
44 fun equals (s, s') = PropertyList.equals (plist s, plist s')
45
46 local
47 fun make f (s, s') = f (name s, name s')
48 in
49 val op <= = make String.<=
50 val compare = make String.compare
51 end
52
53 val asterisk = fromString "*"
54 val bogus = fromString "<bogus>"
55 val equal = fromString "="
56 val itt = fromString "it"
57 val unit = fromString "unit"
58
59 end