diff --git a/lib/parfait/typed_method.rb b/lib/parfait/typed_method.rb index 370ce96c..4dcae2f8 100644 --- a/lib/parfait/typed_method.rb +++ b/lib/parfait/typed_method.rb @@ -62,28 +62,6 @@ module Parfait @cpu_instructions end - # determine whether this method has an argument by the name - def has_argument( name ) - raise "has_argument #{name}.#{name.class}" unless name.is_a? Symbol - index = arguments_type.variable_index( name ) - index ? (index - 1) : index - end - - def add_argument(name , type) - @arguments_type = @arguments_type.add_instance_variable(name,type) - end - - def arguments_length - arguments_type.instance_length - 1 - end - - def argument_name( index ) - arguments_type.names.get(index + 1) - end - def argument_type( index ) - arguments_type.types.get(index + 1) - end - # determine if method has a local variable or tmp (anonymous local) by given name def has_local( name ) raise "has_local #{name}.#{name.class}" unless name.is_a? Symbol diff --git a/test/parfait/test_typed_method.rb b/test/parfait/test_typed_method.rb index 06542ccd..47060a71 100644 --- a/test/parfait/test_typed_method.rb +++ b/test/parfait/test_typed_method.rb @@ -20,40 +20,40 @@ module Parfait end def test_arg1 - assert_equal 2 , @method.arguments_length , @method.arguments_type.inspect + assert_equal 3 , @method.arguments_type.get_length , @method.arguments_type.inspect assert_equal Symbol , @method.arguments_type.names.first.class - assert_equal :bar , @method.argument_name(0) + assert_equal :bar , @method.arguments_type.name_at(1) end def test_has_argument - assert_equal 0 , @method.has_argument(:bar) - assert_equal 1 , @method.has_argument(:foo) + assert_equal 1 , @method.arguments_type.variable_index(:bar) + assert_equal 2 , @method.arguments_type.variable_index(:foo) end def test_add_arg - @method.add_argument(:foo2 , :Object) - assert_equal 3 , @method.arguments_length - assert_equal :foo2 , @method.argument_name(2) - assert_equal :Object , @method.argument_type(2) + @method.arguments_type.send( :private_add_instance_variable, :foo2 , :Object) + assert_equal 4 , @method.arguments_type.get_length + assert_equal :foo2 , @method.arguments_type.name_at(3) + assert_equal :Object , @method.arguments_type.type_at(3) end def test_get_arg_name1 - index = @method.has_argument(:bar) - assert_equal 0 , index - assert_equal :bar , @method.argument_name(index) + index = @method.arguments_type.variable_index(:bar) + assert_equal 1 , index + assert_equal :bar , @method.arguments_type.name_at(index) end def test_get_arg_type1 - index = @method.has_argument(:bar) - assert_equal :Integer , @method.argument_type(index) + index = @method.arguments_type.variable_index(:bar) + assert_equal :Integer , @method.arguments_type.type_at(index) end def test_get_arg_name2 - index = @method.has_argument(:foo) - assert_equal 1 , index - assert_equal :foo , @method.argument_name(index) + index = @method.arguments_type.variable_index(:foo) + assert_equal 2 , index + assert_equal :foo , @method.arguments_type.name_at(index) end def test_get_arg_type2 - index = @method.has_argument(:foo) - assert_equal :Type , @method.argument_type(index) + index = @method.arguments_type.variable_index(:foo) + assert_equal :Type , @method.arguments_type.type_at(index) end def test_local1 diff --git a/test/vool/compilers/test_method_compiler.rb b/test/vool/compilers/test_method_compiler.rb index b252f1f0..0991eead 100644 --- a/test/vool/compilers/test_method_compiler.rb +++ b/test/vool/compilers/test_method_compiler.rb @@ -54,8 +54,8 @@ module Vool VoolCompiler.ruby_to_vool in_Test("def meth; @ivar = 5; @ibar = 4;end") test = Parfait.object_space.get_class_by_name(:Test) method = test.instance_type.get_method(:meth) - assert_equal 2, method.for_type.variable_index(:ivar) - assert_equal 3, method.for_type.variable_index(:ibar) + assert_equal 1, method.for_type.variable_index(:ivar) + assert_equal 2, method.for_type.variable_index(:ibar) end def test_vool_method_has_one_local @@ -63,7 +63,8 @@ module Vool test = Parfait.object_space.get_class_by_name(:Test) method = test.get_method(:meth) assert_equal 3 , method.frame_type.instance_length - assert_equal 2 , method.frame_type.variable_index(:local) + assert_equal 1 , method.frame_type.variable_index(:local) + assert_equal 2 , method.frame_type.variable_index(:a) end def test_typed_method_has_one_local @@ -71,7 +72,7 @@ module Vool test = Parfait.object_space.get_class_by_name(:Test) method = test.instance_type.get_method(:meth) assert_equal 3 , method.frame_type.instance_length - assert_equal 2 , method.frame_type.variable_index(:local) + assert_equal 1 , method.frame_type.variable_index(:local) end end