diff --git a/lib/melon/compilers/method_compiler.rb b/lib/melon/compilers/method_compiler.rb new file mode 100644 index 00000000..2d594e5b --- /dev/null +++ b/lib/melon/compilers/method_compiler.rb @@ -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 diff --git a/lib/melon/compilers/normalizer.rb b/lib/melon/compilers/normalizer.rb new file mode 100644 index 00000000..8647c570 --- /dev/null +++ b/lib/melon/compilers/normalizer.rb @@ -0,0 +1,12 @@ +module Melon + module Compilers + + class Normalizer < AST::Processor + + def initialize( ruby_method ) + @ruby_method + end + + end + end +end diff --git a/lib/melon/ruby_compiler.rb b/lib/melon/ruby_compiler.rb index a0cf723d..6442cba2 100644 --- a/lib/melon/ruby_compiler.rb +++ b/lib/melon/ruby_compiler.rb @@ -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 diff --git a/lib/melon/ruby_method.rb b/lib/melon/ruby_method.rb index b80d3741..3a0cb68e 100644 --- a/lib/melon/ruby_method.rb +++ b/lib/melon/ruby_method.rb @@ -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 diff --git a/test/melon/compilers/test_normalizer.rb b/test/melon/compilers/test_normalizer.rb new file mode 100644 index 00000000..e5cfaff2 --- /dev/null +++ b/test/melon/compilers/test_normalizer.rb @@ -0,0 +1,16 @@ +require_relative "helper" + +module Melon + module Compilers + class TestNormalizer < MiniTest::Test + + def setup + Register.machine.boot unless Register.machine.booted + end + + def test_no_thing + assert true + end + end + end +end diff --git a/test/melon/compilers/test_type_collector.rb b/test/melon/compilers/test_type_collector.rb index 5f39cfd3..f2aa4bcf 100644 --- a/test/melon/compilers/test_type_collector.rb +++ b/test/melon/compilers/test_type_collector.rb @@ -29,7 +29,7 @@ module Melon end def test_compile_class - Compiler.compile "class TestIvar < Object ; def meth; @ivar;end; end" + RubyCompiler.compile "class TestIvar < Object ; def meth; @ivar;end; end" itest = Parfait.object_space.get_class_by_name(:TestIvar) assert itest assert itest.instance_type.names.include?(:ivar) , itest.instance_type.names.inspect diff --git a/test/melon/fragments/helper.rb b/test/melon/fragments/helper.rb index a51b2237..808293ba 100644 --- a/test/melon/fragments/helper.rb +++ b/test/melon/fragments/helper.rb @@ -10,7 +10,7 @@ module Melon end def check - Compiler.compile @string_input + RubyCompiler.compile @string_input Register::Collector.collect_space @interpreter = Register::Interpreter.new @interpreter.start Register.machine.init diff --git a/test/melon/test_compiler.rb b/test/melon/test_compiler.rb index 81c75a43..fb049382 100644 --- a/test/melon/test_compiler.rb +++ b/test/melon/test_compiler.rb @@ -8,14 +8,14 @@ module Melon end def test_creates_class_without_deriviation - Compiler.compile "class Testing ; end" + RubyCompiler.compile "class Testing ; end" clazz = Parfait.object_space.get_class_by_name(:Testing) assert clazz , "No classes created" assert_equal :Object , clazz.super_class_name end def test_creates_class_with_deriviation - Compiler.compile "class Test2 < List ;end" + RubyCompiler.compile "class Test2 < List ;end" clazz = Parfait.object_space.get_class_by_name(:Test2) assert clazz, "No classes created" assert_equal :List , clazz.super_class_name diff --git a/test/melon/test_ruby_method.rb b/test/melon/test_ruby_method.rb index 98ef739a..f5f925bd 100644 --- a/test/melon/test_ruby_method.rb +++ b/test/melon/test_ruby_method.rb @@ -9,7 +9,7 @@ module Melon end def create_method - Compiler.compile in_Space("def meth; @ivar;end") + RubyCompiler.compile in_Space("def meth; @ivar;end") space = Parfait.object_space.get_class space.get_method(:meth) end