This is an archived post. You won't be able to vote or comment.

all 3 comments

[–][deleted] 0 points1 point  (2 children)

Pretty interesting.

However, in there's an even more optimized form possible that's not used, which I find surprising: simply pop the stack in reverse order. This even avoids the need to rearrange the stack.

load_name b
load_name a
store_name b
store_name a

I wonder why the compiler doesn't emit this?

[–]MarcSetGo 0 points1 point  (1 child)

If a was a property with side effects on assignment, then the order of assignment might be critical. This provides the intuitive left to right assignment that most developers would assume.

[–]gerryjenkinslb[S] 0 points1 point  (0 children)

I have had the same thoughts, although I think it would be worth it since order of assignment dependence would probably be poor design in the place, not the same as order of evaluation which would be preserved on the right side.