xbintsc 0.6.28 → 0.7.6
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 +10 -0
- 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/source.js +4 -0
- package/dist/src/checker/source.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/help.d.ts +1 -1
- package/dist/src/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +29 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +95 -1
- 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/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +24 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- 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.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +13 -29
- 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/generator.js +4 -0
- package/dist/src/codegen/generator/generator.js.map +1 -1
- package/dist/src/codegen/generator/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- 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 +21 -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 +18 -12
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.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 +79 -8
- 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 +4 -4
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +43 -13
- 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 +11 -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/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/options.d.ts +1 -4
- 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 +28 -5
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.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/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +48 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- 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/registry.d.ts +27 -0
- package/dist/src/extensions/registry.js +13 -4
- package/dist/src/extensions/registry.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/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.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/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +28 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- 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/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/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.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-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.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 +53 -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-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.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/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/fetch.test.js +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +35 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +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/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- 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/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
- 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/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- 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/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.js +44 -29
- package/dist/tests/e2e/web-streams.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- 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 +1 -0
- package/doc/ai/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/cli.md +1 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +26 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/known-issues.md +35 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +2 -1
- package/doc/implemented/checker.md +14 -0
- package/doc/implemented/codegen.md +7 -0
- 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.md +7 -1
- package/doc/implemented/operators.md +3 -1
- package/doc/implemented/parser.md +3 -2
- package/doc/implemented/runtime-core.md +13 -2
- package/doc/implemented/stdlib.md +79 -4
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/unimplemented/classes.md +1 -0
- package/doc/unimplemented/modules.md +1 -0
- package/doc/unimplemented/stdlib.md +2 -1
- package/doc/xbintsc.config.schema.json +5 -0
- package/doc/zh-CN/gui/api.md +19 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/known-issues.md +24 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +10 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- 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.md +1 -1
- package/doc/zh-CN/implemented/operators.md +2 -1
- package/doc/zh-CN/implemented/parser.md +3 -2
- package/doc/zh-CN/implemented/runtime-core.md +10 -2
- package/doc/zh-CN/implemented/stdlib.md +64 -4
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- package/doc/zh-CN/unimplemented/classes.md +1 -0
- package/doc/zh-CN/unimplemented/modules.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +2 -1
- package/package.json +7 -7
- package/runtime/ext_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +9 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_internal.h +3 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +3 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +6 -1
- package/runtime/ext_gui/gui_engine.h +2 -0
- package/runtime/ext_gui/gui_events.cpp +13 -8
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +20 -170
- package/runtime/ext_gui/webgl_context.cpp +117 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_objects.h +16 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +8 -0
- 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/rt.h +63 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +61 -69
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +154 -181
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +29 -24
- package/runtime/xt_constructors.c +102 -2
- package/runtime/xt_containers/access.inc +125 -12
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/function_prototypes.inc +58 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +59 -75
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +5 -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_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +136 -0
- package/runtime/xt_intl.c +224 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +66 -1
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_module_values.c +82 -0
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_proxy.c +140 -0
- package/runtime/xt_stdlib/dispatch.inc +104 -9
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +71 -55
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/runtime/xt_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/scripts/build-runtime.ts +8 -0
- package/src/ast/common.ts +10 -0
- package/src/binder/declarations.ts +34 -0
- package/src/binder/references.ts +12 -0
- package/src/checker/globals.ts +1 -0
- package/src/checker/source.ts +3 -0
- package/src/checker/type-system.ts +23 -3
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +28 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +99 -1
- package/src/codegen/generator/calls/super.ts +5 -4
- package/src/codegen/generator/calls/unwrap.ts +47 -0
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +26 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/module-values.ts +57 -19
- package/src/codegen/generator/expressions/primary.ts +13 -36
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/generator.ts +4 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/lookup-tables.ts +63 -0
- package/src/codegen/generator/module.ts +38 -7
- package/src/codegen/generator/state.ts +22 -0
- package/src/codegen/generator/tables.ts +18 -12
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/commonjs.ts +12 -5
- package/src/driver/bundler/concatenate.ts +96 -12
- package/src/driver/bundler/deferred.ts +122 -6
- package/src/driver/bundler/dynamic-import.ts +75 -2
- package/src/driver/bundler/graph.ts +4 -4
- package/src/driver/bundler/merge.ts +42 -9
- package/src/driver/bundler/namespace-object.ts +44 -0
- package/src/driver/bundler/reexport-resolution.ts +14 -2
- package/src/driver/bundler/symbols.ts +17 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/config.ts +1 -1
- package/src/driver/frontend.ts +3 -4
- package/src/driver/options.ts +1 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +28 -5
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +50 -1
- 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/registry.ts +41 -4
- package/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
- package/src/parser/literals.ts +6 -2
|
@@ -39,6 +39,21 @@ function escapeMetadata(text: string): string {
|
|
|
39
39
|
return escapeBytes(utf8Bytes(text));
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* DWARF/Verifier limits for `!DILocation`. The column is a 16-bit field, so a
|
|
44
|
+
* minified source line (`<script>` bundles are routinely 60–80k columns wide)
|
|
45
|
+
* makes the verifier reject the whole module. The line has its own, larger
|
|
46
|
+
* limit; clamp both rather than failing the build: a debug location is a
|
|
47
|
+
* best-effort hint, and a wrong-but-valid one still points at the statement.
|
|
48
|
+
*/
|
|
49
|
+
const MAX_DEBUG_LINE = 0xffffff;
|
|
50
|
+
const MAX_DEBUG_COLUMN = 0xffff;
|
|
51
|
+
|
|
52
|
+
function clampDebugPosition(value: number, limit: number): number {
|
|
53
|
+
if (!Number.isFinite(value) || value < 0) return 0;
|
|
54
|
+
return Math.min(Math.floor(value), limit);
|
|
55
|
+
}
|
|
56
|
+
|
|
42
57
|
/**
|
|
43
58
|
* Create the compile unit and module flags once. LLVM requires the `Debug Info
|
|
44
59
|
* Version` flag for any `!dbg` attachment, and clang only emits DWARF/CodeView
|
|
@@ -97,10 +112,11 @@ export const debugMethods: DebugMethods = {
|
|
|
97
112
|
: fn.isConstructor && fn.classInfo
|
|
98
113
|
? `new ${this.displayNameOf(fn.classInfo.name)}`
|
|
99
114
|
: this.displayNameOf(fn.name.length > 0 ? fn.name : "anonymous");
|
|
115
|
+
const line = clampDebugPosition(position.line, MAX_DEBUG_LINE);
|
|
100
116
|
const subprogram = this.addMetadata(
|
|
101
117
|
'distinct !DISubprogram(name: ' +
|
|
102
118
|
`"${escapeMetadata(displayName)}", scope: ${this.debugUnit}, file: ${file}, ` +
|
|
103
|
-
`line: ${
|
|
119
|
+
`line: ${line}, type: ${this.debugSubroutineType}, scopeLine: ${line}, ` +
|
|
104
120
|
`spFlags: DISPFlagDefinition, unit: ${this.debugUnit})`,
|
|
105
121
|
);
|
|
106
122
|
this.debugSubprograms.set(fn.id, subprogram);
|
|
@@ -110,11 +126,13 @@ export const debugMethods: DebugMethods = {
|
|
|
110
126
|
setDebugLocation(node) {
|
|
111
127
|
if (!this.debug || this.current.debugSubprogram === undefined) return;
|
|
112
128
|
const position = this.positionOf(node);
|
|
113
|
-
const
|
|
129
|
+
const line = clampDebugPosition(position.line, MAX_DEBUG_LINE);
|
|
130
|
+
const column = clampDebugPosition(position.column, MAX_DEBUG_COLUMN);
|
|
131
|
+
const key = `${this.current.debugSubprogram}:${line}:${column}`;
|
|
114
132
|
let location = this.debugLocations.get(key);
|
|
115
133
|
if (!location) {
|
|
116
134
|
location = this.addMetadata(
|
|
117
|
-
`!DILocation(line: ${
|
|
135
|
+
`!DILocation(line: ${line}, column: ${column}, scope: ${this.current.debugSubprogram})`,
|
|
118
136
|
);
|
|
119
137
|
this.debugLocations.set(key, location);
|
|
120
138
|
}
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
import { SymbolKind } from "../../../binder/binder.js";
|
|
20
20
|
import { DiagnosticCode } from "../../../diagnostics/diagnostic.js";
|
|
21
21
|
import { i64, numberLiteral, XT_UNDEFINED } from "../../values.js";
|
|
22
|
+
import { NAMESPACE_PROPERTY_SETTERS } from "../lookup-tables.js";
|
|
22
23
|
import { BINARY_RUNTIME, compoundToBinary, propertyNameText } from "../tables.js";
|
|
23
24
|
import type { Generator } from "../generator.js";
|
|
24
25
|
|
|
@@ -127,16 +128,38 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
|
|
|
127
128
|
}
|
|
128
129
|
case SyntaxKind.PropertyAccessExpression: {
|
|
129
130
|
const access = target as PropertyAccessExpression;
|
|
131
|
+
/* `process.exitCode = 1`: a namespace property with a runtime setter.
|
|
132
|
+
* Reads go through `NAMESPACE_PROPERTIES`, writes through the matching
|
|
133
|
+
* entry here; a namespace without one keeps the generic object path. */
|
|
134
|
+
const holder =
|
|
135
|
+
access.expression.kind === SyntaxKind.Identifier ? (access.expression as Identifier) : undefined;
|
|
136
|
+
const symbol = holder ? this.binding.symbolOfIdentifier.get(holder) : undefined;
|
|
137
|
+
const namespace = holder ? (symbol ? this.namespaceOfSymbol(symbol) : holder.text) : undefined;
|
|
138
|
+
const setter = namespace === undefined ? undefined : NAMESPACE_PROPERTY_SETTERS[namespace];
|
|
139
|
+
if (setter) {
|
|
140
|
+
const key = this.stringValue(access.name.text);
|
|
141
|
+
this.extraDeclarations.add(`declare i64 @${setter}(i64, i64)`);
|
|
142
|
+
this.emit(` call i64 @${setter}(i64 ${key}, i64 ${value})`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
130
145
|
const object = this.emitExpression(access.expression);
|
|
131
146
|
const key = this.stringValue(access.name.text);
|
|
132
|
-
|
|
147
|
+
/* A store site gets the same monomorphic inline cache a read site has:
|
|
148
|
+
* `obj.x = v` in a hot loop otherwise resolves the property (own scan,
|
|
149
|
+
* prototype-chain walk for setters) on every assignment. */
|
|
150
|
+
this.extraDeclarations.add("declare i64 @xt_set_ic(i64, i64, i64, i64*)");
|
|
151
|
+
const cache = `@st.${this.icCounter++}`;
|
|
152
|
+
this.globals.push(`${cache} = internal global [2 x i64] zeroinitializer`);
|
|
153
|
+
const slot = this.reg();
|
|
154
|
+
this.emit(` ${slot} = getelementptr [2 x i64], [2 x i64]* ${cache}, i64 0, i64 0`);
|
|
155
|
+
this.emit(` call i64 @xt_set_ic(i64 ${object}, i64 ${key}, i64 ${value}, i64* ${slot})`);
|
|
133
156
|
return;
|
|
134
157
|
}
|
|
135
158
|
case SyntaxKind.ElementAccessExpression: {
|
|
136
159
|
const access = target as ElementAccessExpression;
|
|
137
160
|
const object = this.emitExpression(access.expression);
|
|
138
161
|
const key = this.emitExpression(access.argumentExpression);
|
|
139
|
-
this.
|
|
162
|
+
this.emitElementWrite(object, key, value);
|
|
140
163
|
return;
|
|
141
164
|
}
|
|
142
165
|
case SyntaxKind.ParenthesizedExpression:
|
|
@@ -229,3 +252,4 @@ export const assignmentExpressionMethods: AssignmentExpressionMethods = {
|
|
|
229
252
|
}
|
|
230
253
|
},
|
|
231
254
|
};
|
|
255
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension-provided global values.
|
|
3
|
+
*
|
|
4
|
+
* An extension names a global (`window`, `document`, `Image`, `location`) and
|
|
5
|
+
* the runtime getter that produces it; this group turns such a name into a
|
|
6
|
+
* value, including the two richer shapes:
|
|
7
|
+
*
|
|
8
|
+
* - a global that is a *member of a host object* (`location` off the window),
|
|
9
|
+
* so a browser global that only exists as a window property is still live;
|
|
10
|
+
* - `console`, which is both a namespace at call sites and a first-class
|
|
11
|
+
* object as a value (`console.error.bind(console)`).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { GlobalValue } from "../../../extensions/registry.js";
|
|
15
|
+
import type { Generator } from "../generator.js";
|
|
16
|
+
|
|
17
|
+
export interface GlobalValueMethods {
|
|
18
|
+
emitGlobalValue(this: Generator, value: GlobalValue): string;
|
|
19
|
+
emitConsoleObject(this: Generator): string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const globalValueMethods: GlobalValueMethods = {
|
|
23
|
+
/**
|
|
24
|
+
* Read an extension-provided global (`window`, `document`, `new Image()`).
|
|
25
|
+
* The getter is a normal runtime call with the uniform ABI; the optional
|
|
26
|
+
* argument is how one getter serves a whole family of host types.
|
|
27
|
+
*/
|
|
28
|
+
emitGlobalValue(value: GlobalValue): string {
|
|
29
|
+
this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
|
|
30
|
+
let argc = "0";
|
|
31
|
+
let pointer = "i64* null";
|
|
32
|
+
if (value.argument !== undefined) {
|
|
33
|
+
const argument = this.stringValue(value.argument);
|
|
34
|
+
const slot = `%gval${this.current.allocas.length}`;
|
|
35
|
+
this.current.allocas.push(`${slot} = alloca i64, i32 1`);
|
|
36
|
+
const cell = this.reg();
|
|
37
|
+
this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
|
|
38
|
+
this.emit(` store i64 ${argument}, i64* ${cell}`);
|
|
39
|
+
argc = "1";
|
|
40
|
+
pointer = `i64* ${slot}`;
|
|
41
|
+
}
|
|
42
|
+
const result = this.reg();
|
|
43
|
+
this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
|
|
44
|
+
if (value.member === undefined) return result;
|
|
45
|
+
/* A browser global that lives on the window object (`location`): read it
|
|
46
|
+
* off the host object so a getter runs and answers a live value. */
|
|
47
|
+
const name = this.stringValue(value.member);
|
|
48
|
+
return this.runtimeCall("xt_get", [result, name]);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/** The global `console` object (see `runtime/xt_io/console.inc`). */
|
|
52
|
+
emitConsoleObject(): string {
|
|
53
|
+
const result = this.reg();
|
|
54
|
+
this.emit(` ${result} = call i64 @xt_console_object(i32 0, i64* null)`);
|
|
55
|
+
return result;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -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
|
};
|
|
@@ -41,8 +41,8 @@ import {
|
|
|
41
41
|
NAMESPACE_VALUES,
|
|
42
42
|
WEB_GLOBALS,
|
|
43
43
|
} from "../tables.js";
|
|
44
|
-
import type { GlobalValue } from "../../../extensions/registry.js";
|
|
45
44
|
import type { Generator } from "../generator.js";
|
|
45
|
+
import { newCalleeName } from "../calls/unwrap.js";
|
|
46
46
|
|
|
47
47
|
export interface PrimaryExpressionMethods {
|
|
48
48
|
emitExpression(this: Generator, node: Expression): string;
|
|
@@ -56,7 +56,6 @@ export interface PrimaryExpressionMethods {
|
|
|
56
56
|
*/
|
|
57
57
|
emitTypeOf(this: Generator, operand: Expression): string;
|
|
58
58
|
globalTypeOf(this: Generator, name: string): string | undefined;
|
|
59
|
-
emitGlobalValue(this: Generator, value: GlobalValue): string;
|
|
60
59
|
emitFunctionValue(this: Generator, symbol: SymbolInfo): string;
|
|
61
60
|
emitTemplate(this: Generator, node: TemplateLiteral): string;
|
|
62
61
|
emitTaggedTemplate(this: Generator, node: TaggedTemplateExpression): string;
|
|
@@ -293,7 +292,10 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
293
292
|
case "Infinity":
|
|
294
293
|
return numberLiteral(Infinity);
|
|
295
294
|
case "console":
|
|
296
|
-
|
|
295
|
+
/* `console` is a namespace at call sites (`console.log(...)`) and a
|
|
296
|
+
* first-class object as a value: `const log = console.log`,
|
|
297
|
+
* `console.error.bind(console)`, `const { warn } = console`. */
|
|
298
|
+
return this.emitConsoleObject();
|
|
297
299
|
case "arguments": {
|
|
298
300
|
const argc = this.reg();
|
|
299
301
|
this.emit(` ${argc} = load i32, i32* %saved.argc`);
|
|
@@ -349,10 +351,9 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
349
351
|
return this.runtimeCall("xt_error_constructor", [nameValue]);
|
|
350
352
|
}
|
|
351
353
|
// A bare `require` reference is CommonJS; steer the user to `import`.
|
|
352
|
-
if (identifier.text === "require") {
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
}
|
|
354
|
+
if (identifier.text === "require") { this.reportRequireUse(identifier); return i64(XT_UNDEFINED); }
|
|
355
|
+
// `globalThis` / Node's `global` as a value is the (plain-bag) global object.
|
|
356
|
+
if (identifier.text === "globalThis" || identifier.text === "global") return this.runtimeCall("xt_global_object", []);
|
|
356
357
|
// Recognized web globals with no runtime yet lower to `undefined`.
|
|
357
358
|
if (WEB_GLOBALS.has(identifier.text)) return i64(XT_UNDEFINED);
|
|
358
359
|
/* The parser's recovery node for a missing expression. The syntax
|
|
@@ -375,30 +376,6 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
375
376
|
}
|
|
376
377
|
},
|
|
377
378
|
|
|
378
|
-
/**
|
|
379
|
-
* Read an extension-provided global (`window`, `document`, `new Image()`).
|
|
380
|
-
* The getter is a normal runtime call with the uniform ABI; the optional
|
|
381
|
-
* argument is how one getter serves a whole family of host types.
|
|
382
|
-
*/
|
|
383
|
-
emitGlobalValue(value: GlobalValue): string {
|
|
384
|
-
this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
|
|
385
|
-
let argc = "0";
|
|
386
|
-
let pointer = "i64* null";
|
|
387
|
-
if (value.argument !== undefined) {
|
|
388
|
-
const argument = this.stringValue(value.argument);
|
|
389
|
-
const slot = `%gval${this.current.allocas.length}`;
|
|
390
|
-
this.current.allocas.push(`${slot} = alloca i64, i32 1`);
|
|
391
|
-
const cell = this.reg();
|
|
392
|
-
this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
|
|
393
|
-
this.emit(` store i64 ${argument}, i64* ${cell}`);
|
|
394
|
-
argc = "1";
|
|
395
|
-
pointer = `i64* ${slot}`;
|
|
396
|
-
}
|
|
397
|
-
const result = this.reg();
|
|
398
|
-
this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
|
|
399
|
-
return result;
|
|
400
|
-
},
|
|
401
|
-
|
|
402
379
|
emitFunctionValue(symbol: SymbolInfo): string {
|
|
403
380
|
const fn = implementationFunctionInfo(this.binding, symbol);
|
|
404
381
|
if (!fn) return i64(XT_UNDEFINED);
|
|
@@ -446,9 +423,9 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
446
423
|
|
|
447
424
|
emitNew(node: NewExpression): string {
|
|
448
425
|
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
426
|
this.emit(` call void @xt_stack_set_line(i32 ${this.lineOf(node)})`);
|
|
427
|
+
const calleeText = newCalleeName(callee);
|
|
428
|
+
const calleeName = calleeText === undefined ? i64(XT_UNDEFINED) : this.stringValue(calleeText);
|
|
452
429
|
if (callee.kind === SyntaxKind.Identifier) {
|
|
453
430
|
const identifier = callee as Identifier;
|
|
454
431
|
const symbol = this.binding.symbolOfIdentifier.get(identifier);
|
|
@@ -459,7 +436,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
459
436
|
const ctor = this.emitClassReference(info);
|
|
460
437
|
const args = this.emitArguments(node.arguments);
|
|
461
438
|
const result = this.reg();
|
|
462
|
-
this.emit(` ${result} = call i64 @
|
|
439
|
+
this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctor}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
|
|
463
440
|
return result;
|
|
464
441
|
}
|
|
465
442
|
}
|
|
@@ -476,7 +453,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
476
453
|
const ctorValue = this.emitGlobalValue(extensionConstructor);
|
|
477
454
|
const args = this.emitArguments(node.arguments);
|
|
478
455
|
const result = this.reg();
|
|
479
|
-
this.emit(` ${result} = call i64 @
|
|
456
|
+
this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctorValue}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
|
|
480
457
|
return result;
|
|
481
458
|
}
|
|
482
459
|
if (identifier.text === "Object") {
|
|
@@ -500,7 +477,7 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
500
477
|
const ctorValue = this.emitExpression(callee);
|
|
501
478
|
const args = this.emitArguments(node.arguments);
|
|
502
479
|
const result = this.reg();
|
|
503
|
-
this.emit(` ${result} = call i64 @
|
|
480
|
+
this.emit(` ${result} = call i64 @xt_new_named(i64 ${ctorValue}, i64 ${calleeName}, i32 ${args.argc}, i64* ${args.ptr})`);
|
|
504
481
|
return result;
|
|
505
482
|
},
|
|
506
483
|
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { primaryExpressionMethods, type PrimaryExpressionMethods } from "./expressions/primary.js";
|
|
12
|
+
import { globalValueMethods, type GlobalValueMethods } from "./expressions/global-values.js";
|
|
12
13
|
import { moduleValueExpressionMethods, type ModuleValueExpressionMethods } from "./expressions/module-values.js";
|
|
13
14
|
import { operatorExpressionMethods, type OperatorExpressionMethods } from "./expressions/operators.js";
|
|
14
15
|
import { assignmentExpressionMethods, type AssignmentExpressionMethods } from "./expressions/assignment.js";
|
|
15
16
|
|
|
16
17
|
export interface ExpressionMethods
|
|
17
18
|
extends PrimaryExpressionMethods,
|
|
19
|
+
GlobalValueMethods,
|
|
18
20
|
ModuleValueExpressionMethods,
|
|
19
21
|
OperatorExpressionMethods,
|
|
20
22
|
AssignmentExpressionMethods {}
|
|
@@ -22,6 +24,7 @@ export interface ExpressionMethods
|
|
|
22
24
|
export const expressionMethods: ExpressionMethods = Object.assign(
|
|
23
25
|
{},
|
|
24
26
|
primaryExpressionMethods,
|
|
27
|
+
globalValueMethods,
|
|
25
28
|
moduleValueExpressionMethods,
|
|
26
29
|
operatorExpressionMethods,
|
|
27
30
|
assignmentExpressionMethods,
|
|
@@ -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,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Byte offsets into the runtime's container structs that generated code reads
|
|
3
|
+
* directly.
|
|
4
|
+
*
|
|
5
|
+
* The element fast path (`element-inline.ts`) skips the generic dispatch by
|
|
6
|
+
* looking at a value's tag and then loading the fields it needs — an array's
|
|
7
|
+
* `items`/`length`, a typed-array view's `view_bytes`/`view_length`/kind — out of
|
|
8
|
+
* the object header. That only works if the compiler knows the layout, so these
|
|
9
|
+
* constants mirror `runtime/rt_object.h`; `tests/codegen/element-layout.test.ts`
|
|
10
|
+
* compiles a C probe against the runtime header and fails when the two drift
|
|
11
|
+
* apart.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { XT_ARRAY, XT_NUMBER_MASK, XT_OBJECT, XT_TAG_MASK } from "../values.js";
|
|
15
|
+
|
|
16
|
+
export const XT_LAYOUT = {
|
|
17
|
+
/** `xt_header` size: the payload starts here in every heap object. */
|
|
18
|
+
headerSize: 16,
|
|
19
|
+
/** `xt_array.length` (uint32). */
|
|
20
|
+
arrayLength: 16,
|
|
21
|
+
/** `xt_array.items` (i64 pointer to the element vector). */
|
|
22
|
+
arrayItems: 24,
|
|
23
|
+
/** `xt_object.reserved2` (uint16): a typed-array view's `kind + 1`. */
|
|
24
|
+
objectTypedKind: 50,
|
|
25
|
+
/** `xt_object.view_bytes` (i64 raw pointer): the view's first element. */
|
|
26
|
+
objectViewBytes: 96,
|
|
27
|
+
/** `xt_object.view_length` (uint32): bytes available from `view_bytes`. */
|
|
28
|
+
objectViewLength: 104,
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
/** Tags and masks the inline guards compare against (`runtime/rt.h`). */
|
|
32
|
+
export const XT_INLINE_TAGS = {
|
|
33
|
+
tagMask: XT_TAG_MASK,
|
|
34
|
+
numberMask: XT_NUMBER_MASK,
|
|
35
|
+
array: XT_ARRAY,
|
|
36
|
+
object: XT_OBJECT,
|
|
37
|
+
} as const;
|
|
38
|
+
|
|
39
|
+
/** Typed-array element kinds, in `XT_TA_*` order (`runtime/xt_typed_array.c`). */
|
|
40
|
+
export const XT_TYPED_KINDS = [
|
|
41
|
+
{ name: "Uint8Array", width: 1 },
|
|
42
|
+
{ name: "Int8Array", width: 1 },
|
|
43
|
+
{ name: "Uint8ClampedArray", width: 1 },
|
|
44
|
+
{ name: "Uint16Array", width: 2 },
|
|
45
|
+
{ name: "Int16Array", width: 2 },
|
|
46
|
+
{ name: "Uint32Array", width: 4 },
|
|
47
|
+
{ name: "Int32Array", width: 4 },
|
|
48
|
+
{ name: "Float32Array", width: 4 },
|
|
49
|
+
{ name: "Float64Array", width: 8 },
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
/** Index of `Float32Array` / `Float64Array` in {@link XT_TYPED_KINDS}. */
|
|
53
|
+
export const XT_KIND_F32 = 7;
|
|
54
|
+
export const XT_KIND_F64 = 8;
|
|
@@ -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
|
}
|