get block resolution to use the extra

block_compiler puts in the extra, that we get out when resolving the type
Thus block args work, though only by assuming direct call
This commit is contained in:
Torsten Ruger
2018-07-17 10:37:33 +03:00
parent 280ea8a8c4
commit ff8b95f21a
7 changed files with 36 additions and 11 deletions

View File

@ -16,6 +16,20 @@ module Risc
"#{@method.self_type.name}.init"
end
# resolve the type of the slot, by inferring from it's name, using the type
# scope related slots are resolved by the compiler by method/block
#
# This mainly calls super, and only for :caller adds extra info
# Using the info, means assuming that the block is not passed around (FIXME in 2020)
def slot_type( slot , type)
new_type = super
if slot == :caller
extra_info = { type_frame: @method.frame_type ,
type_arguments: @method.arguments_type ,
type_self: @method.self_type}
end
return new_type , extra_info
end
# determine how given name need to be accsessed.
# For blocks the options are args or frame
# or then the methods arg or frame

View File

@ -66,7 +66,7 @@ module Risc
end
# resolve the type of the slot, by inferring from it's name, using the type
# scope related slots are resolved by the compiler by methood/block
# scope related slots are resolved by the compiler by method/block
def slot_type( slot , type)
case slot
when :frame

View File

@ -9,7 +9,7 @@ module Risc
# results of dsl operations (like <<) back to the builder
class RegisterValue
attr_reader :symbol , :type , :value
attr_reader :symbol , :type , :extra
attr_accessor :builder
@ -20,13 +20,14 @@ module Risc
# be :value, or :value_XX or :type_XX to indicate value or type information
# for an XX instance
def initialize( reg , type , extra = {})
extra = {} unless extra
raise "Not Hash #{extra}" unless extra.is_a?(Hash)
raise "not reg #{reg}" unless self.class.look_like_reg( reg )
raise "No type " unless type
type = Parfait.object_space.get_type_by_class_name(type) if type.is_a?(Symbol)
@type = type
@symbol = reg
@value = extra
@extra = extra
end
# using the registers type, resolve the slot to an index
@ -54,18 +55,19 @@ module Risc
# overwrite the message)
# We get the type with resolve_new_type
def get_new_left(slot, compiler)
new_type = compiler.slot_type(slot , type)
new_type = extra["type_#{slot}".to_sym]
new_type , extra = compiler.slot_type(slot , type) unless new_type
if( @symbol == :r0 )
new_left = compiler.use_reg( new_type )
new_left = compiler.use_reg( new_type , extra)
else
new_left = RegisterValue.new( @symbol , new_type)
new_left = RegisterValue.new( @symbol , new_type , extra)
end
new_left
end
def to_s
s = "#{symbol}:#{type}"
s += ":#{value}" if value
s += ":#{extra}" unless extra.empty?
s
end
@ -93,11 +95,11 @@ module Risc
end
#helper method to calculate with register symbols
def next_reg_use( type , value = nil )
def next_reg_use( type , extra = {} )
int = @symbol[1,3].to_i
raise "No more registers #{self}" if int > 11
sym = "r#{int + 1}".to_sym
RegisterValue.new( sym , type, value)
RegisterValue.new( sym , type, extra)
end
def rxf_reference_name