add normalizing and method compilation phases (empty)
This commit is contained in:
parent
1c2b6d103c
commit
9eeb9f65f3
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
|
||||
|
16
test/melon/compilers/test_normalizer.rb
Normal file
16
test/melon/compilers/test_normalizer.rb
Normal file
@ -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
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user