extract position as module to be included
This commit is contained in:
parent
6c7004688b
commit
efe39292ae
@ -1,6 +1,20 @@
|
|||||||
require_relative "type"
|
require_relative "type"
|
||||||
require "parfait/message"
|
require "parfait/message"
|
||||||
|
|
||||||
|
module Positioned
|
||||||
|
def position
|
||||||
|
raise "position accessed but not set at #{length} for #{self.inspect}" if @position == nil
|
||||||
|
@position
|
||||||
|
end
|
||||||
|
def set_position pos
|
||||||
|
# resetting of position used to be error, but since relink and dynamic instruction size it is ok. in measures
|
||||||
|
if @position != nil and ((@position - pos).abs > 15)
|
||||||
|
raise "position set again #{pos}!=#{@position} for #{self}"
|
||||||
|
end
|
||||||
|
@position = pos
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module Virtual
|
module Virtual
|
||||||
# our machine is made up of objects, some of which are code, some data
|
# our machine is made up of objects, some of which are code, some data
|
||||||
#
|
#
|
||||||
@ -17,22 +31,12 @@ module Virtual
|
|||||||
# (ruby)Array Array
|
# (ruby)Array Array
|
||||||
# String String
|
# String String
|
||||||
class Object
|
class Object
|
||||||
|
include Positioned
|
||||||
def initialize
|
def initialize
|
||||||
@position = nil
|
@position = nil
|
||||||
@length = -1
|
@length = -1
|
||||||
end
|
end
|
||||||
attr_accessor :length , :layout
|
attr_accessor :length , :layout
|
||||||
def position
|
|
||||||
raise "position accessed but not set at #{length} for #{self.inspect}" if @position == nil
|
|
||||||
@position
|
|
||||||
end
|
|
||||||
def set_position pos
|
|
||||||
# resetting of position used to be error, but since relink and dynamic instruction size it is ok. in measures
|
|
||||||
if @position != nil and ((@position - pos).abs > 15)
|
|
||||||
raise "position set again #{pos}!=#{@position} for #{self}"
|
|
||||||
end
|
|
||||||
@position = pos
|
|
||||||
end
|
|
||||||
def inspect
|
def inspect
|
||||||
Sof::Writer.write(self)
|
Sof::Writer.write(self)
|
||||||
end
|
end
|
||||||
@ -82,6 +86,7 @@ module Virtual
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
::Message.class_eval do
|
::Message.class_eval do
|
||||||
|
include Positioned
|
||||||
def layout
|
def layout
|
||||||
Virtual::Object.layout
|
Virtual::Object.layout
|
||||||
end
|
end
|
||||||
@ -90,6 +95,7 @@ end
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
::Frame.class_eval do
|
::Frame.class_eval do
|
||||||
|
include Positioned
|
||||||
def layout
|
def layout
|
||||||
Virtual::Object.layout
|
Virtual::Object.layout
|
||||||
end
|
end
|
||||||
@ -98,41 +104,26 @@ end
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
Parfait::Hash.class_eval do
|
Parfait::Hash.class_eval do
|
||||||
|
include Positioned
|
||||||
HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
HASH = { :names => [:keys,:values] , :types => [Virtual::Reference,Virtual::Reference]}
|
||||||
def layout
|
def layout
|
||||||
HASH
|
HASH
|
||||||
end
|
end
|
||||||
def set_position pos
|
|
||||||
@position = pos
|
|
||||||
end
|
|
||||||
def position
|
|
||||||
@position
|
|
||||||
end
|
|
||||||
def mem_length
|
def mem_length
|
||||||
Virtual::Object.new.padded_words(2)
|
Virtual::Object.new.padded_words(2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Array.class_eval do
|
Array.class_eval do
|
||||||
|
include Positioned
|
||||||
def layout
|
def layout
|
||||||
Virtual::Object.layout
|
Virtual::Object.layout
|
||||||
end
|
end
|
||||||
def set_position pos
|
|
||||||
@position = pos
|
|
||||||
end
|
|
||||||
def position
|
|
||||||
@position
|
|
||||||
end
|
|
||||||
def mem_length
|
def mem_length
|
||||||
Virtual::Object.new.padded_words(length())
|
Virtual::Object.new.padded_words(length())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Symbol.class_eval do
|
Symbol.class_eval do
|
||||||
def set_position pos
|
include Positioned
|
||||||
@position = pos
|
|
||||||
end
|
|
||||||
def position
|
|
||||||
@position
|
|
||||||
end
|
|
||||||
def layout
|
def layout
|
||||||
Virtual::Object.layout
|
Virtual::Object.layout
|
||||||
end
|
end
|
||||||
@ -141,12 +132,7 @@ Symbol.class_eval do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
String.class_eval do
|
String.class_eval do
|
||||||
def set_position pos
|
include Positioned
|
||||||
@position = pos
|
|
||||||
end
|
|
||||||
def position
|
|
||||||
@position
|
|
||||||
end
|
|
||||||
def layout
|
def layout
|
||||||
Virtual::Object.layout
|
Virtual::Object.layout
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user