Exercise 2: Reproducing the Raw-Slot Local Bug — Possible Solution ==================================================================== THE REVERT ------------------------------ elif instr == OP_GET_LOCAL: slot = code[frame.ip]; frame.ip += 1 self.stack.append(self.stack[slot]) # reverted -- no frame.base elif instr == OP_SET_LOCAL: slot = code[frame.ip]; frame.ip += 1 self.stack[slot] = self.stack[-1] # reverted -- no frame.base # program: fun identity(n) { return n; } print identity(42); RESULT ------------------------------ [''] (correct answer: ['42']) WHAT'S SITTING AT ABSOLUTE STACK POSITION 0 ------------------------------ Right before identity's own body starts running, the stack (built by the exact same call convention as every other function call) is: stack = [, 42.0] position 0: -- the function value itself position 1: 42.0 -- the one real argument, n identity's own body compiles `return n;` as OP_GET_LOCAL 0 (n was declared as the function's first, and only, local -- slot 0). With the frame.base offset removed, OP_GET_LOCAL 0 reads stack[0] literally -- which is the FUNCTION OBJECT, not the argument. That object gets returned, printed, and stringify()'s own WispFunction branch renders it as "" -- a plausible-looking, entirely wrong answer, with no error or crash anywhere to flag it. WHY THIS WORKS AS AN ANSWER ------------------------------ This confirms the chapter's own central claim precisely: slot numbers were always meant to be relative to "wherever this particular call's arguments start," not absolute positions in the whole stack. Chapter 4 could get away with treating them as the same thing because the top-level script was the only frame that ever existed, so its own base was always 0 -- slot number and stack position happened to be identical by coincidence, not by design. The instant a second frame exists (which happens on literally the FIRST function call this course ever compiles, since even calling a 1-argument function pushes the function value at position 0 first), that coincidence breaks, and "slot 0" stops meaning "absolute position 0" for any frame except the outermost one.