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

C99/C11 keyword support #43

Open
tgtakaoka opened this issue May 3, 2018 · 7 comments
Open

C99/C11 keyword support #43

tgtakaoka opened this issue May 3, 2018 · 7 comments

Comments

@tgtakaoka
Copy link
Contributor

It is great if nesc can support some of C99 and C11 reserved keywords, for instance restrict, _Noreturn, and _Bool.

While I tried the latest nesc and tinyos with the beta release of TI MSP430-GCC which is based on gcc 7.3, I noticed that restrict and _Noreturn weren't processed correctly by nesc and caused errors. I worked around errors by making those keywords as empty string. But supporting those keywords in nesc is apparently preferable.

TinyOS defines bool as uint8_t in tos.h, but defining it as _Bool may utilize further compiler optimization. nx_bool has similar definition too. So it is highly preferable for nesc to support _Bool type.

@cire831
Copy link
Member

cire831 commented May 4, 2018

cool.

i don't understand how this stuff works in nesc and am buried in getting a release of the msp432/arm cortex-4mf based mammark code out.

is this simple to do following the proposed commits that david has done?

@tgtakaoka
Copy link
Contributor Author

Thank you for being interested in. In order to support

  1. restrict, as I commented in pull request#42, a simple text substitution seems enough.

  2. _Noreturn, adding it as one of storage class specification (SCSPEC) seems work. The change is such like adding a few lines. I'm happy to upload a pull request once I could prepare a regression test case.

  3. _Bool, adding it as one of a primitive type (TYPESPEC) seems work, The change is not a simple but rather straightforward (adding a dozen of lines). I'll upload a pull request once I can come up with a regression test case.

@dgay42
Copy link
Member

dgay42 commented May 4, 2018

Adding _Bool is definitely not going to be completely straightforward, e.g., from an extremely brief perusal of the C standard:
6.3.1.2 Boolean type: When any scalar value is converted to _Bool, the result is 0 if the value compares equal to 0; otherwise, the result is 1.

nesC does constant folding, so will need to implement this rule.

@cire831
Copy link
Member

cire831 commented May 4, 2018 via email

@tgtakaoka
Copy link
Contributor Author

Thank you for your precious insight, David.
I'll look into constant folding code in nesc and try implementing _Bool handling.

@tgtakaoka
Copy link
Contributor Author

And I pull-requested the change to support _Noreturn. It is great if you can review it.

@tgtakaoka
Copy link
Contributor Author

tgtakaoka commented May 13, 2018

For constant folding of _Bool, as far as I can tell, since _Bool constant is parsed as int, constant folding of _Bool is already correctly handled by nesc without further modification (except an issue I found with fixing).

Anyway I created a pull request for _Bool handling. It is great if you can take a look.

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

No branches or pull requests

3 participants