--- a/progs/compile.scala Fri Oct 25 14:55:31 2019 +0100
+++ b/progs/compile.scala Fri Oct 25 17:23:23 2019 +0100
@@ -120,7 +120,7 @@
// environments
-type Env = Map[String, String]
+type Env = Map[String, Int]
// arithmetic expression compilation
def compile_aexp(a: AExp, env : Env) : String = a match {
@@ -150,8 +150,7 @@
def compile_stmt(s: Stmt, env: Env) : (String, Env) = s match {
case Skip => ("", env)
case Assign(x, a) => {
- val index = if (env.isDefinedAt(x)) env(x) else
- env.keys.size.toString
+ val index = if (env.isDefinedAt(x)) env(x) else env.keys.size
(compile_aexp(a, env) ++ i"istore $index", env + (x -> index))
}
case If(b, bl1, bl2) => {
@@ -180,8 +179,7 @@
(i"iload ${env(x)}" ++
i"invokestatic XXX/XXX/write(I)V", env)
case Read(x) => {
- val index = if (env.isDefinedAt(x)) env(x) else
- env.keys.size.toString
+ val index = if (env.isDefinedAt(x)) env(x) else env.keys.size
(i"invokestatic XXX/XXX/read()I" ++
i"istore $index", env + (x -> index))
}