add branch listener functionaliy

have to store the branches and loop again as labels
dont neccessarily have positions yet
This commit is contained in:
Torsten Ruger
2018-06-17 22:25:38 +03:00
parent 3298651238
commit 046617f8dc
6 changed files with 46 additions and 13 deletions

View File

@ -37,6 +37,14 @@ module Risc
DummyInstruction.new
end
end
class DummyBranch < Branch
attr_reader :precheck_called
def precheck
@precheck_called = true
end
end
class DummyInstruction < Dummy
include Util::List
def initialize(nekst = nil)

View File

@ -1,14 +1,35 @@
require_relative "helper"
require 'minitest/mock'
module Risc
class TestBranchListener < MiniTest::Test
class TestBranchListenerBooted < MiniTest::Test
def setup
DummyPlatform.boot
@binary = Parfait::BinaryCode.new(1)
@bin_pos = CodeListener.init(@binary).set(0)
@label = Label.new("HI","ho" , FakeAddress.new(2))
@branch = DummyBranch.new( "Dummy" , @label )
@branch.insert @label
InstructionListener.init(@branch , @binary)
@position = Position.get(@label)
end
def test_init_add_listener
assert_equal BranchListener , @position.event_table.values.first.last.class
end
def test_set
Position.get(@branch).set(12)
assert_equal 16 , Position.get(@label).at
end
def test_set_fires
Position.get(@label).set(20)
assert @branch.precheck_called
end
end
class TestBranchListenerPositioned < MiniTest::Test
def setup
@machine = Risc.machine.boot
@machine.translate(:interpreter)
@machine.position_all
end
def test_has_init
end
end
end