Commit 13b56a4
committed
fix: add array compound literal support
Previously, array compound literals such as (int[]){100, 200, 300}
failed with an "Unexpected token" error. Struct compound literals
worked correctly, but array syntax [] was unhandled in the parser.
This change adds proper array compound literal handling, including
scalar and pointer contexts. In scalar context, the literal returns
its first element (e.g. int x = (int[]){100,200}; yields 100). In
pointer context, it allocates and initializes backing storage and
returns the address (e.g. int *p = (int[]){100,200};). Arithmetic
expressions using literals (e.g. 50 + (int[]){100}) also evaluate
correctly.
Additional fixes include:
- Consume missing '{' token for int/char compound literals
- Add return statements to prevent control flow fall-through
- Prevent segfaults in pointer assignments by allocating memory
As a result, shecc now supports array compound literals alongside
existing struct compound literals, improving C99 compatibility and
preserving self-hosting capability.
Known limitations remain: designated initializers and complex
expression combinations are still unsupported.1 parent 12357f1 commit 13b56a4
1 file changed
+22
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| |||
1864 | 1864 | | |
1865 | 1865 | | |
1866 | 1866 | | |
1867 | | - | |
1868 | 1867 | | |
1869 | | - | |
| 1868 | + | |
1870 | 1869 | | |
1871 | 1870 | | |
1872 | 1871 | | |
| |||
2075 | 2074 | | |
2076 | 2075 | | |
2077 | 2076 | | |
2078 | | - | |
2079 | 2077 | | |
2080 | 2078 | | |
2081 | 2079 | | |
| |||
2154 | 2152 | | |
2155 | 2153 | | |
2156 | 2154 | | |
2157 | | - | |
2158 | | - | |
2159 | | - | |
2160 | | - | |
2161 | | - | |
| 2155 | + | |
| 2156 | + | |
| 2157 | + | |
| 2158 | + | |
2162 | 2159 | | |
2163 | | - | |
2164 | | - | |
2165 | | - | |
| 2160 | + | |
| 2161 | + | |
| 2162 | + | |
| 2163 | + | |
| 2164 | + | |
| 2165 | + | |
| 2166 | + | |
| 2167 | + | |
| 2168 | + | |
| 2169 | + | |
2166 | 2170 | | |
2167 | 2171 | | |
2168 | 2172 | | |
| |||
2172 | 2176 | | |
2173 | 2177 | | |
2174 | 2178 | | |
| 2179 | + | |
2175 | 2180 | | |
2176 | 2181 | | |
2177 | 2182 | | |
| |||
2339 | 2344 | | |
2340 | 2345 | | |
2341 | 2346 | | |
2342 | | - | |
2343 | | - | |
2344 | | - | |
| 2347 | + | |
| 2348 | + | |
| 2349 | + | |
2345 | 2350 | | |
2346 | 2351 | | |
2347 | 2352 | | |
| |||
0 commit comments