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
This commit is contained in:
Torsten Ruger 2018-05-19 12:21:20 +03:00
parent 15e4533a2f
commit a350325b6b
4 changed files with 17 additions and 25 deletions

View File

@ -17,20 +17,18 @@ module Mom
def to_s def to_s
"SimpleCall #{@method.name}" "SimpleCall #{@method.name}"
end end
# To call the method, we determine the jumpable address (method.binary), move that # Calling a Method is basically jumping to the Binary (+ offset).
# into a register and issue a FunctionCall # 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 # 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. # return_address of the next_message, for the ReturnSequence to pick it up.
def to_risc(compiler) def to_risc(compiler)
jump_address = compiler.use_reg(:Object)
return_label = Risc::Label.new(self,"continue_#{object_id}") return_label = Risc::Label.new(self,"continue_#{object_id}")
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self) save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self)
moves = save_return.to_risc(compiler) moves = save_return.to_risc(compiler)
moves << Risc.slot_to_reg(self, :message , :next_message , Risc.message_reg) 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 )
moves << Risc::FunctionCall.new(self, method ,jump_address)
moves << return_label moves << return_label
end end

View File

@ -67,7 +67,7 @@ module Risc
builder.build do builder.build do
add_load_constant("__init__ load return", exit_label , ret_tmp) add_load_constant("__init__ load return", exit_label , ret_tmp)
add_reg_to_slot("__init__ store return", ret_tmp , :message , :return_address) 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 add_code exit_label
end end
compiler.reset_regs compiler.reset_regs

View File

@ -4,32 +4,19 @@ module Risc
# assembly takes care of the rest (ie getting the address) # assembly takes care of the rest (ie getting the address)
class FunctionCall < Instruction class FunctionCall < Instruction
def initialize( source , method , register) def initialize( source , method)
super(source) super(source)
@method = method @method = method
@register = register
end end
attr_reader :method , :register attr_reader :method
def to_s def to_s
class_source method.name class_source method.name
end end
end end
def self.function_call( source , method , register) def self.function_call( source , method )
Risc::FunctionCall.new( source , method , register) Risc::FunctionCall.new( source , method )
end 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 end

View File

@ -49,6 +49,9 @@ module Risc
raise "Not int #{pos}" unless pos.is_a? Numeric raise "Not int #{pos}" unless pos.is_a? Numeric
position = Position.at(pos) position = Position.at(pos)
log.debug "Setting Position #{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) raise "not instruction position #{position}-#{position.class}-#{position.object.class}" unless position.is_a?(Position::InstructionPosition)
set_instruction( position.instruction) set_instruction( position.instruction)
@clock = position.at @clock = position.at
@ -207,7 +210,11 @@ module Risc
end end
def execute_FunctionCall 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 false
end end