mostly renames from the type change

also making setters as explicit set_xx methods
This commit is contained in:
Torsten Ruger 2016-12-29 18:45:32 +02:00
parent f4b3c645e5
commit b5f04ec718
11 changed files with 42 additions and 30 deletions

View File

@ -8,7 +8,7 @@ module Register
def __init__ context def __init__ context
compiler = Typed::MethodCompiler.new.create_method(:Kernel,:__init__ ) compiler = Typed::MethodCompiler.new.create_method(:Kernel,:__init__ )
new_start = Register.label("__init__ start" , "__init__" ) new_start = Register.label("__init__ start" , "__init__" )
compiler.method.instructions = new_start compiler.method.set_instructions( new_start)
compiler.set_current new_start compiler.set_current new_start
space = Parfait::Space.object_space space = Parfait::Space.object_space

View File

@ -21,7 +21,7 @@ module Register
type = object.get_type type = object.get_type
keep(type , depth + 1) keep(type , depth + 1)
return if object.is_a? Symbol return if object.is_a? Symbol
type.instance_names.each do |name| type.names.each do |name|
#puts "Keep #{name} for #{object.class}" #puts "Keep #{name} for #{object.class}"
inst = object.get_instance_variable name inst = object.get_instance_variable name
keep(inst , depth + 1) keep(inst , depth + 1)

View File

@ -88,7 +88,7 @@ module Register
clazz = Parfait::Space.object_space.get_class_by_name(real_name) clazz = Parfait::Space.object_space.get_class_by_name(real_name)
raise "Class name not given #{real_name}" unless clazz raise "Class name not given #{real_name}" unless clazz
index = clazz.instance_type.variable_index( instance_name ) index = clazz.instance_type.variable_index( instance_name )
raise "Instance name=#{instance_name} not found on #{real_name}" unless index.is_a?(Numeric) raise "Instance name=#{instance_name} not found on #{real_name}:#{clazz.instance_type}" unless index.is_a?(Numeric)
return index # the type word is at index 0, but type is a list and starts at 1 == type return index # the type word is at index 0, but type is a list and starts at 1 == type
end end

View File

@ -133,7 +133,7 @@ module Typed
def init_method def init_method
source = "_init_method" source = "_init_method"
name = "#{method.for_type.name}.#{method.name}" name = "#{method.for_type.name}.#{method.name}"
@method.instructions = Register.label(source, name) @method.set_instructions( Register.label(source, name))
@current = enter = method.instructions @current = enter = method.instructions
add_label( source, "return #{name}") add_label( source, "return #{name}")
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm) #load the return address into pc, affecting return. (other cpus have commands for this, but not arm)

View File

@ -30,7 +30,7 @@ module Melon
def test_compile_class def test_compile_class
Compiler.compile "class TestIvar < Object ; def meth; @ivar;end; end" Compiler.compile "class TestIvar < Object ; def meth; @ivar;end; end"
itest = Parfait::Space.object_space.get_class_by_name(:TestIvar) itest = Parfait::Space.object_space.get_class_by_name(:TestIvar)
assert itest.instance_type.instance_names.include?(:ivar) , itest.instance_type.instance_names.inspect assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect
end end
end end

View File

@ -10,18 +10,15 @@ class TestPositioning < MiniTest::Test
end end
def test_list1 def test_list1
list = Parfait.new_list([1]) list = Parfait.new_list([1])
list.set_type( Parfait::Type.new Object)
assert_equal 32 , list.padded_length assert_equal 32 , list.padded_length
end end
def test_list5 def test_list5
list = Parfait.new_list([1,2,3,4,5]) list = Parfait.new_list([1,2,3,4,5])
list.set_type( Parfait::Type.new Object)
assert_equal 32 , list.padded_length assert_equal 32 , list.padded_length
end end
def test_type def test_type
type = Parfait::Type.new Object type = Parfait::Type.new Parfait::Space.object_space.get_class_by_name(:Object)
type.set_type( Parfait::Type.new Object) type.set_type( type )
type.push 5
assert_equal 32 , type.padded_length assert_equal 32 , type.padded_length
end end
def test_word def test_word

View File

@ -11,7 +11,7 @@ class TestMessage < MiniTest::Test
end end
def test_attribute_set def test_attribute_set
@mess.receiver = 55 @mess.set_receiver( 55)
assert_equal 55 , @mess.receiver assert_equal 55 , @mess.receiver
end end
@ -19,4 +19,7 @@ class TestMessage < MiniTest::Test
assert_equal 9 , @mess.get_type.variable_index(:arguments) assert_equal 9 , @mess.get_type.variable_index(:arguments)
end end
def test_next
assert @mess.next_message
end
end end

View File

@ -9,7 +9,7 @@ class TestNamedLists < MiniTest::Test
def test_named_list_get_type def test_named_list_get_type
assert_equal Parfait::Type , @type.class assert_equal Parfait::Type , @type.class
assert @type.instance_names assert @type.names
assert @named_list.get_instance_variables assert @named_list.get_instance_variables
end end

View File

@ -4,7 +4,7 @@ class TestMethod < MiniTest::Test
def setup def setup
obj = Register.machine.space.get_class_by_name(:Object).instance_type obj = Register.machine.space.get_class_by_name(:Object).instance_type
args = Parfait::Type.for_hash( obj , { bar: :Integer , foo: :Type}) args = Parfait::Type.for_hash( obj.object_class , { bar: :Integer , foo: :Type})
@method = ::Parfait::TypedMethod.new obj , :meth , args @method = ::Parfait::TypedMethod.new obj , :meth , args
@method.add_local :local_bar , :Integer @method.add_local :local_bar , :Integer
@method.add_local :local_foo , :Type @method.add_local :local_foo , :Type
@ -20,7 +20,7 @@ class TestMethod < MiniTest::Test
def test_arg1 def test_arg1
assert_equal 2 , @method.arguments_length , @method.arguments.inspect assert_equal 2 , @method.arguments_length , @method.arguments.inspect
assert_equal Symbol , @method.arguments.first.class assert_equal Symbol , @method.arguments.names.first.class
assert_equal :bar , @method.argument_name(1) assert_equal :bar , @method.argument_name(1)
end end
@ -57,7 +57,7 @@ class TestMethod < MiniTest::Test
def test_local1 def test_local1
assert_equal 2 , @method.locals_length , @method.locals.inspect assert_equal 2 , @method.locals_length , @method.locals.inspect
assert_equal Symbol , @method.locals.first.class assert_equal Symbol , @method.locals.names.first.class
assert_equal :local_bar , @method.locals_name(1) assert_equal :local_bar , @method.locals_name(1)
end end

View File

@ -21,7 +21,7 @@ class TypeMessages < MiniTest::Test
end end
def test_type_methods def test_type_methods
assert_equal 3 , @mess.get_type.get_type.variable_index(:instance_methods) assert_equal 5 , @mess.get_type.get_type.variable_index(:instance_methods)
end end
end end

View File

@ -16,8 +16,8 @@ class TypeApi < MiniTest::Test
assert_equal Parfait::Class , oc.class assert_equal Parfait::Class , oc.class
type = oc.instance_type type = oc.instance_type
assert_equal Parfait::Type , type.class assert_equal Parfait::Type , type.class
assert_equal 1 , type.instance_names.get_length , type.instance_names.inspect assert_equal 1 , type.names.get_length , type.names.inspect
assert_equal type.first , :type assert_equal type.names.first , :type
end end
def test_class_space def test_class_space
@ -25,20 +25,22 @@ class TypeApi < MiniTest::Test
assert_equal Parfait::Space , space.class assert_equal Parfait::Space , space.class
type = space.get_type type = space.get_type
assert_equal Parfait::Type , type.class assert_equal Parfait::Type , type.class
assert_equal 4 , type.instance_names.get_length assert_equal 4 , type.names.get_length
assert_equal type.object_class.class , Parfait::Class assert_equal type.object_class.class , Parfait::Class
assert_equal type.object_class.name , :Space assert_equal type.object_class.name , :Space
end end
def test_add_name def test_add_name
@type.add_instance_variable( :boo , :Object) t = @type.add_instance_variable( :boo , :Object)
assert t
t
end end
def test_added_name_length def test_added_name_length
type = test_add_name type = test_add_name
assert_equal 4 , type.get_length , type.inspect assert_equal 2 , type.names.get_length , type.inspect
assert_equal :type , type.get(1) assert_equal :type , type.names.get(1)
assert_equal :boo , type.get(3) assert_equal :boo , type.names.get(2)
end end
def test_added_name_index def test_added_name_index
@ -61,16 +63,26 @@ class TypeApi < MiniTest::Test
def test_added_names def test_added_names
type = test_add_name type = test_add_name
assert_equal :type , type.instance_names.get(1) assert_equal :type , type.names.get(1)
assert_equal :boo , type.instance_names.get(2) assert_equal :boo , type.names.get(2)
assert_equal 2 , type.instance_names.get_length assert_equal 2 , type.names.get_length
end end
def test_each def test_each_name
type = test_add_name type = test_add_name
assert_equal 4 , type.get_length assert_equal 2 , type.get_length
counter = [ :boo , :Object , :type , :Type] counter = [ :boo , :type ]
type.each do |item| type.names.each do |item|
assert_equal item , counter.delete(item)
end
assert counter.empty? , counter.inspect
end
def test_each_type
type = test_add_name
assert_equal 2 , type.get_length
counter = [ :Object , :Type]
type.types.each do |item|
assert_equal item , counter.delete(item) assert_equal item , counter.delete(item)
end end
assert counter.empty? , counter.inspect assert counter.empty? , counter.inspect