diff --git a/lib/parfait/list.rb b/lib/parfait/list.rb index 33c80412..686bc4e2 100644 --- a/lib/parfait/list.rb +++ b/lib/parfait/list.rb @@ -175,7 +175,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 - Padding.padded_words( get_type().instance_length + get_length() ) + Object.padded_words( get_type().instance_length + get_length() ) end def each diff --git a/lib/parfait/object.rb b/lib/parfait/object.rb index 1a698ee2..f107d393 100644 --- a/lib/parfait/object.rb +++ b/lib/parfait/object.rb @@ -68,8 +68,20 @@ type.variable_index(name) end + # 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 self.padded( len ) + a = 32 * (1 + ((len + 3)/32).floor ) + #puts "#{a} for #{len}" + a + end + + def self.padded_words( words ) + padded(words*4) # 4 == word length, a constant waiting for a home + end + def padded_length - Padding.padded_words( type.instance_length ) + Object.padded_words( type.instance_length ) end # parfait versions are deliberately called different, so we "relay" diff --git a/lib/parfait/object2.rb b/lib/parfait/object2.rb deleted file mode 100644 index a450c825..00000000 --- a/lib/parfait/object2.rb +++ /dev/null @@ -1,93 +0,0 @@ -# From a programmers perspective an object has hash like data (with instance variables as keys) -# and functions to work on that data. -# Only the object may access it's data directly. - -# From an implementation perspective it is a chunk of memory with a type as the first -# word (instance of class Type). - -# Objects are arranged or layed out (in memory) according to their Type -# every object has a Type. Type objects are immutable and may be reused for a group/class -# of objects. -# The Type of an object may change, but then a new Type is created -# The Type also defines the class of the object -# The Type is **always** the first entry (index 0) in an object - - - class Object - attr :type - - def == other - o_id = other.object_id - m_id = self.object_id - ok = m_id == o_id - return ok -# self.object_id == other.object_id - end - - # This is the core of the object system. - # The class of an object is stored in the objects memory - # - # In RubyX we store the class in the Type, and so the Type is the only fixed - # data that every object carries. - def get_class() - l = get_type() - #puts "Type #{l.class} in #{self.class} , #{self}" - l.object_class() - end - - # private - def set_type(typ) - raise "not type" + typ.class.to_s + "in " + object_id.to_s(16) unless typ.is_a?(Type) - self.type = typ - end - - # so we can keep the raise in get_type - def has_type? - ! type.nil? - end - - def get_type() - raise "No type " + self.object_id.to_s(16) + ":" + self.class.name unless has_type? - type - end - - def get_instance_variables - type.names - end - - def get_instance_variable( name ) - index = instance_variable_defined(name) - #puts "getting #{name} at #{index}" - return nil if index == nil - return get_internal_word(index) - end - - def set_instance_variable( name , value ) - index = instance_variable_defined(name) - return nil if index == nil - return set_internal_word(index , value) - end - - def instance_variable_defined( name ) - type.variable_index(name) - end - - def padded_length - Padding.padded_words( type.instance_length ) - end - - # parfait versions are deliberately called different, so we "relay" - # have to put the "" on the names for rfx to take them off again - def instance_variables - get_instance_variables.to_a.collect{ |n| n.to_s.to_sym } - end - - # name comes in as a ruby var name - def instance_variable_ged( name ) - #TODO the [] shoud be a range, but currenly that is not processed in RubyCompiler - var = get_instance_variable name.to_s[1 , name.to_s.length - 1].to_sym - #puts "getting #{name} #{var}" - var - end - - end diff --git a/lib/parfait/word.rb b/lib/parfait/word.rb index 8cf81baa..ad92965a 100644 --- a/lib/parfait/word.rb +++ b/lib/parfait/word.rb @@ -183,7 +183,7 @@ module Parfait end def padded_length - Padding.padded( 4 * get_type().instance_length + char_length ) + Object.padded( 4 * get_type().instance_length + char_length ) end private diff --git a/lib/risc.rb b/lib/risc.rb index 65ab5c54..e2a4c31c 100644 --- a/lib/risc.rb +++ b/lib/risc.rb @@ -20,7 +20,6 @@ module Risc end end -require_relative "risc/padding" require_relative "risc/position/position" require_relative "risc/platform" require_relative "risc/parfait_boot" diff --git a/lib/risc/padding.rb b/lib/risc/padding.rb deleted file mode 100644 index 37205b34..00000000 --- a/lib/risc/padding.rb +++ /dev/null @@ -1,22 +0,0 @@ -# Helper functions to pad memory. -# -# Meory is always in lines, chunks of 8 words / 32 bytes -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 self.padded( len ) - a = 32 * (1 + ((len + 3)/32).floor ) - #puts "#{a} for #{len}" - a - end - - def self.padded_words( words ) - padded(words*4) # 4 == word length, a constant waiting for a home - end - - def self.padding_for( length ) - pad = padded(length) - length # for header, type - pad - end -end diff --git a/lib/risc/parfait_adapter.rb b/lib/risc/parfait_adapter.rb index b22cee2a..c1434752 100644 --- a/lib/risc/parfait_adapter.rb +++ b/lib/risc/parfait_adapter.rb @@ -99,7 +99,7 @@ class Symbol l end def padded_length - Padding.padded( to_s.length + 4) + Parfait::Object.padded( to_s.length + 4) end end diff --git a/lib/risc/text_writer.rb b/lib/risc/text_writer.rb index c3e7686d..cf1600a5 100644 --- a/lib/risc/text_writer.rb +++ b/lib/risc/text_writer.rb @@ -216,7 +216,7 @@ module Risc # 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.padding_for(length) + pad = Parfait::Object.padded(length) - length # for header, type pad.times do @stream.write_unsigned_int_8(0) end diff --git a/test/risc/test_padding.rb b/test/parfait/test_object2.rb similarity index 75% rename from test/risc/test_padding.rb rename to test/parfait/test_object2.rb index 1144a446..180d7dc3 100644 --- a/test/risc/test_padding.rb +++ b/test/parfait/test_object2.rb @@ -1,6 +1,6 @@ -require_relative "../helper" +require_relative "helper" -module Risc +module Parfait class TestPadding < MiniTest::Test def setup @@ -9,18 +9,18 @@ module Risc def test_small [6,27,28].each do |p| - assert_equal 32 , Padding.padded(p) , "Expecting 32 for #{p}" + assert_equal 32 , Parfait::Object.padded(p) , "Expecting 32 for #{p}" end end def test_medium [29,33,40,57,60].each do |p| - assert_equal 64 , Padding.padded(p) , "Expecting 64 for #{p}" + assert_equal 64 , Parfait::Object.padded(p) , "Expecting 64 for #{p}" end end def test_large [61,65,88].each do |p| - assert_equal 96 , Padding.padded(p) , "Expecting 96 for #{p}" + assert_equal 96 , Parfait::Object.padded(p) , "Expecting 96 for #{p}" end end def test_list1