Remix.run Logo
int_19h 2 days ago

> I've been using it as an experimental backend for my language project with great results.

One annoyance that I've ran into when using Zig as a transpiler backend is the lack of unstructured goto. Many languages don't need that, but if you're dealing with the one that does, converting such code is non-trivial.

olivia-banks 2 days ago | parent | next [-]

Yeah, this is one of the bigger pain points (that and no dynamic stack allocation). I got around this by defining anonymous functions and then calling between them (using `@call(.always-tail, ...)` where possible to avoid stack-frame overhead).

Eventually, I restructured my IR to allow for more imperative code-generation, which I believe will lead to slightly better optimizations by the compiler.

hansvm a day ago | parent | prev [-]

Labeled switches come pretty close. Is there a particular case you have in mind where they don't suffice?

int_19h 41 minutes ago | parent [-]

Ah, I wasn't aware of those - they seem to be a fairly recent addition? It definitely does simplify things for many common patterns, but not all, unfortunately; consider the case of a goto into the middle of a loop in C, or even something like Duff's Device.