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,5 +1,6 @@
|
|||||||
# 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 Util
|
||||||
module Eventable
|
module Eventable
|
||||||
|
|
||||||
# Risc a handler for the given event name.
|
# Risc a handler for the given event name.
|
||||||
@ -35,3 +36,4 @@ module Eventable
|
|||||||
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…
x
Reference in New Issue
Block a user