tinyos / nesc

Master nesc repository
GNU General Public License v2.0
100 stars 53 forks source link

C99/C11 keyword support #43

Open tgtakaoka opened 6 years ago

tgtakaoka commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

thanks to both of you.

If we find ourselves in the same place physically, beers all around (or replacement beverage of choice).

On Thu, May 3, 2018 at 9:59 PM, dgay42 notifications@github.com wrote:

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.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/tinyos/nesc/issues/43#issuecomment-386506029, or mute the thread https://github.com/notifications/unsubscribe-auth/AAY46b2XN-GLZDjwI-B5qdlqpkkNUH_Bks5tu-A-gaJpZM4TwjLT .

-- Eric B. Decker Senior (over 50 :-) Researcher

tgtakaoka commented 6 years ago

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

tgtakaoka commented 6 years ago

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

tgtakaoka commented 6 years ago

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.