Skip to content
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

Tranlate c fixes #695

Merged
merged 3 commits into from Jan 16, 2018
Merged

Tranlate c fixes #695

merged 3 commits into from Jan 16, 2018

Conversation

Hejsil
Copy link
Sponsor Contributor

@Hejsil Hejsil commented Jan 16, 2018

A few fixes/additions to translate-c

  • Undefined C variables now get initialized to undefined in Zig.
  • If statements on floats and ints in C, are now translated to working Zig code. The code generated seems to be the simplest code, that both handles ints and floats. Sadly, this doesn't work on nullable pointers (or pointers, but every pointer becomes nullable in translation).

I can see, that translate_c puts ; behind every statement. This is actually not always valid in Zig.

test "" {
    // error: invalid token: ';'
    if (true) { };
}

I was considering making translate_c only sometimes output semicolon, but I didn't actually know if Zig is supposed to accept the use case above (All tests a written with the semicolon, so maybe it's supposed to work?)

@andrewrk
Copy link
Member

(All tests a written with the semicolon, so maybe it's supposed to work?)

I think this is a flaw in ast_render.cpp. When I made those tests, I figured, better to get the translate-c code working, then fix the rendering code later.

The parser is correct that the semicolon is invalid in the above code. They used to be accepted, until d917815.

Thanks for the patch! I'll wait for the tests to complete and then hit the green button.

@andrewrk andrewrk merged commit ee9ab15 into ziglang:master Jan 16, 2018
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.

None yet

2 participants