Skip to content
This repository has been archived by the owner on Jul 4, 2022. It is now read-only.

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

Open
exp-table opened this issue May 29, 2022 · 2 comments
Open

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

exp-table opened this issue May 29, 2022 · 2 comments

Comments

@exp-table
Copy link
Collaborator

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.

@d1ll0n
Copy link
Contributor

d1ll0n commented May 31, 2022

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

@exp-table
Copy link
Collaborator Author

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants