manage to create ruby methods

This commit is contained in:
Torsten Ruger
2017-01-12 20:38:04 +02:00
parent 89f5badc16
commit 3f6c1bc3a3
12 changed files with 76 additions and 24 deletions

View File

@ -8,33 +8,39 @@ require_relative "compiler/ruby_method"
module Melon
class Compiler < AST::Processor
def self.compile input
ast = Parser::Ruby22.parse input
compiler = self.new
compiler.process ast
end
def get_name( statement )
return nil unless statement
statement.children[1]
def self.compile( input )
ast = Parser::Ruby22.parse( input )
self.new.process( ast )
end
def on_class statement
name , sup , body = *statement
class_name = get_name(name)
clazz = Parfait.object_space.create_class(class_name , get_name(sup) )
clazz = Parfait.object_space.get_class_by_name!(class_name , get_name(sup) )
ivar_hash = TypeCollector.new.collect(body)
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
create_methods(clazz , body)
end
MethodCollector.new.collect(body)
def create_methods(clazz , body)
methods = MethodCollector.new.collect(body)
methods.each do |method|
clazz.add_method( method )
end
end
def handler_missing(node)
# raise "Oh"
node.children.each do |kid |
process(kid) if kid.is_a?(AST::Node)
end
end
private
def get_name( statement )
return nil unless statement
statement.children[1]
end
end
end