update return address in label
so return jumps go to the right address
This commit is contained in:
parent
c7ad1d98ca
commit
0513cd504f
@ -50,8 +50,11 @@ module Risc
|
|||||||
raise "Invalid negative index #{@index} , #{Position.get(@binary)}" if index < 0
|
raise "Invalid negative index #{@index} , #{Position.get(@binary)}" if index < 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# update label positions. All else done in position_changing
|
||||||
def position_changed(position)
|
def position_changed(position)
|
||||||
#code moved to position_changing
|
instruction = position.object
|
||||||
|
return unless instruction.is_a?(Label)
|
||||||
|
instruction.address.set_value(position.at)
|
||||||
end
|
end
|
||||||
|
|
||||||
# When this is called, only the actual insert has happened (keeping the
|
# When this is called, only the actual insert has happened (keeping the
|
||||||
|
@ -10,6 +10,13 @@ module Risc
|
|||||||
@instruction = DummyInstruction.new(DummyInstruction.new)
|
@instruction = DummyInstruction.new(DummyInstruction.new)
|
||||||
@position = InstructionListener.init(@instruction , @binary)
|
@position = InstructionListener.init(@instruction , @binary)
|
||||||
end
|
end
|
||||||
|
def test_label_address
|
||||||
|
label = Label.new("hi" ,"ho" , FakeAddress.new(0))
|
||||||
|
label_pos = Position.new( label , -1 )
|
||||||
|
label_pos.position_listener(InstructionListener.new(@binary))
|
||||||
|
label_pos.set(8)
|
||||||
|
assert_equal 8 , label_pos.object.address.value
|
||||||
|
end
|
||||||
def test_init
|
def test_init
|
||||||
assert InstructionListener.init(@instruction , @binary)
|
assert InstructionListener.init(@instruction , @binary)
|
||||||
end
|
end
|
||||||
|
@ -52,7 +52,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
def test_pc1
|
def test_pc1
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 20172 , @interpreter.pc
|
assert_equal 20344 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def test_tick2
|
def test_tick2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@ -66,22 +66,26 @@ module Risc
|
|||||||
def test_pc2
|
def test_pc2
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal 20176 , @interpreter.pc
|
assert_equal 20348 , @interpreter.pc
|
||||||
end
|
end
|
||||||
def pest_tick_14_jump
|
def test_tick_14_jump
|
||||||
14.times {@interpreter.tick}
|
14.times {@interpreter.tick}
|
||||||
assert_equal Branch , @interpreter.instruction.class
|
assert_equal Branch , @interpreter.instruction.class
|
||||||
end
|
end
|
||||||
def pest_tick_14_bin
|
def test_tick_14_bin
|
||||||
13.times {@interpreter.tick}
|
13.times {@interpreter.tick}
|
||||||
binary_pos = binary_position
|
binary_pos = binary_position
|
||||||
|
@interpreter.tick #jump has no listener
|
||||||
@interpreter.tick
|
@interpreter.tick
|
||||||
assert_equal binary_pos , binary_position , "#{binary_pos.to_s(16)}!=#{binary_position.to_s(16)}"
|
assert binary_pos.at != binary_position.at , "#{binary_pos}!=#{binary_position}"
|
||||||
end
|
end
|
||||||
def binary_position
|
def binary_position
|
||||||
Position.get(Position.get(@interpreter.instruction).binary).at
|
pos = Position.get(@interpreter.instruction)
|
||||||
|
list = pos.event_table[:position_changed].first
|
||||||
|
assert_equal InstructionListener, list.class
|
||||||
|
Position.get(list.binary)
|
||||||
end
|
end
|
||||||
def pest_tick_15 #more than a binary code worth
|
def test_tick_15 #more than a binary code worth
|
||||||
15.times {@interpreter.tick}
|
15.times {@interpreter.tick}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user