Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Brainfuck 0.2.0

  • Loading branch information...
commit 282eaf1cfbb71c3f44dcf50603e627a30e3203d5 1 parent 14a95b4
@txus authored
Showing with 36 additions and 40 deletions.
  1. +17 −11 Readme.md
  2. +19 −29 lib/brainfuck/main.rb
View
28 Readme.md
@@ -1,31 +1,37 @@
# brainfuck
-Just another Brainfuck interpreter in Ruby!
+An implementation of Brainfuck on the [Rubinius](http://rubini.us) VM.
+
(If you don't know what Brainfuck is, you definitely
[should](http://en.wikipedia.org/wiki/Brainfuck)).
-This interpreter works with MRI 1.8.7, 1.9.2 and JRuby 1.5.5.
-
-## UPDATE: Known caveats solved since 0.1.0!
-
-Thanks to a complete rewrite using Kaspar Schiess' `parslet` (which you should
-definitely [check it out](http://github.com/kschiess/parslet)) nested loops
-work flawlessly. So yes, you can now run that high-security online payment
-system you wrote in Brainfuck :)
+Obviously... needs Rubinius!
## Installation and usage
You just `gem install brainfuck` (or `gem 'brainfuck'` in your Gemfile)!
-And then: `brainfuck my_file.bf`
+And then:
+
+ $ brainfuck my_file.bf
+
+Or if you just want to generate the compiled bytecode in `my_file.bfc`:
+
+ $ brainfuck -C my_file.bf
You can also require the gem and use inline brainfuck in your ruby scripts like this:
require 'brainfuck'
- Brainfuck.run "+++>+++<---"
+ # Brainfuck needs an object binding to do its stuff.
+ bnd = Object.new
+ def bnd.get; binding; end
+ bnd = bnd.get
+
+ Brainfuck::CodeLoader.execute_code "+++>+++<---", bnd, nil
# => [0, 3]
+
## Note on Patches/Pull Requests
* Fork the project.
View
48 lib/brainfuck/main.rb
@@ -50,12 +50,6 @@ def script
CodeLoader.execute_file @rest.first, nil, @print
end
- # # Run the Brainfuck REPL unless we were given an script
- # def repl
- # require 'brainfuck/repl'
- # ReadEvalPrintLoop.new(@print).main
- # end
-
# Parse command line options
def options(argv)
options = Rubinius::Options.new "Usage: brainfuck [options] [program]", 20
@@ -63,33 +57,33 @@ def options(argv)
options.doc ""
options.doc "OPTIONS:"
- options.on "-", "Read and evalute code from STDIN" do
- @evals << STDIN.read
- end
+ # options.on "-", "Read and evalute code from STDIN" do
+ # @evals << STDIN.read
+ # end
- options.on "--print-ast", "Print the Brainfuck AST" do
- @print.ast = true
- end
+ # options.on "--print-ast", "Print the Brainfuck AST" do
+ # @print.ast = true
+ # end
- options.on "--print-asm", "Print the Rubinius ASM" do
- @print.asm = true
- end
+ # options.on "--print-asm", "Print the Rubinius ASM" do
+ # @print.asm = true
+ # end
- options.on "--print-sexp", "Print the Brainfuck Sexp" do
- @print.sexp = true
- end
+ # options.on "--print-sexp", "Print the Brainfuck Sexp" do
+ # @print.sexp = true
+ # end
- options.on "--print-all", "Print Sexp, AST and Rubinius ASM" do
- @print.ast = @print.asm = @print.sexp = true
- end
+ # options.on "--print-all", "Print Sexp, AST and Rubinius ASM" do
+ # @print.ast = @print.asm = @print.sexp = true
+ # end
options.on "-C", "--compile", "Just batch compile dont execute." do
@compile_only = true
end
-
- options.on "-e", "CODE", "Execute CODE" do |e|
- @evals << e
- end
+#
+# options.on "-e", "CODE", "Execute CODE" do |e|
+# @evals << e
+# end
options.on "-h", "--help", "Display this help" do
puts options
@@ -99,10 +93,6 @@ def options(argv)
options.doc ""
@rest = options.parse(argv)
-
- # if ENV['DEBUG']
- # @print.ast = @print.asm = @print.sexp = true
- # end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.