rename code.length tp mem_length with lots of noise impact

This commit is contained in:
Torsten Ruger
2014-09-16 17:16:56 +03:00
parent cffa7f1953
commit 8b8a8eea56
14 changed files with 124 additions and 50 deletions

View File

@ -19,7 +19,7 @@ module Virtual
@codes = []
end
attr_reader :name , :codes , :method , :position
attr_reader :name , :codes , :method
attr_accessor :branch
def reachable ret = []
@ -58,13 +58,14 @@ module Virtual
def set_position at
@position = at
@codes.each do |code|
code.position = at
at += code.length
code.set_position( at)
raise code.inspect unless code.mem_length
at += code.mem_length
end
end
def length
@codes.inject(0){|count , instruction| count += instruction.length }
def mem_length
@codes.inject(0){|count , instruction| count += instruction.mem_length }
end
private

View File

@ -43,6 +43,9 @@ module Virtual
def layout
@@CLAZZ
end
def mem_length
padded_words(3)
end
def to_s
inspect
end

View File

@ -12,7 +12,7 @@ module Virtual
# While data ususally would live in a .data section, we may also "inline" it into the code
# in an oo system all data is represented as objects
class BootSpace
class BootSpace < Virtual::Object
# Initialize with a string for cpu. Naming conventions are: for Machine XXX there exists a module XXX
# with a XXXMachine in it that derives from Virtual::RegisterMachine
@ -114,5 +114,8 @@ module Virtual
end
c
end
def mem_length
padded_words( 2 )
end
end
end

View File

@ -166,12 +166,16 @@ module Virtual
add_code ::Register::RegisterMachine.instance.send(meth , *args)
end
def mem_length
l = @blocks.inject(0) { |c , block| c += block.mem_length }
padded(l)
end
# position of the function is the position of the entry block, is where we call
def set_position at
at += 8 #for the 2 header words
@blocks.each do |block|
block.set_position at
at = at + block.length
at = at + block.mem_length
end
end
def position

View File

@ -1,6 +1,6 @@
module Virtual
class Constant < ::Virtual::Value
class Constant < ::Virtual::Object
end
class TrueConstant < Constant
end
@ -15,7 +15,7 @@ module Virtual
def type
Virtual::Reference
end
def claszz
def clazz
raise "abstract #{self}"
end
end
@ -40,12 +40,19 @@ module Virtual
@string = str
end
attr_reader :string
def result= value
class_for(MoveInstruction).new(value , self , :opcode => :mov)
end
def clazz
BootSpace.space.get_or_create_class(:String)
end
def layout
Virtual::Object.layout
end
def mem_length
padded(1 + string.length)
end
end
end

View File

@ -17,19 +17,24 @@ module Virtual
# String String
class Object
def initialize
@position = -1
@position = nil
@length = -1
end
attr_accessor :position , :length , :layout
attr_accessor :length , :layout
def position
raise "position accessed but not set at #{length} for #{self.objekt}" if @position == -1
raise "position accessed but not set at #{length} for #{self.objekt}" if @position == nil
@position
end
def set_position pos
raise "position set again #{pos}!=#{@position} for #{self}" if @position != nil and (@position != pos)
@position = pos
end
def inspect
Sof::Writer.write(self)
end
def mem_length
raise "abstract #{self}"
end
@@EMPTY = { :names => [] , :types => []}
def layout
raise "Find me #{self}"
@ -58,7 +63,27 @@ module Virtual
raise "linker encounters unknown class #{object.class}"
end
end
# objects only come in lengths of multiple of 8 words
# but there is a constant overhead of 2 words, one for type, one for layout
# and as we would have to subtract 1 to make it work without overhead, we now have to add 7
def padded len
a = 32 * (1 + (len + 7)/32 )
#puts "#{a} for #{len}"
a
end
def padded_words words
padded(words*4) # 4 == word length, a constant waiting for a home
end
# pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary
def pad_after length
pad = padded(length) - length - 8 # for header, type and layout
pad.times do
@stream.write_uint8(0)
end
#puts "padded #{length} with #{pad} stream pos #{@stream.length.to_s(16)}"
end
end
end
Parfait::Hash.class_eval do
@ -66,14 +91,55 @@ Parfait::Hash.class_eval do
def layout
@@HASH
end
def set_position pos
@position = pos
end
def position
@position
end
def mem_length
Virtual::Object.new.padded_words(2)
end
end
Array.class_eval do
def layout
Virtual::Object.layout
end
def set_position pos
@position = pos
end
def position
@position
end
def mem_length
Virtual::Object.new.padded_words(length())
end
end
Symbol.class_eval do
def set_position pos
@position = pos
end
def position
@position
end
def layout
Virtual::Object.layout
end
def mem_length
Virtual::Object.new.padded(1 + to_s.length())
end
end
String.class_eval do
def set_position pos
@position = pos
end
def position
@position
end
def layout
Virtual::Object.layout
end
def mem_length
Virtual::Object.new.padded(1 + length())
end
end

View File

@ -37,9 +37,9 @@ module Virtual
# Code interface follows. Note position is inheitted as is from Code
# length of the Plock is the length of the block, plus the branch, plus data.
def length
len = @data.inject(super) {| sum , item | sum + item.length}
len + @branch_code.length
def mem_length
len = @data.inject(super) {| sum , item | sum + item.mem_length}
len + @branch_code.mem_length
end
# again, super + branch plus data
@ -48,7 +48,7 @@ module Virtual
@branch_code.link_at pos , context
@data.each do |code|
code.link_at(pos , context)
pos += code.length
pos += code.mem_length
end
end

View File

@ -8,7 +8,7 @@ module Virtual
# additionally frame, self and return are slots in Message and NewMessage
class Slot < Value
class Slot
RETURN = 0
SELF = 1
FRAME = 2