From 96f19d18c0bcd25a0ca79e0fd1c19eef86b12542 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 15 Jan 2017 20:30:47 +0200 Subject: [PATCH] starting on ruby send --- lib/melon/compilers/method_compiler.rb | 14 ++++++++++++++ lib/melon/ruby_compiler.rb | 1 - lib/vm/method_compiler/call_site.rb | 2 +- test/melon/fragments/helper.rb | 3 ++- test/melon/fragments/test_hello.rb | 4 ++-- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/lib/melon/compilers/method_compiler.rb b/lib/melon/compilers/method_compiler.rb index 26059c44..e44b6e1b 100644 --- a/lib/melon/compilers/method_compiler.rb +++ b/lib/melon/compilers/method_compiler.rb @@ -27,6 +27,20 @@ module Melon w end + def on_send( statement ) + receiver , name , args = *statement + w = Vm::Tree::CallSite.new() + puts "receiver #{statement}" + w.name = process(receiver) + w.arguments = process(args) + w.receiver = nil + w + end + + def on_str( string ) + Vm::Tree::StringExpression.new(string.children.first) + end + def on_int( expression) Vm::Tree::IntegerExpression.new(expression.children.first) end diff --git a/lib/melon/ruby_compiler.rb b/lib/melon/ruby_compiler.rb index 90fe4a62..ed7243a4 100644 --- a/lib/melon/ruby_compiler.rb +++ b/lib/melon/ruby_compiler.rb @@ -40,7 +40,6 @@ module Melon 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 diff --git a/lib/vm/method_compiler/call_site.rb b/lib/vm/method_compiler/call_site.rb index 1421a524..b8de4ea0 100644 --- a/lib/vm/method_compiler/call_site.rb +++ b/lib/vm/method_compiler/call_site.rb @@ -12,7 +12,7 @@ module Vm type = get_my_type(me) method = type.get_method(statement.name) - raise "Method not implemented #{type.inspect}.#{statement.name}" unless method + raise "Method not implementedfor me#{type} #{type.inspect}.#{statement.name}" unless method # move our receiver there add_reg_to_slot( statement , me , :new_message , :receiver) diff --git a/test/melon/fragments/helper.rb b/test/melon/fragments/helper.rb index 808293ba..15b7660d 100644 --- a/test/melon/fragments/helper.rb +++ b/test/melon/fragments/helper.rb @@ -4,7 +4,8 @@ require "parser/ruby22" module Melon module MelonTests - + include CompilerHelper + def setup Register.machine.boot end diff --git a/test/melon/fragments/test_hello.rb b/test/melon/fragments/test_hello.rb index 5f30eab2..8cfcf3c0 100644 --- a/test/melon/fragments/test_hello.rb +++ b/test/melon/fragments/test_hello.rb @@ -6,9 +6,9 @@ module Melon def test_ruby_hello - @string_input = 'puts "Hello there"' + @string_input = in_Space 'def puts(str) ; str.putstring; end ; def main; putstring "Hello there"; end' assert !check -# assert_equal "Hello there" , @interpreter.stdout + assert_equal "Hello there" , @interpreter.stdout end end