Crafting Interpreters · Week 15

Crafting Interpreters 27: Classes and Instances: reading guide

Read the chapterVerified by tests

Classes and instances in clox: class objects, instance objects with a fields hash table, and get and set property instructions.

Time About 6 hours this week

Why it matters

Shows the real cost of dynamic objects: every field access is a hash lookup, which is why engines like V8 invented hidden classes.

How to approach it

Remember to mark new object types in the GC. Run under stress GC again.

Challenges

4 challenges at the end of the chapter.

Challenges 1 (handling missing fields gracefully), 2 (dynamic field access by string) and 3 (deleting fields) all involve language design choices; pick one. Challenge 4 asks about faster field access, which connects to hidden classes.

Traps

  • Forgetting to blacken new object types in the GC, which causes use-after-free bugs.

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

Links

Back to week 15