Closed marekjm closed 8 years ago
Since returns have move semantics, they can be combined with pamv
to write copy-free processing functions; such functions would receive parameters by move, process and return the very same object.
.function: performProcessing
arg 1 0
; do stuff
move 1 0
end
.end
.function: main
new 1 SomeType
frame ^[(pamv 0 1)]
call 1 performProcessing
izero 0
end
.end
This can also be used to move objects to new threads during initialisation.
Add
pamv
instruction to machine's CPU instruction set.This instruction would extend and enhance mechanism used to pass parameters between functions by implementing pass-by-move in addition to value, reference and pointer pass-bys. An object passed by-move as a parameter would be taken out of its source register and put inside the call frame's parameter set. When accessed inside the function it would be taken out of the parameter set instead of being copied.
As can be seen by above description, the semantics of
pamv
would be different from those of other parameter passing instructions. However, I consider this justified by the functionality gained from this addition as moving is a powerful concept; pass-by-value can be implemented atop pass-by-move, while it's not really possible the other way around.