use the return jump to jump to the return sequence

thus every method only has one exit
should make multi return messages smaller
especially when we have escape analisis
(maybe will help with inlining too)
This commit is contained in:
Torsten Ruger 2018-08-02 17:36:39 +03:00
parent 4d4b691a4b
commit 5346077a72
3 changed files with 27 additions and 12 deletions

View File

@ -1,14 +1,15 @@
# A CallableMethod is static object that primarily holds the executable code.
# It is callable through it's binary code
# Additionally to the base class it has a name
#
# It's relation to the method a ruby programmer knows (called VoolMethod) is many to one,
# meaning one VoolMethod (untyped) has many CallableMethod implementations.
# The VoolMethod only holds vool code, no binary.
module Parfait
# A CallableMethod is static object that primarily holds the executable code.
# It is callable through it's binary code
#
# It's relation to the method a ruby programmer knows (called VoolMethod) is many to one,
# meaning one VoolMethod (untyped) has many CallableMethod implementations.
# The VoolMethod only holds vool code, no binary.
#
# CallableMethods are bound to a known type (self_type) and have known argument
# and local variables. All variable resolution inside the method is exact (static),
# only method resolution may be dynamic
class CallableMethod < Callable
def ==(other)

View File

@ -13,14 +13,28 @@ module Risc
def initialize( callable )
@callable = callable
@regs = []
@risc_instructions = Risc.label(source_name, source_name)
@risc_instructions << Risc.label( source_name, "unreachable")
init_instructions
@current = @risc_instructions
@constants = []
@block_compilers = []
end
attr_reader :risc_instructions , :constants , :block_compilers , :callable
def init_instructions
@risc_instructions = Risc.label(source_name, source_name)
@risc_instructions.append Risc.label( source_name, "return_label")
@risc_instructions.append Mom::ReturnSequence.new.to_risc(self)
@risc_instructions.append Risc.label( source_name, "unreachable")
reset_regs
end
def return_label
@risc_instructions.each do |ins|
next unless ins.is_a?(Label)
return ins if ins.name == "return_label"
end
end
# convert the given mom instruction to_risc and then add it (see add_code)
# continue down the instruction chain unti depleted
# (adding moves the insertion point so the whole mom chain is added as a risc chain)

View File

@ -18,7 +18,7 @@ module Vool
def to_mom( compiler )
ret = Mom::SlotLoad.new( [:message , :return_value] ,
@return_value.slot_definition(compiler) )
ret << Mom::ReturnSequence.new
ret << Mom::ReturnJump.new
end
def to_s(depth = 0)