diff --git a/lib/interpreter.rb b/lib/interpreter.rb index fc54268..5392099 100644 --- a/lib/interpreter.rb +++ b/lib/interpreter.rb @@ -31,6 +31,7 @@ class Interpreter def set_instruction i return if @instruction == i raise "Error, nil instruction" unless i + puts "next up #{i.class}" old = @instruction @instruction = i trigger(:instruction_changed, old , i) @@ -65,6 +66,12 @@ class Interpreter set_block @block.method.source.blocks[next_b] end end + + def object_for reg + id = get_register(reg) + object = Virtual.machine.objects[id] + end + # Instruction interpretation starts here def execute_Branch target = @instruction.block set_block target @@ -76,4 +83,17 @@ class Interpreter set_register( to , value ) true end + def execute_GetSlot + object = object_for( @instruction.array ) + value = object.internal_object_get( @instruction.index ) + set_register( @instruction.register , value ) + true + end + def execute_SetSlot + object = object_for( @instruction.register ) + value = object_for( @instruction.array ) + object.internal_object_set( @instruction.index , value ) + true + end + end diff --git a/test/interpreter_test.rb b/test/interpreter_test.rb index 3e16611..e558858 100644 --- a/test/interpreter_test.rb +++ b/test/interpreter_test.rb @@ -11,7 +11,25 @@ class InterpreterTest < MiniTest::Test @interpreter.start Virtual.machine.init end - def test_first - @interpreter.tick + def ticks num + last = nil + num.times do + last = @interpreter.tick + end + return last + end + def test_takes_branch + was = @interpreter.block + ticks 1 + assert was != @interpreter.block + end + def test_second + ticks 2 + assert_equal Parfait::Space , Virtual.machine.objects[ @interpreter.get_register(:r1)].class + assert_equal Register::GetSlot , @interpreter.instruction.class + assert_equal :r1, @interpreter.instruction.array.symbol + end + def test_third + assert ticks 4 end end