Class: Brainfuck::Stage::EvalExpr

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

Overview

AST trasnformation for evaling source string.

This stage removes the ModuleNode from root of AST tree if the code being compiled is going to be used for eval. We remove the module, because in eval we must not return the module object Also if the last statement is a DiscardNode, we replace it with its inner expression, in order to return a value.

If the source is not being compiled for eval, then output is the same AST given as input.

Instance Method Summary collapse

Constructor Details

#initialize(compiler, last) ⇒ EvalExpr

Returns a new instance of EvalExpr.



82
83
84
85
# File 'lib/brainfuck/stages.rb', line 82

def initialize(compiler, last)
  @compiler = compiler
  super
end

Instance Method Details

#runObject



87
88
89
90
# File 'lib/brainfuck/stages.rb', line 87

def run
  @output = @input
  run_next
end