rustgd / vnodes

[Experimental] Virtual node system
Apache License 2.0
6 stars 0 forks source link

Passing multiple args to a function #4

Open torkleyy opened 6 years ago

torkleyy commented 6 years ago

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:

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 commented 6 years ago

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.