-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
translate-c: support goto statements #19146
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
Conversation
d0bd7fd to
5a6574e
Compare
4509616 to
0e5b47c
Compare
|
I think I completed this PR now. It lacks the ability to use |
|
Shouldn't a feature like this wait on #19812? That will be a more performant and general way to translate gotos into Zig, without adding extra conditionals to the code. |
@mnemnion I don't see how #19812 will make this more performant or general. For the translation of c-switch statements, I argree. Translate-c outputs zig code multiple times, if the code is accessible by multiple cases. This PR makes translate-c also output case code once more, if the case is accessed by a goto. But this rewrite would be translate-c-switch specific and not translate-c-goto specific. |
Thanks for the reply. My main intention was to bring that branch to your attention, if you weren't aware of it, I apologize if it came across as second-guessing. Many non-trivial uses of goto are in complex case statements, particularly those implementing a VM dispatch loop, a case (heh) that the labeled continue branch is specifically designed to handle. You say that would constitute a distinct branch? I believe you. Cheers. |
a02a560 to
4ff0e2f
Compare
4ff0e2f to
59e543b
Compare
should fix ziglang/zig#14809
(mostly in combination with statement-expressions)
59e543b to
4d3fb79
Compare
|
I closed this PR because it has not been merged yet, and new features in Zig allow for better code for these changes and the generated code. |
Goto support works by creating a boolean variable per label, which is false by default. A goto changes this variable to
trueand breaks to the highest common scope of the goto and the label. Now,ifandwhilestatements, which are controlled by the boolean variable, jump over the execution part of the code to get to the label.closes ziglang/translate-c#148