Skip to content

Passing multiple args to a function #4

@torkleyy

Description

@torkleyy

In my rewrite I'm using a Stack (similar to the Lua one) to store values of different types in a plain Vec. This allows me to save unnecessary allocations.

Every time you call a dynamic function, you push the arguments to the stack, the function pops them off again and pushes the return value.

In my current experimentations (PR will follow soon), I've used tuples with the intention to always expect a tuple for function args.

This, however has two disadvantages:

  • exposing the vnodes_push_* functions for tuples to C seems to be rather complicated
  • individually popping off only one element at a time is impossible, we need to pop the whole tuple at once

Why is that a problem? Each segment of a path is basically a u64. So let's say we search for a node /foo/bar/other/meaning/ful/words. The first segment we can pop (that's at the top of the stack) is "foo". So the root node knows it needs to go to the foo node. That's enough, we don't need to know any more. But if we need to pop the whole tuple, we can't pop just a single path segment. We'd need to pop the whole path, provide a rather large buffer for it or even allocate for it. That's not what we want.

Thus, I think we should simply allow to push and pop multiple values to the stack for the function parameters. However, this has a drawback. We can't check if we have all the right types upfront and a node might pop too many elements from the stack. How should we deal with that? Pass an integer indicating the number of arguments?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions