Dictu
Dictu copied to clipboard
Chunk constant
Currently a chunk is only allowed 255 constants at a time.
I ran into this over the holiday break while writing a language translation module. I'd love to give this a go if that's alright.
That’s absolutely fine @briandowns! I think there are examples of how we could handle this in Wren which I can find for you if you need them.
Yes, please! Any and all help/hints are appreciated. 😀
Ran into this fun one again. Trying some things now. Any points or suggestions are very welcome.
Ah yeah there’s a hard 255 limit at the moment as that’s all we’re allowed to pass with our constant byte code. We’d probably want a new opcode that deals with passing 2 bytes for the index once we get over 255
Bit more context, if we use the same opcode and just change it to be 2 bytes instead:
- https://github.com/dictu-lang/Dictu/blob/develop/src/vm/vm.c#L841 Here we'd change it to READ_SHORT()
Here (and essentially all other places that make constants) we'd need to change it to emit two bytes instead (like how loops work)
- https://github.com/dictu-lang/Dictu/blob/develop/src/vm/compiler.c#L139-L141
int constant = makeConstant(compiler, value);
emitByte(compiler, OP_CONSTANT);
emitBytes((constant >> 8) & 0xff, constant & 0xff);
And then change the check to be the new limit 1 << 16