# HG changeset patch # User Christian Urban # Date 1581079467 0 # Node ID 0ea14d84efe383ecae1a48d297b19b05bdbf3720 # Parent e71eb9ce2373ceb49bac7e6d9797f07928b77cd8 updated diff -r e71eb9ce2373 -r 0ea14d84efe3 handouts/ho07.pdf Binary file handouts/ho07.pdf has changed diff -r e71eb9ce2373 -r 0ea14d84efe3 handouts/ho07.tex --- 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: diff -r e71eb9ce2373 -r 0ea14d84efe3 progs/compile_arr3.scala --- 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) ++