xbintsc 0.6.24 → 0.7.0
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/binder/declarations.d.ts +1 -0
- package/dist/src/binder/declarations.js +37 -0
- package/dist/src/binder/declarations.js.map +1 -1
- package/dist/src/binder/references.js +12 -0
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/globals.js +1 -0
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-system.d.ts +5 -0
- package/dist/src/checker/type-system.js +22 -3
- package/dist/src/checker/type-system.js.map +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/calls/access.js +25 -0
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +13 -0
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls/super.js +3 -4
- package/dist/src/codegen/generator/calls/super.js.map +1 -1
- package/dist/src/codegen/generator/calls/unwrap.d.ts +18 -0
- package/dist/src/codegen/generator/calls/unwrap.js +45 -0
- package/dist/src/codegen/generator/calls/unwrap.js.map +1 -0
- package/dist/src/codegen/generator/expressions/assignment.js +14 -0
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/module-values.d.ts +6 -0
- package/dist/src/codegen/generator/expressions/module-values.js +51 -17
- package/dist/src/codegen/generator/expressions/module-values.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.js +9 -5
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/generator.js +4 -0
- package/dist/src/codegen/generator/generator.js.map +1 -1
- package/dist/src/codegen/generator/lookup-tables.d.ts +22 -0
- package/dist/src/codegen/generator/lookup-tables.js +48 -0
- package/dist/src/codegen/generator/lookup-tables.js.map +1 -0
- package/dist/src/codegen/generator/module.js +38 -7
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +24 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +2 -6
- package/dist/src/codegen/generator/tables.js +37 -13
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.d.ts +9 -2
- package/dist/src/driver/bundler/commonjs.js +11 -4
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.d.ts +20 -0
- package/dist/src/driver/bundler/concatenate.js +68 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/deferred.d.ts +29 -1
- package/dist/src/driver/bundler/deferred.js +114 -5
- package/dist/src/driver/bundler/deferred.js.map +1 -1
- package/dist/src/driver/bundler/dynamic-import.d.ts +6 -0
- package/dist/src/driver/bundler/dynamic-import.js +59 -3
- package/dist/src/driver/bundler/dynamic-import.js.map +1 -1
- package/dist/src/driver/bundler/graph.d.ts +13 -0
- package/dist/src/driver/bundler/graph.js +11 -7
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +32 -8
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/namespace-object.d.ts +11 -0
- package/dist/src/driver/bundler/namespace-object.js +32 -0
- package/dist/src/driver/bundler/namespace-object.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +8 -2
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/bundler/symbols.d.ts +4 -0
- package/dist/src/driver/bundler/symbols.js +14 -1
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/config.d.ts +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/options.d.ts +1 -4
- package/dist/src/driver/paths.js +8 -4
- package/dist/src/driver/paths.js.map +1 -1
- package/dist/src/driver/runtime-lib.d.ts +27 -0
- package/dist/src/driver/runtime-lib.js +78 -2
- package/dist/src/driver/runtime-lib.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +37 -6
- 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/driver/version.js.map +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/buffer/index.d.ts +5 -4
- package/dist/src/extensions/node/buffer/index.js +5 -4
- package/dist/src/extensions/node/buffer/index.js.map +1 -1
- package/dist/src/extensions/node/events/index.js +8 -1
- package/dist/src/extensions/node/events/index.js.map +1 -1
- package/dist/src/extensions/node/fs/callbacks.d.ts +9 -0
- package/dist/src/extensions/node/fs/callbacks.js +42 -0
- package/dist/src/extensions/node/fs/callbacks.js.map +1 -0
- package/dist/src/extensions/node/fs/index.d.ts +2 -3
- package/dist/src/extensions/node/fs/index.js +11 -4
- package/dist/src/extensions/node/fs/index.js.map +1 -1
- package/dist/src/extensions/node/process/index.d.ts +10 -3
- package/dist/src/extensions/node/process/index.js +30 -5
- package/dist/src/extensions/node/process/index.js.map +1 -1
- 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 +16 -1
- package/dist/src/extensions/registry.js +17 -5
- 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/src/lexer/scanner.d.ts +7 -1
- package/dist/src/lexer/scanner.js +15 -0
- package/dist/src/lexer/scanner.js.map +1 -1
- package/dist/src/parser/context.d.ts +10 -0
- package/dist/src/parser/context.js +42 -3
- package/dist/src/parser/context.js.map +1 -1
- package/dist/src/parser/literals.js +6 -2
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/binder/binder.test.js +43 -0
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +15 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/driver/bundler-resolve.test.js +12 -0
- package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
- package/dist/tests/driver/commonjs-prelude.test.d.ts +11 -0
- package/dist/tests/driver/commonjs-prelude.test.js +69 -0
- package/dist/tests/driver/commonjs-prelude.test.js.map +1 -0
- package/dist/tests/driver/compiler.test.js +42 -1
- package/dist/tests/driver/compiler.test.js.map +1 -1
- package/dist/tests/driver/html-deferred-cycles.test.d.ts +10 -0
- package/dist/tests/driver/html-deferred-cycles.test.js +75 -0
- package/dist/tests/driver/html-deferred-cycles.test.js.map +1 -0
- package/dist/tests/driver/link-features.test.js +9 -0
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/driver/namespace-type-exports.test.d.ts +9 -0
- package/dist/tests/driver/namespace-type-exports.test.js +59 -0
- package/dist/tests/driver/namespace-type-exports.test.js.map +1 -0
- package/dist/tests/driver/runtime-lib.test.js +49 -1
- package/dist/tests/driver/runtime-lib.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/compile-basics.test.js +53 -0
- package/dist/tests/e2e/compile-basics.test.js.map +1 -1
- package/dist/tests/e2e/compile-deferred-marker.test.d.ts +14 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js +68 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js.map +1 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.d.ts +12 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js +89 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js.map +1 -0
- package/dist/tests/e2e/compile-error-module.test.d.ts +9 -0
- package/dist/tests/e2e/compile-error-module.test.js +29 -0
- package/dist/tests/e2e/compile-error-module.test.js.map +1 -0
- package/dist/tests/e2e/compile-gc-promises.test.d.ts +11 -0
- package/dist/tests/e2e/compile-gc-promises.test.js +52 -0
- package/dist/tests/e2e/compile-gc-promises.test.js.map +1 -0
- package/dist/tests/e2e/compile-modules.test.js +40 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-node-fs-callbacks.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js +46 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-inheritance.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js +48 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-require.test.d.ts +9 -0
- package/dist/tests/e2e/compile-node-require.test.js +29 -0
- package/dist/tests/e2e/compile-node-require.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-stats.test.d.ts +8 -0
- package/dist/tests/e2e/compile-node-stats.test.js +26 -0
- package/dist/tests/e2e/compile-node-stats.test.js.map +1 -0
- package/dist/tests/e2e/compile-proxy.test.d.ts +6 -0
- package/dist/tests/e2e/compile-proxy.test.js +66 -0
- package/dist/tests/e2e/compile-proxy.test.js.map +1 -0
- package/dist/tests/e2e/compile-web-globals.test.d.ts +6 -0
- package/dist/tests/e2e/compile-web-globals.test.js +94 -0
- package/dist/tests/e2e/compile-web-globals.test.js.map +1 -0
- package/dist/tests/e2e/fetch.test.js +1 -1
- package/dist/tests/e2e/gui-script-import-order.test.js +24 -0
- package/dist/tests/e2e/gui-script-import-order.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/json-stringify-to-json.test.d.ts +10 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js +61 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js.map +1 -0
- 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/node-process.test.d.ts +7 -0
- package/dist/tests/e2e/node-process.test.js +50 -0
- package/dist/tests/e2e/node-process.test.js.map +1 -0
- package/dist/tests/e2e/runtime-coverage-buffer.test.js +31 -0
- package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.d.ts +8 -0
- package/dist/tests/e2e/web-streams.test.js +289 -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/dist/tests/parser/literals.test.js +19 -0
- package/dist/tests/parser/literals.test.js.map +1 -1
- package/dist/tests/parser/statements.test.js +13 -0
- package/dist/tests/parser/statements.test.js.map +1 -1
- package/doc/ai/cli.md +2 -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 +2 -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/binder.md +2 -1
- package/doc/implemented/checker.md +5 -0
- package/doc/implemented/cli.md +1 -1
- package/doc/implemented/extensions.md +6 -5
- package/doc/implemented/lexer.md +1 -1
- package/doc/implemented/modules.md +23 -1
- package/doc/implemented/node/buffer.md +18 -5
- package/doc/implemented/node/fs.md +22 -1
- package/doc/implemented/node/process.md +65 -5
- package/doc/implemented/node/stream-web.md +31 -0
- package/doc/implemented/node/worker-threads.md +88 -5
- package/doc/implemented/node.md +9 -2
- package/doc/implemented/operators.md +3 -1
- package/doc/implemented/parser.md +1 -1
- package/doc/implemented/runtime-core.md +6 -2
- package/doc/implemented/stdlib.md +69 -2
- 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/classes.md +1 -0
- package/doc/unimplemented/deviations.md +1 -0
- package/doc/unimplemented/modules.md +1 -0
- package/doc/unimplemented/node/worker-threads.md +23 -0
- package/doc/unimplemented/node.md +1 -0
- package/doc/unimplemented/stdlib.md +3 -1
- package/doc/unimplemented/wasm.md +21 -9
- package/doc/unimplemented.md +1 -1
- package/doc/xbintsc.config.schema.json +5 -0
- package/doc/zh-CN/gui/api.md +1 -1
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +3 -0
- package/doc/zh-CN/implemented/cli.md +1 -1
- package/doc/zh-CN/implemented/extensions.md +7 -6
- package/doc/zh-CN/implemented/lexer.md +1 -1
- package/doc/zh-CN/implemented/modules.md +17 -1
- package/doc/zh-CN/implemented/node/buffer.md +3 -1
- package/doc/zh-CN/implemented/node/fs.md +19 -1
- package/doc/zh-CN/implemented/node/process.md +59 -5
- 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 +3 -2
- package/doc/zh-CN/implemented/operators.md +2 -1
- package/doc/zh-CN/implemented/parser.md +1 -1
- package/doc/zh-CN/implemented/runtime-core.md +3 -2
- package/doc/zh-CN/implemented/stdlib.md +58 -2
- 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/classes.md +1 -0
- package/doc/zh-CN/unimplemented/deviations.md +1 -0
- package/doc/zh-CN/unimplemented/modules.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 +3 -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/buffer/buffer.c +5 -4
- package/runtime/ext_node/buffer/parts/byte-access.inc +115 -11
- package/runtime/ext_node/buffer/parts/prototype.inc +4 -1
- package/runtime/ext_node/events/events.c +9 -0
- package/runtime/ext_node/fs/callbacks.c +138 -0
- package/runtime/ext_node/fs/fs_ops.c +28 -15
- package/runtime/ext_node/module/module.c +18 -9
- package/runtime/ext_node/process/process.c +117 -32
- package/runtime/ext_node/process/streams.c +370 -0
- package/runtime/ext_node/process/streams.h +20 -0
- package/runtime/ext_node/stream_web/stream_web.c +20 -6
- package/runtime/rt.h +36 -0
- package/runtime/rt_internal.h +10 -10
- 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_alloc.c +67 -49
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +41 -23
- package/runtime/xt_constructors.c +148 -2
- package/runtime/xt_containers/access.inc +29 -1
- package/runtime/xt_containers/function_prototypes.inc +58 -0
- package/runtime/xt_containers/objects.inc +18 -2
- package/runtime/xt_containers.c +1 -0
- package/runtime/xt_exit.c +34 -0
- package/runtime/xt_fetch/headers.inc +1 -0
- package/runtime/xt_fetch/response.inc +28 -8
- package/runtime/xt_fetch/webapi.inc +82 -0
- package/runtime/xt_fetch.c +5 -0
- package/runtime/xt_gc_verify.c +135 -0
- package/runtime/xt_intl.c +224 -0
- package/runtime/xt_io/exception.inc +40 -1
- package/runtime/xt_module_values.c +82 -0
- package/runtime/xt_proxy.c +140 -0
- package/runtime/xt_stdlib/dispatch.inc +98 -9
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/error.inc +4 -0
- package/runtime/xt_stdlib2/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +70 -53
- 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_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/runtime/xt_webassembly.c +15 -4
- package/scripts/build-runtime.ts +8 -0
- package/scripts/fetch-vendored.ts +187 -20
- package/scripts/package-release.ts +3 -2
- package/src/binder/declarations.ts +34 -0
- package/src/binder/references.ts +12 -0
- package/src/checker/globals.ts +1 -0
- package/src/checker/type-system.ts +23 -3
- package/src/cli/extensions.ts +11 -3
- package/src/cli/help.ts +1 -1
- package/src/codegen/generator/calls/access.ts +23 -0
- package/src/codegen/generator/calls/invocation.ts +12 -0
- package/src/codegen/generator/calls/super.ts +5 -4
- package/src/codegen/generator/calls/unwrap.ts +47 -0
- package/src/codegen/generator/expressions/assignment.ts +15 -0
- package/src/codegen/generator/expressions/module-values.ts +57 -19
- package/src/codegen/generator/expressions/primary.ts +9 -9
- package/src/codegen/generator/generator.ts +4 -0
- package/src/codegen/generator/lookup-tables.ts +63 -0
- package/src/codegen/generator/module.ts +38 -7
- package/src/codegen/generator/state.ts +24 -0
- package/src/codegen/generator/tables.ts +37 -13
- package/src/driver/bundler/commonjs.ts +12 -5
- package/src/driver/bundler/concatenate.ts +84 -7
- package/src/driver/bundler/deferred.ts +122 -6
- package/src/driver/bundler/dynamic-import.ts +75 -2
- package/src/driver/bundler/graph.ts +11 -7
- package/src/driver/bundler/merge.ts +31 -5
- package/src/driver/bundler/namespace-object.ts +44 -0
- package/src/driver/bundler/reexport-resolution.ts +12 -2
- package/src/driver/bundler/symbols.ts +17 -0
- package/src/driver/config.ts +1 -1
- package/src/driver/fingerprint.ts +3 -3
- package/src/driver/link-features.ts +1 -1
- package/src/driver/options.ts +1 -4
- package/src/driver/paths.ts +8 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +37 -6
- 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/buffer/index.ts +5 -4
- package/src/extensions/node/events/index.ts +8 -1
- package/src/extensions/node/fs/callbacks.ts +45 -0
- package/src/extensions/node/fs/index.ts +11 -4
- package/src/extensions/node/process/index.ts +30 -5
- 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 +34 -6
- 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/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/literals.ts +6 -2
- 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
|
@@ -17,6 +17,12 @@ import type { Generator } from "../generator.js";
|
|
|
17
17
|
export interface ModuleValueExpressionMethods {
|
|
18
18
|
/** Lower one module export to a first-class closure value. */
|
|
19
19
|
emitModuleExportValue(this: Generator, exported: ModuleExport): string;
|
|
20
|
+
/**
|
|
21
|
+
* Build (once) and register the table of linked extension modules, and return
|
|
22
|
+
* the table value. `createRequire`'s function and a computed `import()` look
|
|
23
|
+
* their specifier up in it.
|
|
24
|
+
*/
|
|
25
|
+
ensureModuleRegistry(this: Generator): string;
|
|
20
26
|
/** Build a namespace object holding every export of an imported module. */
|
|
21
27
|
emitNamespaceObject(this: Generator, exports: ModuleExports): string;
|
|
22
28
|
/** Lower a non-literal `import(specifier)` to a rejected promise. */
|
|
@@ -27,15 +33,30 @@ export const moduleValueExpressionMethods: ModuleValueExpressionMethods = {
|
|
|
27
33
|
emitModuleExportValue(this: Generator, exported: ModuleExport): string {
|
|
28
34
|
if (exported.symbol) {
|
|
29
35
|
// A direct runtime function: wrap its `(argc, argv)` pointer in a closure.
|
|
30
|
-
|
|
36
|
+
// A `void` binding (the console output methods) keeps that return type so
|
|
37
|
+
// the declaration matches the runtime's, and gets a trampoline that
|
|
38
|
+
// answers `undefined`.
|
|
39
|
+
const returnsVoid = exported.returnVoid === true;
|
|
40
|
+
const resultType = returnsVoid ? "void" : "i64";
|
|
41
|
+
this.extraDeclarations.add(`declare ${resultType} @${exported.symbol}(i32, i64*)`);
|
|
31
42
|
const fnPtr = this.reg();
|
|
32
|
-
this.emit(` ${fnPtr} = ptrtoint
|
|
43
|
+
this.emit(` ${fnPtr} = ptrtoint ${resultType} (i32, i64*)* @${exported.symbol} to i64`);
|
|
33
44
|
const env = this.alloca();
|
|
34
45
|
this.emit(` store i64 ${fnPtr}, i64* ${env}`);
|
|
46
|
+
const trampoline = returnsVoid ? "xt_voidptr_trampoline" : "xt_fnptr_trampoline";
|
|
35
47
|
const closure = this.reg();
|
|
36
48
|
this.emit(
|
|
37
|
-
` ${closure} = call i64 @xt_closure_new(i8* bitcast (i64 (i64, i64, i32, i64*)*
|
|
49
|
+
` ${closure} = call i64 @xt_closure_new(i8* bitcast (i64 (i64, i64, i32, i64*)* @${trampoline} to i8*), i32 1, i64* ${env})`,
|
|
38
50
|
);
|
|
51
|
+
/* A native constructor publishes its prototype object, so a class that
|
|
52
|
+
* extends this value chains onto the real `X.prototype` (with its
|
|
53
|
+
* methods) instead of a fresh plain object. */
|
|
54
|
+
if (exported.prototypeSymbol) {
|
|
55
|
+
this.extraDeclarations.add(`declare i64 @${exported.prototypeSymbol}(i32, i64*)`);
|
|
56
|
+
const prototype = this.reg();
|
|
57
|
+
this.emit(` ${prototype} = call i64 @${exported.prototypeSymbol}(i32 0, i64* null)`);
|
|
58
|
+
this.emit(` call i64 @xt_function_set_prototype(i64 ${closure}, i64 ${prototype})`);
|
|
59
|
+
}
|
|
39
60
|
return closure;
|
|
40
61
|
}
|
|
41
62
|
if (exported.valueSymbol) {
|
|
@@ -84,22 +105,39 @@ export const moduleValueExpressionMethods: ModuleValueExpressionMethods = {
|
|
|
84
105
|
return object;
|
|
85
106
|
},
|
|
86
107
|
|
|
108
|
+
ensureModuleRegistry(this: Generator): string {
|
|
109
|
+
/* Built at each use site: the value is a local register, so a cached one
|
|
110
|
+
* would not be readable from another function. Programs that both call
|
|
111
|
+
* `createRequire` and use a computed `import()` are rare enough that the
|
|
112
|
+
* duplicate table is cheaper than a program-wide global plus a guard. */
|
|
113
|
+
const table = this.reg();
|
|
114
|
+
this.emit(` ${table} = call i64 @xt_object_new()`);
|
|
115
|
+
for (const [name, linked] of Object.entries(this.modules)) {
|
|
116
|
+
const exports = linked.exports;
|
|
117
|
+
if (!exports) continue;
|
|
118
|
+
const namespace = this.emitNamespaceObject(exports);
|
|
119
|
+
const keys = name.startsWith("node:") ? [name] : [name, `node:${name}`];
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
this.emit(` call i64 @xt_set(i64 ${table}, i64 ${this.stringValue(key)}, i64 ${namespace})`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
this.extraDeclarations.add("declare void @xt_module_registry_set(i64)");
|
|
125
|
+
this.emit(` call void @xt_module_registry_set(i64 ${table})`);
|
|
126
|
+
return table;
|
|
127
|
+
},
|
|
128
|
+
|
|
87
129
|
emitDynamicImportReject(this: Generator, specifier: Expression): string {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
this.
|
|
96
|
-
|
|
97
|
-
this.
|
|
98
|
-
this.emit(`
|
|
99
|
-
|
|
100
|
-
this.emit(` ${error} = call i64 @xt_error_ctor(i32 1, i64* ${argPtr})`);
|
|
101
|
-
const promise = this.reg();
|
|
102
|
-
this.emit(` ${promise} = call i64 @xt_promise_reject(i64 ${error})`);
|
|
103
|
-
return promise;
|
|
130
|
+
/* A compiled binary has no module loader, but the modules linked into it
|
|
131
|
+
* are still there: the specifier can name any enabled extension module, so
|
|
132
|
+
* build a table of their namespace objects and let the runtime look it up.
|
|
133
|
+
* Anything else rejects with a message that names the specifier. This is
|
|
134
|
+
* what makes `import("node:" + "fs")` — the usual "load Node built-ins
|
|
135
|
+
* without a bundler" idiom — work. */
|
|
136
|
+
const value = this.emitExpression(specifier);
|
|
137
|
+
const table = this.ensureModuleRegistry();
|
|
138
|
+
this.extraDeclarations.add("declare i64 @xt_dynamic_import(i64, i64)");
|
|
139
|
+
const result = this.reg();
|
|
140
|
+
this.emit(` ${result} = call i64 @xt_dynamic_import(i64 ${table}, i64 ${value})`);
|
|
141
|
+
return result;
|
|
104
142
|
},
|
|
105
143
|
};
|
|
@@ -43,6 +43,7 @@ import {
|
|
|
43
43
|
} from "../tables.js";
|
|
44
44
|
import type { GlobalValue } from "../../../extensions/registry.js";
|
|
45
45
|
import type { Generator } from "../generator.js";
|
|
46
|
+
import { newCalleeName } from "../calls/unwrap.js";
|
|
46
47
|
|
|
47
48
|
export interface PrimaryExpressionMethods {
|
|
48
49
|
emitExpression(this: Generator, node: Expression): string;
|
|
@@ -349,10 +350,9 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
349
350
|
return this.runtimeCall("xt_error_constructor", [nameValue]);
|
|
350
351
|
}
|
|
351
352
|
// A bare `require` reference is CommonJS; steer the user to `import`.
|
|
352
|
-
if (identifier.text === "require") {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
353
|
+
if (identifier.text === "require") { this.reportRequireUse(identifier); return i64(XT_UNDEFINED); }
|
|
354
|
+
// `globalThis` / Node's `global` as a value is the (plain-bag) global object.
|
|
355
|
+
if (identifier.text === "globalThis" || identifier.text === "global") return this.runtimeCall("xt_global_object", []);
|
|
356
356
|
// Recognized web globals with no runtime yet lower to `undefined`.
|
|
357
357
|
if (WEB_GLOBALS.has(identifier.text)) return i64(XT_UNDEFINED);
|
|
358
358
|
/* The parser's recovery node for a missing expression. The syntax
|
|
@@ -446,9 +446,9 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
446
446
|
|
|
447
447
|
emitNew(node: NewExpression): string {
|
|
448
448
|
const callee = node.expression;
|
|
449
|
-
// A `new` expression is where the innermost frame's line should point for
|
|
450
|
-
// `Error.stack`; harmless for every other constructor.
|
|
451
449
|
this.emit(` call void @xt_stack_set_line(i32 ${this.lineOf(node)})`);
|
|
450
|
+
const calleeText = newCalleeName(callee);
|
|
451
|
+
const calleeName = calleeText === undefined ? i64(XT_UNDEFINED) : this.stringValue(calleeText);
|
|
452
452
|
if (callee.kind === SyntaxKind.Identifier) {
|
|
453
453
|
const identifier = callee as Identifier;
|
|
454
454
|
const symbol = this.binding.symbolOfIdentifier.get(identifier);
|
|
@@ -459,7 +459,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
459
459
|
const ctor = this.emitClassReference(info);
|
|
460
460
|
const args = this.emitArguments(node.arguments);
|
|
461
461
|
const result = this.reg();
|
|
462
|
-
this.emit(` ${result} = call i64 @
|
|
462
|
+
this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctor}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
|
|
463
463
|
return result;
|
|
464
464
|
}
|
|
465
465
|
}
|
|
@@ -476,7 +476,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
476
476
|
const ctorValue = this.emitGlobalValue(extensionConstructor);
|
|
477
477
|
const args = this.emitArguments(node.arguments);
|
|
478
478
|
const result = this.reg();
|
|
479
|
-
this.emit(` ${result} = call i64 @
|
|
479
|
+
this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctorValue}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
|
|
480
480
|
return result;
|
|
481
481
|
}
|
|
482
482
|
if (identifier.text === "Object") {
|
|
@@ -500,7 +500,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
500
500
|
const ctorValue = this.emitExpression(callee);
|
|
501
501
|
const args = this.emitArguments(node.arguments);
|
|
502
502
|
const result = this.reg();
|
|
503
|
-
this.emit(` ${result} = call i64 @
|
|
503
|
+
this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctorValue}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
|
|
504
504
|
return result;
|
|
505
505
|
},
|
|
506
506
|
|
|
@@ -12,6 +12,7 @@ import type { DiagnosticBag } from "../../diagnostics/diagnostic.js";
|
|
|
12
12
|
import { bind } from "../../binder/binder.js";
|
|
13
13
|
import { checkProgram } from "../../checker/checker.js";
|
|
14
14
|
import { GeneratorContext } from "./context.js";
|
|
15
|
+
import { hardenLookupTables } from "./lookup-tables.js";
|
|
15
16
|
import { moduleMethods, type ModuleMethods } from "./module.js";
|
|
16
17
|
import { statementMethods, type StatementMethods } from "./statements.js";
|
|
17
18
|
import { expressionMethods, type ExpressionMethods } from "./expressions.js";
|
|
@@ -47,6 +48,9 @@ export function generate(
|
|
|
47
48
|
diagnostics: DiagnosticBag,
|
|
48
49
|
options: CodegenOptions = {},
|
|
49
50
|
): CodegenResult {
|
|
51
|
+
// Lookup tables must not answer for inherited members (`toString`) before
|
|
52
|
+
// any name is lowered; see `lookup-tables.ts`.
|
|
53
|
+
hardenLookupTables();
|
|
50
54
|
// Bind once: the checker and the generator must see the same symbol table.
|
|
51
55
|
const binding = bind(sourceFile);
|
|
52
56
|
if (options.check !== false) {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hardening and extras for the builtin lookup tables in `./tables.ts`.
|
|
3
|
+
*
|
|
4
|
+
* The generator reads every table with `table[name]`, where `name` comes from the
|
|
5
|
+
* program's source. A plain object literal inherits `Object.prototype`, so
|
|
6
|
+
* `NAMESPACE_VALUES["toString"]` resolves to `Object.prototype.toString` and the
|
|
7
|
+
* generator used to emit that function's text as an LLVM symbol
|
|
8
|
+
* (`declare i64 @function toString() { [native code] }(i32, i64*)`), which clang
|
|
9
|
+
* rejects. `constructor`, `valueOf` and the other inherited members did the same.
|
|
10
|
+
*
|
|
11
|
+
* `hardenLookupTables` drops the prototype of every table once, before code
|
|
12
|
+
* generation starts. It lives here rather than in `tables.ts` so the tables stay
|
|
13
|
+
* a data module (and the file stays inside the repository's length budget).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import {
|
|
17
|
+
BINARY_RUNTIME,
|
|
18
|
+
BUILTIN_FUNCTION_VALUES,
|
|
19
|
+
BUILTIN_INSTANCEOF,
|
|
20
|
+
CONSOLE_METHODS,
|
|
21
|
+
CTOR_FUNCTIONS,
|
|
22
|
+
ERROR_CONSTRUCTORS,
|
|
23
|
+
GLOBAL_FUNCTIONS,
|
|
24
|
+
MATH_CONSTANTS,
|
|
25
|
+
NAMESPACE_PROPERTIES,
|
|
26
|
+
NAMESPACE_STATICS,
|
|
27
|
+
NAMESPACE_VALUES,
|
|
28
|
+
TYPED_ARRAYS,
|
|
29
|
+
} from "./tables.js";
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Namespaces whose properties are writable from JavaScript (`process.exitCode =
|
|
33
|
+
* 1`), mapped to the runtime setter `(key, value)`. A namespace without an entry
|
|
34
|
+
* is read-only: assigning to one of its properties takes the generic object path.
|
|
35
|
+
*/
|
|
36
|
+
export const NAMESPACE_PROPERTY_SETTERS: Record<string, string> = {
|
|
37
|
+
process: "xt_process_set",
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const LOOKUP_TABLES: readonly Record<string, unknown>[] = [
|
|
41
|
+
BINARY_RUNTIME,
|
|
42
|
+
BUILTIN_FUNCTION_VALUES,
|
|
43
|
+
BUILTIN_INSTANCEOF,
|
|
44
|
+
CONSOLE_METHODS,
|
|
45
|
+
CTOR_FUNCTIONS,
|
|
46
|
+
ERROR_CONSTRUCTORS,
|
|
47
|
+
GLOBAL_FUNCTIONS,
|
|
48
|
+
MATH_CONSTANTS,
|
|
49
|
+
NAMESPACE_PROPERTIES,
|
|
50
|
+
NAMESPACE_PROPERTY_SETTERS,
|
|
51
|
+
NAMESPACE_STATICS,
|
|
52
|
+
NAMESPACE_VALUES,
|
|
53
|
+
TYPED_ARRAYS,
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
let hardened = false;
|
|
57
|
+
|
|
58
|
+
/** Idempotent: called by `generate` before the first expression is lowered. */
|
|
59
|
+
export function hardenLookupTables(): void {
|
|
60
|
+
if (hardened) return;
|
|
61
|
+
hardened = true;
|
|
62
|
+
for (const table of LOOKUP_TABLES) Object.setPrototypeOf(table, null);
|
|
63
|
+
}
|
|
@@ -215,6 +215,19 @@ export const moduleMethods: ModuleMethods = {
|
|
|
215
215
|
this.declareSlot(symbol, i64(XT_UNDEFINED));
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
/* `var` is function scoped and hoisted, so a reference textually *before*
|
|
219
|
+
* the declaration must already have a slot holding `undefined`:
|
|
220
|
+
* `tsIsDeclarationStart() { return (e = this.state.type) >= 124; var e }`.
|
|
221
|
+
* The binder lifts every `var` into the function scope, so declaring the
|
|
222
|
+
* slots now makes the later statement a plain store (minified bundles use
|
|
223
|
+
* this idiom constantly — it used to report "no slot for 'e'"). */
|
|
224
|
+
for (const symbol of fn.locals) {
|
|
225
|
+
if (symbol.kind !== SymbolKind.Var) continue;
|
|
226
|
+
if (this.moduleGlobals.has(symbol.id)) continue;
|
|
227
|
+
if (this.current.slots.has(symbol.id)) continue;
|
|
228
|
+
this.declareSlot(symbol, i64(XT_UNDEFINED));
|
|
229
|
+
}
|
|
230
|
+
|
|
218
231
|
// Hoisted function declarations: create their closure values in this
|
|
219
232
|
// frame (before the body runs) so a nested function that references one
|
|
220
233
|
// gets the closure built against the declaring frame, not against the
|
|
@@ -245,11 +258,10 @@ export const moduleMethods: ModuleMethods = {
|
|
|
245
258
|
this.emit(` ${proto} = call i64 @xt_function_get_prototype(i64 ${owner})`);
|
|
246
259
|
const parentProto = this.reg();
|
|
247
260
|
this.emit(` ${parentProto} = call i64 @xt_object_get_prototype(i64 ${proto})`);
|
|
248
|
-
const ctorKey = this.stringValue("__ctor");
|
|
249
|
-
const parentCtor = this.reg();
|
|
250
|
-
this.emit(` ${parentCtor} = call i64 @xt_get(i64 ${parentProto}, i64 ${ctorKey})`);
|
|
251
261
|
const superThis = this.emitThis();
|
|
252
|
-
this.emit(
|
|
262
|
+
this.emit(
|
|
263
|
+
` call i64 @xt_super_construct(i64 ${superThis}, i64 ${owner}, i64 ${parentProto}, i32 %argc, i64* %argv)`,
|
|
264
|
+
);
|
|
253
265
|
} else if (!explicitBody && errorName) {
|
|
254
266
|
// `extends Error` / `extends TypeError` with no explicit constructor:
|
|
255
267
|
// initialise the instance's name and message from the arguments.
|
|
@@ -286,7 +298,21 @@ export const moduleMethods: ModuleMethods = {
|
|
|
286
298
|
|
|
287
299
|
// Body.
|
|
288
300
|
if (fn.node.kind === SyntaxKind.SourceFile) {
|
|
289
|
-
|
|
301
|
+
/* Record which module is initialising. Every module of a bundle shares
|
|
302
|
+
* this one function, so without it a crash (or an `Error.stack`) inside a
|
|
303
|
+
* module body points at the entry file's offsets — the coordinates say
|
|
304
|
+
* `cli.ts:653` no matter where it really happened. */
|
|
305
|
+
let currentModule: string | undefined;
|
|
306
|
+
for (const statement of this.sourceFile.statements) {
|
|
307
|
+
const origin = this.sourceFile.origins?.get(statement);
|
|
308
|
+
if (origin !== undefined && origin !== currentModule) {
|
|
309
|
+
currentModule = origin;
|
|
310
|
+
this.emit(` call void @xt_stack_set_module(i8* ${this.internStatic(artifactPath(origin))})`);
|
|
311
|
+
}
|
|
312
|
+
this.emitStatement(statement);
|
|
313
|
+
}
|
|
314
|
+
/* Module bodies are done; later errors should not name the last module. */
|
|
315
|
+
this.emit(` call void @xt_stack_set_module(i8* null)`);
|
|
290
316
|
} else if (fn.node.kind === SyntaxKind.ArrowFunction && (fn.node as ArrowFunction).body.kind !== SyntaxKind.Block) {
|
|
291
317
|
const value = this.emitExpression((fn.node as ArrowFunction).body as Expression);
|
|
292
318
|
this.emitFunctionReturn(value);
|
|
@@ -338,12 +364,17 @@ export const moduleMethods: ModuleMethods = {
|
|
|
338
364
|
" call void @xt_gc_init()",
|
|
339
365
|
...rootLines,
|
|
340
366
|
...stringInit,
|
|
367
|
+
" call void @xt_gc_begin_startup()",
|
|
341
368
|
" call void @xt_gc_arm()",
|
|
342
369
|
" call void @xt_set_program_args(i32 %argc, i8** %argv)",
|
|
343
370
|
` %result = call i64 @${moduleName}(i64 ${i64(XT_UNDEFINED)}, i64 ${i64(XT_UNDEFINED)}, i32 0, i64* null)`,
|
|
371
|
+
" call void @xt_gc_end_startup()",
|
|
344
372
|
" call void @xt_drain_microtasks()",
|
|
345
373
|
" call void @xt_run_event_loop()",
|
|
346
|
-
"
|
|
374
|
+
/* Run the exit hook (Node's `process` "exit" listeners) and report the
|
|
375
|
+
* status the program asked for (`process.exitCode` / `process.exit`). */
|
|
376
|
+
" %exitstatus = call i32 @xt_finish()",
|
|
377
|
+
" ret i32 %exitstatus",
|
|
347
378
|
"}",
|
|
348
379
|
"",
|
|
349
380
|
].join(ARTIFACT_LINE_ENDING),
|
|
@@ -443,7 +474,7 @@ export const moduleMethods: ModuleMethods = {
|
|
|
443
474
|
this.emit(` call i64 @xt_object_set_prototype(i64 ${proto}, i64 ${parentProto})`);
|
|
444
475
|
} else {
|
|
445
476
|
const parentProto = this.reg();
|
|
446
|
-
this.emit(` ${parentProto} = call i64 @
|
|
477
|
+
this.emit(` ${parentProto} = call i64 @xt_parent_prototype(i64 ${parentValue})`);
|
|
447
478
|
this.emit(` call i64 @xt_object_set_prototype(i64 ${proto}, i64 ${parentProto})`);
|
|
448
479
|
}
|
|
449
480
|
}
|
|
@@ -113,6 +113,7 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
113
113
|
"declare i64 @xt_arg(i32, i64*, i32)",
|
|
114
114
|
"declare i64 @xt_closure_new(i8*, i32, i64*)",
|
|
115
115
|
"declare i64 @xt_fnptr_trampoline(i64, i64, i32, i64*)",
|
|
116
|
+
"declare i64 @xt_voidptr_trampoline(i64, i64, i32, i64*)",
|
|
116
117
|
"declare i64 @xt_method_trampoline(i64, i64, i32, i64*)",
|
|
117
118
|
"declare i64 @xt_function_set_metadata(i64, i64, i32)",
|
|
118
119
|
"declare i64 @xt_function_set_generator(i64)",
|
|
@@ -125,6 +126,10 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
125
126
|
"declare i64 @xt_call_with_this(i64, i64, i32, i64*)",
|
|
126
127
|
"declare i64 @xt_this()",
|
|
127
128
|
"declare i64 @xt_new(i64, i32, i64*)",
|
|
129
|
+
"declare i64 @xt_new_named(i64, i64, i32, i64*)",
|
|
130
|
+
"declare i64 @xt_super_construct(i64, i64, i64, i32, i64*)",
|
|
131
|
+
"declare i64 @xt_parent_prototype(i64)",
|
|
132
|
+
"declare i64 @xt_global_object()",
|
|
128
133
|
"declare i64 @xt_instance_of(i64, i64)",
|
|
129
134
|
"declare i64 @xt_instance_of_builtin(i64, i32)",
|
|
130
135
|
"declare i64 @xt_builtin_constructor(i64)",
|
|
@@ -140,9 +145,12 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
140
145
|
"declare i64 @xt_await(i64)",
|
|
141
146
|
"declare void @xt_drain_microtasks()",
|
|
142
147
|
"declare void @xt_run_event_loop()",
|
|
148
|
+
"declare i32 @xt_finish()",
|
|
143
149
|
"declare void @xt_gc_init()",
|
|
144
150
|
"declare void @xt_gc_set_stack_base(i8*)",
|
|
145
151
|
"declare void @xt_gc_arm()",
|
|
152
|
+
"declare void @xt_gc_begin_startup()",
|
|
153
|
+
"declare void @xt_gc_end_startup()",
|
|
146
154
|
"declare void @xt_gc_add_root(i64*)",
|
|
147
155
|
"declare i64 @xt_promise_resolve(i64)",
|
|
148
156
|
"declare i64 @xt_promise_reject(i64)",
|
|
@@ -158,6 +166,7 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
158
166
|
"declare i64 @xt_crypto_get(i64)",
|
|
159
167
|
"declare i64 @xt_webassembly_static(i64, i32, i64*)",
|
|
160
168
|
"declare i64 @xt_webassembly_object(i32, i64*)",
|
|
169
|
+
"declare i64 @xt_intl_object(i32, i64*)",
|
|
161
170
|
"declare i64 @xt_path_static(i64, i32, i64*)",
|
|
162
171
|
"declare i64 @xt_os_static(i64, i32, i64*)",
|
|
163
172
|
"declare i64 @xt_buffer_static(i64, i32, i64*)",
|
|
@@ -207,6 +216,20 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
207
216
|
"declare i64 @xt_finalization_registry_ctor(i32, i64*)",
|
|
208
217
|
"declare i64 @xt_text_encoder_ctor(i32, i64*)",
|
|
209
218
|
"declare i64 @xt_text_decoder_ctor(i32, i64*)",
|
|
219
|
+
"declare i64 @xt_readable_stream_ctor(i32, i64*)",
|
|
220
|
+
"declare i64 @xt_writable_stream_ctor(i32, i64*)",
|
|
221
|
+
"declare i64 @xt_transform_stream_ctor(i32, i64*)",
|
|
222
|
+
"declare i64 @xt_count_queuing_strategy_ctor(i32, i64*)",
|
|
223
|
+
"declare i64 @xt_byte_length_queuing_strategy_ctor(i32, i64*)",
|
|
224
|
+
"declare i64 @xt_text_encoder_stream_ctor(i32, i64*)",
|
|
225
|
+
"declare i64 @xt_text_decoder_stream_ctor(i32, i64*)",
|
|
226
|
+
"declare i64 @xt_abort_controller_ctor(i32, i64*)",
|
|
227
|
+
"declare i64 @xt_abort_signal_ctor(i32, i64*)",
|
|
228
|
+
"declare i64 @xt_abort_signal_static(i64, i32, i64*)",
|
|
229
|
+
"declare i64 @xt_headers_ctor(i32, i64*)",
|
|
230
|
+
"declare i64 @xt_proxy_ctor(i32, i64*)",
|
|
231
|
+
"declare i64 @xt_response_ctor(i32, i64*)",
|
|
232
|
+
"declare i64 @xt_defer_module(i32, i64*)",
|
|
210
233
|
"declare i64 @xt_date_ctor(i32, i64*)",
|
|
211
234
|
"declare i64 @xt_regexp_ctor(i32, i64*)",
|
|
212
235
|
"declare i64 @xt_url_ctor(i32, i64*)",
|
|
@@ -365,6 +388,7 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
365
388
|
"declare i64 @xt_try_exception(i8*)",
|
|
366
389
|
"declare void @xt_try_leave(i8*)",
|
|
367
390
|
"declare void @xt_stack_push(i8*, i8*, i32)",
|
|
391
|
+
"declare void @xt_stack_set_module(i8*)",
|
|
368
392
|
"declare void @xt_stack_pop()",
|
|
369
393
|
"declare void @xt_stack_set_line(i32)",
|
|
370
394
|
"declare void @xt_console_log(i32, i64*)",
|
|
@@ -49,6 +49,11 @@ export const BUILTIN_INSTANCEOF: Readonly<Record<string, number>> = {
|
|
|
49
49
|
Int32Array: 22,
|
|
50
50
|
Float32Array: 23,
|
|
51
51
|
Float64Array: 24,
|
|
52
|
+
ReadableStream: 11,
|
|
53
|
+
WritableStream: 12,
|
|
54
|
+
TransformStream: 13,
|
|
55
|
+
TextEncoderStream: 14,
|
|
56
|
+
TextDecoderStream: 15,
|
|
52
57
|
};
|
|
53
58
|
|
|
54
59
|
export const BINARY_RUNTIME: Record<string, string | undefined> = {
|
|
@@ -161,6 +166,7 @@ export const GLOBAL_FUNCTIONS: Record<string, string> = {
|
|
|
161
166
|
queueMicrotask: "xt_queue_microtask",
|
|
162
167
|
structuredClone: "xt_structured_clone",
|
|
163
168
|
fetch: "xt_fetch",
|
|
169
|
+
__xt_defer: "xt_defer_module",
|
|
164
170
|
Number: "xt_number_ctor",
|
|
165
171
|
String: "xt_string_ctor",
|
|
166
172
|
Boolean: "xt_boolean_ctor",
|
|
@@ -258,6 +264,7 @@ export const NAMESPACE_STATICS: Record<string, string> = {
|
|
|
258
264
|
Duplex: "xt_stream_static",
|
|
259
265
|
Transform: "xt_stream_static",
|
|
260
266
|
PassThrough: "xt_stream_static",
|
|
267
|
+
AbortSignal: "xt_abort_signal_static",
|
|
261
268
|
net: "xt_net_static",
|
|
262
269
|
dgram: "xt_dgram_static",
|
|
263
270
|
http: "xt_http_static",
|
|
@@ -289,29 +296,20 @@ export const SYMBOL_WELL_KNOWN = new Set<string>([
|
|
|
289
296
|
/** Namespaces that also exist as a first-class object value (`Math.cos`). */
|
|
290
297
|
export const NAMESPACE_VALUES: Record<string, string> = {
|
|
291
298
|
Math: "xt_math_object",
|
|
299
|
+
JSON: "xt_json_object",
|
|
292
300
|
crypto: "xt_crypto_object",
|
|
293
301
|
WebAssembly: "xt_webassembly_object",
|
|
302
|
+
Intl: "xt_intl_object",
|
|
294
303
|
};
|
|
295
304
|
|
|
296
|
-
/**
|
|
297
|
-
*
|
|
298
|
-
* type-checks, but with no runtime implementation yet: they lower to
|
|
299
|
-
* `undefined`. A construct such as `new AbortController()` therefore fails at
|
|
300
|
-
* run time rather than being reported as an unknown name.
|
|
301
|
-
*/
|
|
305
|
+
/** Web-platform globals recognized for type checking but not implemented: they
|
|
306
|
+
* lower to `undefined` and fail at run time, not as an unknown name. */
|
|
302
307
|
export const WEB_GLOBALS: ReadonlySet<string> = new Set<string>([
|
|
303
308
|
"globalThis",
|
|
304
|
-
"AbortController",
|
|
305
|
-
"AbortSignal",
|
|
306
309
|
"Reflect",
|
|
307
|
-
"Proxy",
|
|
308
|
-
"Intl",
|
|
309
310
|
"FormData",
|
|
310
311
|
"Blob",
|
|
311
|
-
"Headers",
|
|
312
312
|
"Request",
|
|
313
|
-
"Response",
|
|
314
|
-
"ReadableStream",
|
|
315
313
|
"EventTarget",
|
|
316
314
|
]);
|
|
317
315
|
|
|
@@ -349,8 +347,20 @@ export const CTOR_FUNCTIONS: Record<string, string> = {
|
|
|
349
347
|
URLSearchParams: "xt_url_search_params_ctor",
|
|
350
348
|
TextEncoder: "xt_text_encoder_ctor",
|
|
351
349
|
TextDecoder: "xt_text_decoder_ctor",
|
|
350
|
+
ReadableStream: "xt_readable_stream_ctor",
|
|
351
|
+
WritableStream: "xt_writable_stream_ctor",
|
|
352
|
+
TransformStream: "xt_transform_stream_ctor",
|
|
353
|
+
CountQueuingStrategy: "xt_count_queuing_strategy_ctor",
|
|
354
|
+
ByteLengthQueuingStrategy: "xt_byte_length_queuing_strategy_ctor",
|
|
355
|
+
TextEncoderStream: "xt_text_encoder_stream_ctor",
|
|
356
|
+
TextDecoderStream: "xt_text_decoder_stream_ctor",
|
|
352
357
|
ArrayBuffer: "xt_array_buffer_ctor",
|
|
353
358
|
DataView: "xt_data_view_ctor",
|
|
359
|
+
AbortController: "xt_abort_controller_ctor",
|
|
360
|
+
AbortSignal: "xt_abort_signal_ctor",
|
|
361
|
+
Headers: "xt_headers_ctor",
|
|
362
|
+
Response: "xt_response_ctor",
|
|
363
|
+
Proxy: "xt_proxy_ctor",
|
|
354
364
|
...ERROR_CONSTRUCTORS,
|
|
355
365
|
...TYPED_ARRAY_CTORS,
|
|
356
366
|
};
|
|
@@ -381,6 +391,20 @@ export const FIRST_CLASS_CONSTRUCTORS = new Set<string>([
|
|
|
381
391
|
"Boolean",
|
|
382
392
|
"BigInt",
|
|
383
393
|
"Symbol",
|
|
394
|
+
"ReadableStream",
|
|
395
|
+
"WritableStream",
|
|
396
|
+
"TransformStream",
|
|
397
|
+
"CountQueuingStrategy",
|
|
398
|
+
"ByteLengthQueuingStrategy",
|
|
399
|
+
"TextEncoderStream",
|
|
400
|
+
"TextDecoderStream",
|
|
401
|
+
"AbortController",
|
|
402
|
+
"AbortSignal",
|
|
403
|
+
"Headers",
|
|
404
|
+
"Response",
|
|
405
|
+
"ArrayBuffer",
|
|
406
|
+
"DataView",
|
|
407
|
+
"Proxy",
|
|
384
408
|
]);
|
|
385
409
|
|
|
386
410
|
export const BUILTIN_METHODS = new Set<string>([
|
|
@@ -105,9 +105,16 @@ export interface CommonJSLoweringContext {
|
|
|
105
105
|
* free references, and record its export surface (whole-object `default` plus
|
|
106
106
|
* every syntactically detectable named export). Runs before the ESM export
|
|
107
107
|
* collection so re-exports of a CommonJS module resolve.
|
|
108
|
+
*
|
|
109
|
+
* Returns the statements that must run *before any* module body: the
|
|
110
|
+
* `module`/`exports` pair. Node creates them when a module starts loading, so a
|
|
111
|
+
* `require` cycle sees the earlier module's (partly filled) object; keeping them
|
|
112
|
+
* in the module's own block would leave the later module reading an object that
|
|
113
|
+
* does not exist yet. The caller hoists them into a program-wide prelude, and
|
|
114
|
+
* the module keeps only its body plus the export snapshot at the end.
|
|
108
115
|
*/
|
|
109
|
-
export function prepareCommonJS(record: ModuleRecord):
|
|
110
|
-
if (!record.commonjs) return;
|
|
116
|
+
export function prepareCommonJS(record: ModuleRecord): Statement[] {
|
|
117
|
+
if (!record.commonjs) return [];
|
|
111
118
|
const statements = record.sourceFile.statements as Statement[];
|
|
112
119
|
const anchor = statements[0]?.start ?? record.sourceFile.start;
|
|
113
120
|
|
|
@@ -125,12 +132,12 @@ export function prepareCommonJS(record: ModuleRecord): void {
|
|
|
125
132
|
else if (identifier.text === "exports" && hasExports) (identifier as { text: string }).text = exportsName;
|
|
126
133
|
}
|
|
127
134
|
|
|
128
|
-
const
|
|
135
|
+
const preludeStatements: Statement[] = [
|
|
129
136
|
variableStatement(moduleName, objectLiteral([propertyAssignment("exports", objectLiteral([]))]), anchor),
|
|
130
137
|
];
|
|
131
138
|
// `exports` may be reassigned (`exports = module.exports = {}`), so the alias
|
|
132
139
|
// is a `let`, not a `const`.
|
|
133
|
-
|
|
140
|
+
preludeStatements.push(variableStatement(exportsName, member(moduleName, "exports", anchor), anchor, "let"));
|
|
134
141
|
|
|
135
142
|
const suffixStatements: Statement[] = [];
|
|
136
143
|
const defaultName = `${record.prefix}$cjs_default`;
|
|
@@ -142,8 +149,8 @@ export function prepareCommonJS(record: ModuleRecord): void {
|
|
|
142
149
|
record.exports.set(name, local);
|
|
143
150
|
}
|
|
144
151
|
|
|
145
|
-
statements.unshift(...prefixStatements);
|
|
146
152
|
statements.push(...suffixStatements);
|
|
153
|
+
return preludeStatements;
|
|
147
154
|
}
|
|
148
155
|
|
|
149
156
|
/**
|