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