Commit a09a6b8b
a09a6b8b339bMerged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +1 added · ~2 modified
Description
feat(codegen): inspect for nested T_array_ptr_array (p / inspect)
p [[1, 2], [3, 4]] previously printed a pointer address because
compile_inspect_for had no branch for ptr_array types and fell
through to compile_puts_single's printf("%lld", ...) default.
Adds four runtime helpers — sp_{Int,Float,Str,Sym}ArrayPtrArray_inspect — that recurse into the matching primitive inspect for each element, and a compile_inspect_for branch dispatching on the four T_array_ptr_array shapes. Output now matches CRuby byte-for-byte for nested arrays of the four built-in T_array element types.
obj__ptr_array and poly_array_ptr_array still fall through; those need their own per-element formatting and aren't covered here.
Closes #169
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- a09a6b8b339b
- Parent
- a2504c560496
lib/sp_runtime.hmodifiedView file
/* PtrArray elements are object pointers without a per-element class tag, so we render them as `#<Object>` rather than recursing. */static const char*sp_PtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,"#<Object>");}sp_String_append(s,"]");return s->data;}/* Nested-array inspect: when codegen knows the ptr_array's element type is one of the four built-in T_array shapes, recurse into the matching primitive inspect (issue #169). */static const char*sp_IntArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_IntArray_inspect((sp_IntArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}static const char*sp_FloatArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_FloatArray_inspect((sp_FloatArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}static const char*sp_StrArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_StrArray_inspect((sp_StrArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}static const char*sp_SymArrayPtrArray_inspect(sp_PtrArray*a){sp_String*s=sp_String_new("[");for(mrb_int i=0;i<a->len;i++){if(i>0)sp_String_append(s,", ");sp_String_append(s,sp_SymArray_inspect((sp_IntArray*)a->data[i]));}sp_String_append(s,"]");return s->data;}/* Regexp engine (link with libspre.a from lib/regexp/) */typedef struct mrb_regexp_pattern mrb_regexp_pattern;spinel_codegen.rbmodifiedView file
Loading diff…
test/array_ptr_array_inspect.rbaddedView file
Loading diff…