small refactor on arg loading
This commit is contained in:
parent
fa9807102b
commit
c60949fe24
@ -10,7 +10,7 @@ module Register
|
|||||||
attr_reader :label
|
attr_reader :label
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{self.class.name}: #{label ? label.name : ''}"
|
"#{self.class.name.split("::").last}: #{label ? label.name : ''}"
|
||||||
end
|
end
|
||||||
alias :inspect :to_s
|
alias :inspect :to_s
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ module Register
|
|||||||
attr_accessor :array , :index , :register
|
attr_accessor :array , :index , :register
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{self.class.name}: #{array}[#{index}] -> #{register}"
|
"#{self.class.name.split("::").last}: #{array}[#{index}] -> #{register}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -15,7 +15,7 @@ module Register
|
|||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"Label: #{@name} (#{self.next.class})"
|
"Label: #{@name} (#{self.next.class.name.split("::").last})"
|
||||||
end
|
end
|
||||||
def sof_reference_name
|
def sof_reference_name
|
||||||
@name
|
@name
|
||||||
|
@ -28,7 +28,7 @@ module Register
|
|||||||
attr_accessor :register , :array , :index
|
attr_accessor :register , :array , :index
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"#{self.class.name}: #{register} -> #{array}[#{index}]"
|
"#{self.class.name.split("::").last}: #{register} -> #{array}[#{index}]"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -82,17 +82,21 @@ module Typed
|
|||||||
message = "Arg number mismatch, method=#{arg_type.instance_length - 1} , call=#{arguments.length}"
|
message = "Arg number mismatch, method=#{arg_type.instance_length - 1} , call=#{arguments.length}"
|
||||||
raise message if (arg_type.instance_length - 1 ) != arguments.length
|
raise message if (arg_type.instance_length - 1 ) != arguments.length
|
||||||
arguments.each_with_index do |arg , i |
|
arguments.each_with_index do |arg , i |
|
||||||
|
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
|
reset_regs
|
||||||
# processing should return the register with the value
|
i = i + 1 # disregarding type field
|
||||||
val = process( arg)
|
val = process( arg) # processing should return the register with the value
|
||||||
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
|
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
|
||||||
#FIXME definately needs some tests
|
#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)
|
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 )
|
list_reg = use_reg(:NamedList , arguments )
|
||||||
add_slot_to_reg( "Set arg #{i}:#{arg}" , :new_message , :arguments , list_reg )
|
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
|
# 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
|
add_reg_to_slot( arg , val , list_reg , i ) #one for type and one for ruby
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -8,10 +8,17 @@ module Typed
|
|||||||
def on_NameExpression statement
|
def on_NameExpression statement
|
||||||
name = statement.name
|
name = statement.name
|
||||||
[:self , :space , :message].each do |special|
|
[: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
|
end
|
||||||
# either an argument, so it's stored in message
|
return load_argument(statement) if( @method.has_arg(name))
|
||||||
if( index = @method.has_arg(name))
|
load_local(statement)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_argument(statement)
|
||||||
|
name = statement.name
|
||||||
|
index = @method.has_arg(name)
|
||||||
named_list = use_reg :NamedList
|
named_list = use_reg :NamedList
|
||||||
ret = use_reg @method.argument_type(index)
|
ret = use_reg @method.argument_type(index)
|
||||||
#puts "For #{name} at #{index} got #{@method.arguments.inspect}"
|
#puts "For #{name} at #{index} got #{@method.arguments.inspect}"
|
||||||
@ -19,13 +26,8 @@ module Typed
|
|||||||
add_slot_to_reg("#{statement} load #{name}" , named_list , index + 1, ret )
|
add_slot_to_reg("#{statement} load #{name}" , named_list , index + 1, ret )
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
# or a local so it is in the named_list
|
|
||||||
handle_local(statement)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
def load_local( statement )
|
||||||
|
|
||||||
def handle_local( statement )
|
|
||||||
name = statement.name
|
name = statement.name
|
||||||
index = @method.has_local( name )
|
index = @method.has_local( name )
|
||||||
raise "must define variable '#{name}' before using it" unless index
|
raise "must define variable '#{name}' before using it" unless index
|
||||||
@ -36,20 +38,20 @@ module Typed
|
|||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_special_self(statement)
|
def load_special_self(statement)
|
||||||
ret = use_reg @type
|
ret = use_reg @type
|
||||||
add_slot_to_reg("#{statement} load self" , :message , :receiver , ret )
|
add_slot_to_reg("#{statement} load self" , :message , :receiver , ret )
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_special_space(statement)
|
def load_special_space(statement)
|
||||||
space = Parfait::Space.object_space
|
space = Parfait::Space.object_space
|
||||||
reg = use_reg :Space , space
|
reg = use_reg :Space , space
|
||||||
add_load_constant( "#{statement} load space", space , reg )
|
add_load_constant( "#{statement} load space", space , reg )
|
||||||
return reg
|
return reg
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_special_message(statement)
|
def load_special_message(statement)
|
||||||
reg = use_reg :Message
|
reg = use_reg :Message
|
||||||
add_transfer( "#{statement} load message", Register.message_reg , reg )
|
add_transfer( "#{statement} load message", Register.message_reg , reg )
|
||||||
return reg
|
return reg
|
||||||
|
Loading…
Reference in New Issue
Block a user