Commit e63fe27a

e63fe27ab2e5Merged

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

Description

Handle to_s on unknown/VALUE/Float types and puts/print on unknown receivers

Add codegen for to_s called on Float (sp_float_to_s), VALUE and UNKNOWN (sp_int_to_s cast) typed receivers in expr.c, preventing them from hitting the unsupported-call fallback. In stmt.c, handle puts/print with a receiver of VALUE/UNKNOWN type by emitting fprintf(stdout, ...) instead of falling through to codegen_expr which would emit a warning.

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

Details

Commit
e63fe27ab2e5
Parent
e4a7da259090

src/expr.cmodifiedView file

@@ -3188,6 +3188,19 @@
31883188 free(recv); free(method);
31893189 return r;
31903190 }
3191+ if (strcmp(method, "to_s") == 0 && recv_t.kind == SPINEL_TYPE_FLOAT) {
3192+ char *recv = codegen_expr(ctx, call->receiver);
3193+ char *r = sfmt("sp_float_to_s(%s)", recv);
3194+ free(recv); free(method);
3195+ return r;
3196+ }
3197+ if (strcmp(method, "to_s") == 0 &&
3198+ (recv_t.kind == SPINEL_TYPE_VALUE || recv_t.kind == SPINEL_TYPE_UNKNOWN)) {
3199+ char *recv = codegen_expr(ctx, call->receiver);
3200+ char *r = sfmt("sp_int_to_s((mrb_int)%s)", recv);
3201+ free(recv); free(method);
3202+ return r;
3203+ }
31913204 if (strcmp(method, "to_i") == 0 && recv_t.kind == SPINEL_TYPE_FLOAT) {
31923205 char *recv = codegen_expr(ctx, call->receiver);
31933206 char *r = sfmt("((mrb_int)%s)", recv);