huffc icon indicating copy to clipboard operation
huffc copied to clipboard

feat(compiler): function to push bytecode size onto the stack

Open exp-table opened this issue 3 years ago • 2 comments
trafficstars

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.

exp-table avatar May 29 '22 09:05 exp-table

We have the __codesize built-in function, would that work if you gave MAIN as the input?

d1ll0n avatar May 31 '22 03:05 d1ll0n

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?

exp-table avatar May 31 '22 08:05 exp-table