Commit 5c19d067
5c19d067935fMerged
dak2 <[email protected]> · 6 months ago · 4 files · +2 added · ~2 modified
Description
feat(codegen): Hash#dig across hash variants
Hash#dig was unimplemented, so nested-hash traversal patterns common in Ruby code (config lookups, JSON-shaped data) had no path through the codegen. Multi-key dig also requires recovering the concrete hash type at each step, which needed cls_id stamping on boxed hash pointers — previously they boxed with cls_id=0 and lost type.
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 5c19d067935f
- Parent
- 2b02f7b1a841
lib/sp_runtime.hmodifiedView file
@@ -765,6 +765,15 @@
765765
#define SP_BUILTIN_RANGE (-10) /* sp_Range *, heap copy of stack-typed sp_Range when crossing into poly */766766
#define SP_BUILTIN_TIME (-11) /* sp_Time *, heap copy of stack-typed sp_Time when crossing into poly */767767
#define SP_BUILTIN_POLY_ARRAY (-12) /* sp_PolyArray *, array of sp_RbVal */768+
/* Hash variant cls_ids — boxed into the cls_id of a poly slot so769+
Hash#dig can recover the concrete hash type at runtime. */770+
#define SP_BUILTIN_STR_INT_HASH (-13)771+
#define SP_BUILTIN_STR_STR_HASH (-14)772+
#define SP_BUILTIN_INT_STR_HASH (-15)773+
#define SP_BUILTIN_SYM_INT_HASH (-16)774+
#define SP_BUILTIN_SYM_STR_HASH (-17)775+
#define SP_BUILTIN_STR_POLY_HASH (-18)776+
#define SP_BUILTIN_SYM_POLY_HASH (-19)768777
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;769778
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; }770779
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; }spinel_codegen.rbmodifiedView file
Loading diff…
test/hash_dig.rbaddedView file
Loading diff…
test/hash_dig.rb.expectedaddedView file
Loading diff…