split compilers resolve_type into the three possibilities
cleaner code, though temporary it shifts some dirt into the index method. up next
This commit is contained in:
parent
3343017dba
commit
29363e7f72
@ -34,19 +34,17 @@ module Risc
|
|||||||
slot_def << name
|
slot_def << name
|
||||||
end
|
end
|
||||||
|
|
||||||
# resolve a symbol to a type. Allowed symbols are :frame , :receiver and arguments
|
# return the frame type, ie the blocks frame type
|
||||||
# which return the respective types, otherwise nil
|
def frame_type
|
||||||
def resolve_type( name )
|
@block.frame_type
|
||||||
case name
|
|
||||||
when :frame
|
|
||||||
return @block.frame_type
|
|
||||||
when :arguments
|
|
||||||
return @block.arguments_type
|
|
||||||
when :receiver
|
|
||||||
return @block.self_type
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
# return the frame type, ie the blocks arguments type
|
||||||
|
def arg_type
|
||||||
|
@block.arguments_type
|
||||||
|
end
|
||||||
|
# return the frame type, ie the blocks self_type
|
||||||
|
def receiver_type
|
||||||
|
@block.self_type
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -183,8 +183,12 @@ module Risc
|
|||||||
case object
|
case object
|
||||||
when :name
|
when :name
|
||||||
type = Parfait.object_space.get_type_by_class_name( :Word )
|
type = Parfait.object_space.get_type_by_class_name( :Word )
|
||||||
when :frame , :arguments , :receiver
|
when :frame
|
||||||
type = compiler.resolve_type(object)
|
type = compiler.frame_type
|
||||||
|
when :arguments
|
||||||
|
type = compiler.arg_type
|
||||||
|
when :receiver
|
||||||
|
type = compiler.receiver_type
|
||||||
when :message , :next_message , :caller
|
when :message , :next_message , :caller
|
||||||
type = Parfait.object_space.get_type_by_class_name(:Message)
|
type = Parfait.object_space.get_type_by_class_name(:Message)
|
||||||
when Parfait::Object
|
when Parfait::Object
|
||||||
@ -207,7 +211,14 @@ module Risc
|
|||||||
# Third arg, compiler, is only needed to resolve receiver/arguments/frame
|
# Third arg, compiler, is only needed to resolve receiver/arguments/frame
|
||||||
def self.resolve_to_index(object , variable_name ,compiler = nil)
|
def self.resolve_to_index(object , variable_name ,compiler = nil)
|
||||||
return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue)
|
return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue)
|
||||||
type = compiler.resolve_type( object) if compiler
|
case object
|
||||||
|
when :frame
|
||||||
|
type = compiler.frame_type
|
||||||
|
when :arguments
|
||||||
|
type = compiler.arg_type
|
||||||
|
when :receiver
|
||||||
|
type = compiler.receiver_type
|
||||||
|
end if compiler
|
||||||
type = resolve_type(object , compiler) unless type
|
type = resolve_type(object , compiler) unless type
|
||||||
#puts "TYPE #{type} obj:#{object} var:#{variable_name} comp:#{compiler}"
|
#puts "TYPE #{type} obj:#{object} var:#{variable_name} comp:#{compiler}"
|
||||||
index = type.variable_index(variable_name)
|
index = type.variable_index(variable_name)
|
||||||
|
@ -63,7 +63,7 @@ module Risc
|
|||||||
message[:receiver] << space
|
message[:receiver] << space
|
||||||
end
|
end
|
||||||
|
|
||||||
exit_label = Risc.label(compiler.source , "#{compiler.resolve_type(:receiver).object_class.name}.#{compiler.source.name}" )
|
exit_label = Risc.label(compiler.source , "#{compiler.receiver_type.object_class.name}.#{compiler.source.name}" )
|
||||||
ret_tmp = compiler.use_reg(:Label)
|
ret_tmp = compiler.use_reg(:Label)
|
||||||
builder.build do
|
builder.build do
|
||||||
add_load_constant("__init__ load return", exit_label , ret_tmp)
|
add_load_constant("__init__ load return", exit_label , ret_tmp)
|
||||||
|
@ -69,8 +69,12 @@ module Risc
|
|||||||
# scope related slots are resolved by the compiler by methood/block
|
# scope related slots are resolved by the compiler by methood/block
|
||||||
def slot_type( slot , type)
|
def slot_type( slot , type)
|
||||||
case slot
|
case slot
|
||||||
when :frame , :arguments , :receiver
|
when :frame
|
||||||
new_type = self.resolve_type(slot)
|
new_type = self.frame_type
|
||||||
|
when :arguments
|
||||||
|
new_type = self.arg_type
|
||||||
|
when :receiver
|
||||||
|
new_type = self.receiver_type
|
||||||
when Symbol
|
when Symbol
|
||||||
new_type = type.type_for(slot)
|
new_type = type.type_for(slot)
|
||||||
raise "Not found object #{slot}: in #{type}" unless new_type
|
raise "Not found object #{slot}: in #{type}" unless new_type
|
||||||
|
@ -74,19 +74,18 @@ module Risc
|
|||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
|
||||||
# resolve a symbol to a type. Allowed symbols are :frame , :receiver and arguments
|
|
||||||
# which return the respective types, otherwise nil
|
# return the frame type, ie the method frame type
|
||||||
def resolve_type( name )
|
def frame_type
|
||||||
case name
|
@method.frame_type
|
||||||
when :frame
|
|
||||||
return @method.frame_type
|
|
||||||
when :arguments
|
|
||||||
return @method.arguments_type
|
|
||||||
when :receiver
|
|
||||||
return @method.self_type
|
|
||||||
else
|
|
||||||
return nil
|
|
||||||
end
|
end
|
||||||
|
# return the frame type, ie the method arguments type
|
||||||
|
def arg_type
|
||||||
|
@method.arguments_type
|
||||||
|
end
|
||||||
|
# return the frame type, ie the method self_type
|
||||||
|
def receiver_type
|
||||||
|
@method.self_type
|
||||||
end
|
end
|
||||||
|
|
||||||
# convert the given mom instruction to_risc and then add it (see add_code)
|
# convert the given mom instruction to_risc and then add it (see add_code)
|
||||||
|
@ -70,7 +70,7 @@ module Vool
|
|||||||
@my_type = type
|
@my_type = type
|
||||||
end
|
end
|
||||||
def slot_definition(compiler)
|
def slot_definition(compiler)
|
||||||
@my_type = compiler.resolve_type(:receiver)
|
@my_type = compiler.receiver_type
|
||||||
Mom::SlotDefinition.new(:message , [:receiver])
|
Mom::SlotDefinition.new(:message , [:receiver])
|
||||||
end
|
end
|
||||||
def ct_type
|
def ct_type
|
||||||
|
@ -72,7 +72,7 @@ module Vool
|
|||||||
# - Setting up the next message, with receiver, arguments, and (importantly) return address
|
# - Setting up the next message, with receiver, arguments, and (importantly) return address
|
||||||
# - a CachedCall , or a SimpleCall, depending on wether the receiver type can be determined
|
# - a CachedCall , or a SimpleCall, depending on wether the receiver type can be determined
|
||||||
def to_mom( compiler )
|
def to_mom( compiler )
|
||||||
@receiver = SelfExpression.new(compiler.resolve_type(:receiver)) if @receiver.is_a?(SelfExpression)
|
@receiver = SelfExpression.new(compiler.receiver_type) if @receiver.is_a?(SelfExpression)
|
||||||
if(@receiver.ct_type)
|
if(@receiver.ct_type)
|
||||||
simple_call(compiler)
|
simple_call(compiler)
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user