add parfait block
This commit is contained in:
@ -11,6 +11,7 @@ require_relative "parfait/list"
|
||||
require_relative "parfait/word"
|
||||
require_relative "parfait/binary_code"
|
||||
require_relative "parfait/callable"
|
||||
require_relative "parfait/block"
|
||||
require_relative "parfait/callable_method"
|
||||
require_relative "parfait/vool_method"
|
||||
require_relative "parfait/dictionary"
|
||||
|
23
lib/parfait/block.rb
Normal file
23
lib/parfait/block.rb
Normal file
@ -0,0 +1,23 @@
|
||||
module Parfait
|
||||
|
||||
# A Block is a callable object, much like a CallableMethod.
|
||||
# Surprisingly similar in fact, as the block is really only missing the name.
|
||||
#
|
||||
# The difference lies mostly in the way they are compiled
|
||||
#
|
||||
# Also both have a list of blocks defined in their scope. But this is
|
||||
# notimplemented for blocks yet
|
||||
#
|
||||
class Block < Callable
|
||||
|
||||
def ==(other)
|
||||
return false unless other.is_a?(Block)
|
||||
super
|
||||
end
|
||||
|
||||
def inspect
|
||||
"#{@self_type.object_class.name}(#{arguments_type.inspect})"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
@ -36,5 +36,24 @@ module Parfait
|
||||
block.call( self )
|
||||
@next.each_method( &block ) if @next
|
||||
end
|
||||
|
||||
def create_block(args , frame)
|
||||
bl = Block.new(self_type , args , frame)
|
||||
block = self.blocks
|
||||
bl.next = block if(block)
|
||||
@blocks = bl
|
||||
end
|
||||
|
||||
def has_block(block)
|
||||
each_block{ |bl| return true if bl == block}
|
||||
false
|
||||
end
|
||||
def each_block(&bl)
|
||||
blo = blocks
|
||||
while( blo )
|
||||
yield(blo)
|
||||
blo = blo.next
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -124,6 +124,7 @@ module Parfait
|
||||
Word: :Data8 ,
|
||||
List: :Data16 ,
|
||||
CallableMethod: :Callable,
|
||||
Block: :Callable,
|
||||
ReturnAddress: :Integer}
|
||||
end
|
||||
|
||||
@ -132,6 +133,9 @@ module Parfait
|
||||
# and all instance variable names. Really have to find a better way
|
||||
def self.type_names
|
||||
{BinaryCode: {next: :BinaryCode} ,
|
||||
Block: {binary: :BinaryCode, next: :CallableMethod,
|
||||
arguments_type: :Type , self_type: :Type, frame_type: :Type } ,
|
||||
|
||||
CacheEntry: {cached_type: :Type , cached_method: :CallableMethod } ,
|
||||
Callable: {binary: :BinaryCode,next: :Callable ,
|
||||
arguments_type: :Type , self_type: :Type, frame_type: :Type } ,
|
||||
|
Reference in New Issue
Block a user