Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variadic calls and functions #48

Open
p7g opened this issue Jan 5, 2025 · 2 comments
Open

Variadic calls and functions #48

p7g opened this issue Jan 5, 2025 · 2 comments

Comments

@p7g
Copy link
Owner

p7g commented Jan 5, 2025

Variadic calls

New opcode OP_CALL_VARARG expects func and arg array on stack.

New opcode OP_ARRAY_CONCAT has one operand for the number of arrays to concatenate. Pops them off the stack, ensures all are arrays, concatenates, pushes result.

func(a, ...b, c);

OP_LOAD_LOCAL("func")
OP_LOAD_LOCAL("a")
OP_ARRAY_FROM_VALUES(1)
OP_LOAD_LOCAL("b")
OP_LOAD_LOCAL("c")
OP_ARRAY_FROM_VALUES(1)
OP_ARRAY_CONCAT(3)
OP_CALL_VARARG

Variadic functions

Somehow build array holding excess arguments... Can't use OP_ARRAY_FROM_VALUES since length isn't know statically; on the other hand, the bytecode doesn't have access to the actual number of arguments, so it's not possible to use a dynamic version of that opcode. Maybe building the array will have to be part of the call opcode.

@p7g
Copy link
Owner Author

p7g commented Jan 5, 2025

The apply and arguments builtins can be used to achieve the same result so this isn't very high priority

@p7g
Copy link
Owner Author

p7g commented Jan 5, 2025

Actually arguments doesn't exist so I'll need to add that

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

No branches or pull requests

1 participant