--- a/progs/compile.scala Mon Nov 14 15:50:42 2016 +0000
+++ b/progs/compile.scala Sat Jan 07 14:52:26 2017 +0000
@@ -1,5 +1,5 @@
// A Small Compiler for the WHILE Language
-//
+// (it does not use a parser and lexer)
// the abstract syntax trees
abstract class Stmt
@@ -94,6 +94,9 @@
.end method
"""
+println("starting")
+
+
// for generating new labels
var counter = -1
@@ -221,7 +224,25 @@
//
// java fib/fib
+import scala.util._
+import scala.sys.process._
+import scala.io
+
+def compile_tofile(bl: Block, class_name: String) = {
+ val output = compile(bl, class_name)
+ val fw = new java.io.FileWriter(class_name + ".j")
+ fw.write(output)
+ fw.close()
+}
+
+def compile_and_run(bl: Block, class_name: String) : Unit = {
+ compile_tofile(bl, class_name)
+ println("compiled ")
+ val test = ("java -jar jvm/jasmin-2.4/jasmin.jar " + class_name + ".j").!!
+ println("assembled ")
+ ("java " + class_name + "/" + class_name).!!
+}
+compile_and_run(fib_test, "fib")
-