Commit 3c63156f
3c63156f2478Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 6 files · ~6 modified
Description
fix(analyze,codegen,runtime): close remaining #555 cases (07 dig, 11 =~ 0-indexed)
Followup to 085fc41 + 3dcb18f. With this commit spinel matches CRuby on all 12 cases of Adam Doppelt's "should be true but they are false" corpus.
Case 11: =~ returns 0-indexed match position with -1
sentinel for no match. Pre-fix it returned pos + 1 (or 0
for no match) -- a truthiness-compatible sentinel that was
load-bearing for if (s =~ /pat/) working at position 0,
but off-by-one from CRuby's int return semantics. The
truthiness check at regex_match_call_node? is updated from
!= 0 to >= 0 so match-at-position-0 stays truthy. The
existing test/regex.rb expected line for m_s2_index + 10
goes from 12 (1+1+10 pre-fix) to 11 (1+10 CRuby).
Case 07: Array#dig over a heterogeneous poly_array of hashes. Two pieces:
-
poly_array.dig(idx, key...) emit: get arr[idx] then walk the remaining keys via emit_dig_step's cls_id-aware Hash dispatch. Mirror of the existing Hash#dig multi-key path. compile_array_method_expr's dig arm previously fell through to "unsupported" for multi-arg.
-
sym-key sym-value hash literals (
{foo: :bar}) infer as sym_poly_hash rather than sym_int_hash so the symbol value preserves its SP_TAG_SYM tag through lookup. The sym_int_hash storage stores sym ids as mrb_int and the dispatch'ssp_box_intround-trip lost the symbol-ness -- comparing the dug value to:barfailed because poly_eq's tag check saw SP_TAG_INT vs SP_TAG_SYM. The sym_poly_hash path boxes correctly. -
scan_for_dig_usage pre-scan that arms @needs_sym_int_hash / sym_str_hash / sym_poly_hash / str_poly_hash so emit_dig_step's full arm set has every typedef it references. The compile-side
@needs_flag flips run after the typedef-emit pass.
Verified: 525 tests pass (including the 12-case fixture and the updated regex.rb expected), optcarrot checksum 59662 preserved.
Refs #555
Co-Authored-By: Claude Opus 4.7 (1M context) [email protected]
Details
- Commit
- 3c63156f2478
- Parent
- 1043795935b5
lib/sp_runtime.hmodifiedView file
}}/* `=~` returns the match position (0-indexed) or -1 on miss. Codegen's regex truthy check (regex_match_call_node? arm in compile_cond_expr) compares against -1 so match-at-position-0 is correctly truthy. Direct value use lines up with CRuby's `String#=~` int semantics: "abc" =~ /b/ -> 1, not 2. */static mrb_int sp_re_match(mrb_regexp_pattern *pat, const char *str) { int64_t slen = (int64_t)strlen(str); int ncaps = 32; int n = re_exec(pat, str, slen, 0, sp_re_caps, ncaps); if (n > 0) { sp_re_set_captures(str, sp_re_caps, n/2); return sp_re_caps[0] + 1; } return 0; if (n > 0) { sp_re_set_captures(str, sp_re_caps, n/2); return sp_re_caps[0]; } return -1;}/* `s.rindex(regex)` — last match start, in BYTE offset (matchesspinel_analyze.rbmodifiedView file
Loading diff…
spinel_codegen.rbmodifiedView file
Loading diff…
test/equality_should_be_true.rbmodifiedView file
Loading diff…
test/equality_should_be_true.rb.expectedmodifiedView file
Loading diff…
test/regex.rb.expectedmodifiedView file
Loading diff…