Import Upstream version 20180207
[hcoop/debian/mlton.git] / mlton / atoms / symbol.fun
CommitLineData
7f918cf1
CE
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
8functor Symbol (S: SYMBOL_STRUCTS): SYMBOL =
9struct
10
11open S
12
13datatype t = T of {hash: word,
14 name: string,
15 plist: PropertyList.t}
16
17local
18 fun make f (T r) = f r
19in
20 val hash = make #hash
21 val plist = make #plist
22 val name = make #name
23end
24
25val table: t HashSet.t = HashSet.new {hash = hash}
26
27fun 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
38fun foreach f = HashSet.foreach (table, f)
39
40val toString = name
41
42val layout = Layout.str o toString
43
44fun equals (s, s') = PropertyList.equals (plist s, plist s')
45
46local
47 fun make f (s, s') = f (name s, name s')
48in
49 val op <= = make String.<=
50 val compare = make String.compare
51end
52
53val asterisk = fromString "*"
54val bogus = fromString "<bogus>"
55val equal = fromString "="
56val itt = fromString "it"
57val unit = fromString "unit"
58
59end