lib/regex: verbatim cast-expr appends; correct bare-decl zero cite (fold-2a review)

The lit/match appends went through a let-temp; the direct Hare
spelling append(insts, (r: inst_lit)) compiles and runs correctly
(probed at the real 48B-payload inst shape), so the temps were an
undocumented reshape. Void variants (skip/any) keep the typed let —
a bare type name is a symbol ref in ww — now documented at-site.
The bare-slice-decl zeroing cite pointed at shlex.ww:215, which
zeroes its header EXPLICITLY and so proves nothing; the real
mechanism is cgen.c:9836's no-rhs multi-word composite zero-fill.
This commit is contained in:
2026-06-04 05:45:52 +09:00
parent 3cffe204d1
commit de7dc36da3

View File

@@ -118,7 +118,8 @@ export fn finish(re: *regex) void = { };
// runtime (#27) — the port drops every Hare free().
export fn compile(expr: str) (regex | error | nomem) = {
// Hare `let insts: []inst = [];` — a bare ww slice declaration
// zeroes the header (cf lib/shlex/shlex.ww:215).
// zeroes the header (cgen.c:9836 no-rhs multi-word composite
// zero-fill, symmetric in cgenstmt.ww).
let insts: []inst;
let charsets: []charset; // stays empty until the '[' fold
let iter: strings.iterator = strings.iter(expr);
@@ -131,6 +132,10 @@ export fn compile(expr: str) (regex | error | nomem) = {
if (r_idx == 0 && next is rune && (next as rune) != '^') {
// Bare append: ww append returns void; Hare's
// `append(...)?` nomem propagation is filed #36.
// Hare appends the bare type name (`inst_skip`) as
// the void-variant value; in ww that resolves as a
// symbol ref (cf the alloc(T) rule), so void
// variants go through a typed let.
let sk: inst_skip;
let v: inst = sk;
append(insts, v);
@@ -149,17 +154,13 @@ export fn compile(expr: str) (regex | error | nomem) = {
let v: inst = av;
append(insts, v);
};
case ']': { // regex.ha:315-316 — literal outside a bracket
let v: inst = (r: inst_lit);
append(insts, v);
};
case ']': // regex.ha:315-316 — literal outside a bracket
append(insts, (r: inst_lit));
case '\\', '^', '$', '[', '(', ')', '|', '{', '?', '*', '+':
// fold-2a boundary: regex.ha:286-459 arms deferred.
return "regex: metacharacter not yet ported": error;
case: { // regex.ha:462-463
let v: inst = (r: inst_lit);
append(insts, v);
};
case: // regex.ha:462-463
append(insts, (r: inst_lit));
};
r_idx += 1;
};
@@ -167,8 +168,7 @@ export fn compile(expr: str) (regex | error | nomem) = {
// regex.ha:475-477. `$` appends true: inst_match — deferred, so
// the guard can only see no-match today; kept verbatim.
if (insts.len == 0 || !(insts[insts.len - 1] is inst_match)) {
let m: inst = (false: inst_match);
append(insts, m);
append(insts, (false: inst_match));
};
// regex.ha:479-484. The alternation fixup (ha:470-473) drops with
// jump_idxs.