lib/regex: type model + finish() (regex port fold 1, partial)

Port of ref/hare/regex/regex.ha fold 1 (the data model). Lands the
full type model — error, the inst_* variants + 10-variant inst union
(the nominally-distinct same-underlying size/void aliases included),
result/capture, charset + items, the regex struct — plus finish().
Test 989_regex_run pins variant discrimination, payload extraction,
struct shapes, and finish() on cstage; w6c == w6c_ww byte-identical.

Two fold-1 constructs are held back behind filed compiler/fidelity
gaps, documented at their sites (regex tasks A–D):

  - charclass_map (regex.ha:74-87): const [](str, *fn(rune) bool)
    table — blocked on the array-literal->slice element-coercion
    checker gap (type.c:402-404 #258 borrow uses exact type_eq,
    no element decay). It needs `import ascii;`, so both land with
    the consuming fold (compile) once the gap is fixed.

  - finish() free()s; ww is a no-free runtime (rt/alloc.s:30), so the
    faithful body drops the frees, as the port drops every Hare
    free(). Kept as a no-op for API parity.

DEFERRED to later folds: compile()/exec/find/replace.
This commit is contained in:
2026-06-03 23:29:34 +09:00
parent 1e081e28c6
commit b6a41ae063
4 changed files with 318 additions and 0 deletions

View File

@@ -408,6 +408,7 @@ TESTS = $(BIN)/test_smoke $(BIN)/test_lex $(BIN)/test_parse $(BIN)/test_check \
$(BIN)/test_adler32_run $(BIN)/test_crc16_run \
$(BIN)/test_crc32_run $(BIN)/test_crc64_run \
$(BIN)/test_siphash_run $(BIN)/test_sha256_run \
$(BIN)/test_regex_run \
$(BIN)/test_checked_run \
$(BIN)/test_floatarr_run \
$(BIN)/test_deref_narrow_run \
@@ -1665,6 +1666,10 @@ $(BIN)/test_sha256_run: test/wcc/989_sha256_run.c $(BIN)/ww $(BIN)/w6c \
$(BIN)/w6a $(BIN)/w6l $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_regex_run: test/wcc/989_regex_run.c $(BIN)/ww $(BIN)/w6c \
$(BIN)/w6a $(BIN)/w6l $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<
$(BIN)/test_bufio_run: test/wcc/998_bufio_run.c $(BIN)/ww $(BIN)/w6c \
$(BIN)/w6a $(BIN)/w6l $(LIB)/libwwrt.a | $(BIN)
$(CC) $(CFLAGS) -o $@ $<