-
Notifications
You must be signed in to change notification settings - Fork 230
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
Place parameter check up top. Prevents varargs, but is more robust. #1107
Comments
Just curious here on the latter part. Are you referring to setting up an external mechanism to make passing LIST()s to functions easier? Or adding something akin to the JavaScript Can definitely think of some uses for the latter (particularly passing "flags" to functions, which couldn't be done using conditional declares). Either way, excited for this :) If I can feature creep a tiny bit...would there be any possibility of allowing functions to be passed as arguments (either directly or through a |
I was considering a means of varargs that make a list for you, not something where you just pass a list, which you can do now. The idea is that it would get the remaining args up to the end, like so:
That would fill A parameterlist would have to come last, only allowing varying args at the end. As for function pointers, it's definitely a doable thing if we just add the syntax for it. Right now we don't just because it wasn't a high priority. |
Oh nice, so just a trailing splat. I like it! |
Do you think that we could also turn the system into named parameters once @erendrake's associative array is finished and merged? Maybe using |
That feels like a significant diversion in language style. It feels like you'll be easily able to do that with |
Good point. Just pass the lex as a parameter itself... Why did I want to make that more complicated? |
Named args is a good language feature, but it's quite a departure from how kerboscript works at the moment. |
So I think I'm going to make a hidden user-land LIST() variable with local function scope that holds all the parameters and gets filled up at the top before you do anything, having popped the stack all the way off, removing all the parameters. Then whenever you do parameter foo, it's just going to eat the head of the list and cut it down. When you hit parameterlist, it will give you what's left in the list. Thus you can't get stack misalignment because it already consumed everything before you even began. |
(Added "Beaks KSM" as a reminder that whatever solution is used, it will change the way the args have to be processed in the stack, which does invalidate old KSM files that had function calls in them.) |
Fixed by #1133 |
@gisikw posted an issue, #1100 which is closed, but I'd still like to address an issue connected to it.
The problem is that since we don't check number of arguments until the bottom of the function, users typically end up seeing complaints about wrong argument types before they see a complaint about mismatched arguments, because passing the wrong number of args causes stack misalignment. (Which IS detected eventually, but not until after it tried using the values that were shifted into the wrong variables, which often causes its own errors that stop it before it gets to the check for missing or too many args).
The entire reason for not checking until the bottom was to allow for clever varying args situations where you execute the
declare parameter
commands conditionally depending on what you see.But I doubt anyone is doing this, and it's preventing us from giving proper error messages out for mismatched argument counts.
I'd like to switch it to a system that requires the declare parameter commands to be "flat" in the outermost nesting level (not contained inside loops or if's), and can throw an error right away when they don't have the right number of arguments to match. I might provide people with an alternate technique where they can get a LIST() of parameters instead if they like to try some vararg logic.
The text was updated successfully, but these errors were encountered: