Commit b2c832b6

b2c832b691bfMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · ~4 modified

Description

Add TY_CLASS type for class/module constants as first-class values

  • New TY_CLASS enum value (sp_Class{cls_id} struct)
  • analyze.c: ConstantReadNode/ConstantPathNode for registered classes infer TY_CLASS instead of TY_UNKNOWN
  • codegen.c: TY_CLASS in c_type_name, default_value, is_scalar_ret, declare_local; emit_box_open/close handles boxing to sp_RbVal
  • ConstantReadNode/ConstantPathNode now emit ((sp_Class){cidx}) for unboxed class value; emit_boxed wraps as sp_box_class(...)
  • TY_CLASS method dispatch: to_s/name/inspect, nil?, class, ==/!=
  • types.c: "class" string tag for TY_CLASS
  • emit_box_close: TY_UNKNOWN is now truly a no-op (matching emit_box_open which emits nothing for unknown types)

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
b2c832b691bf
Parent
58a591724069

src/analyze.cmodifiedView file

@@ -1967,6 +1967,7 @@
19671967 !strcmp(nm, "RUBY_ENGINE_VERSION") || !strcmp(nm, "RUBY_RELEASE_DATE") ||
19681968 !strcmp(nm, "RUBY_REVISION") || !strcmp(nm, "RUBY_COPYRIGHT"))) return TY_STRING;
19691969 if (nm && !strcmp(nm, "ARGV")) return TY_STR_ARRAY;
1970+ if (nm && comp_class_index(c, nm) >= 0) return TY_CLASS;
19701971 return TY_UNKNOWN;
19711972 }
19721973 if (!strcmp(ty, "DefinedNode")) return TY_STRING; /* a label string, or nil (NULL) */
@@ -1998,6 +1999,7 @@
19981999 if (par_nm && !strcmp(par_nm, "Integer")) {
19992000 if (nm && (!strcmp(nm, "MAX") || !strcmp(nm, "MIN"))) return TY_UNKNOWN; /* raises NameError */
20002001 }
2002+ if (nm && comp_class_index(c, nm) >= 0) return TY_CLASS;
20012003 return TY_UNKNOWN;
20022004 }
20032005 if (!strcmp(ty, "SelfNode")) {