Commit 2efc0f49
2efc0f4970dcMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Force int return/params for bound-Method targets; coerce poly tail returns
The bound-Method dispatch ABI is mrb_int (*)(void *, mrb_int...): the call sites (sp_poly_arr_get_hash / sp_poly_slice) read the result as mrb_int and pass int args. A method(:sym) target that returned poly (e.g. PPU#peek_2002 returning the poly @io_latch) was called through the int cast, so its sp_RbVal struct return was misread as garbage (0) -- the CPU saw 0 at $2002 and never left the vblank-poll warmup, leaving every pixel at palette[0].
Pin such targets to int return (in addition to int params) so the body return is coerced, and teach the explicit/implicit return paths to wrap a poly value in sp_poly_to_i / sp_poly_to_f for a scalar return slot.
make optcarrot now passes: checksum 59662, pixel-identical to CRuby.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 2efc0f4970dc
- Parent
- a976593b14a7
src/analyze.cmodifiedView file
entry typed here flows into `@pads[0].poke(data)` -> Pad#poke). */ for (int s = 0; s < c->nscopes; s++) { Scope *sc = &c->scopes[s]; if (!sc->reachable || sc->nparams == 0 || !sc->name) continue; int has_unknown = 0; for (int i = 0; i < sc->nparams; i++) { LocalVar *p = sc->pnames[i] ? scope_local(sc, sc->pnames[i]) : NULL; if (p && p->type == TY_UNKNOWN) { has_unknown = 1; break; } } if (!has_unknown) continue; if (!sc->reachable || !sc->name) continue; int taken = 0; for (int id = 0; id < c->nt->count && !taken; id++) { const char *nty = nt_type(c->nt, id); if (msym && !strcmp(msym, sc->name)) taken = 1; } if (taken) { /* The bound-Method ABI is `mrb_int (*)(void *, mrb_int...)`: the dispatch site (sp_poly_arr_get_hash / sp_poly_slice) reads the return as mrb_int and passes int args. So a method(:sym) target MUST return int and take int params -- a poly return (e.g. PPU#peek_2002 returning the poly @io_latch) would be misread as a struct through the int cast and yield garbage. Pin unknown params to int and a poly/unknown return to int (codegen coerces the body's poly return via sp_poly_to_i). */ for (int i = 0; i < sc->nparams; i++) { LocalVar *p = sc->pnames[i] ? scope_local(sc, sc->pnames[i]) : NULL; if (p && p->type == TY_UNKNOWN) p->type = TY_INT; } if (sc->ret == TY_UNKNOWN) sc->ret = TY_INT; if (sc->ret == TY_UNKNOWN || sc->ret == TY_POLY) sc->ret = TY_INT; } }src/codegen_stmt.cmodifiedView file
Loading diff…