Commit Graph

84 Commits

Author SHA1 Message Date
Rui Ueyama
86440068b4 Add &, |, ^, &=, |= and ^= 2020-12-07 12:00:06 +09:00
Rui Ueyama
daa739817c Add % and %= 2020-12-07 12:00:06 +09:00
Rui Ueyama
46a96d6862 Add ~ operator 2020-12-07 12:00:06 +09:00
Rui Ueyama
6b88bcb306 Add ! operator 2020-12-07 12:00:06 +09:00
Rui Ueyama
7df934d2b6 Add hexadecimal, octal and binary number literals 2020-12-07 12:00:06 +09:00
Rui Ueyama
e8ca48cf41 Add post ++ and -- 2020-12-07 12:00:06 +09:00
Rui Ueyama
47f19371f7 Add pre ++ and -- 2020-12-07 12:00:06 +09:00
Rui Ueyama
01a94c04aa Add +=, -=, *= and /= 2020-12-07 12:00:06 +09:00
Rui Ueyama
a4fea2ba3e Allow for-loops to define local variables 2020-12-07 12:00:06 +09:00
Rui Ueyama
736232f3d6 Support file-scope functions 2020-12-07 12:00:05 +09:00
Rui Ueyama
48ba2656fe Add enum 2020-12-07 12:00:05 +09:00
Rui Ueyama
aa0accc75e Add character literal 2020-12-07 12:00:05 +09:00
Rui Ueyama
44bba965cb Add _Bool type
_Bool isn't just a 1-bit integer because when you convert a value
to bool, the result is 1 if the original value is non-zero. This
is contrary to the other small integral types, e.g. char, as you
can see below:

  char x  = 256; // x is 0
  _Bool y = 256; // y is 1
2020-12-07 12:00:05 +09:00
Rui Ueyama
fdc80bc6b5 Handle function argument type conversion 2020-12-07 12:00:05 +09:00
Rui Ueyama
818352acc0 Handle return type conversion 2020-12-07 12:00:05 +09:00
Rui Ueyama
9e211cbf1d Report an error on undefined/undeclared functions 2020-12-07 12:00:05 +09:00
Rui Ueyama
8b430a6c5f Implement usual arithmetic conversion 2020-12-07 12:00:05 +09:00
Rui Ueyama
cfc4fa94c1 Add type cast 2020-12-07 12:00:05 +09:00
Rui Ueyama
cb81a379d9 Use 32 bit registers for char, short and int 2020-12-07 12:00:05 +09:00
Rui Ueyama
67543ea113 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.
2020-12-07 11:59:59 +09:00
Rui Ueyama
a6b82da1ae Add typedef
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;
2020-12-07 11:51:20 +09:00
Rui Ueyama
f46370ef98 Add long long as an alias for long 2020-12-07 11:51:20 +09:00
Rui Ueyama
287906abb8 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;
  long long x;
  long long int x;
2020-12-07 11:51:20 +09:00
Rui Ueyama
8c3503bb94 Add void type 2020-12-07 11:51:20 +09:00
Rui Ueyama
74e3acc296 Add function declaration 2020-12-07 11:51:20 +09:00
Rui Ueyama
a817b23da3 Add nested type declarators 2020-12-07 11:51:18 +09:00
Rui Ueyama
9d48eef58b Add short type 2020-10-15 14:22:16 +09:00
Rui Ueyama
43c2f0829f Add long type 2020-10-15 14:22:16 +09:00
Rui Ueyama
5831edaab3 Change size of int from 8 to 4 2020-10-15 14:22:16 +09:00
Rui Ueyama
bef05432c9 Add struct assignment 2020-10-15 14:22:16 +09:00
Rui Ueyama
11e3841832 Add union 2020-10-15 14:22:16 +09:00
Rui Ueyama
f0a018a7d6 Add -> operator 2020-10-15 14:22:16 +09:00
Rui Ueyama
e1e831ea3e Support struct tags 2020-10-15 14:22:16 +09:00
Rui Ueyama
dfec1157b4 Align local variables 2020-10-15 14:22:16 +09:00
Rui Ueyama
9443e4b8bc Align struct members 2020-10-15 14:22:16 +09:00
Rui Ueyama
f814033d04 Add struct 2020-10-15 14:22:16 +09:00
Rui Ueyama
e6307ad374 Add comma operator
This patch allows writing a comma expression on the left-hand side
of an assignment expression. This is called the "generalized lvalue"
which is a deprecated GCC language extension. I'm implementing it
anyway because it's useful to implement other features.
2020-10-15 14:22:16 +09:00
Rui Ueyama
1c91d1943a Emit .file and .loc assembler directives
With these directives, gdb can print out an error location when
a compiled program crashes.
2020-10-15 14:22:16 +09:00
Rui Ueyama
6647ad9b84 Precompute line number for each token
No functionality change
2020-10-15 14:22:16 +09:00
Rui Ueyama
cd832a311e Rewrite tests in shell script in C 2020-10-15 14:22:15 +09:00
Rui Ueyama
ca8b2434c9 Handle block scope 2020-10-08 16:23:53 +09:00
Rui Ueyama
6c0a42926a Add line and block comments 2020-10-08 16:23:53 +09:00
Rui Ueyama
a0388bada4 Add -o and --help options 2020-10-08 16:23:53 +09:00
Rui Ueyama
7b8528f71c Refactor -- no functionality change 2020-10-08 16:23:53 +09:00
Rui Ueyama
d9ea59757e Read code from a file instead of argv[1] 2020-10-08 16:23:49 +09:00
Rui Ueyama
9dae23461e [GNU] Add statement expression
This is a GNU C extension but will be useful for writing tests.
2020-10-08 15:43:05 +09:00
Rui Ueyama
c2cc1d3c45 Add \x<hexadecimal-sequence> 2020-10-08 15:43:05 +09:00
Rui Ueyama
699d2b7e3f Add \<octal-sequence> 2020-10-08 15:43:04 +09:00
Rui Ueyama
ad7749f2fa Add \a, \b, \t, \n \v, \f, \r and \e 2020-10-08 15:42:45 +09:00
Rui Ueyama
35a0bcd366 Refactoring: Add a utility function 2020-10-08 14:31:22 +09:00