Commit 7ed9f18c

7ed9f18ce32dMerged

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

Description

Add TY_REGEX type and interpolated regex codegen

  • Add TY_REGEX to TyKind enum for RegularExpressionNode and InterpolatedRegularExpressionNode AST nodes
  • Analyze: infer TY_REGEX for regex literals/vars, dispatch Regexp instance methods (match?, ===, match, =~, source, etc.)
  • Codegen: emit regex pattern C expressions via emit_regex_pat_to_buf; handle InterpolatedRegularExpressionNode by building pattern at runtime with re_compile(); fix emit_interp to C-escape backslashes in format strings so regex escapes like \d survive into the runtime
  • Fix SourceFileNode (TY_STRING) and SourceLineNode (TY_INT) analysis and codegen
  • Add FLT_ARRAY case to sp_PolyArray_flatten_into runtime helper
  • Fix empty ArrayNode boxed as empty IntArray in emit_boxed

Closes #61

Co-Authored-By: Claude Sonnet 4.6 [email protected]

Details

Commit
7ed9f18ce32d
Parent
219767d27954

lib/sp_runtime.hmodifiedView file

@@ -3217,6 +3217,7 @@
32173217 if (v.tag != SP_TAG_OBJ) { sp_PolyArray_push(dst, v); return; }
32183218 if (v.cls_id == SP_BUILTIN_INT_ARRAY) { sp_IntArray *ia = (sp_IntArray *)v.v.p; for (mrb_int i = 0; i < ia->len; i++) sp_PolyArray_push(dst, sp_box_int(ia->data[ia->start + i])); return; }
32193219 if (v.cls_id == SP_BUILTIN_STR_ARRAY) { sp_StrArray *sa = (sp_StrArray *)v.v.p; for (mrb_int i = 0; i < sa->len; i++) sp_PolyArray_push(dst, sp_box_str(sa->data[i])); return; }
3220+ if (v.cls_id == SP_BUILTIN_FLT_ARRAY) { sp_FloatArray *fa = (sp_FloatArray *)v.v.p; for (mrb_int i = 0; i < fa->len; i++) sp_PolyArray_push(dst, sp_box_float(fa->data[i])); return; }
32203221 if (v.cls_id == SP_BUILTIN_POLY_ARRAY) { sp_PolyArray *pa = (sp_PolyArray *)v.v.p; for (mrb_int i = 0; i < pa->len; i++) sp_PolyArray_flatten_into(dst, pa->data[i]); return; }
32213222 /* Other array variants fall through as opaque elements; rare for
32223223 deep-flatten use cases. */