Commit 411bf93a

411bf93a5b3aMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 8 months ago · 4 files · ~4 modified

Description

Reduce lrama compilation warnings: add unless-expr, kwargs, map!, warn, insert, fix Integer#<=

  • Add PM_UNLESS_NODE as expression in codegen_expr (node type 146)
  • Handle PM_KEYWORD_HASH_NODE in codegen_expr (node type 90)
  • Add Array#map! (in-place map) for IntArray in expr.c
  • Add Kernel#warn as fprintf(stderr, ...) in stmt.c
  • Add Array#insert with sp_IntArray_insert in emit.c and expr.c
  • Fix Integer#<= by allowing VALUE type on one side of numeric binops
  • Add map!/insert to type inference in type.c

Reduces lrama warnings from 205 to 183.

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

Details

Commit
411bf93a5b3a
Parent
37d3a83c1dfa

src/emit.cmodifiedView file

@@ -1815,6 +1815,21 @@
18151815 emit_raw(ctx, " }\n");
18161816 emit_raw(ctx, " return r;\n}\n\n");
18171817
1818+ /* ---- IntArray insert ---- */
1819+ emit_raw(ctx, "static void sp_IntArray_insert(sp_IntArray *a, mrb_int idx, mrb_int val) {\n");
1820+ emit_raw(ctx, " if (idx < 0) idx += a->len;\n");
1821+ emit_raw(ctx, " if (idx < 0) idx = 0;\n");
1822+ emit_raw(ctx, " if (idx > a->len) idx = a->len;\n");
1823+ emit_raw(ctx, " if (a->start + a->len >= a->cap) {\n");
1824+ emit_raw(ctx, " a->cap = (a->cap < 16) ? 16 : a->cap * 2;\n");
1825+ emit_raw(ctx, " a->data = (mrb_int *)realloc(a->data, sizeof(mrb_int) * a->cap);\n");
1826+ emit_raw(ctx, " }\n");
1827+ emit_raw(ctx, " memmove(a->data + a->start + idx + 1, a->data + a->start + idx,\n");
1828+ emit_raw(ctx, " sizeof(mrb_int) * (a->len - idx));\n");
1829+ emit_raw(ctx, " a->data[a->start + idx] = val;\n");
1830+ emit_raw(ctx, " a->len++;\n");
1831+ emit_raw(ctx, "}\n\n");
1832+
18181833 /* Built-in sp_StrArray for string split support (only when needed) */
18191834 if (ctx->needs_str_split && !ctx->lambda_mode) {
18201835 emit_raw(ctx, "/* ---- Built-in string array ---- */\n");