fix util namespace
and instruction move ripples
This commit is contained in:
parent
c5b3c3f106
commit
4cc1d8455e
@ -6,12 +6,12 @@ module Mom
|
|||||||
# Mom::Instructions are created by the Vool level as an intermediate step
|
# Mom::Instructions are created by the Vool level as an intermediate step
|
||||||
# towards the next level down, the Risc level.
|
# towards the next level down, the Risc level.
|
||||||
# Mom and Risc are both abstract machines (ie have instructions), so both
|
# Mom and Risc are both abstract machines (ie have instructions), so both
|
||||||
# share the linked list functionality (In Common::List)
|
# share the linked list functionality (In Util::List)
|
||||||
#
|
#
|
||||||
# To convert a Mom instruction to it's Risc equivalent to_risc is called
|
# To convert a Mom instruction to it's Risc equivalent to_risc is called
|
||||||
#
|
#
|
||||||
class Instruction
|
class Instruction
|
||||||
include Common::List
|
include Util::List
|
||||||
|
|
||||||
# to_risc, like the name says, converts the instruction to it's Risc equivalent.
|
# to_risc, like the name says, converts the instruction to it's Risc equivalent.
|
||||||
# The Risc machine is basically a simple register machine (kind of arm).
|
# The Risc machine is basically a simple register machine (kind of arm).
|
||||||
|
@ -20,9 +20,9 @@ module Risc
|
|||||||
# Labels are the only valid branch targets
|
# Labels are the only valid branch targets
|
||||||
#
|
#
|
||||||
class Instruction
|
class Instruction
|
||||||
include Common::List
|
include Util::List
|
||||||
|
|
||||||
def initialize source , nekst = nil
|
def initialize( source , nekst = nil )
|
||||||
@source = source
|
@source = source
|
||||||
@next = nekst
|
@next = nekst
|
||||||
return unless source
|
return unless source
|
||||||
@ -40,22 +40,6 @@ module Risc
|
|||||||
translator.translate( self )
|
translator.translate( self )
|
||||||
end
|
end
|
||||||
|
|
||||||
def total_byte_length
|
|
||||||
ret = 0
|
|
||||||
self.each{|ins| ret += ins.byte_length}
|
|
||||||
ret
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_position( position )
|
|
||||||
Positioned.set_position(self,position)
|
|
||||||
position += byte_length
|
|
||||||
if self.next
|
|
||||||
self.next.set_position( position )
|
|
||||||
else
|
|
||||||
position
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def class_source( derived)
|
def class_source( derived)
|
||||||
"#{self.class.name.split("::").last}: #{derived} #{source_mini}"
|
"#{self.class.name.split("::").last}: #{derived} #{source_mini}"
|
||||||
end
|
end
|
||||||
|
@ -38,9 +38,15 @@ module Risc
|
|||||||
def assemble io
|
def assemble io
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def total_byte_length
|
||||||
|
ret = 0
|
||||||
|
self.each{|ins| ret += ins.byte_length}
|
||||||
|
ret
|
||||||
|
end
|
||||||
|
|
||||||
# labels have the same position as their next
|
# labels have the same position as their next
|
||||||
def set_position( position )
|
def set_position( position )
|
||||||
super(position)
|
Positioned.set_position(self,position)
|
||||||
self.next.set_position(position) if self.next
|
self.next.set_position(position) if self.next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ module Risc
|
|||||||
#
|
#
|
||||||
class Interpreter
|
class Interpreter
|
||||||
# fire events for changed pc and register contents
|
# fire events for changed pc and register contents
|
||||||
include Eventable
|
include Util::Eventable
|
||||||
include Logging
|
include Logging
|
||||||
log_level :info
|
log_level :info
|
||||||
|
|
||||||
|
@ -1,37 +1,39 @@
|
|||||||
# A simple event registering/triggering module to mix into classes.
|
# A simple event registering/triggering module to mix into classes.
|
||||||
# Events are stored in the `@events` ivar.
|
# Events are stored in the `@events` ivar.
|
||||||
module Eventable
|
module Util
|
||||||
|
module Eventable
|
||||||
|
|
||||||
# Risc a handler for the given event name.
|
# Risc a handler for the given event name.
|
||||||
# The event name is the method name called on the handler object
|
# The event name is the method name called on the handler object
|
||||||
#
|
#
|
||||||
# obj.on(:foo , some_object_that_implements foo( whateverargs)
|
# obj.on(:foo , some_object_that_implements foo( whateverargs)
|
||||||
#
|
#
|
||||||
# @param [String, Symbol] name event name
|
# @param [String, Symbol] name event name
|
||||||
# @param [Object] object handling the event, ie implement the function name
|
# @param [Object] object handling the event, ie implement the function name
|
||||||
# @return handler
|
# @return handler
|
||||||
def register_event(name, handler)
|
def register_event(name, handler)
|
||||||
event_table[name] << handler
|
event_table[name] << handler
|
||||||
handler
|
handler
|
||||||
end
|
end
|
||||||
|
|
||||||
def unregister_event(name, handler)
|
def unregister_event(name, handler)
|
||||||
event_table[name].delete handler
|
event_table[name].delete handler
|
||||||
end
|
end
|
||||||
|
|
||||||
def event_table
|
def event_table
|
||||||
return @event_table if @event_table
|
return @event_table if @event_table
|
||||||
@event_table = Hash.new { |hash, key| hash[key] = [] }
|
@event_table = Hash.new { |hash, key| hash[key] = [] }
|
||||||
end
|
end
|
||||||
|
|
||||||
# Trigger the given event name and passes all args to each handler
|
# Trigger the given event name and passes all args to each handler
|
||||||
# for this event.
|
# for this event.
|
||||||
#
|
#
|
||||||
# obj.trigger(:foo)
|
# obj.trigger(:foo)
|
||||||
# obj.trigger(:foo, 1, 2, 3)
|
# obj.trigger(:foo, 1, 2, 3)
|
||||||
#
|
#
|
||||||
# @param [String, Symbol] name event name to trigger
|
# @param [String, Symbol] name event name to trigger
|
||||||
def trigger(name, *args)
|
def trigger(name, *args)
|
||||||
event_table[name].each { |handler| handler.send( name.to_sym , *args) }
|
event_table[name].each { |handler| handler.send( name.to_sym , *args) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
module Common
|
module Util
|
||||||
module List
|
module List
|
||||||
|
|
||||||
# set the next instruction (also aliased as <<)
|
# set the next instruction (also aliased as <<)
|
||||||
|
@ -30,7 +30,7 @@ module Risc
|
|||||||
def test_write_space
|
def test_write_space
|
||||||
@assembler = Assembler.new(@machine , Collector.collect_space)
|
@assembler = Assembler.new(@machine , Collector.collect_space)
|
||||||
assert @machine.translate_arm
|
assert @machine.translate_arm
|
||||||
assert @assembler.write_as_string
|
#assert @assembler.write_as_string
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user