]> Joshua Wise's Git repositories - snipe.git/blob - trans/temp.sml
3f6c806232a4ef5eb094d4e9438fcace997a656e
[snipe.git] / trans / temp.sml
1 (* L1 Compiler
2  * Temporaries
3  * Author: Kaustuv Chaudhuri <kaustuv+@cs.cmu.edu>
4  * Modified: Alex Vaynberg <alv@andrew.cmu.edu>
5  * Modified: Frank Pfenning <fp@cs.cmu.edu>
6  *)
7
8 signature TEMP = 
9 sig
10   type temp
11
12   val reset : unit -> unit      (* resets temp numbering *)
13   val new : unit -> temp        (* returns a unique new temp *)
14   val name : temp -> string     (* returns the name of a temp *)
15   val compare : temp * temp -> order (* comparison function *)
16 end
17
18 structure Temp :> TEMP = 
19 struct
20   type temp = int
21
22   local
23     val counter = ref 1
24   in
25     (* warning: calling reset() may jeopardize uniqueness of temps! *)
26     fun reset () = ( counter := 1 )
27     fun new () = !counter before ( counter := !counter + 1 )
28   end
29
30   fun name t = "+t" ^ Int.toString t
31                       
32   fun compare (t1,t2) = Int.compare (t1,t2)
33 end
This page took 0.016826 seconds and 2 git commands to generate.