xbintsc 0.6.18 → 0.6.22
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/dist/src/ast/common.d.ts +2 -2
- package/dist/src/ast/declarations.d.ts +2 -0
- package/dist/src/ast/expressions.d.ts +5 -0
- package/dist/src/ast/kinds.d.ts +2 -0
- package/dist/src/ast/kinds.js +2 -0
- package/dist/src/ast/kinds.js.map +1 -1
- package/dist/src/ast/types.d.ts +2 -0
- package/dist/src/binder/binder.d.ts +6 -0
- package/dist/src/binder/binder.js +13 -0
- package/dist/src/binder/binder.js.map +1 -1
- package/dist/src/binder/references.js +9 -2
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/assignability.js +11 -3
- package/dist/src/checker/assignability.js.map +1 -1
- package/dist/src/checker/calls.js +4 -0
- package/dist/src/checker/calls.js.map +1 -1
- package/dist/src/checker/flow.js +16 -12
- package/dist/src/checker/flow.js.map +1 -1
- package/dist/src/checker/globals.js +3 -1
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/type-system.js +1 -0
- package/dist/src/checker/type-system.js.map +1 -1
- package/dist/src/checker/typecheck.js +8 -1
- package/dist/src/checker/typecheck.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +4 -0
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +3 -1
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +8 -4
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/context.js +3 -3
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +1 -0
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/module-values.d.ts +21 -0
- package/dist/src/codegen/generator/expressions/module-values.js +84 -0
- package/dist/src/codegen/generator/expressions/module-values.js.map +1 -0
- package/dist/src/codegen/generator/expressions/primary.js +38 -6
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/module.js +16 -6
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +6 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/statements/dispatch.js +10 -0
- package/dist/src/codegen/generator/statements/dispatch.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +7 -0
- package/dist/src/codegen/generator/tables.js +26 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +3 -0
- package/dist/src/driver/build-key.js +3 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.js +9 -5
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/deferred.d.ts +1 -1
- package/dist/src/driver/bundler/deferred.js +2 -2
- package/dist/src/driver/bundler/deferred.js.map +1 -1
- package/dist/src/driver/bundler/dynamic-import.d.ts +30 -0
- package/dist/src/driver/bundler/dynamic-import.js +123 -0
- package/dist/src/driver/bundler/dynamic-import.js.map +1 -0
- package/dist/src/driver/bundler/graph.d.ts +1 -1
- package/dist/src/driver/bundler/graph.js +30 -12
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.d.ts +1 -1
- package/dist/src/driver/bundler/merge.js +37 -55
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/namespace-import.d.ts +7 -0
- package/dist/src/driver/bundler/namespace-import.js +46 -0
- package/dist/src/driver/bundler/namespace-import.js.map +1 -0
- package/dist/src/driver/bundler/reexport-fixup.d.ts +14 -0
- package/dist/src/driver/bundler/reexport-fixup.js +92 -0
- package/dist/src/driver/bundler/reexport-fixup.js.map +1 -0
- package/dist/src/driver/bundler/resolve.d.ts +6 -5
- package/dist/src/driver/bundler/resolve.js +52 -6
- package/dist/src/driver/bundler/resolve.js.map +1 -1
- package/dist/src/driver/bundler/symbols.d.ts +4 -0
- package/dist/src/driver/bundler/symbols.js +12 -0
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/bundler/types.d.ts +1 -0
- package/dist/src/driver/compiler.js +12 -1
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +14 -0
- package/dist/src/driver/config.js +40 -0
- package/dist/src/driver/config.js.map +1 -1
- package/dist/src/driver/frontend.d.ts +3 -1
- package/dist/src/driver/frontend.js +5 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/index.d.ts +2 -1
- package/dist/src/driver/index.js +1 -0
- package/dist/src/driver/index.js.map +1 -1
- package/dist/src/driver/options.d.ts +13 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +2 -0
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/storage.d.ts +34 -0
- package/dist/src/driver/storage.js +67 -0
- package/dist/src/driver/storage.js.map +1 -0
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/gui/features.d.ts +1 -1
- package/dist/src/extensions/gui/features.js +2 -2
- package/dist/src/extensions/gui/features.js.map +1 -1
- package/dist/src/extensions/gui/index.js +3 -1
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/node/async-hooks/index.d.ts +6 -0
- package/dist/src/extensions/node/async-hooks/index.js +19 -0
- package/dist/src/extensions/node/async-hooks/index.js.map +1 -0
- package/dist/src/extensions/node/buffer/index.js +2 -0
- package/dist/src/extensions/node/buffer/index.js.map +1 -1
- package/dist/src/extensions/node/child_process/index.js +10 -1
- package/dist/src/extensions/node/child_process/index.js.map +1 -1
- package/dist/src/extensions/node/console/index.d.ts +6 -0
- package/dist/src/extensions/node/console/index.js +34 -0
- package/dist/src/extensions/node/console/index.js.map +1 -0
- package/dist/src/extensions/node/constants/index.d.ts +6 -0
- package/dist/src/extensions/node/constants/index.js +27 -0
- package/dist/src/extensions/node/constants/index.js.map +1 -0
- package/dist/src/extensions/node/diagnostics-channel/index.d.ts +5 -0
- package/dist/src/extensions/node/diagnostics-channel/index.js +16 -0
- package/dist/src/extensions/node/diagnostics-channel/index.js.map +1 -0
- package/dist/src/extensions/node/dns/index.d.ts +5 -0
- package/dist/src/extensions/node/dns/index.js +14 -0
- package/dist/src/extensions/node/dns/index.js.map +1 -0
- package/dist/src/extensions/node/events/index.js +1 -0
- package/dist/src/extensions/node/events/index.js.map +1 -1
- package/dist/src/extensions/node/http/index.js +5 -1
- package/dist/src/extensions/node/http/index.js.map +1 -1
- package/dist/src/extensions/node/http2/index.d.ts +5 -0
- package/dist/src/extensions/node/http2/index.js +16 -0
- package/dist/src/extensions/node/http2/index.js.map +1 -0
- package/dist/src/extensions/node/index.js +36 -0
- package/dist/src/extensions/node/index.js.map +1 -1
- package/dist/src/extensions/node/module/index.d.ts +5 -0
- package/dist/src/extensions/node/module/index.js +15 -0
- package/dist/src/extensions/node/module/index.js.map +1 -0
- package/dist/src/extensions/node/os/index.js +4 -1
- package/dist/src/extensions/node/os/index.js.map +1 -1
- package/dist/src/extensions/node/path/index.js +9 -1
- package/dist/src/extensions/node/path/index.js.map +1 -1
- package/dist/src/extensions/node/perf_hooks/index.d.ts +6 -0
- package/dist/src/extensions/node/perf_hooks/index.js +15 -0
- package/dist/src/extensions/node/perf_hooks/index.js.map +1 -0
- package/dist/src/extensions/node/readline-promises/index.d.ts +5 -0
- package/dist/src/extensions/node/readline-promises/index.js +14 -0
- package/dist/src/extensions/node/readline-promises/index.js.map +1 -0
- package/dist/src/extensions/node/sqlite/index.d.ts +6 -0
- package/dist/src/extensions/node/sqlite/index.js +16 -0
- package/dist/src/extensions/node/sqlite/index.js.map +1 -0
- package/dist/src/extensions/node/stream/index.js +2 -0
- package/dist/src/extensions/node/stream/index.js.map +1 -1
- package/dist/src/extensions/node/stream-web/index.d.ts +5 -0
- package/dist/src/extensions/node/stream-web/index.js +17 -0
- package/dist/src/extensions/node/stream-web/index.js.map +1 -0
- package/dist/src/extensions/node/string-decoder/index.d.ts +5 -0
- package/dist/src/extensions/node/string-decoder/index.js +14 -0
- package/dist/src/extensions/node/string-decoder/index.js.map +1 -0
- package/dist/src/extensions/node/timers/index.d.ts +6 -0
- package/dist/src/extensions/node/timers/index.js +20 -0
- package/dist/src/extensions/node/timers/index.js.map +1 -0
- package/dist/src/extensions/node/timers-promises/index.d.ts +5 -0
- package/dist/src/extensions/node/timers-promises/index.js +15 -0
- package/dist/src/extensions/node/timers-promises/index.js.map +1 -0
- package/dist/src/extensions/node/tls/index.d.ts +5 -0
- package/dist/src/extensions/node/tls/index.js +16 -0
- package/dist/src/extensions/node/tls/index.js.map +1 -0
- package/dist/src/extensions/node/tty/index.d.ts +5 -0
- package/dist/src/extensions/node/tty/index.js +14 -0
- package/dist/src/extensions/node/tty/index.js.map +1 -0
- package/dist/src/extensions/node/url/index.js +1 -0
- package/dist/src/extensions/node/url/index.js.map +1 -1
- package/dist/src/extensions/node/util/index.js +15 -1
- package/dist/src/extensions/node/util/index.js.map +1 -1
- package/dist/src/extensions/node/util-types/index.d.ts +6 -0
- package/dist/src/extensions/node/util-types/index.js +26 -0
- package/dist/src/extensions/node/util-types/index.js.map +1 -0
- package/dist/src/extensions/node/worker_threads/index.js +1 -0
- package/dist/src/extensions/node/worker_threads/index.js.map +1 -1
- package/dist/src/extensions/node/zlib/compression.d.ts +10 -0
- package/dist/src/extensions/node/zlib/compression.js +44 -0
- package/dist/src/extensions/node/zlib/compression.js.map +1 -0
- package/dist/src/extensions/node/zlib/index.d.ts +5 -2
- package/dist/src/extensions/node/zlib/index.js +21 -2
- package/dist/src/extensions/node/zlib/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +4 -1
- package/dist/src/extensions/registry.js +8 -2
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/extensions/storage.d.ts +22 -0
- package/dist/src/extensions/storage.js +50 -0
- package/dist/src/extensions/storage.js.map +1 -0
- package/dist/src/lexer/scanner/punctuation.js +8 -2
- package/dist/src/lexer/scanner/punctuation.js.map +1 -1
- package/dist/src/lexer/scanner/regex.d.ts +3 -1
- package/dist/src/lexer/scanner/regex.js +32 -22
- package/dist/src/lexer/scanner/regex.js.map +1 -1
- package/dist/src/lexer/scanner.d.ts +2 -0
- package/dist/src/lexer/scanner.js +8 -0
- package/dist/src/lexer/scanner.js.map +1 -1
- package/dist/src/lexer/token.d.ts +1 -0
- package/dist/src/lexer/token.js +2 -0
- package/dist/src/lexer/token.js.map +1 -1
- package/dist/src/parser/declarations/classes.js +7 -0
- package/dist/src/parser/declarations/classes.js.map +1 -1
- package/dist/src/parser/declarations/functions.js +8 -2
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/expressions.d.ts +2 -2
- package/dist/src/parser/expressions.js +32 -17
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.js +1 -0
- package/dist/src/parser/helpers.js.map +1 -1
- package/dist/src/parser/literals.js +27 -0
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/src/parser/statements.js +3 -0
- package/dist/src/parser/statements.js.map +1 -1
- package/dist/src/parser/types.js +106 -45
- package/dist/src/parser/types.js.map +1 -1
- package/dist/tests/binder/binder.test.js +8 -1
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +63 -0
- package/dist/tests/checker/checker.test.js.map +1 -1
- package/dist/tests/codegen/expressions.test.js +8 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/conformance/test262/manifest.js +9 -10
- package/dist/tests/conformance/test262/manifest.js.map +1 -1
- package/dist/tests/driver/bundler-resolve.test.js +22 -0
- package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
- package/dist/tests/driver/config.test.js +46 -0
- package/dist/tests/driver/config.test.js.map +1 -1
- package/dist/tests/driver/deferred-reexport.test.d.ts +9 -0
- package/dist/tests/driver/deferred-reexport.test.js +62 -0
- package/dist/tests/driver/deferred-reexport.test.js.map +1 -0
- package/dist/tests/driver/link-features.test.js +4 -2
- package/dist/tests/driver/link-features.test.js.map +1 -1
- package/dist/tests/driver/modules.test.js +110 -11
- package/dist/tests/driver/modules.test.js.map +1 -1
- package/dist/tests/driver/storage.test.d.ts +1 -0
- package/dist/tests/driver/storage.test.js +29 -0
- package/dist/tests/driver/storage.test.js.map +1 -0
- package/dist/tests/e2e/compile-basics.test.js +11 -0
- package/dist/tests/e2e/compile-basics.test.js.map +1 -1
- 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.test.js +49 -0
- package/dist/tests/e2e/compile-node.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js +32 -0
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/node-modules.test.js +174 -0
- package/dist/tests/e2e/node-modules.test.js.map +1 -1
- package/dist/tests/e2e/npm-modules.test.js +8 -0
- package/dist/tests/e2e/npm-modules.test.js.map +1 -1
- package/dist/tests/e2e/storage.test.d.ts +7 -0
- package/dist/tests/e2e/storage.test.js +86 -0
- package/dist/tests/e2e/storage.test.js.map +1 -0
- package/dist/tests/e2e/weak-collections.test.js +12 -0
- package/dist/tests/e2e/weak-collections.test.js.map +1 -1
- package/dist/tests/extensions/gui-features.test.js +1 -1
- package/dist/tests/extensions/gui-features.test.js.map +1 -1
- package/dist/tests/extensions/storage.test.d.ts +1 -0
- package/dist/tests/extensions/storage.test.js +50 -0
- package/dist/tests/extensions/storage.test.js.map +1 -0
- package/dist/tests/lexer/scanner.test.js +17 -0
- package/dist/tests/lexer/scanner.test.js.map +1 -1
- package/dist/tests/parser/declarations.test.js +24 -0
- package/dist/tests/parser/declarations.test.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +34 -7
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/dist/tests/parser/literals.test.js +15 -0
- package/dist/tests/parser/literals.test.js.map +1 -1
- package/dist/tests/parser/types.test.js +26 -0
- package/dist/tests/parser/types.test.js.map +1 -1
- package/doc/ai/cli.md +2 -0
- package/doc/ai/extensions.md +26 -0
- package/doc/ai/language-support.md +4 -2
- package/doc/ai/zh-CN/cli.md +2 -0
- package/doc/ai/zh-CN/extensions.md +23 -0
- package/doc/ai/zh-CN/language-support.md +4 -2
- package/doc/gui/build.md +3 -3
- package/doc/gui/media.md +4 -4
- package/doc/gui.md +2 -2
- package/doc/implemented/extensions.md +1 -1
- package/doc/implemented/node/buffer.md +2 -0
- package/doc/implemented/node/child-process.md +29 -6
- package/doc/implemented/node/http.md +2 -0
- package/doc/implemented/node/os.md +1 -0
- package/doc/implemented/node/path.md +3 -0
- package/doc/implemented/node/stream.md +3 -0
- package/doc/implemented/node/util.md +1 -0
- package/doc/implemented/node/zlib.md +12 -1
- package/doc/implemented/node.md +8 -1
- package/doc/implemented/storage.md +64 -0
- package/doc/implemented/wasm.md +22 -0
- package/doc/implemented.md +3 -0
- package/doc/support-matrix.md +3 -3
- package/doc/unimplemented/node/modules.md +4 -3
- package/doc/unimplemented/stdlib.md +1 -0
- package/doc/unimplemented/wasm.md +15 -0
- package/doc/unimplemented.md +1 -0
- package/doc/xbintsc.config.schema.json +16 -1
- package/doc/zh-CN/gui/build.md +3 -3
- package/doc/zh-CN/gui/media.md +3 -3
- package/doc/zh-CN/gui.md +2 -2
- package/doc/zh-CN/implemented/extensions.md +1 -1
- package/doc/zh-CN/implemented/node/child-process.md +27 -5
- package/doc/zh-CN/implemented/node.md +1 -1
- package/doc/zh-CN/implemented/storage.md +51 -0
- package/doc/zh-CN/implemented/wasm.md +20 -0
- package/doc/zh-CN/implemented.md +3 -0
- package/doc/zh-CN/support-matrix.md +3 -3
- package/doc/zh-CN/unimplemented/node/modules.md +3 -2
- package/doc/zh-CN/unimplemented/stdlib.md +1 -0
- package/doc/zh-CN/unimplemented/wasm.md +14 -0
- package/doc/zh-CN/unimplemented.md +1 -0
- package/package.json +7 -7
- package/runtime/ext_gui/dom_api_form.cpp +10 -0
- package/runtime/ext_gui/gui_media.cpp +1 -1
- package/runtime/ext_gui/media.cpp +1 -1
- package/runtime/ext_gui/media_api.h +2 -2
- package/runtime/ext_node/async_hooks/async_hooks.c +59 -0
- package/runtime/ext_node/buffer/parts/static-api.inc +39 -0
- package/runtime/ext_node/child_process/spawn.c +201 -0
- package/runtime/ext_node/child_process/spawn.h +56 -0
- package/runtime/ext_node/child_process/spawn_posix.c +206 -0
- package/runtime/ext_node/child_process/spawn_win.c +276 -0
- package/runtime/ext_node/console/console.c +67 -0
- package/runtime/ext_node/constants/constants.c +72 -0
- package/runtime/ext_node/diagnostics_channel/diagnostics_channel.c +61 -0
- package/runtime/ext_node/dns/dns.c +77 -0
- package/runtime/ext_node/events/events.c +7 -0
- package/runtime/ext_node/http/http.c +38 -0
- package/runtime/ext_node/http2/http2.c +26 -0
- package/runtime/ext_node/module/module.c +31 -0
- package/runtime/ext_node/os/os.c +42 -0
- package/runtime/ext_node/path/path.c +93 -0
- package/runtime/ext_node/perf_hooks/perf_hooks.c +22 -0
- package/runtime/ext_node/readline_promises/readline_promises.c +59 -0
- package/runtime/ext_node/sqlite/sqlite.c +24 -0
- package/runtime/ext_node/stream/stream.c +19 -1
- package/runtime/ext_node/stream_web/stream_web.c +22 -0
- package/runtime/ext_node/string_decoder/string_decoder.c +31 -0
- package/runtime/ext_node/timers_promises/timers_promises.c +58 -0
- package/runtime/ext_node/tls/tls.c +26 -0
- package/runtime/ext_node/tty/tty.c +18 -0
- package/runtime/ext_node/util/util.c +84 -0
- package/runtime/ext_node/worker_threads/worker_threads.c +8 -0
- package/runtime/ext_node/zlib/miniz/compression_bridge.c +43 -0
- package/runtime/ext_node/zlib/miniz/miniz.c +646 -0
- package/runtime/ext_node/zlib/miniz/miniz.h +615 -0
- package/runtime/ext_node/zlib/miniz/miniz_common.h +89 -0
- package/runtime/ext_node/zlib/miniz/miniz_export.h +4 -0
- package/runtime/ext_node/zlib/miniz/miniz_tdef.c +1653 -0
- package/runtime/ext_node/zlib/miniz/miniz_tdef.h +206 -0
- package/runtime/ext_node/zlib/miniz/miniz_tinfl.c +778 -0
- package/runtime/ext_node/zlib/miniz/miniz_tinfl.h +150 -0
- package/runtime/ext_node/zlib/miniz/miniz_zip.h +454 -0
- package/runtime/ext_node/zlib/zlib.c +194 -0
- package/runtime/xt_builtins.c +1 -0
- package/runtime/xt_constructors.c +5 -0
- package/runtime/xt_module_values.c +29 -0
- package/runtime/xt_storage/indexed_db.c +408 -0
- package/runtime/xt_storage/indexed_db_internal.h +26 -0
- package/runtime/xt_storage/indexed_db_store.c +305 -0
- package/runtime/xt_storage/sqlite3/sqlite3.c +271131 -0
- package/runtime/xt_storage/sqlite3/sqlite3.h +14447 -0
- package/runtime/xt_storage/storage.c +209 -0
- package/runtime/xt_storage/storage_internal.h +66 -0
- package/runtime/xt_weak.c +43 -0
- package/runtime/xt_webassembly.c +53 -0
- package/scripts/build-gui.ts +1 -1
- package/scripts/build-media.ts +2 -2
- package/scripts/check-file-length.ts +14 -0
- package/src/ast/common.ts +2 -0
- package/src/ast/declarations.ts +2 -0
- package/src/ast/expressions.ts +6 -0
- package/src/ast/kinds.ts +2 -0
- package/src/ast/types.ts +2 -0
- package/src/binder/binder.ts +13 -0
- package/src/binder/references.ts +9 -2
- package/src/checker/assignability.ts +12 -2
- package/src/checker/calls.ts +3 -0
- package/src/checker/flow.ts +13 -9
- package/src/checker/globals.ts +3 -0
- package/src/checker/type-system.ts +1 -0
- package/src/checker/typecheck.ts +8 -1
- package/src/cli/main.ts +4 -0
- package/src/codegen/generator/calls/access.ts +4 -1
- package/src/codegen/generator/calls/invocation.ts +8 -4
- package/src/codegen/generator/context.ts +5 -3
- package/src/codegen/generator/expressions/assignment.ts +1 -0
- package/src/codegen/generator/expressions/module-values.ts +105 -0
- package/src/codegen/generator/expressions/primary.ts +35 -5
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/module.ts +16 -5
- package/src/codegen/generator/state.ts +6 -0
- package/src/codegen/generator/statements/dispatch.ts +9 -0
- package/src/codegen/generator/tables.ts +27 -0
- package/src/driver/build-key.ts +6 -1
- package/src/driver/bundler/commonjs.ts +18 -5
- package/src/driver/bundler/deferred.ts +2 -1
- package/src/driver/bundler/dynamic-import.ts +135 -0
- package/src/driver/bundler/graph.ts +34 -19
- package/src/driver/bundler/merge.ts +38 -64
- package/src/driver/bundler/namespace-import.ts +59 -0
- package/src/driver/bundler/reexport-fixup.ts +102 -0
- package/src/driver/bundler/resolve.ts +49 -5
- package/src/driver/bundler/symbols.ts +13 -0
- package/src/driver/bundler/types.ts +1 -0
- package/src/driver/compiler.ts +14 -1
- package/src/driver/config.ts +55 -0
- package/src/driver/frontend.ts +13 -8
- package/src/driver/index.ts +8 -0
- package/src/driver/options.ts +13 -1
- package/src/driver/runtime-objects.ts +2 -0
- package/src/driver/storage.ts +84 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/features.ts +2 -2
- package/src/extensions/gui/index.ts +3 -1
- package/src/extensions/node/async-hooks/index.ts +23 -0
- package/src/extensions/node/buffer/index.ts +2 -0
- package/src/extensions/node/child_process/index.ts +13 -1
- package/src/extensions/node/console/index.ts +44 -0
- package/src/extensions/node/constants/index.ts +34 -0
- package/src/extensions/node/diagnostics-channel/index.ts +20 -0
- package/src/extensions/node/dns/index.ts +18 -0
- package/src/extensions/node/events/index.ts +1 -0
- package/src/extensions/node/http/index.ts +5 -3
- package/src/extensions/node/http2/index.ts +20 -0
- package/src/extensions/node/index.ts +36 -0
- package/src/extensions/node/module/index.ts +19 -0
- package/src/extensions/node/os/index.ts +4 -3
- package/src/extensions/node/path/index.ts +9 -3
- package/src/extensions/node/perf_hooks/index.ts +19 -0
- package/src/extensions/node/readline-promises/index.ts +18 -0
- package/src/extensions/node/sqlite/index.ts +20 -0
- package/src/extensions/node/stream/index.ts +3 -0
- package/src/extensions/node/stream-web/index.ts +21 -0
- package/src/extensions/node/string-decoder/index.ts +18 -0
- package/src/extensions/node/timers/index.ts +27 -0
- package/src/extensions/node/timers-promises/index.ts +19 -0
- package/src/extensions/node/tls/index.ts +20 -0
- package/src/extensions/node/tty/index.ts +18 -0
- package/src/extensions/node/url/index.ts +1 -0
- package/src/extensions/node/util/index.ts +15 -3
- package/src/extensions/node/util-types/index.ts +33 -0
- package/src/extensions/node/worker_threads/index.ts +1 -0
- package/src/extensions/node/zlib/compression.ts +48 -0
- package/src/extensions/node/zlib/index.ts +23 -2
- package/src/extensions/registry.ts +8 -2
- package/src/extensions/storage.ts +57 -0
- package/src/lexer/scanner/punctuation.ts +7 -1
- package/src/lexer/scanner/regex.ts +31 -22
- package/src/lexer/scanner.ts +7 -0
- package/src/lexer/token.ts +2 -0
- package/src/parser/declarations/classes.ts +7 -0
- package/src/parser/declarations/functions.ts +9 -3
- package/src/parser/expressions.ts +29 -20
- package/src/parser/helpers.ts +1 -0
- package/src/parser/literals.ts +28 -0
- package/src/parser/statements.ts +3 -0
- package/src/parser/types.ts +106 -43
- /package/runtime/{ext_media → xt_media}/decode_audio.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media.cpp +0 -0
- /package/runtime/{ext_media → xt_media}/media_bridge.c +0 -0
|
@@ -16,7 +16,7 @@ const RESOLVE_SUFFIXES = ["", ".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mj
|
|
|
16
16
|
/** File extensions a directory `index` entry may use. */
|
|
17
17
|
const INDEX_SUFFIXES = [".ts", ".tsx", ".mts", ".cts", ".js", ".jsx", ".mjs", ".cjs"];
|
|
18
18
|
/** Conditions consulted, in order, when reading a package `exports` map. */
|
|
19
|
-
const EXPORT_CONDITIONS = ["import", "module", "
|
|
19
|
+
const EXPORT_CONDITIONS = ["import", "module", "node", "require", "default"];
|
|
20
20
|
|
|
21
21
|
/** A specifier is a file path (`./x`, `../x`, `/x`) rather than a package. */
|
|
22
22
|
function isRelativeSpecifier(specifier: string): boolean {
|
|
@@ -155,6 +155,40 @@ function resolvePackageSubpath(packageDir: string, subpath: string): string | un
|
|
|
155
155
|
return resolvePath(join(packageDir, subpath));
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
/** Resolve a package-internal `#name` import through the package `imports` map. */
|
|
159
|
+
function resolvePackageImport(fromDir: string, specifier: string): string | undefined {
|
|
160
|
+
let directory = fromDir;
|
|
161
|
+
for (;;) {
|
|
162
|
+
const pkg = readPackageJson(directory);
|
|
163
|
+
const target = importsValue(pkg?.imports, specifier);
|
|
164
|
+
if (target) {
|
|
165
|
+
const resolved = resolvePath(resolve(directory, target));
|
|
166
|
+
if (resolved) return resolved;
|
|
167
|
+
}
|
|
168
|
+
const parent = dirname(directory);
|
|
169
|
+
if (parent === directory) return undefined;
|
|
170
|
+
directory = parent;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** Pick the target for a `#name` specifier from a package `imports` map. */
|
|
175
|
+
function importsValue(importsField: unknown, specifier: string): string | undefined {
|
|
176
|
+
if (!importsField || typeof importsField !== "object") return undefined;
|
|
177
|
+
const record = importsField as Record<string, unknown>;
|
|
178
|
+
if (specifier in record) return resolveExportTarget(record[specifier]);
|
|
179
|
+
for (const key of Object.keys(record)) {
|
|
180
|
+
const star = key.indexOf("*");
|
|
181
|
+
if (star === -1) continue;
|
|
182
|
+
const prefix = key.slice(0, star);
|
|
183
|
+
const suffix = key.slice(star + 1);
|
|
184
|
+
if (specifier.startsWith(prefix) && specifier.endsWith(suffix)) {
|
|
185
|
+
const matched = specifier.slice(prefix.length, specifier.length - suffix.length);
|
|
186
|
+
return resolveExportTarget(substituteStar(record[key], matched));
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
158
192
|
/** Pick the export target for a subpath (`"."` or `"./sub"`) from an exports map. */
|
|
159
193
|
function subpathValue(exportsField: unknown, subpath: string): unknown {
|
|
160
194
|
if (exportsField === undefined) return undefined;
|
|
@@ -217,19 +251,29 @@ function resolveExportTarget(target: unknown): string | undefined {
|
|
|
217
251
|
}
|
|
218
252
|
|
|
219
253
|
/**
|
|
220
|
-
* Classify an import specifier.
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
254
|
+
* Classify an import specifier. A module override (a bare specifier mapped to a
|
|
255
|
+
* local replacement file) wins over node_modules resolution; known platform
|
|
256
|
+
* modules (extension modules and `node:` builtins) are left for code
|
|
257
|
+
* generation; relative paths and `node_modules` packages are resolved to a
|
|
258
|
+
* source file to bundle; a relative path that does not exist is an error.
|
|
224
259
|
*/
|
|
225
260
|
export function classifyDependency(
|
|
226
261
|
fromDir: string,
|
|
227
262
|
specifier: string,
|
|
228
263
|
externalSpecifiers: ReadonlySet<string>,
|
|
264
|
+
moduleOverrides?: Readonly<Record<string, string>>,
|
|
229
265
|
): DependencyResolution {
|
|
266
|
+
const override = moduleOverrides?.[specifier];
|
|
267
|
+
if (override !== undefined) {
|
|
268
|
+
return { kind: "file", path: override };
|
|
269
|
+
}
|
|
230
270
|
if (specifier.startsWith("node:") || externalSpecifiers.has(specifier)) {
|
|
231
271
|
return { kind: "external" };
|
|
232
272
|
}
|
|
273
|
+
if (specifier.startsWith("#")) {
|
|
274
|
+
const resolved = resolvePackageImport(fromDir, specifier);
|
|
275
|
+
return resolved ? { kind: "file", path: resolved } : { kind: "missing" };
|
|
276
|
+
}
|
|
233
277
|
const resolved = isRelativeSpecifier(specifier)
|
|
234
278
|
? resolveModule(fromDir, specifier)
|
|
235
279
|
: resolveNodePackage(fromDir, specifier);
|
|
@@ -50,6 +50,19 @@ export function renameReferences(symbol: SymbolInfo, finalName: string): void {
|
|
|
50
50
|
for (const reference of symbol.references) (reference as { text: string }).text = finalName;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/** `export { foo }` where `foo` is imported: point the export at the renamed target. */
|
|
54
|
+
export function remapExports(record: ModuleRecord, fromName: string, toName: string): void {
|
|
55
|
+
for (const [name, value] of record.exports) {
|
|
56
|
+
if (value === fromName) record.exports.set(name, toName);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Rename an imported binding and fix any `export { foo }` that re-exports it. */
|
|
61
|
+
export function renameImport(record: ModuleRecord, symbol: SymbolInfo, target: string): void {
|
|
62
|
+
renameReferences(symbol, target);
|
|
63
|
+
remapExports(record, symbol.name, target);
|
|
64
|
+
}
|
|
65
|
+
|
|
53
66
|
export function moduleScope(record: ModuleRecord) {
|
|
54
67
|
return record.bind.scopes.get(record.sourceFile);
|
|
55
68
|
}
|
package/src/driver/compiler.ts
CHANGED
|
@@ -21,6 +21,7 @@ import { BuildCache } from "./cache.js";
|
|
|
21
21
|
import { findRuntimeDir, platformSlug } from "./paths.js";
|
|
22
22
|
import { resolveToolchain, type ResolvedToolchain } from "./toolchain-provider.js";
|
|
23
23
|
import { readIcon, IconError, type IconInfo } from "./icon.js";
|
|
24
|
+
import { ensureStorageObject, resolveStorage } from "./storage.js";
|
|
24
25
|
import { bundlePathFor, packageMacApp } from "./mac-bundle.js";
|
|
25
26
|
import type { AppConfig } from "./config.js";
|
|
26
27
|
import { compileIr, link, mergeProfileData, realRunner, ToolchainError } from "./toolchain.js";
|
|
@@ -127,7 +128,7 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
127
128
|
|
|
128
129
|
// -- front end -----------------------------------------------------------
|
|
129
130
|
const diagnostics = new DiagnosticBag();
|
|
130
|
-
const parsed = parseEntry(absoluteEntry, registry, diagnostics);
|
|
131
|
+
const parsed = parseEntry(absoluteEntry, registry, diagnostics, options.moduleOverrides);
|
|
131
132
|
timings.push({ phase: "frontend", ms: Date.now() - buildStarted });
|
|
132
133
|
|
|
133
134
|
/* Parse (or module-graph) errors leave missing nodes in the tree. Stop before
|
|
@@ -178,6 +179,8 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
|
|
182
|
+
const storage = resolveStorage(options.storage);
|
|
183
|
+
|
|
181
184
|
const runtimeDir = findRuntimeDir();
|
|
182
185
|
const cacheKey = buildCacheKey({
|
|
183
186
|
sourceText: parsed.cacheText,
|
|
@@ -187,6 +190,7 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
187
190
|
runtimeDir,
|
|
188
191
|
icon,
|
|
189
192
|
app,
|
|
193
|
+
storage,
|
|
190
194
|
debug: options.debug === true,
|
|
191
195
|
lto,
|
|
192
196
|
check: options.check !== false,
|
|
@@ -332,6 +336,14 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
332
336
|
return { outputPath, irPath, cached: false, diagnostics: diagnostics.diagnostics, ir };
|
|
333
337
|
}
|
|
334
338
|
|
|
339
|
+
/* The storage extension reads its backend/path from an embedded object, the
|
|
340
|
+
* same way the GUI reads the icon. Only linked when the storage link feature
|
|
341
|
+
* is active (the program actually reaches a storage global). */
|
|
342
|
+
const storageObjects: string[] = [];
|
|
343
|
+
if (linkFeatures.some((feature) => feature.name === "storage")) {
|
|
344
|
+
storageObjects.push(ensureStorageObject(runner, clang, cacheDir, storage, toolchain.env, toolchain.sdkRoot));
|
|
345
|
+
}
|
|
346
|
+
|
|
335
347
|
const linkAssembled = (runtimeObjects: RuntimeObjects): string => {
|
|
336
348
|
const started = Date.now();
|
|
337
349
|
const result = link(runner, {
|
|
@@ -349,6 +361,7 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
349
361
|
...runtimeObjects.nativeObjects,
|
|
350
362
|
...(artifacts.entryObject !== undefined ? [artifacts.entryObject] : []),
|
|
351
363
|
...artifacts.iconObjects,
|
|
364
|
+
...storageObjects,
|
|
352
365
|
]),
|
|
353
366
|
],
|
|
354
367
|
outputPath,
|
package/src/driver/config.ts
CHANGED
|
@@ -33,6 +33,17 @@ export interface AppConfig {
|
|
|
33
33
|
readonly console?: boolean;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
/**
|
|
37
|
+
* Persistent-storage backend for the `storage` extension (localStorage,
|
|
38
|
+
* sessionStorage, indexedDB). `backend` defaults to `memory`; `file` also needs
|
|
39
|
+
* `path`, which is resolved against the config file's directory (absolute paths
|
|
40
|
+
* are used as-is).
|
|
41
|
+
*/
|
|
42
|
+
export interface StorageConfig {
|
|
43
|
+
readonly backend?: "memory" | "file";
|
|
44
|
+
readonly path?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
36
47
|
/** The on-disk schema of `xbintsc.config.json`. Every field is optional. */
|
|
37
48
|
export interface ProjectConfig {
|
|
38
49
|
readonly entry?: string;
|
|
@@ -48,8 +59,12 @@ export interface ProjectConfig {
|
|
|
48
59
|
readonly features?: readonly string[];
|
|
49
60
|
/** Optional link features to keep out even when auto-detection finds a use. */
|
|
50
61
|
readonly noFeatures?: readonly string[];
|
|
62
|
+
/** Bare module specifiers mapped to local replacement files. */
|
|
63
|
+
readonly moduleOverrides?: Readonly<Record<string, string>>;
|
|
51
64
|
readonly force?: boolean;
|
|
52
65
|
readonly app?: AppConfig;
|
|
66
|
+
/** Storage backend for the `storage` extension (default: memory). */
|
|
67
|
+
readonly storage?: StorageConfig;
|
|
53
68
|
}
|
|
54
69
|
|
|
55
70
|
export class ProjectConfigError extends Error {
|
|
@@ -96,6 +111,20 @@ function readStringArray(root: Record<string, unknown>, key: string, where: stri
|
|
|
96
111
|
return value as string[];
|
|
97
112
|
}
|
|
98
113
|
|
|
114
|
+
function readStringMap(root: Record<string, unknown>, key: string, where: string): Record<string, string> | undefined {
|
|
115
|
+
const value = root[key];
|
|
116
|
+
if (value === undefined) return undefined;
|
|
117
|
+
const record = expectObject(value, `${where}: '${key}'`);
|
|
118
|
+
const map: Record<string, string> = {};
|
|
119
|
+
for (const [specifier, target] of Object.entries(record)) {
|
|
120
|
+
if (typeof target !== "string") {
|
|
121
|
+
throw new ProjectConfigError(`${where}: '${key}' values must be strings`);
|
|
122
|
+
}
|
|
123
|
+
map[specifier] = target;
|
|
124
|
+
}
|
|
125
|
+
return map;
|
|
126
|
+
}
|
|
127
|
+
|
|
99
128
|
/** Parse and validate config text. Throws {@link ProjectConfigError}. */
|
|
100
129
|
export function parseProjectConfig(text: string, where: string = CONFIG_FILE_NAME): ProjectConfig {
|
|
101
130
|
let raw: unknown;
|
|
@@ -130,6 +159,23 @@ export function parseProjectConfig(text: string, where: string = CONFIG_FILE_NAM
|
|
|
130
159
|
}
|
|
131
160
|
}
|
|
132
161
|
|
|
162
|
+
let storage: StorageConfig | undefined;
|
|
163
|
+
if (root.storage !== undefined) {
|
|
164
|
+
const storageRoot = expectObject(root.storage, `${where}: 'storage'`);
|
|
165
|
+
const backend = readString(storageRoot, "backend", `${where}: 'storage'`);
|
|
166
|
+
if (backend !== undefined && backend !== "memory" && backend !== "file") {
|
|
167
|
+
throw new ProjectConfigError(`${where}: 'storage.backend' must be "memory" or "file"`);
|
|
168
|
+
}
|
|
169
|
+
const path = readString(storageRoot, "path", `${where}: 'storage'`);
|
|
170
|
+
if (backend === "file" && (path === undefined || path === "")) {
|
|
171
|
+
throw new ProjectConfigError(`${where}: 'storage.path' is required when 'storage.backend' is "file"`);
|
|
172
|
+
}
|
|
173
|
+
storage = { backend: backend as StorageConfig["backend"], path };
|
|
174
|
+
for (const key of Object.keys(storage) as (keyof StorageConfig)[]) {
|
|
175
|
+
if (storage[key] === undefined) delete storage[key];
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
133
179
|
const config: ProjectConfig = {
|
|
134
180
|
entry: readString(root, "entry", where),
|
|
135
181
|
outDir: readString(root, "outDir", where),
|
|
@@ -142,8 +188,10 @@ export function parseProjectConfig(text: string, where: string = CONFIG_FILE_NAM
|
|
|
142
188
|
extNative: readStringArray(root, "extNative", where),
|
|
143
189
|
features: readStringArray(root, "features", where),
|
|
144
190
|
noFeatures: readStringArray(root, "noFeatures", where),
|
|
191
|
+
moduleOverrides: readStringMap(root, "moduleOverrides", where),
|
|
145
192
|
force: readBoolean(root, "force", where),
|
|
146
193
|
app,
|
|
194
|
+
storage,
|
|
147
195
|
};
|
|
148
196
|
for (const key of Object.keys(config) as (keyof ProjectConfig)[]) {
|
|
149
197
|
if (config[key] === undefined) delete config[key];
|
|
@@ -186,6 +234,9 @@ export function resolveConfigPaths(loaded: LoadedProjectConfig): ProjectConfig {
|
|
|
186
234
|
const app: AppConfig | undefined = config.app
|
|
187
235
|
? { ...config.app, ...(config.app.icon ? { icon: resolvePath(directory, config.app.icon) } : {}) }
|
|
188
236
|
: undefined;
|
|
237
|
+
const storage: StorageConfig | undefined = config.storage
|
|
238
|
+
? { ...config.storage, ...(config.storage.path ? { path: resolvePath(directory, config.storage.path) } : {}) }
|
|
239
|
+
: undefined;
|
|
189
240
|
return {
|
|
190
241
|
...config,
|
|
191
242
|
...(config.entry ? { entry: resolvePath(directory, config.entry) } : {}),
|
|
@@ -193,6 +244,10 @@ export function resolveConfigPaths(loaded: LoadedProjectConfig): ProjectConfig {
|
|
|
193
244
|
...(config.output ? { output: resolvePath(directory, config.output) } : {}),
|
|
194
245
|
...(config.pgoDir ? { pgoDir: resolvePath(directory, config.pgoDir) } : {}),
|
|
195
246
|
...(config.extNative ? { extNative: config.extNative.map((path) => resolvePath(directory, path)) } : {}),
|
|
247
|
+
...(config.moduleOverrides
|
|
248
|
+
? { moduleOverrides: Object.fromEntries(Object.entries(config.moduleOverrides).map(([k, v]) => [k, resolvePath(directory, v)])) }
|
|
249
|
+
: {}),
|
|
196
250
|
...(app ? { app } : {}),
|
|
251
|
+
...(storage ? { storage } : {}),
|
|
197
252
|
};
|
|
198
253
|
}
|
package/src/driver/frontend.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { Parser } from "../parser/parser.js";
|
|
|
16
16
|
import { generate } from "../codegen/llvm.js";
|
|
17
17
|
import { SyntaxKind, type SourceFileNode } from "../ast/nodes.js";
|
|
18
18
|
import { bundleModules } from "./modules.js";
|
|
19
|
+
import { collectDynamicImportSites } from "./bundler/dynamic-import.js";
|
|
19
20
|
import { createDefaultRegistry, type ExtensionRegistry } from "../extensions/registry.js";
|
|
20
21
|
import type { CompileStringResult } from "./options.js";
|
|
21
22
|
|
|
@@ -37,6 +38,8 @@ export interface FrontendOptions {
|
|
|
37
38
|
readonly debug?: boolean;
|
|
38
39
|
/** Run the semantic checker (default true; `--no-check` disables it). */
|
|
39
40
|
readonly check?: boolean;
|
|
41
|
+
/** Bare specifiers mapped to local replacement files (resolved first). */
|
|
42
|
+
readonly moduleOverrides?: Readonly<Record<string, string>>;
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
/** A parsed (and, for module entries, already bundled) entry file. */
|
|
@@ -57,21 +60,23 @@ export function parseEntry(
|
|
|
57
60
|
entryPath: string,
|
|
58
61
|
registry: ExtensionRegistry,
|
|
59
62
|
diagnostics: DiagnosticBag,
|
|
63
|
+
moduleOverrides?: Readonly<Record<string, string>>,
|
|
60
64
|
): ParsedEntry {
|
|
61
65
|
const absoluteEntry = resolve(entryPath);
|
|
62
66
|
const sourceText = sourceTextBytes(readFileSync(absoluteEntry, "utf8"));
|
|
63
67
|
const file = new SourceFile(absoluteEntry, sourceText);
|
|
64
68
|
const parser = new Parser(file, diagnostics);
|
|
65
69
|
let sourceFile = parser.parseSourceFile();
|
|
66
|
-
const isModule =
|
|
67
|
-
(
|
|
68
|
-
statement
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
const isModule =
|
|
71
|
+
sourceFile.statements.some(
|
|
72
|
+
(statement) =>
|
|
73
|
+
statement.kind === SyntaxKind.ImportDeclaration ||
|
|
74
|
+
statement.kind === SyntaxKind.ExportDeclaration ||
|
|
75
|
+
statement.kind === SyntaxKind.ExportAssignment,
|
|
76
|
+
) || collectDynamicImportSites(sourceFile).length > 0;
|
|
72
77
|
let cacheText = sourceText;
|
|
73
78
|
if (isModule) {
|
|
74
|
-
const bundled = bundleModules(absoluteEntry, diagnostics, externalModuleSpecifiers(registry), registry.assetLoaders());
|
|
79
|
+
const bundled = bundleModules(absoluteEntry, diagnostics, externalModuleSpecifiers(registry), registry.assetLoaders(), moduleOverrides);
|
|
75
80
|
if (bundled) {
|
|
76
81
|
sourceFile = bundled.sourceFile;
|
|
77
82
|
cacheText = bundled.text;
|
|
@@ -117,7 +122,7 @@ export function compileEntry(
|
|
|
117
122
|
): CompileStringResult {
|
|
118
123
|
const registry = extensions ?? createDefaultRegistry();
|
|
119
124
|
const diagnostics = new DiagnosticBag();
|
|
120
|
-
const parsed = parseEntry(entryPath, registry, diagnostics);
|
|
125
|
+
const parsed = parseEntry(entryPath, registry, diagnostics, options.moduleOverrides);
|
|
121
126
|
if (diagnostics.hasErrors) return { ir: "", diagnostics: diagnostics.diagnostics };
|
|
122
127
|
const { ir } = generate(parsed.sourceFile, diagnostics, {
|
|
123
128
|
builtins: registry.builtins(),
|
package/src/driver/index.ts
CHANGED
|
@@ -19,7 +19,15 @@ export {
|
|
|
19
19
|
type AppConfig,
|
|
20
20
|
type LoadedProjectConfig,
|
|
21
21
|
type ProjectConfig,
|
|
22
|
+
type StorageConfig,
|
|
22
23
|
} from "./config.js";
|
|
24
|
+
export {
|
|
25
|
+
ensureStorageObject,
|
|
26
|
+
resolveStorage,
|
|
27
|
+
storageSource,
|
|
28
|
+
STORAGE_SYMBOLS,
|
|
29
|
+
type ResolvedStorage,
|
|
30
|
+
} from "./storage.js";
|
|
23
31
|
export {
|
|
24
32
|
ensureIconObject,
|
|
25
33
|
iconSource,
|
package/src/driver/options.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
import type { Diagnostic } from "../diagnostics/diagnostic.js";
|
|
10
10
|
import type { ExtensionRegistry } from "../extensions/registry.js";
|
|
11
|
-
import type { AppConfig } from "./config.js";
|
|
11
|
+
import type { AppConfig, StorageConfig } from "./config.js";
|
|
12
12
|
import type { PgoMode, Runner } from "./toolchain.js";
|
|
13
13
|
|
|
14
14
|
/** What `build` produces: an executable, an object file or LLVM IR only. */
|
|
@@ -39,6 +39,13 @@ export interface BuildOptions {
|
|
|
39
39
|
readonly icon?: string;
|
|
40
40
|
/** Application metadata: name, icon and macOS bundle settings. */
|
|
41
41
|
readonly app?: AppConfig;
|
|
42
|
+
/**
|
|
43
|
+
* Storage backend for the `storage` extension (`localStorage`, `sessionStorage`,
|
|
44
|
+
* `indexedDB`). Defaults to memory; `{ backend: "file", path }` persists to
|
|
45
|
+
* the given file. `path` must already be absolute (config resolution does
|
|
46
|
+
* this), and sessionStorage is always memory-backed regardless.
|
|
47
|
+
*/
|
|
48
|
+
readonly storage?: StorageConfig;
|
|
42
49
|
/** Emit LLVM debug metadata so `-g` produces DWARF/CodeView (default false). */
|
|
43
50
|
readonly debug?: boolean;
|
|
44
51
|
/**
|
|
@@ -64,6 +71,11 @@ export interface BuildOptions {
|
|
|
64
71
|
readonly features?: readonly string[];
|
|
65
72
|
/** Optional link features to keep out even when the scan detects a use. */
|
|
66
73
|
readonly noFeatures?: readonly string[];
|
|
74
|
+
/**
|
|
75
|
+
* Bare module specifiers mapped to local replacement files. A specifier in
|
|
76
|
+
* this map resolves to its file (an absolute path) before `node_modules`.
|
|
77
|
+
*/
|
|
78
|
+
readonly moduleOverrides?: Readonly<Record<string, string>>;
|
|
67
79
|
}
|
|
68
80
|
|
|
69
81
|
/** One phase of a build, in milliseconds (reported by `--time`). */
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Compile-time storage configuration for the `storage` extension.
|
|
3
|
+
*
|
|
4
|
+
* The project config's `storage` object (memory vs file, plus the resolved
|
|
5
|
+
* database path) is embedded into the binary as a small linkable object, the
|
|
6
|
+
* same way the application icon is (see `icon.ts`). The storage runtime reads
|
|
7
|
+
* these symbols when it opens its database, so a project can choose between an
|
|
8
|
+
* in-memory database (the default) and a persistent file without any runtime
|
|
9
|
+
* lookup.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { hashParts } from "./cache.js";
|
|
15
|
+
import { compileC, sysrootFlags, type Runner } from "./toolchain.js";
|
|
16
|
+
import type { StorageConfig } from "./config.js";
|
|
17
|
+
|
|
18
|
+
/** The C symbols the embedded storage configuration exposes. */
|
|
19
|
+
export const STORAGE_SYMBOLS = {
|
|
20
|
+
backend: "xt_storage_backend",
|
|
21
|
+
path: "xt_storage_path",
|
|
22
|
+
pathLen: "xt_storage_path_len",
|
|
23
|
+
} as const;
|
|
24
|
+
|
|
25
|
+
/** The storage backend after config defaults and path resolution. */
|
|
26
|
+
export interface ResolvedStorage {
|
|
27
|
+
readonly backend: "memory" | "file";
|
|
28
|
+
/** Absolute database path; empty for the memory backend. */
|
|
29
|
+
readonly path: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Normalise a (possibly undefined) config into a concrete backend + path. */
|
|
33
|
+
export function resolveStorage(config: StorageConfig | undefined): ResolvedStorage {
|
|
34
|
+
if (config?.backend === "file") return { backend: "file", path: config.path ?? "" };
|
|
35
|
+
return { backend: "memory", path: "" };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Generate the C translation unit embedding the storage backend + path. */
|
|
39
|
+
export function storageSource(storage: ResolvedStorage): string {
|
|
40
|
+
const backend = storage.backend === "file" ? 1 : 0;
|
|
41
|
+
/* The path is emitted as raw UTF-8 bytes plus a trailing NUL, so a path that
|
|
42
|
+
* contains `\`, `"` or non-ASCII characters needs no escaping. */
|
|
43
|
+
const path = storage.backend === "file" ? Buffer.from(storage.path, "utf8") : Buffer.alloc(0);
|
|
44
|
+
const bytes = [...path, 0x00];
|
|
45
|
+
const lines: string[] = [];
|
|
46
|
+
for (let offset = 0; offset < bytes.length; offset += 16) {
|
|
47
|
+
const chunk = Array.from(bytes.slice(offset, offset + 16), (byte) => `0x${byte.toString(16).padStart(2, "0")}`);
|
|
48
|
+
lines.push(" " + chunk.join(", ") + ",");
|
|
49
|
+
}
|
|
50
|
+
if (lines.length === 0) lines.push(" 0x00,");
|
|
51
|
+
return [
|
|
52
|
+
"/* Generated by xbintsc - embedded storage configuration. Do not edit. */",
|
|
53
|
+
`const unsigned int ${STORAGE_SYMBOLS.backend} = ${backend}u;`,
|
|
54
|
+
`const unsigned char ${STORAGE_SYMBOLS.path}[] = {`,
|
|
55
|
+
...lines,
|
|
56
|
+
"};",
|
|
57
|
+
`const unsigned long long ${STORAGE_SYMBOLS.pathLen} = ${path.length}ull;`,
|
|
58
|
+
"",
|
|
59
|
+
].join("\n");
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Compile the storage configuration into an object exposing
|
|
64
|
+
* {@link STORAGE_SYMBOLS}. Cached by the backend + path, so an unchanged
|
|
65
|
+
* configuration is never recompiled.
|
|
66
|
+
*/
|
|
67
|
+
export function ensureStorageObject(
|
|
68
|
+
runner: Runner,
|
|
69
|
+
clang: string,
|
|
70
|
+
cacheDir: string,
|
|
71
|
+
storage: ResolvedStorage,
|
|
72
|
+
env?: Record<string, string>,
|
|
73
|
+
sdkRoot?: string,
|
|
74
|
+
): string {
|
|
75
|
+
const key = hashParts(["storage", process.platform, storage.backend, storage.path]);
|
|
76
|
+
const sourcePath = join(cacheDir, `storage-${key}.c`);
|
|
77
|
+
const objectPath = join(cacheDir, `storage-${key}.o`);
|
|
78
|
+
if (!existsSync(objectPath)) {
|
|
79
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
80
|
+
writeFileSync(sourcePath, storageSource(storage));
|
|
81
|
+
compileC(runner, clang, sourcePath, objectPath, cacheDir, env, sysrootFlags(sdkRoot));
|
|
82
|
+
}
|
|
83
|
+
return objectPath;
|
|
84
|
+
}
|
package/src/driver/version.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* The GUI engine itself is always linked with `--ext gui`; these are the two
|
|
5
5
|
* heavy halves a program may never touch:
|
|
6
6
|
*
|
|
7
|
-
* - `media` — the FFmpeg decoder backend (`runtime/
|
|
7
|
+
* - `media` — the FFmpeg decoder backend (`runtime/xt_media/`, `media.a`).
|
|
8
8
|
* The DOM media surface lives in `gui.a`; only decoding is optional, and an
|
|
9
9
|
* element without the backend still exists and fires `error`.
|
|
10
10
|
* - `gpu` — glslang (+ SPIRV-Cross on macOS), the GLSL→SPIR-V translator used
|
|
@@ -108,7 +108,7 @@ export const guiLinkFeatures: readonly LinkFeature[] = [
|
|
|
108
108
|
* the linker extract `media.a` — an archive whose only entry point is a
|
|
109
109
|
* constructor would otherwise never be pulled in.
|
|
110
110
|
*/
|
|
111
|
-
runtimeSources: () => [join(findRuntimeDir(), "
|
|
111
|
+
runtimeSources: () => [join(findRuntimeDir(), "xt_media", "media_bridge.c")],
|
|
112
112
|
nativeObjects: () => {
|
|
113
113
|
const archive = findRuntimeLibrary("media");
|
|
114
114
|
if (archive === undefined) {
|
|
@@ -151,7 +151,9 @@ const browserGlobals: Record<string, { symbol: string; argument?: string }> = {
|
|
|
151
151
|
self: { symbol: "xt_browser_window" },
|
|
152
152
|
document: { symbol: "xt_browser_document" },
|
|
153
153
|
navigator: { symbol: "xt_browser_navigator" },
|
|
154
|
-
localStorage
|
|
154
|
+
/* `localStorage` (and `sessionStorage` / `indexedDB`) are core globals backed
|
|
155
|
+
* by the SQLite `storage` link feature, so a page reaches them through core
|
|
156
|
+
* rather than the engine's in-memory `window.localStorage` store. */
|
|
155
157
|
__THREE_DEVTOOLS__: { symbol: "xt_browser_missing" },
|
|
156
158
|
createImageBitmap: { symbol: "xt_browser_create_image_bitmap" },
|
|
157
159
|
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `async_hooks` module: `AsyncResource` (a constructible base class) and
|
|
3
|
+
* the stateless async-id / hook stubs.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { NodeModule } from "../module.js";
|
|
7
|
+
import { resolveFrom } from "../module.js";
|
|
8
|
+
import type { ModuleExports } from "../../registry.js";
|
|
9
|
+
|
|
10
|
+
const exports: ModuleExports = {
|
|
11
|
+
AsyncResource: { symbol: "xt_async_resource_ctor", isConstructor: true },
|
|
12
|
+
AsyncLocalStorage: { symbol: "xt_async_resource_ctor", isConstructor: true },
|
|
13
|
+
executionAsyncId: { symbol: "xt_async_hooks_execution_id" },
|
|
14
|
+
triggerAsyncId: { symbol: "xt_async_hooks_trigger_id" },
|
|
15
|
+
createHook: { symbol: "xt_async_hooks_create_hook" },
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const asyncHooksModule: NodeModule = {
|
|
19
|
+
name: "async_hooks",
|
|
20
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/async_hooks/async_hooks.c")],
|
|
21
|
+
builtins: () => ({}),
|
|
22
|
+
exports: () => exports,
|
|
23
|
+
};
|
|
@@ -18,6 +18,7 @@ const statics = [
|
|
|
18
18
|
"allocUnsafe",
|
|
19
19
|
"allocUnsafeSlow",
|
|
20
20
|
"isBuffer",
|
|
21
|
+
"isUtf8",
|
|
21
22
|
"byteLength",
|
|
22
23
|
"concat",
|
|
23
24
|
"compare",
|
|
@@ -26,6 +27,7 @@ const statics = [
|
|
|
26
27
|
const exports: ModuleExports = {
|
|
27
28
|
Buffer: { symbol: "xt_buffer_ctor", isConstructor: true },
|
|
28
29
|
...Object.fromEntries(statics.map((method) => [method, { namespace: "Buffer", method }])),
|
|
30
|
+
constants: { valueSymbol: "xt_buffer_constants_value" },
|
|
29
31
|
};
|
|
30
32
|
|
|
31
33
|
export const bufferModule: NodeModule = {
|
|
@@ -17,11 +17,23 @@ const builtins: Record<string, BuiltinFunction> = {
|
|
|
17
17
|
|
|
18
18
|
const exports: ModuleExports = {
|
|
19
19
|
spawnSync: { symbol: "xt_child_process_spawn_sync" },
|
|
20
|
+
spawn: { symbol: "xt_child_process_spawn" },
|
|
21
|
+
execFile: { symbol: "xt_child_process_exec_file" },
|
|
22
|
+
execSync: { symbol: "xt_child_process_exec_sync" },
|
|
20
23
|
};
|
|
21
24
|
|
|
22
25
|
export const childProcessModule: NodeModule = {
|
|
23
26
|
name: "child_process",
|
|
24
|
-
runtimeSources: () => [
|
|
27
|
+
runtimeSources: () => [
|
|
28
|
+
resolveFrom(import.meta.url, "../../../../runtime/ext_node/child_process/child_process.c"),
|
|
29
|
+
resolveFrom(import.meta.url, "../../../../runtime/ext_node/child_process/spawn.c"),
|
|
30
|
+
resolveFrom(
|
|
31
|
+
import.meta.url,
|
|
32
|
+
process.platform === "win32"
|
|
33
|
+
? "../../../../runtime/ext_node/child_process/spawn_win.c"
|
|
34
|
+
: "../../../../runtime/ext_node/child_process/spawn_posix.c",
|
|
35
|
+
),
|
|
36
|
+
],
|
|
25
37
|
builtins: () => builtins,
|
|
26
38
|
exports: () => exports,
|
|
27
39
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's `console` module: the `Console` constructor plus the console methods
|
|
3
|
+
* as named exports.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { NodeModule } from "../module.js";
|
|
7
|
+
import { resolveFrom } from "../module.js";
|
|
8
|
+
import type { ModuleExports } from "../../registry.js";
|
|
9
|
+
|
|
10
|
+
const voidMethods: readonly string[] = ["log", "info", "warn", "error", "debug"];
|
|
11
|
+
const valueMethods: readonly string[] = [
|
|
12
|
+
"dir",
|
|
13
|
+
"trace",
|
|
14
|
+
"assert",
|
|
15
|
+
"count",
|
|
16
|
+
"countReset",
|
|
17
|
+
"group",
|
|
18
|
+
"groupEnd",
|
|
19
|
+
"table",
|
|
20
|
+
"time",
|
|
21
|
+
"timeEnd",
|
|
22
|
+
"timeLog",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const exports: ModuleExports = {
|
|
26
|
+
Console: { symbol: "xt_console_ctor", isConstructor: true },
|
|
27
|
+
...Object.fromEntries(
|
|
28
|
+
voidMethods.map((method) => [method, { symbol: `xt_console_${method === "debug" ? "log" : method}`, returnVoid: true }]),
|
|
29
|
+
),
|
|
30
|
+
...Object.fromEntries(
|
|
31
|
+
valueMethods.map((method) => [method, { symbol: `xt_console_${snakeCase(method)}` }]),
|
|
32
|
+
),
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
function snakeCase(name: string): string {
|
|
36
|
+
return name.replace(/([a-z])([A-Z])/g, "$1_$2").toLowerCase();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const consoleModule: NodeModule = {
|
|
40
|
+
name: "console",
|
|
41
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/console/console.c")],
|
|
42
|
+
builtins: () => ({}),
|
|
43
|
+
exports: () => exports,
|
|
44
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node's deprecated `constants` module: the file-system flags older packages
|
|
3
|
+
* read (`O_RDONLY` / `O_WRONLY` / `O_SYMLINK`, the `F_OK` access checks, ...).
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { NodeModule } from "../module.js";
|
|
7
|
+
import { resolveFrom } from "../module.js";
|
|
8
|
+
import type { ModuleExports } from "../../registry.js";
|
|
9
|
+
|
|
10
|
+
const names: readonly string[] = [
|
|
11
|
+
"F_OK",
|
|
12
|
+
"R_OK",
|
|
13
|
+
"W_OK",
|
|
14
|
+
"X_OK",
|
|
15
|
+
"O_RDONLY",
|
|
16
|
+
"O_WRONLY",
|
|
17
|
+
"O_RDWR",
|
|
18
|
+
"O_CREAT",
|
|
19
|
+
"O_EXCL",
|
|
20
|
+
"O_TRUNC",
|
|
21
|
+
"O_APPEND",
|
|
22
|
+
"O_SYMLINK",
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const exports: ModuleExports = Object.fromEntries(
|
|
26
|
+
names.map((name) => [name, { valueSymbol: `xt_constants_${name.toLowerCase()}` }]),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const constantsModule: NodeModule = {
|
|
30
|
+
name: "constants",
|
|
31
|
+
runtimeSources: () => [resolveFrom(import.meta.url, "../../../../runtime/ext_node/constants/constants.c")],
|
|
32
|
+
builtins: () => ({}),
|
|
33
|
+
exports: () => exports,
|
|
34
|
+
};
|