Author Topic: update wk17  (Read 10548 times)

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
update wk17
« on: April 23, 2014, 08:29:28 PM »
Hi,

Current progress on the C2 compiler has focused on the Analyser. Currently there are
over 250 unit tests to make sure it keeps working. Not an easy thing. Recently I've
added some checks for array initializations. While I've been programming C for a long
time, I've never realized just how many details there are to a compiler. Some situations:

    int[]   a;    // @error{definition of variable with array type needs an explicit size or an initializer}
    char[] b;   // @error{definition of variable with array type needs an explicit size or an initializer}

    int[]   c = 10;  // @error{array initializer must be an initializer list}
    char[]  d = 20;  // @error{array initializer must be an initializer list or string literal}
    uint8[] e = 20;  // @error{array initializer must be an initializer list or string literal}

    int[]   f = "foo"; // @error{array initializer must be an initializer list}
    char[]  g = "bar";
    uint8[] h = "faa";

    char[3] i = "bar";
    char[3] j = "hello"; // @error{initializer-string for char array is too long}

and that's just a tiny part.
But with a *Lot* of small steps, we're getting there. Slowly more and more situations
are being handled. While C2 is still a far way from being a full fledged C alternative,
the Analyser part is definitely showing it's advantages over gcc/clang. Getting warnings
about unused struct fields and unused types is very nice!

Hopefully the next update won't take as long as this one...

Bas