Rui Ueyama
cd4355888f
Support line continuation
2020-09-22 18:34:00 +09:00
Rui Ueyama
661108f9a4
Preserve newline and space during macro expansion
2020-09-22 18:34:00 +09:00
Rui Ueyama
0e8b78b1c3
Replace remaining identifiers with 0 in macro constexpr
2020-09-22 18:34:00 +09:00
Rui Ueyama
90d37c55df
Add defined() macro operator
2020-09-22 18:34:00 +09:00
Rui Ueyama
0514ff2f7f
Use chibicc's preprocessor for all tests
2020-09-22 18:34:00 +09:00
Rui Ueyama
cbfb62fb0e
Add macro token-pasting operator (##)
2020-09-22 18:34:00 +09:00
Rui Ueyama
50d487f4ed
Add macro stringizing operator (#)
2020-09-22 18:34:00 +09:00
Rui Ueyama
040c549877
Do not expand a token more than once for the same funclike macro
2020-09-22 18:34:00 +09:00
Rui Ueyama
20fa4df5a3
Allow parenthesized expressions as macro arguments
2020-09-22 18:34:00 +09:00
Rui Ueyama
5163938702
Allow empty macro arguments
2020-09-22 18:34:00 +09:00
Rui Ueyama
f2397d0585
Add multi-arity funclike #define
2020-09-22 18:34:00 +09:00
Rui Ueyama
4008c21dd3
Add zero-arity funclike #define
2020-09-22 18:34:00 +09:00
Rui Ueyama
db2815b4fb
Add #ifdef and #ifndef
2020-09-22 18:34:00 +09:00
Rui Ueyama
f86cb47357
Do not expand a token more than once for the same objlike macro
2020-09-22 18:34:00 +09:00
Rui Ueyama
add8ae695d
Expand macros in the #if and #elif argument context
2020-09-22 18:34:00 +09:00
Rui Ueyama
ae83f298ec
Add #undef
2020-09-22 18:34:00 +09:00
Rui Ueyama
9c44a1c666
Add objlike #define
2020-09-22 18:34:00 +09:00
Rui Ueyama
7a62e206e9
Add #elif
2020-09-22 18:34:00 +09:00
Rui Ueyama
9fc67e114a
Add #else
2020-09-22 18:34:00 +09:00
Rui Ueyama
6f47e5ab8e
Skip nested #if in a skipped #if-clause
2020-09-22 18:34:00 +09:00
Rui Ueyama
592f89f3c2
Add #if and #endif
2020-09-22 18:34:00 +09:00
Rui Ueyama
2019f3a79e
Add -E option
2020-09-22 18:34:00 +09:00
Rui Ueyama
18a2c49f03
Add #include "..."
2020-09-22 18:34:00 +09:00
Rui Ueyama
88305ee5fc
Add the null directive
2020-09-22 18:34:00 +09:00
Rui Ueyama
f51e65a01c
Run "ld" unless -c is given
2020-09-22 18:34:00 +09:00
Rui Ueyama
e664fd254a
Accept multiple input files
2020-09-22 18:34:00 +09:00
Rui Ueyama
af5e8a98a6
Run "as" command unless -S is given
2020-09-22 18:34:00 +09:00
Rui Ueyama
51d0bffbef
Add usual arithmetic conversion for function pointer
2020-09-22 18:34:00 +09:00
Rui Ueyama
005413b789
Decay a function to a pointer in the func param context
2020-09-22 18:34:00 +09:00
Rui Ueyama
dddcea280a
Add function pointer
2020-09-22 18:34:00 +09:00
Rui Ueyama
5fb12d8bfe
Add stage2 build
2020-09-22 18:34:00 +09:00
Rui Ueyama
e01a44d0d6
Add "long double" as an alias for "double"
2020-09-22 18:34:00 +09:00
Rui Ueyama
3bfd2200dd
Add flonum constant expression
2020-09-22 18:34:00 +09:00
Rui Ueyama
3a051359fd
Support variadic function with floating-point parameters
2020-09-22 18:34:00 +09:00
Rui Ueyama
c2a73c5727
Implement default argument promotion for float
2020-09-22 18:34:00 +09:00
Rui Ueyama
a2a92e5e91
Allow to define a function that takes/returns flonums
2020-09-22 18:34:00 +09:00
Rui Ueyama
d8188588f4
Allow to call a function that takes/returns flonums
2020-09-22 18:34:00 +09:00
Rui Ueyama
fade39d85e
Handle flonum for if, while, do, !, ?:, || and &&
2020-09-22 18:33:51 +09:00
Rui Ueyama
f3667e271c
Add flonum +, -, * and /
2020-09-22 18:33:34 +09:00
Rui Ueyama
efd10ced54
Add flonum ==, !=, < and <=
2020-09-22 18:33:34 +09:00
Rui Ueyama
9bbbbba878
Add "float" and "double" local variables and casts
2020-09-22 18:33:32 +09:00
Rui Ueyama
0d85517407
Add floating-point constant
2020-09-22 17:39:48 +09:00
Rui Ueyama
8a474bd008
Ignore "static" and "const" in array-dimensions
2020-09-22 17:39:48 +09:00
Rui Ueyama
ace64171e6
Ignore const, volatile, auto, register, restrict or _Noreturn.
2020-09-22 17:39:38 +09:00
Rui Ueyama
62d4db8d84
Handle unsigned types in the constant expression
2020-09-21 19:00:48 +09:00
Rui Ueyama
56c967c71b
When comparing two pointers, treat them as unsigned
2020-09-21 19:00:47 +09:00
Rui Ueyama
0aa02ee38a
Use long or ulong instead of int for some expressions
2020-09-21 19:00:47 +09:00
Rui Ueyama
fd14c5b8e1
Add U, L and LL prefixes
2020-09-21 19:00:47 +09:00
Rui Ueyama
10192ad2d8
Add unsigned integral types
2020-09-21 19:00:47 +09:00
Rui Ueyama
07480d02ec
Add `signed` keyword
2020-09-21 19:00:47 +09:00
Rui Ueyama
6be5d3ab67
Add va_start to support variadic functions
2020-09-21 19:00:46 +09:00
Rui Ueyama
8e19cadfd6
Allow to call a variadic function
2020-09-21 19:00:46 +09:00
Rui Ueyama
76bc202552
Handle a function returning bool, char or short
...
x86-64 psABI says that only the least significant 8 bits are
significant if RAX has a return value of a function returning bool.
Likewise, it looks like only the least significant 1 or 2 bytes
are guaranteed to have a correct value for char and short return
values, respectively.
2020-09-21 19:00:46 +09:00
Rui Ueyama
87d358024c
Add do ... while
2020-09-21 19:00:46 +09:00
Rui Ueyama
5c50f75153
Add static global variables
2020-09-21 19:00:46 +09:00
Rui Ueyama
148deadd2d
Add return that doesn't take any value
2020-09-21 19:00:45 +09:00
Rui Ueyama
dbb29fe796
Add compound literals
2020-09-21 19:00:45 +09:00
Rui Ueyama
94ed9371e0
Add static local variables
2020-09-21 19:00:45 +09:00
Rui Ueyama
5346cfced5
Add _Alignof and _Alignas
2020-09-21 19:00:45 +09:00
Rui Ueyama
b471a676f0
Handle extern declarations in a block
2020-09-21 19:00:45 +09:00
Rui Ueyama
c5d0c7b525
Add extern
2020-09-21 19:00:44 +09:00
Rui Ueyama
72639a250b
Accept `void` as a parameter list
...
`foo(void)` indicate that function foo does not take a parameter.
2020-09-21 19:00:44 +09:00
Rui Ueyama
f157838277
Allow to initialize struct flexible array member
2020-09-21 19:00:44 +09:00
Rui Ueyama
a4bf63d826
Add flexible array member
2020-09-21 19:00:44 +09:00
Rui Ueyama
4e4a687902
Allow extraneous comma at the end of enum or initializer list
2020-09-21 19:00:43 +09:00
Rui Ueyama
2c65190a84
Allow extraneous braces for scalar initializer
2020-09-21 19:00:43 +09:00
Rui Ueyama
05ea7cde43
Allow parentheses in initializers to be omitted
2020-09-21 19:00:43 +09:00
Rui Ueyama
85589c8b8f
Handle union initializers for global variable
2020-09-21 19:00:43 +09:00
Rui Ueyama
7a3ba2aac1
Add struct initializer for global variable
2020-09-21 19:00:43 +09:00
Rui Ueyama
d8de284862
Add global initializer for scalar and string
2020-09-21 19:00:42 +09:00
Rui Ueyama
7b22d6ff15
Handle union initializers for local variables
2020-09-21 19:00:42 +09:00
Rui Ueyama
b48147b688
Allow to initialize a struct with other struct
2020-09-21 19:00:42 +09:00
Rui Ueyama
21336ef47f
Handle struct initializers for local variables
2020-09-21 19:00:42 +09:00
Rui Ueyama
53c6fc6f7e
Allow to omit array length 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}`.
2020-09-21 19:00:42 +09:00
Rui Ueyama
9e777dbdc5
Add string literal initializer
2020-09-21 19:00:42 +09:00
Rui Ueyama
a6cfc4b995
Initialize excess array elements with zero
2020-09-21 19:00:41 +09:00
Rui Ueyama
0635bdb5eb
Support local variable initializers
2020-09-21 19:00:41 +09:00
Rui Ueyama
5aa50beacb
Add constant expression
2020-09-21 19:00:41 +09:00
Rui Ueyama
0924ab0aa5
Add ?: operator
2020-09-21 19:00:41 +09:00
Rui Ueyama
1bb4c6d4b8
Add <<, >>, <<= and >>=
2020-09-21 19:00:41 +09:00
Rui Ueyama
6244cc4a84
Add switch-case
2020-09-21 19:00:41 +09:00
Rui Ueyama
cb813c68cc
Add continue statement
2020-09-21 19:00:40 +09:00
Rui Ueyama
1715797963
Add break statement
2020-09-21 19:00:40 +09:00
Rui Ueyama
f92f581de4
Resolve conflict between labels and typedefs
2020-09-21 19:00:40 +09:00
Rui Ueyama
1efd307626
Add goto and labeled statement
2020-09-21 19:00:40 +09:00
Rui Ueyama
f9a327ae97
Add a notion of an incomplete struct type
2020-09-21 19:00:40 +09:00
Rui Ueyama
0993b404fc
Decay an array to a pointer in the func param context
2020-09-21 19:00:40 +09:00
Rui Ueyama
a9ac32fbfb
Add a notion of an incomplete array type
2020-09-21 19:00:39 +09:00
Rui Ueyama
c7cb814fec
Add && and ||
2020-09-21 19:00:39 +09:00
Rui Ueyama
fcc9daa39d
Add &, |, ^, &=, |= and ^=
2020-09-21 19:00:39 +09:00
Rui Ueyama
4af75d51f7
Add % and %=
2020-09-21 19:00:39 +09:00
Rui Ueyama
fad13556b5
Add ~ operator
2020-09-21 19:00:39 +09:00
Rui Ueyama
775db13f37
Add ! operator
2020-09-21 19:00:39 +09:00
Rui Ueyama
50164db2eb
Add hexadecimal, octal and binary number literals
2020-09-21 19:00:39 +09:00
Rui Ueyama
5313ed2294
Add post ++ and --
2020-09-21 19:00:38 +09:00
Rui Ueyama
1282bd9683
Add pre ++ and --
2020-09-21 19:00:38 +09:00
Rui Ueyama
9948b77155
Add +=, -=, *= and /=
2020-09-21 19:00:38 +09:00
Rui Ueyama
db660e9ffb
Allow for-loops to define local variables
2020-09-21 19:00:38 +09:00
Rui Ueyama
32bc9723b1
Support file-scope functions
2020-09-21 19:00:38 +09:00
Rui Ueyama
d7f3435730
Add enum
2020-09-21 19:00:38 +09:00
Rui Ueyama
acabd99ee4
Add character literal
2020-09-21 19:00:36 +09:00
Rui Ueyama
733e0dc2cb
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-09-20 16:20:06 +09:00
Rui Ueyama
fececef73b
Handle function argument type conversion
2020-09-20 16:20:06 +09:00
Rui Ueyama
18a31bdaea
Handle return type conversion
2020-09-20 16:20:06 +09:00
Rui Ueyama
aa4ad5b000
Report an error on undefined/undeclared functions
2020-09-20 16:20:06 +09:00
Rui Ueyama
3aef744406
Implement usual arithmetic conversion
2020-09-20 16:20:06 +09:00
Rui Ueyama
4879438182
Add type cast
2020-09-20 16:20:06 +09:00
Rui Ueyama
615b3a51fc
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-09-20 16:20:06 +09:00
Rui Ueyama
60d12c07b7
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-09-20 16:20:05 +09:00
Rui Ueyama
a7f24b1bfa
Add `long long` as an alias for `long`
2020-09-20 16:20:05 +09:00
Rui Ueyama
66fa61e90e
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-09-20 16:20:05 +09:00
Rui Ueyama
8260122116
Add void type
2020-09-20 16:20:05 +09:00
Rui Ueyama
71b92d35c4
Add function declaration
2020-09-20 16:20:05 +09:00
Rui Ueyama
a796af1fbe
Add nested type declarators
2020-09-20 16:20:05 +09:00
Rui Ueyama
549373b3bd
Add short type
2020-09-20 16:20:05 +09:00
Rui Ueyama
98af405a2f
Add long type
2020-09-20 16:20:05 +09:00
Rui Ueyama
cb0065e352
Change size of int from 8 to 4
2020-09-20 16:20:05 +09:00
Rui Ueyama
5161e203fd
Add struct assignment
2020-09-20 16:20:04 +09:00
Rui Ueyama
198f0e8f1d
Add union
2020-09-20 16:20:04 +09:00
Rui Ueyama
c38f99488f
Add -> operator
2020-09-20 16:19:42 +09:00
Rui Ueyama
b8a3b88dcd
Support struct tags
2020-09-20 16:19:41 +09:00
Rui Ueyama
2e36dcdb09
Align local variables
2020-09-20 16:19:35 +09:00
Rui Ueyama
c821c4f709
Align struct members
2020-09-20 16:19:34 +09:00
Rui Ueyama
d16f54ba0a
Add struct
2020-09-20 16:19:18 +09:00
Rui Ueyama
b09f5ae7ae
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-09-13 21:36:54 +09:00
Rui Ueyama
bc0c468a42
Rewrite tests in shell script in C
2020-09-13 21:36:53 +09:00