clean up Get/SetSlot

document and make arguments consistent
This commit is contained in:
Torsten Ruger
2015-06-21 21:00:16 +03:00
parent f3ee11fca5
commit 836089a249
6 changed files with 56 additions and 26 deletions

View File

@ -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