2016-12-18 19:05:11 +01:00
|
|
|
require_relative "type_collector"
|
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
|
|
|
|
clazz = Parfait::Space.object_space.create_class(get_name(name) , get_name(sup) )
|
2016-12-19 13:20:47 +01:00
|
|
|
ivar_hash = TypeCollector.new.collect(body)
|
|
|
|
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
|
2016-12-18 16:02:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|