Starting to rework slot instructions that create risc

have to go through all and all macros and all thems tests. What did the wise man say: one step at a time
This commit is contained in:
2020-03-01 16:41:58 +02:00
parent 4643be0ae6
commit 4888b3b6db
14 changed files with 73 additions and 44 deletions

View File

@ -19,10 +19,11 @@ module Risc
# a new regsister will be created as the result, ie the reg part for slot_to_reg
def self.slot_to_reg( source , array , index )
raise "Register #{array}" if RegisterValue.look_like_reg(array.symbol)
new_name = "#{array.symbol}.#{index.to_s.downcase}".to_sym
index = array.resolve_index(index) if index.is_a?(Symbol)
type = array.type_at(index)
#puts "Slot for #{array.symbol}@ index #{index} is #{type}"
to = RegisterValue.new( "#{array.symbol}.#{type.to_s.downcase}".to_sym , type )
to = RegisterValue.new( new_name , type )
SlotToReg.new( source , array , index , to)
end
end

View File

@ -25,17 +25,25 @@ module Risc
def <<( reg )
case reg
when RegisterValue
puts reg.symbol
to_mem("#{reg.class_name} -> #{register.class_name}[#{index}]" , reg)
when RegisterSlot
puts reg.register.symbol
reg = to_reg("reduce #{@register.symbol}[@index]")
to_mem("#{reg.class_name} -> #{register.class_name}[#{index}]" , reg)
to_mem("#{reg.class_name} -> #{register.class_name}[#{index}]" , reg)
else
raise "not reg value or slot #{reg}"
end
end
# for chaining the array operator is defined here too.
# It basically reduces the slot to a register and applies the [] on that reg.
# thus returning a new RegisterSlot.
# Example: message[:caller][:next_message]
# message[:caller] returns a RegisterSlot, which would be self for this example
# to evaluate self[:next_message] we reduce self to a register with to_reg
def [](index)
reg = to_reg("reduce #{@register.symbol}[@index]")
reg[index]
end
# push the given register into the slot that self represents
# ie create a slot_to_reg instruction and add to the compiler
# the register represents and "array", and the content of the
@ -47,7 +55,7 @@ module Risc
end
# load the conntent of the slot that self descibes into a a new register.
# the regsiter is created, and the slot_to_reg instruction added to the
# the register is created, and the slot_to_reg instruction added to the
# compiler. the return is a bit like @register[@index]
def to_reg(source )
slot_to_reg = Risc.slot_to_reg(source , register, index)

View File

@ -82,7 +82,6 @@ module Risc
new_type , extra = compiler.slot_type(slot , type) unless new_type
new_name = "#{@symbol}.#{slot}"
raise "no #{self}" if RegisterValue.look_like_reg(@symbol)
puts "New name #{new_name}"
new_left = RegisterValue.new( new_name.to_sym , new_type , extra)
new_left
end