starting to create vm_method from ruby_method

issues galore though
This commit is contained in:
Torsten Ruger 2017-01-15 12:10:37 +02:00
parent 9eeb9f65f3
commit 4095bb397f
5 changed files with 40 additions and 9 deletions

View File

@ -4,7 +4,31 @@ module Melon
class MethodCompiler < AST::Processor
def initialize( ruby_method )
@ruby_method
@ruby_method = ruby_method
end
def get_code
process(@ruby_method.source)
end
def on_ivasgn(statement)
name , value = *statement
w = Vm::Tree::Assignment.new()
w.name = Vm::Tree::NameExpression.new( name[1..-1].to_sym)
w.value = process(value)
w
end
def on_ivar( var )
name = var.children.first
w = Vm::Tree::FieldAccess.new()
w.receiver = Vm::Tree::NameExpression.new(:self)
w.field = Vm::Tree::NameExpression.new( name[1..-1].to_sym)
w
end
def on_int( expression)
Vm::Tree::IntegerExpression.new(expression.children.first)
end
def handler_missing(node)

View File

@ -3,6 +3,7 @@ require "parser/ruby22"
require_relative "compilers/total_processor"
require_relative "compilers/type_collector"
require_relative "compilers/method_collector"
require_relative "compilers/method_compiler"
require_relative "compilers/locals_collector"
require_relative "compilers/normalizer"
require_relative "ruby_method"
@ -23,7 +24,7 @@ module Melon
ivar_hash = Compilers::TypeCollector.new.collect(body)
clazz.set_instance_type( Parfait::Type.for_hash( clazz , ivar_hash ) )
methods = create_methods(clazz , body)
compiler_methods(methods)
compile_methods(clazz,methods)
end
def create_methods(clazz , body)
@ -36,8 +37,12 @@ module Melon
methods
end
def compiler_methods(methods)
def compile_methods(clazz , methods)
methods.each do |method|
typed_method = method.create_vm_method(clazz.instance_type)
raise "NIL" unless method
code = Compilers::MethodCompiler.new(method).get_code
Vm::MethodCompiler.new( typed_method ).init_method.process( code)
end
end

View File

@ -11,5 +11,12 @@ module Melon
def normalize_source
@source = yield @source
end
def create_vm_method( type )
raise "create_method #{type.inspect} is not a Type" unless type.is_a? Parfait::Type
type.create_method( @name , @args_type )#FIXME, @locals_type)
end
end
end

View File

@ -61,11 +61,6 @@ module Vm
compiler.process code
end
def self.compile_method( method )
compiler = new(method)
compiler.process( code )
end
class MethodCompiler
CompilerModules.each do |mod|
include Vm.const_get( mod.camelize )

View File

@ -9,7 +9,7 @@ module Melon
end
def create_method
RubyCompiler.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