X-Git-Url: http://git.joshuawise.com/snipe.git/blobdiff_plain/2ab9671fde5297fc59583361f152e812e66c2d17..a83f1d602c6f50eb9ab0448a20f0ecb80fefcead:/trans/stringref.sml diff --git a/trans/stringref.sml b/trans/stringref.sml new file mode 100644 index 0000000..f78bd95 --- /dev/null +++ b/trans/stringref.sml @@ -0,0 +1,33 @@ +(* L3 Compiler + * Stringreforaries + * Like temporaries, except more different + * Author: Joshua Wise + *) + +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