]>
Commit | Line | Data |
---|---|---|
1 | (* L3 Compiler | |
2 | * Labeloraries | |
3 | * Like temporaries, except more different | |
4 | * Author: Joshua Wise <jwise@cs.cmu.edu> | |
5 | *) | |
6 | ||
7 | signature LABEL = | |
8 | sig | |
9 | type label | |
10 | ||
11 | val reset : unit -> unit (* resets label numbering *) | |
12 | val new : unit -> label (* returns a unique new label *) | |
13 | val name : label -> string (* returns the name of a label *) | |
14 | val compare : label * label -> order (* comparison function *) | |
15 | end | |
16 | ||
17 | structure Label :> LABEL = | |
18 | struct | |
19 | type label = int | |
20 | ||
21 | local | |
22 | val counter = ref 1 | |
23 | in | |
24 | (* warning: calling reset() may jeopardize uniqueness of labels! *) | |
25 | fun reset () = ( counter := 1 ) | |
26 | fun new () = !counter before ( counter := !counter + 1 ) | |
27 | end | |
28 | ||
29 | fun name t = ".L" ^ Int.toString t | |
30 | ||
31 | fun compare (t1,t2) = Int.compare (t1,t2) | |
32 | end |