Exercise 2: The 256-Constant Ceiling, Through the Real Compiler — Possible Solution ==================================================================== THE SETUP ------------------------------ def build_flat_sum(n): node = Literal(1.0, line=1) for i in range(n - 1): node = Binary(node, '+', Literal(float(i), line=1), line=1) return node tree_256 = build_flat_sum(256) # 256 distinct literal values tree_300 = build_flat_sum(300) # 300 distinct literal values RESULTS ------------------------------ Compiler().compile(tree_256) -> succeeds, 256 constants in the pool Compiler().compile(tree_300) -> ValueError: byte must be in range(0, 256) WHY THIS WORKS AS AN ANSWER ------------------------------ The exact same ceiling from Chapter 2 -- and the exact same error message -- shows up here too, and that's not a coincidence: it's the same underlying chunk.add_constant() call, hit the same way, just triggered by a real AST walk instead of a hand-written loop. This chapter's Compiler doesn't add any new protection against the ceiling and doesn't need to -- Chapter 2 already established WHY the limit exists (a single-byte operand for OP_CONSTANT), and this exercise confirms that limit applies unconditionally to any chunk, regardless of whether it was hand-assembled or produced by walking a real Wisp expression tree. A Wisp program with 257 or more distinct literal values anywhere in a single compiled unit will hit this today, exactly as documented in Chapter 2's own tip-box -- this course still doesn't implement the wider-operand fix real VMs use (an OP_CONSTANT_LONG variant), since no exercise or capstone in this course actually needs more than 256 distinct constants in one chunk.