Commit 43fcd7c7
43fcd7c7d9d5Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified
Description
fix(codegen): box procs into sp_RbVal slots; promote empty {} ivar to *_poly_hash
Issue #65: an ivar initialized as {} and later assigned a captured
&block proc dropped into str_int_hash, then fed sp_Proc * into
sp_StrIntHash_set (which takes mrb_int). Two pieces:
-
box_expr_to_poly/box_value_to_polyhad noproc/lambdacase, so the[]=site fell through tosp_box_int(lv_block). Add a newSP_BUILTIN_PROC(-9) cls_id andsp_box_proc(p)runtime helper, and route both boxers through it. -
The empty-hash promotion from issue #64 already widens
str_int_hash→str_poly_hashfor non-int/string/sym values (procs land here), but the inline empty-hash constructor switches incompile_stmtandemit_constructoronly knew about the monomorphic*_*_hashtypes. Addstr_poly_hash/sym_poly_hasharms so@h = {}against a poly-promoted slot emitssp_StrPolyHash_new()/sp_SymPolyHash_new()instead of the str_int_hash default. The corresponding@needs_*flags are set inscan_writer_callsat promotion time so emit_features picks up the runtime helpers.
test/proc_hash_value.rb covers the issue's exact reproducer
(@h[name] = block against an empty-hash ivar inside a method that
captures &block).
Closes #65
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 43fcd7c7d9d5
- Parent
- c734bbad3ac0
lib/sp_runtime.hmodifiedView file
#define SP_BUILTIN_FLT_ARRAY SP_BUILTIN_ARRAY_OF(SP_TAG_FLT) /* -3 */#define SP_BUILTIN_PTR_ARRAY SP_BUILTIN_ARRAY_OF(SP_TAG_OBJ) /* -6 */#define SP_BUILTIN_SYM_ARRAY SP_BUILTIN_ARRAY_OF(SP_TAG_SYM) /* -7 */#define SP_BUILTIN_PROC (-9) /* sp_Proc *, distinct from any tag-based id */typedef struct { int tag; int cls_id; union { mrb_int i; const char *s; mrb_float f; mrb_bool b; void *p; } v; } sp_RbVal;static sp_RbVal sp_box_int(mrb_int v) { sp_RbVal r; r.tag = SP_TAG_INT; r.cls_id = 0; r.v.i = v; return r; }static sp_RbVal sp_box_str(const char *v) { sp_RbVal r; r.tag = SP_TAG_STR; r.cls_id = 0; r.v.s = v; return r; }static sp_RbVal sp_box_str_array(void *p) { return sp_box_obj(p, SP_BUILTIN_STR_ARRAY); }static sp_RbVal sp_box_sym_array(void *p) { return sp_box_obj(p, SP_BUILTIN_SYM_ARRAY); }static sp_RbVal sp_box_ptr_array(void *p) { return sp_box_obj(p, SP_BUILTIN_PTR_ARRAY); }static sp_RbVal sp_box_proc(void *p) { return sp_box_obj(p, SP_BUILTIN_PROC); }static void sp_poly_puts(sp_RbVal v) { switch (v.tag) { case SP_TAG_INT: printf("%lld\n", (long long)v.v.i); break;spinel_codegen.rbmodifiedView file
Loading diff…
test/proc_hash_value.rbaddedView file
Loading diff…