-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlabel.sml
66 lines (46 loc) · 1.46 KB
/
label.sml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
(* label.sml
*
* Representing assembly labels in the MLPolyR compiler.
*
* Copyright (c) 2005 by Matthias Blume ([email protected])
*)
structure Label :> sig
structure Atom : ATOM
type label = Atom.atom
structure Set : ORD_SET where type Key.ord_key = label
structure Map : ORD_MAP where type Key.ord_key = label
val new : LVar.lvar option -> label
val external : string -> label
val stringlabel : unit -> label
val reset : unit -> unit
val isExternal : label -> bool
val name : label -> string
val escname : label -> string
val compare : label * label -> order
end = struct
structure Atom = Atom
structure Set = AtomRedBlackSet
structure Map = AtomRedBlackMap
type label = Atom.atom
val next = ref 0
val externals = ref Set.empty
fun reset () = next := 0
fun freshid () = let val n = !next in next := n+1; n end
fun new NONE = Atom.atom ("l_" ^ Int.toString (freshid ()))
| new (SOME v) = Atom.atom ("l_" ^ Int.toString (freshid ())
^ "_" ^ LVar.baseName v)
fun stringlabel () =
Atom.atom ("l_mlpr_string_" ^ Int.toString (freshid ()))
fun external s =
let val l = Atom.atom ("_" ^ s)
in externals := Set.add (!externals, l);
l
end
fun isExternal l = Set.member (!externals, l)
val name = Atom.toString
fun escname l =
let val n = name l
in if Char.contains n #"'" then concat ["\"", n, "\""] else n
end
val compare = Atom.compare
end