|
|
|
|
|
by Merad
3478 days ago
|
|
> I am curious as to where you heard this. Modifying the stack in place seems like an implementation detail. You are correct, but as the other reply mentioned, when we're talking about abstract specifications a stack typically doesn't allow reads and writes to arbitrary indices, therefore a stack machine can't perform an in-place swap. The implementation will almost certainly optimize the operation as you're describing, but I'd still expect to see a swap operation defined as "pop pop push push". Likewise I would usually expect to see an add described as popping two arguments and pushing one result, even thought the implementation probably pops one argument, then reads the second and overwrites it with the result. In short, it's the abstract description of the thing vs the actual implementation. |
|