Commit d0104eb8
d0104eb864c8Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 2 files · ~2 modified
Description
Add each_slice multi-param block, poly bitwise ops, and infer each_slice param types
each_slice: add multi-param block destructuring (|x, y| picks elements from the slice) mirroring the existing each_cons multi-param path. Also add each_slice to the analyze.c param-type inference block alongside each_cons.
Poly bitwise ops: poly_val >> int / & / | / ^ now lowers to sp_poly_to_i(recv) OP arg, matching how poly shift/bitops work in the runtime. Add TY_POLY recv to the infer_type bitwise table so calls return TY_INT rather than TY_UNKNOWN, fixing "unsupported puts argument" for expressions like arr[1][1] >> 1.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- d0104eb864c8
- Parent
- f4869a2e1761
src/analyze.cmodifiedView file
(!strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^") || !strcmp(name, "<<") || !strcmp(name, ">>"))) return TY_INT; /* poly recv bitwise shift: result is int (sp_poly_to_i applied) */ if (recv >= 0 && argc == 1 && rt == TY_POLY && (!strcmp(name, ">>") || !strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^"))) return TY_INT; /* boolean &/|/^ */ if (recv >= 0 && argc == 1 && rt == TY_BOOL && (!strcmp(name, "&") || !strcmp(name, "|") || !strcmp(name, "^"))) !strcmp(name, "detect") || !strcmp(name, "any?") || !strcmp(name, "all?"))) pt = TY_POLY; /* array.each_cons(n) { |a, b, ...| } -- a single param binds the n-element sub-array; multiple params destructure consecutive elements */ if (!strcmp(name, "each_cons") && ty_is_array(rt)) { /* array.each_cons(n) / each_slice(n) { |a, b, ...| } -- a single param binds the n-element sub-array; multiple params destructure elements */ if ((!strcmp(name, "each_cons") || !strcmp(name, "each_slice")) && ty_is_array(rt)) { Scope *es = comp_scope_of(c, block); int np = 0; while (block_param_name(c, block, np)) np++; for (int pj = 0; pj < np; pj++) {src/codegen.cmodifiedView file
Loading diff…