Commit b6ca2e98
b6ca2e981e94Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 4 files · ~4 modified
Description
Add TY_IO type, File/IO methods, Mutex/Monitor synchronize, Process.clock_gettime
- New TY_IO type for File/IO handles (types.h, types.c)
- analyze.c: pin File.open/new block param to TY_IO; TY_IO instance methods (read, write, puts, each_line, readlines, closed?, etc.); File.join/readlines class methods; Process.clock_gettime -> TY_FLOAT; Monitor.new -> TY_POLY; synchronize block return type inference
- codegen.c: File.open block form with last-stmt can_expr check; File.join (sp_file_join), File.readlines (chomp kwarg); TY_IO each_line/each -> sp_File_gets while loop; TY_IO/TY_FIBER emit_boxed cases; Process.clock_gettime dispatch; Mutex/Monitor.new -> sp_box_nil(); synchronize block inline emission
Fixes mutex_synchronize_block and several File/IO/Process tests.
Co-Authored-By: Claude Sonnet 4.6 [email protected]
Details
- Commit
- b6ca2e981e94
- Parent
- f1f6caafc613
src/analyze.cmodifiedView file
@@ -583,7 +583,7 @@
583583
if (cn && !strcmp(cn, "Hash")) return TY_UNKNOWN;584584
if (cn && !strcmp(cn, "Regexp")) return TY_REGEX;585585
if (cn && !strcmp(cn, "Fiber")) return TY_FIBER;586-
if (cn && (!strcmp(cn, "Thread") || !strcmp(cn, "Mutex") ||586+
if (cn && (!strcmp(cn, "Thread") || !strcmp(cn, "Mutex") || !strcmp(cn, "Monitor") ||587587
!strcmp(cn, "Random") || !strcmp(cn, "IO") || !strcmp(cn, "File") ||588588
!strcmp(cn, "GzipReader") || !strcmp(cn, "GzipWriter"))) return TY_POLY;589589
}@@ -617,7 +617,7 @@
617617
if (cn && !strcmp(cn, "Regexp")) return TY_REGEX;618618
/* Builtin object types */619619
if (cn && !strcmp(cn, "Fiber")) return TY_FIBER;620-
if (cn && (!strcmp(cn, "Thread") || !strcmp(cn, "Mutex") ||620+
if (cn && (!strcmp(cn, "Thread") || !strcmp(cn, "Mutex") || !strcmp(cn, "Monitor") ||621621
!strcmp(cn, "Random") || !strcmp(cn, "IO") || !strcmp(cn, "File") ||622622
!strcmp(cn, "GzipReader") || !strcmp(cn, "GzipWriter"))) return TY_POLY;623623
}@@ -1505,6 +1505,15 @@
15051505
!strcmp(name, "readline")) return TY_STRING;15061506
if (!strcmp(name, "close") || !strcmp(name, "flush")) return TY_NIL;15071507
if (!strcmp(name, "fileno")) return TY_INT;1508+
if (!strcmp(name, "synchronize")) {1509+
int blk_id = nt_ref(nt, id, "block");1510+
if (blk_id >= 0) {1511+
int bdy = nt_ref(nt, blk_id, "body");1512+
int bbn = 0; const int *bbb = bdy >= 0 ? nt_arr(nt, bdy, "body", &bbn) : NULL;1513+
if (bbn > 0) return infer_type(c, bbb[bbn - 1]);1514+
}1515+
return TY_NIL;1516+
}15081517
}15091518
}15101519
src/codegen.cmodifiedView file
Loading diff…
src/types.cmodifiedView file
Loading diff…
src/types.hmodifiedView file
Loading diff…