Class: Brainfuck::Stage::Generator
- Inherits:
-
Rubinius::Compiler::Stage
- Object
- Rubinius::Compiler::Stage
- Brainfuck::Stage::Generator
- Defined in:
- lib/brainfuck/stages.rb
Overview
This stage takes a tree of Brainfuck::AST nodes and simply calls the bytecode method on them.
Instance Attribute Summary collapse
-
#root ⇒ Object
Returns the value of attribute root.
-
#variable_scope ⇒ Object
Returns the value of attribute variable_scope.
Instance Method Summary collapse
-
#initialize(compiler, last) ⇒ Generator
constructor
A new instance of Generator.
- #run ⇒ Object
Constructor Details
#initialize(compiler, last) ⇒ Generator
Returns a new instance of Generator.
12 13 14 15 16 17 |
# File 'lib/brainfuck/stages.rb', line 12 def initialize(compiler, last) super @compiler = compiler @variable_scope = nil compiler.generator = self end |
Instance Attribute Details
#root ⇒ Object
Returns the value of attribute root.
10 11 12 |
# File 'lib/brainfuck/stages.rb', line 10 def root @root end |
#variable_scope ⇒ Object
Returns the value of attribute variable_scope.
10 11 12 |
# File 'lib/brainfuck/stages.rb', line 10 def variable_scope @variable_scope end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/brainfuck/stages.rb', line 19 def run @output = Rubinius::Generator.new @output.set_line Integer(1) # ENVIRONMENT INITIALIZATION # -------------------------- # Initialize the heap as a one-cell array containing zero, # and the pointer as a zero integer. @output. @output.set_local 1 @output.cast_array @output.set_local 0 @input.bytecode @output bottom = @output.new_label @output.push_const :ENV @output.push_literal "DEBUG" @output.send :[], 1, false @output.gif bottom # Print the heap and the pointer if ENV['DEBUG'] @output.push_literal "Heap: " @output.push_local 0 @output.send :inspect, 0 @output.push_literal "\nPointer: " @output.push_local 1 @output.push_literal "\n" @output.send :print, 5, true # end Print bottom.set! @output.use_detected # Return the heap @output.push_local 0 @output.ret @output.close run_next end |