Closed AndrewTolmach closed 1 year ago
Yes, that is a bit misleading. I've revised to clarify, first introducing a fully general 3-instruction sequence, and then saying how we can do better with either a single instruction for with 2-instructions depending on whether the first argument is the same as the LHS or not.
p. 25 para 2 says "There are also cases that require special care to avoid generating needlessly complicated code." In fact, special care is required just to generate correct code in some cases, including this example! That is, if we use the initial scheme on
x = y + x
, we'll computex +x
by mistake. So the current wording is a bit misleading. (And subtraction is thornier still, although maybe that is best kept as a nasty surprise for the student.)