progs/while-arrays/compile_bfc.sc
changeset 1005 0ffb6e4de10a
parent 975 ae5c03560d4d
--- a/progs/while-arrays/compile_bfc.sc	Wed Oct 08 16:52:45 2025 +0100
+++ b/progs/while-arrays/compile_bfc.sc	Fri Oct 10 10:18:05 2025 +0100
@@ -25,8 +25,8 @@
 // compile_arrays.sc (no peephole optimisations)
 // compile_arrays2.sc (peephole optimisations applied)
 
-//> using file compile_arrays.sc
-import compile_arrays.*
+//> using file compile_arrays2.sc
+import compile_arrays2.*
 
 def time_needed[T](i: Int, code: => T) = {
   val start = System.nanoTime()
@@ -192,6 +192,7 @@
   case '.' => "x := mem[ptr]; write x;"
   case '['  => "while (mem[ptr] != 0) do {"
   case ']'  => "skip};"
+  case '0' => "mem[ptr] := 0;"
   case _ => ""
 }
 
@@ -249,6 +250,7 @@
 def bf_run(prog: String, name: String) = {
   println(s"BF pre-processing of $name")
   val bf_string = bf_str(prog)
+  os.write.over(os.pwd / s"$name.while", bf_string)
   println(s"BF parsing (program length ${bf_string.length} characters)")
   val (time, bf_prog) = 
     time_needed(1, fastparse.parse(bf_string, implicit p  => Stmts).get.value)
@@ -320,10 +322,10 @@
 def all() = { bfc0(); bfc1(); bfc2(); bfc3(); bfc4() } 
 
 //all()
-bfc4()
+//bfc4()
 
-
-
+def donut() = bf_run(read(pwd / "donut.bf"), "donut")
+donut()
 
 // old way to run it with Ammonite
 //