move type resolution to compiler

from risc_value.
also unite mock compilers
This commit is contained in:
Torsten Ruger
2018-07-16 11:46:18 +03:00
parent e3673e579c
commit 3343017dba
12 changed files with 43 additions and 56 deletions

View File

@ -136,7 +136,7 @@ module Risc
case name
when :receiver
message = Risc.message_reg
ret_type = message.resolve_new_type(:receiver, compiler)
ret_type = compiler.slot_type(:receiver, message.type)
ret = compiler.use_reg( ret_type )
add_slot_to_reg(" load self" , message , :receiver , ret )
return ret

View File

@ -65,6 +65,22 @@ module Risc
return reg
end
# resolve the type of the slot, by inferring from it's name, using the type
# 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 Symbol
new_type = type.type_for(slot)
raise "Not found object #{slot}: in #{type}" unless new_type
else
raise "Not implemented object #{slot}:#{slot.class}"
end
#puts "RESOLVE in #{@type.class_name} #{slot}->#{type}"
return new_type
end
def copy( reg , source )
copied = use_reg reg.type
add_code Register.transfer( source , reg , copied )

View File

@ -22,6 +22,7 @@ module Risc
def initialize( reg , type , extra = {})
raise "Not Hash #{extra}" unless extra.is_a?(Hash)
raise "not reg #{reg}" unless self.class.look_like_reg( reg )
raise "No type " unless type
type = Parfait.object_space.get_type_by_class_name(type) if type.is_a?(Symbol)
@type = type
@symbol = reg
@ -53,7 +54,7 @@ module Risc
# overwrite the message)
# We get the type with resolve_new_type
def get_new_left(slot, compiler)
new_type = resolve_new_type(slot , compiler)
new_type = compiler.slot_type(slot , type)
if( @symbol == :r0 )
new_left = compiler.use_reg( new_type )
else
@ -62,22 +63,6 @@ module Risc
new_left
end
# resolve the type of the slot, by inferring from it's name, using the type
# scope related slots are resolved by the compiler
def resolve_new_type(slot, compiler)
case slot
when :frame , :arguments , :receiver
type = compiler.resolve_type(slot)
when Symbol
type = @type.type_for(slot)
raise "Not found object #{slot}: in #{@type}" unless type
else
raise "Not implemented object #{slot}:#{slot.class}"
end
#puts "RESOLVE in #{@type.class_name} #{slot}->#{type}"
return type
end
def to_s
s = "#{symbol}:#{type}"
s += ":#{value}" if value