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:
parent
15e4533a2f
commit
a350325b6b
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user