diff -r c82a45f48bfc -r 5365ef60707e progs/while-arrays/compile_arrays2.sc --- a/progs/while-arrays/compile_arrays2.sc Fri Oct 13 23:49:34 2023 +0100 +++ b/progs/while-arrays/compile_arrays2.sc Sat Oct 21 09:09:09 2023 +0100 @@ -1,5 +1,8 @@ // A Small Compiler for the WHILE Language // +// - there are some small peep-hole optimisations +// implemented +// // - this compiler contains support for "static" integer // arrays (they are mutable but cannot be re-sized) // @@ -88,11 +91,12 @@ // convenient string interpolations // for generating instructions and labels -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" } + def compile_num(i: Int) = if (0 <= i && i <= 5) i"iconst_$i" else if (-128 <= i && i <= 127) i"bipush $i" else i"ldc $i" @@ -262,5 +266,3 @@ - -// runs with amm2 and amm3