selfhost: cgen for enum (member fold + as pass-through)
w6c_ww now compiles enum end-to-end and emits byte-identical
asm to the C w6c on the new 994 corpus case (`type mode = enum u8
{ R, W, RW = R | W }; main() { return (mode.RW): i32 }`). Mechanism
mirrors the C side:
- collectenums walks every `type X = enum {...}` at file scope and
pre-resolves each member's u64 value (auto-increment from prior,
sibling-ref folding for `RDWR = READ | WRITE`).
- cgdot recognises `EnumName.MEMBER` before the local lookup and
emits MOVQ $value, AX directly.
- cgtypeassert short-circuits when either side is enum: cgexpr on
the LHS lands the value in AX with the right integer width; no
tag/unwrap.
main.combined.ww (wwdump/ + w6c/) regenerated by ww build.
This commit is contained in:
@@ -143,6 +143,12 @@ main(void)
|
||||
" return n * fact(n - 1);\n"
|
||||
"};\n"
|
||||
"fn main() i32 = { return fact(5); };" },
|
||||
{ "enum",
|
||||
"type mode = enum u8 { R = 1, W = 2, RW = R | W };\n"
|
||||
"fn main() i32 = {\n"
|
||||
" let m: mode = mode.RW;\n"
|
||||
" return m as i32;\n"
|
||||
"};" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user