lib: graduate bytes/strings find-funcs to (i32 | void)
Replaces the -1 sentinel return on indexbyte/byteindex/rbyteindex/ index with Hare's optional-shaped tagged union. Callers `match` on the result and bind the index from the i32 variant. Two cgen fixes were needed first: 1. resolve_type for N_TTAGGED rounded value payload up to an 8-byte multiple. (i32 | void) was sized 12 — tag (8) + payload (4) — which made the reg-passing ABI compute size/8 = 1 word and drop the value word. 2. The call-arg push path special-cased struct and slice args but not tagged-return calls. A nested `f(g())` where g returns a tagged union pushed only AX (tag); the matching pop loaded a stale DX/SI for the value. Now pushes AX/DX[/CX] in order so the pop side drains tag → arg-reg[0], value(s) → arg-reg[1..]. strings.contains rewritten to match on the new tagged result. No other callers existed in lib/ — bufio/io still use their own shapes.
This commit is contained in:
@@ -192,7 +192,12 @@ resolve_type(Checker *c, Node *n)
|
||||
if (nv == 0) return ty_never;
|
||||
if (nv == 1 && head) return head->type;
|
||||
t->params = head;
|
||||
t->size = 8 + maxsz;
|
||||
/* Round value payload up to an 8-byte multiple so the slot
|
||||
* layout (tag + N value words) stays word-aligned. The reg-
|
||||
* passing ABI counts size/8 words; 12-byte unions like
|
||||
* (i32 | void) would otherwise lose a value register. */
|
||||
u64 vsz = (maxsz + 7) & ~(u64)7;
|
||||
t->size = 8 + vsz;
|
||||
t->align = al;
|
||||
return t;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user