huffc
huffc copied to clipboard
feat(compiler): function to push bytecode size onto the stack
In order to support arbitrary-sized arrays as arguments of the constructor, we have to know the bytecode size beforehand, so we can use it along with the CODESIZE opcode to parse the arguments bits.
Following an exchange with @JetJadeja on Twitter, a potential solution is to define a reserved keyword, which the compiler knows to replace with a PUSH operation of the bytecode size.
I have a working PoC here. We probably want to change the keyword as I am using scodesize__, along with OperationType.SCODESIZE and the replacement that is done at the end of the compile function.
We have the __codesize built-in function, would that work if you gave MAIN as the input?
I think that __codesize is not supported yet by huffc? Plus, it only gives you the size of a macro, so we would need to call it for both MAIN and CONSTRUCTOR then add the two values (3 operations) vs just 1 if we inject the bytecode size directly.
What do you think?