fixed simple layout offset bug in layout

This commit is contained in:
Torsten Ruger 2015-10-13 14:46:07 +03:00
parent aa20f2ca77
commit 80d58ee03c
9 changed files with 132 additions and 17 deletions

View File

@ -34,7 +34,12 @@ module Parfait
def sof_reference_name def sof_reference_name
name name
end end
def inspect
"Class(#{name})"
end
# ruby 2.1 list (just for reference, keep at bottom) # ruby 2.1 list (just for reference, keep at bottom)
#:allocate, :new, :superclass #:allocate, :new, :superclass
end end
end end

View File

@ -40,6 +40,7 @@ module Parfait
# TODO , later we would need to COPY the layout to keep the old constant # TODO , later we would need to COPY the layout to keep the old constant
# but now we are concerned with booting, ie getting a working structure # but now we are concerned with booting, ie getting a working structure
def add_instance_variable name def add_instance_variable name
self.push(1) if self.get_length == 0
self.push(name) self.push(name)
self.get_length self.get_length
end end
@ -51,7 +52,7 @@ module Parfait
def object_instance_names def object_instance_names
names = List.new names = List.new
index = 2 # first is object_class index = 3
while index <= self.get_length while index <= self.get_length
item = get(index) item = get(index)
names.push item names.push item
@ -74,6 +75,19 @@ module Parfait
list_index(name) list_index(name)
end end
def inspect
ret = "Layout["
index = 3
while index <= self.get_length
item = get(index)
ret += item.inspect
ret += "," unless index == self.get_length
index = index + 1
end
ret += "]"
ret
end
def sof_reference_name def sof_reference_name
"#{self.object_class.name}_Layout" "#{self.object_class.name}_Layout"
end end

View File

@ -69,6 +69,11 @@ module Parfait
get(1) get(1)
end end
def last
return nil if empty?
get(get_length())
end
# set the value at index. # set the value at index.
# Lists start from index 1 # Lists start from index 1
def set( index , value) def set( index , value)

View File

@ -1,6 +1,8 @@
require_relative "test_layout"
require_relative "test_space" require_relative "test_space"
require_relative "test_object" require_relative "test_object"
require_relative "test_list" require_relative "test_list"
require_relative "test_word" require_relative "test_word"
require_relative "test_dictionary" require_relative "test_dictionary"
require_relative "test_method" require_relative "test_method"
require_relative "test_attributes"

View File

@ -0,0 +1,49 @@
require_relative "../helper"
class TestAttributes < MiniTest::Test
def setup
@mess = Virtual.machine.boot.space.first_message
@layout = @mess.get_layout
end
def test_message_get_layout
assert_equal Parfait::Layout , @layout.class
end
def test_message_layout_first
@layout.object_class = :next_message
assert_equal :next_message , @layout.object_instance_names.first
assert_equal :next_message , @layout.object_class
end
def test_message_name_nil
last = @layout.object_instance_names.last
assert_equal :name , last
assert_equal nil , @mess.name
end
def test_message_next_set
@mess.next_message = :next_message
assert_equal :next_message , @mess.next_message
end
def test_message_layout_set
@mess.set_layout :layout
assert_equal :layout , @mess.get_layout
end
def test_attribute_index
@mess.next_message = :message
assert_equal Parfait::Layout , @mess.get_layout.class
end
def test_layout_attribute
@layout.object_class = :message
assert_equal :message , @layout.object_class
end
def test_layout_attribute_check
@layout.object_class = :message
assert_equal Parfait::Layout , @layout.get_layout.class
end
def test_layout_layout
assert_equal Parfait::Layout , @layout.get_layout.get_layout.class
end
def test_layout_layout_layout
assert_equal Parfait::Layout , @layout.get_layout.get_layout.get_layout.class
end
end

View File

@ -16,7 +16,7 @@ class TestLayout < MiniTest::Test
def test_message_by_index def test_message_by_index
assert_equal @mess.next_message , @mess.get_instance_variable(:next_message) assert_equal @mess.next_message , @mess.get_instance_variable(:next_message)
index = @mess.get_layout.variable_index :next_message index = @mess.get_layout.variable_index :next_message
assert_equal 2 , index assert_equal 3 , index
assert_equal @mess.next_message , @mess.internal_object_get(index) assert_equal @mess.next_message , @mess.internal_object_get(index)
end end
@ -24,13 +24,26 @@ class TestLayout < MiniTest::Test
assert_equal @mess.get_layout , @mess.internal_object_get(1) , "mess" assert_equal @mess.get_layout , @mess.internal_object_get(1) , "mess"
end end
def test_no_index_below_2 def test_layout_is_first
layout = @mess.get_layout
assert_equal nil , layout.variable_index(:layout)
end
def test_no_index_below_1
layout = @mess.get_layout layout = @mess.get_layout
names = layout.object_instance_names names = layout.object_instance_names
assert_equal 7 , names.get_length assert_equal 7 , names.get_length , names.inspect
names.each do |n| names.each do |n|
assert layout.variable_index(n) > 1 assert layout.variable_index(n) >= 1
end end
end end
def test_class_layout
oc = Virtual.machine.boot.space.get_class_by_name( :Object )
assert_equal Parfait::Class , oc.class
layout = oc.object_layout
assert_equal Parfait::Layout , layout.class
assert_equal layout.object_instance_names.get_length , 0
#assert_equal layout.first , :layout
end
end end

View File

@ -3,8 +3,33 @@ require_relative "../helper"
class TestList < MiniTest::Test class TestList < MiniTest::Test
def setup def setup
Virtual.machine.boot unless Virtual.machine.booted
@list = ::Parfait::List.new @list = ::Parfait::List.new
end end
def test_old_layout
assert_equal Parfait::Layout , Virtual.machine.space.classes.keys.get_layout.class
end
def test_old_layout_push
list = Virtual.machine.space.classes.keys
list.push(1)
assert_equal Parfait::Layout , list.get_layout.class
end
def test_new_layout
assert_equal Parfait::Layout , @list.get_layout.class
end
def test_new_layout_push
@list.push(1)
assert_equal Parfait::Layout , @list.get_layout.class
end
def notest_layout_is_first
layout = @list.get_layout
assert_equal 1 , layout.variable_index(:layout)
end
def notest_layout_is_first_old
layout = Virtual.machine.space.classes.keys.get_layout
assert_equal 1 , layout.variable_index(:layout)
end
def test_list_inspect def test_list_inspect
@list.set(1,1) @list.set(1,1)
assert_equal "1" , @list.inspect assert_equal "1" , @list.inspect
@ -97,4 +122,11 @@ class TestList < MiniTest::Test
def test_first_empty def test_first_empty
assert_equal nil , @list.first assert_equal nil , @list.first
end end
def test_last
test_many_get
assert_equal :three , @list.last
end
def test_last_empty
assert_equal nil , @list.last
end
end end

View File

@ -6,7 +6,7 @@ class TestSpace < MiniTest::Test
@machine = Virtual.machine.boot @machine = Virtual.machine.boot
end end
def classes def classes
[:Kernel,:Word,:List,:Message,:Frame,:Layout,:Class,:Dictionary,:Method , :Integer] [:Kernel,:Word,:List,:Message,:Frame,:Layout,:Object,:Class,:Dictionary,:Method , :Integer]
end end
def test_booted def test_booted
assert_equal true , @machine.booted assert_equal true , @machine.booted
@ -17,40 +17,35 @@ class TestSpace < MiniTest::Test
def test_global_space def test_global_space
assert_equal Parfait::Space , Parfait::Space.object_space.class assert_equal Parfait::Space , Parfait::Space.object_space.class
end end
def test_intger def test_integer
int = Parfait::Space.object_space.get_class_by_name :Integer int = Parfait::Space.object_space.get_class_by_name :Integer
assert_equal 3, int.method_names.get_length assert_equal 3, int.method_names.get_length
assert int.get_instance_method( :plus ) assert int.get_instance_method( :plus )
end end
def test_classes_class
classes.each do |name|
assert_equal :Class , @machine.space.classes[name].get_class.name
assert_equal Parfait::Class , @machine.space.classes[name].class
assert_equal Parfait::Layout , @machine.space.classes[name].get_layout.class
assert_equal name , @machine.space.classes[name].get_class.name
end
end
def test_classes_class def test_classes_class
classes.each do |name| classes.each do |name|
assert_equal :Class , @machine.space.classes[name].get_class.name assert_equal :Class , @machine.space.classes[name].get_class.name
assert_equal Parfait::Class , @machine.space.classes[name].class assert_equal Parfait::Class , @machine.space.classes[name].class
end end
end end
def test_classes_layout def test_classes_layout
classes.each do |name| classes.each do |name|
assert_equal Parfait::Layout , @machine.space.classes[name].get_layout.class assert_equal Parfait::Layout , @machine.space.classes[name].get_layout.class
end end
end end
def test_classes_name def test_classes_name
classes.each do |name| classes.each do |name|
assert_equal name , @machine.space.classes[name].name assert_equal name , @machine.space.classes[name].name
end end
end end
def test_method_name def test_method_name
classes.each do |name| classes.each do |name|
cl = @machine.space.classes[name] cl = @machine.space.classes[name]
cl.method_names.each do |mname| cl.method_names.each do |mname|
#puts "Mehtod #{mname}"
method = cl.get_instance_method(mname) method = cl.get_instance_method(mname)
assert_equal mname , method.name assert_equal mname , method.name
assert_equal name , method.for_class.name assert_equal name , method.for_class.name