From 45bd4bfdc61de80114c5ef1e5e3171af2574ec08 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Mon, 2 Nov 2015 20:11:12 +0200 Subject: [PATCH] remove save return --- lib/soml/compiler.rb | 3 +-- lib/soml/compiler/call_site.rb | 23 +++++++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/soml/compiler.rb b/lib/soml/compiler.rb index 2377567a..d94944df 100644 --- a/lib/soml/compiler.rb +++ b/lib/soml/compiler.rb @@ -84,8 +84,7 @@ module Soml def init_method source = "_init_method" @method.instructions = Register::Label.new(source, "#{method.for_class.name}.#{method.name}") - @current = method.instructions - add_code enter = Register.save_return(source, :message , :return_address) + @current = enter = method.instructions add_code Register::Label.new( source, "return") # move the current message to new_message add_code Register::RegisterTransfer.new(source, Register.message_reg , Register.new_message_reg ) diff --git a/lib/soml/compiler/call_site.rb b/lib/soml/compiler/call_site.rb index 3f78c5f6..dd9ddb67 100644 --- a/lib/soml/compiler/call_site.rb +++ b/lib/soml/compiler/call_site.rb @@ -4,7 +4,6 @@ module Soml def on_call statement #puts statement name_s , arguments , receiver = *statement - name = name_s.to_a.first raise "not inside method " unless @method reset_regs #move the new message (that we need to populate to make a call) to std register @@ -24,21 +23,30 @@ module Soml end # move our receiver there add_code Register.set_slot( statement , me , :new_message , :receiver) + set_message_details(name_s , arguments) set_arguments(arguments) - #puts "clazz #{clazz.name}" - raise "No such class #{me.type}" unless clazz - method = clazz.get_instance_method(name) - #puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a - raise "Method not implemented #{me.type}.#{name}" unless method - Register.issue_call( self , method ) + do_call(clazz , statement) ret = use_reg( :Integer ) # the effect of the method is that the NewMessage Return slot will be filled, return it # but move it into a register too add_code Register.get_slot(statement, :message , :return_value , ret ) ret end + private + def do_call clazz , statement + name = statement.first.first + #puts "clazz #{clazz.name}" + raise "No such class #{me.type}" unless clazz + method = clazz.get_instance_method(name) + #puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a + raise "Method not implemented #{me.type}.#{name}" unless method + ret_tmp = use_reg(:Label) + add_code Register::LoadConstant.new(statement.first, method.instructions , ret_tmp) + add_code Register.set_slot(statement, ret_tmp , :message , :return_address) + Register.issue_call( self , method ) + end def set_message_details name_s , arguments name = name_s.to_a.first # load method name and set to new message (for exceptions/debug) @@ -49,7 +57,6 @@ module Soml len_tmp = use_reg(:Integer , arguments.to_a.length ) add_code Register::LoadConstant.new(arguments, arguments.to_a.length , len_tmp) add_code Register.set_slot( arguments , len_tmp , :new_message , :indexed_length) - end def set_arguments arguments # reset tmp regs for each and load result into new_message