Skip to content

Commit 8f52c0d

Browse files
committed
Get Fabrice Bellard's JavaScript engine to build
$ m=tiny $ make -j12 MODE=$m o/$m/third_party/quickjs/qjs.com $ o/$m/third_party/quickjs/qjs.com -e 'console.log(2 + 2)' 4 $ ls -hal o/$m/third_party/quickjs/qjs.com 631.5K See #97
1 parent 1fbfbb3 commit 8f52c0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+966
-1311
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ include third_party/third_party.mk
136136
include libc/testlib/testlib.mk
137137
include tool/viz/lib/vizlib.mk
138138
include third_party/lua/lua.mk
139+
include third_party/quickjs/quickjs.mk
139140
include examples/examples.mk
140141
include third_party/lz4cli/lz4cli.mk
141142
include tool/build/lib/buildlib.mk

libc/runtime/dlfcn.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef COSMOPOLITAN_LIBC_RUNTIME_DLFCN_H_
2+
#define COSMOPOLITAN_LIBC_RUNTIME_DLFCN_H_
3+
4+
#define RTLD_LOCAL 0
5+
#define RTLD_LAZY 1
6+
#define RTLD_NOW 2
7+
#define RTLD_GLOBAL 256
8+
9+
#if !(__ASSEMBLER__ + __LINKER__ + 0)
10+
COSMOPOLITAN_C_START_
11+
12+
#define RTLD_NEXT ((void *)-1)
13+
#define RTLD_DEFAULT ((void *)0)
14+
15+
char *dlerror(void);
16+
void *dlopen(const char *, int);
17+
void *dlsym(void *, const char *);
18+
int dlclose(void *);
19+
int dl_iterate_phdr(int (*)(void *, size_t, void *), void *);
20+
21+
COSMOPOLITAN_C_END_
22+
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
23+
#endif /* COSMOPOLITAN_LIBC_RUNTIME_DLFCN_H_ */

libc/runtime/fegetround.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2021 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/runtime/fenv.h"
20+
21+
/**
22+
* Returns rounding mode.
23+
*
24+
* This implementation retrieves it from the x87 FPU control word.
25+
*
26+
* @see fesetround() for changing this
27+
*/
28+
int fegetround(void) {
29+
uint16_t x87cw;
30+
asm("fnstcw\t%0" : "=m"(x87cw));
31+
return x87cw & 0x0c00;
32+
}

libc/runtime/fenv.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2021 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/runtime/fenv.h"
20+
21+
/* TODO: implement these functions */
22+
23+
int feclearexcept(int mask) {
24+
return 0;
25+
}
26+
27+
int fegetenv(fenv_t *envp) {
28+
return 0;
29+
}
30+
31+
int feraiseexcept(int mask) {
32+
return 0;
33+
}
34+
35+
int fetestexcept(int mask) {
36+
return 0;
37+
}
38+
39+
int fesetenv(const fenv_t *envp) {
40+
return 0;
41+
}

libc/runtime/fenv.h

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#ifndef COSMOPOLITAN_LIBC_RUNTIME_FENV_H_
2+
#define COSMOPOLITAN_LIBC_RUNTIME_FENV_H_
3+
4+
#define FE_TONEAREST 0x0000
5+
#define FE_DOWNWARD 0x0400
6+
#define FE_UPWARD 0x0800
7+
#define FE_TOWARDZERO 0x0c00
8+
9+
#define FE_INVALID 1
10+
#define FE_DIVBYZERO 4
11+
#define FE_OVERFLOW 8
12+
#define FE_UNDERFLOW 16
13+
#define FE_INEXACT 32
14+
#define FE_ALL_EXCEPT 61
15+
16+
#if !(__ASSEMBLER__ + __LINKER__ + 0)
17+
COSMOPOLITAN_C_START_
18+
19+
#define FLT_ROUNDS (__flt_rounds())
20+
21+
typedef void *fenv_t;
22+
typedef uint16_t fexcept_t;
23+
24+
int feclearexcept(int);
25+
int fegetenv(fenv_t *);
26+
int fegetexceptflag(fexcept_t *, int);
27+
int fegetround(void);
28+
int feholdexcept(fenv_t *);
29+
int feraiseexcept(int);
30+
int fesetenv(const fenv_t *);
31+
int fesetexceptflag(const fexcept_t *, int);
32+
int fesetround(int);
33+
int fetestexcept(int);
34+
int feupdateenv(const fenv_t *);
35+
int __flt_rounds(void);
36+
37+
COSMOPOLITAN_C_END_
38+
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
39+
#endif /* COSMOPOLITAN_LIBC_RUNTIME_FENV_H_ */

libc/runtime/fesetround.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2021 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/runtime/fenv.h"
20+
21+
/* TODO(jart): This needs tests. */
22+
23+
/**
24+
* Sets rounding mode.
25+
*
26+
* This configures the x87 FPU as well as SSE.
27+
*
28+
* @param mode may be FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, or FE_TOWARDZERO
29+
* @return 0 on success, or -1 on error
30+
*/
31+
int fesetround(int mode) {
32+
uint16_t x87cw;
33+
uint32_t ssecw;
34+
switch (mode) {
35+
case FE_TONEAREST:
36+
case FE_DOWNWARD:
37+
case FE_UPWARD:
38+
case FE_TOWARDZERO:
39+
asm("fnstcw\t%0" : "=m"(x87cw));
40+
x87cw &= ~0x0c00;
41+
x87cw |= mode;
42+
asm volatile("fldcw\t%0" : /* no outputs */ : "m"(x87cw));
43+
asm("stmxcsr\t%0" : "=m"(ssecw));
44+
ssecw &= ~(0x0c00 << 3);
45+
ssecw |= (mode << 3);
46+
asm volatile("ldmxcsr\t%0" : /* no outputs */ : "m"(ssecw));
47+
return 0;
48+
default:
49+
return -1;
50+
}
51+
}

libc/runtime/fltrounds.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
2+
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
3+
╞══════════════════════════════════════════════════════════════════════════════╡
4+
│ Copyright 2021 Justine Alexandra Roberts Tunney │
5+
│ │
6+
│ Permission to use, copy, modify, and/or distribute this software for │
7+
│ any purpose with or without fee is hereby granted, provided that the │
8+
│ above copyright notice and this permission notice appear in all copies. │
9+
│ │
10+
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
11+
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
12+
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
13+
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
14+
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
15+
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
16+
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
17+
│ PERFORMANCE OF THIS SOFTWARE. │
18+
╚─────────────────────────────────────────────────────────────────────────────*/
19+
#include "libc/runtime/fenv.h"
20+
21+
int __flt_rounds(void) {
22+
switch (fegetround()) {
23+
case FE_TOWARDZERO:
24+
return 0;
25+
case FE_TONEAREST:
26+
return 1;
27+
case FE_UPWARD:
28+
return 2;
29+
case FE_DOWNWARD:
30+
return 3;
31+
default:
32+
return -1;
33+
}
34+
}

libc/runtime/ldso.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
1717
│ PERFORMANCE OF THIS SOFTWARE. │
1818
╚─────────────────────────────────────────────────────────────────────────────*/
19-
#include "libc/runtime/runtime.h"
19+
#include "libc/runtime/dlfcn.h"
2020

2121
char *dlerror(void) {
2222
return "cosmopolitan doesn't support dsos";

libc/sysv/consts.sh

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1573,17 +1573,6 @@ syscon misc TCOFLUSH 1 2 2 2 2 0 # bsd consensus
15731573
syscon misc TCOOFF 0 1 1 1 1 0 # bsd consensus
15741574
syscon misc TCOON 1 2 2 2 2 0 # bsd consensus
15751575

1576-
syscon misc FE_TONEAREST 0 0 0 0 0 0 # consensus
1577-
syscon misc FE_DIVBYZERO 4 4 4 4 4 0 # unix consensus
1578-
syscon misc FE_DOWNWARD 0x0400 0x0400 0x0400 0x0400 0x0400 0 # unix consensus
1579-
syscon misc FE_INEXACT 0x20 0x20 0x20 0x20 0x20 0 # unix consensus
1580-
syscon misc FE_INVALID 1 1 1 1 1 0 # unix consensus
1581-
syscon misc FE_OVERFLOW 8 8 8 8 8 0 # unix consensus
1582-
syscon misc FE_TOWARDZERO 0x0c00 0x0c00 0x0c00 0x0c00 0x0c00 0 # unix consensus
1583-
syscon misc FE_UNDERFLOW 0x10 0x10 0x10 0x10 0x10 0 # unix consensus
1584-
syscon misc FE_UPWARD 0x0800 0x0800 0x0800 0x0800 0x0800 0 # unix consensus
1585-
syscon misc FE_ALL_EXCEPT 61 63 63 63 63 0 # bsd consensus
1586-
15871576
syscon misc TYPE_DISK 0 0 0 0 0 0 # consensus
15881577
syscon misc TYPE_A 1 1 1 1 1 0 # unix consensus
15891578
syscon misc TYPE_E 2 2 2 2 2 0 # unix consensus
@@ -1637,18 +1626,6 @@ syscon misc PTHREAD_MUTEX_NORMAL 0 0 0 3 3 0
16371626
syscon misc PTHREAD_MUTEX_ROBUST 0 0 1 0 0 0
16381627
syscon misc PTHREAD_PROCESS_PRIVATE 0 2 0 0 0 0
16391628

1640-
syscon misc FTW_F 0 0 0 0 0 0 # consensus
1641-
syscon misc FTW_D 1 1 1 1 1 0 # unix consensus
1642-
syscon misc FTW_DNR 2 2 2 2 2 0 # unix consensus
1643-
syscon misc FTW_MOUNT 2 2 2 2 2 0 # unix consensus
1644-
syscon misc FTW_PHYS 1 1 1 1 1 0 # unix consensus
1645-
syscon misc FTW_SLN 6 6 6 6 6 0 # unix consensus
1646-
syscon misc FTW_CHDIR 4 8 8 8 8 0 # bsd consensus
1647-
syscon misc FTW_DEPTH 8 4 4 4 4 0 # bsd consensus
1648-
syscon misc FTW_DP 5 3 3 3 3 0 # bsd consensus
1649-
syscon misc FTW_NS 3 4 4 4 4 0 # bsd consensus
1650-
syscon misc FTW_SL 4 5 5 5 5 0 # bsd consensus
1651-
16521629
syscon misc N_TTY 0 0 0 0 0 0 # consensus
16531630
syscon misc N_6PACK 7 0 0 0 0 0
16541631
syscon misc N_AX25 5 0 0 0 0 0
@@ -2009,14 +1986,6 @@ syscon misc NL_TEXTMAX 0x7fffffff 0x0800 0x0800 255 255 0
20091986
syscon misc NL_NMAX 0x7fffffff 1 1 0 0 0
20101987
syscon misc NL_SETD 1 1 0 1 1 0
20111988

2012-
syscon misc RTLD_LAZY 1 1 1 1 1 0 # unix consensus
2013-
syscon misc RTLD_NOW 2 2 2 2 2 0 # unix consensus
2014-
syscon misc RTLD_GLOBAL 0x0100 8 0x0100 0x0100 0x0100 0
2015-
syscon misc RTLD_NODELETE 0x1000 0x80 0x1000 0 0 0
2016-
syscon misc RTLD_NOLOAD 4 0x10 0x2000 0 0 0
2017-
syscon misc RTLD_DI_LINKMAP 0 0 2 0 0 0
2018-
syscon misc RTLD_LOCAL 0 4 0 0 0 0
2019-
20201989
syscon rusage RUSAGE_SELF 0 0 0 0 0 0 # unix consensus & faked nt
20211990
syscon rusage RUSAGE_CHILDREN -1 -1 -1 -1 -1 99 # unix consensus & unavailable on nt
20221991
syscon rusage RUSAGE_THREAD 1 99 1 1 1 1 # faked nt & unavailable on xnu

libc/sysv/consts/FE_ALL_EXCEPT.S

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)