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
@ -21,7 +21,7 @@ module Risc
|
||||
# or then the methods arg or frame
|
||||
def slot_type_for(name)
|
||||
if @block.arguments_type.variable_index(name)
|
||||
slot_def = [ :arguments]
|
||||
slot_def = [:arguments]
|
||||
elsif @block.frame_type.variable_index(name)
|
||||
slot_def = [:frame]
|
||||
elsif @method.arguments_type.variable_index(name)
|
||||
@ -34,19 +34,17 @@ module Risc
|
||||
slot_def << name
|
||||
end
|
||||
|
||||
# resolve a symbol to a type. Allowed symbols are :frame , :receiver and arguments
|
||||
# which return the respective types, otherwise nil
|
||||
def resolve_type( name )
|
||||
case name
|
||||
when :frame
|
||||
return @block.frame_type
|
||||
when :arguments
|
||||
return @block.arguments_type
|
||||
when :receiver
|
||||
return @block.self_type
|
||||
else
|
||||
return nil
|
||||
end
|
||||
# return the frame type, ie the blocks frame type
|
||||
def frame_type
|
||||
@block.frame_type
|
||||
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
|
||||
|
@ -183,8 +183,12 @@ module Risc
|
||||
case object
|
||||
when :name
|
||||
type = Parfait.object_space.get_type_by_class_name( :Word )
|
||||
when :frame , :arguments , :receiver
|
||||
type = compiler.resolve_type(object)
|
||||
when :frame
|
||||
type = compiler.frame_type
|
||||
when :arguments
|
||||
type = compiler.arg_type
|
||||
when :receiver
|
||||
type = compiler.receiver_type
|
||||
when :message , :next_message , :caller
|
||||
type = Parfait.object_space.get_type_by_class_name(:Message)
|
||||
when Parfait::Object
|
||||
@ -207,7 +211,14 @@ module Risc
|
||||
# Third arg, compiler, is only needed to resolve receiver/arguments/frame
|
||||
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)
|
||||
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
|
||||
#puts "TYPE #{type} obj:#{object} var:#{variable_name} comp:#{compiler}"
|
||||
index = type.variable_index(variable_name)
|
||||
|
@ -63,7 +63,7 @@ module Risc
|
||||
message[:receiver] << space
|
||||
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)
|
||||
builder.build do
|
||||
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
|
||||
def slot_type( slot , type)
|
||||
case slot
|
||||
when :frame , :arguments , :receiver
|
||||
new_type = self.resolve_type(slot)
|
||||
when :frame
|
||||
new_type = self.frame_type
|
||||
when :arguments
|
||||
new_type = self.arg_type
|
||||
when :receiver
|
||||
new_type = self.receiver_type
|
||||
when Symbol
|
||||
new_type = type.type_for(slot)
|
||||
raise "Not found object #{slot}: in #{type}" unless new_type
|
||||
|
@ -74,19 +74,18 @@ module Risc
|
||||
ret
|
||||
end
|
||||
|
||||
# resolve a symbol to a type. Allowed symbols are :frame , :receiver and arguments
|
||||
# which return the respective types, otherwise nil
|
||||
def resolve_type( name )
|
||||
case name
|
||||
when :frame
|
||||
return @method.frame_type
|
||||
when :arguments
|
||||
return @method.arguments_type
|
||||
when :receiver
|
||||
return @method.self_type
|
||||
else
|
||||
return nil
|
||||
end
|
||||
|
||||
# return the frame type, ie the method frame type
|
||||
def frame_type
|
||||
@method.frame_type
|
||||
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
|
||||
|
||||
# convert the given mom instruction to_risc and then add it (see add_code)
|
||||
|
@ -70,7 +70,7 @@ module Vool
|
||||
@my_type = type
|
||||
end
|
||||
def slot_definition(compiler)
|
||||
@my_type = compiler.resolve_type(:receiver)
|
||||
@my_type = compiler.receiver_type
|
||||
Mom::SlotDefinition.new(:message , [:receiver])
|
||||
end
|
||||
def ct_type
|
||||
|
@ -72,7 +72,7 @@ module Vool
|
||||
# - 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
|
||||
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)
|
||||
simple_call(compiler)
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user