Commit 2863364f

2863364f391aMerged

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

Description

Box ranges and string/sym-keyed hashes into poly

emit_boxed now handles TY_RANGE (sp_box_range) and the hash variants with builtin poly tags (StrInt/StrStr/IntStr via sp_box_obj), so these can be stored in poly arrays / slots.

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
2863364f391a
Parent
ca31a2aa41c1

src/codegen.cmodifiedView file

@@ -2627,6 +2627,17 @@
26272627 buf_printf(b, ", %d)", ty_object_class(t));
26282628 return;
26292629 }
2630+ if (ty_is_hash(t)) {
2631+ static const struct { TyKind t; const char *id; } hids[] = {
2632+ {TY_STR_INT_HASH, "SP_BUILTIN_STR_INT_HASH"}, {TY_STR_STR_HASH, "SP_BUILTIN_STR_STR_HASH"},
2633+ {TY_INT_STR_HASH, "SP_BUILTIN_INT_STR_HASH"}, {TY_INT_INT_HASH, NULL} };
2634+ for (unsigned i = 0; i < sizeof hids / sizeof hids[0]; i++)
2635+ if (hids[i].t == t && hids[i].id) {
2636+ buf_printf(b, "sp_box_obj("); emit_expr(c, node, b); buf_printf(b, ", %s)", hids[i].id);
2637+ return;
2638+ }
2639+ unsupported(c, node, "boxing value into poly"); return;
2640+ }
26302641 const char *fn = NULL;
26312642 switch (t) {
26322643 case TY_INT: fn = "sp_box_int"; break;
@@ -2634,6 +2645,7 @@
26342645 case TY_STRING: fn = "sp_box_str"; break;
26352646 case TY_BOOL: fn = "sp_box_bool"; break;
26362647 case TY_SYMBOL: fn = "sp_box_sym"; break;
2648+ case TY_RANGE: fn = "sp_box_range"; break;
26372649 case TY_INT_ARRAY: fn = "sp_box_int_array"; break;
26382650 case TY_FLOAT_ARRAY: fn = "sp_box_float_array"; break;
26392651 case TY_STR_ARRAY: fn = "sp_box_str_array"; break;