Class: BlocklyInterpreter::Interpreter

Inherits:
Object
  • Object
show all
Defined in:
lib/blockly_interpreter/interpreter.rb

Direct Known Subclasses

ConsoleInterpreter, TestInterpreter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(program) ⇒ Interpreter

Returns a new instance of Interpreter.



6
7
8
9
# File 'lib/blockly_interpreter/interpreter.rb', line 6

def initialize(program)
  @program = program
  @debug_messages = []
end

Instance Attribute Details

#debug_messagesObject (readonly)

Returns the value of attribute debug_messages.



4
5
6
# File 'lib/blockly_interpreter/interpreter.rb', line 4

def debug_messages
  @debug_messages
end

#programObject (readonly)

Returns the value of attribute program.



4
5
6
# File 'lib/blockly_interpreter/interpreter.rb', line 4

def program
  @program
end

Instance Method Details

#add_debug_messages(debug_messages) ⇒ Object



22
23
24
# File 'lib/blockly_interpreter/interpreter.rb', line 22

def add_debug_messages(debug_messages)
  @debug_messages.push *debug_messages
end

#build_execution_contextObject



11
12
13
# File 'lib/blockly_interpreter/interpreter.rb', line 11

def build_execution_context
  BlocklyInterpreter::ExecutionContext.new(self)
end

#executeObject



15
16
17
18
19
20
# File 'lib/blockly_interpreter/interpreter.rb', line 15

def execute
  build_execution_context.tap do |context|
    context.execute(program.first_block)
    add_debug_messages context.debug_messages
  end
end