rename set_slot

set_slot was clear about the target, but not the source.
Better with reg_to_slot (and soon it’s inverse slot_to_reg)
This commit is contained in:
Torsten Ruger
2016-12-25 18:02:39 +02:00
parent 1b8d6149dd
commit 35adf9a5e6
31 changed files with 126 additions and 115 deletions

View File

@ -65,7 +65,7 @@ module Register
compiler.add_code Register.op( s , ">>" , tmp , const )
# return q + tmp
compiler.add_code Register.op( s , "+" , q , tmp )
compiler.add_code Register.set_slot( s , q , :message , :return_value)
compiler.add_code Register.reg_to_slot( s , q , :message , :return_value)
return compiler.method
end
end

View File

@ -21,11 +21,11 @@ module Register
# Load the message to new message register (r1)
compiler.add_code Register.get_slot( source , space_reg , message_ind , :message)
# And store the space as the new self (so the call can move it back as self)
compiler.add_code Register.set_slot( source, space_reg , :message , :receiver)
compiler.add_code Register.reg_to_slot( source, space_reg , :message , :receiver)
exit_label = Label.new("_exit_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
ret_tmp = compiler.use_reg(:Label)
compiler.add_code Register::LoadConstant.new(source, exit_label , ret_tmp)
compiler.add_code Register.set_slot(source, ret_tmp , :message , :return_address)
compiler.add_code Register.reg_to_slot(source, ret_tmp , :message , :return_address)
# do the register call
compiler.add_code FunctionCall.new( source , Register.machine.space.get_main )
compiler.add_code exit_label
@ -65,7 +65,7 @@ module Register
# load the stored message into the base RegisterMachine
compiler.add_code RegisterTransfer.new(source, r8 , Register.message_reg )
# save the return value into the message
compiler.add_code Register.set_slot( source , return_tmp , :message , :return_value )
compiler.add_code Register.reg_to_slot( source , return_tmp , :message , :return_value )
end
end
extend ClassMethods

View File

@ -16,7 +16,7 @@ module Register
# reduce me to me[index]
compiler.add_code GetSlot.new( source , me , index , me)
# and put it back into the return value
compiler.add_code Register.set_slot( source , me , :message , :return_value)
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
return compiler.method
end
@ -29,7 +29,7 @@ module Register
value = load_arg_at(compiler,source , 2)
# do the set
compiler.add_code SetSlot.new( source , value , me , index)
compiler.add_code RegToSlot.new( source , value , me , index)
return compiler.method
end

View File

@ -25,7 +25,7 @@ module Register
# reduce me to me[index]
compiler.add_code GetByte.new( source , me , index , me)
# and put it back into the return value
compiler.add_code Register.set_slot( source , me , :message , :return_value)
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
return compiler.method
end

View File

@ -119,7 +119,7 @@ end
require_relative "instructions/setter"
require_relative "instructions/getter"
require_relative "instructions/set_slot"
require_relative "instructions/reg_to_slot"
require_relative "instructions/get_slot"
require_relative "instructions/set_byte"
require_relative "instructions/get_byte"

View File

@ -20,7 +20,7 @@ module Register
return_label = Label.new("_return_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
ret_tmp = compiler.use_reg(:Label)
compiler.add_code Register::LoadConstant.new(source, return_label , ret_tmp)
compiler.add_code Register.set_slot(source, ret_tmp , :new_message , :return_address)
compiler.add_code Register.reg_to_slot(source, ret_tmp , :new_message , :return_address)
# move the current new_message to message
compiler.add_code RegisterTransfer.new(source, Register.new_message_reg , Register.message_reg )
# do the register call

View File

@ -1,7 +1,7 @@
module Register
# GetSlot moves data into a register from memory.
# SetSlot moves data into memory from a register.
# RegToSlot moves data into memory from a register.
# Both use a base memory (a register)
# This is because that is what cpu's can do. In programming terms this would be accessing

View File

@ -1,19 +1,19 @@
module Register
# SetSlot moves data into memory from a register.
# RegToSlot moves data into memory from a register.
# GetSlot moves data into a register from memory.
# Both use a base memory (a register)
# This is because that is what cpu's can do. In programming terms this would be accessing
# an element in an array, in the case of SetSlot setting the register in the array.
# an element in an array, in the case of RegToSlot setting the register in the array.
# btw: to move data between registers, use RegisterTransfer
class SetSlot < Setter
class RegToSlot < Setter
# If you had a c array and index offset
# the instruction would do array[index] = register
# So SetSlot means the register (first argument) moves to the slot (array and index)
# So RegToSlot means the register (first argument) moves to the slot (array and index)
# def initialize source , register , array , index
# super
@ -22,14 +22,14 @@ module Register
end
# Produce a SetSlot instruction.
# Produce a RegToSlot instruction.
# From and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.set_slot source , from , to , index
def self.reg_to_slot source , from , to , index
from = resolve_to_register from
index = resolve_index( to , index)
to = resolve_to_register to
SetSlot.new( source, from , to , index)
RegToSlot.new( source, from , to , index)
end
end

View File

@ -3,7 +3,7 @@ module Register
# transfer the constents of one register to another.
# possibly called move in some cpus
# There are other instructions to move data from / to memory, namely GetSlot and SetSlot
# There are other instructions to move data from / to memory, namely GetSlot and RegToSlot
# Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine)
#

View File

@ -1,5 +1,5 @@
module Register
# Setter is a base class for set instructions (SetSlot and SetByte , possibly more coming)
# Setter is a base class for set instructions (RegToSlot and SetByte , possibly more coming)
#
# The instruction that is modelled is loading data from a register into an array
#

View File

@ -144,7 +144,7 @@ module Register
true
end
def execute_SetSlot
def execute_RegToSlot
value = get_register( @instruction.register )
object = get_register( @instruction.array )
if( @instruction.index.is_a?(Numeric) )