]> Joshua Wise's Git repositories - snipe.git/blame - trans/stringref.sml
Add strings to the IR
[snipe.git] / trans / stringref.sml
CommitLineData
a83f1d60
JW
1(* L3 Compiler
2 * Stringreforaries
3 * Like temporaries, except more different
4 * Author: Joshua Wise <jwise@cs.cmu.edu>
5 *)
6
7signature STRINGREF =
8sig
9 type stringref
10
11 val reset : unit -> unit (* resets stringref numbering *)
12 val new : string -> stringref (* returns a unique new stringref *)
13 val name : stringref -> string (* returns the name of a stringref *)
14 val compare : stringref * stringref -> order (* comparison function *)
15end
16
17structure Stringref :> STRINGREF =
18struct
19 type stringref = int
20
21 local
22 val counter = ref 1
23 val strings = ref []
24 in
25 (* warning: calling reset() may jeopardize uniqueness of stringrefs! *)
26 fun reset () = ( counter := 1 ; strings := [] )
27 fun new (s : string) = !counter before ( strings := (!counter, s) :: !strings ; counter := !counter + 1 )
28 end
29
30 fun name t = "S" ^ Int.toString t
31
32 fun compare (t1,t2) = Int.compare (t1,t2)
33end
This page took 0.024834 seconds and 4 git commands to generate.