progs/compile2.scala
changeset 692 8c7ccdebcb89
parent 689 d7c9ef381437
child 693 605d971e98fd
equal deleted inserted replaced
691:991849dfbcb1 692:8c7ccdebcb89
   479 
   479 
   480 def bf_str(prog: String) : String = {
   480 def bf_str(prog: String) : String = {
   481   "\n" ++
   481   "\n" ++
   482   //"new field[30000];\n" ++
   482   //"new field[30000];\n" ++
   483   "ptr := 15000;" ++
   483   "ptr := 15000;" ++
   484   instrs2(prog) ++
   484   instrs(prog) ++
   485   "skip"
   485   "skip"
   486 }
   486 }
   487 
   487 
   488 def bf_run(prog: String, name: String) = {
   488 def bf_run(prog: String, name: String) = {
   489   println("BF processing start")
   489   println("BF processing start")
   490   val bf_string = bf_str(prog).replaceAll("\\s", "")
   490   val bf_string = bf_str(prog).replaceAll("\\s", "")
       
   491   
   491   println(s"BF parsing start (string length ${bf_string.length})")
   492   println(s"BF parsing start (string length ${bf_string.length})")
   492   val bf_prog = Stmts.parse_all(bf_string).toList.head
   493   val bf_prog = Stmts.parse_all(bf_string).toList.head
   493   println("BF Compile start")
   494   println(s"BF Compile start ${bf_string.toList.length} characters")
   494   compile_run(Array("field", 30000) :: bf_prog, name)
   495   compile_run(Array("field", 30000) :: bf_prog, name)
   495 }
   496 }
   496 
   497 
   497 // a benchmark program (counts down from 'Z' to 'A')
   498 // a benchmark program (counts down from 'Z' to 'A')
   498 val b0 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
   499 val bf0 = """>++[<+++++++++++++>-]<[[>+>+<<-]>[<+>-]++++++++
   499             [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
   500             [>++++++++<-]>.[-]<<>++++++++++[>++++++++++[>++
   500             ++++++++[>++++++++++[>++++++++++[>++++++++++[>+
   501             ++++++++[>++++++++++[>++++++++++[>++++++++++[>+
   501             +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++."""
   502             +++++++++[-]<-]<-]<-]<-]<-]<-]<-]++++++++++."""
   502 
   503 
   503 bf_run(b0, "bench")
   504 bf_run(bf0, "bench")
   504 
   505 
   505 
   506 
   506 
   507 
   507 val bf1 = """++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
   508 val bf1 = """++++++++[>+>++++<<-]>++>>+<[-[>>+<<-]+>>]>+[-<<<[
   508       ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
   509       ->[+[-]+>++>>>-<<]<[<]>>++++++[<<+++++>>-]+<<++.[-]<<
   511 bf_run(bf1, "sier")
   512 bf_run(bf1, "sier")
   512 
   513 
   513 bf_run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
   514 bf_run("""++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++
   514        ..+++.>>.<-.<.+++.------.--------.>>+.>++.""", "hello")
   515        ..+++.>>.<-.<.+++.------.--------.>>+.>++.""", "hello")
   515 
   516 
   516 bf_run("""+++++++++++
   517 println("BF SIER Prog")
       
   518 println(bf_str(bf1).replaceAll("\\s", "").split(";").toList.length)
       
   519 
       
   520 
       
   521 val bf2 = """+++++++++++
   517       >+>>>>++++++++++++++++++++++++++++++++++++++++++++
   522       >+>>>>++++++++++++++++++++++++++++++++++++++++++++
   518       >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
   523       >++++++++++++++++++++++++++++++++<<<<<<[>[>>>>>>+>
   519       +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
   524       +<<<<<<<-]>>>>>>>[<<<<<<<+>>>>>>>-]<[>++++++++++[-
   520       <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
   525       <-[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]>[<<[>>>+<<<
   521       -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
   526       -]>>[-]]<<]>>>[>>+>+<<<-]>>>[<<<+>>>-]+<[>[-]<[-]]
   522       >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
   527       >[<<+>>[-]]<<<<<<<]>>>>>[+++++++++++++++++++++++++
   523       +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
   528       +++++++++++++++++++++++.[-]]++++++++++<[->-<]>++++
   524       ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
   529       ++++++++++++++++++++++++++++++++++++++++++++.[-]<<
   525       <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
   530       <<<<<<<<<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<-[>>.>.<<<
   526       [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]""", "fibs")
   531       [-]]<<[>>+>+<<<-]>>>[<<<+>>>-]<<[<+>-]>[<+>-]<<<-]"""
       
   532 
       
   533 bf_run(bf2, "fibs")
       
   534 
       
   535 println("BF FIB Prog")
       
   536 println(bf_str(bf2).replaceAll("\\s", "").split(";").toList.length)
   527 
   537 
   528 /*
   538 /*
   529 
   539 
   530 bf_run("""      A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
   540 bf_run("""      A mandelbrot set fractal viewer in brainf*** written by Erik Bosman
   531 +++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[
   541 +++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[[