X-Git-Url: https://git.xandkar.net/?p=tiger.ml.git;a=blobdiff_plain;f=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_temp.ml;fp=compiler%2Fsrc%2Flib%2Ftiger%2Ftiger_temp.ml;h=439b0c00cb9f3b41ea49e34c0e6902d7096b2ecd;hp=0000000000000000000000000000000000000000;hb=cc540a7e2dfcee4411953075210a64de874b91e5;hpb=21d0f0503ea169988685a4f39d0e32b2b097dae6 diff --git a/compiler/src/lib/tiger/tiger_temp.ml b/compiler/src/lib/tiger/tiger_temp.ml new file mode 100644 index 0000000..439b0c0 --- /dev/null +++ b/compiler/src/lib/tiger/tiger_temp.ml @@ -0,0 +1,47 @@ +open Printf + +module Sym = Tiger_symbol + +module Counter : sig + type t + + val create : unit -> t + + val next : t -> int +end = struct + type t = int ref + + let create () = + ref 0 + + let next t = + incr t; + !t +end + +module Temp = struct + type t = int + + let t = Counter.create () + + let gen () = + Counter.next t + + let to_string t = + sprintf "t%d" t +end + +module Label = struct + type t = Sym.t + + let counter = Counter.create () + + let of_string = + Sym.of_string + + let gen () = + of_string (sprintf "L%d" (Counter.next counter)) + + let to_string = + Sym.to_string +end