2016-12-21 09:51:33 +01:00
|
|
|
require_relative "compiler/total_processor"
|
2016-12-20 19:02:52 +01:00
|
|
|
require_relative "compiler/type_collector"
|
|
|
|
require_relative "compiler/method_collector"
|
2016-12-21 10:20:36 +01:00
|
|
|
require_relative "compiler/locals_collector"
|
2016-12-20 19:02:52 +01:00
|
|
|
require_relative "compiler/ruby_method"
|
2016-12-18 16:02:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
module Melon
|
|
|
|
class Compiler < AST::Processor
|
|
|
|
|
|
|
|
def self.compile input
|
|
|
|
ast = Parser::Ruby22.parse input
|
|
|
|
compiler = self.new
|
|
|
|
compiler.process ast
|
|
|
|
end
|
|
|
|
|
2016-12-18 16:17:58 +01:00
|
|
|
def get_name( statement )
|
|
|
|
return nil unless statement
|
|
|
|
statement.children[1]
|
|
|
|
end
|
|
|
|
|
2016-12-18 16:02:55 +01:00
|
|
|
def on_class statement
|
2016-12-18 19:05:11 +01:00
|
|
|
name , sup , body = *statement
|
2017-01-01 20:50:54 +01:00
|
|
|
class_name = get_name(name)
|
|
|
|
clazz = Parfait.object_space.create_class(class_name , get_name(sup) )
|
2016-12-19 13:20:47 +01:00
|
|
|
ivar_hash = TypeCollector.new.collect(body)
|
2016-12-20 19:02:52 +01:00
|
|
|
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
|
|
|
|
|
|
|
|
MethodCollector.new.collect(body)
|
|
|
|
|
2016-12-18 16:02:55 +01:00
|
|
|
end
|
2016-12-20 19:02:52 +01:00
|
|
|
|
|
|
|
def handler_missing(node)
|
|
|
|
node.children.each do |kid |
|
|
|
|
process(kid) if kid.is_a?(AST::Node)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-12-18 16:02:55 +01:00
|
|
|
end
|
|
|
|
end
|