2018-07-07 08:11:09 +02:00
|
|
|
module Parfait
|
|
|
|
|
2018-08-02 16:36:39 +02:00
|
|
|
# A CallableMethod is static object that primarily holds the executable code.
|
|
|
|
# It is callable through it's binary code
|
|
|
|
#
|
2019-10-03 23:36:49 +02:00
|
|
|
# It's relation to the method a ruby programmer knows (called SolMethod) is many to one,
|
|
|
|
# meaning one SolMethod (untyped) has many CallableMethod implementations.
|
|
|
|
# The SolMethod only holds sol code, no binary.
|
2018-08-02 16:36:39 +02:00
|
|
|
#
|
|
|
|
# CallableMethods are bound to a known type (self_type) and have known argument
|
|
|
|
# and local variables. All variable resolution inside the method is exact (static),
|
|
|
|
# only method resolution may be dynamic
|
2018-07-07 08:11:09 +02:00
|
|
|
class CallableMethod < Callable
|
|
|
|
|
|
|
|
def ==(other)
|
|
|
|
return false unless other.is_a?(CallableMethod)
|
2019-09-09 19:26:54 +02:00
|
|
|
return false if @name != other.name
|
2018-07-07 08:11:09 +02:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def rxf_reference_name
|
2020-03-14 11:23:34 +01:00
|
|
|
to_s
|
|
|
|
end
|
|
|
|
def to_s
|
2019-09-09 19:26:54 +02:00
|
|
|
"Method: " + @name.to_s
|
2018-07-07 08:11:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def inspect
|
2019-09-09 19:26:54 +02:00
|
|
|
"#{@self_type.object_class.name}:#{@name}(#{@arguments_type.inspect})"
|
2018-07-07 08:11:09 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def each_method( &block )
|
|
|
|
block.call( self )
|
2019-09-10 11:33:57 +02:00
|
|
|
@next_callable.each_method( &block ) if @next_callable
|
2018-07-07 08:11:09 +02:00
|
|
|
end
|
2018-07-07 14:50:43 +02:00
|
|
|
|
|
|
|
def create_block(args , frame)
|
2019-09-09 19:26:54 +02:00
|
|
|
block_name = "#{@name}_block".to_sym #TODO with id, to distinguish
|
|
|
|
add_block( Block.new(block_name , @self_type , args , frame))
|
2018-07-07 21:42:00 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_block(bl)
|
2018-08-11 18:15:34 +02:00
|
|
|
was = blocks
|
2018-07-27 09:46:22 +02:00
|
|
|
bl.set_next(was) if(was)
|
2019-09-09 19:26:54 +02:00
|
|
|
@blocks = bl
|
2018-07-07 14:50:43 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def has_block(block)
|
|
|
|
each_block{ |bl| return true if bl == block}
|
|
|
|
false
|
|
|
|
end
|
|
|
|
def each_block(&bl)
|
2019-09-09 19:26:54 +02:00
|
|
|
blo = @blocks
|
2018-07-07 14:50:43 +02:00
|
|
|
while( blo )
|
|
|
|
yield(blo)
|
2018-08-11 18:15:34 +02:00
|
|
|
blo = blo.next_callable
|
2018-07-07 14:50:43 +02:00
|
|
|
end
|
|
|
|
end
|
2018-07-07 08:11:09 +02:00
|
|
|
end
|
|
|
|
end
|