Commit 0a5696d5
0a5696d5fa62Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add SelfNode and fix object-returning method default
- SelfNode:
selfas a value -> (*self); typed as the enclosing class's object. self counts as an lvalue receiver soself.methodpasses the real self (not a copy). Methods can return self. - Fix the unreachable default return for object-returning methods ((sp_){0} was missing its opening paren).
A Counter with chaining-style methods (inc returning self, self.value)
matches CRuby. make test: 34 (one test exposes the value-type-object
limitation: mutating an object passed as a method parameter doesn't
persist to the caller -- objects are value structs, not references).
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 0a5696d5fa62
- Parent
- 08c3bad28a82
src/analyze.cmodifiedView file
@@ -288,6 +288,10 @@
288288
LocalVar *lv = nm ? comp_const(c, nm) : NULL;289289
return lv ? lv->type : TY_UNKNOWN;290290
}291+
if (!strcmp(ty, "SelfNode")) {292+
Scope *s = comp_scope_of(c, id);293+
return s->class_id >= 0 ? ty_object(s->class_id) : TY_UNKNOWN;294+
}291295
if (!strcmp(ty, "InstanceVariableReadNode")) {292296
const char *nm = nt_str(nt, id, "name");293297
Scope *s = comp_scope_of(c, id);src/codegen.cmodifiedView file
Loading diff…