Crafting Interpreters · Week 16

Crafting Interpreters 29: Superclasses: reading guide

Read the chapterVerified by tests

Inheritance in clox with copy-down inheritance (copy superclass methods into the subclass at definition time), and super calls, including an optimized super invoke instruction.

Time About 4 hours this week

Why it matters

Copy-down is a neat trick that trades flexibility for speed, a classic VM design trade-off.

How to approach it

Short chapter; run the full clox test suite at the end.

Challenges

3 challenges at the end of the chapter.

Challenge 3 (BETA-style inner, again, now in C) is satisfying if you did it in jlox. 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

  • A class inheriting from a non-class value must be a runtime error.

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

Links

Back to week 16