mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-03-03 15:38:22 +00:00
quickjs: add repl + qjscalc (#251)
- Compile repl.js & qjscalc.js and include them in qjs.com zip - Change quickjs-libc.c / js_os_poll to handle Windows console This last change is needed because poll and select on Windows forbid non-socket handles and Cosmopolitan Libc hasn't polyfilled that yet.
This commit is contained in:
parent
1b93066883
commit
6ad0602392
4 changed files with 27 additions and 30 deletions
2
third_party/quickjs/qjsc.c
vendored
2
third_party/quickjs/qjsc.c
vendored
|
@ -632,9 +632,11 @@ int main(int argc, char **argv)
|
|||
"\n"
|
||||
);
|
||||
} else {
|
||||
#ifndef COSMO
|
||||
fprintf(fo, "#include <inttypes.h>\n"
|
||||
"\n"
|
||||
);
|
||||
#endif
|
||||
}
|
||||
for(i = optind; i < argc; i++) {
|
||||
const char *filename = argv[i];
|
||||
|
|
16
third_party/quickjs/quickjs-libc.c
vendored
16
third_party/quickjs/quickjs-libc.c
vendored
|
@ -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;
|
||||
|
|
15
third_party/quickjs/quickjs.mk
vendored
15
third_party/quickjs/quickjs.mk
vendored
|
@ -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)
|
||||
|
|
24
third_party/quickjs/wut.c
vendored
24
third_party/quickjs/wut.c
vendored
|
@ -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;
|
Loading…
Add table
Reference in a new issue