]> Joshua Wise's Git repositories - snipe.git/blobdiff - trans/stringref.sml
Add strings to the IR
[snipe.git] / trans / stringref.sml
diff --git a/trans/stringref.sml b/trans/stringref.sml
new file mode 100644 (file)
index 0000000..f78bd95
--- /dev/null
@@ -0,0 +1,33 @@
+(* L3 Compiler
+ * Stringreforaries
+ * Like temporaries, except more different
+ * Author: Joshua Wise <jwise@cs.cmu.edu>
+ *)
+
+signature STRINGREF = 
+sig
+  type stringref
+
+  val reset : unit -> unit     (* resets stringref numbering *)
+  val new : string -> stringref        (* returns a unique new stringref *)
+  val name : stringref -> string       (* returns the name of a stringref *)
+  val compare : stringref * stringref -> order (* comparison function *)
+end
+
+structure Stringref :> STRINGREF = 
+struct
+  type stringref = int
+
+  local
+    val counter = ref 1
+    val strings = ref []
+  in
+    (* warning: calling reset() may jeopardize uniqueness of stringrefs! *)
+    fun reset () = ( counter := 1 ; strings := [] )
+    fun new (s : string) = !counter before ( strings := (!counter, s) :: !strings ; counter := !counter + 1 )
+  end
+
+  fun name t = "S" ^ Int.toString t
+                     
+  fun compare (t1,t2) = Int.compare (t1,t2)
+end
This page took 0.0217619999999999 seconds and 4 git commands to generate.