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

Passing multiple args to a function #4

Open
torkleyy opened this issue May 17, 2018 · 1 comment
Open

Passing multiple args to a function #4

torkleyy opened this issue May 17, 2018 · 1 comment

Comments

@torkleyy
Copy link
Member

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?

@torkleyy torkleyy added the help wanted Extra attention is needed label May 17, 2018
@torkleyy
Copy link
Member Author

I think I'll drop the current way tuples work and replace it by just using a tuple tag consisting of a type tag (Ty::Tuple) and the size, that way we only need to inspect the last element of the stack to see how many we may pop.

@torkleyy torkleyy removed the help wanted Extra attention is needed label May 18, 2018
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