modern-compiler-ml/tiger/chap7/temp.sml
jmug 33d8bac511 Add the tiger source code bundle from the book site
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2024-12-18 15:18:45 -08:00

24 lines
555 B
Standard ML

(* make this an abstraction sometime *)
structure Temp : TEMP =
struct
type temp = int
val temps = ref 100
fun newtemp() = let val t = !temps in temps := t+1; t end
structure Table = IntMapTable(type key = int
fun getInt n = n)
fun makestring t = "t" ^ Int.toString t
type label = Symbol.symbol
local structure F = Format
fun postinc x = let val i = !x in x := i+1; i end
val labs = ref 0
in
fun newlabel() = Symbol.symbol(F.format "L%d" [F.INT(postinc labs)])
val namedlabel = Symbol.symbol
end
end