add normalizing and method compilation phases (empty)
This commit is contained in:
16
lib/melon/compilers/method_compiler.rb
Normal file
16
lib/melon/compilers/method_compiler.rb
Normal file
@ -0,0 +1,16 @@
|
||||
module Melon
|
||||
module Compilers
|
||||
|
||||
class MethodCompiler < AST::Processor
|
||||
|
||||
def initialize( ruby_method )
|
||||
@ruby_method
|
||||
end
|
||||
|
||||
def handler_missing(node)
|
||||
raise "No handler for #{node}"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
12
lib/melon/compilers/normalizer.rb
Normal file
12
lib/melon/compilers/normalizer.rb
Normal file
@ -0,0 +1,12 @@
|
||||
module Melon
|
||||
module Compilers
|
||||
|
||||
class Normalizer < AST::Processor
|
||||
|
||||
def initialize( ruby_method )
|
||||
@ruby_method
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
@ -4,11 +4,12 @@ require_relative "compilers/total_processor"
|
||||
require_relative "compilers/type_collector"
|
||||
require_relative "compilers/method_collector"
|
||||
require_relative "compilers/locals_collector"
|
||||
require_relative "compilers/normalizer"
|
||||
require_relative "ruby_method"
|
||||
|
||||
|
||||
module Melon
|
||||
class Compiler < Compilers::TotalProcessor
|
||||
class RubyCompiler < Compilers::TotalProcessor
|
||||
|
||||
def self.compile( input )
|
||||
ast = Parser::Ruby22.parse( input )
|
||||
@ -21,13 +22,22 @@ module Melon
|
||||
clazz = Parfait.object_space.get_class_by_name!(class_name , get_name(sup) )
|
||||
ivar_hash = Compilers::TypeCollector.new.collect(body)
|
||||
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
|
||||
create_methods(clazz , body)
|
||||
methods = create_methods(clazz , body)
|
||||
compiler_methods(methods)
|
||||
end
|
||||
|
||||
def create_methods(clazz , body)
|
||||
methods = Compilers::MethodCollector.new.collect(body)
|
||||
methods.each do |method|
|
||||
clazz.add_method( method )
|
||||
normalizer = Compilers::Normalizer.new(method)
|
||||
method.normalize_source { |sourc| normalizer.process( sourc ) }
|
||||
end
|
||||
methods
|
||||
end
|
||||
|
||||
def compiler_methods(methods)
|
||||
methods.each do |method|
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -8,5 +8,8 @@ module Melon
|
||||
@name , @args_type , @locals_type , @source = name , args_type, locals_type , source
|
||||
end
|
||||
|
||||
def normalize_source
|
||||
@source = yield @source
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user