# HG changeset patch # User Christian Urban # Date 1544122253 0 # Node ID c51305a2217f91035b99b2f91c4a55c227c43c9c # Parent 38ea26f227af20597f4b48f18228900c9d2fc7fe updated diff -r 38ea26f227af -r c51305a2217f cws/cw05.pdf Binary file cws/cw05.pdf has changed diff -r 38ea26f227af -r c51305a2217f cws/cw05.tex --- a/cws/cw05.tex Thu Dec 06 18:37:17 2018 +0000 +++ b/cws/cw05.tex Thu Dec 06 18:50:53 2018 +0000 @@ -463,7 +463,16 @@ worthwhile overall (of course for the \pcode{>A}'s and so on, the compiler incurs a penalty). Luckily, after you have performed all optimisations in (5) - (7), you can expect that the - \pcode{benchmark.bf} program runs four to five times faster.\hfill{[2 Marks]} + \pcode{benchmark.bf} program runs four to five times faster. + You can also test whether your compiler produces the correct result + by for example testing + + \begin{center} + \pcode{run(load_bff("sierpinski.bf")) == run4(load_bff("sierpinski.bf"))} + \end{center} + + which should return true for all the different compiler stages. \\ + \mbox{}\hfill{[2 Marks]} \end{itemize} \end{document} diff -r 38ea26f227af -r c51305a2217f solutions5/bfc.jar Binary file solutions5/bfc.jar has changed diff -r 38ea26f227af -r c51305a2217f solutions5/bfc.scala --- a/solutions5/bfc.scala Thu Dec 06 18:37:17 2018 +0000 +++ b/solutions5/bfc.scala Thu Dec 06 18:50:53 2018 +0000 @@ -1,7 +1,7 @@ // Part 2 about a "Compiler" for the Brainf*** language //====================================================== -//object CW10b { +object CW10b { // !!! Copy any function you need from file bf.scala !!! // @@ -254,7 +254,7 @@ def spl(s: String) = splice(s.toList, Nil).reverse -spl(load_bff("benchmark.bf")) +//spl(load_bff("benchmark.bf")) def combine(s: String) : String = { (for ((c, n) <- spl(s)) yield c match { @@ -267,7 +267,7 @@ } -combine(load_bff("benchmark.bf")) +//combine(load_bff("benchmark.bf")) def compute4(pg: String, tb: Map[Int, Int], pc: Int, mp: Int, mem: Mem) : Mem = { if (0 <= pc && pc < pg.length) { @@ -295,8 +295,8 @@ compute4(pg_opt, jtable(pg_opt), 0, 0, m) } - -combine(optimise(load_bff("benchmark.bf"))) // => """>A+B[A-A] """>A+B[A-A]