small refactor on arg loading

This commit is contained in:
Torsten Ruger 2016-12-28 21:10:14 +02:00
parent fa9807102b
commit c60949fe24
6 changed files with 36 additions and 30 deletions

View File

@ -10,7 +10,7 @@ module Register
attr_reader :label
def to_s
"#{self.class.name}: #{label ? label.name : ''}"
"#{self.class.name.split("::").last}: #{label ? label.name : ''}"
end
alias :inspect :to_s

View File

@ -30,7 +30,7 @@ module Register
attr_accessor :array , :index , :register
def to_s
"#{self.class.name}: #{array}[#{index}] -> #{register}"
"#{self.class.name.split("::").last}: #{array}[#{index}] -> #{register}"
end
end

View File

@ -15,7 +15,7 @@ module Register
attr_reader :name
def to_s
"Label: #{@name} (#{self.next.class})"
"Label: #{@name} (#{self.next.class.name.split("::").last})"
end
def sof_reference_name
@name

View File

@ -28,7 +28,7 @@ module Register
attr_accessor :register , :array , :index
def to_s
"#{self.class.name}: #{register} -> #{array}[#{index}]"
"#{self.class.name.split("::").last}: #{register} -> #{array}[#{index}]"
end
end

View File

@ -82,17 +82,21 @@ module Typed
message = "Arg number mismatch, method=#{arg_type.instance_length - 1} , call=#{arguments.length}"
raise message if (arg_type.instance_length - 1 ) != arguments.length
arguments.each_with_index do |arg , i |
reset_regs
# processing should return the register with the value
val = process( arg)
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
#FIXME definately needs some tests
raise "TypeMismatch calling with #{val.type} , instead of #{arg_type.type_at(i + 2)}" if val.type != arg_type.type_at(i + 2)
list_reg = use_reg(:NamedList , arguments )
add_slot_to_reg( "Set arg #{i}:#{arg}" , :new_message , :arguments , list_reg )
# which we load int the new_message at the argument's index
add_reg_to_slot( arg , val , list_reg , i + 2 ) #one for type and one for ruby
store_arg_no(arguments , arg_type , arg , i + 1) #+1 for ruby(0 based)
end
end
def store_arg_no(arguments , arg_type , arg , i )
reset_regs
i = i + 1 # disregarding type field
val = process( arg) # processing should return the register with the value
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
#FIXME definately needs some tests
raise "TypeMismatch calling with #{val.type} , instead of #{arg_type.type_at(i)}" if val.type != arg_type.type_at(i)
list_reg = use_reg(:NamedList , arguments )
add_slot_to_reg( "Set arg #{i}:#{arg}" , :new_message , :arguments , list_reg )
# which we load int the new_message at the argument's index
add_reg_to_slot( arg , val , list_reg , i ) #one for type and one for ruby
end
end
end

View File

@ -8,24 +8,26 @@ module Typed
def on_NameExpression statement
name = statement.name
[:self , :space , :message].each do |special|
return send(:"handle_special_#{special}" , statement ) if name == special
return send(:"load_special_#{special}" , statement ) if name == special
end
# either an argument, so it's stored in message
if( index = @method.has_arg(name))
named_list = use_reg :NamedList
ret = use_reg @method.argument_type(index)
#puts "For #{name} at #{index} got #{@method.arguments.inspect}"
add_slot_to_reg("#{statement} load args" , :message , :arguments, named_list )
add_slot_to_reg("#{statement} load #{name}" , named_list , index + 1, ret )
return ret
end
# or a local so it is in the named_list
handle_local(statement)
return load_argument(statement) if( @method.has_arg(name))
load_local(statement)
end
private
def handle_local( statement )
def load_argument(statement)
name = statement.name
index = @method.has_arg(name)
named_list = use_reg :NamedList
ret = use_reg @method.argument_type(index)
#puts "For #{name} at #{index} got #{@method.arguments.inspect}"
add_slot_to_reg("#{statement} load args" , :message , :arguments, named_list )
add_slot_to_reg("#{statement} load #{name}" , named_list , index + 1, ret )
return ret
end
def load_local( statement )
name = statement.name
index = @method.has_local( name )
raise "must define variable '#{name}' before using it" unless index
@ -36,20 +38,20 @@ module Typed
return ret
end
def handle_special_self(statement)
def load_special_self(statement)
ret = use_reg @type
add_slot_to_reg("#{statement} load self" , :message , :receiver , ret )
return ret
end
def handle_special_space(statement)
def load_special_space(statement)
space = Parfait::Space.object_space
reg = use_reg :Space , space
add_load_constant( "#{statement} load space", space , reg )
return reg
end
def handle_special_message(statement)
def load_special_message(statement)
reg = use_reg :Message
add_transfer( "#{statement} load message", Register.message_reg , reg )
return reg