Rewrite with working async

This commit is contained in:
2026-10-16 08:00:06 +00:00
parent d0c2f291e9
commit 1e4647347f
36 changed files with 5106 additions and 654 deletions
+9 -9
View File
@@ -31,7 +31,7 @@
// ── sync ──
undefined_t __native_print_string(string_t s) {
char *utf8 = jsrt_string_utf8(s);
char *utf8 = __rt_string_utf8(s);
puts(utf8);
free(utf8);
return (undefined_t){0};
@@ -178,7 +178,7 @@ static void jsrt_io_release(int32_t h) {
// The op that the last wait gave. A handle of any other op is an error
static jsrt_io_op *jsrt_io_given(int32_t h) {
if (h < 0 || h != jsrt_io.given) {
jsrt_type_error();
__rt_type_error("an IO result read outside its op's callback");
}
return &jsrt_io.ops[h];
@@ -320,7 +320,7 @@ int32_t __native_io_queue_timeout(double ms) {
// `flags` and `mode` are open(2)'s, as numbers
int32_t __native_io_queue_open(string_t path, int32_t flags, int32_t mode) {
int32_t h = jsrt_io_new(JSRT_IO_OPEN);
jsrt_io.ops[h].buf = jsrt_string_utf8(path);
jsrt_io.ops[h].buf = __rt_string_utf8(path);
jsrt_io.ops[h].flags = flags | O_CLOEXEC;
jsrt_io.ops[h].mode = mode;
return jsrt_io_queue(h);
@@ -334,7 +334,7 @@ int32_t __native_io_queue_read(int32_t fd, int32_t len, double offset) {
op->fd = fd;
op->len = len > 0 ? (uint32_t)len : 0;
op->off = offset < 0 ? (uint64_t)-1 : (uint64_t)offset;
op->buf = jsrt_alloc(op->len ? op->len : 1);
op->buf = __rt_alloc(op->len ? op->len : 1);
return jsrt_io_queue(h);
}
@@ -344,7 +344,7 @@ int32_t __native_io_queue_write(int32_t fd, string_t data, double offset) {
int32_t h = jsrt_io_new(JSRT_IO_WRITE);
jsrt_io_op *op = &jsrt_io.ops[h];
op->fd = fd;
op->buf = jsrt_string_utf8(data);
op->buf = __rt_string_utf8(data);
op->len = (uint32_t)strlen(op->buf);
op->off = offset < 0 ? (uint64_t)-1 : (uint64_t)offset;
return jsrt_io_queue(h);
@@ -359,9 +359,9 @@ int32_t __native_io_queue_close(int32_t fd) {
// Gives the file's size, as `__native_io_result_number`
int32_t __native_io_queue_stat(string_t path) {
int32_t h = jsrt_io_new(JSRT_IO_STAT);
char *utf8 = jsrt_string_utf8(path);
char *utf8 = __rt_string_utf8(path);
size_t size = strlen(utf8) + 1;
char *buf = jsrt_alloc(sizeof(struct statx) + size);
char *buf = __rt_alloc(sizeof(struct statx) + size);
memcpy(buf + sizeof(struct statx), utf8, size);
free(utf8);
jsrt_io.ops[h].buf = buf;
@@ -373,7 +373,7 @@ int32_t __native_io_queue_stat(string_t path) {
// -EALREADY
int32_t __native_io_queue_cancel(int32_t target) {
if (target < 0 || target >= jsrt_io.cap) {
jsrt_type_error();
__rt_type_error("a cancel of an op that does not exist");
}
int32_t h = jsrt_io_new(JSRT_IO_CANCEL);
@@ -439,7 +439,7 @@ int32_t __native_io_status(int32_t h) {
string_t __native_io_result_string(int32_t h) {
jsrt_io_op *op = jsrt_io_given(h);
bool data = op->kind == JSRT_IO_READ && op->res > 0;
return jsrt_string_from_utf8(op->buf, data ? (size_t)op->res : 0);
return __rt_string_from_utf8(op->buf, data ? (size_t)op->res : 0);
}
// The size of a stat's file. The status for any other op