]> Joshua Wise's Git repositories - snipe.git/blobdiff - trans/label.sml
Initial import of l2c
[snipe.git] / trans / label.sml
diff --git a/trans/label.sml b/trans/label.sml
new file mode 100644 (file)
index 0000000..76041f4
--- /dev/null
@@ -0,0 +1,32 @@
+(* L2 Compiler
+ * Labeloraries
+ * Like temporaries, except more different
+ * Author: Joshua Wise <jwise@cs.cmu.edu>
+ *)
+
+signature LABEL = 
+sig
+  type label
+
+  val reset : unit -> unit     (* resets label numbering *)
+  val new : unit -> label      (* returns a unique new label *)
+  val name : label -> string   (* returns the name of a label *)
+  val compare : label * label -> order (* comparison function *)
+end
+
+structure Label :> LABEL = 
+struct
+  type label = int
+
+  local
+    val counter = ref 1
+  in
+    (* warning: calling reset() may jeopardize uniqueness of labels! *)
+    fun reset () = ( counter := 1 )
+    fun new () = !counter before ( counter := !counter + 1 )
+  end
+
+  fun name t = ".L" ^ Int.toString t
+                     
+  fun compare (t1,t2) = Int.compare (t1,t2)
+end
This page took 0.023803 seconds and 4 git commands to generate.