xbintsc 0.6.23 → 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.
Files changed (249) hide show
  1. package/AGENTS.md +1 -1
  2. package/dist/src/cli/extensions.js +11 -3
  3. package/dist/src/cli/extensions.js.map +1 -1
  4. package/dist/src/cli/help.d.ts +1 -1
  5. package/dist/src/cli/help.js +1 -1
  6. package/dist/src/codegen/generator/state.js +7 -0
  7. package/dist/src/codegen/generator/state.js.map +1 -1
  8. package/dist/src/codegen/generator/tables.js +19 -1
  9. package/dist/src/codegen/generator/tables.js.map +1 -1
  10. package/dist/src/driver/bundler/concatenate.d.ts +23 -0
  11. package/dist/src/driver/bundler/concatenate.js +210 -0
  12. package/dist/src/driver/bundler/concatenate.js.map +1 -0
  13. package/dist/src/driver/bundler/graph.js +9 -5
  14. package/dist/src/driver/bundler/graph.js.map +1 -1
  15. package/dist/src/driver/bundler/merge.d.ts +4 -4
  16. package/dist/src/driver/bundler/merge.js +24 -207
  17. package/dist/src/driver/bundler/merge.js.map +1 -1
  18. package/dist/src/driver/bundler/{namespace-import.d.ts → namespace-object.d.ts} +5 -1
  19. package/dist/src/driver/bundler/{namespace-import.js → namespace-object.js} +6 -2
  20. package/dist/src/driver/bundler/namespace-object.js.map +1 -0
  21. package/dist/src/driver/bundler/{reexport-fixup.d.ts → reexport-resolution.d.ts} +9 -3
  22. package/dist/src/driver/bundler/{reexport-fixup.js → reexport-resolution.js} +16 -6
  23. package/dist/src/driver/bundler/reexport-resolution.js.map +1 -0
  24. package/dist/src/driver/fingerprint.d.ts +2 -2
  25. package/dist/src/driver/fingerprint.js +3 -3
  26. package/dist/src/driver/fingerprint.js.map +1 -1
  27. package/dist/src/driver/link-features.js +1 -1
  28. package/dist/src/driver/link-features.js.map +1 -1
  29. package/dist/src/driver/modules.d.ts +12 -5
  30. package/dist/src/driver/modules.js +12 -5
  31. package/dist/src/driver/modules.js.map +1 -1
  32. package/dist/src/driver/paths.js +8 -4
  33. package/dist/src/driver/paths.js.map +1 -1
  34. package/dist/src/driver/runtime-objects.d.ts +1 -1
  35. package/dist/src/driver/runtime-objects.js +13 -1
  36. package/dist/src/driver/runtime-objects.js.map +1 -1
  37. package/dist/src/driver/version.d.ts +1 -1
  38. package/dist/src/driver/version.js +1 -1
  39. package/dist/src/extensions/catalog.js +5 -1
  40. package/dist/src/extensions/catalog.js.map +1 -1
  41. package/dist/src/extensions/gui/index.js +0 -1
  42. package/dist/src/extensions/gui/index.js.map +1 -1
  43. package/dist/src/extensions/link-feature.d.ts +8 -0
  44. package/dist/src/extensions/node/stream-web/index.d.ts +6 -1
  45. package/dist/src/extensions/node/stream-web/index.js +59 -4
  46. package/dist/src/extensions/node/stream-web/index.js.map +1 -1
  47. package/dist/src/extensions/node/worker_threads/index.d.ts +14 -4
  48. package/dist/src/extensions/node/worker_threads/index.js +24 -11
  49. package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
  50. package/dist/src/extensions/registry.d.ts +9 -1
  51. package/dist/src/extensions/registry.js +4 -1
  52. package/dist/src/extensions/registry.js.map +1 -1
  53. package/dist/src/extensions/wasm-asset.d.ts +16 -0
  54. package/dist/src/extensions/wasm-asset.js +28 -0
  55. package/dist/src/extensions/wasm-asset.js.map +1 -0
  56. package/dist/src/extensions/wasm.d.ts +17 -0
  57. package/dist/src/extensions/wasm.js +68 -0
  58. package/dist/src/extensions/wasm.js.map +1 -0
  59. package/dist/src/extensions/webworker/index.d.ts +24 -0
  60. package/dist/src/extensions/webworker/index.js +54 -0
  61. package/dist/src/extensions/webworker/index.js.map +1 -0
  62. package/dist/src/index.d.ts +1 -0
  63. package/dist/src/index.js +1 -0
  64. package/dist/src/index.js.map +1 -1
  65. package/dist/tests/driver/deferred-reexport.test.js +25 -0
  66. package/dist/tests/driver/deferred-reexport.test.js.map +1 -1
  67. package/dist/tests/driver/link-features.test.js +9 -0
  68. package/dist/tests/driver/link-features.test.js.map +1 -1
  69. package/dist/tests/e2e/async-fs.test.js +44 -0
  70. package/dist/tests/e2e/async-fs.test.js.map +1 -1
  71. package/dist/tests/e2e/harness.d.ts +6 -0
  72. package/dist/tests/e2e/harness.js +13 -1
  73. package/dist/tests/e2e/harness.js.map +1 -1
  74. package/dist/tests/e2e/node-crypto-random.test.d.ts +8 -0
  75. package/dist/tests/e2e/node-crypto-random.test.js +148 -0
  76. package/dist/tests/e2e/node-crypto-random.test.js.map +1 -0
  77. package/dist/tests/e2e/node-modules.test.js +1 -1
  78. package/dist/tests/e2e/node-modules.test.js.map +1 -1
  79. package/dist/tests/e2e/web-streams.test.d.ts +8 -0
  80. package/dist/tests/e2e/web-streams.test.js +274 -0
  81. package/dist/tests/e2e/web-streams.test.js.map +1 -0
  82. package/dist/tests/e2e/web-worker.test.d.ts +7 -0
  83. package/dist/tests/e2e/web-worker.test.js +74 -0
  84. package/dist/tests/e2e/web-worker.test.js.map +1 -0
  85. package/dist/tests/e2e/webassembly.test.d.ts +8 -0
  86. package/dist/tests/e2e/webassembly.test.js +113 -0
  87. package/dist/tests/e2e/webassembly.test.js.map +1 -0
  88. package/dist/tests/e2e/worker-api.test.d.ts +14 -0
  89. package/dist/tests/e2e/worker-api.test.js +460 -0
  90. package/dist/tests/e2e/worker-api.test.js.map +1 -0
  91. package/dist/tests/e2e/worker-threads.test.d.ts +8 -0
  92. package/dist/tests/e2e/worker-threads.test.js +160 -0
  93. package/dist/tests/e2e/worker-threads.test.js.map +1 -0
  94. package/dist/tests/extensions/wasm.test.d.ts +1 -0
  95. package/dist/tests/extensions/wasm.test.js +53 -0
  96. package/dist/tests/extensions/wasm.test.js.map +1 -0
  97. package/doc/ai/cli.md +1 -1
  98. package/doc/ai/contributing.md +11 -4
  99. package/doc/ai/extensions.md +25 -2
  100. package/doc/ai/language-support.md +14 -2
  101. package/doc/ai/zh-CN/cli.md +1 -1
  102. package/doc/ai/zh-CN/contributing.md +8 -3
  103. package/doc/ai/zh-CN/extensions.md +23 -2
  104. package/doc/ai/zh-CN/language-support.md +13 -2
  105. package/doc/gui/api.md +1 -1
  106. package/doc/implemented/cli.md +1 -1
  107. package/doc/implemented/extensions.md +6 -5
  108. package/doc/implemented/node/stream-web.md +31 -0
  109. package/doc/implemented/node/worker-threads.md +88 -5
  110. package/doc/implemented/node.md +2 -1
  111. package/doc/implemented/streams.md +82 -0
  112. package/doc/implemented/wasm.md +80 -18
  113. package/doc/implemented/web-worker.md +84 -0
  114. package/doc/implemented.md +6 -2
  115. package/doc/unimplemented/deviations.md +1 -0
  116. package/doc/unimplemented/node/worker-threads.md +23 -0
  117. package/doc/unimplemented/node.md +1 -0
  118. package/doc/unimplemented/stdlib.md +2 -1
  119. package/doc/unimplemented/wasm.md +21 -9
  120. package/doc/unimplemented.md +1 -1
  121. package/doc/zh-CN/gui/api.md +1 -1
  122. package/doc/zh-CN/implemented/cli.md +1 -1
  123. package/doc/zh-CN/implemented/extensions.md +7 -6
  124. package/doc/zh-CN/implemented/node/stream-web.md +24 -0
  125. package/doc/zh-CN/implemented/node/worker-threads.md +77 -4
  126. package/doc/zh-CN/implemented/node.md +2 -1
  127. package/doc/zh-CN/implemented/streams.md +60 -0
  128. package/doc/zh-CN/implemented/wasm.md +73 -16
  129. package/doc/zh-CN/implemented/web-worker.md +79 -0
  130. package/doc/zh-CN/implemented.md +6 -2
  131. package/doc/zh-CN/unimplemented/deviations.md +1 -0
  132. package/doc/zh-CN/unimplemented/node/worker-threads.md +20 -0
  133. package/doc/zh-CN/unimplemented/node.md +1 -0
  134. package/doc/zh-CN/unimplemented/stdlib.md +2 -1
  135. package/doc/zh-CN/unimplemented/wasm.md +16 -8
  136. package/doc/zh-CN/unimplemented.md +1 -1
  137. package/llms.txt +2 -0
  138. package/package.json +8 -7
  139. package/runtime/ext_gui/browser.cpp +1 -1
  140. package/runtime/ext_node/stream_web/stream_web.c +20 -6
  141. package/runtime/worker/worker_api.c +422 -0
  142. package/runtime/worker/worker_codec.c +489 -0
  143. package/runtime/worker/worker_core.c +445 -0
  144. package/runtime/worker/worker_internal.h +223 -0
  145. package/runtime/worker/worker_platform.c +344 -0
  146. package/runtime/worker/worker_ports.c +203 -0
  147. package/runtime/worker/worker_transport.c +464 -0
  148. package/runtime/worker/worker_wire.c +150 -0
  149. package/runtime/xt_builtins.c +15 -0
  150. package/runtime/xt_constructors.c +49 -2
  151. package/runtime/xt_stdlib2/error.inc +4 -0
  152. package/runtime/xt_streams/common.inc +232 -0
  153. package/runtime/xt_streams/constructors.inc +232 -0
  154. package/runtime/xt_streams/encoding.inc +124 -0
  155. package/runtime/xt_streams/readable-extra.inc +372 -0
  156. package/runtime/xt_streams/readable.inc +415 -0
  157. package/runtime/xt_streams/transform.inc +195 -0
  158. package/runtime/xt_streams/writable.inc +542 -0
  159. package/runtime/xt_streams.c +30 -0
  160. package/runtime/xt_wasm/wasm.h +148 -0
  161. package/runtime/xt_wasm/wasm_api.c +357 -0
  162. package/runtime/xt_wasm/wasm_api.h +37 -0
  163. package/runtime/xt_wasm/wasm_bridge.c +30 -0
  164. package/runtime/xt_wasm/wasm_instance.c +591 -0
  165. package/runtime/xt_wasm/wasm_module.c +270 -0
  166. package/runtime/xt_wasm/wasm_values.c +177 -0
  167. package/runtime/xt_webassembly.c +15 -4
  168. package/scripts/fetch-vendored.ts +187 -20
  169. package/scripts/package-release.ts +3 -2
  170. package/src/cli/extensions.ts +11 -3
  171. package/src/cli/help.ts +1 -1
  172. package/src/codegen/generator/state.ts +7 -0
  173. package/src/codegen/generator/tables.ts +19 -1
  174. package/src/driver/bundler/README.md +55 -0
  175. package/src/driver/bundler/concatenate.ts +244 -0
  176. package/src/driver/bundler/graph.ts +9 -5
  177. package/src/driver/bundler/merge.ts +24 -215
  178. package/src/driver/bundler/{namespace-import.ts → namespace-object.ts} +5 -1
  179. package/src/driver/bundler/{reexport-fixup.ts → reexport-resolution.ts} +15 -5
  180. package/src/driver/fingerprint.ts +3 -3
  181. package/src/driver/link-features.ts +1 -1
  182. package/src/driver/modules.ts +12 -5
  183. package/src/driver/paths.ts +8 -4
  184. package/src/driver/runtime-objects.ts +13 -1
  185. package/src/driver/version.ts +1 -1
  186. package/src/extensions/catalog.ts +5 -1
  187. package/src/extensions/gui/index.ts +0 -1
  188. package/src/extensions/link-feature.ts +8 -0
  189. package/src/extensions/node/stream-web/index.ts +59 -4
  190. package/src/extensions/node/worker_threads/index.ts +24 -11
  191. package/src/extensions/registry.ts +13 -2
  192. package/src/extensions/wasm-asset.ts +32 -0
  193. package/src/extensions/wasm.ts +74 -0
  194. package/src/extensions/webworker/index.ts +58 -0
  195. package/src/index.ts +1 -0
  196. package/vendor/wasm3/.pin +1 -0
  197. package/vendor/wasm3/LICENSE +21 -0
  198. package/vendor/wasm3/m3_api_libc.c +265 -0
  199. package/vendor/wasm3/m3_api_libc.h +19 -0
  200. package/vendor/wasm3/m3_api_meta_wasi.c +1107 -0
  201. package/vendor/wasm3/m3_api_tracer.c +173 -0
  202. package/vendor/wasm3/m3_api_tracer.h +19 -0
  203. package/vendor/wasm3/m3_api_uvwasi.c +1290 -0
  204. package/vendor/wasm3/m3_api_wasi.c +1207 -0
  205. package/vendor/wasm3/m3_api_wasi.h +74 -0
  206. package/vendor/wasm3/m3_api_wasi_host.h +137 -0
  207. package/vendor/wasm3/m3_api_wasi_posix.h +979 -0
  208. package/vendor/wasm3/m3_api_wasi_win32.h +1093 -0
  209. package/vendor/wasm3/m3_atomic.h +114 -0
  210. package/vendor/wasm3/m3_bind.c +174 -0
  211. package/vendor/wasm3/m3_bind.h +20 -0
  212. package/vendor/wasm3/m3_code.c +232 -0
  213. package/vendor/wasm3/m3_code.h +74 -0
  214. package/vendor/wasm3/m3_compile.c +6603 -0
  215. package/vendor/wasm3/m3_compile.h +354 -0
  216. package/vendor/wasm3/m3_config.h +448 -0
  217. package/vendor/wasm3/m3_config_platforms.h +345 -0
  218. package/vendor/wasm3/m3_core.c +1034 -0
  219. package/vendor/wasm3/m3_core.h +526 -0
  220. package/vendor/wasm3/m3_deterministic.c +65 -0
  221. package/vendor/wasm3/m3_deterministic.h +59 -0
  222. package/vendor/wasm3/m3_env.c +3146 -0
  223. package/vendor/wasm3/m3_env.h +748 -0
  224. package/vendor/wasm3/m3_exception.h +33 -0
  225. package/vendor/wasm3/m3_exec.c +8 -0
  226. package/vendor/wasm3/m3_exec.h +4110 -0
  227. package/vendor/wasm3/m3_exec_atomic.h +146 -0
  228. package/vendor/wasm3/m3_exec_defs.h +76 -0
  229. package/vendor/wasm3/m3_function.c +278 -0
  230. package/vendor/wasm3/m3_function.h +244 -0
  231. package/vendor/wasm3/m3_host.h +226 -0
  232. package/vendor/wasm3/m3_host_none.h +76 -0
  233. package/vendor/wasm3/m3_host_posix.h +543 -0
  234. package/vendor/wasm3/m3_host_win32.h +253 -0
  235. package/vendor/wasm3/m3_info.c +616 -0
  236. package/vendor/wasm3/m3_info.h +38 -0
  237. package/vendor/wasm3/m3_math_utils.h +560 -0
  238. package/vendor/wasm3/m3_module.c +431 -0
  239. package/vendor/wasm3/m3_parse.c +1549 -0
  240. package/vendor/wasm3/m3_snapshot.c +3825 -0
  241. package/vendor/wasm3/m3_validate.c +1770 -0
  242. package/vendor/wasm3/m3_validate.h +25 -0
  243. package/vendor/wasm3/m3_wasi.h +10 -0
  244. package/vendor/wasm3/m3_xxh64.c +211 -0
  245. package/vendor/wasm3/wasm3.h +684 -0
  246. package/vendor/wasm3/wasm3_defs.h +350 -0
  247. package/dist/src/driver/bundler/namespace-import.js.map +0 -1
  248. package/dist/src/driver/bundler/reexport-fixup.js.map +0 -1
  249. package/runtime/ext_node/worker_threads/worker_threads.c +0 -214
@@ -0,0 +1,448 @@
1
+ //
2
+ // m3_config.h
3
+ //
4
+ // Created by Steven Massey on 5/4/19.
5
+ // Copyright © 2019 Steven Massey. All rights reserved.
6
+ //
7
+
8
+ #ifndef m3_config_h
9
+ #define m3_config_h
10
+
11
+ #include "m3_config_platforms.h"
12
+
13
+ // general --------------------------------------------------------------------
14
+
15
+ #ifndef d_m3CodePageAlignSize
16
+ # define d_m3CodePageAlignSize 32*1024
17
+ #endif
18
+
19
+ #ifndef d_m3MaxFunctionStackHeight
20
+ # define d_m3MaxFunctionStackHeight 8000 // max: 32768
21
+ #endif
22
+
23
+ #ifndef d_m3MaxLinearMemoryPages
24
+ # define d_m3MaxLinearMemoryPages 65536
25
+ #endif
26
+
27
+ #ifndef d_m3MaxFunctionSlots
28
+ # define d_m3MaxFunctionSlots ((d_m3MaxFunctionStackHeight)*2)
29
+ #endif
30
+
31
+ #ifndef d_m3ValStack // validator operand and local type stacks:
32
+ # define d_m3ValStack (d_m3MaxFunctionStackHeight) // the same operand stack the compiler bounds
33
+ #endif
34
+
35
+ #ifndef d_m3ValCtrlDepth // validator block nesting depth. Each frame is bigger than an
36
+ # define d_m3ValCtrlDepth ((d_m3MaxFunctionStackHeight)/4) // operand entry, so this dominates the validator's stack usage
37
+ #endif
38
+
39
+ #ifndef d_m3MaxConstantTableSize
40
+ # define d_m3MaxConstantTableSize 120
41
+ #endif
42
+
43
+ #ifndef d_m3MaxDuplicateFunctionImpl
44
+ # define d_m3MaxDuplicateFunctionImpl 3
45
+ #endif
46
+
47
+ #ifndef d_m3VerboseErrorMessages
48
+ # define d_m3VerboseErrorMessages 1
49
+ #endif
50
+
51
+ #ifndef d_m3FixedHeap
52
+ # define d_m3FixedHeap false
53
+ //# define d_m3FixedHeap (32*1024)
54
+ #endif
55
+
56
+ #ifndef d_m3FixedHeapAlign
57
+ # define d_m3FixedHeapAlign 16
58
+ #endif
59
+
60
+ #ifndef d_m3Use32BitSlots
61
+ # define d_m3Use32BitSlots 1
62
+ #endif
63
+
64
+ #ifndef d_m3ProfilerSlotMask
65
+ # define d_m3ProfilerSlotMask 0xFFFF
66
+ #endif
67
+
68
+ #ifndef d_m3RecordBacktraces
69
+ # define d_m3RecordBacktraces 0
70
+ #endif
71
+
72
+ #ifndef d_m3EnableExceptionBreakpoint
73
+ # define d_m3EnableExceptionBreakpoint 0 // see m3_exception.h
74
+ #endif
75
+
76
+ // Backtraces and structured traces need op_Entry to still be around when the function
77
+ // body returns, so it can't tail-call into it. Everywhere else it can, which keeps the
78
+ // native stack flat across calls -- and is what makes return_call actually iterative.
79
+ #ifndef d_m3EntryKeepsFrame
80
+ # define d_m3EntryKeepsFrame (d_m3RecordBacktraces || (d_m3EnableStrace >= 2))
81
+ #endif
82
+
83
+ // Whether return_call/return_call_indirect can reuse the caller's frame. Reusing it stops
84
+ // the m3 stack from growing, so it's only safe where the native stack doesn't grow either
85
+ // -- otherwise runaway tail recursion would blow the native stack with nothing to trap it.
86
+ // Where that doesn't hold they compile to a plain call followed by a return: still
87
+ // correct, just not iterative, and the m3 stack keeps overflowing (and trapping) first.
88
+ #ifndef d_m3CanTailCall
89
+ # define d_m3CanTailCall (!d_m3EntryKeepsFrame && M3_GUARANTEED_TAIL_CALL)
90
+ #endif
91
+
92
+
93
+ // profiling and tracing ------------------------------------------------------
94
+
95
+ #ifndef d_m3EnableOpProfiling
96
+ # define d_m3EnableOpProfiling 0 // opcode usage counters
97
+ #endif
98
+
99
+ #ifndef d_m3EnableOpTracing
100
+ # define d_m3EnableOpTracing 0 // only works with DEBUG
101
+ #endif
102
+
103
+ #ifndef d_m3EnableWasiTracing
104
+ # define d_m3EnableWasiTracing 0
105
+ #endif
106
+
107
+ #ifndef d_m3EnableStrace
108
+ # define d_m3EnableStrace 0 // 1 - trace exported function calls
109
+ // 2 - trace all calls (structured)
110
+ // 3 - all calls + loops + memory operations
111
+ #endif
112
+
113
+
114
+ // logging --------------------------------------------------------------------
115
+
116
+ #ifndef d_m3LogParse
117
+ # define d_m3LogParse 0 // .wasm binary decoding info
118
+ #endif
119
+
120
+ #ifndef d_m3LogModule
121
+ # define d_m3LogModule 0 // wasm module info
122
+ #endif
123
+
124
+ #ifndef d_m3LogCompile
125
+ # define d_m3LogCompile 0 // wasm -> metacode generation phase
126
+ #endif
127
+
128
+ #ifndef d_m3LogWasmStack
129
+ # define d_m3LogWasmStack 0 // dump the wasm stack when pushed or popped
130
+ #endif
131
+
132
+ #ifndef d_m3LogEmit
133
+ # define d_m3LogEmit 0 // metacode generation info
134
+ #endif
135
+
136
+ #ifndef d_m3LogCodePages
137
+ # define d_m3LogCodePages 0 // dump metacode pages when released
138
+ #endif
139
+
140
+ #ifndef d_m3LogRuntime
141
+ # define d_m3LogRuntime 0 // higher-level runtime information
142
+ #endif
143
+
144
+ #ifndef d_m3LogNativeStack
145
+ # define d_m3LogNativeStack 0 // track the memory usage of the C-stack
146
+ #endif
147
+
148
+ #ifndef d_m3LogHeapOps
149
+ # define d_m3LogHeapOps 0 // track heap usage
150
+ #endif
151
+
152
+ #ifndef d_m3LogTimestamps
153
+ # define d_m3LogTimestamps 0 // track timestamps on heap logs
154
+ #endif
155
+
156
+ // other ----------------------------------------------------------------------
157
+
158
+ #ifndef d_m3HasFloat
159
+ # define d_m3HasFloat 1 // implement floating point ops
160
+ #endif
161
+
162
+ // The deterministic profile: the same module fed the same input produces the same
163
+ // run, wherever and whenever it is run.
164
+ //
165
+ // A profile in the WebAssembly sense is a subset of the language that an ecosystem
166
+ // picks once, for all of its modules - not something a module or a call turns on -
167
+ // which is why this is a build option and not a runtime one. See
168
+ // https://github.com/WebAssembly/profiles. That proposal names the deterministic
169
+ // profile as the marker set {N,T}: it excludes the constructs whose behaviour is
170
+ // nondeterministic, and threading.
171
+ //
172
+ // What that comes to here:
173
+ //
174
+ // N the one rule the proposal spells out is that a NaN result is normalized to
175
+ // the canonical NaN, which is d_m3CanonicalNaN below and is turned on by this.
176
+ // The other N-marked constructs are relaxed SIMD, which wasm3 does not
177
+ // implement at all, so there is nothing to exclude.
178
+ // T threads and atomics, which wasm3 does not implement either. Whoever adds
179
+ // them has to keep them out of this profile.
180
+ //
181
+ // The proposal is about the language and stops at the module's edge. What a module
182
+ // reads through its imports - the clock, entropy, whether a wait actually waits - is
183
+ // nondeterministic in exactly the way that matters and is nobody's profile, so this
184
+ // option covers it too: the WASI clock counts from a fixed instant in fixed steps,
185
+ // random_get is a stream from a fixed seed, and poll_oneoff stops waiting on
186
+ // anything real. That half is wasm3's own, not the proposal's.
187
+ //
188
+ // Two limits belong beside it and stay separate because each is useful alone:
189
+ // m3_SetResourceLimit with c_m3Limit_GasUnits, so a runaway module stops after
190
+ // the same amount of work, and c_m3Limit_MemoryBytes (--max-memory in the CLI),
191
+ // so memory.grow fails at the same point rather than wherever the allocator gives out.
192
+ #ifndef d_m3DeterministicProfile
193
+ # define d_m3DeterministicProfile 0
194
+ #endif
195
+
196
+ // Where a float operation's result is a NaN, the spec lets the host choose its sign
197
+ // and payload, and different architectures choose differently: the same module
198
+ // produces different bits on x86, on ARM and on MIPS. With this on, every such
199
+ // result is replaced by the one canonical NaN, so those bits are the same
200
+ // everywhere.
201
+ //
202
+ // Follows the deterministic profile, which is the thing that needs it, and can be
203
+ // set on its own by a build that wants the float behaviour and nothing else. It
204
+ // costs a compare and a predictable branch on each of the float operations the spec
205
+ // calls arithmetic. It changes nothing else - a canonical NaN satisfies every
206
+ // assertion the spec suite makes about an arithmetic NaN - and abs, neg and copysign
207
+ // keep carrying their operand's payload through, as the spec defines them to.
208
+ #ifndef d_m3CanonicalNaN
209
+ # define d_m3CanonicalNaN d_m3DeterministicProfile
210
+ #endif
211
+
212
+ // Issue the dispatch load for the next operation as soon as this one's immediates are
213
+ // consumed, rather than at the point of the jump that consumes it, so the operation's
214
+ // own work covers the load latency. See the comment in m3_exec.h.
215
+ #ifndef d_m3PreloadNextOp
216
+ # define d_m3PreloadNextOp 0
217
+ #endif
218
+
219
+ #ifndef d_m3FoldSetLocal
220
+ # define d_m3FoldSetLocal 1 // fuse a value-producing op with an immediately
221
+ #endif // following local.set by retro-patching its destination
222
+
223
+ #ifndef d_m3FuseBranch
224
+ # define d_m3FuseBranch 1 // fuse a compare with an immediately following
225
+ #endif // br_if/if into one op (needs d_m3FoldSetLocal)
226
+ #if d_m3FuseBranch && !d_m3FoldSetLocal
227
+ # undef d_m3FuseBranch
228
+ # define d_m3FuseBranch 0 // the fusion candidate tracking lives in the fold machinery
229
+ #endif
230
+
231
+ #if !d_m3HasFloat && !defined(d_m3NoFloatDynamic)
232
+ # define d_m3NoFloatDynamic 1 // if no floats, do not fail until flops are actually executed
233
+ #endif
234
+
235
+ // funcref/externref values, the table instructions and multiple tables.
236
+ // Without it a module may still declare one funcref table and use call_indirect.
237
+ #ifndef d_m3HasRefTypes
238
+ # define d_m3HasRefTypes 1 // implement the reference types proposal
239
+ #endif
240
+
241
+ // i32/i64 add, sub and mul inside constant expressions, so a global, data or
242
+ // element offset can be computed from an imported global instead of a literal.
243
+ #ifndef d_m3HasExtendedConst
244
+ # define d_m3HasExtendedConst 1 // implement the extended constant expressions proposal
245
+ #endif
246
+
247
+ // More than one linear memory per module, each memory instruction naming the
248
+ // one it addresses. Memory 0 keeps the fast path -- the interpreter carries it
249
+ // in the _mem register -- and the others are reached by swapping that register
250
+ // around the access, so the cost lands only on modules that use them.
251
+ #ifndef d_m3HasMultiMemory
252
+ # define d_m3HasMultiMemory 1 // implement the multiple memories proposal
253
+ #endif
254
+
255
+ // 64-bit linear memories: a memory declares whether it is addressed by i32 or
256
+ // i64, and every instruction that names it takes operands of that type. The
257
+ // address space wasm3 can actually back is far smaller than 2^64 either way --
258
+ // see d_m3AddressLimit -- so this buys the addressing, not the range.
259
+ #ifndef d_m3HasMemory64
260
+ # define d_m3HasMemory64 1 // implement the memory64 proposal
261
+ #endif
262
+
263
+ // The import section's compact encodings: one module name shared by a run of
264
+ // imports, optionally with one externtype shared as well. Decoding only - a
265
+ // module means exactly what it would spelled out the long way.
266
+ #ifndef d_m3HasCompactImports
267
+ # define d_m3HasCompactImports 1 // implement the compact import section proposal
268
+ #endif
269
+
270
+ // 128-bit arithmetic over pairs of i64 halves
271
+ #ifndef d_m3HasWideArithmetic
272
+ # define d_m3HasWideArithmetic 1 // implement the wide arithmetic proposal
273
+ #endif
274
+
275
+ // The threads proposal's 0xFE atomic instructions, and the shared flag on a memory's
276
+ // limits. On their own they keep single-thread semantics: an atomic access is an
277
+ // ordinary one that also checks its alignment, and memory.atomic.wait can only
278
+ // time out. Sharing a memory between runtimes is d_m3HasThreads.
279
+ #ifndef d_m3HasAtomics
280
+ # define d_m3HasAtomics 1 // implement the atomic instructions of the threads proposal
281
+ #endif
282
+
283
+ // The exception handling proposal: a tag section, the exnref value type, and
284
+ // the try_table / throw / throw_ref instructions. Exceptions unwind by riding
285
+ // the same m3ret_t return path traps already use, so the cost when no module
286
+ // throws is a handful of branches.
287
+ //
288
+ // An imported tag is the exporting module's when that module is already loaded
289
+ // into the runtime, or the host's when m3_LinkTag supplied one; otherwise it is
290
+ // a fresh tag of the importing module's own. The host throws with
291
+ // m3_ThrowException and reads what escaped with m3_GetExceptionTag.
292
+ //
293
+ // Three things it does not do:
294
+ // - exception objects belong to the runtime. One caught without being reified
295
+ // is released at the catch; the rest are held until the outermost m3_Call
296
+ // returns, which is the last point an exnref can still be reached from the
297
+ // Wasm stack. One parked in a global or a table outlives that and dangles;
298
+ // there is no collector to say otherwise.
299
+ // - only the exnref shorthand is understood, not the (ref exn) / (ref null
300
+ // exn) spellings, which need the exn heap type alongside typed function
301
+ // references.
302
+ // - entering a try region costs a native frame that is only given back when
303
+ // the enclosing function returns or an enclosing loop comes round, so a long
304
+ // straight-line run of try blocks in one function trades native stack for it.
305
+ // d_m3MaxNativeStack bounds this the same way it bounds call depth.
306
+ #ifndef d_m3HasExceptionHandling
307
+ # define d_m3HasExceptionHandling 1
308
+ #endif
309
+
310
+ // (ref $t) and (ref null $t), call_ref and the rest of the typed function
311
+ // references proposal. Off by default: it is not finished, and it widens the
312
+ // value type from one byte to two wherever the compiler carries one.
313
+ #ifndef d_m3HasTypedRefs
314
+ # define d_m3HasTypedRefs 1
315
+ #endif
316
+
317
+ // The stack switching proposal: typed first-class continuations, control tags,
318
+ // suspend and resume. Built on the typed reference types, which is where a
319
+ // continuation type gets the identity that switch needs to name its peer, so
320
+ // it follows d_m3HasTypedRefs unless asked for explicitly.
321
+ #ifndef d_m3HasStackSwitching
322
+ # define d_m3HasStackSwitching d_m3HasTypedRefs
323
+ #endif
324
+
325
+ #if d_m3HasStackSwitching && !d_m3HasTypedRefs
326
+ # error "d_m3HasStackSwitching requires d_m3HasTypedRefs"
327
+ #endif
328
+
329
+ // The Wasm value stack a continuation runs on. It has to be its own buffer
330
+ // rather than a window onto the runtime stack, because it outlives the resume
331
+ // that started it.
332
+ #ifndef d_m3ContinuationStackSlots
333
+ # define d_m3ContinuationStackSlots 1024
334
+ #endif
335
+
336
+ // How many values a control tag may carry, and how many a suspended
337
+ // continuation may be handed when it is resumed or switched into. Bounds the
338
+ // fixed arrays a continuation keeps for them, so a module that asks for more
339
+ // is rejected at compile time.
340
+ #ifndef d_m3MaxContinuationPayload
341
+ # define d_m3MaxContinuationPayload 16
342
+ #endif
343
+
344
+ // How deep the interpreter may be in native frames when a continuation
345
+ // suspends. Only reached frames are recorded and the array grows to fit, so
346
+ // this is a ceiling rather than an allocation; past it, the suspend traps.
347
+ #ifndef d_m3ContinuationMaxFrames
348
+ # define d_m3ContinuationMaxFrames 256
349
+ #endif
350
+
351
+ // Snapshot serialization & deserialization. Allows saving suspended execution
352
+ // state (linear memory, globals, tables, value stack, and virtual frames) and
353
+ // restoring it to resume execution.
354
+ #ifndef d_m3HasSnapshots
355
+ # define d_m3HasSnapshots d_m3HasStackSwitching
356
+ #endif
357
+
358
+ // Minimum run length of consecutive 0x00 or 0xFF bytes to trigger sparse
359
+ // compression during snapshot linear memory encoding.
360
+ #ifndef d_m3SnapshotRunThreshold
361
+ # define d_m3SnapshotRunThreshold 128
362
+ #endif
363
+
364
+
365
+ // Gas metering. Once m3_SetResourceLimit has armed a runtime, the compiler
366
+ // instruments the function bodies it compiles from then on: each straight-line
367
+ // segment of a body is charged, before any of it runs, for the instructions it
368
+ // is about to execute, and execution traps once the budget is gone. The
369
+ // segmentation and the per-opcode costs follow ewasm's metering design.
370
+ #ifndef d_m3HasGasMetering
371
+ # define d_m3HasGasMetering 1
372
+ #endif
373
+
374
+ #ifndef d_m3EnableValidation
375
+ # define d_m3EnableValidation 1 // pre-pass bytecode type validation
376
+ #endif
377
+
378
+ #ifndef d_m3SkipStackCheck
379
+ # define d_m3SkipStackCheck 0 // skip stack overrun checks
380
+ #endif
381
+
382
+ #ifndef d_m3MaxNativeStack
383
+ // native C-stack budget (bytes) available to Wasm execution. A recursive
384
+ // Wasm module builds up native call frames (op_Call -> op_Entry -> ...);
385
+ // once this budget is exhausted the interpreter traps instead of
386
+ // overflowing the real C stack. 0 disables.
387
+ //
388
+ // This is a ceiling, not a promise: where the system can be asked what the
389
+ // calling thread's stack actually is (m3_HostStackBase), a budget that would
390
+ // reach past the bottom of it is cut down to what is really there, less
391
+ // d_m3NativeStackMargin. That is what keeps the default safe on a thread
392
+ // smaller than it - a 256KiB worker, say - without every embedder having to
393
+ // know to lower it.
394
+ # define d_m3MaxNativeStack ((8 * 1024 * 1024) - (128 * 1024))
395
+ #endif
396
+
397
+ #ifndef d_m3NativeStackMargin
398
+ // How much of a measured stack to leave below the mark. The mark is only tested
399
+ // between calls, so everything after the last test still has to fit: the rest of
400
+ // the op that traps, the interpreter frames unwinding behind it, and any host
401
+ // function already on the stack. Only used where the stack was measured rather
402
+ // than assumed; a stack too small to spare this much gives up a quarter of
403
+ // itself instead.
404
+ # define d_m3NativeStackMargin (64 * 1024)
405
+ #endif
406
+
407
+ #ifndef d_m3SkipMemoryBoundsCheck
408
+ # define d_m3SkipMemoryBoundsCheck 0 // skip memory bounds checks
409
+ #endif
410
+
411
+ // Back each linear memory with enough reserved address space that every address a
412
+ // Wasm instruction could name lands inside it, and commit only the part the memory
413
+ // actually has. An access past the end then reaches address space that is reserved
414
+ // and not committed, and the fault that follows is turned back into the trap the
415
+ // spec asks for - so the bounds check on every load and store goes away entirely.
416
+ //
417
+ // It asks a lot of the system, and m3_config_platforms.h turns it on for every target
418
+ // that answers - which leaves it off here for everything else:
419
+ //
420
+ // - 64-bit only. The reservation is 8GiB per memory, because a 32-bit address
421
+ // plus a 32-bit memarg offset reaches that far; there is no room for that in a
422
+ // 32-bit address space, and none to spare on anything embedded.
423
+ // - address space to reserve, and a way to say so: mmap on POSIX, VirtualAlloc on
424
+ // Windows. m3_host_none.h refuses to build with this on.
425
+ // - a way to catch the fault. On Windows that means a compiler that speaks
426
+ // __try/__except - MSVC or clang-cl, not MinGW.
427
+ // - no d_m3FixedHeap: the memory comes from the system here, not from that heap.
428
+ //
429
+ // d_m3GuardedArenaSlots caps how many memories a process can have at once, since
430
+ // each one takes a slot of that reserved arena. It costs address space and nothing
431
+ // else - no memory is committed for a slot until a module asks for one. The arena is
432
+ // shared by every runtime in the process and is not itself locked, so two threads
433
+ // loading modules at the same time need the embedder to keep them apart, as the rest
434
+ // of loading already does.
435
+ #ifndef d_m3GuardedMemory
436
+ # define d_m3GuardedMemory 0
437
+ #endif
438
+
439
+ #ifndef d_m3GuardedArenaSlots
440
+ # define d_m3GuardedArenaSlots 128
441
+ #endif
442
+
443
+ // What it is incompatible with is checked in m3_host.h, which is the first place
444
+ // that has seen enough of the configuration to say
445
+
446
+ #define d_m3EnableCodePageRefCounting 0 // not supported currently
447
+
448
+ #endif // m3_config_h