Commit f1c25771
f1c25771efecMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified
Description
Route ivar op-write to the module static in class methods
InstanceVariableOperatorWriteNode (@x += y) inside a def self.X now targets the civ__ static, consistent with the ivar read and plain-write routing already added.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- f1c25771efec
- Parent
- 72265ac7a9d8
src/codegen.cmodifiedView file
@@ -4527,13 +4527,19 @@
45274527
int sc = comp_scope_of(c, id)->class_id;45284528
TyKind vt = TY_UNKNOWN;45294529
if (sc >= 0) { int iv = comp_ivar_index(&c->classes[sc], nm); if (iv >= 0) vt = c->classes[sc].ivar_types[iv]; }4530+
char ref[300];4531+
Scope *cs = comp_scope_of(c, id);4532+
if (cs && cs->is_cmethod && cs->class_id >= 0)4533+
snprintf(ref, sizeof ref, "civ_%s_%s", c->classes[cs->class_id].name, nm + 1);4534+
else4535+
snprintf(ref, sizeof ref, "%s->iv_%s", g_self, nm + 1);45304536
emit_indent(b, indent);45314537
if (vt == TY_STRING && op && !strcmp(op, "+")) {4532-
buf_printf(b, "%s->iv_%s = sp_str_concat(%s->iv_%s, ", g_self, nm + 1, g_self, nm + 1);4538+
buf_printf(b, "%s = sp_str_concat(%s, ", ref, ref);45334539
emit_expr(c, nt_ref(nt, id, "value"), b); buf_puts(b, ");\n");45344540
}45354541
else {4536-
buf_printf(b, "%s->iv_%s %s= ", g_self, nm + 1, op ? op : "+");4542+
buf_printf(b, "%s %s= ", ref, op ? op : "+");45374543
emit_expr(c, nt_ref(nt, id, "value"), b); buf_puts(b, ";\n");45384544
}45394545
return;