Slot instructions and tests

This commit is contained in:
Torsten Ruger 2015-07-24 21:15:47 +03:00
parent 93ac945dd2
commit 2f66bd9f08
2 changed files with 40 additions and 2 deletions

View File

@ -31,6 +31,7 @@ class Interpreter
def set_instruction i def set_instruction i
return if @instruction == i return if @instruction == i
raise "Error, nil instruction" unless i raise "Error, nil instruction" unless i
puts "next up #{i.class}"
old = @instruction old = @instruction
@instruction = i @instruction = i
trigger(:instruction_changed, old , i) trigger(:instruction_changed, old , i)
@ -65,6 +66,12 @@ class Interpreter
set_block @block.method.source.blocks[next_b] set_block @block.method.source.blocks[next_b]
end end
end end
def object_for reg
id = get_register(reg)
object = Virtual.machine.objects[id]
end
# Instruction interpretation starts here
def execute_Branch def execute_Branch
target = @instruction.block target = @instruction.block
set_block target set_block target
@ -76,4 +83,17 @@ class Interpreter
set_register( to , value ) set_register( to , value )
true true
end 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 end

View File

@ -11,7 +11,25 @@ class InterpreterTest < MiniTest::Test
@interpreter.start Virtual.machine.init @interpreter.start Virtual.machine.init
end end
def test_first def ticks num
@interpreter.tick 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
end end