diff --git a/lib/arm/translator.rb b/lib/arm/translator.rb index 5d24ae71..76e1c841 100644 --- a/lib/arm/translator.rb +++ b/lib/arm/translator.rb @@ -69,7 +69,7 @@ module Arm ArmMachine.mov( :pc , code.register) end def translate_DynamicJump(code) - index = Parfait.object_space.get_class_by_name(:CallableMethod).instance_type.variable_index(:binary) + index = Parfait.object_space.get_type_by_class_name(:CallableMethod).variable_index(:binary) codes = ArmMachine.ldr( code.register , code.register , arm_index(index) ) codes << ArmMachine.mov( :pc , code.register) codes diff --git a/lib/mom/instruction/basic_values.rb b/lib/mom/instruction/basic_values.rb index efd62ba9..0c697207 100644 --- a/lib/mom/instruction/basic_values.rb +++ b/lib/mom/instruction/basic_values.rb @@ -27,7 +27,7 @@ module Mom value end def ct_type - Parfait.object_space.get_class_by_name(:Integer).instance_type + Parfait.object_space.get_type_by_class_name(:Integer) end end class FloatConstant < Constant @@ -44,7 +44,7 @@ module Mom Parfait.object_space.true_object end def ct_type - Parfait.object_space.get_class_by_name(:TrueClass).instance_type + Parfait.object_space.get_type_by_class_name(:TrueClass) end end class FalseConstant < Constant @@ -52,7 +52,7 @@ module Mom Parfait.object_space.false_object end def ct_type - Parfait.object_space.get_class_by_name(:FalseClass).instance_type + Parfait.object_space.get_type_by_class_name(:FalseClass) end end class NilConstant < Constant @@ -60,7 +60,7 @@ module Mom Parfait.object_space.nil_object end def ct_type - Parfait.object_space.get_class_by_name(:NilClass).instance_type + Parfait.object_space.get_type_by_class_name(:NilClass) end end class StringConstant < Constant @@ -74,12 +74,12 @@ module Mom value end def ct_type - Parfait.object_space.get_class_by_name(:Word).instance_type + Parfait.object_space.get_type_by_class_name(:Word) end end class SymbolConstant < Constant def ct_type - Parfait.object_space.get_class_by_name(:Word).instance_type + Parfait.object_space.get_type_by_class_name(:Word) end end end diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 67e7c36e..b3410c61 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -113,6 +113,11 @@ module Parfait object.instance_type.get_method :__init__ end + # get the current instance_typ of the class with the given name + def get_type_by_class_name(name) + get_class_by_name(name).instance_type + end + # get a class by name (symbol) # return nili if no such class. Use bang version if create should be implicit def get_class_by_name( name ) @@ -137,7 +142,7 @@ module Parfait raise "create_class #{name.class}" unless name.is_a? Symbol superclass = :Object unless superclass raise "create_class #{superclass.class}" unless superclass.is_a? Symbol - type = get_class_by_name(superclass).instance_type + type = get_type_by_class_name(superclass) c = Class.new(name , superclass , type ) @classes[name] = c end diff --git a/lib/risc/builtin.rb b/lib/risc/builtin.rb index 9d5594fc..b9c48b36 100644 --- a/lib/risc/builtin.rb +++ b/lib/risc/builtin.rb @@ -24,18 +24,18 @@ module Risc compilers << compiler_for( space_type , Space , :main) end - obj_type = space.get_class_by_name(:Object).instance_type + obj_type = space.get_type_by_class_name(:Object) [ :get_internal_word , :set_internal_word , :_method_missing, :exit , :__init__].each do |f| compilers << compiler_for( obj_type , Object , f) end - word_type = space.get_class_by_name(:Word).instance_type + word_type = space.get_type_by_class_name(:Word) [:putstring , :get_internal_byte , :set_internal_byte ].each do |f| compilers << compiler_for( word_type , Word , f) end - int_type = space.get_class_by_name(:Integer).instance_type + int_type = space.get_type_by_class_name(:Integer) Risc.operators.each do |op| compilers << operator_compiler( int_type , op) end diff --git a/lib/vool/basic_values.rb b/lib/vool/basic_values.rb index a77b994d..ebe07aff 100644 --- a/lib/vool/basic_values.rb +++ b/lib/vool/basic_values.rb @@ -14,7 +14,7 @@ module Vool return Mom::SlotDefinition.new(Mom::IntegerConstant.new(@value) , []) end def ct_type - Parfait.object_space.get_class_by_name(:Integer).instance_type + Parfait.object_space.get_type_by_class_name(:Integer) end def to_s value.to_s @@ -33,7 +33,7 @@ module Vool end class TrueConstant < Constant def ct_type - Parfait.object_space.get_class_by_name(:True).instance_type + Parfait.object_space.get_type_by_class_name(:True) end def slot_definition(compiler) return Mom::SlotDefinition.new(Parfait.object_space.true_object , []) @@ -44,7 +44,7 @@ module Vool end class FalseConstant < Constant def ct_type - Parfait.object_space.get_class_by_name(:False).instance_type + Parfait.object_space.get_type_by_class_name(:False) end def slot_definition(compiler) return Mom::SlotDefinition.new(Parfait.object_space.false_object , []) @@ -55,7 +55,7 @@ module Vool end class NilConstant < Constant def ct_type - Parfait.object_space.get_class_by_name(:Nil).instance_type + Parfait.object_space.get_type_by_class_name(:Nil) end def slot_definition(compiler) return Mom::SlotDefinition.new(Parfait.object_space.nil_object , []) @@ -94,7 +94,7 @@ module Vool return Mom::SlotDefinition.new(Mom::StringConstant.new(@value),[]) end def ct_type - Parfait.object_space.get_class_by_name(:Word).instance_type + Parfait.object_space.get_type_by_class_name(:Word) end def to_s(depth = 0) "'#{@value}'" @@ -102,7 +102,7 @@ module Vool end class SymbolConstant < StringConstant def ct_type - Parfait.object_space.get_class_by_name(:Word).instance_type + Parfait.object_space.get_type_by_class_name(:Word) end end end diff --git a/test/mom/helper.rb b/test/mom/helper.rb index ead749b5..efec686c 100644 --- a/test/mom/helper.rb +++ b/test/mom/helper.rb @@ -16,7 +16,7 @@ module Risc end # test hack to in place change object type def add_space_field(name,type) - class_type = Parfait.object_space.get_class_by_name(:Space).instance_type + class_type = Parfait.object_space.get_type_by_class_name(:Space) class_type.send(:private_add_instance_variable, name , type) end def produce_body diff --git a/test/parfait/helper.rb b/test/parfait/helper.rb index d732fb05..3fc7df0e 100644 --- a/test/parfait/helper.rb +++ b/test/parfait/helper.rb @@ -8,7 +8,7 @@ module Parfait @space = Parfait.object_space end def make_method - @obj = Parfait.object_space.get_class_by_name(:Object).instance_type + @obj = Parfait.object_space.get_type_by_class_name(:Object) @args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type}) @frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type}) @method = Parfait::CallableMethod.new( @obj , :meth , @args , @frame) diff --git a/test/parfait/type/test_method_api.rb b/test/parfait/type/test_method_api.rb index dbb497dd..a194fb8d 100644 --- a/test/parfait/type/test_method_api.rb +++ b/test/parfait/type/test_method_api.rb @@ -14,15 +14,15 @@ module Parfait end def foo_method( for_class = :Try) args = Parfait::Type.for_hash( @try_class , { bar: :Integer}) - ::Parfait::CallableMethod.new( @space.get_class_by_name(for_class).instance_type , :foo , args,empty_frame) + ::Parfait::CallableMethod.new( @space.get_type_by_class_name(for_class) , :foo , args,empty_frame) end def add_foo_to( clazz = :Try ) foo = foo_method( clazz ) - assert_equal foo , @space.get_class_by_name(clazz).instance_type.add_method(foo) + assert_equal foo , @space.get_type_by_class_name(clazz).add_method(foo) foo end def object_type - @space.get_class_by_name(:Object).instance_type + @space.get_type_by_class_name(:Object) end def test_new_methods assert_equal Parfait::List , @try_type.method_names.class @@ -59,7 +59,7 @@ module Parfait end def test_get_instance foo = foo_method :Object - type = @space.get_class_by_name(:Object).instance_type + type = @space.get_type_by_class_name(:Object) type.add_method(foo) assert_equal :foo , type.get_method(:foo).name end diff --git a/test/rubyx/test_rubyx_compiler.rb b/test/rubyx/test_rubyx_compiler.rb index c2d6e85d..33bce242 100644 --- a/test/rubyx/test_rubyx_compiler.rb +++ b/test/rubyx/test_rubyx_compiler.rb @@ -36,9 +36,9 @@ module RubyX end def test_space_type_is_unchanged_by_compile - space1 = Parfait.object_space.get_class_by_name(:Space).instance_type + space1 = Parfait.object_space.get_type_by_class_name(:Space) ruby_to_vool "class Space ;end" - space2 = Parfait.object_space.get_class_by_name(:Space).instance_type + space2 = Parfait.object_space.get_type_by_class_name(:Space) assert_equal space1 , space2 end diff --git a/test/rubyx/test_rubyx_compiler1.rb b/test/rubyx/test_rubyx_compiler1.rb index ee2e7e11..c2f5d920 100644 --- a/test/rubyx/test_rubyx_compiler1.rb +++ b/test/rubyx/test_rubyx_compiler1.rb @@ -25,9 +25,9 @@ module RubyX end def test_space_type_is_unchanged_by_compile - space1 = Parfait.object_space.get_class_by_name(:Space).instance_type + space1 = Parfait.object_space.get_type_by_class_name(:Space) ruby_to_vool "class Space ;end" - space2 = Parfait.object_space.get_class_by_name(:Space).instance_type + space2 = Parfait.object_space.get_type_by_class_name(:Space) assert_equal space1 , space2 end