Commit c6e0a277

c6e0a2778324Merged

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

Description

analyze+codegen: class variable op-write, ARGV support, cvar class-body scan

  • ClassVariableOperatorWriteNode/OrWriteNode/AndWriteNode: analyze + codegen (both compile_stmt and compile_expr)
  • infer_cvar_types: pass 1 scans class body-level writes (scope 0, class_id=-1) so @@x = 0 at class level registers the cvar type for method reads
  • compile_stmt for cvar writes: g_class_body_id fallback when scope class_id=-1
  • ARGV: TY_STR_ARRAY type inference + sp_get_ARGV() accessor in runtime (::ARGV ConstantPathNode handled too)
  • sp_argv initialized from argc/argv in generated main
  • sp_argv_array_cache GC-rooted via sp_re_mark_globals
  • sp_IntArray_delete_at: already returned SP_INT_NIL for out-of-range (previous fix)

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

Details

Commit
c6e0a2778324
Parent
980bdfada79d

lib/sp_runtime.hmodifiedView file

@@ -2082,6 +2082,14 @@
20822082 underlying issue is unconditional. */
20832083 typedef struct{const char**data;mrb_int len;}sp_Argv;
20842084 static sp_Argv sp_argv;
2085+static sp_StrArray *sp_argv_array_cache = NULL;
2086+static sp_StrArray *sp_get_ARGV(void) {
2087+ if (!sp_argv_array_cache) {
2088+ sp_argv_array_cache = sp_StrArray_new();
2089+ for (mrb_int i = 0; i < sp_argv.len; i++) sp_StrArray_push(sp_argv_array_cache, sp_argv.data[i]);
2090+ }
2091+ return sp_argv_array_cache;
2092+}
20852093
20862094 /* Mark active in-flight exception messages. Most raises pass string
20872095 literals (rodata, marker byte ≠ 0xfe → no-op for sp_mark_string),
@@ -2114,6 +2122,7 @@
21142122 sp_mark_string(sp_re_match_pre);
21152123 sp_mark_string(sp_re_match_post);
21162124 for (mrb_int i = 0; i < sp_argv.len; i++) sp_mark_string(sp_argv.data[i]);
2125+ if (sp_argv_array_cache) sp_gc_mark(sp_argv_array_cache);
21172126 sp_mark_in_flight_exceptions();
21182127 sp_mark_fiber_root_storage();
21192128 }