Class: Brainfuck::Stage::BfCode

Inherits:
Rubinius::Compiler::Stage
  • Object
show all
Defined in:
lib/brainfuck/stages.rb

Overview

This stage takes python code and produces a ruby array containing representation of the python source. We are currently using python’s own parser, so we just read the sexp as its printed by bin/astpretty.py

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(compiler, last) ⇒ BfCode

Returns a new instance of BfCode.



121
122
123
124
125
# File 'lib/brainfuck/stages.rb', line 121

def initialize(compiler, last)
  super
  @print = Compiler::Print.new
  compiler.parser = self
end

Instance Attribute Details

#filenameObject (readonly)

Returns the value of attribute filename.



118
119
120
# File 'lib/brainfuck/stages.rb', line 118

def filename
  @filename
end

#lineObject (readonly)

Returns the value of attribute line.



118
119
120
# File 'lib/brainfuck/stages.rb', line 118

def line
  @line
end

Returns the value of attribute print.



119
120
121
# File 'lib/brainfuck/stages.rb', line 119

def print
  @print
end

Instance Method Details

#input(code, filename = "eval", line = 1) ⇒ Object



127
128
129
130
131
# File 'lib/brainfuck/stages.rb', line 127

def input(code, filename = "eval", line = 1)
  @code = code
  @filename = filename
  @line = line
end

#runObject



133
134
135
136
137
138
# File 'lib/brainfuck/stages.rb', line 133

def run
  code = Lexer.clean(@code)
  @output = Lexer.new.tokenize(code)
  pp(@output) if @print.sexp?
  run_next
end