--- a/progs/bfc1.scala Thu Sep 26 12:59:33 2019 +0100
+++ b/progs/bfc1.scala Thu Sep 26 14:12:11 2019 +0100
@@ -9,6 +9,7 @@
def load_bff(name: String) : String =
Try(Source.fromFile(name)("ISO-8859-1").mkString).getOrElse("")
+// "splicing" a BF program counting occurrences
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)))
@@ -19,6 +20,7 @@
def spl(s: String) = splice(s.toList, Nil).reverse
+// generating "compound" c-instructions
def instr2(c: Char, n: Int) : String = c match {
case '>' => "ptr += " + n.toString + ";"
case '<' => "ptr -= " + n.toString + ";"
@@ -59,7 +61,7 @@
def compile_run(prog: String) = {
compile("tmp", prog)
- "gcc -O3 -o tmp tmp.c".!
+ "gcc -O0 -o tmp tmp.c".!
"./tmp".!
()
}
@@ -71,8 +73,10 @@
(end - start) / (n * 1.0e9)
}
+// mandelbrot program
+val b0 = load_bff("mandelbrot.bf")
-println(s"${time_needed(1, compile_run(load_bff("mandelbrot.bf")))} secs")
+println(s"${time_needed(1, compile_run(b0))} secs")