]>
Commit | Line | Data |
---|---|---|
6ade8b0a | 1 | (* L3 Compiler |
12aa4087 JW |
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 | ||
5c79bb68 | 12 | val reset : unit -> unit (* resets temp numbering *) |
6c5506c5 | 13 | val new : string -> temp (* returns a unique new temp *) |
5c79bb68 | 14 | val name : temp -> string (* returns the name of a temp *) |
12aa4087 | 15 | val compare : temp * temp -> order (* comparison function *) |
6ade8b0a | 16 | val eq : temp * temp -> bool |
12aa4087 JW |
17 | end |
18 | ||
19 | structure Temp :> TEMP = | |
20 | struct | |
6c5506c5 | 21 | type temp = int * string |
12aa4087 JW |
22 | |
23 | local | |
24 | val counter = ref 1 | |
25 | in | |
26 | (* warning: calling reset() may jeopardize uniqueness of temps! *) | |
27 | fun reset () = ( counter := 1 ) | |
6c5506c5 | 28 | fun new str = (!counter, str) before ( counter := !counter + 1 ) |
12aa4087 JW |
29 | end |
30 | ||
6c5506c5 JW |
31 | fun name (t,s) = "+t" ^ Int.toString t ^ "[" ^ s ^ "]" |
32 | fun compare ((t1,_),(t2,_)) = Int.compare (t1,t2) | |
5c79bb68 | 33 | |
6c5506c5 | 34 | fun eq ((t1,_), (t2,_)) = t1 = t2 |
12aa4087 | 35 | end |