clean up Get/SetSlot
document and make arguments consistent
This commit is contained in:
@ -1,16 +1,28 @@
|
||||
module Register
|
||||
# offset memory get access
|
||||
# so the value to be set must be given as the first register
|
||||
# the second argument holds the base address
|
||||
# and the third a possible (small) offset into the "object"
|
||||
|
||||
# GetSlot moves data into a register from memory.
|
||||
# SetSlot moves data into memory from a register.
|
||||
# Both use a base memory (a register)
|
||||
|
||||
# While the virtual machine has only one instruction (Set) to move data between slots,
|
||||
# the register has two, namely GetSlot and SetSlot
|
||||
#
|
||||
# if for example the value is pointed to by a register, a VariableGet (load) is needed first
|
||||
# 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.
|
||||
|
||||
# btw: to move data between registers, use RegisterTransfer
|
||||
|
||||
class GetSlot < Instruction
|
||||
def initialize value , reference , index = 0
|
||||
@value = value
|
||||
@reference = reference
|
||||
|
||||
# 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 Instruciton name
|
||||
# So GetSlot means the slot (array and index) moves to the register (last argument)
|
||||
def initialize array , index , register
|
||||
@register = register
|
||||
@array = array
|
||||
@index = index
|
||||
end
|
||||
attr_accessor :value , :reference , :index
|
||||
attr_accessor :register , :array , :index
|
||||
end
|
||||
end
|
||||
|
@ -1,7 +1,14 @@
|
||||
module Register
|
||||
|
||||
#transfer the constents of one register to another. possibly called move in some cpus
|
||||
# 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
|
||||
|
||||
# Get/Set Slot move data around in vm objects, but transfer moves the objects (in the machine)
|
||||
#
|
||||
# Also it is used for moving temorary data
|
||||
|
||||
class RegisterTransfer < Instruction
|
||||
def initialize from , to
|
||||
@from = wrap_register(from)
|
||||
@ -9,4 +16,4 @@ module Register
|
||||
end
|
||||
attr_reader :from, :to
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,16 +1,27 @@
|
||||
module Register
|
||||
# offset memory set access
|
||||
# so the value must be given as the first register
|
||||
# the second argument holds the base address
|
||||
# and the third a possible (small) offset into the "object"
|
||||
|
||||
# SetSlot moves data into memory from a register.
|
||||
# GetSlot moves data into a register from memory.
|
||||
# Both use a base memory (a register)
|
||||
|
||||
# While the virtual machine has only one instruction (Set) to move data between slots,
|
||||
# the register has two, namely GetSlot and SetSlot
|
||||
#
|
||||
# if for example the value is pointed to by a register, a VariableGet (load) is needed first
|
||||
# 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.
|
||||
|
||||
# btw: to move data between registers, use RegisterTransfer
|
||||
|
||||
class SetSlot < Instruction
|
||||
def initialize value , reference , index = 0
|
||||
@value = value
|
||||
@reference = reference
|
||||
|
||||
# If you had a c array and index offset
|
||||
# the instruction would do array[index] = register
|
||||
# So SGetSlot means the register (first argument) moves to the slot (array and index)
|
||||
def initialize register , array , index
|
||||
@register = register
|
||||
@array = array
|
||||
@index = index
|
||||
end
|
||||
attr_accessor :value , :reference , :index
|
||||
attr_accessor :register , :array , :index
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user