]> Joshua Wise's Git repositories - snipe.git/blame - trans/stringref.sml
Emit strings at the end.
[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 *)
469e60eb 15 val all : unit -> (stringref * string) list
a83f1d60
JW
16end
17
18structure Stringref :> STRINGREF =
19struct
20 type stringref = int
21
22 local
23 val counter = ref 1
24 val strings = ref []
25 in
26 (* warning: calling reset() may jeopardize uniqueness of stringrefs! *)
27 fun reset () = ( counter := 1 ; strings := [] )
28 fun new (s : string) = !counter before ( strings := (!counter, s) :: !strings ; counter := !counter + 1 )
469e60eb 29 fun all () = !strings
a83f1d60
JW
30 end
31
32 fun name t = "S" ^ Int.toString t
33
34 fun compare (t1,t2) = Int.compare (t1,t2)
35end
This page took 0.026479 seconds and 4 git commands to generate.