From 7223ca9a1c101258be3a755ff37c35bbc27f70aa Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 16 Jan 2017 17:44:34 +0200 Subject: [PATCH] clean and refactor --- lib/melon/passes/method_compiler.rb | 2 +- lib/melon/ruby_method.rb | 3 +++ lib/vm/method_compiler/call_site.rb | 15 ++++++++++----- test/vm/method_compiler/test_assignment.rb | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/melon/passes/method_compiler.rb b/lib/melon/passes/method_compiler.rb index 3fbb20a5..5f8be200 100644 --- a/lib/melon/passes/method_compiler.rb +++ b/lib/melon/passes/method_compiler.rb @@ -32,7 +32,7 @@ module Melon w = Vm::Tree::CallSite.new() puts "receiver #{statement}" w.name = name - w.arguments = process(args) + w.arguments = process(args) || [] w.receiver = process(receiver) w end diff --git a/lib/melon/ruby_method.rb b/lib/melon/ruby_method.rb index d97d8996..067f990f 100644 --- a/lib/melon/ruby_method.rb +++ b/lib/melon/ruby_method.rb @@ -6,6 +6,9 @@ module Melon def initialize(name , args_type , locals_type , source ) @name , @args_type , @locals_type , @source = name , args_type, locals_type , source + raise "Name must be symbol" unless name.is_a?(Symbol) + raise "args_type must be type" unless args_type.is_a?(Parfait::Type) + raise "locals_type must be type" unless locals_type.is_a?(Parfait::Type) end def normalize_source diff --git a/lib/vm/method_compiler/call_site.rb b/lib/vm/method_compiler/call_site.rb index b8de4ea0..0643fa88 100644 --- a/lib/vm/method_compiler/call_site.rb +++ b/lib/vm/method_compiler/call_site.rb @@ -2,24 +2,22 @@ module Vm module CallSite def on_CallSite( statement ) -# name_s , arguments , receiver = *statement raise "not inside method " unless @method reset_regs #move the new message (that we need to populate to make a call) to std register - new_message = Register.resolve_to_register(:new_message) - add_slot_to_reg(statement, :message , :next_message , new_message ) + load_new_message(statement) me = get_me( statement ) type = get_my_type(me) method = type.get_method(statement.name) - raise "Method not implementedfor me#{type} #{type.inspect}.#{statement.name}" unless method + raise "Method not implemented for me:#{me} #{type.inspect}.#{statement.name}" unless method # move our receiver there add_reg_to_slot( statement , me , :new_message , :receiver) set_message_details(method , statement , statement.arguments) set_arguments(method , statement.arguments) - ret = use_reg( :Integer ) #FIXME real return type + ret = use_reg( :Object ) #FIXME real return type Register.issue_call( self , method ) @@ -31,6 +29,12 @@ module Vm private + def load_new_message(statement) + new_message = Register.resolve_to_register(:new_message) + add_slot_to_reg(statement, :message , :next_message , new_message ) + new_message + end + def get_me( statement ) if statement.receiver me = process( statement.receiver ) @@ -40,6 +44,7 @@ module Vm end me end + def get_my_type( me ) # now we have to resolve the method name (+ receiver) into a callable method case me.type diff --git a/test/vm/method_compiler/test_assignment.rb b/test/vm/method_compiler/test_assignment.rb index 2c8c94e6..00088767 100644 --- a/test/vm/method_compiler/test_assignment.rb +++ b/test/vm/method_compiler/test_assignment.rb @@ -41,7 +41,7 @@ module Register end def test_assign_call - Parfait.object_space.get_main.add_local(:r , :Integer) + Parfait.object_space.get_main.add_local(:r , :Object) @input = s(:statements, s(:l_assignment, s(:local, :r), s(:call, :main, s(:arguments)))) @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,