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
taskfunc -> return and out params don't work correctly #217
Comments
I dug into the return issue a little further and basically this is what the compiled code looks like:
The tf function is the same for both, it's just the caller that changes. Essentially what is happening is that 2 spots in the frame are being allocated -- first, one spot (sp - 1) for the return value, and second, one spot (sp - 2) for the argument. In the CB that doesn't assign the return value, it thinks "oh I don't need two slots because I don't care about the return value, I just need 1 slot for the argument", so it puts the argument in sp - 1 instead of sp - 2. But the function doesn't mimic this behavior, and still tries to read the argument from sp - 2, thus getting a 0 because nothing was put there. So the solution is to ensure that the structure of the frame doesn't change, and a spot for the return value is still allocated, regardless if it will end up being used. Not sure what would need to change in the repository for that to happen. |
@Reid115 I may have a fix for the first issue that you reported here (the return value not being used messing with stack pointer offset). However I am unsure what's the impact on existing scripts out there, so this would require a lot of testing. The diff goes like this: In
with these:
See what happens! |
As for the other issue you outlined, I am inclined to agree with your assumption:
Yeah they are only supposed to be assigned to. If you wanted to do what you're doing in that second example you posted, you're supposed to use the |
The TCM manual states that, when calling taskfuncs that have a return value, assigning that value to something is optional. However, if you don't assign it to something, for some reason none of the parameters in the call will be read (and they will all be set to 0). Example:
When you click the switch, it will print out "0". If you replace the tf call line with the line above it that sets the return value to i, you will see the correct "123" printed out.
Another problem is with out parameters. I could be wrong, but I assume that out params are supposed to be initialized to zero. But they're actually remembering whatever the ending value was the last time the taskfunc was called. Example:
If you press the switch again and again, the numbers being printed out will be 1, 2, 3, 4, 5, etc... whereas it should keep printing out 1. Perhaps out params are only supposed to be assigned to, I'm not sure.
The text was updated successfully, but these errors were encountered: