Commit Graph

93 Commits

Author SHA1 Message Date
Rui Ueyama ce61154cf5 Support file-scope functions 2019-08-20 09:29:09 +09:00
Rui Ueyama 7938157072 Accept `void` as a parameter list
`foo(void)` indicate that function foo does not take a parameter.
2019-08-20 09:29:09 +09:00
Rui Ueyama 1e7c50c454 Allow global variable initializer to have an addend
A global variable can be initialized with an address of other global
variable, so the following code is legal.

  int x[3];
  int &y = x;

In addition to that, an address can have an addend, so the following
code is also legal

  int x[3];
  int &y = x+2;
2019-08-20 09:29:09 +09:00
Rui Ueyama 0b4dcf1f14 Add string literal initializer for global variable 2019-08-20 09:29:09 +09:00
Rui Ueyama c8617ad9b1 Skip excess initializer elements 2019-08-20 09:29:09 +09:00
Rui Ueyama c9dd8d9e7f Allow parentheses in initializers to be omitted 2019-08-20 09:29:09 +09:00
Rui Ueyama 84da4b7bd6 Add array and struct initializers for global variables 2019-08-20 09:29:09 +09:00
Rui Ueyama afaa81c528 Add scalar global initializer 2019-08-20 09:29:09 +09:00
Rui Ueyama 708b20c210 Handle struct initializers for local variables 2019-08-20 09:29:09 +09:00
Rui Ueyama c0b71d15c7 Allow array length to be omitted if an initializer is given
So that you can write something like `int x[] = {1, 2, 3}`
instead of `int x[3] = {1, 2, 3}`.
2019-08-20 09:29:09 +09:00
Rui Ueyama ea010a162b Add string literal initializer 2019-08-20 09:29:09 +09:00
Rui Ueyama b9ffede885 Initialize excess array elements with zero 2019-08-20 09:29:09 +09:00
Rui Ueyama bde480789e Support local variable initializers 2019-08-20 09:29:09 +09:00
Rui Ueyama fb95a97850 Add constant expression 2019-08-20 09:29:09 +09:00
Rui Ueyama b130ba62d0 Add ?: operator 2019-08-20 09:29:09 +09:00
Rui Ueyama 7b2715e902 Add <<, >>, <<= and >>= 2019-08-20 09:29:09 +09:00
Rui Ueyama 69702c1e12 Allow functions returning void 2019-08-20 09:29:09 +09:00
Rui Ueyama 29a9059916 Add switch-case 2019-08-20 09:29:09 +09:00
Rui Ueyama 4c4ff597e6 Add goto and labeled statement 2019-08-20 09:29:09 +09:00
Rui Ueyama e464458b97 Add continue statement 2019-08-20 09:29:09 +09:00
Rui Ueyama fb31bad4cf Add break statement 2019-08-20 09:29:09 +09:00
Rui Ueyama 63f9e536d1 Add a notion of an incomplete struct type 2019-08-20 09:29:09 +09:00
Rui Ueyama 2c121830d3 Implement array-to-pointer decay in the func param context 2019-08-20 09:29:09 +09:00
Rui Ueyama 13dd809190 Add a notion of an incomplete array type 2019-08-20 09:29:09 +09:00
Rui Ueyama 4f07c7e167 Add && and || operators 2019-08-20 09:29:09 +09:00
Rui Ueyama 1ee4aed1f8 Add |, & and ^ operators 2019-08-20 09:29:09 +09:00
Rui Ueyama 989e7eabb1 Add ~ operator 2019-08-20 09:29:09 +09:00
Rui Ueyama 3bd2f40b82 Add ! operator 2019-08-20 09:29:09 +09:00
Rui Ueyama 01a451653c Add +=, -=, *= and /= operators 2019-08-20 09:29:09 +09:00
Rui Ueyama e8fb5f1500 Add ++ and -- operators 2019-08-20 09:29:09 +09:00
Rui Ueyama a628e0d7c6 Add comma operator 2019-08-20 09:29:09 +09:00
Rui Ueyama 9c9cbacc20 Add examples/nqueen.c 2019-08-20 09:29:09 +09:00
Rui Ueyama b8c3c8d3df Allow for-loops to define local variables 2019-08-20 09:29:09 +09:00
Rui Ueyama f282f6f181 Add block-scope global variable, a.k.a. static local variable 2019-08-20 09:29:09 +09:00
Rui Ueyama 898feaba67 Add enum 2019-08-20 09:29:09 +09:00
Rui Ueyama f29b04b32e Add function declaration 2019-08-20 09:29:09 +09:00
Rui Ueyama eb0c092d9d Handle function return type correctly 2019-08-20 09:29:09 +09:00
Rui Ueyama e28e2cbd12 Add char literal 2019-08-20 09:29:09 +09:00
Rui Ueyama b7efb0f5f7 Add type cast 2019-08-20 09:29:09 +09:00
Rui Ueyama f8f0508834 Fix large literal number's type
If a literal number cannot be represented as an int,
it should have type long.
2019-08-20 09:29:09 +09:00
Rui Ueyama 2f394eb800 Make sizeof to accept not only an expression but also a typename
Previously, chibicc's sizeof accepted only an expression, so you
couldn't write something like `sizeof(int)`. Now it accepts that.
2019-08-20 09:29:09 +09:00
Rui Ueyama 1b8715cde6 Handle complex type declarations correctly
chibicc can now read complex type declarations such as below.

  long x;
  long int x;
  int long x;
  short x;
  short int x;
  int short x;

In the following example, `x` is defined as an alias for `int`.

  typedef x;

Below is valid C code where the second `t` is a local variable
of type int having value 3.

  typedef int t;
  t t = 3;
2019-08-20 09:29:09 +09:00
Rui Ueyama df52150246 Add _Bool type 2019-08-20 09:29:09 +09:00
Rui Ueyama 95781b8d80 Add void type 2019-08-20 09:29:09 +09:00
Rui Ueyama 2e6dbb051f Add a return type to a function 2019-08-20 09:29:09 +09:00
Rui Ueyama f27e866b72 Support nested type declarators, e.g., "int (*x)[3]" 2019-08-20 09:29:09 +09:00
Rui Ueyama 12fbefa47e Add short and long types 2019-08-20 09:29:09 +09:00
Rui Ueyama b0ae168045 Change the size of `int` from 8 to 4 2019-08-20 09:29:09 +09:00
Rui Ueyama 3af44cefa6 Add typedef 2019-08-20 09:29:09 +09:00
Rui Ueyama 4d07786d4d Add "->" operator 2019-08-20 09:29:09 +09:00