add reg to slot

This commit is contained in:
Torsten Ruger
2018-04-06 20:21:14 +03:00
parent fe71ddc5ae
commit cae5e323ec
5 changed files with 42 additions and 19 deletions

View File

@ -10,9 +10,8 @@ module Risc
def method_missing(*args)
super if args.length != 1
name = args[0].to_s.capitalize.to_sym
Risc.resolve_type(name , @compiler) #checking
reg = @compiler.use_reg( name )
type = Risc.resolve_type(args[0] , @compiler) #checking
reg = @compiler.use_reg( type.object_class.name )
reg.builder = self
reg
end
@ -54,6 +53,8 @@ module Risc
def self.resolve_type( object , compiler )
object = object.type if object.is_a?(RiscValue)
case object
when :typed_method
type = Parfait.object_space.get_class_by_name( :TypedMethod ).instance_type
when :frame
type = compiler.method.frame_type
when :message , :next_message , :caller
@ -65,6 +66,8 @@ module Risc
when Parfait::Object
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
when Symbol
# object = object.to_s.split('_').map(&:capitalize).join.to_sym
object = :Space if object == :space
clazz = Parfait.object_space.get_class_by_name(object)
raise "Not implemented/found object #{object}:#{object.class}" unless clazz
type = clazz.instance_type

View File

@ -64,8 +64,6 @@ module Risc
# - an RValue, which gets procuced by the [] below
def <<( load )
case load
when RValue
raise "not yet"
when Parfait::Object
ins = Risc.load_constant("#{load.class} to #{self.type}" , load , self)
when RiscValue
@ -77,6 +75,14 @@ module Risc
return ins
end
# create a RegToSlot instruction
# right hand must be an RValue
def >>( slot )
raise "not RValue #{slot}" unless slot.is_a?(RValue)
reg_to_slot = Risc.reg_to_slot("#{self.type} -> #{slot.register.type}[#{slot.index}]" , self, slot.register, slot.index)
builder.add_instruction(reg_to_slot) if builder
reg_to_slot
end
# just capture the values in an intermediary object (RValue)
# The RValue then gets used in a RegToSlot ot SlotToReg, where
# the values are unpacked to call Risc.reg_to_slot or Risc.slot_to_reg