rename also get_slot, to slot_to_reg
makes source and target clear
This commit is contained in:
@ -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
|
||||
|
||||
|
@ -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}" )
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
#
|
||||
|
@ -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
|
@ -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
|
||||
|
Reference in New Issue
Block a user