extracting methods for the compiler to handle

This commit is contained in:
Torsten Ruger
2016-12-20 20:02:52 +02:00
parent a70d20d63e
commit 8507bef08b
3 changed files with 81 additions and 2 deletions

View File

@ -0,0 +1,35 @@
module Melon
class MethodCollector < AST::Processor
def initialize
@methods = []
end
def collect(statement)
process statement
@methods
end
def on_def(statement)
name , args , body = *statement
args_type = make_type(args)
@methods << RubyMethod.new(name , args_type , body )
end
def make_type( statement )
type = Parfait::Space.object_space.get_class_by_name(:Message ).instance_type
statement.children.each do |arg|
type = type.add_instance_variable( arg.children[0] , :Object )
end
type
end
def handler_missing(node)
node.children.each do |kid |
process(kid) if kid.is_a?(AST::Node)
end
end
end
end