Commit c6ddf4aa

c6ddf4aaa973Merged

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

Description

Add TY_POLY_POLY_HASH to hash boxing and handle empty hash literals

  • hash_box_cls: add TY_POLY_POLY_HASH -> SP_BUILTIN_POLY_POLY_HASH
  • emit_boxed: handle TY_UNKNOWN HashNode (empty {}) -> empty PolyPolyHash, mirroring the existing TY_UNKNOWN ArrayNode -> empty IntArray case

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

Details

Commit
c6ddf4aaa973
Parent
e96d335861d1

src/codegen.cmodifiedView file

@@ -10826,12 +10826,13 @@
1082610826 /* Box a C-text expression `expr` of static type `t` into an sp_RbVal. */
1082710827 static const char *hash_box_cls(TyKind t) {
1082810828 switch (t) {
10829- case TY_STR_INT_HASH: return "SP_BUILTIN_STR_INT_HASH";
10830- case TY_STR_STR_HASH: return "SP_BUILTIN_STR_STR_HASH";
10831- case TY_INT_STR_HASH: return "SP_BUILTIN_INT_STR_HASH";
10832- case TY_STR_POLY_HASH: return "SP_BUILTIN_STR_POLY_HASH";
10833- case TY_SYM_POLY_HASH: return "SP_BUILTIN_SYM_POLY_HASH";
10834- default: return NULL;
10829+ case TY_STR_INT_HASH: return "SP_BUILTIN_STR_INT_HASH";
10830+ case TY_STR_STR_HASH: return "SP_BUILTIN_STR_STR_HASH";
10831+ case TY_INT_STR_HASH: return "SP_BUILTIN_INT_STR_HASH";
10832+ case TY_STR_POLY_HASH: return "SP_BUILTIN_STR_POLY_HASH";
10833+ case TY_SYM_POLY_HASH: return "SP_BUILTIN_SYM_POLY_HASH";
10834+ case TY_POLY_POLY_HASH: return "SP_BUILTIN_POLY_POLY_HASH";
10835+ default: return NULL;
1083510836 }
1083610837 }
1083710838
@@ -10899,6 +10900,11 @@
1089910900 int _ne = 0; nt_arr(c->nt, node, "elements", &_ne);
1090010901 if (_ne == 0) { buf_puts(b, "sp_box_int_array(sp_IntArray_new())"); return; }
1090110902 }
10903+ /* an empty hash literal {} has TY_UNKNOWN; box it as an empty PolyPolyHash */
10904+ if (t == TY_UNKNOWN && nt_type(c->nt, node) && !strcmp(nt_type(c->nt, node), "HashNode")) {
10905+ int _ne = 0; nt_arr(c->nt, node, "elements", &_ne);
10906+ if (_ne == 0) { buf_puts(b, "sp_box_obj(sp_PolyPolyHash_new(), SP_BUILTIN_POLY_POLY_HASH)"); return; }
10907+ }
1090210908 const char *fn = NULL;
1090310909 switch (t) {
1090410910 case TY_INT: fn = "sp_box_int"; break;