xbintsc 0.6.24 → 0.6.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/dist/src/cli/extensions.js +11 -3
- package/dist/src/cli/extensions.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/help.js +1 -1
- package/dist/src/codegen/generator/state.js +7 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +19 -1
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +9 -5
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/fingerprint.d.ts +2 -2
- package/dist/src/driver/fingerprint.js +3 -3
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/link-features.js +1 -1
- package/dist/src/driver/link-features.js.map +1 -1
- package/dist/src/driver/paths.js +8 -4
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +13 -1
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/catalog.js +5 -1
- package/dist/src/extensions/catalog.js.map +1 -1
- package/dist/src/extensions/gui/index.js +0 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/link-feature.d.ts +8 -0
- package/dist/src/extensions/node/stream-web/index.d.ts +6 -1
- package/dist/src/extensions/node/stream-web/index.js +59 -4
- package/dist/src/extensions/node/stream-web/index.js.map +1 -1
- package/dist/src/extensions/node/worker_threads/index.d.ts +14 -4
- package/dist/src/extensions/node/worker_threads/index.js +24 -11
- package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +9 -1
- package/dist/src/extensions/registry.js +4 -1
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/wasm-asset.d.ts +16 -0
- package/dist/src/extensions/wasm-asset.js +28 -0
- package/dist/src/extensions/wasm-asset.js.map +1 -0
- package/dist/src/extensions/wasm.d.ts +17 -0
- package/dist/src/extensions/wasm.js +68 -0
- package/dist/src/extensions/wasm.js.map +1 -0
- package/dist/src/extensions/webworker/index.d.ts +24 -0
- package/dist/src/extensions/webworker/index.js +54 -0
- package/dist/src/extensions/webworker/index.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +1 -0
- package/dist/src/index.js.map +1 -1
- package/dist/tests/driver/link-features.test.js +9 -0
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/e2e/async-fs.test.js +44 -0
- package/dist/tests/e2e/async-fs.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +6 -0
- package/dist/tests/e2e/harness.js +13 -1
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/node-crypto-random.test.d.ts +8 -0
- package/dist/tests/e2e/node-crypto-random.test.js +148 -0
- package/dist/tests/e2e/node-crypto-random.test.js.map +1 -0
- package/dist/tests/e2e/node-modules.test.js +1 -1
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.d.ts +8 -0
- package/dist/tests/e2e/web-streams.test.js +274 -0
- package/dist/tests/e2e/web-streams.test.js.map +1 -0
- package/dist/tests/e2e/web-worker.test.d.ts +7 -0
- package/dist/tests/e2e/web-worker.test.js +74 -0
- package/dist/tests/e2e/web-worker.test.js.map +1 -0
- package/dist/tests/e2e/webassembly.test.d.ts +8 -0
- package/dist/tests/e2e/webassembly.test.js +113 -0
- package/dist/tests/e2e/webassembly.test.js.map +1 -0
- package/dist/tests/e2e/worker-api.test.d.ts +14 -0
- package/dist/tests/e2e/worker-api.test.js +460 -0
- package/dist/tests/e2e/worker-api.test.js.map +1 -0
- package/dist/tests/e2e/worker-threads.test.d.ts +8 -0
- package/dist/tests/e2e/worker-threads.test.js +160 -0
- package/dist/tests/e2e/worker-threads.test.js.map +1 -0
- package/dist/tests/extensions/wasm.test.d.ts +1 -0
- package/dist/tests/extensions/wasm.test.js +53 -0
- package/dist/tests/extensions/wasm.test.js.map +1 -0
- package/doc/ai/cli.md +1 -1
- package/doc/ai/contributing.md +11 -4
- package/doc/ai/extensions.md +25 -2
- package/doc/ai/language-support.md +14 -2
- package/doc/ai/zh-CN/cli.md +1 -1
- package/doc/ai/zh-CN/contributing.md +8 -3
- package/doc/ai/zh-CN/extensions.md +23 -2
- package/doc/ai/zh-CN/language-support.md +13 -2
- package/doc/gui/api.md +1 -1
- package/doc/implemented/cli.md +1 -1
- package/doc/implemented/extensions.md +6 -5
- package/doc/implemented/node/stream-web.md +31 -0
- package/doc/implemented/node/worker-threads.md +88 -5
- package/doc/implemented/node.md +2 -1
- package/doc/implemented/streams.md +82 -0
- package/doc/implemented/wasm.md +80 -18
- package/doc/implemented/web-worker.md +84 -0
- package/doc/implemented.md +6 -2
- package/doc/unimplemented/deviations.md +1 -0
- package/doc/unimplemented/node/worker-threads.md +23 -0
- package/doc/unimplemented/node.md +1 -0
- package/doc/unimplemented/stdlib.md +2 -1
- package/doc/unimplemented/wasm.md +21 -9
- package/doc/unimplemented.md +1 -1
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/implemented/cli.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +7 -6
- package/doc/zh-CN/implemented/node/stream-web.md +24 -0
- package/doc/zh-CN/implemented/node/worker-threads.md +77 -4
- package/doc/zh-CN/implemented/node.md +2 -1
- package/doc/zh-CN/implemented/streams.md +60 -0
- package/doc/zh-CN/implemented/wasm.md +73 -16
- package/doc/zh-CN/implemented/web-worker.md +79 -0
- package/doc/zh-CN/implemented.md +6 -2
- package/doc/zh-CN/unimplemented/deviations.md +1 -0
- package/doc/zh-CN/unimplemented/node/worker-threads.md +20 -0
- package/doc/zh-CN/unimplemented/node.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +2 -1
- package/doc/zh-CN/unimplemented/wasm.md +16 -8
- package/doc/zh-CN/unimplemented.md +1 -1
- package/llms.txt +2 -0
- package/package.json +8 -7
- package/runtime/ext_gui/browser.cpp +1 -1
- package/runtime/ext_node/stream_web/stream_web.c +20 -6
- package/runtime/worker/worker_api.c +422 -0
- package/runtime/worker/worker_codec.c +489 -0
- package/runtime/worker/worker_core.c +445 -0
- package/runtime/worker/worker_internal.h +223 -0
- package/runtime/worker/worker_platform.c +344 -0
- package/runtime/worker/worker_ports.c +203 -0
- package/runtime/worker/worker_transport.c +464 -0
- package/runtime/worker/worker_wire.c +150 -0
- package/runtime/xt_builtins.c +15 -0
- package/runtime/xt_constructors.c +49 -2
- package/runtime/xt_stdlib2/error.inc +4 -0
- package/runtime/xt_streams/common.inc +232 -0
- package/runtime/xt_streams/constructors.inc +232 -0
- package/runtime/xt_streams/encoding.inc +124 -0
- package/runtime/xt_streams/readable-extra.inc +372 -0
- package/runtime/xt_streams/readable.inc +415 -0
- package/runtime/xt_streams/transform.inc +195 -0
- package/runtime/xt_streams/writable.inc +542 -0
- package/runtime/xt_streams.c +30 -0
- package/runtime/xt_wasm/wasm.h +148 -0
- package/runtime/xt_wasm/wasm_api.c +357 -0
- package/runtime/xt_wasm/wasm_api.h +37 -0
- package/runtime/xt_wasm/wasm_bridge.c +30 -0
- package/runtime/xt_wasm/wasm_instance.c +591 -0
- package/runtime/xt_wasm/wasm_module.c +270 -0
- package/runtime/xt_wasm/wasm_values.c +177 -0
- package/runtime/xt_webassembly.c +15 -4
- package/scripts/fetch-vendored.ts +187 -20
- package/scripts/package-release.ts +3 -2
- package/src/cli/extensions.ts +11 -3
- package/src/cli/help.ts +1 -1
- package/src/codegen/generator/state.ts +7 -0
- package/src/codegen/generator/tables.ts +19 -1
- package/src/driver/bundler/graph.ts +9 -5
- package/src/driver/fingerprint.ts +3 -3
- package/src/driver/link-features.ts +1 -1
- package/src/driver/paths.ts +8 -4
- package/src/driver/runtime-objects.ts +13 -1
- package/src/driver/version.ts +1 -1
- package/src/extensions/catalog.ts +5 -1
- package/src/extensions/gui/index.ts +0 -1
- package/src/extensions/link-feature.ts +8 -0
- package/src/extensions/node/stream-web/index.ts +59 -4
- package/src/extensions/node/worker_threads/index.ts +24 -11
- package/src/extensions/registry.ts +13 -2
- package/src/extensions/wasm-asset.ts +32 -0
- package/src/extensions/wasm.ts +74 -0
- package/src/extensions/webworker/index.ts +58 -0
- package/src/index.ts +1 -0
- package/vendor/wasm3/.pin +1 -0
- package/vendor/wasm3/LICENSE +21 -0
- package/vendor/wasm3/m3_api_libc.c +265 -0
- package/vendor/wasm3/m3_api_libc.h +19 -0
- package/vendor/wasm3/m3_api_meta_wasi.c +1107 -0
- package/vendor/wasm3/m3_api_tracer.c +173 -0
- package/vendor/wasm3/m3_api_tracer.h +19 -0
- package/vendor/wasm3/m3_api_uvwasi.c +1290 -0
- package/vendor/wasm3/m3_api_wasi.c +1207 -0
- package/vendor/wasm3/m3_api_wasi.h +74 -0
- package/vendor/wasm3/m3_api_wasi_host.h +137 -0
- package/vendor/wasm3/m3_api_wasi_posix.h +979 -0
- package/vendor/wasm3/m3_api_wasi_win32.h +1093 -0
- package/vendor/wasm3/m3_atomic.h +114 -0
- package/vendor/wasm3/m3_bind.c +174 -0
- package/vendor/wasm3/m3_bind.h +20 -0
- package/vendor/wasm3/m3_code.c +232 -0
- package/vendor/wasm3/m3_code.h +74 -0
- package/vendor/wasm3/m3_compile.c +6603 -0
- package/vendor/wasm3/m3_compile.h +354 -0
- package/vendor/wasm3/m3_config.h +448 -0
- package/vendor/wasm3/m3_config_platforms.h +345 -0
- package/vendor/wasm3/m3_core.c +1034 -0
- package/vendor/wasm3/m3_core.h +526 -0
- package/vendor/wasm3/m3_deterministic.c +65 -0
- package/vendor/wasm3/m3_deterministic.h +59 -0
- package/vendor/wasm3/m3_env.c +3146 -0
- package/vendor/wasm3/m3_env.h +748 -0
- package/vendor/wasm3/m3_exception.h +33 -0
- package/vendor/wasm3/m3_exec.c +8 -0
- package/vendor/wasm3/m3_exec.h +4110 -0
- package/vendor/wasm3/m3_exec_atomic.h +146 -0
- package/vendor/wasm3/m3_exec_defs.h +76 -0
- package/vendor/wasm3/m3_function.c +278 -0
- package/vendor/wasm3/m3_function.h +244 -0
- package/vendor/wasm3/m3_host.h +226 -0
- package/vendor/wasm3/m3_host_none.h +76 -0
- package/vendor/wasm3/m3_host_posix.h +543 -0
- package/vendor/wasm3/m3_host_win32.h +253 -0
- package/vendor/wasm3/m3_info.c +616 -0
- package/vendor/wasm3/m3_info.h +38 -0
- package/vendor/wasm3/m3_math_utils.h +560 -0
- package/vendor/wasm3/m3_module.c +431 -0
- package/vendor/wasm3/m3_parse.c +1549 -0
- package/vendor/wasm3/m3_snapshot.c +3825 -0
- package/vendor/wasm3/m3_validate.c +1770 -0
- package/vendor/wasm3/m3_validate.h +25 -0
- package/vendor/wasm3/m3_wasi.h +10 -0
- package/vendor/wasm3/m3_xxh64.c +211 -0
- package/vendor/wasm3/wasm3.h +684 -0
- package/vendor/wasm3/wasm3_defs.h +350 -0
- package/runtime/ext_node/worker_threads/worker_threads.c +0 -214
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — internal interface of the wasm3-backed WebAssembly feature.
|
|
3
|
+
*
|
|
4
|
+
* `wasm_api.c` owns the JS-facing namespace and the object prototypes;
|
|
5
|
+
* `wasm_module.c` parses bytes into the metadata a `WebAssembly.Module` needs;
|
|
6
|
+
* `wasm_instance.c` links, instantiates and bridges calls in both directions.
|
|
7
|
+
* The split keeps each translation unit inside the repository's file budget.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#ifndef XT_WASM_H
|
|
11
|
+
#define XT_WASM_H
|
|
12
|
+
|
|
13
|
+
#include "../rt_internal.h"
|
|
14
|
+
|
|
15
|
+
#include "wasm3/m3_env.h"
|
|
16
|
+
#include "wasm3/wasm3.h"
|
|
17
|
+
|
|
18
|
+
#include <stdarg.h>
|
|
19
|
+
#include <stdint.h>
|
|
20
|
+
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
extern "C" {
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
typedef struct wasm_module wasm_module;
|
|
26
|
+
typedef struct wasm_instance wasm_instance;
|
|
27
|
+
typedef struct wasm_memory wasm_memory;
|
|
28
|
+
typedef struct wasm_import wasm_import;
|
|
29
|
+
|
|
30
|
+
/* Object kinds with a shared prototype and constructor. */
|
|
31
|
+
enum {
|
|
32
|
+
XT_WASM_KIND_MODULE = 0,
|
|
33
|
+
XT_WASM_KIND_INSTANCE = 1,
|
|
34
|
+
XT_WASM_KIND_MEMORY = 2,
|
|
35
|
+
XT_WASM_KIND_TABLE = 3,
|
|
36
|
+
XT_WASM_KIND_GLOBAL = 4,
|
|
37
|
+
XT_WASM_KIND_COUNT = 5,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
typedef struct wasm_export_desc {
|
|
41
|
+
char *name;
|
|
42
|
+
uint32_t name_length;
|
|
43
|
+
uint8_t kind;
|
|
44
|
+
uint32_t index;
|
|
45
|
+
} wasm_export_desc;
|
|
46
|
+
|
|
47
|
+
typedef struct wasm_import_desc {
|
|
48
|
+
char *module;
|
|
49
|
+
char *name;
|
|
50
|
+
uint32_t name_length;
|
|
51
|
+
uint8_t kind;
|
|
52
|
+
} wasm_import_desc;
|
|
53
|
+
|
|
54
|
+
struct wasm_module {
|
|
55
|
+
uint8_t *bytes;
|
|
56
|
+
uint32_t length;
|
|
57
|
+
wasm_export_desc *exports;
|
|
58
|
+
uint32_t export_count;
|
|
59
|
+
wasm_import_desc *imports;
|
|
60
|
+
uint32_t import_count;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
struct wasm_import {
|
|
64
|
+
wasm_instance *instance;
|
|
65
|
+
xt_value function;
|
|
66
|
+
uint32_t function_index;
|
|
67
|
+
struct wasm_import *next;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
struct wasm_memory {
|
|
71
|
+
wasm_instance *instance;
|
|
72
|
+
uint32_t index;
|
|
73
|
+
xt_value object;
|
|
74
|
+
xt_value buffer;
|
|
75
|
+
uint32_t buffer_bytes;
|
|
76
|
+
struct wasm_memory *next;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
struct wasm_instance {
|
|
80
|
+
IM3Environment environment;
|
|
81
|
+
IM3Runtime runtime;
|
|
82
|
+
IM3Module module;
|
|
83
|
+
wasm_module *source;
|
|
84
|
+
xt_value object;
|
|
85
|
+
xt_value exports;
|
|
86
|
+
xt_value imports;
|
|
87
|
+
xt_value pending_exception;
|
|
88
|
+
wasm_import *import_functions;
|
|
89
|
+
wasm_memory *memories;
|
|
90
|
+
struct wasm_instance *next;
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/* -- prototype / hidden-key helpers (wasm_api.c) -------------------------- */
|
|
94
|
+
xt_value xt_wasm_object_new(int kind);
|
|
95
|
+
xt_value xt_wasm_constructor(int kind);
|
|
96
|
+
xt_value xt_wasm_module_key(void);
|
|
97
|
+
xt_value xt_wasm_instance_key(void);
|
|
98
|
+
xt_value xt_wasm_memory_key(void);
|
|
99
|
+
xt_value xt_wasm_ptr_value(const void *pointer);
|
|
100
|
+
void *xt_wasm_value_ptr(xt_value value);
|
|
101
|
+
/** Register/prototype setup; safe to call repeatedly. */
|
|
102
|
+
void xt_wasm_api_init(void);
|
|
103
|
+
|
|
104
|
+
/* -- value and error helpers (wasm_values.c) ------------------------------ */
|
|
105
|
+
void xt_wasm_set_error(char **error, const char *format, ...);
|
|
106
|
+
xt_value xt_wasm_error(const char *kind, const char *message);
|
|
107
|
+
xt_value xt_wasm_type_error(const char *message);
|
|
108
|
+
/** Copy a BufferSource (`ArrayBuffer` or typed-array view) into fresh memory. */
|
|
109
|
+
int xt_wasm_bytes_from_value(xt_value value, uint8_t **bytes, uint32_t *length,
|
|
110
|
+
char **error);
|
|
111
|
+
int xt_wasm_is_buffer_source(xt_value value);
|
|
112
|
+
int64_t xt_wasm_to_i64(xt_value value);
|
|
113
|
+
xt_value xt_wasm_from_i64(int64_t value);
|
|
114
|
+
xt_value xt_wasm_number_arg(int32_t argc, xt_value *argv, int32_t index);
|
|
115
|
+
xt_value xt_wasm_object_arg(int32_t argc, xt_value *argv, int32_t index);
|
|
116
|
+
|
|
117
|
+
/* -- module metadata (wasm_module.c) -------------------------------------- */
|
|
118
|
+
wasm_module *xt_wasm_module_parse(const uint8_t *bytes, uint32_t length, char **error);
|
|
119
|
+
void xt_wasm_module_release(wasm_module *module);
|
|
120
|
+
wasm_module *xt_wasm_module_of(xt_value value);
|
|
121
|
+
xt_value xt_wasm_module_object(wasm_module *module, char **error);
|
|
122
|
+
xt_value xt_wasm_compile_to_module(xt_value bytes, char **error);
|
|
123
|
+
xt_value xt_wasm_module_exports_value(const wasm_module *module);
|
|
124
|
+
xt_value xt_wasm_module_imports_value(const wasm_module *module);
|
|
125
|
+
const wasm_export_desc *xt_wasm_module_find_export(const wasm_module *module,
|
|
126
|
+
const char *name);
|
|
127
|
+
|
|
128
|
+
/* -- instances and calls (wasm_instance.c) -------------------------------- */
|
|
129
|
+
xt_value xt_wasm_instance_value(wasm_module *module, xt_value imports, char **error);
|
|
130
|
+
xt_value xt_wasm_instantiate_value(xt_value module_or_bytes, xt_value imports,
|
|
131
|
+
char **error);
|
|
132
|
+
int xt_wasm_is_instance(xt_value value);
|
|
133
|
+
void xt_wasm_sync_memories(wasm_instance *instance, int into_wasm);
|
|
134
|
+
int xt_wasm_memory_pointer(xt_value object, wasm_memory **out);
|
|
135
|
+
uint32_t xt_wasm_memory_index(wasm_memory *memory);
|
|
136
|
+
void xt_wasm_memory_grow(wasm_memory *memory, uint32_t delta_pages, char **error);
|
|
137
|
+
xt_value xt_wasm_memory_buffer(wasm_memory *memory);
|
|
138
|
+
const char *xt_wasm_memory_name(wasm_memory *memory);
|
|
139
|
+
|
|
140
|
+
/* -- namespace entry points (wasm_api.c) ---------------------------------- */
|
|
141
|
+
xt_value xt_wasm_dispatch_static(xt_value name, int32_t argc, xt_value *argv);
|
|
142
|
+
xt_value xt_wasm_build_object(int32_t argc, xt_value *argv);
|
|
143
|
+
|
|
144
|
+
#ifdef __cplusplus
|
|
145
|
+
}
|
|
146
|
+
#endif
|
|
147
|
+
|
|
148
|
+
#endif /* XT_WASM_H */
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — the wasm3-backed `WebAssembly` namespace.
|
|
3
|
+
*
|
|
4
|
+
* This is the JavaScript surface: the `compile` / `instantiate` / `validate`
|
|
5
|
+
* statics, the `Module` / `Instance` / `Memory` constructors and their shared
|
|
6
|
+
* prototypes. The interpreter itself lives in `wasm_module.c` (parse and
|
|
7
|
+
* metadata) and `wasm_instance.c` (linking and calls).
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "wasm.h"
|
|
11
|
+
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
#include <string.h>
|
|
14
|
+
|
|
15
|
+
static xt_value xt_wasm_prototypes[XT_WASM_KIND_COUNT];
|
|
16
|
+
static xt_value xt_wasm_constructors[XT_WASM_KIND_COUNT];
|
|
17
|
+
static int xt_wasm_initialised = 0;
|
|
18
|
+
|
|
19
|
+
static xt_value xt_wasm_module_key_value = XT_UNDEFINED;
|
|
20
|
+
static xt_value xt_wasm_instance_key_value = XT_UNDEFINED;
|
|
21
|
+
static xt_value xt_wasm_memory_key_value = XT_UNDEFINED;
|
|
22
|
+
|
|
23
|
+
static const char *const xt_wasm_kind_names[XT_WASM_KIND_COUNT] = {
|
|
24
|
+
"Module", "Instance", "Memory", "Table", "Global",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
static xt_value xt_wasm_ctor_invoke(xt_value thisValue, xt_value env, int32_t argc,
|
|
28
|
+
xt_value *argv);
|
|
29
|
+
|
|
30
|
+
void xt_wasm_api_init(void) {
|
|
31
|
+
if (xt_wasm_initialised) return;
|
|
32
|
+
xt_wasm_initialised = 1;
|
|
33
|
+
xt_gc_add_root_range(xt_wasm_prototypes, XT_WASM_KIND_COUNT);
|
|
34
|
+
xt_gc_add_root_range(xt_wasm_constructors, XT_WASM_KIND_COUNT);
|
|
35
|
+
for (int kind = 0; kind < XT_WASM_KIND_COUNT; kind++) {
|
|
36
|
+
xt_value prototype = xt_object_new();
|
|
37
|
+
xt_value name = xt_string_from_cstr(xt_wasm_kind_names[kind]);
|
|
38
|
+
xt_value kindValue = xt_number((double)kind);
|
|
39
|
+
xt_value constructor = xt_closure_new((void *)xt_wasm_ctor_invoke, 1, &kindValue);
|
|
40
|
+
xt_function_set_prototype(constructor, prototype);
|
|
41
|
+
xt_function_set_metadata(constructor, name, 1);
|
|
42
|
+
xt_object_set(prototype, xt_string_from_cstr("constructor"), constructor);
|
|
43
|
+
xt_wasm_prototypes[kind] = prototype;
|
|
44
|
+
xt_wasm_constructors[kind] = constructor;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
xt_value xt_wasm_object_new(int kind) {
|
|
49
|
+
xt_wasm_api_init();
|
|
50
|
+
if (kind < 0 || kind >= XT_WASM_KIND_COUNT) return xt_object_new();
|
|
51
|
+
return xt_object_new_with_proto(xt_wasm_prototypes[kind]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
xt_value xt_wasm_constructor(int kind) {
|
|
55
|
+
xt_wasm_api_init();
|
|
56
|
+
if (kind < 0 || kind >= XT_WASM_KIND_COUNT) return XT_UNDEFINED;
|
|
57
|
+
return xt_wasm_constructors[kind];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static xt_value xt_wasm_cached_symbol(xt_value *slot, const char *name) {
|
|
61
|
+
if (!xt_is_symbol(*slot)) {
|
|
62
|
+
*slot = xt_symbol_new(xt_string_from_cstr(name));
|
|
63
|
+
xt_gc_add_root(slot);
|
|
64
|
+
}
|
|
65
|
+
return *slot;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
xt_value xt_wasm_module_key(void) {
|
|
69
|
+
return xt_wasm_cached_symbol(&xt_wasm_module_key_value, "__wasmModule");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
xt_value xt_wasm_instance_key(void) {
|
|
73
|
+
return xt_wasm_cached_symbol(&xt_wasm_instance_key_value, "__wasmInstance");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
xt_value xt_wasm_memory_key(void) {
|
|
77
|
+
return xt_wasm_cached_symbol(&xt_wasm_memory_key_value, "__wasmMemory");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
xt_value xt_wasm_ptr_value(const void *pointer) {
|
|
81
|
+
return xt_number((double)(uintptr_t)pointer);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
void *xt_wasm_value_ptr(xt_value value) {
|
|
85
|
+
if (!XT_IS_NUMBER(value)) return NULL;
|
|
86
|
+
return (void *)(uintptr_t)xt_to_double(value);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/* -- constructors --------------------------------------------------------- */
|
|
90
|
+
|
|
91
|
+
static xt_value xt_wasm_module_ctor(int32_t argc, xt_value *argv) {
|
|
92
|
+
xt_value argument = xt_wasm_number_arg(argc, argv, 0);
|
|
93
|
+
if (!xt_wasm_is_buffer_source(argument)) {
|
|
94
|
+
xt_throw(xt_wasm_type_error("WebAssembly.Module: argument must be a BufferSource"));
|
|
95
|
+
return XT_UNDEFINED;
|
|
96
|
+
}
|
|
97
|
+
char *error = NULL;
|
|
98
|
+
xt_value module = xt_wasm_compile_to_module(argument, &error);
|
|
99
|
+
if (module == XT_UNDEFINED) {
|
|
100
|
+
xt_value thrown = xt_wasm_error("CompileError", error ? error : "invalid module");
|
|
101
|
+
free(error);
|
|
102
|
+
xt_throw(thrown);
|
|
103
|
+
return XT_UNDEFINED;
|
|
104
|
+
}
|
|
105
|
+
free(error);
|
|
106
|
+
return module;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
static xt_value xt_wasm_instance_ctor(int32_t argc, xt_value *argv) {
|
|
110
|
+
xt_value module = xt_wasm_number_arg(argc, argv, 0);
|
|
111
|
+
if (xt_wasm_module_of(module) == NULL) {
|
|
112
|
+
xt_throw(xt_wasm_type_error("WebAssembly.Instance: first argument must be a Module"));
|
|
113
|
+
return XT_UNDEFINED;
|
|
114
|
+
}
|
|
115
|
+
char *error = NULL;
|
|
116
|
+
xt_value instance = xt_wasm_instantiate_value(module, xt_wasm_number_arg(argc, argv, 1), &error);
|
|
117
|
+
if (instance == XT_UNDEFINED) {
|
|
118
|
+
xt_value thrown = xt_wasm_error("LinkError", error ? error : "could not instantiate module");
|
|
119
|
+
free(error);
|
|
120
|
+
xt_throw(thrown);
|
|
121
|
+
return XT_UNDEFINED;
|
|
122
|
+
}
|
|
123
|
+
free(error);
|
|
124
|
+
return instance;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* A standalone `new WebAssembly.Memory({ initial, maximum })`. It owns an
|
|
128
|
+
* ArrayBuffer rather than wasm3 memory: it cannot be imported by a module (the
|
|
129
|
+
* bridge only links function imports), but its `.buffer` and `.grow()` behave
|
|
130
|
+
* like the platform object. */
|
|
131
|
+
static uint32_t xt_wasm_page_count(xt_value descriptor, const char *key,
|
|
132
|
+
uint32_t fallback) {
|
|
133
|
+
xt_value value = xt_get(descriptor, xt_string_from_cstr(key));
|
|
134
|
+
if (value == XT_UNDEFINED) return fallback;
|
|
135
|
+
double count = xt_to_number(value);
|
|
136
|
+
if (!(count >= 0) || count > 65536) return fallback;
|
|
137
|
+
return (uint32_t)count;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static xt_value xt_wasm_standalone_memory_grow(xt_value thisValue, xt_value env,
|
|
141
|
+
int32_t argc, xt_value *argv) {
|
|
142
|
+
(void)env;
|
|
143
|
+
uint32_t delta = argc > 0 ? (uint32_t)xt_to_int32(argv[0]) : 0;
|
|
144
|
+
xt_value oldBuffer = xt_get(thisValue, xt_string_from_cstr("buffer"));
|
|
145
|
+
uint32_t oldBytes = xt_is_array_buffer(oldBuffer) ? xt_array_buffer_byte_length(oldBuffer) : 0;
|
|
146
|
+
uint32_t newBytes = oldBytes + delta * 65536u;
|
|
147
|
+
xt_value newBuffer = xt_array_buffer_alloc(newBytes);
|
|
148
|
+
if (xt_is_array_buffer(oldBuffer)) {
|
|
149
|
+
uint8_t *scratch = (uint8_t *)malloc(oldBytes == 0 ? 1 : oldBytes);
|
|
150
|
+
if (scratch != NULL) {
|
|
151
|
+
uint32_t copied = xt_array_buffer_copy_bytes_out(oldBuffer, 0, scratch, oldBytes);
|
|
152
|
+
xt_array_buffer_copy_bytes_in(newBuffer, 0, scratch, copied);
|
|
153
|
+
free(scratch);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
xt_object_set(thisValue, xt_string_from_cstr("buffer"), newBuffer);
|
|
157
|
+
return xt_number((double)(oldBytes / 65536u));
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static xt_value xt_wasm_memory_ctor(int32_t argc, xt_value *argv) {
|
|
161
|
+
xt_value descriptor = xt_wasm_object_arg(argc, argv, 0);
|
|
162
|
+
if (descriptor == XT_UNDEFINED) {
|
|
163
|
+
xt_throw(xt_wasm_type_error("WebAssembly.Memory: descriptor must be an object"));
|
|
164
|
+
return XT_UNDEFINED;
|
|
165
|
+
}
|
|
166
|
+
uint32_t initial = xt_wasm_page_count(descriptor, "initial", 0);
|
|
167
|
+
uint32_t maximum = xt_wasm_page_count(descriptor, "maximum", 0);
|
|
168
|
+
if (maximum != 0 && initial > maximum) {
|
|
169
|
+
xt_throw(xt_wasm_error("RangeError", "initial memory is larger than maximum"));
|
|
170
|
+
return XT_UNDEFINED;
|
|
171
|
+
}
|
|
172
|
+
xt_value memory = xt_wasm_object_new(XT_WASM_KIND_MEMORY);
|
|
173
|
+
xt_value buffer = xt_array_buffer_alloc(initial * 65536u);
|
|
174
|
+
xt_object_set(memory, xt_string_from_cstr("buffer"), buffer);
|
|
175
|
+
xt_object_set(memory, xt_string_from_cstr("grow"),
|
|
176
|
+
xt_closure_new((void *)xt_wasm_standalone_memory_grow, 0, NULL));
|
|
177
|
+
return memory;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
static xt_value xt_wasm_ctor_invoke(xt_value thisValue, xt_value env, int32_t argc,
|
|
181
|
+
xt_value *argv) {
|
|
182
|
+
(void)thisValue;
|
|
183
|
+
int kind = (int)xt_to_number(xt_closure_env(env, 0));
|
|
184
|
+
switch (kind) {
|
|
185
|
+
case XT_WASM_KIND_MODULE:
|
|
186
|
+
return xt_wasm_module_ctor(argc, argv);
|
|
187
|
+
case XT_WASM_KIND_INSTANCE:
|
|
188
|
+
return xt_wasm_instance_ctor(argc, argv);
|
|
189
|
+
case XT_WASM_KIND_MEMORY:
|
|
190
|
+
return xt_wasm_memory_ctor(argc, argv);
|
|
191
|
+
default:
|
|
192
|
+
xt_throw(xt_wasm_type_error("WebAssembly: this constructor is not supported in this build"));
|
|
193
|
+
return XT_UNDEFINED;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/* -- static helpers ------------------------------------------------------- */
|
|
198
|
+
|
|
199
|
+
static xt_value xt_wasm_static_closure(xt_value thisValue, xt_value env, int32_t argc,
|
|
200
|
+
xt_value *argv) {
|
|
201
|
+
(void)thisValue;
|
|
202
|
+
return xt_wasm_dispatch_static(xt_closure_env(env, 0), argc, argv);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
static xt_value xt_wasm_module_exports_static(xt_value thisValue, xt_value env,
|
|
206
|
+
int32_t argc, xt_value *argv) {
|
|
207
|
+
(void)thisValue;
|
|
208
|
+
(void)env;
|
|
209
|
+
xt_value argument = xt_wasm_number_arg(argc, argv, 0);
|
|
210
|
+
wasm_module *module = xt_wasm_module_of(argument);
|
|
211
|
+
if (module == NULL) {
|
|
212
|
+
xt_throw(xt_wasm_type_error("WebAssembly.Module.exports: argument must be a Module"));
|
|
213
|
+
return XT_UNDEFINED;
|
|
214
|
+
}
|
|
215
|
+
return xt_wasm_module_exports_value(module);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static xt_value xt_wasm_module_imports_static(xt_value thisValue, xt_value env,
|
|
219
|
+
int32_t argc, xt_value *argv) {
|
|
220
|
+
(void)thisValue;
|
|
221
|
+
(void)env;
|
|
222
|
+
xt_value argument = xt_wasm_number_arg(argc, argv, 0);
|
|
223
|
+
wasm_module *module = xt_wasm_module_of(argument);
|
|
224
|
+
if (module == NULL) {
|
|
225
|
+
xt_throw(xt_wasm_type_error("WebAssembly.Module.imports: argument must be a Module"));
|
|
226
|
+
return XT_UNDEFINED;
|
|
227
|
+
}
|
|
228
|
+
return xt_wasm_module_imports_value(module);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
static xt_value xt_wasm_module_custom_sections(xt_value thisValue, xt_value env,
|
|
232
|
+
int32_t argc, xt_value *argv) {
|
|
233
|
+
(void)thisValue;
|
|
234
|
+
(void)env;
|
|
235
|
+
(void)argc;
|
|
236
|
+
(void)argv;
|
|
237
|
+
return xt_array_new(0, NULL);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
static xt_value xt_wasm_validate(xt_value argument) {
|
|
241
|
+
if (!xt_wasm_is_buffer_source(argument)) {
|
|
242
|
+
xt_throw(xt_wasm_type_error("WebAssembly.validate: argument must be a BufferSource"));
|
|
243
|
+
return XT_UNDEFINED;
|
|
244
|
+
}
|
|
245
|
+
uint8_t *bytes = NULL;
|
|
246
|
+
uint32_t length = 0;
|
|
247
|
+
char *error = NULL;
|
|
248
|
+
if (!xt_wasm_bytes_from_value(argument, &bytes, &length, &error)) {
|
|
249
|
+
free(error);
|
|
250
|
+
return XT_FALSE;
|
|
251
|
+
}
|
|
252
|
+
wasm_module *module = xt_wasm_module_parse(bytes, length, &error);
|
|
253
|
+
free(bytes);
|
|
254
|
+
free(error);
|
|
255
|
+
if (module == NULL) return XT_FALSE;
|
|
256
|
+
xt_wasm_module_release(module);
|
|
257
|
+
return XT_TRUE;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
xt_value xt_wasm_dispatch_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
261
|
+
const char *method = xt_string_data(name);
|
|
262
|
+
if (method == NULL) return XT_UNDEFINED;
|
|
263
|
+
if (strcmp(method, "validate") == 0) {
|
|
264
|
+
return xt_wasm_validate(xt_wasm_number_arg(argc, argv, 0));
|
|
265
|
+
}
|
|
266
|
+
if (strcmp(method, "compile") == 0) {
|
|
267
|
+
xt_value argument = xt_wasm_number_arg(argc, argv, 0);
|
|
268
|
+
if (!xt_wasm_is_buffer_source(argument)) {
|
|
269
|
+
return xt_promise_reject(
|
|
270
|
+
xt_wasm_type_error("WebAssembly.compile: argument must be a BufferSource"));
|
|
271
|
+
}
|
|
272
|
+
char *error = NULL;
|
|
273
|
+
xt_value module = xt_wasm_compile_to_module(argument, &error);
|
|
274
|
+
if (module == XT_UNDEFINED) {
|
|
275
|
+
xt_value rejected = xt_wasm_error("CompileError", error ? error : "invalid module");
|
|
276
|
+
free(error);
|
|
277
|
+
return xt_promise_reject(rejected);
|
|
278
|
+
}
|
|
279
|
+
free(error);
|
|
280
|
+
return xt_promise_resolve(module);
|
|
281
|
+
}
|
|
282
|
+
if (strcmp(method, "instantiate") == 0) {
|
|
283
|
+
xt_value argument = xt_wasm_number_arg(argc, argv, 0);
|
|
284
|
+
xt_value imports = xt_wasm_number_arg(argc, argv, 1);
|
|
285
|
+
wasm_module *existing = xt_wasm_module_of(argument);
|
|
286
|
+
xt_value module = argument;
|
|
287
|
+
int fromBytes = 0;
|
|
288
|
+
char *error = NULL;
|
|
289
|
+
if (existing == NULL) {
|
|
290
|
+
if (!xt_wasm_is_buffer_source(argument)) {
|
|
291
|
+
return xt_promise_reject(
|
|
292
|
+
xt_wasm_type_error("WebAssembly.instantiate: argument must be a Module or BufferSource"));
|
|
293
|
+
}
|
|
294
|
+
module = xt_wasm_compile_to_module(argument, &error);
|
|
295
|
+
if (module == XT_UNDEFINED) {
|
|
296
|
+
xt_value rejected = xt_wasm_error("CompileError", error ? error : "invalid module");
|
|
297
|
+
free(error);
|
|
298
|
+
return xt_promise_reject(rejected);
|
|
299
|
+
}
|
|
300
|
+
fromBytes = 1;
|
|
301
|
+
}
|
|
302
|
+
xt_value instance = xt_wasm_instantiate_value(module, imports, &error);
|
|
303
|
+
if (instance == XT_UNDEFINED) {
|
|
304
|
+
xt_value rejected = xt_wasm_error("LinkError", error ? error : "could not instantiate module");
|
|
305
|
+
free(error);
|
|
306
|
+
return xt_promise_reject(rejected);
|
|
307
|
+
}
|
|
308
|
+
free(error);
|
|
309
|
+
if (!fromBytes) return xt_promise_resolve(instance);
|
|
310
|
+
xt_value result = xt_object_new();
|
|
311
|
+
xt_object_set(result, xt_string_from_cstr("module"), module);
|
|
312
|
+
xt_object_set(result, xt_string_from_cstr("instance"), instance);
|
|
313
|
+
return xt_promise_resolve(result);
|
|
314
|
+
}
|
|
315
|
+
return XT_UNDEFINED;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
xt_value xt_wasm_build_object(int32_t argc, xt_value *argv) {
|
|
319
|
+
(void)argc;
|
|
320
|
+
(void)argv;
|
|
321
|
+
xt_wasm_api_init();
|
|
322
|
+
xt_value object = xt_object_new();
|
|
323
|
+
static const char *const statics[] = {"compile", "instantiate", "validate"};
|
|
324
|
+
for (size_t i = 0; i < sizeof(statics) / sizeof(statics[0]); i++) {
|
|
325
|
+
xt_value environment[1];
|
|
326
|
+
environment[0] = xt_string_from_cstr(statics[i]);
|
|
327
|
+
xt_object_set(object, environment[0],
|
|
328
|
+
xt_closure_new((void *)xt_wasm_static_closure, 1, environment));
|
|
329
|
+
}
|
|
330
|
+
static const struct {
|
|
331
|
+
const char *name;
|
|
332
|
+
int kind;
|
|
333
|
+
} constructors[] = {
|
|
334
|
+
{"Module", XT_WASM_KIND_MODULE},
|
|
335
|
+
{"Instance", XT_WASM_KIND_INSTANCE},
|
|
336
|
+
{"Memory", XT_WASM_KIND_MEMORY},
|
|
337
|
+
{"Table", XT_WASM_KIND_TABLE},
|
|
338
|
+
{"Global", XT_WASM_KIND_GLOBAL},
|
|
339
|
+
};
|
|
340
|
+
for (size_t i = 0; i < sizeof(constructors) / sizeof(constructors[0]); i++) {
|
|
341
|
+
xt_object_set(object, xt_string_from_cstr(constructors[i].name),
|
|
342
|
+
xt_wasm_constructor(constructors[i].kind));
|
|
343
|
+
}
|
|
344
|
+
static const char *const errors[] = {"CompileError", "LinkError", "RuntimeError"};
|
|
345
|
+
for (size_t i = 0; i < sizeof(errors) / sizeof(errors[0]); i++) {
|
|
346
|
+
xt_object_set(object, xt_string_from_cstr(errors[i]),
|
|
347
|
+
xt_error_constructor(xt_string_from_cstr(errors[i])));
|
|
348
|
+
}
|
|
349
|
+
xt_value moduleConstructor = xt_wasm_constructor(XT_WASM_KIND_MODULE);
|
|
350
|
+
xt_object_set(moduleConstructor, xt_string_from_cstr("exports"),
|
|
351
|
+
xt_closure_new((void *)xt_wasm_module_exports_static, 0, NULL));
|
|
352
|
+
xt_object_set(moduleConstructor, xt_string_from_cstr("imports"),
|
|
353
|
+
xt_closure_new((void *)xt_wasm_module_imports_static, 0, NULL));
|
|
354
|
+
xt_object_set(moduleConstructor, xt_string_from_cstr("customSections"),
|
|
355
|
+
xt_closure_new((void *)xt_wasm_module_custom_sections, 0, NULL));
|
|
356
|
+
return object;
|
|
357
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — WebAssembly feature registration table.
|
|
3
|
+
*
|
|
4
|
+
* The `WebAssembly` namespace lives in the core runtime (`xt_webassembly.c`),
|
|
5
|
+
* but the interpreter behind it is optional: wasm3 and the bridge are compiled
|
|
6
|
+
* and linked only for a program the driver's usage scan selects as a wasm user.
|
|
7
|
+
* This tiny table is the seam between the two halves.
|
|
8
|
+
*
|
|
9
|
+
* The feature's `wasm_bridge.c` installs the table from a constructor before
|
|
10
|
+
* `main` runs. When the feature is absent the pointer stays NULL and the
|
|
11
|
+
* namespace keeps its original "not supported in this build" behaviour, so a
|
|
12
|
+
* program that never touches WebAssembly pays nothing and one that does fails
|
|
13
|
+
* with a runtime error rather than an unresolved linker symbol.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#ifndef XT_WASM_API_H
|
|
17
|
+
#define XT_WASM_API_H
|
|
18
|
+
|
|
19
|
+
#include "../rt.h"
|
|
20
|
+
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
extern "C" {
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
typedef struct XtWasmApi {
|
|
26
|
+
xt_value (*dispatch)(xt_value name, int32_t argc, xt_value *argv);
|
|
27
|
+
xt_value (*object)(int32_t argc, xt_value *argv);
|
|
28
|
+
} XtWasmApi;
|
|
29
|
+
|
|
30
|
+
/** Install the wasm3-backed implementation (called by the feature bridge). */
|
|
31
|
+
void xt_wasm_install(const XtWasmApi *api);
|
|
32
|
+
|
|
33
|
+
#ifdef __cplusplus
|
|
34
|
+
}
|
|
35
|
+
#endif
|
|
36
|
+
|
|
37
|
+
#endif /* XT_WASM_API_H */
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc wasm link feature — registration bridge.
|
|
3
|
+
*
|
|
4
|
+
* wasm3 is a plain C library, not a prebuilt archive, but keeping the install
|
|
5
|
+
* in a separate translation unit mirrors the other optional features: the core
|
|
6
|
+
* runtime stays unaware of wasm3, and this object is linked only when the
|
|
7
|
+
* driver's usage scan selects the `wasm` feature.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "wasm.h"
|
|
11
|
+
#include "wasm_api.h"
|
|
12
|
+
|
|
13
|
+
static const XtWasmApi kXtWasmApi = {
|
|
14
|
+
xt_wasm_dispatch_static,
|
|
15
|
+
xt_wasm_build_object,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
#if defined(__GNUC__) || defined(__clang__)
|
|
19
|
+
/* clang targeting Windows implements this attribute with a `.CRT$XCU` entry,
|
|
20
|
+
* which the MSVC CRT runs before `main`. */
|
|
21
|
+
__attribute__((constructor)) static void xt_wasm_feature_boot(void) {
|
|
22
|
+
xt_wasm_install(&kXtWasmApi);
|
|
23
|
+
}
|
|
24
|
+
#elif defined(_MSC_VER)
|
|
25
|
+
void xt_wasm_feature_boot(void);
|
|
26
|
+
#pragma section(".CRT$XCU", read)
|
|
27
|
+
__declspec(allocate(".CRT$XCU")) static void (*const xt_wasm_feature_ctor)(void) =
|
|
28
|
+
xt_wasm_feature_boot;
|
|
29
|
+
void xt_wasm_feature_boot(void) { xt_wasm_install(&kXtWasmApi); }
|
|
30
|
+
#endif
|