Commit 9be33518
9be3351880ccMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add InstanceVariableTargetNode and CallTargetNode to multi-write codegen
The ArrayNode-literal multi-write path (a, b = [x, y]) only handled LocalVariableTargetNode, ConstantTargetNode, and MultiTargetNode in its lefts/rights loops. Two missing arms:
-
InstanceVariableTargetNode: @a, @b = [1, 2] now emits self->iv_a = _t0; self->iv_b = _t1; with boxing when the ivar slot is poly but the element is not.
-
CallTargetNode: obj.setter = t (e.g. @c.v = 33) now resolves through comp_writer_in_chain and emits a direct ivar store: (recv)->iv = _t;
Both paths added symmetrically to analyze.c's multi-write loop so that ivar types are inferred from the literal element types.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- 9be3351880cc
- Parent
- 6bb066577fcc
src/analyze.cmodifiedView file
TyKind mg = ty_unify(cv->type, et); if (mg != cv->type) { cv->type = mg; changed = 1; } } else if (!strcmp(lty, "InstanceVariableTargetNode")) { Scope *iv_sc = comp_scope_of(c, id); int iv_cid = iv_sc ? iv_sc->class_id : -1; if (iv_cid < 0) continue; const char *ivnm = nt_str(nt, lefts[i], "name"); int iv_idx = ivnm ? comp_ivar_index(&c->classes[iv_cid], ivnm) : -1; if (iv_idx < 0) continue; TyKind et = infer_type(c, els[i]); if (et == TY_NIL) continue; TyKind mg = ty_unify(c->classes[iv_cid].ivar_types[iv_idx], et); if (mg != c->classes[iv_cid].ivar_types[iv_idx]) { c->classes[iv_cid].ivar_types[iv_idx] = mg; changed = 1; } } else if (!strcmp(lty, "MultiTargetNode")) { /* (b, c) nested target: inner RHS must be an ArrayNode literal */ const char *ety = nt_type(nt, els[i]); TyKind mg3 = ty_unify(cv2->type, et); if (mg3 != cv2->type) { cv2->type = mg3; changed = 1; } } else if (!strcmp(rty3, "InstanceVariableTargetNode")) { Scope *iv_sc3 = comp_scope_of(c, id); int iv_cid3 = iv_sc3 ? iv_sc3->class_id : -1; if (iv_cid3 < 0) continue; const char *ivnm3 = nt_str(nt, rights[j], "name"); int iv_idx3 = ivnm3 ? comp_ivar_index(&c->classes[iv_cid3], ivnm3) : -1; if (iv_idx3 < 0) continue; TyKind mg4 = ty_unify(c->classes[iv_cid3].ivar_types[iv_idx3], et); if (mg4 != c->classes[iv_cid3].ivar_types[iv_idx3]) { c->classes[iv_cid3].ivar_types[iv_idx3] = mg4; changed = 1; } } } /* rest (splat) target: elements [ln, en-rn) become a typed array */ int rest_nid = nt_ref(nt, id, "rest");src/codegen.cmodifiedView file
Loading diff…