Skip to content

Commit 021490b

Browse files
committed
Got a little more of the code gen framework written.
1 parent 82ec9a5 commit 021490b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

benchmark/src/main/scala/bench/CodeGen.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import scala.util.control.NonFatal
55

66
object Generator {
77
val names = "arr ish lst ils que stm trs vec arb ars ast mhs lhs prq muq wra jix jln".split(' ')
8+
89
def writeTo(f: java.io.File)(pr: (String => Unit) => Unit): Either[Throwable, Unit] = {
910
try {
1011
val pw = new java.io.PrintWriter(f)
@@ -15,10 +16,21 @@ object Generator {
1516
}
1617
catch { case NonFatal(t) => Left(t) }
1718
}
19+
20+
def sayArrayI(oa: Option[Array[Int]]) = oa match { case Some(a) => a.mkString("Array(", ",", ")"); case _ => "" }
21+
1822
def agreement(target: java.io.File, sizes: Option[Array[Int]] = None) {
1923
if (target.exists) throw new java.io.IOException("Generator will not write to existing file: " + target.getPath)
2024
writeTo(target){ pr =>
21-
Seq("test").foreach(pr)
25+
pr("""package bench.test""")
26+
pr("""""")
27+
pr("""object Agreement {""")
28+
pr(""" def run() {""")
29+
pr(""" val wrong = new collection.mutable.ArrayBuffer[String]""")
30+
pr(""" def check[A](a1: A, a2: A, msg: String) = if (a1 != a2) wrong += msg""")
31+
pr( s" val x = new bench.generate.Things(${sayArrayI(sizes)})" )
32+
pr(""" }""")
33+
pr("""}""")
2234
} match {
2335
case Left(t) => println("Did not successfully write file: " + target.getPath); throw t
2436
case _ =>

0 commit comments

Comments
 (0)