extract padding functions to module
and finally TEST them its especially the brain bending stuff that needs tests
This commit is contained in:
@ -140,12 +140,6 @@ module Virtual
|
||||
padded(l)
|
||||
end
|
||||
|
||||
def padded len
|
||||
a = 32 * (1 + (len + 7)/32 )
|
||||
#puts "#{a} for #{len}"
|
||||
a
|
||||
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
|
||||
|
22
lib/virtual/padding.rb
Normal file
22
lib/virtual/padding.rb
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
module Padding
|
||||
|
||||
# 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
|
||||
|
||||
def padding_for length
|
||||
pad = padded(length) - length - 8 # for header, type and layout
|
||||
puts "padded #{length.to_s(16)} with #{pad.to_s(16)} stream pos #{@stream.length.to_s(16)}"
|
||||
pad
|
||||
end
|
||||
end
|
@ -39,18 +39,6 @@ module FakeMem
|
||||
end
|
||||
@position = pos
|
||||
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
|
||||
end
|
||||
module Virtual
|
||||
def self.new_list array
|
||||
@ -110,7 +98,8 @@ module Parfait
|
||||
# These are the same functions that Builtin implements at run-time
|
||||
class Object
|
||||
include FakeMem
|
||||
|
||||
include Padding
|
||||
|
||||
# these internal functions are _really_ internal
|
||||
# they respresent the smallest code needed to build larger functionality
|
||||
# but should _never_ be used outside parfait. in fact that should be impossible
|
||||
|
@ -15,16 +15,5 @@ module Positioned
|
||||
end
|
||||
@position = pos
|
||||
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
|
||||
end
|
||||
|
Reference in New Issue
Block a user