+(* L3 Compiler
+ * Stringreforaries
+ * Like temporaries, except more different
+ * Author: Joshua Wise <jwise@cs.cmu.edu>
+ *)
+
+signature STRINGREF =
+sig
+ type stringref
+
+ val reset : unit -> unit (* resets stringref numbering *)
+ val new : string -> stringref (* returns a unique new stringref *)
+ val name : stringref -> string (* returns the name of a stringref *)
+ val compare : stringref * stringref -> order (* comparison function *)
+end
+
+structure Stringref :> STRINGREF =
+struct
+ type stringref = int
+
+ local
+ val counter = ref 1
+ val strings = ref []
+ in
+ (* warning: calling reset() may jeopardize uniqueness of stringrefs! *)
+ fun reset () = ( counter := 1 ; strings := [] )
+ fun new (s : string) = !counter before ( strings := (!counter, s) :: !strings ; counter := !counter + 1 )
+ end
+
+ fun name t = "S" ^ Int.toString t
+
+ fun compare (t1,t2) = Int.compare (t1,t2)
+end