three more instruction for interpreter
This commit is contained in:
parent
3464e50b2f
commit
6ba3c54690
@ -5,6 +5,7 @@ class Interpreter
|
||||
include Eventable
|
||||
|
||||
attr_accessor :instruction
|
||||
attr_accessor :link
|
||||
attr_accessor :block
|
||||
attr_accessor :registers
|
||||
|
||||
@ -77,18 +78,22 @@ class Interpreter
|
||||
set_block target
|
||||
false
|
||||
end
|
||||
|
||||
def execute_LoadConstant
|
||||
to = @instruction.register
|
||||
value = @instruction.constant.object_id
|
||||
set_register( to , value )
|
||||
true
|
||||
end
|
||||
|
||||
def execute_GetSlot
|
||||
object = object_for( @instruction.array )
|
||||
value = object.internal_object_get( @instruction.index )
|
||||
value = value.object_id unless value.is_a? Integer
|
||||
set_register( @instruction.register , value )
|
||||
true
|
||||
end
|
||||
|
||||
def execute_SetSlot
|
||||
object = object_for( @instruction.register )
|
||||
value = object_for( @instruction.array )
|
||||
@ -96,4 +101,23 @@ class Interpreter
|
||||
true
|
||||
end
|
||||
|
||||
def execute_RegisterTransfer
|
||||
value = get_register @instruction.from
|
||||
set_register @instruction.to , value
|
||||
true
|
||||
end
|
||||
|
||||
def execute_FunctionCall
|
||||
@link = [@block , @instruction]
|
||||
next_block = @instruction.method.source.blocks.first
|
||||
set_block next_block
|
||||
false
|
||||
end
|
||||
|
||||
def execute_SaveReturn
|
||||
object = object_for @instruction.register
|
||||
object.internal_object_set @instruction.index , @link
|
||||
true
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -14,22 +14,45 @@ class InterpreterTest < MiniTest::Test
|
||||
def ticks num
|
||||
last = nil
|
||||
num.times do
|
||||
last = @interpreter.tick
|
||||
last = @interpreter.instruction
|
||||
@interpreter.tick
|
||||
end
|
||||
return last
|
||||
end
|
||||
def test_takes_branch
|
||||
def test_first_branch
|
||||
was = @interpreter.block
|
||||
ticks 1
|
||||
assert_equal Register::Branch , ticks(1).class
|
||||
assert was != @interpreter.block
|
||||
end
|
||||
def test_second
|
||||
ticks 2
|
||||
assert_equal Register::LoadConstant , ticks(2).class
|
||||
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
|
||||
assert_equal Register::GetSlot , ticks(3).class
|
||||
assert @interpreter.get_register( :r3 )
|
||||
assert @interpreter.get_register( :r3 ).is_a? Integer
|
||||
end
|
||||
def test_fourth
|
||||
assert_equal Register::SetSlot , ticks(4).class
|
||||
end
|
||||
def test_fifth
|
||||
transfer = ticks 5
|
||||
assert_equal Register::RegisterTransfer , transfer.class
|
||||
assert_equal @interpreter.get_register(transfer.to) , @interpreter.get_register(transfer.from)
|
||||
end
|
||||
def test_sixth
|
||||
assert_equal Register::GetSlot , ticks(6).class
|
||||
end
|
||||
def test_seventh
|
||||
assert_equal Register::FunctionCall , ticks(7).class
|
||||
end
|
||||
def test_eighth
|
||||
assert_equal Register::SaveReturn , ticks(8).class
|
||||
end
|
||||
def test_ninth
|
||||
assert_equal Register::LoadConstant , ticks(9).class
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user