Skip to content

Commit 3639c24

Browse files
author
yang.zhao2
committed
Merge branch 'master' into prototype-inline-cache
2 parents 7826ad8 + a7914d1 commit 3639c24

39 files changed

+4047
-5022
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,11 @@ jobs:
160160
git submodule update --init --checkout --depth 1
161161
time make test262
162162
163+
- name: test standalone
164+
run: |
165+
./build/qjs -c examples/hello.js -o hello
166+
./hello
167+
163168
windows-msvc:
164169
runs-on: windows-latest
165170
strategy:
@@ -184,6 +189,10 @@ jobs:
184189
build\${{matrix.buildType}}\qjs.exe examples\test_point.js
185190
build\${{matrix.buildType}}\run-test262.exe -c tests.conf
186191
build\${{matrix.buildType}}\function_source.exe
192+
- name: test standalone
193+
run: |
194+
build\${{matrix.buildType}}\qjs.exe -c examples\hello.js -o hello.exe
195+
.\hello.exe
187196
- name: Set up Visual Studio shell
188197
uses: egor-tensin/vs-shell@v2
189198
with:
@@ -351,6 +360,10 @@ jobs:
351360
- name: test
352361
run: |
353362
make test
363+
- name: test standalone
364+
run: |
365+
./build/qjs -c examples/hello.js -o hello.exe
366+
./hello
354367
windows-mingw-shared:
355368
runs-on: windows-latest
356369
defaults:
@@ -385,7 +398,7 @@ jobs:
385398
run: emcc -v
386399
- name: build
387400
run: |
388-
emcmake cmake -B build
401+
emcmake cmake -B build -DBUILD_QJS_LIBC=ON
389402
emmake make -C build qjs_wasm -j$(getconf _NPROCESSORS_ONLN)
390403
- name: result
391404
run: ls -lh build

.github/workflows/release.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- name: Setup MSYS2
7676
uses: msys2/setup-msys2@v2
7777
with:
78-
msystem: ${{ matrix.arch == 'x86' && 'mingw32' || 'mingw64' }}
78+
msystem: ${{ matrix.arch == 'x86' && 'mingw32' || 'ucrt64' }}
7979
install: >-
8080
git
8181
make
@@ -90,6 +90,7 @@ jobs:
9090
mv build/qjsc.exe build/qjsc-windows-${{matrix.arch}}.exe
9191
- name: check
9292
run: |
93+
file build/qjs-windows-${{matrix.arch}}.exe
9394
ldd build/qjs-windows-${{matrix.arch}}.exe build/qjsc-windows-${{matrix.arch}}.exe
9495
- name: upload
9596
uses: actions/upload-artifact@v4

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
.obj/
55
build/
66
unicode/
7-
test262_*.txt
87
.idea
98
cmake-*
9+
.vs
10+
out/
11+
CMakeUserPresets.json
1012
fuzz
13+
.vscode/

CMakeLists.txt

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,6 @@ endif()
165165

166166
if(CONFIG_UBSAN)
167167
message(STATUS "Building with UBSan")
168-
# __has_feature(undefined_sanitizer) or __SANITIZE_UNDEFINED__ don't exist
169-
add_compile_definitions(
170-
__UBSAN__=1
171-
)
172168
add_compile_options(
173169
-fsanitize=undefined
174170
-fno-sanitize-recover=all
@@ -212,7 +208,10 @@ find_package(Threads)
212208
if(NOT CMAKE_SYSTEM_NAME STREQUAL "WASI")
213209
list(APPEND qjs_libs ${CMAKE_THREAD_LIBS_INIT})
214210
endif()
215-
if(NOT MSVC)
211+
212+
# try to find libm
213+
find_library(M_LIBRARIES m)
214+
if(M_LIBRARIES OR CMAKE_C_COMPILER_ID STREQUAL "TinyCC")
216215
list(APPEND qjs_libs m)
217216
endif()
218217

@@ -259,6 +258,7 @@ target_link_libraries(qjsc qjs)
259258

260259
add_executable(qjs_exe
261260
gen/repl.c
261+
gen/standalone.c
262262
qjs.c
263263
)
264264
add_qjs_libc_if_needed(qjs_exe)
@@ -370,10 +370,6 @@ if(BUILD_EXAMPLES)
370370
target_link_libraries(test_fib qjs)
371371
endif()
372372

373-
add_executable(test_conv
374-
tests/test_conv.c
375-
)
376-
377373
# Install target
378374
#
379375

@@ -392,6 +388,7 @@ if(NOT IOS)
392388
install(FILES quickjs-libc.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
393389
endif()
394390
install(TARGETS qjs_exe RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
391+
install(TARGETS qjsc RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
395392
install(TARGETS qjs EXPORT qjsConfig
396393
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
397394
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

Makefile

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#
22
# QuickJS Javascript Engine
3-
#
3+
#
44
# Copyright (c) 2017-2021 Fabrice Bellard
55
# Copyright (c) 2017-2021 Charlie Gordon
66
# Copyright (c) 2023 Ben Noordhuis
@@ -26,6 +26,7 @@
2626

2727
BUILD_DIR=build
2828
BUILD_TYPE?=Release
29+
INSTALL_PREFIX?=/usr/local
2930

3031
QJS=$(BUILD_DIR)/qjs
3132
QJSC=$(BUILD_DIR)/qjsc
@@ -49,26 +50,23 @@ fuzz:
4950
./fuzz
5051

5152
$(BUILD_DIR):
52-
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE)
53+
cmake -B $(BUILD_DIR) -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_INSTALL_PREFIX=$(INSTALL_PREFIX)
5354

5455
$(QJS): $(BUILD_DIR)
5556
cmake --build $(BUILD_DIR) -j $(JOBS)
5657

5758
$(QJSC): $(BUILD_DIR)
5859
cmake --build $(BUILD_DIR) --target qjsc -j $(JOBS)
5960

60-
$(BUILD_DIR)/test_conv: $(BUILD_DIR) tests/test_conv.c
61-
cmake --build $(BUILD_DIR) --target test_conv
62-
6361
install: $(QJS) $(QJSC)
6462
cmake --build $(BUILD_DIR) --target install
6563

6664
clean:
67-
@rm -f v8.txt[1-9]*
6865
cmake --build $(BUILD_DIR) --target clean
6966

7067
codegen: $(QJSC)
7168
$(QJSC) -ss -o gen/repl.c -m repl.js
69+
$(QJSC) -ss -o gen/standalone.c -m standalone.js
7270
$(QJSC) -e -o gen/function_source.c tests/function_source.js
7371
$(QJSC) -e -o gen/hello.c examples/hello.js
7472
$(QJSC) -e -o gen/hello_module.c -m examples/hello_module.js
@@ -98,9 +96,6 @@ cxxtest: cxxtest.cc quickjs.h
9896
test: $(QJS)
9997
$(RUN262) -c tests.conf
10098

101-
testconv: $(BUILD_DIR)/test_conv
102-
$(BUILD_DIR)/test_conv
103-
10499
test262: $(QJS)
105100
$(RUN262) -m -c test262.conf -a
106101

cutils.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#pragma GCC visibility push(default)
4242
#endif
4343

44-
void pstrcpy(char *buf, int buf_size, const char *str)
44+
void js__pstrcpy(char *buf, int buf_size, const char *str)
4545
{
4646
int c;
4747
char *q = buf;
@@ -59,16 +59,16 @@ void pstrcpy(char *buf, int buf_size, const char *str)
5959
}
6060

6161
/* strcat and truncate. */
62-
char *pstrcat(char *buf, int buf_size, const char *s)
62+
char *js__pstrcat(char *buf, int buf_size, const char *s)
6363
{
6464
int len;
6565
len = strlen(buf);
6666
if (len < buf_size)
67-
pstrcpy(buf + len, buf_size - len, s);
67+
js__pstrcpy(buf + len, buf_size - len, s);
6868
return buf;
6969
}
7070

71-
int strstart(const char *str, const char *val, const char **ptr)
71+
int js__strstart(const char *str, const char *val, const char **ptr)
7272
{
7373
const char *p, *q;
7474
p = str;
@@ -84,7 +84,7 @@ int strstart(const char *str, const char *val, const char **ptr)
8484
return 1;
8585
}
8686

87-
int has_suffix(const char *str, const char *suffix)
87+
int js__has_suffix(const char *str, const char *suffix)
8888
{
8989
size_t len = strlen(str);
9090
size_t slen = strlen(suffix);
@@ -125,7 +125,7 @@ int dbuf_realloc(DynBuf *s, size_t new_size)
125125
new_size = size;
126126
new_buf = s->realloc_func(s->opaque, s->buf, new_size);
127127
if (!new_buf) {
128-
s->error = TRUE;
128+
s->error = true;
129129
return -1;
130130
}
131131
s->buf = new_buf;
@@ -590,7 +590,13 @@ size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_
590590
*/
591591

592592
/* 2 <= base <= 36 */
593-
char const digits36[36] = "0123456789abcdefghijklmnopqrstuvwxyz";
593+
char const digits36[36] = {
594+
'0','1','2','3','4','5','6','7','8','9',
595+
'a','b','c','d','e','f','g','h','i','j',
596+
'k','l','m','n','o','p','q','r','s','t',
597+
'u','v','w','x','y','z'
598+
};
599+
594600

595601
#define USE_SPECIAL_RADIX_10 1 // special case base 10 radix conversions
596602
#define USE_SINGLE_CASE_FAST 1 // special case single digit numbers
@@ -1203,12 +1209,12 @@ typedef struct {
12031209
js__once_cb callback;
12041210
} js__once_data_t;
12051211

1206-
static BOOL WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
1212+
static int WINAPI js__once_inner(INIT_ONCE *once, void *param, void **context) {
12071213
js__once_data_t *data = param;
12081214

12091215
data->callback();
12101216

1211-
return TRUE;
1217+
return 1;
12121218
}
12131219

12141220
void js_once(js_once_t *guard, js__once_cb callback) {

cutils.h

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#ifndef CUTILS_H
2626
#define CUTILS_H
2727

28+
#include <stdbool.h>
2829
#include <stdlib.h>
2930
#include <string.h>
3031
#include <inttypes.h>
@@ -54,14 +55,6 @@ extern "C" {
5455
#include <pthread.h>
5556
#endif
5657

57-
#if defined(__SANITIZE_ADDRESS__)
58-
# define __ASAN__ 1
59-
#elif defined(__has_feature)
60-
# if __has_feature(address_sanitizer)
61-
# define __ASAN__ 1
62-
# endif
63-
#endif
64-
6558
#if defined(_MSC_VER) && !defined(__clang__)
6659
# define likely(x) (x)
6760
# define unlikely(x) (x)
@@ -70,10 +63,6 @@ extern "C" {
7063
# define __maybe_unused
7164
# define __attribute__(x)
7265
# define __attribute(x)
73-
# include <intrin.h>
74-
static void *__builtin_frame_address(unsigned int level) {
75-
return (void *)((char*)_AddressOfReturnAddress() - sizeof(int *) - level * sizeof(int *));
76-
}
7766
#else
7867
# define likely(x) __builtin_expect(!!(x), 1)
7968
# define unlikely(x) __builtin_expect(!!(x), 0)
@@ -124,19 +113,10 @@ static void *__builtin_frame_address(unsigned int level) {
124113
#define minimum_length(n) static n
125114
#endif
126115

127-
typedef int BOOL;
128-
129-
#ifndef FALSE
130-
enum {
131-
FALSE = 0,
132-
TRUE = 1,
133-
};
134-
#endif
135-
136-
void pstrcpy(char *buf, int buf_size, const char *str);
137-
char *pstrcat(char *buf, int buf_size, const char *s);
138-
int strstart(const char *str, const char *val, const char **ptr);
139-
int has_suffix(const char *str, const char *suffix);
116+
void js__pstrcpy(char *buf, int buf_size, const char *str);
117+
char *js__pstrcat(char *buf, int buf_size, const char *s);
118+
int js__strstart(const char *str, const char *val, const char **ptr);
119+
int js__has_suffix(const char *str, const char *suffix);
140120

141121
static inline uint8_t is_be(void) {
142122
union {
@@ -440,7 +420,7 @@ typedef struct DynBuf {
440420
uint8_t *buf;
441421
size_t size;
442422
size_t allocated_size;
443-
BOOL error; /* true if a memory allocation error occurred */
423+
bool error; /* true if a memory allocation error occurred */
444424
DynBufReallocFunc *realloc_func;
445425
void *opaque; /* for realloc_func */
446426
} DynBuf;
@@ -468,12 +448,12 @@ static inline int dbuf_put_u64(DynBuf *s, uint64_t val)
468448
int __attribute__((format(printf, 2, 3))) dbuf_printf(DynBuf *s,
469449
FORMAT_STRING(const char *fmt), ...);
470450
void dbuf_free(DynBuf *s);
471-
static inline BOOL dbuf_error(DynBuf *s) {
451+
static inline bool dbuf_error(DynBuf *s) {
472452
return s->error;
473453
}
474454
static inline void dbuf_set_error(DynBuf *s)
475455
{
476-
s->error = TRUE;
456+
s->error = true;
477457
}
478458

479459
/*---- UTF-8 and UTF-16 handling ----*/
@@ -497,17 +477,17 @@ size_t utf8_decode_buf16(uint16_t *dest, size_t dest_len, const char *src, size_
497477
size_t utf8_encode_buf8(char *dest, size_t dest_len, const uint8_t *src, size_t src_len);
498478
size_t utf8_encode_buf16(char *dest, size_t dest_len, const uint16_t *src, size_t src_len);
499479

500-
static inline BOOL is_surrogate(uint32_t c)
480+
static inline bool is_surrogate(uint32_t c)
501481
{
502482
return (c >> 11) == (0xD800 >> 11); // 0xD800-0xDFFF
503483
}
504484

505-
static inline BOOL is_hi_surrogate(uint32_t c)
485+
static inline bool is_hi_surrogate(uint32_t c)
506486
{
507487
return (c >> 10) == (0xD800 >> 10); // 0xD800-0xDBFF
508488
}
509489

510-
static inline BOOL is_lo_surrogate(uint32_t c)
490+
static inline bool is_lo_surrogate(uint32_t c)
511491
{
512492
return (c >> 10) == (0xDC00 >> 10); // 0xDC00-0xDFFF
513493
}

dirent_compat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ dirent_next(
656656
} else if (dirp->handle != INVALID_HANDLE_VALUE) {
657657

658658
/* Get the next directory entry from stream */
659-
if (FindNextFileW (dirp->handle, &dirp->data) != FALSE) {
659+
if (FindNextFileW (dirp->handle, &dirp->data) != 0) {
660660
/* Got a file */
661661
p = &dirp->data;
662662
} else {
@@ -1163,4 +1163,4 @@ dirent_set_errno(
11631163
#ifdef __cplusplus
11641164
}
11651165
#endif
1166-
#endif /*DIRENT_H*/
1166+
#endif /*DIRENT_H*/

0 commit comments

Comments
 (0)