start simple with code listner
This commit is contained in:
parent
aa6707337a
commit
91c7903848
@ -8,7 +8,7 @@ module Risc
|
||||
# At the end of the list the propagation spills into the next methods
|
||||
# binary and so on
|
||||
#
|
||||
class CodePosition < ObjectPosition
|
||||
class CodeListener
|
||||
|
||||
attr_reader :code , :method
|
||||
|
||||
@ -61,6 +61,18 @@ module Risc
|
||||
return nekst if nekst.methods
|
||||
return next_type(nekst)
|
||||
end
|
||||
def self.init( code , at = -1)
|
||||
while code
|
||||
position = ObjectPosition.new(code , at)
|
||||
Position.set_to(position , at)
|
||||
if code.next
|
||||
listener = ObjectListener.new(code.next)
|
||||
position.register_event(:position_changed , listener)
|
||||
end
|
||||
at += code.padded_length unless at < 0
|
||||
code = code.next
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -74,4 +74,4 @@ end
|
||||
require_relative "object_position"
|
||||
require_relative "object_listener"
|
||||
require_relative "instruction_position"
|
||||
require_relative "code_position"
|
||||
require_relative "code_listener"
|
||||
|
31
test/risc/position/test_code_listener.rb
Normal file
31
test/risc/position/test_code_listener.rb
Normal file
@ -0,0 +1,31 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
module Position
|
||||
# tests that require a boot and test propagation
|
||||
class TestcodeListener < MiniTest::Test
|
||||
def setup
|
||||
Risc.machine.boot
|
||||
@binary = Parfait::BinaryCode.new(1)
|
||||
@method = Parfait.object_space.types.values.first.methods
|
||||
@label = Risc.label("hi","ho")
|
||||
end
|
||||
|
||||
def test_has_init
|
||||
CodeListener.init(@binary)
|
||||
assert Position.get(@binary)
|
||||
end
|
||||
def test_init_listner
|
||||
@binary.extend_one
|
||||
CodeListener.init(@binary)
|
||||
pos = Position.get(@binary)
|
||||
assert !pos.event_table[:position_changed].empty?
|
||||
end
|
||||
def test_not_init_listner
|
||||
CodeListener.init(@binary)
|
||||
pos = Position.get(@binary)
|
||||
assert pos.event_table[:position_changed].empty?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -7,8 +7,8 @@ module Risc
|
||||
def setup
|
||||
@object = Dummy.new
|
||||
@dependent = Dummy.new
|
||||
@pos = Position.set(@object,0)
|
||||
Position.set(@dependent,0)
|
||||
@pos = ObjectPosition.new(@object,0)
|
||||
ObjectPosition.new(@dependent,0)
|
||||
@listener = ObjectListener.new(@dependent)
|
||||
end
|
||||
def test_register
|
||||
@ -16,13 +16,13 @@ module Risc
|
||||
end
|
||||
def test_no_fire
|
||||
@pos.register_event(:position_changed , self)
|
||||
@pos = Position.set(@object,0)
|
||||
assert_equal 0 , Position.get(@dependent).at
|
||||
Position.set_to(@pos,0)
|
||||
assert_equal 0 , Position.get(@object).at
|
||||
end
|
||||
def test_reset
|
||||
@pos.register_event(:position_changed , @listener)
|
||||
@pos = Position.set(@object,4)
|
||||
assert_equal 4 , Position.get(@dependent).at
|
||||
Position.set_to(@pos,4)
|
||||
assert_equal 0 , Position.at(4).at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user