munificent / craftinginterpreters

Repository for the book "Crafting Interpreters"
http://www.craftinginterpreters.com/
Other
8.43k stars 1.01k forks source link

Fix string_equality.lox benchmark compile error. #1101

Closed sslees closed 8 months ago

sslees commented 1 year ago

Running the script test/benchmark/string_equality.lox produces 1,700 lines of

[line XXX] Error at 'xX': Too many constants in one chunk.

This is not part of the benchmark test, and the script can't be compiled or executed.

The script is supposed to compare two of eight globals for equality. The reason the script fails to compile is that globals are referenced by name instead of slot. And the identifier constants created for each reference aren't interned either. After a few lines of script source, the compiler runs out of constants for the script's chunk.

An easy fix is to wrap the script in a function and call the function once at the end. That way, all the variable references are local instead of global, and only a few constants are needed to compile the script.