progs/while-arrays/compile_bfc.sc
changeset 825 dca072e2bb7d
parent 817 89f9c68fc417
child 829 dc3c35673e94
equal deleted inserted replaced
824:284ac979f289 825:dca072e2bb7d
   246   println(s"BF generated WHILE program (needed $time secs for parsing)")
   246   println(s"BF generated WHILE program (needed $time secs for parsing)")
   247   compile_and_run(bf_prog, name)
   247   compile_and_run(bf_prog, name)
   248 }
   248 }
   249 
   249 
   250 // a benchmark program (counts down from 'Z' to 'A')
   250 // a benchmark program (counts down from 'Z' to 'A')
   251 @doc(" Benchmark 'Z' to 'A'.")
   251 //@doc(" Benchmark 'Z' to 'A'.")
   252 @main
   252 @main
   253 def bfc0() = bf_run(read(pwd / "benchmark.bf"), "bench")
   253 def bfc0() = bf_run(read(pwd / "benchmark.bf"), "bench")
   254 
   254 
   255 
   255 
   256 @doc(" Sierpinski triangle.")
   256 //@doc(" Sierpinski triangle.")
   257 @main
   257 @main
   258 def bfc1() = bf_run(read(pwd / "sierpinski.bf"), "sier")
   258 def bfc1() = bf_run(read(pwd / "sierpinski.bf"), "sier")
   259 
   259 
   260 // Hello World
   260 // Hello World
   261 val bf2 = """++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]
   261 val bf2 = """++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]
   262       >>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."""
   262       >>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++."""
   263 
   263 
   264 @doc(" Hello world.")
   264 //@doc(" Hello world.")
   265 @main
   265 @main
   266 def bfc2() = bf_run(bf2, "hello")
   266 def bfc2() = bf_run(bf2, "hello")
   267 
   267 
   268 // Fibonacci 
   268 // Fibonacci 
   269 val bf3 = """+++++++++++
   269 val bf3 = """+++++++++++
   277       ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
   277       ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
   278       <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
   278       <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
   279       [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]
   279       [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]
   280       [-]++++++++++."""
   280       [-]++++++++++."""
   281 
   281 
   282 @doc(" Fibonacci numbers.")
   282 //@doc(" Fibonacci numbers.")
   283 @main
   283 @main
   284 def bfc3() = bf_run(bf3, "fibs")
   284 def bfc3() = bf_run(bf3, "fibs")
   285 
   285 
   286 // Mandelbrot Set
   286 // Mandelbrot Set
   287 //----------------
   287 //----------------
   288 //
   288 //
   289 // Note: Parsing of the generated WHILE program (around 60K in size)
   289 // Note: Parsing of the generated WHILE program (around 60K in size)
   290 // takes approximately 10 minutes to parse with our parser combinators,
   290 // takes approximately 10 minutes to parse with our parser combinators,
   291 // and approximately 30 seconds with Ammonite's fastparse.
   291 // and approximately 30 seconds with Ammonite's fastparse.
   292 
   292 
   293 @doc(" Mandelbrot set.")
   293 //@doc(" Mandelbrot set.")
   294 @main
   294 @main
   295 def bfc4() = bf_run(read(pwd / "mandelbrot.bf"), "mandelbrot")
   295 def bfc4() = bf_run(read(pwd / "mandelbrot.bf"), "mandelbrot")
   296 
   296 
   297 
   297 
   298 // this unfortunately hits the capacity of the JVM, even with optimisations
   298 // this unfortunately hits the capacity of the JVM, even with optimisations
   299 //@doc(" Coolatz serries up to 30.")
   299 //@doc(" Coolatz serries up to 30.")
   300 //@main
   300 //@main
   301 //def bfc5() = bf_run(read(pwd / "collatz.bf"), "coll")
   301 //def bfc5() = bf_run(read(pwd / "collatz.bf"), "coll")
   302 
   302 
   303 
   303 // this unfortunately hits the capacity of the JVM, even with optimisations
   304 //
   304 //@doc(" Towers of Hanoi.")
   305 @doc(" All benchmarks.")
   305 //@main
       
   306 //def bfc6() = bf_run(read(pwd / "hanoi.bf"), "hanoi")
       
   307 
       
   308 //
       
   309 //@doc(" All benchmarks.")
   306 @main
   310 @main
   307 def all() = { bfc0(); bfc1(); bfc2(); bfc3(); bfc4() } 
   311 def all() = { bfc0(); bfc1(); bfc2(); bfc3(); bfc4() } 
   308 
   312 
   309 
   313 
   310 
   314