--- a/progs/while/compile.sc Fri Oct 13 23:49:34 2023 +0100
+++ b/progs/while/compile.sc Sat Oct 21 09:09:09 2023 +0100
@@ -1,11 +1,14 @@
// A Small Compiler for the WHILE Language
// (it does not use a parser nor lexer)
//
-// cal with
+// call with
//
// amm compile.sc test
// amm compile.sc test2
-
+//
+// test2 includes a run of the JVM instructions. This
+// requires that jasmin.jar is present in the same
+// directory.
// the abstract syntax trees
abstract class Stmt
@@ -33,7 +36,7 @@
// compiler headers needed for the JVM
-// (contains methods for read and write)
+// (contains a method for write)
val beginning = """
.class public XXX.XXX
.super java/lang/Object
@@ -75,10 +78,8 @@
// convenient string interpolations
// for instructions and labels
-import scala.language.implicitConversions
-import scala.language.reflectiveCalls
-implicit def sring_inters(sc: StringContext) = new {
+extension (sc: StringContext) {
def i(args: Any*): String = " " ++ sc.s(args:_*) ++ "\n"
def l(args: Any*): String = sc.s(args:_*) ++ ":\n"
}
@@ -150,11 +151,6 @@
case Write(x) =>
(i"iload ${env(x)} \t\t; $x" ++
i"invokestatic XXX/XXX/write(I)V", env)
- //case Read(x) => {
- // val index = env.getOrElse(x, env.keys.size)
- // (i"invokestatic XXX/XXX/read()I" ++
- // i"istore $index \t\t; $x", env + (x -> index))
- //}
}
// compilation of a block (i.e. list of instructions)
@@ -200,8 +196,6 @@
-
-
// compiling and running .j-files
//
// JVM files can be assembled with
@@ -218,6 +212,7 @@
os.write.over(os.pwd / s"$class_name.j", code)
os.proc("java", "-jar", "jasmin.jar", s"$class_name.j").call()
os.proc("java", s"$class_name/$class_name").call(stdout = os.Inherit, stdin = os.Inherit)
+ ()
}
@@ -266,6 +261,3 @@
-
-
-// runs with amm2 and amm3