]> Joshua Wise's Git repositories - snipe.git/blob - trans/stringref.sml
Add strings to the IR
[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 end
16
17 structure Stringref :> STRINGREF = 
18 struct
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)
33 end
This page took 0.024813 seconds and 4 git commands to generate.