Skip to content

Variadic calls and functions #48

@p7g

Description

@p7g

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions