refactor a bit for upcoming delegations
must get method to be private more tell, not ask
This commit is contained in:
parent
06e78a7326
commit
63b55f2aa4
@ -171,7 +171,11 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# The first arg is a class name (possibly lowercase) and the second an instance variable name.
|
# resolve a symbol to a type. In the simplest case the sybbol is the class name
|
||||||
|
# But in building sometimes variations are needed, so next_message or caller work
|
||||||
|
# too (and return Message)
|
||||||
|
# Also objects work, in which case the instance_type of their class is returned
|
||||||
|
# An error is raised if the symbol/object can not be resolved
|
||||||
def self.resolve_type( object , compiler )
|
def self.resolve_type( object , compiler )
|
||||||
object = object.type if object.is_a?(RegisterValue)
|
object = object.type if object.is_a?(RegisterValue)
|
||||||
case object
|
case object
|
||||||
@ -205,7 +209,8 @@ 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 = resolve_type(object , compiler)
|
type = compiler.resolve_type( object) if compiler
|
||||||
|
type = resolve_type(object , compiler) unless type
|
||||||
index = type.variable_index(variable_name)
|
index = type.variable_index(variable_name)
|
||||||
raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index
|
raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index
|
||||||
return index
|
return index
|
||||||
|
@ -69,6 +69,21 @@ 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
|
||||||
|
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
|
||||||
|
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)
|
||||||
# continue down the instruction chain unti depleted
|
# continue down the instruction chain unti depleted
|
||||||
# (adding moves the insertion point so the whole mom chain is added as a risc chain)
|
# (adding moves the insertion point so the whole mom chain is added as a risc chain)
|
||||||
|
@ -2,6 +2,11 @@ require_relative '../helper'
|
|||||||
|
|
||||||
module Mom
|
module Mom
|
||||||
class CompilerMock
|
class CompilerMock
|
||||||
|
# resolve a symbol to a type. Allowed symbols are :frame , :receiver and arguments
|
||||||
|
# which return the respective types, otherwise nil
|
||||||
|
def resolve_type( name )
|
||||||
|
return nil
|
||||||
|
end
|
||||||
def use_reg( type )
|
def use_reg( type )
|
||||||
Risc.tmp_reg(type , nil)
|
Risc.tmp_reg(type , nil)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user