# HG changeset patch # User Christian Urban # Date 1603708021 0 # Node ID d47041b23498382561694b856fa63c5cb09eb8cc # Parent 31a9f89776a3dea1db05229057296dc704fde6e1 updated diff -r 31a9f89776a3 -r d47041b23498 progs/while-arrays/benchmark.bf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/while-arrays/benchmark.bf Mon Oct 26 10:27:01 2020 +0000 @@ -0,0 +1,4 @@ +>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++ +[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++ +++++++++[>++++++++++[>++++++++++[>++++++++++[>+ ++++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++. \ No newline at end of file diff -r 31a9f89776a3 -r d47041b23498 progs/while-arrays/compile_arrays.sc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/while-arrays/compile_arrays.sc Mon Oct 26 10:27:01 2020 +0000 @@ -0,0 +1,239 @@ +// A Small Compiler for the WHILE Language +// +// - this compiler contains support for "static" integer +// arrays (they are mutable but cannot be re-sized) +// +// Call with +// +// amm compile_arrays.sc + + +// the abstract syntax trees for WHILE + +abstract class Stmt +abstract class AExp +abstract class BExp +type Block = List[Stmt] + +// statements +case object Skip extends Stmt +case class ArrayDef(s: String, n: Int) extends Stmt // array definition +case class If(a: BExp, bl1: Block, bl2: Block) extends Stmt +case class While(b: BExp, bl: Block) extends Stmt +case class Assign(s: String, a: AExp) extends Stmt // var := exp +case class AssignA(s: String, a1: AExp, a2: AExp) extends Stmt // arr[exp1] := exp2 +case class Write(s: String) extends Stmt + + +// arithmetic expressions +case class Var(s: String) extends AExp +case class Num(i: Int) extends AExp +case class Aop(o: String, a1: AExp, a2: AExp) extends AExp +case class Ref(s: String, a: AExp) extends AExp + +// boolean expressions +case object True extends BExp +case object False extends BExp +case class Bop(o: String, a1: AExp, a2: AExp) extends BExp + + +// compiler headers needed for the JVM +// +// - contains a main method and a method for writing out an integer +// +// - the stack and locals are hard-coded +// + +val beginning = """ +.class public XXX.XXX +.super java/lang/Object + +.method public static write(I)V + .limit locals 1 + .limit stack 2 + getstatic java/lang/System/out Ljava/io/PrintStream; + iload 0 + invokevirtual java/io/PrintStream/print(I)V + return +.end method + +.method public static main([Ljava/lang/String;)V + .limit locals 200 + .limit stack 200 + +; COMPILED CODE STARTS + +""" + +val ending = """ +; COMPILED CODE ENDS + return + +.end method +""" + + + +// for generating new labels +var counter = -1 + +def Fresh(x: String) = { + counter += 1 + x ++ "_" ++ counter.toString() +} + +// environments for variables and indices +type Env = Map[String, Int] + +// convenient string interpolations +// for generating instructions and labels + +implicit def sring_inters(sc: StringContext) = new { + def i(args: Any*): String = " " ++ sc.s(args:_*) ++ "\n" + def l(args: Any*): String = sc.s(args:_*) ++ ":\n" +} + +def compile_op(op: String) = op match { + case "+" => i"iadd" + case "-" => i"isub" + case "*" => i"imul" +} + +// arithmetic expression compilation +def compile_aexp(a: AExp, env : Env) : String = a match { + case Num(i) => i"ldc $i" + case Var(s) => i"iload ${env(s)}" + case Aop(op, a1, a2) => + compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ compile_op(op) + case Ref(s, a) => + i"aload ${env(s)}" ++ compile_aexp(a, env) ++ i"iaload" +} + +// boolean expression compilation +def compile_bexp(b: BExp, env : Env, jmp: String) : String = b match { + case True => "" + case False => i"goto $jmp" + case Bop("==", a1, a2) => + compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpne $jmp" + case Bop("!=", a1, a2) => + compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpeq $jmp" + case Bop("<", a1, a2) => + compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpge $jmp" +} + +// statement compilation +def compile_stmt(s: Stmt, env: Env) : (String, Env) = s match { + case Skip => ("", env) + case Assign(x, a) => { + val index = env.getOrElse(x, env.keys.size) + (compile_aexp(a, env) ++ i"istore $index \t\t; $x", env + (x -> index)) + } + case If(b, bl1, bl2) => { + val if_else = Fresh("If_else") + val if_end = Fresh("If_end") + val (instrs1, env1) = compile_block(bl1, env) + val (instrs2, env2) = compile_block(bl2, env1) + (compile_bexp(b, env, if_else) ++ + instrs1 ++ + i"goto $if_end" ++ + l"$if_else" ++ + instrs2 ++ + l"$if_end", env2) + } + case While(b, bl) => { + val loop_begin = Fresh("Loop_begin") + val loop_end = Fresh("Loop_end") + val (instrs1, env1) = compile_block(bl, env) + (l"$loop_begin" ++ + compile_bexp(b, env, loop_end) ++ + instrs1 ++ + i"goto $loop_begin" ++ + l"$loop_end", env1) + } + case Write(x) => + (i"iload ${env(x)} \t\t; $x" ++ + i"invokestatic XXX/XXX/write(I)V", env) + case ArrayDef(s: String, n: Int) => { + val index = if (env.isDefinedAt(s)) throw new Exception("array def error") else + env.keys.size + (i"ldc $n" ++ + i"newarray int" ++ + i"astore $index", env + (s -> index)) + } + case AssignA(s, a1, a2) => { + val index = if (env.isDefinedAt(s)) env(s) else + throw new Exception("array not defined") + (i"aload ${env(s)}" ++ + compile_aexp(a1, env) ++ + compile_aexp(a2, env) ++ + i"iastore", env) + } +} + +// compile a block (i.e. list of statements) +def compile_block(bl: Block, env: Env) : (String, Env) = bl match { + case Nil => ("", env) + case s::bl => { + val (instrs1, env1) = compile_stmt(s, env) + val (instrs2, env2) = compile_block(bl, env1) + (instrs1 ++ instrs2, env2) + } +} + + +// main compile function for blocks (adds headers and proper JVM names) +def compile(bl: Block, class_name: String) : String = { + val instructions = compile_block(bl, Map())._1 + (beginning ++ instructions ++ ending).replace("XXX", class_name) +} + + + +// contrived example involving arrays +val array_test = + List(ArrayDef("a", 10), // array a[10] + ArrayDef("b", 2), // array b[2] + AssignA("a", Num(0), Num(10)), // a[0] := 10 + Assign("x", Ref("a", Num(0))), // x := a[0] + Write("x"), + AssignA("b", Num(1), Num(5)), // b[1] := 5 + Assign("x", Ref("b", Num(1))), // x := b[1] + Write("x")) + + +// prints out the JVM-assembly instructions for fib above +// +// println(compile(array_test, "arr")) +// +// can be assembled by hand with +// +// java -jar jasmin.jar arr.j +// +// and run with +// +// java arr/arr + +// automating the above +import ammonite.ops._ + +def compile_to_file(bl: Block, class_name: String) : Unit = + write.over(pwd / s"$class_name.j", compile(bl, class_name)) + +def compile_and_run(bl: Block, class_name: String) : Unit = { + println(s"Start of compilation") + compile_to_file(bl, class_name) + println(s"generated $class_name.j file") + os.proc("java", "-jar", "jasmin.jar", s"$class_name.j").call() + println(s"generated $class_name.class file ") + //println(os.proc("java", s"${class_name}/${class_name}").call().out.text()) + os.proc("java", s"${class_name}/${class_name}").call(stdout = os.Inherit) + println(s"done.") +} + + + +@main def main() = { + compile_and_run(array_test, "arr") +} + + diff -r 31a9f89776a3 -r d47041b23498 progs/while-arrays/compile_bfc.sc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/while-arrays/compile_bfc.sc Mon Oct 26 10:27:01 2020 +0000 @@ -0,0 +1,310 @@ +// Some more interesting testcases for the +// WHILE compiler with arrays, it includes: +// +// - a small parser for WHILE programs +// +// - transpiles BF programs into WHILE programs +// and then compiles and runs them +// +// - the power-example is the Mandelbrot set: +// +// * 65k for the transpiled WHILE program +// * parsing uses around 30 secs using fastparse +// * the jasmin assembly file is 236k +// * the resulting Java program takes about 20 secs +// +// Call with (X being 0,1,..,4) +// +// amm compile_bfc.sc all +// amm compile_bfc.sc bfcX + + +// load the compiler +import $file.compile_arrays +import compile_arrays._ + +def time_needed[T](i: Int, code: => T) = { + val start = System.nanoTime() + for (j <- 2 to i) code + val result = code + val end = System.nanoTime() + ((end - start) / (i * 1.0e9), result) +} + +// for BF we have to change the write library-function, +// because in BF integers are written out as characters +val beginning = """ +.class public XXX.XXX +.super java/lang/Object + +.method public static write(I)V + .limit locals 1 + .limit stack 2 + getstatic java/lang/System/out Ljava/io/PrintStream; + iload 0 + i2c ; Int => Char + invokevirtual java/io/PrintStream/print(C)V ; println(I)V => print(C)V + return +.end method + +.method public static main([Ljava/lang/String;)V + .limit locals 200 + .limit stack 200 + +; COMPILED CODE STARTS + +""" + + +// modified main compilation function for blocks +def compile(bl: Block, class_name: String) : String = { + val instructions = compile_block(bl, Map())._1 + (beginning ++ instructions ++ ending).replace("XXX", class_name) +} + +// automating the above +import ammonite.ops._ + +def compile_to_file(bl: Block, class_name: String) : Unit = + write.over(pwd / s"$class_name.j", compile(bl, class_name)) + +def compile_and_run(bl: Block, class_name: String) : Unit = { + println(s"Start of compilation") + compile_to_file(bl, class_name) + println(s"generated $class_name.j file") + val (jasmin_time, _) = + time_needed(1, os.proc("java", "-jar", "jasmin.jar", s"$class_name.j").call()) + println(s"generated $class_name.class file (in $jasmin_time secs).") + val (running_time, output) = + time_needed(1, os.proc("java", s"${class_name}/${class_name}").call().out.text()) + println(output) + println(s"done (in $running_time secs).") +} + + +//===================================== +// Grammar Rules for WHILE with arrays +//===================================== + +import fastparse._ +import MultiLineWhitespace._ + +def lowercase [_ : P] = P( CharIn("a-z") ) +def uppercase[_ : P] = P( CharIn("A-Z") ) +def letter[_ : P] = P( lowercase | uppercase ) +def digit [_ : P] = P( CharIn("0-9") ) + +def Number[_ : P]: P[Int] = P( digit.rep(1) ).!.map(_.toInt) +def Ident[_ : P]: P[String] = P( letter ~ (letter | digit | "_").rep ).! + +// arithmetic expressions +def AExp[_ : P]: P[AExp] = + P( P(Te ~ "+" ~ AExp).map{ case (l, r) => Aop("+", l, r)} + | P(Te ~ "-" ~ AExp).map{ case (l, r) => Aop("-", l, r)} + | Te ) +def Te[_ : P]: P[AExp] = + P( P(Fa ~ "*" ~ Te).map{ case (l, r) => Aop("*", l, r)} + | Fa ) +def Fa[_ : P]: P[AExp] = + P( "(" ~ AExp ~ ")" + | P (Ident ~ "[" ~ AExp ~ "]").map{Ref.tupled} + | P(Number).map{Num} + | P(Ident).map{Var} ) + +// boolean expressions +def BExp[_ : P]: P[BExp] = + P( P(AExp ~ "=" ~ AExp).map{ case (x, z) => Bop("=", x, z)} + | P(AExp ~ "!=" ~ AExp).map{ case (x, z) => Bop("!=", x, z)} + | P(AExp ~ "<" ~ AExp).map{ case (x, z) => Bop("<", x, z)} + | P(AExp ~ ">" ~ AExp).map{ case (x, z) => Bop("<", z, x)} + | P("true").map{ _ => True} + | P("false").map{ _ => False} + | "(" ~ BExp ~ ")" ) + +// statements and blocks +def Stmt[_ : P]: P[Stmt] = + P( P("skip").map( _ => Skip) + | P(Ident ~ ":=" ~ AExp).map{Assign.tupled} + | P(Ident ~ "[" ~ AExp ~ "]" ~ ":=" ~ AExp).map{AssignA.tupled} + | P("if" ~ BExp ~ "then" ~ Block ~ "else" ~ Block).map{If.tupled} + | P("while" ~ BExp ~ "do" ~ Block).map{While.tupled} + | P("new(" ~ Ident ~ "[" ~ Number ~ "])").map{ArrayDef.tupled} + | P("write(" ~ Ident ~ ")").map{Write} ) + +def Stmts[_ : P]: P[Block] = + P( P(Stmt ~ ";" ~ Stmts).map{ case (x, z) => x :: z } + | P(Stmt).map{s => List(s)} ) + +def Block[_ : P]: P[Block] = + P( "{" ~ Stmts ~ "}" + | P(Stmt).map(s => List(s)) ) + +// some test cases for the parser + +//println(fastparse.parse("(1 + (2 + 5)) + 4", AExp(_)).get) +//println(fastparse.parse("1 + 2 + 3 + 45", AExp(_))) +//println(fastparse.parse("1 + 2 * 3", AExp(_))) +//println(fastparse.parse("x + 2 * 3", AExp(_))) +//println(fastparse.parse("x2 := 5 + a", Stmts(_))) +//println(fastparse.parse("x2 := 5 + a[3+a]", Stmts(_))) +//println(fastparse.parse("a[x2+3] := 5 + a[3+a]", Stmts(_))) +//println(fastparse.parse("{x := 5; y := 8}", Block(_))) +//println(fastparse.parse("if (false) then {x := 5} else {x := 10}", Block(_))) + +val fib = + """n := 10; + minus1 := 0; + minus2 := 1; + temp:=0; + while (n > 0) do { + temp := minus2; + minus2 := minus1 + minus2; + minus1 := temp; + n := n - 1}; + result := minus2; + write(result) + """ + +//println(fastparse.parse(fib, Stmts(_)).get.value) + + + +//====================================== +// BF transpiler into WHILE with arrays +//====================================== + +// simple BF instructions translation +def instr(c: Char) : String = c match { + case '>' => "ptr := ptr + 1;" + case '<' => "ptr := ptr - 1;" + case '+' => "mem[ptr] := mem[ptr] + 1;" + case '-' => "mem[ptr] := mem[ptr] - 1;" + case '.' => "x := mem[ptr]; write x;" + //case ',' => "XXX" // "ptr = getchar();\n" + case '[' => "while (mem[ptr] != 0) do {" + case ']' => "skip};" + case _ => "" +} + +def instrs(prog: String) : String = + prog.toList.map(instr).mkString + + +// Note: Unfortunately, the transpiled mandelbrot.bf program +// is so large that it does not fit inside the limitations of +// what the JVM imposes on methods (only 64K of instructions). +// Therefore some optimisations are first applied to +// BF programs before WHILE programs are created. The +// optimisations are +// +// - replacing BF-loops of the form [-] with a new 0-instruction +// - combining single increment/decrement instructions +// +// The size of the resulting .j-file is 270K. + + +def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match { + case (Nil, acc) => acc + case (c :: cs, Nil) => splice(cs, List((c, 1))) + case (c :: cs, (d, n) :: acc) => + if (c == d) splice(cs, (c, n + 1) :: acc) + else splice(cs, (c, 1) :: (d, n) :: acc) +} + +def spl(s: String) = splice(s.toList, Nil).reverse + +def instr2(c: Char, n: Int) : String = c match { + case '>' => s"ptr := ptr + $n;" + case '<' => s"ptr := ptr - $n;" + case '0' => s"mem[ptr] := 0;" + case '+' => s"mem[ptr] := mem[ptr] + $n;" + case '-' => s"mem[ptr] := mem[ptr] - $n;" + case '.' => s"x := mem[ptr]; write(x);" + case '[' => "while (mem[ptr] != 0) do {" * n + case ']' => "skip};" * n + case _ => "" +} + +def instrs2(prog: String) : String = + spl(prog.replaceAll("""\[-\]""", "0")).map{ case (c, n) => instr2(c, n) }.mkString + +// adding the "header" to the BF program +def bf_str(prog: String) : String = { + "new(mem[30000]);" ++ + "ptr := 15000;" ++ + instrs2(prog) ++ + "skip" +} + + +def bf_run(prog: String, name: String) = { + println(s"BF pre-processing of $name") + val bf_string = bf_str(prog) + println(s"BF parsing (program length ${bf_string.length} characters)") + val (time, bf_prog) = + time_needed(1, fastparse.parse(bf_string, Stmts(_)).get.value) + println(s"BF generated WHILE program (needed $time secs for parsing)") + compile_and_run(bf_prog, name) +} + +// a benchmark program (counts down from 'Z' to 'A') +@doc(" Benchmark 'Z' to 'A'.") +@main +def bfc0() = bf_run(read(pwd / "benchmark.bf"), "bench") + + +@doc(" Sierpinski triangle.") +@main +def bfc1() = bf_run(read(pwd / "sierpinski.bf"), "sier") + +// Hello World +val bf2 = """++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-] + >>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.""" + +@doc(" Hello world.") +@main +def bfc2() = bf_run(bf2, "hello") + +// Fibonacci +val bf3 = """+++++++++++ + >+>>>>++++++++++++++++++++++++++++++++++++++++++++ + >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+> + +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[- + <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<< + -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]] + >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++ + +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++ + ++++++++++++++++++++++++++++++++++++++++++++.[-]<< + <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<< + [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-] + [-]++++++++++.""" + +@doc(" Fibonacci numbers.") +@main +def bfc3() = bf_run(bf3, "fibs") + +// Mandelbrot Set +//---------------- +// +// Note: Parsing of the generated WHILE program (around 60K in size) +// takes approximately 10 minutes to parse with our parser combinators, +// and approximately 30 seconds with Ammonite's fastparse. + +@doc(" Mandelbrot set.") +@main +def bfc4() = bf_run(read(pwd / "mandelbrot.bf"), "mandelbrot") + + +// this unfortunately hits the capacity of the JVM, even with optimisations +//@doc(" Coolatz serries up to 30.") +//@main +//def bfc5() = bf_run(read(pwd / "collatz.bf"), "coll") + + +// +@doc(" All benchmarks.") +@main +def all() = { bfc0(); bfc1(); bfc2(); bfc3(); bfc4() } + + + diff -r 31a9f89776a3 -r d47041b23498 progs/while-arrays/jasmin.jar Binary file progs/while-arrays/jasmin.jar has changed diff -r 31a9f89776a3 -r d47041b23498 progs/while-arrays/mandelbrot.bf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/while-arrays/mandelbrot.bf Mon Oct 26 10:27:01 2020 +0000 @@ -0,0 +1,148 @@ +// a Mandelbrot set generator in brainf___ written by Erik Bosman +// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/) + + ++++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ +>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+ +<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>> +>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>> +>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>> +>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>> +>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>> +[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<< +<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<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<<<<<<<<<<<<<<[<<<<<<< +<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>> +-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>> +>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++ ++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< +<<<<<]]>>>] diff -r 31a9f89776a3 -r d47041b23498 progs/while-arrays/sierpinski.bf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progs/while-arrays/sierpinski.bf Mon Oct 26 10:27:01 2020 +0000 @@ -0,0 +1,3 @@ +++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[ +->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<< +]>.>+[>>]>+] diff -r 31a9f89776a3 -r d47041b23498 progs/while-compiler-arrays/benchmark.bf --- a/progs/while-compiler-arrays/benchmark.bf Mon Oct 26 10:24:59 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ ->++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++ -[>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++ -++++++++[>++++++++++[>++++++++++[>++++++++++[>+ -+++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++. \ No newline at end of file diff -r 31a9f89776a3 -r d47041b23498 progs/while-compiler-arrays/compile_arrays.sc --- a/progs/while-compiler-arrays/compile_arrays.sc Mon Oct 26 10:24:59 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,239 +0,0 @@ -// A Small Compiler for the WHILE Language -// -// - this compiler contains support for "static" integer -// arrays (they are mutable but cannot be re-sized) -// -// Call with -// -// amm compile_arrays.sc - - -// the abstract syntax trees for WHILE - -abstract class Stmt -abstract class AExp -abstract class BExp -type Block = List[Stmt] - -// statements -case object Skip extends Stmt -case class ArrayDef(s: String, n: Int) extends Stmt // array definition -case class If(a: BExp, bl1: Block, bl2: Block) extends Stmt -case class While(b: BExp, bl: Block) extends Stmt -case class Assign(s: String, a: AExp) extends Stmt // var := exp -case class AssignA(s: String, a1: AExp, a2: AExp) extends Stmt // arr[exp1] := exp2 -case class Write(s: String) extends Stmt - - -// arithmetic expressions -case class Var(s: String) extends AExp -case class Num(i: Int) extends AExp -case class Aop(o: String, a1: AExp, a2: AExp) extends AExp -case class Ref(s: String, a: AExp) extends AExp - -// boolean expressions -case object True extends BExp -case object False extends BExp -case class Bop(o: String, a1: AExp, a2: AExp) extends BExp - - -// compiler headers needed for the JVM -// -// - contains a main method and a method for writing out an integer -// -// - the stack and locals are hard-coded -// - -val beginning = """ -.class public XXX.XXX -.super java/lang/Object - -.method public static write(I)V - .limit locals 1 - .limit stack 2 - getstatic java/lang/System/out Ljava/io/PrintStream; - iload 0 - invokevirtual java/io/PrintStream/print(I)V - return -.end method - -.method public static main([Ljava/lang/String;)V - .limit locals 200 - .limit stack 200 - -; COMPILED CODE STARTS - -""" - -val ending = """ -; COMPILED CODE ENDS - return - -.end method -""" - - - -// for generating new labels -var counter = -1 - -def Fresh(x: String) = { - counter += 1 - x ++ "_" ++ counter.toString() -} - -// environments for variables and indices -type Env = Map[String, Int] - -// convenient string interpolations -// for generating instructions and labels - -implicit def sring_inters(sc: StringContext) = new { - def i(args: Any*): String = " " ++ sc.s(args:_*) ++ "\n" - def l(args: Any*): String = sc.s(args:_*) ++ ":\n" -} - -def compile_op(op: String) = op match { - case "+" => i"iadd" - case "-" => i"isub" - case "*" => i"imul" -} - -// arithmetic expression compilation -def compile_aexp(a: AExp, env : Env) : String = a match { - case Num(i) => i"ldc $i" - case Var(s) => i"iload ${env(s)}" - case Aop(op, a1, a2) => - compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ compile_op(op) - case Ref(s, a) => - i"aload ${env(s)}" ++ compile_aexp(a, env) ++ i"iaload" -} - -// boolean expression compilation -def compile_bexp(b: BExp, env : Env, jmp: String) : String = b match { - case True => "" - case False => i"goto $jmp" - case Bop("==", a1, a2) => - compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpne $jmp" - case Bop("!=", a1, a2) => - compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpeq $jmp" - case Bop("<", a1, a2) => - compile_aexp(a1, env) ++ compile_aexp(a2, env) ++ i"if_icmpge $jmp" -} - -// statement compilation -def compile_stmt(s: Stmt, env: Env) : (String, Env) = s match { - case Skip => ("", env) - case Assign(x, a) => { - val index = env.getOrElse(x, env.keys.size) - (compile_aexp(a, env) ++ i"istore $index \t\t; $x", env + (x -> index)) - } - case If(b, bl1, bl2) => { - val if_else = Fresh("If_else") - val if_end = Fresh("If_end") - val (instrs1, env1) = compile_block(bl1, env) - val (instrs2, env2) = compile_block(bl2, env1) - (compile_bexp(b, env, if_else) ++ - instrs1 ++ - i"goto $if_end" ++ - l"$if_else" ++ - instrs2 ++ - l"$if_end", env2) - } - case While(b, bl) => { - val loop_begin = Fresh("Loop_begin") - val loop_end = Fresh("Loop_end") - val (instrs1, env1) = compile_block(bl, env) - (l"$loop_begin" ++ - compile_bexp(b, env, loop_end) ++ - instrs1 ++ - i"goto $loop_begin" ++ - l"$loop_end", env1) - } - case Write(x) => - (i"iload ${env(x)} \t\t; $x" ++ - i"invokestatic XXX/XXX/write(I)V", env) - case ArrayDef(s: String, n: Int) => { - val index = if (env.isDefinedAt(s)) throw new Exception("array def error") else - env.keys.size - (i"ldc $n" ++ - i"newarray int" ++ - i"astore $index", env + (s -> index)) - } - case AssignA(s, a1, a2) => { - val index = if (env.isDefinedAt(s)) env(s) else - throw new Exception("array not defined") - (i"aload ${env(s)}" ++ - compile_aexp(a1, env) ++ - compile_aexp(a2, env) ++ - i"iastore", env) - } -} - -// compile a block (i.e. list of statements) -def compile_block(bl: Block, env: Env) : (String, Env) = bl match { - case Nil => ("", env) - case s::bl => { - val (instrs1, env1) = compile_stmt(s, env) - val (instrs2, env2) = compile_block(bl, env1) - (instrs1 ++ instrs2, env2) - } -} - - -// main compile function for blocks (adds headers and proper JVM names) -def compile(bl: Block, class_name: String) : String = { - val instructions = compile_block(bl, Map())._1 - (beginning ++ instructions ++ ending).replace("XXX", class_name) -} - - - -// contrived example involving arrays -val array_test = - List(ArrayDef("a", 10), // array a[10] - ArrayDef("b", 2), // array b[2] - AssignA("a", Num(0), Num(10)), // a[0] := 10 - Assign("x", Ref("a", Num(0))), // x := a[0] - Write("x"), - AssignA("b", Num(1), Num(5)), // b[1] := 5 - Assign("x", Ref("b", Num(1))), // x := b[1] - Write("x")) - - -// prints out the JVM-assembly instructions for fib above -// -// println(compile(array_test, "arr")) -// -// can be assembled by hand with -// -// java -jar jasmin.jar arr.j -// -// and run with -// -// java arr/arr - -// automating the above -import ammonite.ops._ - -def compile_to_file(bl: Block, class_name: String) : Unit = - write.over(pwd / s"$class_name.j", compile(bl, class_name)) - -def compile_and_run(bl: Block, class_name: String) : Unit = { - println(s"Start of compilation") - compile_to_file(bl, class_name) - println(s"generated $class_name.j file") - os.proc("java", "-jar", "jasmin.jar", s"$class_name.j").call() - println(s"generated $class_name.class file ") - //println(os.proc("java", s"${class_name}/${class_name}").call().out.text()) - os.proc("java", s"${class_name}/${class_name}").call(stdout = os.Inherit) - println(s"done.") -} - - - -@main def main() = { - compile_and_run(array_test, "arr") -} - - diff -r 31a9f89776a3 -r d47041b23498 progs/while-compiler-arrays/compile_bfc.sc --- a/progs/while-compiler-arrays/compile_bfc.sc Mon Oct 26 10:24:59 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,310 +0,0 @@ -// Some more interesting testcases for the -// WHILE compiler with arrays, it includes: -// -// - a small parser for WHILE programs -// -// - transpiles BF programs into WHILE programs -// and then compiles and runs them -// -// - the power-example is the Mandelbrot set: -// -// * 65k for the transpiled WHILE program -// * parsing uses around 30 secs using fastparse -// * the jasmin assembly file is 236k -// * the resulting Java program takes about 20 secs -// -// Call with (X being 0,1,..,4) -// -// amm compile_bfc.sc all -// amm compile_bfc.sc bfcX - - -// load the compiler -import $file.compile_arrays -import compile_arrays._ - -def time_needed[T](i: Int, code: => T) = { - val start = System.nanoTime() - for (j <- 2 to i) code - val result = code - val end = System.nanoTime() - ((end - start) / (i * 1.0e9), result) -} - -// for BF we have to change the write library-function, -// because in BF integers are written out as characters -val beginning = """ -.class public XXX.XXX -.super java/lang/Object - -.method public static write(I)V - .limit locals 1 - .limit stack 2 - getstatic java/lang/System/out Ljava/io/PrintStream; - iload 0 - i2c ; Int => Char - invokevirtual java/io/PrintStream/print(C)V ; println(I)V => print(C)V - return -.end method - -.method public static main([Ljava/lang/String;)V - .limit locals 200 - .limit stack 200 - -; COMPILED CODE STARTS - -""" - - -// modified main compilation function for blocks -def compile(bl: Block, class_name: String) : String = { - val instructions = compile_block(bl, Map())._1 - (beginning ++ instructions ++ ending).replace("XXX", class_name) -} - -// automating the above -import ammonite.ops._ - -def compile_to_file(bl: Block, class_name: String) : Unit = - write.over(pwd / s"$class_name.j", compile(bl, class_name)) - -def compile_and_run(bl: Block, class_name: String) : Unit = { - println(s"Start of compilation") - compile_to_file(bl, class_name) - println(s"generated $class_name.j file") - val (jasmin_time, _) = - time_needed(1, os.proc("java", "-jar", "jasmin.jar", s"$class_name.j").call()) - println(s"generated $class_name.class file (in $jasmin_time secs).") - val (running_time, output) = - time_needed(1, os.proc("java", s"${class_name}/${class_name}").call().out.text()) - println(output) - println(s"done (in $running_time secs).") -} - - -//===================================== -// Grammar Rules for WHILE with arrays -//===================================== - -import fastparse._ -import MultiLineWhitespace._ - -def lowercase [_ : P] = P( CharIn("a-z") ) -def uppercase[_ : P] = P( CharIn("A-Z") ) -def letter[_ : P] = P( lowercase | uppercase ) -def digit [_ : P] = P( CharIn("0-9") ) - -def Number[_ : P]: P[Int] = P( digit.rep(1) ).!.map(_.toInt) -def Ident[_ : P]: P[String] = P( letter ~ (letter | digit | "_").rep ).! - -// arithmetic expressions -def AExp[_ : P]: P[AExp] = - P( P(Te ~ "+" ~ AExp).map{ case (l, r) => Aop("+", l, r)} - | P(Te ~ "-" ~ AExp).map{ case (l, r) => Aop("-", l, r)} - | Te ) -def Te[_ : P]: P[AExp] = - P( P(Fa ~ "*" ~ Te).map{ case (l, r) => Aop("*", l, r)} - | Fa ) -def Fa[_ : P]: P[AExp] = - P( "(" ~ AExp ~ ")" - | P (Ident ~ "[" ~ AExp ~ "]").map{Ref.tupled} - | P(Number).map{Num} - | P(Ident).map{Var} ) - -// boolean expressions -def BExp[_ : P]: P[BExp] = - P( P(AExp ~ "=" ~ AExp).map{ case (x, z) => Bop("=", x, z)} - | P(AExp ~ "!=" ~ AExp).map{ case (x, z) => Bop("!=", x, z)} - | P(AExp ~ "<" ~ AExp).map{ case (x, z) => Bop("<", x, z)} - | P(AExp ~ ">" ~ AExp).map{ case (x, z) => Bop("<", z, x)} - | P("true").map{ _ => True} - | P("false").map{ _ => False} - | "(" ~ BExp ~ ")" ) - -// statements and blocks -def Stmt[_ : P]: P[Stmt] = - P( P("skip").map( _ => Skip) - | P(Ident ~ ":=" ~ AExp).map{Assign.tupled} - | P(Ident ~ "[" ~ AExp ~ "]" ~ ":=" ~ AExp).map{AssignA.tupled} - | P("if" ~ BExp ~ "then" ~ Block ~ "else" ~ Block).map{If.tupled} - | P("while" ~ BExp ~ "do" ~ Block).map{While.tupled} - | P("new(" ~ Ident ~ "[" ~ Number ~ "])").map{ArrayDef.tupled} - | P("write(" ~ Ident ~ ")").map{Write} ) - -def Stmts[_ : P]: P[Block] = - P( P(Stmt ~ ";" ~ Stmts).map{ case (x, z) => x :: z } - | P(Stmt).map{s => List(s)} ) - -def Block[_ : P]: P[Block] = - P( "{" ~ Stmts ~ "}" - | P(Stmt).map(s => List(s)) ) - -// some test cases for the parser - -//println(fastparse.parse("(1 + (2 + 5)) + 4", AExp(_)).get) -//println(fastparse.parse("1 + 2 + 3 + 45", AExp(_))) -//println(fastparse.parse("1 + 2 * 3", AExp(_))) -//println(fastparse.parse("x + 2 * 3", AExp(_))) -//println(fastparse.parse("x2 := 5 + a", Stmts(_))) -//println(fastparse.parse("x2 := 5 + a[3+a]", Stmts(_))) -//println(fastparse.parse("a[x2+3] := 5 + a[3+a]", Stmts(_))) -//println(fastparse.parse("{x := 5; y := 8}", Block(_))) -//println(fastparse.parse("if (false) then {x := 5} else {x := 10}", Block(_))) - -val fib = - """n := 10; - minus1 := 0; - minus2 := 1; - temp:=0; - while (n > 0) do { - temp := minus2; - minus2 := minus1 + minus2; - minus1 := temp; - n := n - 1}; - result := minus2; - write(result) - """ - -//println(fastparse.parse(fib, Stmts(_)).get.value) - - - -//====================================== -// BF transpiler into WHILE with arrays -//====================================== - -// simple BF instructions translation -def instr(c: Char) : String = c match { - case '>' => "ptr := ptr + 1;" - case '<' => "ptr := ptr - 1;" - case '+' => "mem[ptr] := mem[ptr] + 1;" - case '-' => "mem[ptr] := mem[ptr] - 1;" - case '.' => "x := mem[ptr]; write x;" - //case ',' => "XXX" // "ptr = getchar();\n" - case '[' => "while (mem[ptr] != 0) do {" - case ']' => "skip};" - case _ => "" -} - -def instrs(prog: String) : String = - prog.toList.map(instr).mkString - - -// Note: Unfortunately, the transpiled mandelbrot.bf program -// is so large that it does not fit inside the limitations of -// what the JVM imposes on methods (only 64K of instructions). -// Therefore some optimisations are first applied to -// BF programs before WHILE programs are created. The -// optimisations are -// -// - replacing BF-loops of the form [-] with a new 0-instruction -// - combining single increment/decrement instructions -// -// The size of the resulting .j-file is 270K. - - -def splice(cs: List[Char], acc: List[(Char, Int)]) : List[(Char, Int)] = (cs, acc) match { - case (Nil, acc) => acc - case (c :: cs, Nil) => splice(cs, List((c, 1))) - case (c :: cs, (d, n) :: acc) => - if (c == d) splice(cs, (c, n + 1) :: acc) - else splice(cs, (c, 1) :: (d, n) :: acc) -} - -def spl(s: String) = splice(s.toList, Nil).reverse - -def instr2(c: Char, n: Int) : String = c match { - case '>' => s"ptr := ptr + $n;" - case '<' => s"ptr := ptr - $n;" - case '0' => s"mem[ptr] := 0;" - case '+' => s"mem[ptr] := mem[ptr] + $n;" - case '-' => s"mem[ptr] := mem[ptr] - $n;" - case '.' => s"x := mem[ptr]; write(x);" - case '[' => "while (mem[ptr] != 0) do {" * n - case ']' => "skip};" * n - case _ => "" -} - -def instrs2(prog: String) : String = - spl(prog.replaceAll("""\[-\]""", "0")).map{ case (c, n) => instr2(c, n) }.mkString - -// adding the "header" to the BF program -def bf_str(prog: String) : String = { - "new(mem[30000]);" ++ - "ptr := 15000;" ++ - instrs2(prog) ++ - "skip" -} - - -def bf_run(prog: String, name: String) = { - println(s"BF pre-processing of $name") - val bf_string = bf_str(prog) - println(s"BF parsing (program length ${bf_string.length} characters)") - val (time, bf_prog) = - time_needed(1, fastparse.parse(bf_string, Stmts(_)).get.value) - println(s"BF generated WHILE program (needed $time secs for parsing)") - compile_and_run(bf_prog, name) -} - -// a benchmark program (counts down from 'Z' to 'A') -@doc(" Benchmark 'Z' to 'A'.") -@main -def bfc0() = bf_run(read(pwd / "benchmark.bf"), "bench") - - -@doc(" Sierpinski triangle.") -@main -def bfc1() = bf_run(read(pwd / "sierpinski.bf"), "sier") - -// Hello World -val bf2 = """++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-] - >>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.""" - -@doc(" Hello world.") -@main -def bfc2() = bf_run(bf2, "hello") - -// Fibonacci -val bf3 = """+++++++++++ - >+>>>>++++++++++++++++++++++++++++++++++++++++++++ - >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+> - +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[- - <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<< - -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]] - >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++ - +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++ - ++++++++++++++++++++++++++++++++++++++++++++.[-]<< - <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<< - [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-] - [-]++++++++++.""" - -@doc(" Fibonacci numbers.") -@main -def bfc3() = bf_run(bf3, "fibs") - -// Mandelbrot Set -//---------------- -// -// Note: Parsing of the generated WHILE program (around 60K in size) -// takes approximately 10 minutes to parse with our parser combinators, -// and approximately 30 seconds with Ammonite's fastparse. - -@doc(" Mandelbrot set.") -@main -def bfc4() = bf_run(read(pwd / "mandelbrot.bf"), "mandelbrot") - - -// this unfortunately hits the capacity of the JVM, even with optimisations -//@doc(" Coolatz serries up to 30.") -//@main -//def bfc5() = bf_run(read(pwd / "collatz.bf"), "coll") - - -// -@doc(" All benchmarks.") -@main -def all() = { bfc0(); bfc1(); bfc2(); bfc3(); bfc4() } - - - diff -r 31a9f89776a3 -r d47041b23498 progs/while-compiler-arrays/jasmin.jar Binary file progs/while-compiler-arrays/jasmin.jar has changed diff -r 31a9f89776a3 -r d47041b23498 progs/while-compiler-arrays/mandelbrot.bf --- a/progs/while-compiler-arrays/mandelbrot.bf Mon Oct 26 10:24:59 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,148 +0,0 @@ -// a Mandelbrot set generator in brainf___ written by Erik Bosman -// (http://esoteric.sange.fi/brainfuck/utils/mandelbrot/) - - -+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[ ->>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<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<]>>>>>> ->>]<+<<<<<<<<[>>>>>>[->>+<<]<<<<<<<<<<<<<<<]>>>>>>>>>[>>>>>>>>>]<<<<<<<<<[>[-]<- ->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<<]<+<<<<<< -<<<]>>>>>>>>-<<<<<[-]+<<<]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>->[>>> ->>>[->>+<<]>>>]<<<<<<<<<[>[-]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<< -<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>> -+>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+< -<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<< -<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>> --<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>> ->>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++ -+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<< -<<<<<]]>>>] diff -r 31a9f89776a3 -r d47041b23498 progs/while-compiler-arrays/sierpinski.bf --- a/progs/while-compiler-arrays/sierpinski.bf Mon Oct 26 10:24:59 2020 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[ -->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<< -]>.>+[>>]>+]