xbintsc 0.5.22 → 0.5.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +12 -3
- package/README.md +46 -11
- package/README.zh-CN.md +32 -6
- package/dist/scripts/support-matrix.d.ts +18 -0
- package/dist/scripts/support-matrix.js +141 -0
- package/dist/scripts/support-matrix.js.map +1 -0
- package/dist/src/ast/common.d.ts +2 -2
- package/dist/src/ast/declarations.d.ts +7 -1
- 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/binder/binder.d.ts +2 -1
- package/dist/src/binder/binder.js +2 -0
- package/dist/src/binder/binder.js.map +1 -1
- package/dist/src/binder/declarations.d.ts +9 -0
- package/dist/src/binder/declarations.js +64 -0
- package/dist/src/binder/declarations.js.map +1 -1
- package/dist/src/binder/references.js +85 -3
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/binder/types.d.ts +32 -0
- package/dist/src/binder/types.js.map +1 -1
- package/dist/src/canonical.d.ts +29 -0
- package/dist/src/canonical.js +35 -0
- package/dist/src/canonical.js.map +1 -0
- package/dist/src/checker/assignability.d.ts +13 -0
- package/dist/src/checker/assignability.js +146 -0
- package/dist/src/checker/assignability.js.map +1 -0
- package/dist/src/checker/calls.d.ts +13 -0
- package/dist/src/checker/calls.js +127 -0
- package/dist/src/checker/calls.js.map +1 -0
- package/dist/src/checker/checker.d.ts +26 -0
- package/dist/src/checker/checker.js +31 -0
- package/dist/src/checker/checker.js.map +1 -0
- package/dist/src/checker/declarations.d.ts +9 -0
- package/dist/src/checker/declarations.js +15 -0
- package/dist/src/checker/declarations.js.map +1 -0
- package/dist/src/checker/flow.d.ts +21 -0
- package/dist/src/checker/flow.js +241 -0
- package/dist/src/checker/flow.js.map +1 -0
- package/dist/src/checker/globals.d.ts +9 -0
- package/dist/src/checker/globals.js +29 -0
- package/dist/src/checker/globals.js.map +1 -0
- package/dist/src/checker/source.d.ts +38 -0
- package/dist/src/checker/source.js +48 -0
- package/dist/src/checker/source.js.map +1 -0
- package/dist/src/checker/type-infer.d.ts +18 -0
- package/dist/src/checker/type-infer.js +173 -0
- package/dist/src/checker/type-infer.js.map +1 -0
- package/dist/src/checker/type-model.d.ts +73 -0
- package/dist/src/checker/type-model.js +151 -0
- package/dist/src/checker/type-model.js.map +1 -0
- package/dist/src/checker/type-system.d.ts +58 -0
- package/dist/src/checker/type-system.js +569 -0
- package/dist/src/checker/type-system.js.map +1 -0
- package/dist/src/checker/typecheck-types.d.ts +22 -0
- package/dist/src/checker/typecheck-types.js +109 -0
- package/dist/src/checker/typecheck-types.js.map +1 -0
- package/dist/src/checker/typecheck.d.ts +62 -0
- package/dist/src/checker/typecheck.js +574 -0
- package/dist/src/checker/typecheck.js.map +1 -0
- package/dist/src/checker/undefined.d.ts +14 -0
- package/dist/src/checker/undefined.js +32 -0
- package/dist/src/checker/undefined.js.map +1 -0
- package/dist/src/checker/walk.d.ts +10 -0
- package/dist/src/checker/walk.js +15 -0
- package/dist/src/checker/walk.js.map +1 -0
- package/dist/src/cli/help.d.ts +7 -0
- package/dist/src/cli/help.js +64 -0
- package/dist/src/cli/help.js.map +1 -0
- package/dist/src/cli/hints.js +13 -1
- package/dist/src/cli/hints.js.map +1 -1
- package/dist/src/cli/main.js +12 -48
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +8 -8
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +9 -4
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls/super.d.ts +9 -1
- package/dist/src/codegen/generator/calls/super.js +56 -5
- package/dist/src/codegen/generator/calls/super.js.map +1 -1
- package/dist/src/codegen/generator/context.d.ts +13 -2
- package/dist/src/codegen/generator/context.js +25 -19
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +2 -1
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.d.ts +4 -1
- package/dist/src/codegen/generator/expressions/primary.js +68 -8
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/generator.js +11 -1
- package/dist/src/codegen/generator/generator.js.map +1 -1
- package/dist/src/codegen/generator/module.d.ts +2 -0
- package/dist/src/codegen/generator/module.js +62 -26
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.d.ts +11 -1
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/statements/variables.js +20 -3
- package/dist/src/codegen/generator/statements/variables.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +2 -0
- package/dist/src/codegen/generator/tables.js +4 -0
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +2 -0
- package/dist/src/driver/build-key.js +1 -0
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +5 -1
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +16 -1
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/types.d.ts +12 -0
- package/dist/src/driver/compiler.d.ts +1 -1
- package/dist/src/driver/compiler.js +4 -0
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/fingerprint.js +2 -1
- package/dist/src/driver/fingerprint.js.map +1 -1
- package/dist/src/driver/frontend.d.ts +8 -6
- package/dist/src/driver/frontend.js +4 -0
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/options.d.ts +6 -0
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/extensions/catalog.js +2 -1
- package/dist/src/extensions/catalog.js.map +1 -1
- package/dist/src/extensions/gui/html.js +20 -6
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +63 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/media/index.d.ts +27 -0
- package/dist/src/extensions/media/index.js +60 -0
- package/dist/src/extensions/media/index.js.map +1 -0
- package/dist/src/extensions/registry.d.ts +50 -0
- package/dist/src/extensions/registry.js +26 -0
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.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/expressions.js +14 -1
- package/dist/src/parser/expressions.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 +29 -0
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/canonical.test.d.ts +1 -0
- package/dist/tests/canonical.test.js +19 -0
- package/dist/tests/canonical.test.js.map +1 -0
- package/dist/tests/checker/checker.test.d.ts +1 -0
- package/dist/tests/checker/checker.test.js +245 -0
- package/dist/tests/checker/checker.test.js.map +1 -0
- package/dist/tests/cli/check.test.js +20 -0
- package/dist/tests/cli/check.test.js.map +1 -1
- package/dist/tests/cli/hints.test.js +15 -0
- package/dist/tests/cli/hints.test.js.map +1 -1
- package/dist/tests/cli/process.test.js +12 -0
- package/dist/tests/cli/process.test.js.map +1 -1
- package/dist/tests/conformance/matrix.test.d.ts +6 -0
- package/dist/tests/conformance/matrix.test.js +23 -0
- package/dist/tests/conformance/matrix.test.js.map +1 -0
- package/dist/tests/conformance/test262/manifest.d.ts +115 -0
- package/dist/tests/conformance/test262/manifest.js +257 -0
- package/dist/tests/conformance/test262/manifest.js.map +1 -0
- package/dist/tests/conformance/test262.test.d.ts +11 -0
- package/dist/tests/conformance/test262.test.js +74 -0
- package/dist/tests/conformance/test262.test.js.map +1 -0
- package/dist/tests/docs/structure.test.js +9 -11
- package/dist/tests/docs/structure.test.js.map +1 -1
- package/dist/tests/e2e/child-process.test.js +3 -2
- package/dist/tests/e2e/child-process.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +21 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-objects-classes.test.js +54 -0
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/differential-syntax.test.d.ts +5 -0
- package/dist/tests/e2e/differential-syntax.test.js +95 -0
- package/dist/tests/e2e/differential-syntax.test.js.map +1 -0
- package/dist/tests/e2e/differential-values.test.js +15 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/gui-browser.test.d.ts +13 -0
- package/dist/tests/e2e/gui-browser.test.js +163 -0
- package/dist/tests/e2e/gui-browser.test.js.map +1 -0
- package/dist/tests/e2e/gui-example-browser.test.js +2 -2
- package/dist/tests/e2e/gui-example-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-example-canvas.test.js +8 -5
- package/dist/tests/e2e/gui-example-canvas.test.js.map +1 -1
- package/dist/tests/e2e/gui-example-svg.test.js +4 -3
- package/dist/tests/e2e/gui-example-svg.test.js.map +1 -1
- package/dist/tests/e2e/gui-example.test.js +4 -3
- package/dist/tests/e2e/gui-example.test.js.map +1 -1
- package/dist/tests/e2e/gui-helpers.d.ts +3 -0
- package/dist/tests/e2e/gui-helpers.js +6 -3
- package/dist/tests/e2e/gui-helpers.js.map +1 -1
- package/dist/tests/e2e/gui-media-disabled.test.d.ts +9 -0
- package/dist/tests/e2e/gui-media-disabled.test.js +42 -0
- package/dist/tests/e2e/gui-media-disabled.test.js.map +1 -0
- package/dist/tests/e2e/gui-media.test.d.ts +6 -4
- package/dist/tests/e2e/gui-media.test.js +20 -16
- package/dist/tests/e2e/gui-media.test.js.map +1 -1
- package/dist/tests/e2e/harness.d.ts +9 -0
- package/dist/tests/e2e/harness.js +14 -2
- package/dist/tests/e2e/harness.js.map +1 -1
- package/dist/tests/e2e/native-extensions.test.js +2 -1
- package/dist/tests/e2e/native-extensions.test.js.map +1 -1
- package/dist/tests/e2e/property-descriptors.test.js +20 -0
- package/dist/tests/e2e/property-descriptors.test.js.map +1 -1
- package/dist/tests/e2e/unicode-output.test.d.ts +16 -0
- package/dist/tests/e2e/unicode-output.test.js +67 -0
- package/dist/tests/e2e/unicode-output.test.js.map +1 -0
- package/dist/tests/e2e/weak-collections.test.js +16 -2
- package/dist/tests/e2e/weak-collections.test.js.map +1 -1
- package/dist/tests/extensions/media.test.d.ts +1 -0
- package/dist/tests/extensions/media.test.js +58 -0
- package/dist/tests/extensions/media.test.js.map +1 -0
- package/dist/tests/extensions/registry.test.js +8 -0
- package/dist/tests/extensions/registry.test.js.map +1 -1
- package/dist/tests/helpers.d.ts +1 -0
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/lexer/identifiers.test.js +12 -0
- package/dist/tests/lexer/identifiers.test.js.map +1 -1
- package/dist/tests/lexer/scanner.test.js +8 -0
- package/dist/tests/lexer/scanner.test.js.map +1 -1
- package/dist/tests/lexer/strings.test.js +30 -0
- package/dist/tests/lexer/strings.test.js.map +1 -1
- package/dist/tests/parser/declarations.test.js +20 -0
- package/dist/tests/parser/declarations.test.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/platform.d.ts +32 -0
- package/dist/tests/platform.js +40 -0
- package/dist/tests/platform.js.map +1 -0
- package/dist/tests/platform.test.d.ts +12 -0
- package/dist/tests/platform.test.js +51 -0
- package/dist/tests/platform.test.js.map +1 -0
- package/dist/tests/version.test.js +4 -4
- package/dist/tests/version.test.js.map +1 -1
- package/doc/ai/README.md +10 -4
- package/doc/ai/build-recipe.md +1 -0
- package/doc/ai/cli.md +18 -6
- package/doc/ai/contributing.md +59 -2
- package/doc/ai/extensions.md +46 -23
- package/doc/ai/language-support.md +25 -16
- package/doc/ai/troubleshooting.md +9 -0
- package/doc/ai/zh-CN/README.md +9 -4
- package/doc/ai/zh-CN/build-recipe.md +1 -0
- package/doc/ai/zh-CN/cli.md +14 -4
- package/doc/ai/zh-CN/contributing.md +49 -3
- package/doc/ai/zh-CN/extensions.md +29 -8
- package/doc/ai/zh-CN/language-support.md +23 -14
- package/doc/ai/zh-CN/troubleshooting.md +8 -0
- package/doc/gui/api.md +45 -0
- package/doc/gui/build.md +37 -21
- package/doc/gui/known-issues.md +17 -6
- package/doc/gui/media.md +26 -11
- package/doc/gui/runtime.md +18 -0
- package/doc/gui-scripts.md +7 -0
- package/doc/gui.md +43 -33
- package/doc/implemented/binder.md +2 -0
- package/doc/implemented/checker.md +117 -0
- package/doc/implemented/cli.md +13 -1
- package/doc/implemented/codegen.md +3 -2
- package/doc/implemented/driver.md +2 -2
- package/doc/implemented/operators.md +2 -1
- package/doc/implemented/parser.md +3 -2
- package/doc/implemented/pipeline.md +8 -1
- package/doc/implemented/stdlib.md +2 -1
- package/doc/implemented/tests.md +3 -1
- package/doc/implemented.md +2 -0
- package/doc/npm-package.md +417 -0
- package/doc/requirements.md +4 -1
- package/doc/support-matrix.md +83 -0
- package/doc/unimplemented/classes.md +3 -0
- package/doc/unimplemented/deviations.md +3 -2
- package/doc/unimplemented/toolchain.md +1 -1
- package/doc/unimplemented/types.md +24 -8
- package/doc/unimplemented.md +1 -1
- package/doc/zh-CN/gui/api.md +41 -0
- package/doc/zh-CN/gui/build.md +28 -16
- package/doc/zh-CN/gui/known-issues.md +13 -5
- package/doc/zh-CN/gui/media.md +21 -10
- package/doc/zh-CN/gui/runtime.md +16 -0
- package/doc/zh-CN/gui-scripts.md +5 -0
- package/doc/zh-CN/gui.md +37 -32
- package/doc/zh-CN/implemented/binder.md +2 -0
- package/doc/zh-CN/implemented/checker.md +99 -0
- package/doc/zh-CN/implemented/cli.md +12 -1
- package/doc/zh-CN/implemented/codegen.md +3 -2
- package/doc/zh-CN/implemented/driver.md +2 -2
- package/doc/zh-CN/implemented/operators.md +1 -1
- package/doc/zh-CN/implemented/parser.md +3 -2
- package/doc/zh-CN/implemented/pipeline.md +3 -1
- package/doc/zh-CN/implemented/stdlib.md +2 -1
- package/doc/zh-CN/implemented/tests.md +3 -1
- package/doc/zh-CN/implemented.md +2 -0
- package/doc/zh-CN/npm-package.md +391 -0
- package/doc/zh-CN/post/announce.md +47 -47
- package/doc/zh-CN/requirements.md +4 -1
- package/doc/zh-CN/support-matrix.md +82 -0
- package/doc/zh-CN/unimplemented/classes.md +3 -0
- package/doc/zh-CN/unimplemented/deviations.md +3 -2
- package/doc/zh-CN/unimplemented/toolchain.md +1 -1
- package/doc/zh-CN/unimplemented/types.md +16 -6
- package/doc/zh-CN/unimplemented.md +1 -1
- package/llms.txt +4 -1
- package/package.json +3 -1
- package/runtime/ext_gui/audio.cpp +316 -0
- package/runtime/ext_gui/browser.cpp +547 -0
- package/runtime/ext_gui/browser_escape.cpp +85 -0
- package/runtime/ext_gui/browser_loop.cpp +83 -0
- package/runtime/ext_gui/canvas.cpp +9 -3
- package/runtime/ext_gui/canvas_raster.cpp +19 -1
- package/runtime/ext_gui/dom_api.cpp +36 -0
- package/runtime/ext_gui/dom_api_document.cpp +96 -5
- package/runtime/ext_gui/dom_api_events.cpp +20 -0
- package/runtime/ext_gui/dom_api_internal.h +19 -0
- package/runtime/ext_gui/dom_api_proto.cpp +6 -0
- package/runtime/ext_gui/gui.cpp +90 -23
- package/runtime/ext_gui/gui_engine.h +44 -0
- package/runtime/ext_gui/gui_media.cpp +69 -2
- package/runtime/ext_gui/media.cpp +34 -488
- package/runtime/ext_gui/media.h +54 -19
- package/runtime/ext_gui/media_api.h +65 -0
- package/runtime/ext_gui/window.cpp +9 -0
- package/runtime/ext_media/media.cpp +507 -0
- package/runtime/ext_media/media_bridge.c +35 -0
- package/runtime/ext_node/path/path.c +7 -7
- package/runtime/ext_node/url/url.c +4 -2
- package/runtime/rt.h +15 -0
- package/runtime/xt_constructors.c +2 -1
- package/runtime/xt_containers/objects.inc +22 -2
- package/runtime/xt_io/exception.inc +4 -2
- package/runtime/xt_stdlib/math.inc +62 -0
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/objects.inc +14 -0
- package/scripts/build-gui.ts +6 -72
- package/scripts/build-media.ts +245 -0
- package/scripts/support-matrix.ts +167 -0
- package/src/ast/common.ts +2 -0
- package/src/ast/declarations.ts +12 -1
- package/src/ast/expressions.ts +6 -0
- package/src/ast/kinds.ts +2 -0
- package/src/binder/binder.ts +3 -0
- package/src/binder/declarations.ts +70 -0
- package/src/binder/references.ts +84 -3
- package/src/binder/types.ts +30 -0
- package/src/canonical.ts +37 -0
- package/src/checker/assignability.ts +134 -0
- package/src/checker/calls.ts +135 -0
- package/src/checker/checker.ts +47 -0
- package/src/checker/declarations.ts +26 -0
- package/src/checker/flow.ts +236 -0
- package/src/checker/globals.ts +40 -0
- package/src/checker/source.ts +53 -0
- package/src/checker/type-infer.ts +185 -0
- package/src/checker/type-model.ts +212 -0
- package/src/checker/type-system.ts +578 -0
- package/src/checker/typecheck-types.ts +112 -0
- package/src/checker/typecheck.ts +586 -0
- package/src/checker/undefined.ts +43 -0
- package/src/checker/walk.ts +16 -0
- package/src/cli/help.ts +65 -0
- package/src/cli/hints.ts +13 -1
- package/src/cli/main.ts +12 -49
- package/src/codegen/generator/calls/access.ts +8 -8
- package/src/codegen/generator/calls/invocation.ts +8 -5
- package/src/codegen/generator/calls/super.ts +67 -5
- package/src/codegen/generator/context.ts +31 -19
- package/src/codegen/generator/debug.ts +2 -1
- package/src/codegen/generator/expressions/primary.ts +84 -13
- package/src/codegen/generator/generator.ts +11 -1
- package/src/codegen/generator/module.ts +65 -24
- package/src/codegen/generator/state.ts +11 -1
- package/src/codegen/generator/statements/variables.ts +20 -3
- package/src/codegen/generator/tables.ts +5 -0
- package/src/driver/build-key.ts +3 -0
- package/src/driver/bundler/graph.ts +6 -2
- package/src/driver/bundler/merge.ts +14 -1
- package/src/driver/bundler/types.ts +13 -0
- package/src/driver/compiler.ts +5 -1
- package/src/driver/fingerprint.ts +2 -1
- package/src/driver/frontend.ts +13 -2
- package/src/driver/options.ts +6 -0
- package/src/driver/version.ts +1 -1
- package/src/extensions/catalog.ts +2 -1
- package/src/extensions/gui/html.ts +23 -10
- package/src/extensions/gui/index.ts +65 -0
- package/src/extensions/media/index.ts +67 -0
- package/src/extensions/registry.ts +72 -0
- package/src/index.ts +2 -0
- package/src/parser/declarations/classes.ts +7 -0
- package/src/parser/expressions.ts +13 -1
- package/src/parser/literals.ts +6 -2
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import type { SourceFileNode } from "../../ast/nodes.js";
|
|
11
11
|
import type { DiagnosticBag } from "../../diagnostics/diagnostic.js";
|
|
12
|
+
import { bind } from "../../binder/binder.js";
|
|
13
|
+
import { checkProgram } from "../../checker/checker.js";
|
|
12
14
|
import { GeneratorContext } from "./context.js";
|
|
13
15
|
import { moduleMethods, type ModuleMethods } from "./module.js";
|
|
14
16
|
import { statementMethods, type StatementMethods } from "./statements.js";
|
|
@@ -45,6 +47,14 @@ export function generate(
|
|
|
45
47
|
diagnostics: DiagnosticBag,
|
|
46
48
|
options: CodegenOptions = {},
|
|
47
49
|
): CodegenResult {
|
|
48
|
-
|
|
50
|
+
// Bind once: the checker and the generator must see the same symbol table.
|
|
51
|
+
const binding = bind(sourceFile);
|
|
52
|
+
if (options.check !== false) {
|
|
53
|
+
checkProgram(sourceFile, binding, diagnostics, {
|
|
54
|
+
builtins: options.builtins ?? {},
|
|
55
|
+
globalValues: options.globalValues ?? {},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const generator = new Generator(sourceFile, diagnostics, options, binding);
|
|
49
59
|
return { ir: generator.run(), binding: generator.binding };
|
|
50
60
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import type { ClassInfo, FunctionInfo, SymbolInfo } from "../../binder/binder.js";
|
|
15
15
|
import { SymbolKind } from "../../binder/binder.js";
|
|
16
16
|
import { i64, XT_UNDEFINED } from "../values.js";
|
|
17
|
+
import { ARTIFACT_LINE_ENDING, artifactPath } from "../../canonical.js";
|
|
17
18
|
import { RUNTIME_DECLARATIONS, type FunctionState } from "./state.js";
|
|
18
19
|
import { propertyNameText } from "./tables.js";
|
|
19
20
|
import type { Generator } from "./generator.js";
|
|
@@ -44,6 +45,8 @@ export interface ModuleMethods {
|
|
|
44
45
|
classGlobal(this: Generator, classInfo: ClassInfo): string;
|
|
45
46
|
emitClassReference(this: Generator, classInfo: ClassInfo): string;
|
|
46
47
|
emitClassSetup(this: Generator, classInfo: ClassInfo): void;
|
|
48
|
+
memberKey(this: Generator, method: FunctionInfo): string;
|
|
49
|
+
emitMemberDefine(this: Generator, target: string, method: FunctionInfo, key: string, fnValue: string): void;
|
|
47
50
|
emitDefaultParameter(this: Generator, symbol: SymbolInfo, value: string, initializer: Expression): void;
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -75,7 +78,7 @@ export const moduleMethods: ModuleMethods = {
|
|
|
75
78
|
// the self-hosting fixpoint) is identical whether the compiler runs on
|
|
76
79
|
// Node (which uses `\` on Windows) or as a compiled binary (which always
|
|
77
80
|
// produces `/`).
|
|
78
|
-
const sourceName = this.sourceFile.fileName
|
|
81
|
+
const sourceName = artifactPath(this.sourceFile.fileName);
|
|
79
82
|
const header = [
|
|
80
83
|
"; ModuleID = 'xbintsc'",
|
|
81
84
|
"source_filename = \"" + sourceName + "\"",
|
|
@@ -93,7 +96,7 @@ export const moduleMethods: ModuleMethods = {
|
|
|
93
96
|
...this.functions,
|
|
94
97
|
"",
|
|
95
98
|
...this.debugMetadataLines(),
|
|
96
|
-
].join(
|
|
99
|
+
].join(ARTIFACT_LINE_ENDING);
|
|
97
100
|
},
|
|
98
101
|
|
|
99
102
|
// -- module level --------------------------------------------------------
|
|
@@ -149,7 +152,7 @@ export const moduleMethods: ModuleMethods = {
|
|
|
149
152
|
/* Normalise separators like `source_filename`: the compiler may run under
|
|
150
153
|
* Node (`\`) or as a self-hosted binary (`/`), and the IR must stay
|
|
151
154
|
* byte-identical across the two. */
|
|
152
|
-
const filePointer = this.internStatic(this.fileNameOf(fn.node)
|
|
155
|
+
const filePointer = this.internStatic(artifactPath(this.fileNameOf(fn.node)));
|
|
153
156
|
this.emit(
|
|
154
157
|
` call void @xt_stack_push(i8* ${namePointer}, i8* ${filePointer}, i32 ${this.lineOf(fn.node)})`,
|
|
155
158
|
);
|
|
@@ -267,7 +270,7 @@ export const moduleMethods: ModuleMethods = {
|
|
|
267
270
|
? state.escapePointers.map((ptr) => ` call void asm sideeffect "", "r"(i64* ${ptr})`)
|
|
268
271
|
: [];
|
|
269
272
|
const lines = [...state.allocas.map((a) => ` ${a}`), ...escapes, ...state.buffer];
|
|
270
|
-
this.functions.push([header, ...lines, "}", ""].join(
|
|
273
|
+
this.functions.push([header, ...lines, "}", ""].join(ARTIFACT_LINE_ENDING));
|
|
271
274
|
},
|
|
272
275
|
|
|
273
276
|
emitMain(): void {
|
|
@@ -307,7 +310,7 @@ export const moduleMethods: ModuleMethods = {
|
|
|
307
310
|
" ret i32 0",
|
|
308
311
|
"}",
|
|
309
312
|
"",
|
|
310
|
-
].join(
|
|
313
|
+
].join(ARTIFACT_LINE_ENDING),
|
|
311
314
|
);
|
|
312
315
|
},
|
|
313
316
|
|
|
@@ -346,18 +349,23 @@ export const moduleMethods: ModuleMethods = {
|
|
|
346
349
|
const globalName = this.classGlobal(classInfo);
|
|
347
350
|
const proto = this.reg();
|
|
348
351
|
this.emit(` ${proto} = call i64 @xt_object_new()`);
|
|
352
|
+
/* The parent constructor value, emitted once: it is used both for the
|
|
353
|
+
* instance prototype and for static inheritance (`Dog.kind` sees
|
|
354
|
+
* `Animal.kind`), and evaluating `extends mixin()` twice would run the
|
|
355
|
+
* expression twice. */
|
|
356
|
+
let parentValue: string | undefined;
|
|
349
357
|
if (classInfo.parentExpression) {
|
|
350
358
|
// `extends Error` / `extends TypeError` / other host builtins: chain the
|
|
351
359
|
// subclass prototype onto the builtin's prototype so `instanceof` works.
|
|
352
360
|
const parent = classInfo.parentExpression;
|
|
353
361
|
const errorName = this.errorFamilyName(parent);
|
|
362
|
+
parentValue = this.emitExpression(parent);
|
|
354
363
|
if (errorName) {
|
|
355
364
|
const nameValue = this.stringValue(errorName);
|
|
356
365
|
const parentProto = this.reg();
|
|
357
366
|
this.emit(` ${parentProto} = call i64 @xt_error_prototype(i64 ${nameValue})`);
|
|
358
367
|
this.emit(` call i64 @xt_object_set_prototype(i64 ${proto}, i64 ${parentProto})`);
|
|
359
368
|
} else {
|
|
360
|
-
const parentValue = this.emitExpression(parent);
|
|
361
369
|
const parentProto = this.reg();
|
|
362
370
|
this.emit(` ${parentProto} = call i64 @xt_function_get_prototype(i64 ${parentValue})`);
|
|
363
371
|
this.emit(` call i64 @xt_object_set_prototype(i64 ${proto}, i64 ${parentProto})`);
|
|
@@ -365,36 +373,69 @@ export const moduleMethods: ModuleMethods = {
|
|
|
365
373
|
}
|
|
366
374
|
for (const method of classInfo.methods) {
|
|
367
375
|
const fnValue = this.emitClosureValue(method);
|
|
368
|
-
const key = method
|
|
369
|
-
|
|
370
|
-
: this.stringValue(method.name);
|
|
371
|
-
const accessor = (method.node as { accessor?: "get" | "set" }).accessor;
|
|
372
|
-
if (accessor === "get") {
|
|
373
|
-
this.emit(` call i64 @xt_object_define_getter(i64 ${proto}, i64 ${key}, i64 ${fnValue})`);
|
|
374
|
-
} else if (accessor === "set") {
|
|
375
|
-
this.emit(` call i64 @xt_object_define_setter(i64 ${proto}, i64 ${key}, i64 ${fnValue})`);
|
|
376
|
-
} else {
|
|
377
|
-
this.emit(` call i64 @xt_set(i64 ${proto}, i64 ${key}, i64 ${fnValue})`);
|
|
378
|
-
}
|
|
376
|
+
const key = this.memberKey(method);
|
|
377
|
+
this.emitMemberDefine(proto, method, key, fnValue);
|
|
379
378
|
}
|
|
380
379
|
const ctor = this.emitClosureValue(classInfo.ctor!);
|
|
381
380
|
this.emit(` call i64 @xt_function_set_prototype(i64 ${ctor}, i64 ${proto})`);
|
|
381
|
+
/* Static members are inherited through the constructor's property bag. */
|
|
382
|
+
if (parentValue) {
|
|
383
|
+
this.emit(` call i64 @xt_object_set_prototype(i64 ${ctor}, i64 ${parentValue})`);
|
|
384
|
+
}
|
|
385
|
+
/* `A.prototype.constructor === A`: the standard property, and what
|
|
386
|
+
* `new this.constructor()` (Three.js `Matrix3.clone`, …) relies on. The
|
|
387
|
+
* hidden `__ctor` beside it is the internal hook `super(...)` and the
|
|
388
|
+
* implicit derived constructor read; keeping both means `constructor` can
|
|
389
|
+
* be overwritten by user code without breaking inheritance. */
|
|
382
390
|
const ctorKey = this.stringValue("__ctor");
|
|
383
391
|
this.emit(` call i64 @xt_set(i64 ${proto}, i64 ${ctorKey}, i64 ${ctor})`);
|
|
392
|
+
const constructorKey = this.stringValue("constructor");
|
|
393
|
+
this.emit(` call i64 @xt_set(i64 ${proto}, i64 ${constructorKey}, i64 ${ctor})`);
|
|
394
|
+
/* Publish the constructor before static fields and blocks run: they may
|
|
395
|
+
* refer to the class by name (`static { A.count = 1 }`), and by then the
|
|
396
|
+
* class binding is already initialised in JavaScript. */
|
|
397
|
+
this.emit(` store i64 ${ctor}, i64* ${globalName}`);
|
|
384
398
|
for (const method of classInfo.statics) {
|
|
385
399
|
const fnValue = this.emitClosureValue(method);
|
|
386
|
-
const key = method
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
this.
|
|
400
|
+
const key = this.memberKey(method);
|
|
401
|
+
/* `static get x()` / `static set x(v)` are accessors on the constructor
|
|
402
|
+
* value, not plain data properties. */
|
|
403
|
+
this.emitMemberDefine(ctor, method, key, fnValue);
|
|
390
404
|
}
|
|
391
|
-
for (const
|
|
392
|
-
if (
|
|
405
|
+
for (const entry of classInfo.staticInit) {
|
|
406
|
+
if (entry.kind === "block") {
|
|
407
|
+
/* `static { ... }` blocks run once, in order, with `this` bound to the
|
|
408
|
+
* class constructor. They are compiled as static methods and called
|
|
409
|
+
* immediately, which gives them their own scope and a normal `this`. */
|
|
410
|
+
const fnValue = this.emitClosureValue(entry.fn);
|
|
411
|
+
this.emit(` call i64 @xt_call_with_this(i64 ${fnValue}, i64 ${ctor}, i32 0, i64* null)`);
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
const field = entry.field;
|
|
393
415
|
const key = this.stringValue(field.name);
|
|
394
416
|
const value = field.initializer ? this.emitExpression(field.initializer) : i64(XT_UNDEFINED);
|
|
395
417
|
this.emit(` call i64 @xt_set(i64 ${ctor}, i64 ${key}, i64 ${value})`);
|
|
396
418
|
}
|
|
397
|
-
|
|
419
|
+
},
|
|
420
|
+
|
|
421
|
+
/** The property key of a class member: evaluated when computed. */
|
|
422
|
+
memberKey(method: FunctionInfo): string {
|
|
423
|
+
return method.computedKey
|
|
424
|
+
? this.emitExpression(method.computedKey)
|
|
425
|
+
: this.stringValue(method.name);
|
|
426
|
+
},
|
|
427
|
+
|
|
428
|
+
/** Install a class member as a data property, or as an accessor when it was
|
|
429
|
+
* declared with `get` / `set`. */
|
|
430
|
+
emitMemberDefine(target: string, method: FunctionInfo, key: string, fnValue: string): void {
|
|
431
|
+
const accessor = (method.node as { accessor?: "get" | "set" }).accessor;
|
|
432
|
+
if (accessor === "get") {
|
|
433
|
+
this.emit(` call i64 @xt_object_define_getter(i64 ${target}, i64 ${key}, i64 ${fnValue})`);
|
|
434
|
+
} else if (accessor === "set") {
|
|
435
|
+
this.emit(` call i64 @xt_object_define_setter(i64 ${target}, i64 ${key}, i64 ${fnValue})`);
|
|
436
|
+
} else {
|
|
437
|
+
this.emit(` call i64 @xt_set(i64 ${target}, i64 ${key}, i64 ${fnValue})`);
|
|
438
|
+
}
|
|
398
439
|
},
|
|
399
440
|
|
|
400
441
|
emitDefaultParameter(symbol: SymbolInfo, value: string, initializer: Expression): void {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import type { FunctionInfo } from "../../binder/binder.js";
|
|
6
6
|
import type { BindResult } from "../../binder/binder.js";
|
|
7
|
-
import type { BuiltinFunction, ExtensionModule } from "../../extensions/registry.js";
|
|
7
|
+
import type { BuiltinFunction, ExtensionModule, GlobalValue } from "../../extensions/registry.js";
|
|
8
8
|
import type { Block } from "../../ast/nodes.js";
|
|
9
9
|
|
|
10
10
|
export interface Slot {
|
|
@@ -70,6 +70,8 @@ export interface CodegenResult {
|
|
|
70
70
|
export interface CodegenOptions {
|
|
71
71
|
/** Global names supplied by registered extensions. */
|
|
72
72
|
readonly builtins?: Readonly<Record<string, BuiltinFunction>>;
|
|
73
|
+
/** Global *values* supplied by registered extensions (`window`, `document`). */
|
|
74
|
+
readonly globalValues?: Readonly<Record<string, GlobalValue>>;
|
|
73
75
|
/** Importable modules supplied by registered extensions. */
|
|
74
76
|
readonly modules?: Readonly<Record<string, ExtensionModule>>;
|
|
75
77
|
/**
|
|
@@ -91,6 +93,14 @@ export interface CodegenOptions {
|
|
|
91
93
|
* debugging; `xbintsc build --debug` turns it on.
|
|
92
94
|
*/
|
|
93
95
|
readonly debug?: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Run the semantic checker before lowering (default **true**). It reports
|
|
98
|
+
* unresolved names, redeclarations and call-arity mismatches; `--no-check`
|
|
99
|
+
* (or `check: false` programmatically) restores the previous permissive
|
|
100
|
+
* behaviour. Code generation skips its own unresolved-name diagnostic while
|
|
101
|
+
* the checker is on, so the error is reported exactly once.
|
|
102
|
+
*/
|
|
103
|
+
readonly check?: boolean;
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
@@ -107,17 +107,34 @@ export const variableStatementMethods: VariableStatementMethods = {
|
|
|
107
107
|
}
|
|
108
108
|
},
|
|
109
109
|
|
|
110
|
-
/**
|
|
110
|
+
/**
|
|
111
|
+
* `x = fallback` in a binding pattern: only apply when `x` is `undefined`.
|
|
112
|
+
*
|
|
113
|
+
* The initializer is emitted inside its own block, so it is evaluated *only*
|
|
114
|
+
* when the property is missing — the specification's order. A `select` cannot
|
|
115
|
+
* do that: it would evaluate the fallback unconditionally, which runs side
|
|
116
|
+
* effects and throws for defaults like `canvas = createCanvasElement()` that
|
|
117
|
+
* assume they are only reached when the caller passed nothing.
|
|
118
|
+
*/
|
|
111
119
|
emitBindingDefault(value: string, initializer: Expression): string {
|
|
112
|
-
const
|
|
120
|
+
const slot = this.alloca();
|
|
121
|
+
this.emit(` store i64 ${value}, i64* ${slot}`);
|
|
113
122
|
const isUndefined = this.reg();
|
|
114
123
|
this.emit(` ${isUndefined} = call i64 @xt_seq(i64 ${value}, i64 ${i64(XT_UNDEFINED)})`);
|
|
115
124
|
const truthy = this.reg();
|
|
116
125
|
this.emit(` ${truthy} = call i32 @xt_truthy(i64 ${isUndefined})`);
|
|
117
126
|
const condition = this.reg();
|
|
118
127
|
this.emit(` ${condition} = icmp ne i32 ${truthy}, 0`);
|
|
128
|
+
const defaultLabel = this.label("bind.default");
|
|
129
|
+
const endLabel = this.label("bind.end");
|
|
130
|
+
this.terminate(`br i1 ${condition}, label %${defaultLabel}, label %${endLabel}`);
|
|
131
|
+
this.startBlock(defaultLabel);
|
|
132
|
+
const fallback = this.emitExpression(initializer);
|
|
133
|
+
this.emit(` store i64 ${fallback}, i64* ${slot}`);
|
|
134
|
+
this.terminate(`br label %${endLabel}`);
|
|
135
|
+
this.startBlock(endLabel);
|
|
119
136
|
const result = this.reg();
|
|
120
|
-
this.emit(` ${result} =
|
|
137
|
+
this.emit(` ${result} = load i64, i64* ${slot}`);
|
|
121
138
|
return result;
|
|
122
139
|
},
|
|
123
140
|
|
|
@@ -283,6 +283,11 @@ export const SYMBOL_WELL_KNOWN = new Set<string>([
|
|
|
283
283
|
"unscopables",
|
|
284
284
|
]);
|
|
285
285
|
|
|
286
|
+
/** Namespaces that also exist as a first-class object value (`Math.cos`). */
|
|
287
|
+
export const NAMESPACE_VALUES: Record<string, string> = {
|
|
288
|
+
Math: "xt_math_object",
|
|
289
|
+
};
|
|
290
|
+
|
|
286
291
|
/** Namespace identifiers whose property access maps to a runtime getter. */
|
|
287
292
|
export const NAMESPACE_PROPERTIES: Record<string, string> = {
|
|
288
293
|
process: "xt_process_get",
|
package/src/driver/build-key.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface CacheKeyInput {
|
|
|
27
27
|
readonly app: AppConfig;
|
|
28
28
|
readonly debug: boolean;
|
|
29
29
|
readonly lto: boolean;
|
|
30
|
+
/** Whether the semantic checker ran (default true). */
|
|
31
|
+
readonly check?: boolean;
|
|
30
32
|
readonly pgo?: PgoMode;
|
|
31
33
|
readonly pgoDir: string;
|
|
32
34
|
}
|
|
@@ -49,6 +51,7 @@ export function buildCacheKey(input: CacheKeyInput): string {
|
|
|
49
51
|
app.bundleId ?? "",
|
|
50
52
|
String(input.debug),
|
|
51
53
|
String(input.lto),
|
|
54
|
+
String(input.check !== false),
|
|
52
55
|
pgo ?? "",
|
|
53
56
|
pgo ? input.pgoDir : "",
|
|
54
57
|
]);
|
|
@@ -14,7 +14,7 @@ import { Parser } from "../../parser/parser.js";
|
|
|
14
14
|
import type { AssetLoader } from "../../extensions/registry.js";
|
|
15
15
|
import { classifyDependency } from "./resolve.js";
|
|
16
16
|
import { collectRequireSites, isNodeModulesPath, usesCommonJS } from "./commonjs.js";
|
|
17
|
-
import type { ModuleRecord } from "./types.js";
|
|
17
|
+
import type { ModuleRecord, OriginRange } from "./types.js";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* True when an import has no runtime binding, so it is not a module edge:
|
|
@@ -109,9 +109,12 @@ export function loadGraph(
|
|
|
109
109
|
* module before it is parsed. The core only sees the transformed text. */
|
|
110
110
|
const loader = assetLoaders[extname(path).toLowerCase()];
|
|
111
111
|
let text = raw;
|
|
112
|
+
let originRanges: readonly OriginRange[] | undefined;
|
|
112
113
|
if (loader) {
|
|
113
114
|
try {
|
|
114
|
-
|
|
115
|
+
const loaded = loader(path, raw);
|
|
116
|
+
text = loaded.moduleSource;
|
|
117
|
+
originRanges = loaded.sourceRanges;
|
|
115
118
|
} catch (error) {
|
|
116
119
|
diagnostics.error(
|
|
117
120
|
DiagnosticCode.CodegenError,
|
|
@@ -136,6 +139,7 @@ export function loadGraph(
|
|
|
136
139
|
originalNames: new Map(),
|
|
137
140
|
finalNames: new Map(),
|
|
138
141
|
commonjs: false,
|
|
142
|
+
originRanges,
|
|
139
143
|
};
|
|
140
144
|
// `require` / `module` / `exports` are only honoured inside `node_modules`,
|
|
141
145
|
// so user code keeps its ESM-only diagnostic.
|
|
@@ -176,9 +176,22 @@ export function bundleModules(
|
|
|
176
176
|
* diagnostic can name the right file and line instead of pointing into the
|
|
177
177
|
* entry module (whose text happens to start at the same offsets). */
|
|
178
178
|
const origins = new Map<object, string>();
|
|
179
|
+
/* A synthesized module (an extension asset loader such as the `gui` `.html`
|
|
180
|
+
* transform) may contain spans copied from another file — a `<script
|
|
181
|
+
* src="app.js">` body, say. Nodes inside such a span keep that file, so a
|
|
182
|
+
* diagnostic points at real source and a plain-`.js` script stays exempt
|
|
183
|
+
* from the type checker. */
|
|
184
|
+
const originOf = (record: ModuleRecord, node: Node): string => {
|
|
185
|
+
const ranges = record.originRanges;
|
|
186
|
+
if (ranges === undefined) return record.path;
|
|
187
|
+
for (const range of ranges) {
|
|
188
|
+
if (node.start >= range.start && node.end <= range.end) return range.file;
|
|
189
|
+
}
|
|
190
|
+
return record.path;
|
|
191
|
+
};
|
|
179
192
|
const trackOrigin = (record: ModuleRecord, root: Node): void => {
|
|
180
193
|
const visit = (node: Node): void => {
|
|
181
|
-
origins.set(node, record
|
|
194
|
+
origins.set(node, originOf(record, node));
|
|
182
195
|
const fields = node as unknown as Record<string, unknown>;
|
|
183
196
|
for (const key of Object.keys(fields)) {
|
|
184
197
|
if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
|
|
@@ -5,6 +5,13 @@
|
|
|
5
5
|
import type { SourceFileNode } from "../../ast/nodes.js";
|
|
6
6
|
import type { BindResult } from "../../binder/binder.js";
|
|
7
7
|
|
|
8
|
+
/** A `[start, end)` span of a synthesized module that came from `file`. */
|
|
9
|
+
export interface OriginRange {
|
|
10
|
+
readonly start: number;
|
|
11
|
+
readonly end: number;
|
|
12
|
+
readonly file: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
8
15
|
export interface ModuleRecord {
|
|
9
16
|
readonly path: string;
|
|
10
17
|
readonly text: string;
|
|
@@ -25,6 +32,12 @@ export interface ModuleRecord {
|
|
|
25
32
|
commonjs: boolean;
|
|
26
33
|
/** Synthetic `module` object for a CommonJS module (`<prefix>$cjs_module`). */
|
|
27
34
|
cjsModule?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Spans of a *synthesized* module text that were copied from another file
|
|
37
|
+
* (an extension asset loader's `sourceRanges`). Nodes inside one keep that
|
|
38
|
+
* file as their origin instead of `path`.
|
|
39
|
+
*/
|
|
40
|
+
originRanges?: readonly OriginRange[];
|
|
28
41
|
}
|
|
29
42
|
|
|
30
43
|
export interface BundleResult {
|
package/src/driver/compiler.ts
CHANGED
|
@@ -31,7 +31,7 @@ import { buildCacheKey } from "./build-key.js";
|
|
|
31
31
|
import type { BuildOptions, BuildResult, EmitKind, PhaseTiming } from "./options.js";
|
|
32
32
|
|
|
33
33
|
export { COMPILER_VERSION } from "./version.js";
|
|
34
|
-
export { compileString, compileEntry, parseEntry, type ParsedEntry } from "./frontend.js";
|
|
34
|
+
export { compileString, compileEntry, parseEntry, type FrontendOptions, type ParsedEntry } from "./frontend.js";
|
|
35
35
|
export { RUNTIME_SOURCES, type RuntimeObjects } from "./runtime-objects.js";
|
|
36
36
|
export type { BuildOptions, BuildResult, CompileStringResult, EmitKind, PhaseTiming } from "./options.js";
|
|
37
37
|
|
|
@@ -69,6 +69,7 @@ function executableName(entry: string, outDir: string, explicit: string | undefi
|
|
|
69
69
|
export function build(entryPath: string, options: BuildOptions = {}): BuildResult {
|
|
70
70
|
const runner = options.runner ?? realRunner;
|
|
71
71
|
const registry = options.extensions ?? createDefaultRegistry();
|
|
72
|
+
registry.validate();
|
|
72
73
|
const outDir = resolve(options.outDir ?? join(process.cwd(), "build"));
|
|
73
74
|
const cacheDir = resolve(options.cacheDir ?? defaultCacheDir());
|
|
74
75
|
const emit: EmitKind = options.emit ?? "exe";
|
|
@@ -127,6 +128,7 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
127
128
|
app,
|
|
128
129
|
debug: options.debug === true,
|
|
129
130
|
lto,
|
|
131
|
+
check: options.check !== false,
|
|
130
132
|
pgo,
|
|
131
133
|
pgoDir,
|
|
132
134
|
});
|
|
@@ -148,9 +150,11 @@ export function build(entryPath: string, options: BuildOptions = {}): BuildResul
|
|
|
148
150
|
const codegenStarted = Date.now();
|
|
149
151
|
const { ir } = generate(parsed.sourceFile, diagnostics, {
|
|
150
152
|
builtins: registry.builtins(),
|
|
153
|
+
globalValues: registry.globalValues(),
|
|
151
154
|
modules: registry.modules(),
|
|
152
155
|
moduleHints: registry.moduleHints(),
|
|
153
156
|
debug: options.debug === true,
|
|
157
|
+
check: options.check !== false,
|
|
154
158
|
});
|
|
155
159
|
timings.push({ phase: "codegen", ms: Date.now() - codegenStarted });
|
|
156
160
|
|
|
@@ -11,6 +11,7 @@ import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
|
11
11
|
import { dirname, join, relative, resolve } from "node:path";
|
|
12
12
|
import { fileURLToPath } from "node:url";
|
|
13
13
|
import type { ExtensionRegistry } from "../extensions/registry.js";
|
|
14
|
+
import { artifactPath } from "../canonical.js";
|
|
14
15
|
import { hashParts } from "./cache.js";
|
|
15
16
|
|
|
16
17
|
/** Runtime sources, headers and `#include`d `.inc` fragments, plus prebuilt archives. */
|
|
@@ -56,7 +57,7 @@ export function compilerFingerprint(): string {
|
|
|
56
57
|
if (entry.isDirectory()) {
|
|
57
58
|
walk(full);
|
|
58
59
|
} else if (entry.name.endsWith(".ts")) {
|
|
59
|
-
parts.push(relative(sourceRoot, full)
|
|
60
|
+
parts.push(artifactPath(relative(sourceRoot, full)), readFileSync(full, "utf8"));
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
};
|
package/src/driver/frontend.ts
CHANGED
|
@@ -32,6 +32,13 @@ function externalModuleSpecifiers(registry: ExtensionRegistry): Set<string> {
|
|
|
32
32
|
]);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
/** Front-end switches shared by `compileString` and `compileEntry`. */
|
|
36
|
+
export interface FrontendOptions {
|
|
37
|
+
readonly debug?: boolean;
|
|
38
|
+
/** Run the semantic checker (default true; `--no-check` disables it). */
|
|
39
|
+
readonly check?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
35
42
|
/** A parsed (and, for module entries, already bundled) entry file. */
|
|
36
43
|
export interface ParsedEntry {
|
|
37
44
|
readonly absoluteEntry: string;
|
|
@@ -78,7 +85,7 @@ export function compileString(
|
|
|
78
85
|
source: string,
|
|
79
86
|
fileName = "input.ts",
|
|
80
87
|
extensions?: ExtensionRegistry,
|
|
81
|
-
options:
|
|
88
|
+
options: FrontendOptions = {},
|
|
82
89
|
): CompileStringResult {
|
|
83
90
|
const file = new SourceFile(fileName, source);
|
|
84
91
|
const diagnostics = new DiagnosticBag();
|
|
@@ -90,9 +97,11 @@ export function compileString(
|
|
|
90
97
|
if (diagnostics.hasErrors) return { ir: "", diagnostics: diagnostics.diagnostics };
|
|
91
98
|
const { ir } = generate(sourceFile, diagnostics, {
|
|
92
99
|
builtins: registry.builtins(),
|
|
100
|
+
globalValues: registry.globalValues(),
|
|
93
101
|
modules: registry.modules(),
|
|
94
102
|
moduleHints: registry.moduleHints(),
|
|
95
103
|
debug: options.debug === true,
|
|
104
|
+
check: options.check !== false,
|
|
96
105
|
});
|
|
97
106
|
return { ir, diagnostics: diagnostics.diagnostics };
|
|
98
107
|
}
|
|
@@ -104,7 +113,7 @@ export function compileString(
|
|
|
104
113
|
export function compileEntry(
|
|
105
114
|
entryPath: string,
|
|
106
115
|
extensions?: ExtensionRegistry,
|
|
107
|
-
options:
|
|
116
|
+
options: FrontendOptions = {},
|
|
108
117
|
): CompileStringResult {
|
|
109
118
|
const registry = extensions ?? createDefaultRegistry();
|
|
110
119
|
const diagnostics = new DiagnosticBag();
|
|
@@ -112,9 +121,11 @@ export function compileEntry(
|
|
|
112
121
|
if (diagnostics.hasErrors) return { ir: "", diagnostics: diagnostics.diagnostics };
|
|
113
122
|
const { ir } = generate(parsed.sourceFile, diagnostics, {
|
|
114
123
|
builtins: registry.builtins(),
|
|
124
|
+
globalValues: registry.globalValues(),
|
|
115
125
|
modules: registry.modules(),
|
|
116
126
|
moduleHints: registry.moduleHints(),
|
|
117
127
|
debug: options.debug === true,
|
|
128
|
+
check: options.check !== false,
|
|
118
129
|
});
|
|
119
130
|
return { ir, diagnostics: diagnostics.diagnostics };
|
|
120
131
|
}
|
package/src/driver/options.ts
CHANGED
|
@@ -35,6 +35,12 @@ export interface BuildOptions {
|
|
|
35
35
|
readonly app?: AppConfig;
|
|
36
36
|
/** Emit LLVM debug metadata so `-g` produces DWARF/CodeView (default false). */
|
|
37
37
|
readonly debug?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Run the semantic checker before lowering (default true). `--no-check`
|
|
40
|
+
* disables it; the incremental cache keys on this flag, so a checked and an
|
|
41
|
+
* unchecked build of the same source cannot reuse each other's artifacts.
|
|
42
|
+
*/
|
|
43
|
+
readonly check?: boolean;
|
|
38
44
|
/** Compile the program and runtime to LTO bitcode and link with lld. */
|
|
39
45
|
readonly lto?: boolean;
|
|
40
46
|
/**
|
package/src/driver/version.ts
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
import type { Extension } from "./registry.js";
|
|
14
14
|
import { nodeExtension } from "./node/index.js";
|
|
15
15
|
import { guiExtension } from "./gui/index.js";
|
|
16
|
+
import { mediaExtension } from "./media/index.js";
|
|
16
17
|
|
|
17
18
|
/** Every extension bundled with xbintsc, in registration order. */
|
|
18
19
|
export function bundledExtensions(): readonly Extension[] {
|
|
19
|
-
return [nodeExtension, guiExtension];
|
|
20
|
+
return [nodeExtension, guiExtension, mediaExtension];
|
|
20
21
|
}
|
|
@@ -35,8 +35,9 @@ import {
|
|
|
35
35
|
import { DiagnosticBag } from "../../diagnostics/diagnostic.js";
|
|
36
36
|
import { SourceFile } from "../../diagnostics/source.js";
|
|
37
37
|
import { Parser } from "../../parser/parser.js";
|
|
38
|
+
import { artifactPath } from "../../canonical.js";
|
|
38
39
|
import { hashString } from "../../driver/cache.js";
|
|
39
|
-
import type { AssetLoadResult } from "../registry.js";
|
|
40
|
+
import type { AssetLoadResult, AssetSourceRange } from "../registry.js";
|
|
40
41
|
|
|
41
42
|
/** Matches an inline `<script …>body</script>` element, attributes included. */
|
|
42
43
|
const SCRIPT_RE = /<script\b([^>]*)>([\s\S]*?)<\/script\s*>/gi;
|
|
@@ -80,7 +81,7 @@ function isExecutable(type: string | undefined, lang: string | undefined): boole
|
|
|
80
81
|
function rewriteSpecifier(htmlPath: string, scriptPath: string, specifier: string): string {
|
|
81
82
|
if (!specifier.startsWith(".")) return specifier;
|
|
82
83
|
const absolute = resolve(dirname(scriptPath), specifier);
|
|
83
|
-
let rel = relative(dirname(htmlPath), absolute)
|
|
84
|
+
let rel = artifactPath(relative(dirname(htmlPath), absolute));
|
|
84
85
|
if (!rel.startsWith(".")) rel = `./${rel}`;
|
|
85
86
|
return rel;
|
|
86
87
|
}
|
|
@@ -182,7 +183,10 @@ function resolveScriptPath(htmlPath: string, src: string): string {
|
|
|
182
183
|
|
|
183
184
|
/** Rewrite `<script>` bodies into registered AOT functions + an HTML string. */
|
|
184
185
|
export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
185
|
-
|
|
186
|
+
/* `file` is set for an external `<script src>`: its body keeps that file as
|
|
187
|
+
* the origin of every node, so a `.js` script stays untyped and diagnostics
|
|
188
|
+
* name the script, not the HTML page. */
|
|
189
|
+
const scripts: Array<{ id: string; body: string; file?: string }> = [];
|
|
186
190
|
const imports: string[] = [];
|
|
187
191
|
const importedText = new Set<string>();
|
|
188
192
|
const bound = new Set<string>();
|
|
@@ -212,7 +216,7 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
212
216
|
bound.add(name);
|
|
213
217
|
}
|
|
214
218
|
const id = hashString(compiled.body);
|
|
215
|
-
scripts.push({ id, body: compiled.body });
|
|
219
|
+
scripts.push({ id, body: compiled.body, file: scriptPath });
|
|
216
220
|
return `<script data-xt-id="${id}"></script>`;
|
|
217
221
|
}
|
|
218
222
|
|
|
@@ -225,12 +229,21 @@ export function loadHtmlAsset(path: string, source: string): AssetLoadResult {
|
|
|
225
229
|
});
|
|
226
230
|
|
|
227
231
|
const parts: string[] = [...imports];
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
const sourceRanges: AssetSourceRange[] = [];
|
|
233
|
+
/* Offset of the next part once joined with "\n", so a body's span in the
|
|
234
|
+
* generated module can be reported back as the file it was copied from. */
|
|
235
|
+
let offset = parts.reduce((total, part) => total + part.length + 1, 0);
|
|
236
|
+
for (const { id, body, file } of scripts) {
|
|
237
|
+
const header = `function __xt_script_${id}(window: any, document: any): void {\n`;
|
|
238
|
+
const part =
|
|
239
|
+
`${header}${body}\n}\n` + `__registerScript(${JSON.stringify(id)}, __xt_script_${id});`;
|
|
240
|
+
if (file !== undefined) {
|
|
241
|
+
sourceRanges.push({ start: offset + header.length, end: offset + header.length + body.length, file });
|
|
242
|
+
}
|
|
243
|
+
parts.push(part);
|
|
244
|
+
offset += part.length + 1;
|
|
233
245
|
}
|
|
234
246
|
parts.push(`export default ${JSON.stringify(html)};`);
|
|
235
|
-
|
|
247
|
+
const result: AssetLoadResult = { moduleSource: parts.join("\n") };
|
|
248
|
+
return sourceRanges.length > 0 ? { ...result, sourceRanges } : result;
|
|
236
249
|
}
|