munificent / craftinginterpreters

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

Increasing the locals and up values limit up to UINT16_MAX + 1 #886

Closed mcfriend99 closed 3 years ago

mcfriend99 commented 3 years ago

Hi @munificent,

I am trying to raise the Locals and UpValues limit to UINT16_MAX + 1.

I have tried:

Every approach gives the same problem. THEY CAN'T RUN CLOSURES.

Closures always throw a SEGMENTATION_ERROR and running them though the lldb shows that they all exit during markCompilerRoots's call to markObject.

Please what is the best approach to achieve a UINT16_MAX + 1 like Java or undefined (technically 2^32) like python limit for locals and upvalues (I don't believe either has a concept of upvalues).

Do you have a sample code you can share??

Regards.

munificent commented 3 years ago

I don't have code for this lying around, but it should be possible to make it work. Things you will need to keep in mind:

  1. Make sure to explicitly initialize the array pointer to NULL.
  2. When the garbage collector marks the arrays (both in the compiler and in ObjClosure), make sure to check to see if that array is NULL. Also make sure to walk those arrays and mark all of their entries. Don't mark unused slots in the array since they may have stale pointers to freed objects.
  3. Don't forget to free the arrays when you're done with them.

It's really useful if you haven't already to learn to step through code in a debugger so you can see exactly where it is crashing and what is in memory when that happens. llbd is fine, though I personally prefer IDE debuggers like XCode. You can solve this, but it may take some work to iron out all the bugs. Dealing with garbage collectors and dynamic memory management is tricky for all us. I ran into many many bugs and crashes when I was writing this. :)