--- a/progs/compile_arr2.scala Tue Jan 28 12:23:53 2020 +0000
+++ b/progs/compile_arr2.scala Mon Feb 03 01:10:16 2020 +0000
@@ -8,9 +8,12 @@
//
// Call with
//
-// scala compiler_arr.scala
+// scala compile_arr.scala
-
+// Mandelbrot
+// mand.j size 232266
+// mand.class size 21787
+// running time 16 secs
// the abstract syntax trees
abstract class Stmt
@@ -101,14 +104,28 @@
case "*" => i"imul"
}
+
+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"
+
+def compile_aload(i: Int) =
+ if (0 <= i && i <= 3) i"aload_$i" else i"aload $i"
+
+def compile_iload(i: Int) =
+ if (0 <= i && i <= 3) i"iload_$i" else i"iload $i"
+
+def compile_istore(i: Int) =
+ if (0 <= i && i <= 3) i"istore_$i" else i"istore $i"
+
// 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 Num(i) => compile_num(i)
+ case Var(s) => compile_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"
+ case Ref(s, a) =>
+ compile_aload(env(s)) ++ compile_aexp(a, env) ++ i"iaload"
}
def compile_bop(op: String, jmp: String) = op match {
@@ -117,6 +134,7 @@
case "<" => i"if_icmpge $jmp"
}
+
// boolean expression compilation
def compile_bexp(b: BExp, env : Env, jmp: String) : String = b match {
case True => ""
@@ -129,8 +147,8 @@
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))
+ val index = env.getOrElse(x, env.keys.size) //
+ (compile_aexp(a, env) ++ compile_istore(index), env + (x -> index))
}
case If(b, bl1, bl2) => {
val if_else = Fresh("If_else")
@@ -155,12 +173,12 @@
l"$loop_end", env1)
}
case Write(x) =>
- (i"iload ${env(x)} \t\t; $x" ++
+ (compile_iload(env(x)) ++
i"invokestatic XXX/XXX/write(I)V", env)
case Read(x) => {
val index = env.getOrElse(x, env.keys.size)
- (i"invokestatic XXX/XXX/read()I" ++
- i"istore $index \t\t; $x", env + (x -> index))
+ (i"invokestatic XXX/XXX/read()I" ++
+ compile_istore(index), env + (x -> index))
}
case ArrayDef(s: String, n: Int) => {
val index = if (env.isDefinedAt(s)) throw new Exception("array def error") else
@@ -172,7 +190,7 @@
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_aload(env(s)) ++
compile_aexp(a1, env) ++
compile_aexp(a2, env) ++
i"iastore", env)
@@ -197,6 +215,32 @@
}
+// Fibonacci numbers as a test-case
+val fib_test =
+ List(Read("n"), // read n;
+ Assign("minus1",Num(0)), // minus1 := 0;
+ Assign("minus2",Num(1)), // minus2 := 1;
+ Assign("temp",Num(0)), // temp := 0;
+ While(Bop("<",Num(0),Var("n")), // while n > 0 do {
+ List(Assign("temp",Var("minus2")), // temp := minus2;
+ Assign("minus2",Aop("+",Var("minus1"),Var("minus2"))),
+ // minus2 := minus1 + minus2;
+ Assign("minus1",Var("temp")), // minus1 := temp;
+ Assign("n",Aop("-",Var("n"),Num(1))))), // n := n - 1 };
+ Write("minus1")) // write minus1
+
+// prints out the JVM-assembly instructions for fib
+//
+// println(compile(fib_test, "fib"))
+//
+// can be assembled by hand with
+//
+// java -jar jvm/jasmin-2.4/jasmin.jar fib.j
+//
+// and started with
+//
+// java fib/fib
+
import scala.util._
import scala.sys.process._
@@ -219,20 +263,422 @@
println("generated .j file")
(s"java -jar jvm/jasmin-2.4/jasmin.jar ${class_name}.j").!!
println("generated .class file ")
- println("Time: " + time_needed(1, (s"java ${class_name}/${class_name}").!)._1)
+ println("Time: " + time_needed(3, (s"java ${class_name}/${class_name}").!)._1)
}
val arr_test =
- List(ArrayDef("a", 10), // new(a[10])
- ArrayDef("b", 2), // new(b[2])
- AssignA("a", Num(0), Num(10)), // a[0] := 10
- Assign("x", Ref("a", Num(0))), // x := a[0]
- Write("x"), // write x
- AssignA("b", Num(2), Num(5)), // b[2] := 5
- Assign("x", Ref("b", Num(1))), // x := b[1]
- Write("x")) // write x
+ List(ArrayDef("a", 10),
+ ArrayDef("b", 2),
+ AssignA("a", Num(0), Num(10)),
+ Assign("x", Ref("a", Num(0))),
+ Write("x"),
+ AssignA("b", Num(1), Num(5)),
+ Assign("x", Ref("b", Num(1))),
+ Write("x"))
+
+
+//compile_and_run(arr_test, "a")
+
+//====================
+// Parser Combinators
+//====================
+
+import scala.language.implicitConversions
+import scala.language.reflectiveCalls
+
+// more convenience for the semantic actions later on
+case class ~[+A, +B](_1: A, _2: B)
+
+type IsSeq[A] = A => Seq[_]
+
+abstract class Parser[I : IsSeq, T] {
+ def parse(ts: I): Set[(T, I)]
+
+ def parse_all(ts: I) : Set[T] =
+ for ((head, tail) <- parse(ts); if (tail.isEmpty)) yield head
+}
+
+class SeqParser[I : IsSeq, T, S](p: => Parser[I, T], q: => Parser[I, S]) extends Parser[I, ~[T, S]] {
+ def parse(sb: I) =
+ for ((head1, tail1) <- p.parse(sb);
+ (head2, tail2) <- q.parse(tail1)) yield (new ~(head1, head2), tail2)
+}
+
+class AltParser[I : IsSeq, T](p: => Parser[I, T], q: => Parser[I, T]) extends Parser[I, T] {
+ def parse(sb: I) = p.parse(sb) ++ q.parse(sb)
+}
+
+class FunParser[I : IsSeq, T, S](p: => Parser[I, T], f: T => S) extends Parser[I, S] {
+ def parse(sb: I) =
+ for ((head, tail) <- p.parse(sb)) yield (f(head), tail)
+}
+
+
+import scala.util.matching.Regex
+case class RegexParser(reg: Regex) extends Parser[String, String] {
+ def parse(sb: String) = reg.findPrefixMatchOf(sb) match {
+ case None => Set()
+ case Some(m) => Set((m.matched, m.after.toString))
+ }
+}
+
+def StringParser(s: String) = RegexParser(Regex.quote(s).r)
+
+
+implicit def string2parser(s : String) = StringParser(s)
+
+implicit def ParserOps[I : IsSeq, T](p: Parser[I, T]) = new {
+ def | (q : => Parser[I, T]) = new AltParser[I, T](p, q)
+ def ==>[S] (f: => T => S) = new FunParser[I, T, S](p, f)
+ def ~[S] (q : => Parser[I, S]) = new SeqParser[I, T, S](p, q)
+}
+
+implicit def StringOps(s: String) = new {
+ def | (q : => Parser[String, String]) = new AltParser[String, String](s, q)
+ def | (r: String) = new AltParser[String, String](s, r)
+ def ==>[S] (f: => String => S) = new FunParser[String, String, S](s, f)
+ def ~[S](q : => Parser[String, S]) =
+ new SeqParser[String, String, S](s, q)
+ def ~ (r: String) =
+ new SeqParser[String, String, String](s, r)
+}
+
+
+val NumParser = RegexParser("[0-9]+".r) ==> (s => s.toInt : Int)
+val IdParser = RegexParser("[a-z][a-z,0-9]*".r)
+
+
+
+// Grammar Rules for WHILE with arrays
+
+lazy val AExp: Parser[String, AExp] =
+ (Te ~ "+" ~ AExp) ==> { case x ~ _ ~ z => Aop("+", x, z):AExp } |
+ (Te ~ "-" ~ AExp) ==> { case x ~ _ ~ z => Aop("-", x, z):AExp } | Te
+lazy val Te: Parser[String, AExp] =
+ (Fa ~ "*" ~ Te) ==> { case x ~ _ ~ z => Aop("*", x, z):AExp } | Fa
+lazy val Fa: Parser[String, AExp] =
+ ("(" ~ AExp ~ ")") ==> { case _ ~ y ~ _ => y } |
+ (IdParser ~ "[" ~ AExp ~ "]") ==> { case x ~ _ ~ y ~ _ => Ref(x, y) } |
+ IdParser ==> Var |
+ NumParser ==> Num
+
+// boolean expressions
+lazy val BExp: Parser[String, BExp] =
+ (AExp ~ "=" ~ AExp) ==> { case x ~ y ~ z => Bop("=", x, z):BExp } |
+ (AExp ~ "!=" ~ AExp) ==> { case x ~ y ~ z => Bop("!=", x, z):BExp } |
+ (AExp ~ "<" ~ AExp) ==> { case x ~ y ~ z => Bop("<", x, z):BExp } |
+ (AExp ~ ">" ~ AExp) ==> { case x ~ y ~ z => Bop("<", z, x):BExp } |
+ ("true" ==> ((_) => True:BExp )) |
+ ("false" ==> ((_) => False:BExp )) |
+ ("(" ~ BExp ~ ")") ==> { case x ~ y ~ z => y}
+
+lazy val Stmt: Parser[String, Stmt] =
+ ("skip" ==> (_ => Skip: Stmt)) |
+ (IdParser ~ ":=" ~ AExp) ==> { case x ~ y ~z => Assign(x, z): Stmt } |
+ (IdParser ~ "[" ~ AExp ~ "]" ~ ":=" ~ AExp) ==> {
+ case x ~ _ ~ z ~ _ ~ _ ~ u => AssignA(x, z, u): Stmt } |
+ ("if" ~ BExp ~ "then" ~ Block ~ "else" ~ Block) ==>
+ { case _ ~ y ~ _ ~ u ~ _ ~w => If(y, u, w): Stmt } |
+ ("while" ~ BExp ~ "do" ~ Block) ==> { case _ ~ y ~ _ ~ w => While(y, w) } |
+ ("new(" ~ IdParser ~ "[" ~ NumParser ~ "])") ==> {
+ case _ ~ y ~ _ ~ u ~ _ => ArrayDef(y, u) } |
+ ("write" ~ IdParser) ==> { case _ ~ y => Write(y) }
+
+lazy val Stmts: Parser[String, Block] =
+ (Stmt ~ ";" ~ Stmts) ==> { case x ~ _ ~ z => x :: z : Block } |
+ (Stmt ==> ((s) => List(s) : Block))
+
+
+lazy val Block: Parser[String, Block] =
+ ("{" ~ Stmts ~ "}") ==> { case _ ~ y ~ _ => y} |
+ (Stmt ==> (s => List(s)))
+
+//Stmts.parse_all("x2:=5+a")
+//Stmts.parse_all("x2:=5+a[3+a]")
+//Stmts.parse_all("a[x2+3]:=5+a[3+a]")
+//Block.parse_all("{x:=5;y:=8}")
+//Block.parse_all("if(false)then{x:=5}else{x:=10}")
+
+
+
+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
+ """.replaceAll("\\s+", "")
+
+val fib_prog = Stmts.parse_all(fib).toList
+//compile_and_run(fib_prog.head, "fib")
+
+//======================================
+// 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
-compile_and_run(arr_test, "a")
+// Note: the 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 [-]
+// - 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
+
+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).replaceAll("\\s", "")
+ println(s"BF parsing (program length ${bf_string.length} characters)")
+ val (time, bf_prog) = time_needed(1, Stmts.parse_all(bf_string).toList.head)
+ println(s"BF generated WHILE program (needed $time for parsing)")
+ compile_and_run(bf_prog, name)
+}
+
+// a benchmark program (counts down from 'Z' to 'A')
+val bf0 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
+ [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
+ ++++++++[>++++++++++[>++++++++++[>++++++++++[>+
+ +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++."""
+
+bf_run(bf0, "bench")
+
+// Sierpinski triangle
+val bf1 = """++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
+ ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
+ ]>.>+[>>]>+]"""
+
+bf_run(bf1, "sier")
+
+// Helo World!
+bf_run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
+ ..+++.>>.<-.<.+++.------.--------.>>+.>++.""", "hello")
+
+// Fibonacci
+val bf2 = """+++++++++++
+ >+>>>>++++++++++++++++++++++++++++++++++++++++++++
+ >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
+ +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
+ <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
+ -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
+ >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
+ +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
+ ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
+ <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
+ [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]"""
+
+bf_run(bf2, "fibs")
+
+// Mandelbrot Set
+//----------------
+//
+// Note: Parsing of the generated WHILE program (around 60K in size)
+// takes approximately 10 minutes
+
+
+bf_run("""A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
++++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
+>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+
+<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>>>>>>>>>>>>>>>>>>>>>>>>>
+>+<<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+[>>>>>>[>>>>>>>[-]>>]<<<<<<<<<[<<<<<<<<<]>>
+>>>>>[-]+<<<<<<++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<+++++++[-[->>>
+>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>+<<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[[-]>>>>>>[>>>>>
+>>[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<+<<<+<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>>
+[>>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<+<<]>>>>>>>>]<<<<<<<<<[<<<<<<<
+<<]>>>>>>>[-<<<<<<<+>>>>>>>]<<<<<<<[->>>>>>>+<<+<<<<<]>>>>>>>>>+++++++++++++++[[
+>>>>>>>>>]+>[-]>[-]>[-]>[-]>[-]>[-]>[-]>[-]>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