push the name down into callable
blocks need a name too if just for debug, and stacks
This commit is contained in:
parent
1cb07a4164
commit
4055709529
@ -13,11 +13,14 @@ module Parfait
|
|||||||
class Callable < Object
|
class Callable < Object
|
||||||
|
|
||||||
attr_reader :self_type , :arguments_type , :frame_type , :binary
|
attr_reader :self_type , :arguments_type , :frame_type , :binary
|
||||||
attr_reader :blocks, :next
|
attr_reader :blocks, :next , :name
|
||||||
def initialize( self_type , arguments_type , frame_type)
|
|
||||||
|
def initialize( name , self_type , arguments_type , frame_type)
|
||||||
super()
|
super()
|
||||||
raise "No class #{self}" unless self_type
|
raise "No class #{self}" unless self_type
|
||||||
raise "For type, not class #{self_type}" unless self_type.is_a?(Type)
|
raise "For type, not class #{self_type}" unless self_type.is_a?(Type)
|
||||||
|
raise "Mixup" unless name.is_a?(Symbol)
|
||||||
|
@name = name
|
||||||
@self_type = self_type
|
@self_type = self_type
|
||||||
init(arguments_type, frame_type)
|
init(arguments_type, frame_type)
|
||||||
end
|
end
|
||||||
|
@ -11,13 +11,6 @@ module Parfait
|
|||||||
|
|
||||||
class CallableMethod < Callable
|
class CallableMethod < Callable
|
||||||
|
|
||||||
attr_reader :name
|
|
||||||
|
|
||||||
def initialize( self_type , name , arguments_type , frame_type)
|
|
||||||
@name = name
|
|
||||||
super(self_type , arguments_type , frame_type)
|
|
||||||
end
|
|
||||||
|
|
||||||
def ==(other)
|
def ==(other)
|
||||||
return false unless other.is_a?(CallableMethod)
|
return false unless other.is_a?(CallableMethod)
|
||||||
return false if @name != other.name
|
return false if @name != other.name
|
||||||
@ -38,7 +31,8 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def create_block(args , frame)
|
def create_block(args , frame)
|
||||||
add_block( Block.new(self_type , args , frame))
|
block_name = "#{@name}_block".to_sym #TODO with id, to distinguish
|
||||||
|
add_block( Block.new(block_name , self_type , args , frame))
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_block(bl)
|
def add_block(bl)
|
||||||
|
@ -101,7 +101,7 @@ module Parfait
|
|||||||
found.init(arguments , frame)
|
found.init(arguments , frame)
|
||||||
return found
|
return found
|
||||||
else
|
else
|
||||||
add_method CallableMethod.new( self , method_name , arguments , frame )
|
add_method CallableMethod.new( method_name , self , arguments , frame )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -134,11 +134,13 @@ module Parfait
|
|||||||
def self.type_names
|
def self.type_names
|
||||||
{BinaryCode: {next: :BinaryCode} ,
|
{BinaryCode: {next: :BinaryCode} ,
|
||||||
Block: {binary: :BinaryCode, next: :Block,
|
Block: {binary: :BinaryCode, next: :Block,
|
||||||
arguments_type: :Type , self_type: :Type, frame_type: :Type } ,
|
arguments_type: :Type , self_type: :Type, frame_type: :Type,
|
||||||
|
name: :Word } ,
|
||||||
|
|
||||||
CacheEntry: {cached_type: :Type , cached_method: :CallableMethod } ,
|
CacheEntry: {cached_type: :Type , cached_method: :CallableMethod } ,
|
||||||
Callable: {binary: :BinaryCode,next: :Callable ,
|
Callable: {binary: :BinaryCode,next: :Callable ,
|
||||||
arguments_type: :Type , self_type: :Type, frame_type: :Type } ,
|
arguments_type: :Type , self_type: :Type, frame_type: :Type,
|
||||||
|
name: :Word } ,
|
||||||
CallableMethod: {binary: :BinaryCode, next: :CallableMethod ,
|
CallableMethod: {binary: :BinaryCode, next: :CallableMethod ,
|
||||||
arguments_type: :Type , self_type: :Type, frame_type: :Type ,
|
arguments_type: :Type , self_type: :Type, frame_type: :Type ,
|
||||||
name: :Word , blocks: :Block} ,
|
name: :Word , blocks: :Block} ,
|
||||||
|
@ -11,7 +11,7 @@ module Parfait
|
|||||||
@obj = Parfait.object_space.get_type_by_class_name(:Object)
|
@obj = Parfait.object_space.get_type_by_class_name(:Object)
|
||||||
@args = Parfait::Type.for_hash( @obj.object_class , { bar: :Integer , foo: :Type})
|
@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})
|
@frame = Parfait::Type.for_hash( @obj.object_class , { local_bar: :Integer , local_foo: :Type})
|
||||||
@method = Parfait::CallableMethod.new( @obj , :meth , @args , @frame)
|
@method = Parfait::CallableMethod.new( :meth , @obj , @args , @frame)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -19,6 +19,11 @@ module Parfait
|
|||||||
def test_block_in_method
|
def test_block_in_method
|
||||||
assert @method.has_block( @method.create_block(@args , @frame ))
|
assert @method.has_block( @method.create_block(@args , @frame ))
|
||||||
end
|
end
|
||||||
|
def test_block_hash_name
|
||||||
|
assert_equal :meth_block , @method.create_block( @args , @frame ).name
|
||||||
|
end
|
||||||
|
def test_type_name
|
||||||
|
assert_equal 6 , @method.create_block( @args , @frame ).get_type.variable_index(:name)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -96,7 +96,7 @@ module Parfait
|
|||||||
assert_equal @method , @method
|
assert_equal @method , @method
|
||||||
end
|
end
|
||||||
def test_not_equal
|
def test_not_equal
|
||||||
method = Parfait::CallableMethod.new( @obj , :other , @args , @frame)
|
method = Parfait::CallableMethod.new( :other , @obj , @args , @frame)
|
||||||
assert @method != method
|
assert @method != method
|
||||||
end
|
end
|
||||||
def test_create_block
|
def test_create_block
|
||||||
@ -106,5 +106,8 @@ module Parfait
|
|||||||
def test_has_block
|
def test_has_block
|
||||||
assert_equal 7 , @method.get_type.variable_index( :blocks )
|
assert_equal 7 , @method.get_type.variable_index( :blocks )
|
||||||
end
|
end
|
||||||
|
def test_has_name
|
||||||
|
assert_equal 6 , @method.get_type.variable_index( :name )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -14,7 +14,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
def foo_method( for_class = :Try)
|
def foo_method( for_class = :Try)
|
||||||
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
args = Parfait::Type.for_hash( @try_class , { bar: :Integer})
|
||||||
::Parfait::CallableMethod.new( @space.get_type_by_class_name(for_class) , :foo , args,empty_frame)
|
::Parfait::CallableMethod.new( :foo ,@space.get_type_by_class_name(for_class) , args,empty_frame)
|
||||||
end
|
end
|
||||||
def add_foo_to( clazz = :Try )
|
def add_foo_to( clazz = :Try )
|
||||||
foo = foo_method( clazz )
|
foo = foo_method( clazz )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user