Skip to content

Commit 7f928d2

Browse files
committed
Check-in all generated C files
Closes: #262
1 parent 7ded62c commit 7f928d2

File tree

8 files changed

+13181
-51
lines changed

8 files changed

+13181
-51
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ on:
1515
- master
1616

1717
jobs:
18+
codegen:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- uses: actions/checkout@v3
22+
- name: build
23+
run: |
24+
make codegen
25+
- name: Check if the git repository is clean
26+
run: $(exit $(git status --porcelain --untracked-files=no | head -255 | wc -l)) || (echo "Dirty git tree"; git diff; exit 1)
1827
linux:
1928
runs-on: ubuntu-latest
2029
strategy:

CMakeLists.txt

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ project(quickjs LANGUAGES C)
55
include(CheckCCompilerFlag)
66
include(GNUInstallDirs)
77

8-
# TODO:
9-
# - Support cross-compilation
10-
118
set(CMAKE_C_VISIBILITY_PRESET hidden)
129
set(CMAKE_C_STANDARD_REQUIRED ON)
1310
set(CMAKE_C_EXTENSIONS ON)
@@ -183,19 +180,10 @@ target_link_libraries(qjsc ${qjs_libs})
183180
# QuickJS CLI
184181
#
185182

186-
add_custom_command(
187-
OUTPUT repl.c
188-
COMMAND qjsc -o ./repl.c -m ${CMAKE_CURRENT_SOURCE_DIR}/repl.js
189-
DEPENDS qjsc
190-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
191-
COMMENT "Compile repl.js to bytecode"
192-
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/repl.js
193-
)
194-
195183
add_executable(qjs_exe
184+
gen/repl.c
196185
qjs.c
197186
quickjs-libc.c
198-
${CMAKE_CURRENT_BINARY_DIR}/repl.c
199187
)
200188
set_target_properties(qjs_exe PROPERTIES
201189
OUTPUT_NAME "qjs"
@@ -236,16 +224,8 @@ add_executable(unicode_gen EXCLUDE_FROM_ALL
236224
)
237225
target_compile_definitions(unicode_gen PRIVATE ${qjs_defines})
238226

239-
add_custom_command(
240-
OUTPUT function_source.c
241-
COMMAND qjsc -e -o function_source.c ${CMAKE_CURRENT_SOURCE_DIR}/tests/function_source.js
242-
DEPENDS qjsc ${CMAKE_CURRENT_SOURCE_DIR}/tests/function_source.js
243-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
244-
COMMENT "Compile function_source.js to a C file with bytecode embedded"
245-
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/function_source.js
246-
)
247227
add_executable(function_source
248-
${CMAKE_CURRENT_BINARY_DIR}/function_source.c
228+
gen/function_source.c
249229
quickjs-libc.c
250230
)
251231
target_include_directories(function_source PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
@@ -256,32 +236,16 @@ target_link_libraries(function_source ${qjs_libs})
256236
#
257237

258238
if(BUILD_EXAMPLES AND NOT WIN32)
259-
add_custom_command(
260-
OUTPUT hello.c
261-
COMMAND qjsc -e -o hello.c ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello.js
262-
DEPENDS qjsc
263-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
264-
COMMENT "Compile hello.js to a C file with bytecode embedded"
265-
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello.js
266-
)
267239
add_executable(hello
268-
${CMAKE_CURRENT_BINARY_DIR}/hello.c
240+
gen/hello.c
269241
quickjs-libc.c
270242
)
271243
target_include_directories(hello PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
272244
target_compile_definitions(hello PRIVATE ${qjs_defines})
273245
target_link_libraries(hello ${qjs_libs})
274246

275-
add_custom_command(
276-
OUTPUT hello_module.c
277-
COMMAND qjsc -e -o hello_module.c -m ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello_module.js
278-
DEPENDS qjsc
279-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
280-
COMMENT "Compile hello_module.js to a C file with bytecode embedded"
281-
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/examples/hello_module.js
282-
)
283247
add_executable(hello_module
284-
${CMAKE_CURRENT_BINARY_DIR}/hello_module.c
248+
gen/hello_module.c
285249
quickjs-libc.c
286250
)
287251
target_include_directories(hello_module PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
@@ -320,17 +284,9 @@ if(BUILD_EXAMPLES AND NOT WIN32)
320284
endif()
321285
endif()
322286

323-
add_custom_command(
324-
OUTPUT test_fib.c
325-
COMMAND qjsc -e -o test_fib.c -M ${CMAKE_CURRENT_SOURCE_DIR}/examples/fib.so,fib -m ${CMAKE_CURRENT_SOURCE_DIR}/examples/test_fib.js
326-
DEPENDS qjsc
327-
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
328-
COMMENT "Compile test_fib.js to a C file with bytecode embedded"
329-
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/examples/test_fib.js
330-
)
331287
add_executable(test_fib
332-
${CMAKE_CURRENT_BINARY_DIR}/test_fib.c
333288
examples/fib.c
289+
gen/test_fib.c
334290
quickjs-libc.c
335291
)
336292
target_include_directories(test_fib PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

Makefile

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ BUILD_DIR=build
2828
BUILD_TYPE?=Release
2929

3030
QJS=$(BUILD_DIR)/qjs
31+
QJSC=$(BUILD_DIR)/qjsc
3132
RUN262=$(BUILD_DIR)/run-test262
3233

3334
JOBS?=$(shell getconf _NPROCESSORS_ONLN)
@@ -49,12 +50,22 @@ $(BUILD_DIR):
4950
$(QJS): $(BUILD_DIR)
5051
cmake --build $(BUILD_DIR) -j $(JOBS)
5152

52-
install: $(QJS)
53+
$(QJSC): $(BUILD_DIR)
54+
cmake --build $(BUILD_DIR) --target qjsc -j $(JOBS)
55+
56+
install: $(QJS) $(QJSC)
5357
cmake --build $(BUILD_DIR) --target install
5458

5559
clean:
5660
cmake --build $(BUILD_DIR) --target clean
5761

62+
codegen: $(QJSC)
63+
$(QJSC) -o gen/repl.c -m repl.js
64+
$(QJSC) -e -o gen/function_source.c tests/function_source.js
65+
$(QJSC) -e -o gen/hello.c examples/hello.js
66+
$(QJSC) -e -o gen/hello_module.c -m examples/hello_module.js
67+
$(QJSC) -e -o gen/test_fib.c -M examples/fib.so,fib -m examples/test_fib.js
68+
5869
debug:
5970
BUILD_TYPE=Debug $(MAKE)
6071

@@ -92,4 +103,4 @@ unicode_gen: $(BUILD_DIR)
92103
libunicode-table.h: unicode_gen
93104
$(BUILD_DIR)/unicode_gen unicode $@
94105

95-
.PHONY: all debug install clean distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS)
106+
.PHONY: all debug install clean codegen distclean stats test test262 test262-update test262-check microbench unicode_gen $(QJS) $(QJSC)

gen/function_source.c

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/* File generated automatically by the QuickJS-ng compiler. */
2+
3+
#include "quickjs-libc.h"
4+
5+
const uint32_t qjsc_function_source_size = 393;
6+
7+
const uint8_t qjsc_function_source[393] = {
8+
0x08, 0x06, 0x0c, 0x61, 0x63, 0x74, 0x75, 0x61,
9+
0x6c, 0x02, 0x66, 0x0c, 0x65, 0x78, 0x70, 0x65,
10+
0x63, 0x74, 0x14, 0x75, 0x73, 0x65, 0x20, 0x73,
11+
0x74, 0x72, 0x69, 0x63, 0x74, 0x34, 0x66, 0x75,
12+
0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66,
13+
0x28, 0x29, 0x20, 0x7b, 0x20, 0x72, 0x65, 0x74,
14+
0x75, 0x72, 0x6e, 0x20, 0x34, 0x32, 0x20, 0x7d,
15+
0x30, 0x74, 0x65, 0x73, 0x74, 0x73, 0x2f, 0x66,
16+
0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x5f,
17+
0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x6a,
18+
0x73, 0x0c, 0x00, 0x02, 0x01, 0x9e, 0x01, 0x00,
19+
0x06, 0x00, 0x03, 0x00, 0x01, 0xa0, 0x01, 0x06,
20+
0xa0, 0x01, 0x00, 0x00, 0x00, 0xac, 0x03, 0x02,
21+
0x00, 0x30, 0xae, 0x03, 0x04, 0x00, 0x70, 0xac,
22+
0x03, 0x04, 0x03, 0x70, 0x10, 0x00, 0x01, 0x00,
23+
0xe0, 0x01, 0x00, 0x01, 0x00, 0x0c, 0x03, 0xc1,
24+
0x05, 0x08, 0xc1, 0x04, 0x3f, 0xd8, 0x00, 0x00,
25+
0x00, 0x80, 0x3f, 0xd7, 0x00, 0x00, 0x00, 0x40,
26+
0x3e, 0xd8, 0x00, 0x00, 0x00, 0x80, 0xbe, 0x00,
27+
0x40, 0xd7, 0x00, 0x00, 0x00, 0x00, 0x04, 0xd9,
28+
0x00, 0x00, 0x00, 0xc8, 0x04, 0xda, 0x00, 0x00,
29+
0x00, 0x3a, 0xd8, 0x00, 0x00, 0x00, 0x61, 0x01,
30+
0x00, 0x38, 0xd7, 0x00, 0x00, 0x00, 0x42, 0x36,
31+
0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0xc9, 0x06,
32+
0xc8, 0x62, 0x01, 0x00, 0x38, 0xd8, 0x00, 0x00,
33+
0x00, 0xaf, 0xe9, 0x0b, 0x38, 0x8f, 0x00, 0x00,
34+
0x00, 0x62, 0x01, 0x00, 0xee, 0x2f, 0x61, 0x03,
35+
0x00, 0x61, 0x02, 0x00, 0x38, 0x39, 0x00, 0x00,
36+
0x00, 0x38, 0xd8, 0x00, 0x00, 0x00, 0x04, 0xd7,
37+
0x00, 0x00, 0x00, 0x9d, 0x31, 0x01, 0x00, 0x04,
38+
0x00, 0xca, 0x62, 0x02, 0x00, 0x42, 0x36, 0x00,
39+
0x00, 0x00, 0x24, 0x00, 0x00, 0xcb, 0x06, 0xc8,
40+
0x62, 0x03, 0x00, 0x38, 0xd8, 0x00, 0x00, 0x00,
41+
0xaf, 0xe9, 0x0b, 0x38, 0x8f, 0x00, 0x00, 0x00,
42+
0x62, 0x03, 0x00, 0xee, 0x2f, 0x68, 0x03, 0x00,
43+
0x68, 0x02, 0x00, 0xc4, 0x28, 0xb6, 0x03, 0x01,
44+
0x01, 0x28, 0x60, 0x01, 0x49, 0x02, 0x21, 0x1a,
45+
0x1b, 0x04, 0x1e, 0x1d, 0x12, 0x26, 0x49, 0x1d,
46+
0x0c, 0x06, 0x11, 0x18, 0x2a, 0x1c, 0x37, 0x41,
47+
0x21, 0x1c, 0x34, 0x18, 0x1b, 0x04, 0x26, 0x11,
48+
0x3f, 0x1d, 0x0c, 0x06, 0x11, 0x18, 0x2a, 0x1c,
49+
0x53, 0x41, 0x00, 0xff, 0x49, 0x43, 0x01, 0x6c,
50+
0x0c, 0x43, 0x02, 0x01, 0xae, 0x03, 0x00, 0x00,
51+
0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0xbb, 0x2a,
52+
0x28, 0xb6, 0x03, 0x03, 0x01, 0x04, 0x02, 0x1e,
53+
0x0c, 0x0e, 0x1a, 0x66, 0x75, 0x6e, 0x63, 0x74,
54+
0x69, 0x6f, 0x6e, 0x20, 0x66, 0x28, 0x29, 0x20,
55+
0x7b, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e,
56+
0x20, 0x34, 0x32, 0x20, 0x7d, 0xff, 0x49, 0x43,
57+
0x00,
58+
};
59+
60+
static JSContext *JS_NewCustomContext(JSRuntime *rt)
61+
{
62+
JSContext *ctx = JS_NewContext(rt);
63+
if (!ctx)
64+
return NULL;
65+
return ctx;
66+
}
67+
68+
int main(int argc, char **argv)
69+
{
70+
JSRuntime *rt;
71+
JSContext *ctx;
72+
rt = JS_NewRuntime();
73+
js_std_set_worker_new_context_func(JS_NewCustomContext);
74+
js_std_init_handlers(rt);
75+
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
76+
ctx = JS_NewCustomContext(rt);
77+
js_std_add_helpers(ctx, argc, argv);
78+
js_std_eval_binary(ctx, qjsc_function_source, qjsc_function_source_size, 0);
79+
js_std_loop(ctx);
80+
JS_FreeContext(ctx);
81+
js_std_free_handlers(rt);
82+
JS_FreeRuntime(rt);
83+
return 0;
84+
}

gen/hello.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* File generated automatically by the QuickJS-ng compiler. */
2+
3+
#include "quickjs-libc.h"
4+
5+
const uint32_t qjsc_hello_size = 95;
6+
7+
const uint8_t qjsc_hello[95] = {
8+
0x08, 0x04, 0x0e, 0x63, 0x6f, 0x6e, 0x73, 0x6f,
9+
0x6c, 0x65, 0x06, 0x6c, 0x6f, 0x67, 0x16, 0x48,
10+
0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72,
11+
0x6c, 0x64, 0x22, 0x65, 0x78, 0x61, 0x6d, 0x70,
12+
0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c,
13+
0x6f, 0x2e, 0x6a, 0x73, 0x0c, 0x00, 0x02, 0x00,
14+
0x9e, 0x01, 0x00, 0x01, 0x00, 0x03, 0x00, 0x00,
15+
0x14, 0x01, 0xa0, 0x01, 0x00, 0x00, 0x00, 0x38,
16+
0xd6, 0x00, 0x00, 0x00, 0x42, 0xd7, 0x00, 0x00,
17+
0x00, 0x04, 0xd8, 0x00, 0x00, 0x00, 0x24, 0x01,
18+
0x00, 0xcc, 0x28, 0xb2, 0x03, 0x01, 0x01, 0x00,
19+
0x00, 0xff, 0x49, 0x43, 0x01, 0xae, 0x03,
20+
};
21+
22+
static JSContext *JS_NewCustomContext(JSRuntime *rt)
23+
{
24+
JSContext *ctx = JS_NewContext(rt);
25+
if (!ctx)
26+
return NULL;
27+
return ctx;
28+
}
29+
30+
int main(int argc, char **argv)
31+
{
32+
JSRuntime *rt;
33+
JSContext *ctx;
34+
rt = JS_NewRuntime();
35+
js_std_set_worker_new_context_func(JS_NewCustomContext);
36+
js_std_init_handlers(rt);
37+
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
38+
ctx = JS_NewCustomContext(rt);
39+
js_std_add_helpers(ctx, argc, argv);
40+
js_std_eval_binary(ctx, qjsc_hello, qjsc_hello_size, 0);
41+
js_std_loop(ctx);
42+
JS_FreeContext(ctx);
43+
js_std_free_handlers(rt);
44+
JS_FreeRuntime(rt);
45+
return 0;
46+
}

gen/hello_module.c

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/* File generated automatically by the QuickJS-ng compiler. */
2+
3+
#include "quickjs-libc.h"
4+
5+
const uint32_t qjsc_fib_module_size = 318;
6+
7+
const uint8_t qjsc_fib_module[318] = {
8+
0x08, 0x03, 0x2c, 0x65, 0x78, 0x61, 0x6d, 0x70,
9+
0x6c, 0x65, 0x73, 0x2f, 0x66, 0x69, 0x62, 0x5f,
10+
0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65, 0x2e, 0x6a,
11+
0x73, 0x06, 0x66, 0x69, 0x62, 0x02, 0x6e, 0x0d,
12+
0xac, 0x03, 0x00, 0x01, 0x00, 0x00, 0xae, 0x03,
13+
0x00, 0x00, 0x0c, 0x20, 0x02, 0x01, 0x9e, 0x01,
14+
0x00, 0x00, 0x00, 0x01, 0x01, 0x01, 0x09, 0x00,
15+
0xae, 0x03, 0x00, 0x01, 0x08, 0xe9, 0x05, 0xbe,
16+
0x00, 0xe0, 0x29, 0x06, 0x2e, 0xac, 0x03, 0x01,
17+
0x01, 0x06, 0x01, 0x01, 0x00, 0x07, 0x14, 0x02,
18+
0x00, 0xff, 0x49, 0x43, 0x00, 0x0c, 0x43, 0x02,
19+
0x01, 0xae, 0x03, 0x01, 0x00, 0x01, 0x04, 0x01,
20+
0x00, 0x1a, 0x01, 0xb0, 0x03, 0x00, 0x01, 0x00,
21+
0xae, 0x03, 0x00, 0x00, 0xd0, 0xb3, 0xa7, 0xe9,
22+
0x03, 0xb3, 0x28, 0xd0, 0xb4, 0xac, 0xe9, 0x03,
23+
0xb4, 0x28, 0xdc, 0xd0, 0xb4, 0x9e, 0xee, 0xdc,
24+
0xd0, 0xb5, 0x9e, 0xee, 0x9d, 0x28, 0xac, 0x03,
25+
0x02, 0x08, 0x20, 0x04, 0x00, 0x07, 0x06, 0x07,
26+
0x06, 0x12, 0x09, 0x08, 0x07, 0x07, 0x10, 0x07,
27+
0x06, 0x07, 0x06, 0x12, 0x13, 0x08, 0x07, 0x08,
28+
0x16, 0x0c, 0x0c, 0x07, 0x04, 0x0c, 0x0a, 0x0c,
29+
0x0c, 0x07, 0x04, 0x8d, 0x01, 0x66, 0x75, 0x6e,
30+
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x66, 0x69,
31+
0x62, 0x28, 0x6e, 0x29, 0x0a, 0x7b, 0x0a, 0x20,
32+
0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x6e,
33+
0x20, 0x3c, 0x3d, 0x20, 0x30, 0x29, 0x0a, 0x20,
34+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72,
35+
0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x30, 0x3b,
36+
0x0a, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73,
37+
0x65, 0x20, 0x69, 0x66, 0x20, 0x28, 0x6e, 0x20,
38+
0x3d, 0x3d, 0x20, 0x31, 0x29, 0x0a, 0x20, 0x20,
39+
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65,
40+
0x74, 0x75, 0x72, 0x6e, 0x20, 0x31, 0x3b, 0x0a,
41+
0x20, 0x20, 0x20, 0x20, 0x65, 0x6c, 0x73, 0x65,
42+
0x0a, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
43+
0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20,
44+
0x66, 0x69, 0x62, 0x28, 0x6e, 0x20, 0x2d, 0x20,
45+
0x31, 0x29, 0x20, 0x2b, 0x20, 0x66, 0x69, 0x62,
46+
0x28, 0x6e, 0x20, 0x2d, 0x20, 0x32, 0x29, 0x3b,
47+
0x0a, 0x7d, 0xff, 0x49, 0x43, 0x00,
48+
};
49+
50+
const uint32_t qjsc_hello_module_size = 183;
51+
52+
const uint8_t qjsc_hello_module[183] = {
53+
0x08, 0x07, 0x30, 0x65, 0x78, 0x61, 0x6d, 0x70,
54+
0x6c, 0x65, 0x73, 0x2f, 0x68, 0x65, 0x6c, 0x6c,
55+
0x6f, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
56+
0x2e, 0x6a, 0x73, 0x1e, 0x2e, 0x2f, 0x66, 0x69,
57+
0x62, 0x5f, 0x6d, 0x6f, 0x64, 0x75, 0x6c, 0x65,
58+
0x2e, 0x6a, 0x73, 0x06, 0x66, 0x69, 0x62, 0x0e,
59+
0x63, 0x6f, 0x6e, 0x73, 0x6f, 0x6c, 0x65, 0x06,
60+
0x6c, 0x6f, 0x67, 0x16, 0x48, 0x65, 0x6c, 0x6c,
61+
0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x10,
62+
0x66, 0x69, 0x62, 0x28, 0x31, 0x30, 0x29, 0x3d,
63+
0x0d, 0xac, 0x03, 0x01, 0xae, 0x03, 0x00, 0x00,
64+
0x01, 0x00, 0xb0, 0x03, 0x00, 0x0c, 0x20, 0x02,
65+
0x01, 0x9e, 0x01, 0x00, 0x00, 0x00, 0x05, 0x01,
66+
0x00, 0x32, 0x00, 0xb0, 0x03, 0x00, 0x0c, 0x08,
67+
0xe9, 0x02, 0x29, 0x38, 0xd9, 0x00, 0x00, 0x00,
68+
0x42, 0xda, 0x00, 0x00, 0x00, 0x04, 0xdb, 0x00,
69+
0x00, 0x00, 0x24, 0x01, 0x00, 0x0e, 0x38, 0xd9,
70+
0x00, 0x00, 0x00, 0x42, 0xda, 0x00, 0x00, 0x00,
71+
0x04, 0xdc, 0x00, 0x00, 0x00, 0x65, 0x00, 0x00,
72+
0xbb, 0x0a, 0xee, 0x24, 0x02, 0x00, 0x0e, 0x06,
73+
0x2e, 0xac, 0x03, 0x01, 0x01, 0x0a, 0x01, 0x01,
74+
0x00, 0x04, 0x0a, 0x02, 0x62, 0x00, 0x4d, 0x30,
75+
0x00, 0xff, 0x49, 0x43, 0x01, 0xb4, 0x03,
76+
};
77+
78+
static JSContext *JS_NewCustomContext(JSRuntime *rt)
79+
{
80+
JSContext *ctx = JS_NewContext(rt);
81+
if (!ctx)
82+
return NULL;
83+
js_std_eval_binary(ctx, qjsc_fib_module, qjsc_fib_module_size, 1);
84+
return ctx;
85+
}
86+
87+
int main(int argc, char **argv)
88+
{
89+
JSRuntime *rt;
90+
JSContext *ctx;
91+
rt = JS_NewRuntime();
92+
js_std_set_worker_new_context_func(JS_NewCustomContext);
93+
js_std_init_handlers(rt);
94+
JS_SetModuleLoaderFunc(rt, NULL, js_module_loader, NULL);
95+
ctx = JS_NewCustomContext(rt);
96+
js_std_add_helpers(ctx, argc, argv);
97+
js_std_eval_binary(ctx, qjsc_hello_module, qjsc_hello_module_size, 0);
98+
js_std_loop(ctx);
99+
JS_FreeContext(ctx);
100+
js_std_free_handlers(rt);
101+
JS_FreeRuntime(rt);
102+
return 0;
103+
}

0 commit comments

Comments
 (0)