-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
translate-c: support goto statements #19146
base: master
Are you sure you want to change the base?
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. |
(mostly in combination with statement-expressions)
Goto support works by creating a boolean variable per label, which is false by default. A goto changes this variable to
true
and breaks to the highest common scope of the goto and the label. Now,if
andwhile
statements, which are controlled by the boolean variable, jump over the execution part of the code to get to the label.closes #11992