renaming and test fixing
This commit is contained in:
@ -42,10 +42,12 @@ module Risc
|
||||
cpu_jump.assemble(JumpWriter.new(code))
|
||||
end
|
||||
|
||||
# Create Position for the given BinaryCode object
|
||||
# return the last position that was created, for chaining
|
||||
def self.init( code , at = -1)
|
||||
while code
|
||||
raise "Not Binary Code #{code.class}" unless code.is_a?(Parfait::BinaryCode)
|
||||
position = Position.new(code , at)
|
||||
Position.set_to(position , at)
|
||||
if code.next
|
||||
listener = PositionListener.new(code.next)
|
||||
position.position_listener( listener)
|
||||
|
@ -39,12 +39,6 @@ module Risc
|
||||
Position.set(@instruction.next, nekst , binary)
|
||||
end
|
||||
|
||||
def reset_to(pos , binary)
|
||||
super(pos , binary)
|
||||
init(pos , binary)
|
||||
Position.log.debug "ResetInstruction (#{pos.to_s(16)}) #{instruction}"
|
||||
end
|
||||
|
||||
# initialize the dependency graph for instructions
|
||||
#
|
||||
# starting from the given instruction, create Positions
|
||||
@ -55,6 +49,7 @@ module Risc
|
||||
# return the position for the first instruction which may be used to
|
||||
# set all positions in the chain
|
||||
def self.init( instruction , code )
|
||||
raise "Not Binary Code #{code.class}" unless code.is_a?(Parfait::BinaryCode)
|
||||
first = nil
|
||||
while(instruction)
|
||||
position = Position.new(instruction , -1)
|
||||
|
@ -48,6 +48,7 @@ module Risc
|
||||
def position_listeners
|
||||
event_table[:position_changed]
|
||||
end
|
||||
|
||||
#look for InstructionListener and return its code if found
|
||||
def get_code
|
||||
listener = event_table.find{|one| one.class == InstructionListener}
|
||||
@ -55,6 +56,14 @@ module Risc
|
||||
listener.code
|
||||
end
|
||||
|
||||
def set(int)
|
||||
same = int == self.at
|
||||
Position.set_to(self , int)
|
||||
@at = int
|
||||
trigger(:position_changed , self ) unless same
|
||||
int
|
||||
end
|
||||
|
||||
def +(offset)
|
||||
offset = offset.at if offset.is_a?(Position)
|
||||
@at + offset
|
||||
@ -122,6 +131,6 @@ module Risc
|
||||
end
|
||||
end
|
||||
end
|
||||
require_relative "object_listener"
|
||||
require_relative "position_listener"
|
||||
require_relative "instruction_listener"
|
||||
require_relative "code_listener"
|
||||
|
@ -20,7 +20,8 @@ module Risc
|
||||
# position to reflect that change
|
||||
#
|
||||
def position_changed(previous)
|
||||
me = previous.at + previous.object.padded_length
|
||||
add = previous.object ? previous.object.padded_length : 0
|
||||
me = previous.at + add
|
||||
object_pos = Position.get(@object)
|
||||
return if me == object_pos.at
|
||||
Position.set(@object , me)
|
Reference in New Issue
Block a user