passing frame (locals) into method creation
so typed_method have correct frame information and can resolve slots correctly (next step)
This commit is contained in:
parent
0813312ddc
commit
af94d40cab
@ -74,14 +74,18 @@ module Parfait
|
||||
names
|
||||
end
|
||||
|
||||
def create_method( method_name , arguments )
|
||||
def create_method( method_name , arguments , frame)
|
||||
raise "create_method #{method_name}.#{method_name.class}" unless method_name.is_a?(Symbol)
|
||||
#puts "Self: #{self.class} clazz: #{clazz.name}"
|
||||
found = get_method( method_name )
|
||||
#TODO check types and then what ?
|
||||
return found if found
|
||||
arg_type = arguments
|
||||
arg_type = NamedList.type_for( arguments ) if arguments.is_a?(Hash)
|
||||
add_method TypedMethod.new( self , method_name , arg_type )
|
||||
if arguments.is_a?(Hash)
|
||||
raise "May want to get rid of this way"
|
||||
arguments = NamedList.type_for( arguments )
|
||||
end
|
||||
raise "frame must be a type, not:#{frame}" unless frame.is_a?(Type)
|
||||
add_method TypedMethod.new( self , method_name , arguments , frame )
|
||||
end
|
||||
|
||||
def add_method( method )
|
||||
|
@ -26,16 +26,17 @@ module Parfait
|
||||
# not part of the parfait model, hence ruby accessor
|
||||
attr_accessor :source
|
||||
|
||||
def initialize( type , name , arguments )
|
||||
def initialize( type , name , arguments , frame)
|
||||
super()
|
||||
raise "No class #{name}" unless type
|
||||
raise "For type, not class #{type}" unless type.is_a?(Type)
|
||||
raise "Wrong argument type, expect Type not #{arguments.class}" unless arguments.is_a? Type
|
||||
raise "Wrong frame type, expect Type not #{frame.class}" unless frame.is_a? Type
|
||||
@for_type = type
|
||||
@name = name
|
||||
@binary = BinaryCode.new 0
|
||||
@arguments = arguments
|
||||
@frame = Parfait.object_space.get_class_by_name( :NamedList ).instance_type
|
||||
@frame = frame
|
||||
end
|
||||
|
||||
def set_instructions(inst)
|
||||
|
@ -28,7 +28,7 @@ module Parfait
|
||||
|
||||
def create_parfait_method( type )
|
||||
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
|
||||
type.create_method( @name , @args_type )#FIXME, @frame_type)
|
||||
type.create_method( @name , @args_type , @frame_type)
|
||||
end
|
||||
|
||||
def create_tmp
|
||||
|
@ -50,16 +50,28 @@ module Vool
|
||||
assert_equal Parfait::Class , clazz.body.clazz.class
|
||||
end
|
||||
|
||||
def test_method_statement_has_class_in_main
|
||||
clazz = VoolCompiler.ruby_to_vool in_Space("def meth; @ivar = 5;end")
|
||||
assert clazz.body.clazz
|
||||
def test_typed_method_instance_type
|
||||
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)
|
||||
end
|
||||
|
||||
def test_method_has_one_local
|
||||
VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ;end")
|
||||
def test_vool_method_has_one_local
|
||||
VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ; a = 6;end")
|
||||
test = Parfait.object_space.get_class_by_name(:Test)
|
||||
method = test.get_method(:meth)
|
||||
assert_equal 2 , method.frame_type.instance_length
|
||||
assert_equal 3 , method.frame_type.instance_length
|
||||
assert_equal 2 , method.frame_type.variable_index(:local)
|
||||
end
|
||||
|
||||
def test_typed_method_has_one_local
|
||||
VoolCompiler.ruby_to_vool in_Test("def meth; local = 5 ; a = 6;end")
|
||||
test = Parfait.object_space.get_class_by_name(:Test)
|
||||
method = test.instance_type.get_method(:meth)
|
||||
assert_equal 3 , method.frame.instance_length
|
||||
assert_equal 2 , method.frame.variable_index(:local)
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user