diff --git a/third_party/quickjs/qjsc.c b/third_party/quickjs/qjsc.c index 707c7a230..242b641a7 100644 --- a/third_party/quickjs/qjsc.c +++ b/third_party/quickjs/qjsc.c @@ -632,9 +632,11 @@ int main(int argc, char **argv) "\n" ); } else { +#ifndef COSMO fprintf(fo, "#include \n" "\n" ); +#endif } for(i = optind; i < argc; i++) { const char *filename = argv[i]; diff --git a/third_party/quickjs/quickjs-libc.c b/third_party/quickjs/quickjs-libc.c index d0ebefdfc..163e058cf 100644 --- a/third_party/quickjs/quickjs-libc.c +++ b/third_party/quickjs/quickjs-libc.c @@ -24,6 +24,7 @@ */ #include "libc/assert.h" #include "libc/calls/calls.h" +#include "libc/calls/internal.h" #include "libc/calls/ioctl.h" #include "libc/calls/struct/winsize.h" #include "libc/calls/termios.h" @@ -31,6 +32,7 @@ #include "libc/fmt/conv.h" #include "libc/fmt/fmt.h" #include "libc/limits.h" +#include "libc/nt/synchronization.h" #include "libc/runtime/dlfcn.h" #include "libc/runtime/sysconf.h" #include "libc/sock/select.h" @@ -1737,7 +1739,6 @@ static JSValue js_os_ttySetRaw(JSContext *ctx, JSValueConst this_val, if (JS_ToInt32(ctx, &fd, argv[0])) return JS_EXCEPTION; - memset(&tty, 0, sizeof(tty)); tcgetattr(fd, &tty); oldtty = tty; @@ -2063,9 +2064,14 @@ static void call_handler(JSContext *ctx, JSValueConst func) JS_FreeValue(ctx, ret); } -#if defined(_WIN32) +#if defined(COSMO) +#define DWORD uint32_t +#define HANDLE int64_t +#define _get_osfhandle(fd) g_fds.p[fd].handle +#define INFINITE ((DWORD)-1) +#define WAIT_OBJECT_0 ((DWORD)0) -static int js_os_poll(JSContext *ctx) +static int js_os_poll_nt(JSContext *ctx) { JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = JS_GetRuntimeOpaque(rt); @@ -2138,7 +2144,6 @@ static int js_os_poll(JSContext *ctx) } return 0; } -#else #ifdef USE_WORKER @@ -2219,6 +2224,9 @@ static int handle_posted_message(JSRuntime *rt, JSContext *ctx, static int js_os_poll(JSContext *ctx) { + if (IsWindows()) { + return js_os_poll_nt(ctx); + } JSRuntime *rt = JS_GetRuntime(ctx); JSThreadState *ts = JS_GetRuntimeOpaque(rt); int ret, fd_max, min_delay; diff --git a/third_party/quickjs/quickjs.mk b/third_party/quickjs/quickjs.mk index 8e8396a5f..0e068ef55 100644 --- a/third_party/quickjs/quickjs.mk +++ b/third_party/quickjs/quickjs.mk @@ -52,8 +52,7 @@ THIRD_PARTY_QUICKJS_A_SRCS = \ third_party/quickjs/tok.c \ third_party/quickjs/typedarray.c \ third_party/quickjs/uri.c \ - third_party/quickjs/usage.c \ - third_party/quickjs/wut.c + third_party/quickjs/usage.c THIRD_PARTY_QUICKJS_A_HDRS = \ third_party/quickjs/cutils.h \ @@ -78,6 +77,7 @@ THIRD_PARTY_QUICKJS_A_DIRECTDEPS = \ LIBC_LOG \ LIBC_MEM \ LIBC_NEXGEN32E \ + LIBC_NT_KERNEL32 \ LIBC_RUNTIME \ LIBC_SOCK \ LIBC_STDIO \ @@ -127,11 +127,22 @@ THIRD_PARTY_QUICKJS_CHECKS = \ $(THIRD_PARTY_QUICKJS_A).pkg \ $(THIRD_PARTY_QUICKJS_A_HDRS:%=o/$(MODE)/%.ok) +o/$(MODE)/third_party/quickjs/qjscalc.c: \ +third_party/quickjs/qjscalc.js \ +o/$(MODE)/third_party/quickjs/qjsc.com + o/$(MODE)/third_party/quickjs/qjsc.com -fbignum -o $@ -c $< +o/$(MODE)/third_party/quickjs/repl.c: \ +third_party/quickjs/repl.js \ +o/$(MODE)/third_party/quickjs/qjsc.com + o/$(MODE)/third_party/quickjs/qjsc.com -o $@ -m -c $< + o/$(MODE)/third_party/quickjs/qjs.com.dbg: \ $(THIRD_PARTY_QUICKJS_A_DEPS) \ $(THIRD_PARTY_QUICKJS_A) \ $(THIRD_PARTY_QUICKJS_A).pkg \ o/$(MODE)/third_party/quickjs/qjs.o \ + o/$(MODE)/third_party/quickjs/repl.o \ + o/$(MODE)/third_party/quickjs/qjscalc.o \ $(CRT) \ $(APE) -@$(APELINK) diff --git a/third_party/quickjs/wut.c b/third_party/quickjs/wut.c deleted file mode 100644 index 583019bdc..000000000 --- a/third_party/quickjs/wut.c +++ /dev/null @@ -1,24 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2021 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "third_party/quickjs/quickjs.h" - -uint8_t qjsc_repl[FRAMESIZE]; -uint32_t qjsc_repl_size = FRAMESIZE; -uint8_t qjsc_qjscalc[FRAMESIZE]; -uint32_t qjsc_qjscalc_size = FRAMESIZE;