c2lang / c2compiler

the c2 programming language
c2lang.org
Apache License 2.0
704 stars 49 forks source link

Add the following useful build options to C2 #89

Closed lerno closed 5 years ago

lerno commented 5 years ago
  1. Enable/disable 128 bit floating point (enables f128 types, and all constant folding will be calculated using f128 instead of f64. If not set, f128 will be enabled on machines that support f128.
  2. Compile-time stack depth (if we allow recursive macros)
  3. BracketDepth (default 256): how deep brackets can be nested. (From Clang)
  4. IndirectionDepth (default 256): how deep calls . can be nested, e.g. foo().bar().baz().
  5. Enable i128, u128, i256, u256 (same as for f128, but less of a priority)

These should go in the recipe.txt as well.

bvdberg commented 5 years ago

That is one of the issues with C, you have to tweak a lot. For C2 I just want sane values and enforce that, Not allowing any override. I mean, why would anyone want to have a BracketDepth of more then 16? Code like that probably should not exist. There might be some corner-cases for auto-generated code, but still..

All C2 code should just have the same set of options. That way re-using code also works better.

lerno commented 5 years ago

What about f128? Some platforms have native support for it, some doesn’t.

bvdberg commented 5 years ago

I'm not sure. I've never been involved in any application that needed that. Let's just keep it on the backlog and decide later.

lerno commented 5 years ago

@bvdberg what's interesting is what we should do if we see something like:

sizeof(1.0)

In this case, that would be 8 if we use f64 as default, or 16 if we use f128 as default (since we don't have constant sizes and instead use casts)

For integers it's easier

sizeof(1)

Could return the smallest type that can contain it – in this case 1 although admittedly constants are hard to define correctly for sizeof and typeof.