updated
authorChristian Urban <urbanc@in.tum.de>
Fri, 07 Feb 2020 12:44:27 +0000
changeset 713 0ea14d84efe3
parent 712 e71eb9ce2373
child 714 8a50ccea59e8
updated
handouts/ho07.pdf
handouts/ho07.tex
progs/compile_arr3.scala
Binary file handouts/ho07.pdf has changed
--- a/handouts/ho07.tex	Fri Feb 07 11:32:47 2020 +0000
+++ b/handouts/ho07.tex	Fri Feb 07 12:44:27 2020 +0000
@@ -1074,7 +1074,7 @@
 L2:
 \end{lstlisting}
 
-
+goto\_w problem solved for too large jumps
 \end{document}
 
 %%% Local Variables: 
--- a/progs/compile_arr3.scala	Fri Feb 07 11:32:47 2020 +0000
+++ b/progs/compile_arr3.scala	Fri Feb 07 12:44:27 2020 +0000
@@ -6,14 +6,19 @@
 //  - transpiles BF programs into WHILE programs
 //    and compiles and runs them
 //
+//  - makes array access safe by explicit bound checks
+//    and perform defaults when bounds are exceeded
+//
+//  - uses goto_w for jumps in while-loops
+//
 // Call with
 //
-// scala compile_arr.scala
+// scala compile_arr3.scala
 
 // Mandelbrot
-// mand.j size       232266
-// mand.class size   21787
-// running time      16 secs
+// mand.j size       605196
+// mand.class size   56812
+// running time      26 secs
 
 // the abstract syntax trees
 abstract class Stmt
@@ -179,11 +184,17 @@
   case While(b, bl) => {
     val loop_begin = Fresh("Loop_begin")
     val loop_end = Fresh("Loop_end")
+    val loop_false = Fresh("Loop_false")
+    val loop_true = Fresh("Loop_true")
     val (instrs1, env1) = compile_block(bl, env)
     (l"$loop_begin" ++
-     compile_bexp(b, env, loop_end) ++
+     compile_bexp(b, env, loop_false) ++
+     i"goto $loop_true" ++
+     l"$loop_false" ++
+     i"goto_w $loop_end" ++ 
+     l"$loop_true" ++
      instrs1 ++
-     i"goto $loop_begin" ++
+     i"goto_w $loop_begin" ++
      l"$loop_end", env1)
   }
   case Write(x) => 
@@ -212,7 +223,7 @@
      i"arraylength" ++
      i"if_icmple $arr_safe" ++
      i"pop2" ++
-     i"goto $arr_end" ++
+     i"goto_w $arr_end" ++
      l"$arr_safe" ++
      i"swap" ++
      compile_aexp(a2, env) ++