]> Joshua Wise's Git repositories - snipe.git/blob - trans/stringref.sml
Emit strings at the end.
[snipe.git] / trans / stringref.sml
1 (* L3 Compiler
2  * Stringreforaries
3  * Like temporaries, except more different
4  * Author: Joshua Wise <jwise@cs.cmu.edu>
5  *)
6
7 signature STRINGREF = 
8 sig
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 *)
15   val all : unit -> (stringref * string) list
16 end
17
18 structure Stringref :> STRINGREF = 
19 struct
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 )
29     fun all () = !strings
30   end
31
32   fun name t = "S" ^ Int.toString t
33                       
34   fun compare (t1,t2) = Int.compare (t1,t2)
35 end
This page took 0.01823 seconds and 4 git commands to generate.