|         |      1 // Some more interesting testcases for the  | 
|         |      2 // WHILE compiler with arrays, it includes:  | 
|         |      3 // | 
|         |      4 //  - a small parser for WHILE programs | 
|         |      5 // | 
|         |      6 //  - transpiles BF programs into WHILE programs | 
|         |      7 //    and then compiles and runs them | 
|         |      8 // | 
|         |      9 //  - the power-example is the Mandelbrot set: | 
|         |     10 //        | 
|         |     11 //       * 65k for the transpiled WHILE program  | 
|         |     12 //       * parsing uses around 30 secs using fastparse | 
|         |     13 //       * the jasmin assembly file is 236k | 
|         |     14 //       * the resulting Java program takes about 20 secs  | 
|         |     15 // | 
|         |     16 // Call with (X being 0,1,..,4) | 
|         |     17 // | 
|         |     18 //  amm compile_bfc.sc all | 
|         |     19 //  amm compile_bfc.sc bfcX | 
|         |     20  | 
|         |     21  | 
|         |     22 // load the compiler | 
|         |     23 import $file.compile_arrays | 
|         |     24 import compile_arrays._  | 
|         |     25  | 
|         |     26 def time_needed[T](i: Int, code: => T) = { | 
|         |     27   val start = System.nanoTime() | 
|         |     28   for (j <- 2 to i) code | 
|         |     29   val result = code | 
|         |     30   val end = System.nanoTime() | 
|         |     31   ((end - start) / (i * 1.0e9), result) | 
|         |     32 } | 
|         |     33  | 
|         |     34 // for BF we have to change the write library-function, | 
|         |     35 // because in BF integers are written out as characters | 
|         |     36 val beginning = """ | 
|         |     37 .class public XXX.XXX | 
|         |     38 .super java/lang/Object | 
|         |     39  | 
|         |     40 .method public static write(I)V  | 
|         |     41     .limit locals 1  | 
|         |     42     .limit stack 2  | 
|         |     43     getstatic java/lang/System/out Ljava/io/PrintStream;  | 
|         |     44     iload 0 | 
|         |     45     i2c                                           ; Int => Char | 
|         |     46     invokevirtual java/io/PrintStream/print(C)V   ; println(I)V => print(C)V     | 
|         |     47     return  | 
|         |     48 .end method | 
|         |     49  | 
|         |     50 .method public static main([Ljava/lang/String;)V | 
|         |     51    .limit locals 200 | 
|         |     52    .limit stack 200 | 
|         |     53  | 
|         |     54 ; COMPILED CODE STARTS    | 
|         |     55  | 
|         |     56 """ | 
|         |     57  | 
|         |     58  | 
|         |     59 // modified main compilation function for blocks | 
|         |     60 def compile(bl: Block, class_name: String) : String = { | 
|         |     61   val instructions = compile_block(bl, Map())._1 | 
|         |     62   (beginning ++ instructions ++ ending).replace("XXX", class_name) | 
|         |     63 } | 
|         |     64  | 
|         |     65 // automating the above | 
|         |     66 import ammonite.ops._ | 
|         |     67  | 
|         |     68 def compile_to_file(bl: Block, class_name: String) : Unit =  | 
|         |     69   write.over(pwd / s"$class_name.j", compile(bl, class_name))   | 
|         |     70  | 
|         |     71 def compile_and_run(bl: Block, class_name: String) : Unit = { | 
|         |     72   println(s"Start of compilation") | 
|         |     73   compile_to_file(bl, class_name) | 
|         |     74   println(s"generated $class_name.j file") | 
|         |     75   val (jasmin_time, _) =  | 
|         |     76     time_needed(1, os.proc("java", "-jar", "jasmin.jar", s"$class_name.j").call()) | 
|         |     77   println(s"generated $class_name.class file (in $jasmin_time secs).") | 
|         |     78   val (running_time, output) =  | 
|         |     79     time_needed(1, os.proc("java", s"${class_name}/${class_name}").call().out.text()) | 
|         |     80   println(output) | 
|         |     81   println(s"done (in $running_time secs).") | 
|         |     82 } | 
|         |     83  | 
|         |     84  | 
|         |     85 //===================================== | 
|         |     86 // Grammar Rules for WHILE with arrays | 
|         |     87 //===================================== | 
|         |     88  | 
|         |     89 import fastparse._ | 
|         |     90 import MultiLineWhitespace._ | 
|         |     91  | 
|         |     92 def lowercase [_ : P] = P( CharIn("a-z") ) | 
|         |     93 def uppercase[_ : P]  = P( CharIn("A-Z") ) | 
|         |     94 def letter[_ : P]     = P( lowercase | uppercase ) | 
|         |     95 def digit [_ : P]     = P( CharIn("0-9") ) | 
|         |     96  | 
|         |     97 def Number[_ : P]: P[Int] =  P( digit.rep(1) ).!.map(_.toInt) | 
|         |     98 def Ident[_ : P]: P[String] = P( letter ~ (letter | digit | "_").rep ).! | 
|         |     99  | 
|         |    100 // arithmetic expressions | 
|         |    101 def AExp[_ : P]: P[AExp] =  | 
|         |    102   P(  P(Te ~ "+" ~ AExp).map{ case (l, r) => Aop("+", l, r)}  | 
|         |    103     | P(Te ~ "-" ~ AExp).map{ case (l, r) => Aop("-", l, r)} | 
|         |    104     | Te ) | 
|         |    105 def Te[_ : P]: P[AExp] =  | 
|         |    106   P(  P(Fa ~ "*" ~ Te).map{ case (l, r) => Aop("*", l, r)}  | 
|         |    107     | Fa )    | 
|         |    108 def Fa[_ : P]: P[AExp] =  | 
|         |    109   P( "(" ~ AExp ~ ")"  | 
|         |    110      | P (Ident ~ "[" ~ AExp ~ "]").map{Ref.tupled} | 
|         |    111      | P(Number).map{Num}  | 
|         |    112      | P(Ident).map{Var} ) | 
|         |    113  | 
|         |    114 // boolean expressions | 
|         |    115 def BExp[_ : P]: P[BExp] =  | 
|         |    116   P(  P(AExp ~ "=" ~ AExp).map{ case (x, z) => Bop("=", x, z)}  | 
|         |    117     | P(AExp ~ "!=" ~ AExp).map{ case (x, z) => Bop("!=", x, z)}   | 
|         |    118     | P(AExp ~ "<" ~ AExp).map{ case (x, z) => Bop("<", x, z)}   | 
|         |    119     | P(AExp ~ ">" ~ AExp).map{ case (x, z) => Bop("<", z, x)}   | 
|         |    120     | P("true").map{ _ => True}  | 
|         |    121     | P("false").map{ _ => False}  | 
|         |    122     | "(" ~ BExp ~ ")" ) | 
|         |    123  | 
|         |    124 // statements and blocks | 
|         |    125 def Stmt[_ : P]: P[Stmt] = | 
|         |    126   P(  P("skip").map( _ => Skip)  | 
|         |    127     | P(Ident ~ ":=" ~ AExp).map{Assign.tupled}  | 
|         |    128     | P(Ident ~ "[" ~ AExp ~ "]" ~ ":=" ~ AExp).map{AssignA.tupled}  | 
|         |    129     | P("if" ~ BExp ~ "then" ~ Block ~ "else" ~ Block).map{If.tupled}  | 
|         |    130     | P("while" ~ BExp ~ "do" ~ Block).map{While.tupled}  | 
|         |    131     | P("new(" ~ Ident ~ "[" ~ Number ~ "])").map{ArrayDef.tupled}  | 
|         |    132     | P("write(" ~ Ident ~ ")").map{Write} )  | 
|         |    133  | 
|         |    134 def Stmts[_ : P]: P[Block] = | 
|         |    135   P(  P(Stmt ~ ";" ~ Stmts).map{ case (x, z) => x :: z }  | 
|         |    136     | P(Stmt).map{s => List(s)} )  | 
|         |    137  | 
|         |    138 def Block[_ : P]: P[Block] = | 
|         |    139   P(  "{" ~ Stmts ~ "}"  | 
|         |    140     | P(Stmt).map(s => List(s)) ) | 
|         |    141  | 
|         |    142 // some test cases for the parser | 
|         |    143  | 
|         |    144 //println(fastparse.parse("(1 + (2 + 5)) + 4", AExp(_)).get) | 
|         |    145 //println(fastparse.parse("1 + 2 + 3 + 45", AExp(_))) | 
|         |    146 //println(fastparse.parse("1 + 2 * 3", AExp(_))) | 
|         |    147 //println(fastparse.parse("x + 2 * 3", AExp(_))) | 
|         |    148 //println(fastparse.parse("x2 := 5 + a", Stmts(_))) | 
|         |    149 //println(fastparse.parse("x2 := 5 + a[3+a]", Stmts(_))) | 
|         |    150 //println(fastparse.parse("a[x2+3] := 5 + a[3+a]", Stmts(_))) | 
|         |    151 //println(fastparse.parse("{x := 5; y := 8}", Block(_))) | 
|         |    152 //println(fastparse.parse("if (false) then {x := 5} else {x := 10}", Block(_))) | 
|         |    153  | 
|         |    154 val fib =  | 
|         |    155  """n := 10; | 
|         |    156     minus1 := 0; | 
|         |    157     minus2 := 1; | 
|         |    158     temp:=0; | 
|         |    159     while (n > 0) do { | 
|         |    160       temp := minus2;  | 
|         |    161       minus2 := minus1 + minus2; | 
|         |    162       minus1 := temp; | 
|         |    163       n := n - 1}; | 
|         |    164     result := minus2; | 
|         |    165     write(result) | 
|         |    166    """ | 
|         |    167  | 
|         |    168 //println(fastparse.parse(fib, Stmts(_)).get.value) | 
|         |    169  | 
|         |    170  | 
|         |    171  | 
|         |    172 //====================================== | 
|         |    173 // BF transpiler into WHILE with arrays | 
|         |    174 //====================================== | 
|         |    175  | 
|         |    176 // simple BF instructions translation | 
|         |    177 def instr(c: Char) : String = c match { | 
|         |    178   case '>' => "ptr := ptr + 1;" | 
|         |    179   case '<' => "ptr := ptr - 1;" | 
|         |    180   case '+' => "mem[ptr] := mem[ptr] + 1;" | 
|         |    181   case '-' => "mem[ptr] := mem[ptr] - 1;" | 
|         |    182   case '.' => "x := mem[ptr]; write x;" | 
|         |    183   //case ',' => "XXX" // "ptr = getchar();\n" | 
|         |    184   case '['  => "while (mem[ptr] != 0) do {" | 
|         |    185   case ']'  => "skip};" | 
|         |    186   case _ => "" | 
|         |    187 } | 
|         |    188  | 
|         |    189 def instrs(prog: String) : String = | 
|         |    190   prog.toList.map(instr).mkString | 
|         |    191  | 
|         |    192  | 
|         |    193 // Note: Unfortunately, the transpiled mandelbrot.bf program  | 
|         |    194 // is so large that it does not fit inside the limitations of  | 
|         |    195 // what the JVM imposes on methods (only 64K of instructions). | 
|         |    196 // Therefore some optimisations are first applied to  | 
|         |    197 // BF programs before WHILE programs are created. The | 
|         |    198 // optimisations are  | 
|         |    199 //   | 
|         |    200 //  - replacing BF-loops of the form [-] with a new 0-instruction  | 
|         |    201 //  - combining single increment/decrement instructions | 
|         |    202 // | 
|         |    203 // The size of the resulting .j-file is 270K. | 
|         |    204  | 
|         |    205  | 
|         |    206 def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match { | 
|         |    207   case (Nil, acc) => acc | 
|         |    208   case (c :: cs, Nil) => splice(cs, List((c, 1))) | 
|         |    209   case (c :: cs, (d, n) :: acc) =>  | 
|         |    210     if (c == d) splice(cs, (c, n + 1) :: acc) | 
|         |    211     else splice(cs, (c, 1) :: (d, n) :: acc) | 
|         |    212 } | 
|         |    213  | 
|         |    214 def spl(s: String) = splice(s.toList, Nil).reverse | 
|         |    215  | 
|         |    216 def instr2(c: Char, n: Int) : String = c match { | 
|         |    217   case '>' => s"ptr := ptr + $n;" | 
|         |    218   case '<' => s"ptr := ptr - $n;" | 
|         |    219   case '0' => s"mem[ptr] := 0;" | 
|         |    220   case '+' => s"mem[ptr] := mem[ptr] + $n;" | 
|         |    221   case '-' => s"mem[ptr] := mem[ptr] - $n;" | 
|         |    222   case '.' => s"x := mem[ptr]; write(x);"  | 
|         |    223   case '['  => "while (mem[ptr] != 0) do {" * n  | 
|         |    224   case ']'  => "skip};" * n | 
|         |    225   case _ => "" | 
|         |    226 } | 
|         |    227  | 
|         |    228 def instrs2(prog: String) : String = | 
|         |    229   spl(prog.replaceAll("""\[-\]""", "0")).map{ case (c, n) => instr2(c, n) }.mkString | 
|         |    230  | 
|         |    231 // adding the "header" to the BF program | 
|         |    232 def bf_str(prog: String) : String = { | 
|         |    233   "new(mem[30000]);" ++ | 
|         |    234   "ptr := 15000;" ++ | 
|         |    235   instrs2(prog) ++ | 
|         |    236   "skip" | 
|         |    237 } | 
|         |    238  | 
|         |    239  | 
|         |    240 def bf_run(prog: String, name: String) = { | 
|         |    241   println(s"BF pre-processing of $name") | 
|         |    242   val bf_string = bf_str(prog) | 
|         |    243   println(s"BF parsing (program length ${bf_string.length} characters)") | 
|         |    244   val (time, bf_prog) =  | 
|         |    245     time_needed(1, fastparse.parse(bf_string, Stmts(_)).get.value) | 
|         |    246   println(s"BF generated WHILE program (needed $time for parsing)") | 
|         |    247   compile_and_run(bf_prog, name) | 
|         |    248 } | 
|         |    249  | 
|         |    250 // a benchmark program (counts down from 'Z' to 'A') | 
|         |    251 val bf0 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++ | 
|         |    252             [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++ | 
|         |    253             ++++++++[>++++++++++[>++++++++++[>++++++++++[>+ | 
|         |    254             +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++.""" | 
|         |    255  | 
|         |    256 @doc(" Benchmark 'Z' to 'A'.") | 
|         |    257 @main | 
|         |    258 def bfc0() = bf_run(bf0, "bench") | 
|         |    259  | 
|         |    260 // Sierpinski triangle | 
|         |    261 val bf1 = """++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[ | 
|         |    262       ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<< | 
|         |    263       ]>.>+[>>]>+]""" | 
|         |    264  | 
|         |    265 @doc(" Sierpinski triangle.") | 
|         |    266 @main | 
|         |    267 def bfc1() = bf_run(bf1, "sier") | 
|         |    268  | 
|         |    269 // Hello World | 
|         |    270 val bf2 = """++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-] | 
|         |    271       >>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.""" | 
|         |    272  | 
|         |    273 @doc(" Hello world.") | 
|         |    274 @main | 
|         |    275 def bfc2() = bf_run(bf2, "hello") | 
|         |    276  | 
|         |    277 // Fibonacci  | 
|         |    278 val bf3 = """+++++++++++ | 
|         |    279       >+>>>>++++++++++++++++++++++++++++++++++++++++++++ | 
|         |    280       >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+> | 
|         |    281       +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[- | 
|         |    282       <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<< | 
|         |    283       -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]] | 
|         |    284       >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++ | 
|         |    285       +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++ | 
|         |    286       ++++++++++++++++++++++++++++++++++++++++++++.[-]<< | 
|         |    287       <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<< | 
|         |    288       [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-] | 
|         |    289       [-]++++++++++.""" | 
|         |    290  | 
|         |    291 @doc(" Fibonacci numbers.") | 
|         |    292 @main | 
|         |    293 def bfc3() = bf_run(bf3, "fibs") | 
|         |    294  | 
|         |    295 // Mandelbrot Set | 
|         |    296 //---------------- | 
|         |    297 // | 
|         |    298 // Note: Parsing of the generated WHILE program (around 60K in size) | 
|         |    299 // takes approximately 10 minutes to parse with the parser combinators, and | 
|         |    300 // approximately 30 seconds with fastparse | 
|         |    301  | 
|         |    302  | 
|         |    303 val bf4 = """A mandelbrot set fractal viewer in brainf*** written by Erik Bosman | 
|         |    304 +++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ | 
|         |    305 >>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+ | 
|         |    306 <<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>> | 
|         |    307 >+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>> | 
|         |    308 >>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>> | 
|         |    309 >>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>> | 
|         |    310 >>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>> | 
|         |    311 [>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<< | 
|         |    312 <<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[ | 
|         |    313 >>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[ | 
|         |    314 >+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[ | 
|         |    315 -<<+>>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<< | 
|         |    316 <<[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<< | 
|         |    317 [>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>> | 
|         |    318 >>>>[>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+ | 
|         |    319 <<<<<<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>> | 
|         |    320 >>>>>>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<< | 
|         |    321 +>>>>>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<< | 
|         |    322 <]<+<<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>> | 
|         |    323 >>>>>>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>> | 
|         |    324 >>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<< | 
|         |    325 <<<]>>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<< | 
|         |    326 <<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[-> | 
|         |    327 >>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<< | 
|         |    328 <<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]<<<<<<<[->+>>>-<<<<]>>>>>>>>>+++++++++++++++++++ | 
|         |    329 +++++++>>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>[<<<<<<<+<[-<+>>>>+<<[-]]>[-<<[->+>>>- | 
|         |    330 <<<<]>>>]>>>>>>>>>>>>>[>>[-]>[-]>[-]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>>>>>>[>>>>> | 
|         |    331 [-<<<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>[-<<<<<<<< | 
|         |    332 <+>>>>>>>>>]>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>>>]+>[- | 
|         |    333 ]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>>>>>>>>]<<< | 
|         |    334 <<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+>>]< | 
|         |    335 <[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[->>>> | 
|         |    336 >>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[-]<->>> | 
|         |    337 [-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[>>>>>>[-< | 
|         |    338 <<<<+>>>>>]<<<<<[->>>>>+<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>+>>>>>>>> | 
|         |    339 ]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<[->>[-<<+ | 
|         |    340 >>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[> | 
|         |    341 [->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[- | 
|         |    342 ]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>> | 
|         |    343 [>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 
|         |    344 ]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+> | 
|         |    345 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>++++++++ | 
|         |    346 +++++++[[>>>>>>>>>]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-<<<<<<<+ | 
|         |    347 >>>>>>>]<<<<<<<[->>>>>>>+<<<<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[ | 
|         |    348 -]>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>>>]>[-<<<<<<[->>>>>+<++<<<<]>>>>>[-< | 
|         |    349 <<<<+>>>>>]<->+>]<[->+<]<<<<<[->>>>>+<<<<<]>>>>>>[-]<<<<<<+>>>>[-<<<<->>>>]+<<<< | 
|         |    350 [->>>>->>>>>[>>[-<<->>]+<<[->>->[-<<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-] | 
|         |    351 +>>>>>>[>>>>>>>>>]>+<]]+>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<<<<<<<<<<<[<<<<< | 
|         |    352 <<<<]>>>>[-]+>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<< | 
|         |    353 [<<<<<<<<<]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<< | 
|         |    354 <<<+<[>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<< | 
|         |    355 <<<<<+>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<< | 
|         |    356 <<<<<<<<<<]>>>>[-]<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+<]>>>>>>>>]<<< | 
|         |    357 <<<<<+<[>[->>>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>[->>>>+<<<<]>]<[->>>>-<<<<<<< | 
|         |    358 <<<<<<<+>>>>>>>>>>]<]>>[->>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>>+<<<< | 
|         |    359 ]<<<<<<<<<<<]>>>>>>+<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>>>>>>>>>]<<<<<<<<< | 
|         |    360 [>[->>>>>+<<<<[->>>>-<<<<<<<<<<<<<<+>>>>>>>>>>>[->>>+<<<]<]>[->>>-<<<<<<<<<<<<<< | 
|         |    361 +>>>>>>>>>>>]<<]>[->>>>+<<<[->>>-<<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>>+<<<]<<<<<<< | 
|         |    362 <<<<<]]>[-]>>[-]>[-]>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-< | 
|         |    363 <<<+>>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[ | 
|         |    364 [>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+ | 
|         |    365 [>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->> | 
|         |    366 [-<<+>>]<<[->>+>+<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<< | 
|         |    367 <[>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[ | 
|         |    368 >[-]<->>>[-<<<+>[<->-<<<<<<<+>>>>>>>]<[->+<]>>>]<<[->>+<<]<+<<<<<<<<<]>>>>>>>>>[ | 
|         |    369 >>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>]> | 
|         |    370 >>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>[-]>>>>+++++++++++++++[[>>>>>>>>>]<<<<<<<<<-<<<<< | 
|         |    371 <<<<[<<<<<<<<<]>>>>>>>>>-]+[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<< | 
|         |    372 <<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[- | 
|         |    373 <<<+>>>]<<<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>> | 
|         |    374 >>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>>> | 
|         |    375 [-<<<->>>]<<<[->>>+<<<]>>>>>>>>]<<<<<<<<+<[>[->+>[-<-<<<<<<<<<<+>>>>>>>>>>>>[-<< | 
|         |    376 +>>]<]>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<<<]>>[-<+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>>]<]> | 
|         |    377 [-<<+>>]<<<<<<<<<<<<<]]>>>>[-<<<<+>>>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>> | 
|         |    378 >>>>>>]<<<<<<<<+<[>[->+>>[-<<-<<<<<<<<<<+>>>>>>>>>>>[-<+>]>]<[-<-<<<<<<<<<<+>>>> | 
|         |    379 >>>>>>>]<<]>>>[-<<+>[-<-<<<<<<<<<<+>>>>>>>>>>>]>]<[-<+>]<<<<<<<<<<<<]>>>>>+<<<<< | 
|         |    380 ]>>>>>>>>>[>>>[-]>[-]>[-]>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>>>[-<<<<< | 
|         |    381 <+>>>>>>]<<<<<<[->>>>>>+<<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>+>[-<-<<<<+>>>> | 
|         |    382 >]>>[-<<<<<<<[->>>>>+<++<<<<]>>>>>[-<<<<<+>>>>>]<->+>>]<<[->>+<<]<<<<<[->>>>>+<< | 
|         |    383 <<<]+>>>>[-<<<<->>>>]+<<<<[->>>>->>>>>[>>>[-<<<->>>]+<<<[->>>-<[-<<+>>]<<[->>+<< | 
|         |    384 <<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>[-<<->>]+<<[->>->[-<<<+>>>]< | 
|         |    385 <<[->>>+<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]< | 
|         |    386 <<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-<<<+>>>]<<<[->>>+>>>>>>[>+>[-<->]<[->+ | 
|         |    387 <]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>[->>>+<<<]>]<[->>>- | 
|         |    388 <<<<<<<<<<<<<+>>>>>>>>>>]<]>>[->>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>]>]<[->>>+<<< | 
|         |    389 ]<<<<<<<<<<<]>>>>>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]]>>>>[-<<<<+> | 
|         |    390 >>>]<<<<[->>>>+>>>>>[>+>>[-<<->>]<<[->>+<<]>>>>>>>>]<<<<<<<<+<[>[->>>>+<<<[->>>- | 
|         |    391 <<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<<]>[->>>+<<[ | 
|         |    392 ->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<<<<<<]]>>>>[-]<<<<]>>>>[-<<<<+>> | 
|         |    393 >>]<<<<[->>>>+>[-]>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>[>>>>>> | 
|         |    394 >>>]<<<<<<<<<[>[->>>>+<<<[->>>-<<<<<<<<<<<<<+>>>>>>>>>>>[->>+<<]<]>[->>-<<<<<<<< | 
|         |    395 <<<<<+>>>>>>>>>>>]<<]>[->>>+<<[->>-<<<<<<<<<<<<<+>>>>>>>>>>>]<]>[->>+<<]<<<<<<<< | 
|         |    396 <<<<]]>>>>>>>>>[>>[-]>[-]>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>[-]>[-]>>>>>[>>>>>[-<<<<+ | 
|         |    397 >>>>]<<<<[->>>>+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<+>>>>> | 
|         |    398 ]<<<<<[->>>>>+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>> | 
|         |    399 >>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+[>+>> | 
|         |    400 >>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>[-<<<<+>>>>]<<<<[->>>>+<<<<<[->>[-<<+ | 
|         |    401 >>]<<[->>+>>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[> | 
|         |    402 [->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<]>[->>>>>>>>>+<<<<<<<<<]<+>>>>>>>>]<<<<<<<<<[>[- | 
|         |    403 ]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+<<<<<<<<<]>>>>>>>>> | 
|         |    404 [>+>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>->>>>>[-<<<<<+>>>>>]<<<<<[->>>>>+<<<< | 
|         |    405 <<[->>>[-<<<+>>>]<<<[->>>+>+<<<<]+>>>>>>>>>]<<<<<<<<[<<<<<<<<<]]>>>>>>>>>[>>>>>> | 
|         |    406 >>>]<<<<<<<<<[>>[->>>>>>>>>+<<<<<<<<<]<<<<<<<<<<<]>>[->>>>>>>>>+<<<<<<<<<]<<+>>> | 
|         |    407 >>>>>]<<<<<<<<<[>[-]<->>>>[-<<<<+>[<->-<<<<<<+>>>>>>]<[->+<]>>>>]<<<[->>>+<<<]<+ | 
|         |    408 <<<<<<<<<]>>>>>>>>>[>>>>[-<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>> | 
|         |    409 >>>>>>>>>>>>>>>>>>>]>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>+++++++++++++++[[>>>>>>>> | 
|         |    410 >]<<<<<<<<<-<<<<<<<<<[<<<<<<<<<]>>>>>>>>>-]+>>>>>>>>>>>>>>>>>>>>>+<<<[<<<<<<<<<] | 
|         |    411 >>>>>>>>>[>>>[-<<<->>>]+<<<[->>>->[-<<<<+>>>>]<<<<[->>>>+<<<<<<<<<<<<<[<<<<<<<<< | 
|         |    412 ]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>[-<<<<->>>>]+<<<<[->>>>-<[-<<<+>>>]<<<[->>>+< | 
|         |    413 <<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]> | 
|         |    414 >>>>>>>]<<<<<<<<<[<<<<<<<<<]>>->>[-<<<<+>>>>]<<<<[->>>>+<<[-]<<]>>]<<+>>>>[-<<<< | 
|         |    415 ->>>>]+<<<<[->>>>-<<<<<<.>>]>>>>[-<<<<<<<.>>>>>>>]<<<[-]>[-]>[-]>[-]>[-]>[-]>>>[ | 
|         |    416 >[-]>[-]>[-]>[-]>[-]>[-]>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>[-]>>>>]<<<<<<<<< | 
|         |    417 [<<<<<<<<<]>+++++++++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+>>>>>>>>>+<<<<<<<< | 
|         |    418 <<<<<<[<<<<<<<<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+[-]>>[>>>>>>>>>]<<<<< | 
|         |    419 <<<<[>>>>>>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<[<<<<<<<<<]>>>>>>>[-]+>>>]<<<< | 
|         |    420 <<<<<<]]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+>>[>+>>>>[-<<<<->>>>]<<<<[->>> | 
|         |    421 >+<<<<]>>>>>>>>]<<+<<<<<<<[>>>>>[->>+<<]<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<< | 
|         |    422 <<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<<<<<<[->>>>>>+<<<<<<]< | 
|         |    423 +<<<<<<<<<]>>>>>>>-<<<<[-]+<<<]+>>>>>>>[-<<<<<<<->>>>>>>]+<<<<<<<[->>>>>>>->>[>> | 
|         |    424 >>>[->>+<<]>>>>]<<<<<<<<<[>[-]<->>>>>>>[-<<<<<<<+>[<->-<<<+>>>]<[->+<]>>>>>>>]<< | 
|         |    425 <<<<[->>>>>>+<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>+<<< | 
|         |    426 <<[<<<<<<<<<]>>>>>>>>>[>>>>>[-<<<<<->>>>>]+<<<<<[->>>>>->>[-<<<<<<<+>>>>>>>]<<<< | 
|         |    427 <<<[->>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>[-< | 
|         |    428 <<<<<<->>>>>>>]+<<<<<<<[->>>>>>>-<<[-<<<<<+>>>>>]<<<<<[->>>>>+<<<<<<<<<<<<<<[<<< | 
|         |    429 <<<<<<]>>>[-]+>>>>>>[>>>>>>>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<< | 
|         |    430 <<[<<<<<<<<<]>>>>[-]<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>-<<<<<[<<<<<<< | 
|         |    431 <<]]>>>]<<<<.>>>>>>>>>>[>>>>>>[-]>>>]<<<<<<<<<[<<<<<<<<<]>++++++++++[-[->>>>>>>> | 
|         |    432 >+<<<<<<<<<]>>>>>>>>>]>>>>>+>>>>>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-<<<<<< | 
|         |    433 <<+>>>>>>>>]<<<<<<<<[->>>>>>>>+[-]>[>>>>>>>>>]<<<<<<<<<[>>>>>>>>[-<<<<<<<+>>>>>> | 
|         |    434 >]<<<<<<<[->>>>>>>+<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+>>]<<<<<<<<<<]]>>>>>>>>[-<<<<< | 
|         |    435 <<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+>[>+>>>>>[-<<<<<->>>>>]<<<<<[->>>>>+<<<<<]>>>>>> | 
|         |    436 >>]<+<<<<<<<<[>>>>>>[->>+<<]<<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[-]<- | 
|         |    437 >>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<<]<+<<<<<< | 
|         |    438 <<<]>>>>>>>>-<<<<<[-]+<<<]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>->[>>> | 
|         |    439 >>>[->>+<<]>>>]<<<<<<<<<[>[-]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<< | 
|         |    440 <<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>> | 
|         |    441 +>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+< | 
|         |    442 <<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<< | 
|         |    443 <<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>> | 
|         |    444 -<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>> | 
|         |    445 >>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++ | 
|         |    446 +[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< | 
|         |    447 <<<<<]]>>>]""" | 
|         |    448  | 
|         |    449 @doc(" Mandelbrot set.") | 
|         |    450 @main | 
|         |    451 def bfc4() = bf_run(bf4, "mand") | 
|         |    452  | 
|         |    453  | 
|         |    454 // | 
|         |    455 @doc(" All benchmarks.") | 
|         |    456 @main | 
|         |    457 def all() = { bfc0(); bfc1(); bfc2(); bfc3(); bfc4() }  |