Commit 97a9991
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 3c07644 commit 97a9991
1 file changed
+22
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| |||
1967 | 1967 | | |
1968 | 1968 | | |
1969 | 1969 | | |
1970 | | - | |
1971 | 1970 | | |
1972 | | - | |
| 1971 | + | |
1973 | 1972 | | |
1974 | 1973 | | |
1975 | 1974 | | |
| |||
2179 | 2178 | | |
2180 | 2179 | | |
2181 | 2180 | | |
2182 | | - | |
2183 | 2181 | | |
2184 | 2182 | | |
2185 | 2183 | | |
| |||
2258 | 2256 | | |
2259 | 2257 | | |
2260 | 2258 | | |
2261 | | - | |
2262 | | - | |
2263 | | - | |
2264 | | - | |
2265 | | - | |
| 2259 | + | |
| 2260 | + | |
| 2261 | + | |
| 2262 | + | |
2266 | 2263 | | |
2267 | | - | |
2268 | | - | |
2269 | | - | |
| 2264 | + | |
| 2265 | + | |
| 2266 | + | |
| 2267 | + | |
| 2268 | + | |
| 2269 | + | |
| 2270 | + | |
| 2271 | + | |
| 2272 | + | |
| 2273 | + | |
2270 | 2274 | | |
2271 | 2275 | | |
2272 | 2276 | | |
| |||
2276 | 2280 | | |
2277 | 2281 | | |
2278 | 2282 | | |
| 2283 | + | |
2279 | 2284 | | |
2280 | 2285 | | |
2281 | 2286 | | |
| |||
2443 | 2448 | | |
2444 | 2449 | | |
2445 | 2450 | | |
2446 | | - | |
2447 | | - | |
2448 | | - | |
| 2451 | + | |
| 2452 | + | |
| 2453 | + | |
2449 | 2454 | | |
2450 | 2455 | | |
2451 | 2456 | | |
| |||
0 commit comments