From a350325b6b13ab096c824d216d903829c76edc47 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 19 May 2018 12:21:20 +0300 Subject: [PATCH] fix function call and simple call logic Before creating DynamicJump, the FunctionCall got a register for a possible jump address. Now that is handled by DynamicJump and FunctionCall just needs the method, from which it determines the binaryCode address --- lib/mom/instruction/simple_call.rb | 10 ++++------ lib/risc/builtin/object.rb | 2 +- lib/risc/instructions/function_call.rb | 21 ++++----------------- lib/risc/interpreter.rb | 9 ++++++++- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/lib/mom/instruction/simple_call.rb b/lib/mom/instruction/simple_call.rb index ee086344..7b19b4d0 100644 --- a/lib/mom/instruction/simple_call.rb +++ b/lib/mom/instruction/simple_call.rb @@ -17,20 +17,18 @@ module Mom def to_s "SimpleCall #{@method.name}" end - # To call the method, we determine the jumpable address (method.binary), move that - # into a register and issue a FunctionCall - # + # Calling a Method is basically jumping to the Binary (+ offset). + # We just swap in the new message and go. + # # For returning, we add a label after the call, and load it's address into the # return_address of the next_message, for the ReturnSequence to pick it up. def to_risc(compiler) - jump_address = compiler.use_reg(:Object) return_label = Risc::Label.new(self,"continue_#{object_id}") save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self) moves = save_return.to_risc(compiler) moves << Risc.slot_to_reg(self, :message , :next_message , Risc.message_reg) - moves << Risc.load_constant(self , method.binary , jump_address) - moves << Risc::FunctionCall.new(self, method ,jump_address) + moves << Risc::FunctionCall.new(self, method ) moves << return_label end diff --git a/lib/risc/builtin/object.rb b/lib/risc/builtin/object.rb index 3b296e01..7004cb35 100644 --- a/lib/risc/builtin/object.rb +++ b/lib/risc/builtin/object.rb @@ -67,7 +67,7 @@ module Risc builder.build do add_load_constant("__init__ load return", exit_label , ret_tmp) add_reg_to_slot("__init__ store return", ret_tmp , :message , :return_address) - add_function_call( "__init__ issue call" , Parfait.object_space.get_main , ret_tmp) + add_function_call( "__init__ issue call" , Parfait.object_space.get_main) add_code exit_label end compiler.reset_regs diff --git a/lib/risc/instructions/function_call.rb b/lib/risc/instructions/function_call.rb index f7293ac2..cfc11a74 100644 --- a/lib/risc/instructions/function_call.rb +++ b/lib/risc/instructions/function_call.rb @@ -4,32 +4,19 @@ module Risc # assembly takes care of the rest (ie getting the address) class FunctionCall < Instruction - def initialize( source , method , register) + def initialize( source , method) super(source) @method = method - @register = register end - attr_reader :method , :register + attr_reader :method def to_s class_source method.name end end - def self.function_call( source , method , register) - Risc::FunctionCall.new( source , method , register) + def self.function_call( source , method ) + Risc::FunctionCall.new( source , method ) end - # def self.issue_call( compiler , callee ) - # callee_name = callee.name - # return_label = Risc.label("_return_label #{callee_name}" , "#{compiler.type.object_class.name}.#{compiler.method.name}" ) - # ret_tmp = compiler.use_reg(:Label) - # compiler.add_load_constant("#{callee_name} load ret", return_label , ret_tmp) - # compiler.add_reg_to_slot("#{callee_name} store ret", ret_tmp , :new_message , :return_address) - # compiler.add_transfer("#{callee_name} move new message", Risc.new_message_reg , Risc.message_reg ) - # compiler.add_function_call( "#{callee_name} call" , callee ) - # compiler.add_code return_label - # compiler.add_transfer("#{callee_name} remove new message", Risc.message_reg , Risc.new_message_reg ) - # compiler.add_slot_to_reg("#{callee_name} restore message" , :new_message , :caller , :message ) - # end end diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 2274dfd4..c9e7964b 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -49,6 +49,9 @@ module Risc raise "Not int #{pos}" unless pos.is_a? Numeric position = Position.at(pos) log.debug "Setting Position #{pos}" + if position.is_a?(Position::CodePosition) + return set_pc(position.at + 12) + end raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition) set_instruction( position.instruction) @clock = position.at @@ -207,7 +210,11 @@ module Risc end def execute_FunctionCall - set_instruction @instruction.method.risc_instructions + meth = @instruction.method + at = Position.get(meth.binary).at + log.debug "Call to #{meth.name} at:#{at}" + set_pc(at + 12) + #set_instruction @instruction.method.risc_instructions false end