start BranchListener

but on hold, since it needs positions before we have them
Must create them during collection phase
This commit is contained in:
Torsten Ruger 2018-06-14 21:29:34 +03:00
parent eaaf61c117
commit 3cc9175efa
7 changed files with 48 additions and 6 deletions

View File

@ -23,6 +23,10 @@ module Risc
end end
alias :inspect :to_s alias :inspect :to_s
# if branch is implemented it must return the label it branches to
def branch
label
end
end end
# dynamic version of an Branch branch that jumps to the contents # dynamic version of an Branch branch that jumps to the contents

View File

@ -0,0 +1,22 @@
module Risc
class BranchListener
# initialize with the instruction listener
def initialize(listener)
@listener = listener
end
def position_changed(position)
end
# don't react to insertion, as the CodeListener will take care
def position_inserted(position)
end
# dont react, as we do the work in position_changed
def position_changing(position , to)
end
end
end

View File

@ -13,7 +13,7 @@ module Risc
# the same BinaryCode, or else move it and the code along # the same BinaryCode, or else move it and the code along
# #
class InstructionListener class InstructionListener
attr_reader :binary attr_reader :binary , :index
def initialize(binary) def initialize(binary)
@binary = binary @binary = binary
@ -91,7 +91,12 @@ module Risc
while(instruction) while(instruction)
position = Position.new(instruction , -1) position = Position.new(instruction , -1)
first = position unless first first = position unless first
position.position_listener(InstructionListener.new( code )) il = InstructionListener.new( code )
position.position_listener(il)
if instruction.respond_to?(:branch)
# label_pos = Position.get(instruction.branch)
# label_pos.position_listener( BranchListener.new(il))
end
instruction = instruction.next instruction = instruction.next
end end
first first

View File

@ -0,0 +1,14 @@
require_relative "helper"
module Risc
class TestBranchListener < MiniTest::Test
def setup
@machine = Risc.machine.boot
@machine.translate(:interpreter)
@machine.position_all
end
def test_has_init
end
end
end

View File

@ -1,8 +1,7 @@
require_relative "helper" require_relative "helper"
module Risc module Risc
# tests that require a boot and test propagation class TestCodeListener < MiniTest::Test
class TestcodeListener < MiniTest::Test
def setup def setup
Risc.machine.boot Risc.machine.boot
@binary = Parfait::BinaryCode.new(1) @binary = Parfait::BinaryCode.new(1)

View File

@ -1,7 +1,6 @@
require_relative "helper" require_relative "helper"
module Risc module Risc
# tests that require a boot and test propagation
class TestCodeListenerFull < MiniTest::Test class TestCodeListenerFull < MiniTest::Test
def setup def setup
@machine = Risc.machine.boot @machine = Risc.machine.boot

View File

@ -1,7 +1,6 @@
require_relative "helper" require_relative "helper"
module Risc module Risc
# tests that require a boot and test propagation
class TestInstructionListener < MiniTest::Test class TestInstructionListener < MiniTest::Test
def setup def setup
Risc.machine.boot Risc.machine.boot