Commit fa9ec8a3

fa9ec8a3a75fMerged

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

Description

IO.pipe: bind both pipe ends as IO handles

r, w = IO.pipe now lowers to the existing runtime pipe helpers: a special case in the MultiWriteNode path (and its analyze typing) makes a pipe via sp_io_make_pipe and binds the two LocalVariableTargets to sp_io_fdopen handles typed TY_IO. Also map TY_IO through .class -> "IO".

The IO instance methods (read/write/close) were already wired.

Fixes io_pipe.

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

Details

Commit
fa9ec8a3a75f
Parent
1c9f042df01e

src/analyze.cmodifiedView file

@@ -683,7 +683,7 @@
683683 if (ty_is_object(rt)) return TY_CLASS; /* user object: return sp_Class value */
684684 if (ty_is_numeric(rt) || rt == TY_STRING || rt == TY_SYMBOL || rt == TY_BOOL ||
685685 rt == TY_RANGE || rt == TY_TIME || rt == TY_NIL || rt == TY_POLY ||
686- rt == TY_METHOD || rt == TY_PROC ||
686+ rt == TY_METHOD || rt == TY_PROC || rt == TY_IO ||
687687 ty_is_array(rt) || ty_is_hash(rt))
688688 return TY_STRING;
689689 }
@@ -4514,6 +4514,21 @@
45144514 const int *lefts = nt_arr(nt, id, "lefts", &ln);
45154515 int value = nt_ref(nt, id, "value");
45164516 const char *vty = nt_type(nt, value);
4517+ /* `r, w = IO.pipe` -> both targets are IO handles. */
4518+ if (ln == 2 && vty && !strcmp(vty, "CallNode") && nt_str(nt, value, "name") &&
4519+ !strcmp(nt_str(nt, value, "name"), "pipe")) {
4520+ int vrecv = nt_ref(nt, value, "receiver");
4521+ if (vrecv >= 0 && nt_type(nt, vrecv) && !strcmp(nt_type(nt, vrecv), "ConstantReadNode") &&
4522+ nt_str(nt, vrecv, "name") && !strcmp(nt_str(nt, vrecv, "name"), "IO")) {
4523+ for (int i = 0; i < 2; i++) {
4524+ if (strcmp(nt_type(nt, lefts[i]) ? nt_type(nt, lefts[i]) : "", "LocalVariableTargetNode")) continue;
4525+ const char *lnm = nt_str(nt, lefts[i], "name");
4526+ LocalVar *lv = lnm ? scope_local_intern(comp_scope_of(c, id), lnm) : NULL;
4527+ if (lv && lv->type != TY_IO) { lv->type = TY_IO; changed = 1; }
4528+ }
4529+ continue;
4530+ }
4531+ }
45174532 if (!vty || strcmp(vty, "ArrayNode")) {
45184533 /* scalar RHS (`a, b = 1`): the first target gets the scalar, the rest
45194534 their slot default. Type every target as the scalar's kind. Array /