Commit 3c912d9
fix(gen, gen-c): lower ExprCast in Zig and C emitters (#1337)
* fix(gen,gen-c): lower ExprCast in Zig and C emitters
Companion to #1320 (which added the Rust arm). NodeKind::ExprCast now
has a lowering arm in all three text emitters; only gen-verilog previously
had one.
- gen (Zig), gen_expr default was '_ => {}' (silent drop): now emits
'@as(<target>, @intcast(<operand>))'. @as establishes the explicit target
type, @intcast does the safe integer conversion. Works in any expression
position and for both narrowing (u32->u8) and widening (u8->u32) — better
than the @as-only minimal pass suggested in #1333, which cannot narrow.
- gen-c, gen_c_expr default emitted '/* unsupported: ExprCast */': now emits
'((<target_c_type>)(<operand>))' using the existing Self::type_to_c helper
(u8->uint8_t, u32->uint32_t).
Closes #1333.
Verified:
- t27c self-tests: 20 passed, 0 failed.
- 't27c gen' on tri-net specs/wire.t27: be_byte -> '@as(u8, @intcast((w >> 24) & 255))',
u32_be -> all 'as u32' casts now '@as(u32, @intcast(...))'. Previously silent drop.
- 't27c gen-c' on wire.t27: be_byte -> '((uint8_t)(((w >> 24) & 255)))'.
Previously '/* unsupported: ExprCast */'.
- Minimal repro 'fn hi_byte(w: u32) -> u8 { return ((w >> 24) & 255) as u8; }'
-> gen: 'return @as(u8, @intcast((w >> 24) & 255));',
gen-c: 'return ((uint8_t)(((w >> 24) & 255)));'.
- comprehensive_suite.t27: 0 'unsupported: ExprCast' in both gen and gen-c output.
With #1320 (Rust) + this (Zig, C), ExprCast is fully lowered across all four
backends (gen-verilog already had it). Unblocks multi-target T27-first flips
in downstream consumers (tri-net gen/zig + gen/c drift-guard).
* docs(now): add exprcast-zig-c-emitters section (Closes #1333)
Wave Loop 411 close-out requires docs/NOW.md to reflect every landing PR.
Adds a section for this PR documenting:
- WHERE: gen/gen-c ExprCast arms in bootstrap/src/compiler.rs
- Zig form: @as(<T>, @intcast(<operand>)) -- narrows and widens
- C form: ((<uintN_t>)(<operand>)) via Self::type_to_c
- Coverage: all 4 backends now lower ExprCast (Rust from #1320, Verilog
already, Zig+C in this PR)
- Downstream unblock: tri-net multi-target drift-guard (Rust+Zig+C from
specs/wire.t27) can now proceed
- Regression: t27c self-tests 20/0; comprehensive_suite.t27 shows 0
'unsupported: ExprCast' in Zig+C output
Anchor: phi^2 + phi^-2 = 3
---------
Co-authored-by: SSD DDD <ssdm4@MacBook-Pro.local>
Co-authored-by: Perplexity Computer <agent@perplexity.ai>1 parent f989ee2 commit 3c912d9
2 files changed
Lines changed: 34 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3624 | 3624 | | |
3625 | 3625 | | |
3626 | 3626 | | |
| 3627 | + | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
| 3631 | + | |
| 3632 | + | |
| 3633 | + | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
3627 | 3641 | | |
3628 | 3642 | | |
3629 | 3643 | | |
| |||
5970 | 5984 | | |
5971 | 5985 | | |
5972 | 5986 | | |
| 5987 | + | |
| 5988 | + | |
| 5989 | + | |
| 5990 | + | |
| 5991 | + | |
| 5992 | + | |
| 5993 | + | |
| 5994 | + | |
| 5995 | + | |
| 5996 | + | |
| 5997 | + | |
| 5998 | + | |
| 5999 | + | |
5973 | 6000 | | |
5974 | 6001 | | |
5975 | 6002 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| |||
0 commit comments