Skip to content

Conversation

@rpkak
Copy link
Contributor

@rpkak rpkak commented Mar 2, 2024

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 and while statements, 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

@rpkak rpkak force-pushed the translate-c-goto branch 2 times, most recently from d0bd7fd to 5a6574e Compare March 8, 2024 06:13
@rpkak rpkak force-pushed the translate-c-goto branch 3 times, most recently from 4509616 to 0e5b47c Compare March 14, 2024 20:33
@rpkak rpkak force-pushed the translate-c-goto branch from d133bdc to c6afab3 Compare March 28, 2024 10:31
@rpkak rpkak force-pushed the translate-c-goto branch from dec5d86 to af875a7 Compare April 4, 2024 19:29
@rpkak
Copy link
Contributor Author

rpkak commented Apr 4, 2024

I think I completed this PR now. It lacks the ability to use goto to jump out of or within a statement expression, but I don't think there is much need for this.
As I stated in a87c470 this PR also fixes ziglang/translate-c#133.
This PR inserts while loops which exist not as while loops in the c code. These loops have the same issues as descripted in ziglang/translate-c#132/#16790.

@rpkak rpkak marked this pull request as ready for review April 4, 2024 19:31
@rpkak rpkak force-pushed the translate-c-goto branch from af875a7 to 98ee9a3 Compare April 13, 2024 06:00
@rpkak rpkak force-pushed the translate-c-goto branch from 98ee9a3 to 714ec76 Compare April 23, 2024 09:06
@mnemnion
Copy link

mnemnion commented May 1, 2024

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.

@rpkak rpkak force-pushed the translate-c-goto branch from 714ec76 to 008e88b Compare May 6, 2024 04:53
@rpkak rpkak force-pushed the translate-c-goto branch from 008e88b to aef621c Compare May 15, 2024 17:17
@rpkak
Copy link
Contributor Author

rpkak commented May 25, 2024

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.
I have not seen any c code snippet, where llvm does not optimize away the goto-variable generated by this PR.

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.

@rpkak rpkak force-pushed the translate-c-goto branch from aef621c to 2de160b Compare May 25, 2024 10:07
@mnemnion
Copy link

mnemnion commented Jun 2, 2024

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.

@rpkak rpkak force-pushed the translate-c-goto branch from 2de160b to c2930a9 Compare June 6, 2024 13:49
@rpkak rpkak force-pushed the translate-c-goto branch from c2930a9 to f3a119e Compare June 16, 2024 12:21
@rpkak rpkak force-pushed the translate-c-goto branch 2 times, most recently from a02a560 to 4ff0e2f Compare July 22, 2024 20:18
@rpkak rpkak force-pushed the translate-c-goto branch from 4ff0e2f to 59e543b Compare August 10, 2024 12:08
@rpkak rpkak force-pushed the translate-c-goto branch from 59e543b to 4d3fb79 Compare August 25, 2024 08:21
@rpkak
Copy link
Contributor Author

rpkak commented Dec 14, 2024

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.

@rpkak rpkak closed this Dec 14, 2024
@rpkak rpkak deleted the translate-c-goto branch December 14, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

translate-c: support goto

2 participants