stop including padding

use it as a helper module
This commit is contained in:
Torsten Ruger 2016-12-31 20:08:33 +02:00
parent dccd097fef
commit 86dafccb04
7 changed files with 11 additions and 21 deletions

View File

@ -9,7 +9,6 @@ module Register
# functions on the objects, but now it has gone to a visitor pattern.
class Assembler
include Padding
include Logging
log_level :info
@ -261,7 +260,7 @@ module Register
# pad_after is always in bytes and pads (writes 0's) up to the next 8 word boundary
def pad_after length
before = stream_position
pad = padding_for(length) - 4 # four is for the MARKER we write
pad = Padding.padding_for(length) - 4 # four is for the MARKER we write
pad.times do
@stream.write_unsigned_int_8(0)
end

View File

@ -5,17 +5,17 @@ module Padding
# objects only come in lengths of multiple of 8 words / 32 bytes
# and there is a "hidden" 1 word that is used for debug/check memory corruption
def padded len
def self.padded( len )
a = 32 * (1 + (len + 3)/32 )
#puts "#{a} for #{len}"
a
end
def padded_words words
def self.padded_words( words )
padded(words*4) # 4 == word length, a constant waiting for a home
end
def padding_for length
def self.padding_for( length )
pad = padded(length) - length # for header, type
pad
end

View File

@ -160,7 +160,7 @@ module Parfait
# but additionally, the amount of data comes on top.
# unfortuntely we can't just use super because of the Padding
def padded_length
padded_words( get_type().instance_length + get_length() )
Padding.padded_words( get_type().instance_length + get_length() )
end
def each

View File

@ -30,7 +30,6 @@ module Parfait
object
end
include Padding
include Positioned
# 1 -based index
@ -109,7 +108,7 @@ module Parfait
end
def padded_length
padded_words( @type.instance_length )
Padding.padded_words( @type.instance_length )
end
# parfait versions are deliberately called different, so we "relay"

View File

@ -1,7 +1,6 @@
class Symbol
include Positioned
include Padding
def has_type?
true
@ -12,7 +11,7 @@ class Symbol
l
end
def padded_length
padded to_s.length + 4
Padding.padded( to_s.length + 4)
end
end

View File

@ -196,7 +196,7 @@ module Parfait
end
def padded_length
padded( 4 * get_type().instance_length + @char_length )
Padding.padded( 4 * get_type().instance_length + @char_length )
end
private

View File

@ -1,27 +1,20 @@
require_relative "../helper"
class Padded
include Padding
end
class TestPadding < MiniTest::Test
def setup
@pad = Padded.new
end
def test_small
[6,27,28].each do |p|
assert_equal 32 , @pad.padded(p) , "Expecting 32 for #{p}"
assert_equal 32 , Padding.padded(p) , "Expecting 32 for #{p}"
end
end
def test_medium
[29,33,40,57,60].each do |p|
assert_equal 64 , @pad.padded(p) , "Expecting 64 for #{p}"
assert_equal 64 , Padding.padded(p) , "Expecting 64 for #{p}"
end
end
def test_large
[61,65,88].each do |p|
assert_equal 96 , @pad.padded(p) , "Expecting 96 for #{p}"
assert_equal 96 , Padding.padded(p) , "Expecting 96 for #{p}"
end
end
end