Crafting Interpreters · Week 12

Crafting Interpreters 23: Jumping Back and Forth: reading guide

Read the chapterVerified by tests

Control flow in bytecode: jump instructions with backpatching for if/else, logical operators, while loops with backward jumps, and for loops.

Time About 5 hours this week

Why it matters

Backpatching is how every assembler and compiler resolves forward jumps. You will see it again in real assemblers and in Knuth's MIX.

How to approach it

Disassemble each control structure and draw the jump arrows. Off-by-one jump offsets are the usual bug; the disassembler shows them immediately.

Challenges

3 challenges at the end of the chapter.

Challenge 1 (a switch statement) and challenge 2 (continue) are both excellent. Challenge 3 is an open design question. Do challenges that change Lox's behavior on a separate git branch. The cracked.guide check runs the official test suite for this chapter, and a challenge that changes semantics (new syntax, different errors) can make tests fail on main.

Traps

  • Jump offsets off by the size of the operand bytes.
  • Not popping the condition value on both branches.

Verified by the book's chap23_jumping tests when you push your repo.

Links

Back to week 12