rename also get_slot, to slot_to_reg

makes source and target clear
This commit is contained in:
Torsten Ruger
2016-12-25 18:05:39 +02:00
parent 35adf9a5e6
commit f648bf7bd5
32 changed files with 105 additions and 105 deletions

View File

@ -37,7 +37,7 @@ module Arm
ArmMachine.mov( code.to , code.from)
end
def translate_GetSlot( code )
def translate_SlotToReg( code )
ArmMachine.ldr( *slot_args_for(code) )
end

View File

@ -8,7 +8,7 @@ module Register
me = compiler.process( Typed::Tree::NameExpression.new( :self) )
# Load the argument
index = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , 1 , index )
compiler.add_code Register.slot_to_reg(source , :message , 1 , index )
return me , index
end
@ -20,7 +20,7 @@ module Register
# Load the value
def load_arg_at(compiler, source , at)
value = compiler.use_reg :Integer
compiler.add_code Register.get_slot(source , :message , at , value )
compiler.add_code Register.slot_to_reg(source , :message , at , value )
value
end

View File

@ -19,7 +19,7 @@ module Register
compiler.add_code LoadConstant.new(source, space , space_reg)
message_ind = Register.resolve_index( :space , :first_message )
# Load the message to new message register (r1)
compiler.add_code Register.get_slot( source , space_reg , message_ind , :message)
compiler.add_code Register.slot_to_reg( 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.reg_to_slot( source, space_reg , :message , :receiver)
exit_label = Label.new("_exit_label" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )

View File

@ -14,7 +14,7 @@ module Register
source = "get_internal_word"
me , index = self_and_int_arg(compiler,source)
# reduce me to me[index]
compiler.add_code GetSlot.new( source , me , index , me)
compiler.add_code SlotToReg.new( source , me , index , me)
# and put it back into the return value
compiler.add_code Register.reg_to_slot( source , me , :message , :return_value)
return compiler.method

View File

@ -8,10 +8,10 @@ module Register
def putstring context
compiler = Typed::MethodCompiler.new.create_method(:Word , :putstring ).init_method
compiler.add_code Register.get_slot( "putstring" , :message , :receiver , :new_message )
compiler.add_code Register.slot_to_reg( "putstring" , :message , :receiver , :new_message )
index = Parfait::Word.get_length_index
reg = RegisterValue.new(:r2 , :Integer)
compiler.add_code Register.get_slot( "putstring" , :new_message , index , reg )
compiler.add_code Register.slot_to_reg( "putstring" , :new_message , index , reg )
Kernel.emit_syscall( compiler , :putstring )
compiler.method
end

View File

@ -120,7 +120,7 @@ end
require_relative "instructions/setter"
require_relative "instructions/getter"
require_relative "instructions/reg_to_slot"
require_relative "instructions/get_slot"
require_relative "instructions/slot_to_reg"
require_relative "instructions/set_byte"
require_relative "instructions/get_byte"
require_relative "instructions/load_constant"

View File

@ -29,6 +29,6 @@ module Register
# move the current message to new_message
compiler.add_code Register::RegisterTransfer.new(source, Register.message_reg , Register.new_message_reg )
# and restore the message from saved value in new_message
compiler.add_code Register.get_slot(source , :new_message , :caller , :message )
compiler.add_code Register.slot_to_reg(source , :new_message , :caller , :message )
end
end

View File

@ -10,7 +10,7 @@ module Register
# If you had a c array (of int8) and index offset
# the instruction would do register = array[index]
# The arguments are in the order that makes sense for the Instruction name
# So GetSlot means the slot (array and index) moves to the register (last argument)
# So SlotToReg means the slot (array and index) moves to the register (last argument)
# def initialize source , array , index , register
# super
# end

View File

@ -1,6 +1,6 @@
module Register
# Getter is a base class for get instructions (GetSlot and GetByte , possibly more coming)
# Getter is a base class for get instructions (SlotToReg and GetByte , possibly more coming)
#
# The instruction that is modelled is loading data from an array into a register
#
@ -16,7 +16,7 @@ module Register
# If you had a c array and index offset
# the instruction would do register = array[index]
# The arguments are in the order that makes sense for the Instruction name
# So GetSlot means the slot (array and index) moves to the register (last argument)
# So SlotToReg means the slot (array and index) moves to the register (last argument)
def initialize source , array , index , register
super(source)
@array = array

View File

@ -1,7 +1,7 @@
module Register
# RegToSlot moves data into memory from a register.
# GetSlot moves data into a register from memory.
# SlotToReg 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

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 RegToSlot
# There are other instructions to move data from / to memory, namely SlotToReg and RegToSlot
# Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine)
#

View File

@ -1,20 +1,20 @@
module Register
# GetSlot moves data into a register from memory.
# SlotToReg moves data into a register from memory.
# 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
# an element in an array, in the case of GetSlot setting the value in the array.
# an element in an array, in the case of SlotToReg setting the value in the array.
# btw: to move data between registers, use RegisterTransfer
class GetSlot < Getter
class SlotToReg < Getter
# If you had a c array and index offset
# the instruction would do register = array[index]
# The arguments are in the order that makes sense for the Instruction name
# So GetSlot means the slot (array and index) moves to the register (last argument)
# So SlotToReg means the slot (array and index) moves to the register (last argument)
# def initialize source , array , index , register
# super
# end
@ -22,13 +22,13 @@ module Register
end
# Produce a GetSlot instruction.
# Produce a SlotToReg instruction.
# Array and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index.
def self.get_slot source , array , index , to
def self.slot_to_reg source , array , index , to
index = resolve_index( array , index)
array = resolve_to_register array
to = resolve_to_register to
GetSlot.new( source , array , index , to)
SlotToReg.new( source , array , index , to)
end
end

View File

@ -7,8 +7,8 @@ module Register
# interpreting it is not so terribly difficult.
#
# There is a certain amount of basic machinery to fetch and execute the next instruction
# (as a cpu would), and then there is a method for each instruction. Eg an instruction GetSlot
# will be executed by method execute_GetSlot
# (as a cpu would), and then there is a method for each instruction. Eg an instruction SlotToReg
# will be executed by method execute_SlotToReg
#
# The Interpreter (a bit like a cpu) has a state flag, a current instruction and registers
# We collect the stdout (as a hack not to interpret the OS)
@ -126,7 +126,7 @@ module Register
true
end
def execute_GetSlot
def execute_SlotToReg
object = get_register( @instruction.array )
if( @instruction.index.is_a?(Numeric) )
index = @instruction.index

View File

@ -26,7 +26,7 @@ module Typed
return nil unless index
end
# TODO, check type @method.locals[index].type
add_code Register.get_slot(statement , :message , type , named_list )
add_code Register.slot_to_reg(statement , :message , type , named_list )
return Register.reg_to_slot(statement , value , named_list , index )
end
end

View File

@ -7,7 +7,7 @@ module Typed
reset_regs
#move the new message (that we need to populate to make a call) to std register
new_message = Register.resolve_to_register(:new_message)
add_code Register.get_slot(statement, :message , :next_message , new_message )
add_code Register.slot_to_reg(statement, :message , :next_message , new_message )
me = get_me( statement )
type = get_my_type(me)
# move our receiver there
@ -19,7 +19,7 @@ module Typed
do_call(type , statement)
# the effect of the method is that the NewMessage Return slot will be filled, return it
# but move it into a register too
add_code Register.get_slot(statement, :new_message , :return_value , ret )
add_code Register.slot_to_reg(statement, :new_message , :return_value , ret )
ret
end
@ -30,7 +30,7 @@ module Typed
me = process( statement.receiver )
else
me = use_reg @method.for_type
add_code Register.get_slot(statement, :message , :receiver , me )
add_code Register.slot_to_reg(statement, :message , :receiver , me )
end
me
end
@ -67,7 +67,7 @@ module Typed
args_reg = use_reg(:Type , @method.arguments )
list_reg = use_reg(:NamedList , arguments )
add_code Register::LoadConstant.new(name_s, @method , args_reg)
add_code Register.get_slot( name_s , :message , :arguments , list_reg )
add_code Register.slot_to_reg( name_s , :message , :arguments , list_reg )
add_code Register.reg_to_slot( name_s , args_reg , list_reg , 1 )
#FIXME need to set type of locals too. sama sama
@ -83,7 +83,7 @@ module Typed
val = process( arg)
raise "Not register #{val}" unless val.is_a?(Register::RegisterValue)
list_reg = use_reg(:NamedList , arguments )
add_code Register.get_slot( "Set arg #{i}#{arg}" , :message , :arguments , list_reg )
add_code Register.slot_to_reg( "Set arg #{i}#{arg}" , :message , :arguments , list_reg )
# which we load int the new_message at the argument's index (the one comes from c index)
set = Register.reg_to_slot( arg , val , list_reg , i + 1 )
add_code set

View File

@ -15,7 +15,7 @@ module Typed
raise "no such field:#{field_name} for class #{type.inspect}" unless index
value = use_reg(type.type_at(index))
add_code Register.get_slot(statement , receiver , index, value)
add_code Register.slot_to_reg(statement , receiver , index, value)
value
end

View File

@ -14,7 +14,7 @@ module Typed
if( index = @method.has_arg(name))
ret = use_reg @method.argument_type(index)
#puts "For #{name} at #{index} got #{@method.arguments.inspect}"
add_code Register.get_slot(statement , :message , index, ret )
add_code Register.slot_to_reg(statement , :message , index, ret )
return ret
end
# or a local so it is in the named_list
@ -27,15 +27,15 @@ module Typed
index = @method.has_local( statement.name )
raise "must define variable '#{statement.name}' before using it" unless index
named_list = use_reg :NamedList
add_code Register.get_slot(statement , :message , :locals , named_list )
add_code Register.slot_to_reg(statement , :message , :locals , named_list )
ret = use_reg @method.locals_type( index )
add_code Register.get_slot(statement , named_list , index, ret )
add_code Register.slot_to_reg(statement , named_list , index, ret )
return ret
end
def handle_special_self(statement)
ret = use_reg @type
add_code Register.get_slot(statement , :message , :receiver , ret )
add_code Register.slot_to_reg(statement , :message , :receiver , ret )
return ret
end