clean up Get/SetSlot
document and make arguments consistent
This commit is contained in:
parent
f3ee11fca5
commit
836089a249
@ -1,16 +1,28 @@
|
|||||||
module Register
|
module Register
|
||||||
# offset memory get access
|
|
||||||
# so the value to be set must be given as the first register
|
# GetSlot moves data into a register from memory.
|
||||||
# the second argument holds the base address
|
# SetSlot moves data into memory from a register.
|
||||||
# and the third a possible (small) offset into the "object"
|
# 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
|
class GetSlot < Instruction
|
||||||
def initialize value , reference , index = 0
|
|
||||||
@value = value
|
# If you had a c array and index offset
|
||||||
@reference = reference
|
# 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
|
@index = index
|
||||||
end
|
end
|
||||||
attr_accessor :value , :reference , :index
|
attr_accessor :register , :array , :index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
module Register
|
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
|
class RegisterTransfer < Instruction
|
||||||
def initialize from , to
|
def initialize from , to
|
||||||
|
@ -1,16 +1,27 @@
|
|||||||
module Register
|
module Register
|
||||||
# offset memory set access
|
|
||||||
# so the value must be given as the first register
|
# SetSlot moves data into memory from a register.
|
||||||
# the second argument holds the base address
|
# GetSlot moves data into a register from memory.
|
||||||
# and the third a possible (small) offset into the "object"
|
# 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
|
class SetSlot < Instruction
|
||||||
def initialize value , reference , index = 0
|
|
||||||
@value = value
|
# If you had a c array and index offset
|
||||||
@reference = reference
|
# 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
|
@index = index
|
||||||
end
|
end
|
||||||
attr_accessor :value , :reference , :index
|
attr_accessor :register , :array , :index
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -39,11 +39,11 @@ module Register
|
|||||||
ind = Parfait::Space.object_space.get_layout().index_of( kind )
|
ind = Parfait::Space.object_space.get_layout().index_of( kind )
|
||||||
raise "index not found for #{kind}.#{kind.class}" unless ind
|
raise "index not found for #{kind}.#{kind.class}" unless ind
|
||||||
# load the frame/message from space by index
|
# load the frame/message from space by index
|
||||||
new_codes << GetSlot.new( frame_tmp , space_tmp , 5 )
|
new_codes << GetSlot.new( space_tmp , 5 , frame_tmp )
|
||||||
# save the frame in real frame register
|
# save the frame in real frame register
|
||||||
new_codes << RegisterTransfer.new( RegisterReference.frame_reg , frame_tmp )
|
new_codes << RegisterTransfer.new( RegisterReference.frame_reg , frame_tmp )
|
||||||
# get the next_frame
|
# get the next_frame
|
||||||
new_codes << GetSlot.new( frame_tmp , frame_tmp , 2 ) # 2 index of next_frame
|
new_codes << GetSlot.new( frame_tmp , 2 , frame_tmp) # 2 index of next_frame
|
||||||
# save next frame into space
|
# save next frame into space
|
||||||
new_codes << SetSlot.new( frame_tmp , space_tmp , ind)
|
new_codes << SetSlot.new( frame_tmp , space_tmp , ind)
|
||||||
block.replace(code , new_codes )
|
block.replace(code , new_codes )
|
||||||
|
@ -8,10 +8,10 @@ module Register
|
|||||||
# move the current message to new_message
|
# move the current message to new_message
|
||||||
new_codes << RegisterTransfer.new( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER )
|
new_codes << RegisterTransfer.new( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER )
|
||||||
# and restore the message from saved value in new_message
|
# and restore the message from saved value in new_message
|
||||||
new_codes << GetSlot.new( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER , Virtual::MESSAGE_CALLER )
|
new_codes << GetSlot.new( slot::NEW_MESSAGE_REGISTER , Virtual::MESSAGE_CALLER , slot::MESSAGE_REGISTER)
|
||||||
# "roll out" self and frame into their registers
|
# "roll out" self and frame into their registers
|
||||||
new_codes << GetSlot.new( slot::SELF_REGISTER ,slot::MESSAGE_REGISTER , Virtual::MESSAGE_SELF )
|
new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::MESSAGE_SELF , slot::SELF_REGISTER )
|
||||||
new_codes << GetSlot.new( slot::FRAME_REGISTER ,slot::MESSAGE_REGISTER , Virtual::MESSAGE_FRAME )
|
new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::MESSAGE_FRAME , slot::FRAME_REGISTER )
|
||||||
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
|
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
|
||||||
new_codes << FunctionReturn.new( slot::MESSAGE_REGISTER , Virtual::MESSAGE_RETURN_ADDRESS )
|
new_codes << FunctionReturn.new( slot::MESSAGE_REGISTER , Virtual::MESSAGE_RETURN_ADDRESS )
|
||||||
block.replace(code , new_codes )
|
block.replace(code , new_codes )
|
||||||
|
@ -35,7 +35,7 @@ module Register
|
|||||||
if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol))
|
if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol))
|
||||||
move1 = LoadConstant.new( tmp , code.from )
|
move1 = LoadConstant.new( tmp , code.from )
|
||||||
else # while otherwise we "load"
|
else # while otherwise we "load"
|
||||||
move1 = GetSlot.new( tmp , code.from.reg , code.from.index )
|
move1 = GetSlot.new( code.from.reg , code.from.index , tmp )
|
||||||
end
|
end
|
||||||
move2 = SetSlot.new( tmp , to , code.to.index )
|
move2 = SetSlot.new( tmp , to , code.to.index )
|
||||||
block.replace(code , [move1,move2] )
|
block.replace(code , [move1,move2] )
|
||||||
|
Loading…
Reference in New Issue
Block a user