fix code listener logic bug

next's position was only updated initially
previous logic relied on pushing everything long rightly
but it wasn't right, and no harm in setting position twice,
as events only fire if there is real change
This commit is contained in:
Torsten Ruger
2018-07-02 23:03:00 +03:00
parent a1197fb70c
commit 56f2742e89
7 changed files with 31 additions and 25 deletions

View File

@ -21,9 +21,8 @@ module Risc
end
class DummyPlatform
def self.boot
machine = Risc.machine.boot
machine.set_platform( self.new )
machine
Parfait.boot!
Risc.boot!
end
def translator
DummyTranslator.new

View File

@ -5,7 +5,7 @@ module Risc
def setup
DummyPlatform.boot
@binary = Parfait::BinaryCode.new(1)
@bin_pos = CodeListener.init(@binary).set(0)
@bin_pos = CodeListener.init(@binary, :interpreter).set(0)
@instruction = DummyInstruction.new
13.times {@instruction.last.insert(DummyInstruction.new) }
@position = InstructionListener.init(@instruction , @binary)

View File

@ -17,19 +17,6 @@ module Risc
assert_raises {@machine.add_constant( 1 )}
end
end
class TestMachinePos < MiniTest::Test
def setup
Parfait.boot!
Risc.boot!
@linker = Mom::MomCompiler.new.translate(:arm)
@linker.position_all
end
def test_positions_set
@linker.object_positions.each do |obj , position|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end
end
end
class TestMachineInit < MiniTest::Test
def setup
Parfait.boot!
@ -60,6 +47,5 @@ module Risc
assert position.valid? , "#{position} , #{obj.object_id.to_s(16)}"
end
end
end
end

17
test/risc/test_linker1.rb Normal file
View File

@ -0,0 +1,17 @@
require_relative "helper"
module Risc
class TestMachinePos < MiniTest::Test
def setup
Parfait.boot!
Risc.boot!
@linker = RubyX::RubyXCompiler.new("class Space; def main(arg);a = 1;return a;end;end").ruby_to_risc(:arm)
@linker.position_all
end
def test_positions_set
@linker.object_positions.each do |obj , position|
assert Position.get(obj).valid? , "#{Position.get(obj)} , #{obj.object_id.to_s(16)}"
end
end
end
end