cstage+selfhost+test: fold unary-over-literal in def DATA emit (#24)
Top-level `def NEG: i32 = -100;` skipped DATA emission in both stages — cstage's emit_defs and wwstage's emitdefconstants each carried a literal-leaf whitelist that excluded N_UN nodes. Same gap in check.c's eval_enum_value cstage-side. Surfaced during #10 (lib/os forced an `at` enum for AT_FDCWD=-100 etc. as workaround). Factor a single fold_int_literal helper (cstage check.c; wwstage cgen.ww). Handles N_INTLIT / N_RUNELIT / N_TRUE / N_FALSE / N_NIL plus N_UN with TK_MINUS / TK_TILDE / TK_PLUS recursively. Consume from eval_enum_value, emit_defs, emitdefconstants, enumevalmember — single source of truth for "is this a literal-leaf foldable". Side effect: cstage's def-emit set widens from {INTLIT, RUNELIT, TRUE} to match wwstage's pre-existing 5-shape set plus the new unary peel. Bootstrap byte-id holds (995_self_rebuild green). Test 631 (def_neg_global): 6 rows × cstage/wwstage run + asm byte-identity diff. Covers all three unary arms (-, ~, +), positive regression-pin, i32 + i64 + u32 slots. Follows up #26: revert lib/os.ww `at` enum to three top-level defs.
This commit is contained in:
@@ -531,4 +531,11 @@ struct Checker {
|
||||
void check_init(Checker*, Arena*);
|
||||
void check_file(Checker*, Node *file);
|
||||
|
||||
/* fold_int_literal — fold an integer-literal-leaf expression to its
|
||||
* u64 value. Accepts int/rune literal, true/false/nil, and a unary
|
||||
* +/-/~ over the same (any depth). No sibling-ident, no binary op.
|
||||
* Returns 1 on success; the call site decides what a miss means
|
||||
* (eval_enum_value's leaf delegation, emit_defs's DATA-row gate). */
|
||||
int fold_int_literal(Node*, u64*);
|
||||
|
||||
#endif /* WW_H */
|
||||
|
||||
Reference in New Issue
Block a user