graphitemaster / gmqcc

An Improved Quake C Compiler
Other
160 stars 28 forks source link

passing on varargs... #86

Open Blub opened 11 years ago

Blub commented 11 years ago

How "unexpected" - as mentioned back in #17 we should actually have a way to pass on multiple varargs. The previously proposed syntax was.

void foo(...count) {
    next_function(...(n)); // pass parameters n..count to next_function
}

Note: this would be limited to be the last parameter in a function call.

Blub commented 11 years ago

About typechecking:

void takestrings(string...) { /* stuff */ }
void myfunc(...) {
    /* code */
    takestrings(...(n)); // This should error unless -fpermissive
    takestrings(...(n, string...)); // tells the compiler "myfunc wasn't restricted but I know what I'm doing here"
}
Blub commented 11 years ago

Recursion issue:

void foo(...) {
    foo(1, ...(0));
}

This essentially requires an infinite amount of parameters, so we'll need a hard upper bound of possible varargs which is bigger than the current limit.

Proposal: --max-variadic-growth=16 would mean you get at most 16 more variadic parameters then you ever explicitly pass to a function. iow the above foo could recurse 16 times since it adds 1 parameter per recursion.

graphitemaster commented 11 years ago

Max variadic depth is a good idea.

graphitemaster commented 11 years ago

I tried the following code and there doesn't seem to be a recursion issue in the compiler, just at runtime. Or is a max-depth already implemented? Looks fine.

graphitemaster commented 11 years ago

Pushing this back to a later milestone since 0.3.0 was released about 5 minutes ago.