start BranchListener
but on hold, since it needs positions before we have them Must create them during collection phase
This commit is contained in:
parent
eaaf61c117
commit
3cc9175efa
@ -23,6 +23,10 @@ module Risc
|
||||
end
|
||||
alias :inspect :to_s
|
||||
|
||||
# if branch is implemented it must return the label it branches to
|
||||
def branch
|
||||
label
|
||||
end
|
||||
end
|
||||
|
||||
# dynamic version of an Branch branch that jumps to the contents
|
||||
|
22
lib/risc/position/branch_listener.rb
Normal file
22
lib/risc/position/branch_listener.rb
Normal 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
|
@ -13,7 +13,7 @@ module Risc
|
||||
# the same BinaryCode, or else move it and the code along
|
||||
#
|
||||
class InstructionListener
|
||||
attr_reader :binary
|
||||
attr_reader :binary , :index
|
||||
|
||||
def initialize(binary)
|
||||
@binary = binary
|
||||
@ -91,7 +91,12 @@ module Risc
|
||||
while(instruction)
|
||||
position = Position.new(instruction , -1)
|
||||
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
|
||||
end
|
||||
first
|
||||
|
14
test/risc/position/test_branch_listener.rb
Normal file
14
test/risc/position/test_branch_listener.rb
Normal 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
|
@ -1,8 +1,7 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
# tests that require a boot and test propagation
|
||||
class TestcodeListener < MiniTest::Test
|
||||
class TestCodeListener < MiniTest::Test
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
|
@ -1,7 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
# tests that require a boot and test propagation
|
||||
class TestCodeListenerFull < MiniTest::Test
|
||||
def setup
|
||||
@machine = Risc.machine.boot
|
||||
|
@ -1,7 +1,6 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
# tests that require a boot and test propagation
|
||||
class TestInstructionListener < MiniTest::Test
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
|
Loading…
x
Reference in New Issue
Block a user