Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Brainfuck 0.2.0
  • Loading branch information
Josep M. Bach committed May 15, 2011
1 parent 14a95b4 commit 282eaf1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 40 deletions.
28 changes: 17 additions & 11 deletions 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.
Expand Down
48 changes: 19 additions & 29 deletions lib/brainfuck/main.rb
Expand Up @@ -50,46 +50,40 @@ 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
options.doc "Brainfuck is a Brainfuck implementation for the Rubinius VM."
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
Expand All @@ -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
Expand Down

0 comments on commit 282eaf1

Please sign in to comment.