Commit 2aee2930
2aee2930b822Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · ~4 modified
Description
StringScanner support + nullable-scalar truthiness in conditions
Wire StringScanner (require "strscan") into the compiler as a new TY_STRINGSCANNER type mirroring TY_STRINGIO: StringScanner.new and the scan/check/scan_until/matched/pos/pre_match/rest/getch/peek/[]/... methods dispatch to the existing sp_StringScanner_* runtime. String-returning methods are nullable (NULL = nil); string inspect/p are now NULL-aware (render "nil"), single-evaluating the receiver.
emit_cond now accepts nullable-representable types as a condition with Ruby truthiness: a NULL string/pointer, SP_INT_NIL int, or NaN float reads falsy, every other concrete value truthy. This also unblocks several non-scanner tests that branched on such values.
Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]
Details
- Commit
- 2aee2930b822
- Parent
- fcba30981477
src/analyze.cmodifiedView file
if (cn && !strcmp(cn, "Array") && argc == 2) return ty_array_of(infer_type(c, argv[1])); if (cn && !strcmp(cn, "String")) return TY_STRING; if (cn && !strcmp(cn, "StringIO")) return TY_STRINGIO; if (cn && !strcmp(cn, "StringScanner")) return TY_STRINGSCANNER; } } /* StringScanner instance methods */ if (recv >= 0 && rt == TY_STRINGSCANNER) { if (!strcmp(name, "scan") || !strcmp(name, "check") || !strcmp(name, "scan_until") || !strcmp(name, "matched") || !strcmp(name, "pre_match") || !strcmp(name, "post_match") || !strcmp(name, "rest") || !strcmp(name, "string") || !strcmp(name, "getch") || !strcmp(name, "peek") || !strcmp(name, "[]")) return TY_STRING; /* nullable via NULL */ if (!strcmp(name, "matched?") || !strcmp(name, "eos?") || !strcmp(name, "rest?")) return TY_BOOL; if (!strcmp(name, "pos") || !strcmp(name, "charpos") || !strcmp(name, "rest_size")) return TY_INT; if (!strcmp(name, "reset") || !strcmp(name, "terminate") || !strcmp(name, "unscan")) return TY_STRINGSCANNER; } /* StringIO.open(args) { |io| body } -> the block body's value */ if (recv >= 0 && !strcmp(name, "open") && nt_type(nt, recv) && !strcmp(nt_type(nt, recv), "ConstantReadNode") && nt_str(nt, recv, "name") &&src/codegen.cmodifiedView file
Loading diff…
src/types.cmodifiedView file
Loading diff…
src/types.hmodifiedView file
Loading diff…