xbintsc 0.7.0 → 0.7.7
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/references.js +13 -7
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/source.js +4 -0
- package/dist/src/checker/source.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 +4 -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 +82 -1
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- 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 +10 -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/primary.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +4 -24
- 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/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/state.js +4 -0
- package/dist/src/codegen/generator/state.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/concatenate.js +11 -4
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/graph.js +2 -2
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +11 -5
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +3 -0
- package/dist/src/driver/bundler/reexport-resolution.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/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +4 -0
- 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/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +53 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +20 -0
- package/dist/src/extensions/registry.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/tests/binder/binder.test.js +26 -4
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/checker/checker.test.js +16 -0
- package/dist/tests/checker/checker.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 +13 -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/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-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-modules.test.js +13 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- 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/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/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 +66 -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-events.test.js +89 -0
- package/dist/tests/e2e/gui-events.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-anisotropy.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.test.js +105 -0
- package/dist/tests/e2e/gui-webgl2-anisotropy.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-sampler-array.test.d.ts +11 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.test.js +117 -0
- package/dist/tests/e2e/gui-webgl2-sampler-array.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/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/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/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/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/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/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 +35 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/input.md +8 -0
- package/doc/gui/known-issues.md +43 -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 +1 -1
- package/doc/implemented/checker.md +9 -0
- package/doc/implemented/codegen.md +7 -0
- package/doc/implemented/parser.md +2 -1
- package/doc/implemented/runtime-core.md +9 -2
- package/doc/implemented/stdlib.md +10 -2
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/zh-CN/gui/api.md +27 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/input.md +7 -0
- package/doc/zh-CN/gui/known-issues.md +30 -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 +1 -1
- package/doc/zh-CN/implemented/checker.md +7 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- package/doc/zh-CN/implemented/parser.md +2 -1
- package/doc/zh-CN/implemented/runtime-core.md +9 -2
- package/doc/zh-CN/implemented/stdlib.md +6 -2
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- 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 +11 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api.cpp +4 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_events.cpp +2 -1
- package/runtime/ext_gui/dom_api_internal.h +11 -0
- package/runtime/ext_gui/dom_api_mutation.cpp +49 -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 +6 -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 +11 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +8 -1
- package/runtime/ext_gui/gui_engine.h +20 -2
- package/runtime/ext_gui/gui_events.cpp +31 -126
- package/runtime/ext_gui/gui_input.cpp +148 -0
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/pointer_lock.cpp +137 -0
- 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 +26 -170
- package/runtime/ext_gui/webgl_context.cpp +119 -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.h +4 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_glsl_scan.cpp +14 -0
- package/runtime/ext_gui/webgl_objects.h +18 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_shader.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 +11 -83
- package/runtime/ext_gui/window_diagnostics.cpp +94 -1
- package/runtime/rt.h +27 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +52 -60
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +88 -133
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_builtins.c +3 -1
- package/runtime/xt_constructors.c +1 -0
- package/runtime/xt_containers/access.inc +96 -11
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -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 +47 -79
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +4 -0
- package/runtime/xt_gc_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +1 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +32 -6
- 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_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_stdlib/dispatch.inc +7 -1
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/json_stringify.inc +1 -2
- 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/src/ast/common.ts +10 -0
- package/src/binder/references.ts +13 -7
- package/src/checker/source.ts +3 -0
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +5 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +87 -1
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +11 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/primary.ts +4 -27
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/state.ts +5 -0
- 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/concatenate.ts +12 -5
- package/src/driver/bundler/graph.ts +2 -2
- package/src/driver/bundler/merge.ts +11 -4
- package/src/driver/bundler/reexport-resolution.ts +2 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/frontend.ts +3 -4
- package/src/driver/runtime-objects.ts +4 -0
- 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 +55 -1
- package/src/extensions/registry.ts +20 -0
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
package/src/binder/references.ts
CHANGED
|
@@ -144,15 +144,21 @@ export const referenceMethods: ReferenceMethods = {
|
|
|
144
144
|
clauses: { expression?: Expression; statements: Statement[] }[];
|
|
145
145
|
};
|
|
146
146
|
this.bindNode(statement.expression, scope);
|
|
147
|
-
/*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
147
|
+
/* A switch body is a block scope of its own, so all `case` bodies
|
|
148
|
+
* share one scope *below* the enclosing one: a `let`/`const` written
|
|
149
|
+
* directly in a clause shadows an outer binding
|
|
150
|
+
* (`function f(t) { switch (…) { case 1: let t = … } }` is legal, and
|
|
151
|
+
* minified output relies on it) while two clauses declaring the same
|
|
152
|
+
* name still collide. The declarations have to be pre-declared before
|
|
153
|
+
* any clause is bound; without that a `const` declared directly in a
|
|
154
|
+
* `case` clause had no symbol and later phases crashed on it. */
|
|
155
|
+
const switchScope = this.createScope(ScopeKind.Block, node, scope);
|
|
156
|
+
this.scopes.set(node, switchScope);
|
|
151
157
|
for (const clause of statement.clauses) {
|
|
152
|
-
this.bindNode(clause.expression,
|
|
153
|
-
this.predeclareStatements(clause.statements,
|
|
158
|
+
this.bindNode(clause.expression, switchScope);
|
|
159
|
+
this.predeclareStatements(clause.statements, switchScope);
|
|
154
160
|
}
|
|
155
|
-
for (const clause of statement.clauses) this.bindStatements(clause.statements,
|
|
161
|
+
for (const clause of statement.clauses) this.bindStatements(clause.statements, switchScope);
|
|
156
162
|
return;
|
|
157
163
|
}
|
|
158
164
|
case SyntaxKind.BreakStatement:
|
package/src/checker/source.ts
CHANGED
|
@@ -42,6 +42,9 @@ export function isDependencyNode(sourceFile: SourceFileNode, node: Node): boolea
|
|
|
42
42
|
* reported, but no type, arity or property diagnostic is produced.
|
|
43
43
|
*/
|
|
44
44
|
export function isPlainJavaScriptNode(sourceFile: SourceFileNode, node: Node): boolean {
|
|
45
|
+
/* An inline `<script>` body in an HTML page (no `lang="ts"`): the bundler
|
|
46
|
+
* marks its nodes, because the origin file is the page, not a `.js` file. */
|
|
47
|
+
if (sourceFile.untypedNodes?.has(node)) return true;
|
|
45
48
|
const origin = sourceFile.origins?.get(node) ?? sourceFile.fileName;
|
|
46
49
|
return /\.(js|mjs|cjs|jsx)$/i.test(origin);
|
|
47
50
|
}
|
package/src/cli/main.ts
CHANGED
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { spawnSync } from "node:child_process";
|
|
16
|
-
import { readFileSync } from "node:fs";
|
|
17
16
|
import { dirname, resolve } from "node:path";
|
|
18
17
|
import { pathToFileURL } from "node:url";
|
|
19
18
|
import { formatDiagnostic, type Diagnostic } from "../diagnostics/diagnostic.js";
|
|
20
19
|
import { SourceFile } from "../diagnostics/source.js";
|
|
20
|
+
import { readSourceText } from "../diagnostics/source-text.js";
|
|
21
21
|
import { build, compileEntry, COMPILER_VERSION, type EmitKind, type PhaseTiming } from "../driver/compiler.js";
|
|
22
22
|
import { findRuntimeDir, platformSlug } from "../driver/paths.js";
|
|
23
23
|
import { supportFloor } from "../driver/platform-support.js";
|
|
@@ -149,7 +149,7 @@ function printDiagnostics(diagnostics: readonly Diagnostic[], fileName: string,
|
|
|
149
149
|
const sourceFor = (name: string): SourceFile | undefined => {
|
|
150
150
|
if (!sources.has(name)) {
|
|
151
151
|
try {
|
|
152
|
-
sources.set(name, new SourceFile(name,
|
|
152
|
+
sources.set(name, new SourceFile(name, readSourceText(name)));
|
|
153
153
|
} catch {
|
|
154
154
|
sources.set(name, undefined);
|
|
155
155
|
}
|
|
@@ -558,7 +558,18 @@ function dispatch(argv: readonly string[], io: CliIo): number {
|
|
|
558
558
|
return 1;
|
|
559
559
|
}
|
|
560
560
|
const executed = spawnSync(result.outputPath, args.passthrough, { stdio: "inherit" });
|
|
561
|
-
|
|
561
|
+
/* `status === null` means the program never ran or was killed by a signal;
|
|
562
|
+
* reporting 0 there would hide a crash from CI. */
|
|
563
|
+
if (executed.error) {
|
|
564
|
+
io.stderr(`xbintsc: failed to run ${result.outputPath}: ${executed.error.message}\n`);
|
|
565
|
+
return 1;
|
|
566
|
+
}
|
|
567
|
+
if (executed.status !== null) return executed.status;
|
|
568
|
+
if (executed.signal) {
|
|
569
|
+
io.stderr(`xbintsc: ${result.outputPath} terminated by signal ${executed.signal}\n`);
|
|
570
|
+
return 1;
|
|
571
|
+
}
|
|
572
|
+
return 1;
|
|
562
573
|
}
|
|
563
574
|
|
|
564
575
|
io.stderr(`xbintsc: unknown command '${command}'\n\n${HELP}`);
|
|
@@ -166,19 +166,13 @@ export const accessCallMethods: AccessCallMethods = {
|
|
|
166
166
|
* inside a `static` method), not from the `super` keyword itself. */
|
|
167
167
|
const isSuper = isSuperKeyword(node.expression);
|
|
168
168
|
const object = isSuper ? this.emitSuperHolder() : this.emitExpression(node.expression);
|
|
169
|
-
|
|
169
|
+
if (isSuper) {
|
|
170
170
|
const key = this.emitExpression(node.argumentExpression);
|
|
171
171
|
const result = this.reg();
|
|
172
|
-
|
|
173
|
-
* a numeric literal; every other key may benefit from it. */
|
|
174
|
-
if (isSuper || node.argumentExpression.kind === SyntaxKind.NumericLiteral) {
|
|
175
|
-
this.emit(` ${result} = call i64 @xt_get(i64 ${object}, i64 ${key})`);
|
|
176
|
-
} else {
|
|
177
|
-
const cache = this.icCachePointer();
|
|
178
|
-
this.emit(` ${result} = call i64 @xt_get_ic(i64 ${object}, i64 ${key}, i64* ${cache})`);
|
|
179
|
-
}
|
|
172
|
+
this.emit(` ${result} = call i64 @xt_get(i64 ${object}, i64 ${key})`);
|
|
180
173
|
return result;
|
|
181
|
-
}
|
|
174
|
+
}
|
|
175
|
+
const access = (): string => this.emitElementRead(object, this.emitExpression(node.argumentExpression));
|
|
182
176
|
return node.optional ? this.emitOptional(object, access) : access();
|
|
183
177
|
},
|
|
184
178
|
|
|
@@ -344,3 +338,4 @@ export const accessCallMethods: AccessCallMethods = {
|
|
|
344
338
|
return merged;
|
|
345
339
|
},
|
|
346
340
|
};
|
|
341
|
+
|
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline element access (`obj[key]`) in generated IR.
|
|
3
|
+
*
|
|
4
|
+
* `xt_get_element` / `xt_set_element` are runtime calls, and without LTO clang
|
|
5
|
+
* cannot inline them into generated code, so every element access paid a call
|
|
6
|
+
* plus the whole generic dispatch (tag checks, index canonicalisation, a
|
|
7
|
+
* property-bag fallback). Geometry code performs millions of these per level,
|
|
8
|
+
* which made that call overhead the dominant cost of element access.
|
|
9
|
+
*
|
|
10
|
+
* This module emits the hot path *in the IR*:
|
|
11
|
+
*
|
|
12
|
+
* 1. guard the key to a canonical array index (`0 .. 2^32-2`, integral) —
|
|
13
|
+
* `ta[1.5]` and `ta[-1]` are ordinary property accesses and must not be
|
|
14
|
+
* truncated into element 1 / 0;
|
|
15
|
+
* 2. for a plain array (`XT_TAG_ARRAY`), bounds-check against the live
|
|
16
|
+
* `length` and load/store the NaN-boxed element straight from `items`;
|
|
17
|
+
* 3. for a typed-array view (`XT_TAG_OBJECT` with a resolved `view_bytes`),
|
|
18
|
+
* test the memoized element kind and load the element with that kind's own
|
|
19
|
+
* load + conversion. Writes inline only for the float kinds: integer
|
|
20
|
+
* stores need the runtime's `ToUintN`/`ToIntN` wrapping (NaN → 0, modulo),
|
|
21
|
+
* which is not a plain truncation, so those keep the runtime call.
|
|
22
|
+
*
|
|
23
|
+
* Everything else (strings, `Map`s, host views, out-of-range indices, a view
|
|
24
|
+
* whose kind is not memoized yet, a non-numeric stored value) branches to the
|
|
25
|
+
* ordinary `xt_get_element` / `xt_set_element`, so semantics are exactly the
|
|
26
|
+
* runtime's. Two properties make the direct field reads safe:
|
|
27
|
+
*
|
|
28
|
+
* - the object pointer is reloaded from the value on every access, so an
|
|
29
|
+
* array whose `items` was reallocated by `push` is seen through its current
|
|
30
|
+
* header (no pointer is cached across mutations);
|
|
31
|
+
* - nothing allocates between the field load and the element load, so the
|
|
32
|
+
* collector cannot run in between; it never moves objects, and the receiver
|
|
33
|
+
* is a live value the conservative stack scan already roots.
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
import type { Generator } from "../generator.js";
|
|
37
|
+
import { XT_INLINE_TAGS, XT_LAYOUT } from "../layout.js";
|
|
38
|
+
import { i64 } from "../../values.js";
|
|
39
|
+
|
|
40
|
+
/** Kinds inlined on the read path, in test order (most common first). */
|
|
41
|
+
const INLINE_READ_KINDS = [
|
|
42
|
+
{ kind: 7, width: 4 }, // Float32Array
|
|
43
|
+
{ kind: 8, width: 8 }, // Float64Array
|
|
44
|
+
{ kind: 0, width: 1 }, // Uint8Array
|
|
45
|
+
{ kind: 3, width: 2 }, // Uint16Array
|
|
46
|
+
{ kind: 5, width: 4 }, // Uint32Array
|
|
47
|
+
] as const;
|
|
48
|
+
|
|
49
|
+
export interface ElementInlineMethods {
|
|
50
|
+
/** Read `object[key]` with the inline fast path. */
|
|
51
|
+
emitElementRead(this: Generator, objectValue: string, keyValue: string): string;
|
|
52
|
+
/** Write `object[key] = value` with the inline fast path. */
|
|
53
|
+
emitElementWrite(this: Generator, objectValue: string, keyValue: string, value: string): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/* -- small IR helpers ------------------------------------------------------ */
|
|
57
|
+
|
|
58
|
+
function reg(self: Generator): string {
|
|
59
|
+
return self.reg();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function emit(self: Generator, line: string): void {
|
|
63
|
+
self.emit(line);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** `value` is a number (not undefined/null/string/object/...). */
|
|
67
|
+
function emitIsNumber(self: Generator, value: string): string {
|
|
68
|
+
const masked = reg(self);
|
|
69
|
+
emit(self, ` ${masked} = and i64 ${value}, ${i64(XT_INLINE_TAGS.numberMask)}`);
|
|
70
|
+
const isNumber = reg(self);
|
|
71
|
+
emit(self, ` ${isNumber} = icmp ne i64 ${masked}, ${i64(XT_INLINE_TAGS.numberMask)}`);
|
|
72
|
+
return isNumber;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** `value` carries `tag` in its high 16 bits. */
|
|
76
|
+
function emitHasTag(self: Generator, value: string, tag: bigint): string {
|
|
77
|
+
const masked = reg(self);
|
|
78
|
+
emit(self, ` ${masked} = and i64 ${value}, ${i64(XT_INLINE_TAGS.tagMask)}`);
|
|
79
|
+
const matches = reg(self);
|
|
80
|
+
emit(self, ` ${matches} = icmp eq i64 ${masked}, ${i64(tag)}`);
|
|
81
|
+
return matches;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** `value` is an integral array index in `0 .. 2^32-2`; safe to `fptosi`. */
|
|
85
|
+
function emitIsIndex(self: Generator, value: string): string {
|
|
86
|
+
const asDouble = reg(self);
|
|
87
|
+
emit(self, ` ${asDouble} = bitcast i64 ${value} to double`);
|
|
88
|
+
const truncated = reg(self);
|
|
89
|
+
emit(self, ` ${truncated} = call double @llvm.trunc.f64(double ${asDouble})`);
|
|
90
|
+
const integral = reg(self);
|
|
91
|
+
emit(self, ` ${integral} = fcmp oeq double ${truncated}, ${asDouble}`);
|
|
92
|
+
const nonNegative = reg(self);
|
|
93
|
+
emit(self, ` ${nonNegative} = fcmp oge double ${asDouble}, 0.000000e+00`);
|
|
94
|
+
const bounded = reg(self);
|
|
95
|
+
emit(self, ` ${bounded} = fcmp olt double ${asDouble}, 4.294967294000000e+09`);
|
|
96
|
+
const partial = reg(self);
|
|
97
|
+
emit(self, ` ${partial} = and i1 ${integral}, ${nonNegative}`);
|
|
98
|
+
const isIndex = reg(self);
|
|
99
|
+
emit(self, ` ${isIndex} = and i1 ${partial}, ${bounded}`);
|
|
100
|
+
return isIndex;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Truncate a key already proven to be an index. */
|
|
104
|
+
function emitIndexOf(self: Generator, value: string): string {
|
|
105
|
+
const asDouble = reg(self);
|
|
106
|
+
emit(self, ` ${asDouble} = bitcast i64 ${value} to double`);
|
|
107
|
+
const index = reg(self);
|
|
108
|
+
emit(self, ` ${index} = fptosi double ${asDouble} to i64`);
|
|
109
|
+
return index;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** An `i8*` onto the heap payload of a tagged value. */
|
|
113
|
+
function emitPayload(self: Generator, value: string): string {
|
|
114
|
+
const pointer = reg(self);
|
|
115
|
+
emit(self, ` ${pointer} = and i64 ${value}, ${i64(0x0000ffffffffffffn)}`);
|
|
116
|
+
const base = reg(self);
|
|
117
|
+
emit(self, ` ${base} = inttoptr i64 ${pointer} to i8*`);
|
|
118
|
+
return base;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function addressAt(self: Generator, base: string, offset: number): string {
|
|
122
|
+
const address = reg(self);
|
|
123
|
+
emit(self, ` ${address} = getelementptr i8, i8* ${base}, i64 ${offset}`);
|
|
124
|
+
return address;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function loadU32(self: Generator, base: string, offset: number): string {
|
|
128
|
+
const pointer = reg(self);
|
|
129
|
+
emit(self, ` ${pointer} = bitcast i8* ${addressAt(self, base, offset)} to i32*`);
|
|
130
|
+
const value = reg(self);
|
|
131
|
+
emit(self, ` ${value} = load i32, i32* ${pointer}`);
|
|
132
|
+
return value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function loadI64(self: Generator, base: string, offset: number): string {
|
|
136
|
+
const pointer = reg(self);
|
|
137
|
+
emit(self, ` ${pointer} = bitcast i8* ${addressAt(self, base, offset)} to i64*`);
|
|
138
|
+
const value = reg(self);
|
|
139
|
+
emit(self, ` ${value} = load i64, i64* ${pointer}`);
|
|
140
|
+
return value;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function loadI16(self: Generator, base: string, offset: number): string {
|
|
144
|
+
const pointer = reg(self);
|
|
145
|
+
emit(self, ` ${pointer} = bitcast i8* ${addressAt(self, base, offset)} to i16*`);
|
|
146
|
+
const value = reg(self);
|
|
147
|
+
emit(self, ` ${value} = load i16, i16* ${pointer}`);
|
|
148
|
+
return value;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** `items[index]` as an `i64*` slot of the array whose header starts at `base`. */
|
|
152
|
+
function arraySlot(self: Generator, base: string, index: string): string {
|
|
153
|
+
const raw = loadI64(self, base, XT_LAYOUT.arrayItems);
|
|
154
|
+
const items = reg(self);
|
|
155
|
+
emit(self, ` ${items} = inttoptr i64 ${raw} to i64*`);
|
|
156
|
+
const slot = reg(self);
|
|
157
|
+
emit(self, ` ${slot} = getelementptr i64, i64* ${items}, i64 ${index}`);
|
|
158
|
+
return slot;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** `view_bytes + index * width`, plus the exclusive end of that element. */
|
|
162
|
+
function viewOffset(
|
|
163
|
+
self: Generator,
|
|
164
|
+
view: string,
|
|
165
|
+
index: string,
|
|
166
|
+
width: number,
|
|
167
|
+
): { address: string; end: string } {
|
|
168
|
+
const base = reg(self);
|
|
169
|
+
emit(self, ` ${base} = inttoptr i64 ${view} to i8*`);
|
|
170
|
+
const offset = reg(self);
|
|
171
|
+
emit(self, ` ${offset} = mul i64 ${index}, ${width}`);
|
|
172
|
+
const address = reg(self);
|
|
173
|
+
emit(self, ` ${address} = getelementptr i8, i8* ${base}, i64 ${offset}`);
|
|
174
|
+
const end = reg(self);
|
|
175
|
+
emit(self, ` ${end} = add i64 ${offset}, ${width}`);
|
|
176
|
+
return { address, end };
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/** Load one typed-array element and box it as a NaN-boxed double. */
|
|
180
|
+
function loadTypedElement(self: Generator, address: string, kind: number): string {
|
|
181
|
+
const converted = reg(self);
|
|
182
|
+
switch (kind) {
|
|
183
|
+
case 7: {
|
|
184
|
+
const pointer = reg(self);
|
|
185
|
+
emit(self, ` ${pointer} = bitcast i8* ${address} to float*`);
|
|
186
|
+
const raw = reg(self);
|
|
187
|
+
emit(self, ` ${raw} = load float, float* ${pointer}`);
|
|
188
|
+
emit(self, ` ${converted} = fpext float ${raw} to double`);
|
|
189
|
+
break;
|
|
190
|
+
}
|
|
191
|
+
case 8: {
|
|
192
|
+
const pointer = reg(self);
|
|
193
|
+
emit(self, ` ${pointer} = bitcast i8* ${address} to double*`);
|
|
194
|
+
emit(self, ` ${converted} = load double, double* ${pointer}`);
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
case 0: {
|
|
198
|
+
const raw = reg(self);
|
|
199
|
+
emit(self, ` ${raw} = load i8, i8* ${address}`);
|
|
200
|
+
const wide = reg(self);
|
|
201
|
+
emit(self, ` ${wide} = zext i8 ${raw} to i32`);
|
|
202
|
+
emit(self, ` ${converted} = uitofp i32 ${wide} to double`);
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
case 3: {
|
|
206
|
+
const pointer = reg(self);
|
|
207
|
+
emit(self, ` ${pointer} = bitcast i8* ${address} to i16*`);
|
|
208
|
+
const raw = reg(self);
|
|
209
|
+
emit(self, ` ${raw} = load i16, i16* ${pointer}`);
|
|
210
|
+
const wide = reg(self);
|
|
211
|
+
emit(self, ` ${wide} = zext i16 ${raw} to i32`);
|
|
212
|
+
emit(self, ` ${converted} = uitofp i32 ${wide} to double`);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
default: {
|
|
216
|
+
const pointer = reg(self);
|
|
217
|
+
emit(self, ` ${pointer} = bitcast i8* ${address} to i32*`);
|
|
218
|
+
const raw = reg(self);
|
|
219
|
+
emit(self, ` ${raw} = load i32, i32* ${pointer}`);
|
|
220
|
+
emit(self, ` ${converted} = uitofp i32 ${raw} to double`);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const boxed = reg(self);
|
|
225
|
+
emit(self, ` ${boxed} = bitcast double ${converted} to i64`);
|
|
226
|
+
return boxed;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export const elementInlineMethods: ElementInlineMethods = {
|
|
230
|
+
emitElementRead(objectValue: string, keyValue: string): string {
|
|
231
|
+
const result = this.alloca();
|
|
232
|
+
const done = this.label("elem.done");
|
|
233
|
+
const generic = this.label("elem.generic");
|
|
234
|
+
const numeric = emitIsNumber(this, keyValue);
|
|
235
|
+
const indexPath = this.label("elem.index");
|
|
236
|
+
this.terminate(`br i1 ${numeric}, label %${indexPath}, label %${generic}`);
|
|
237
|
+
|
|
238
|
+
this.startBlock(indexPath);
|
|
239
|
+
const isIndex = emitIsIndex(this, keyValue);
|
|
240
|
+
const keyIndex = this.label("elem.index.ok");
|
|
241
|
+
this.terminate(`br i1 ${isIndex}, label %${keyIndex}, label %${generic}`);
|
|
242
|
+
this.startBlock(keyIndex);
|
|
243
|
+
const index = emitIndexOf(this, keyValue);
|
|
244
|
+
|
|
245
|
+
/* -- plain array ------------------------------------------------------- */
|
|
246
|
+
const isArray = emitHasTag(this, objectValue, XT_INLINE_TAGS.array);
|
|
247
|
+
const arrayHit = this.label("elem.array.hit");
|
|
248
|
+
const notArray = this.label("elem.notarray");
|
|
249
|
+
this.terminate(`br i1 ${isArray}, label %${arrayHit}, label %${notArray}`);
|
|
250
|
+
this.startBlock(arrayHit);
|
|
251
|
+
const base = emitPayload(this, objectValue);
|
|
252
|
+
const length32 = loadU32(this, base, XT_LAYOUT.arrayLength);
|
|
253
|
+
const length = reg(this);
|
|
254
|
+
this.emit(` ${length} = zext i32 ${length32} to i64`);
|
|
255
|
+
const inBounds = reg(this);
|
|
256
|
+
this.emit(` ${inBounds} = icmp ult i64 ${index}, ${length}`);
|
|
257
|
+
const arrayStore = this.label("elem.array.store");
|
|
258
|
+
this.terminate(`br i1 ${inBounds}, label %${arrayStore}, label %${generic}`);
|
|
259
|
+
this.startBlock(arrayStore);
|
|
260
|
+
const slot = arraySlot(this, base, index);
|
|
261
|
+
const loaded = reg(this);
|
|
262
|
+
this.emit(` ${loaded} = load i64, i64* ${slot}`);
|
|
263
|
+
this.emit(` store i64 ${loaded}, i64* ${result}`);
|
|
264
|
+
this.terminate(`br label %${done}`);
|
|
265
|
+
|
|
266
|
+
/* -- typed-array view -------------------------------------------------- */
|
|
267
|
+
this.startBlock(notArray);
|
|
268
|
+
const isObject = emitHasTag(this, objectValue, XT_INLINE_TAGS.object);
|
|
269
|
+
const viewCheck = this.label("elem.view.check");
|
|
270
|
+
this.terminate(`br i1 ${isObject}, label %${viewCheck}, label %${generic}`);
|
|
271
|
+
this.startBlock(viewCheck);
|
|
272
|
+
const viewBase = emitPayload(this, objectValue);
|
|
273
|
+
const view = loadI64(this, viewBase, XT_LAYOUT.objectViewBytes);
|
|
274
|
+
const hasView = reg(this);
|
|
275
|
+
this.emit(` ${hasView} = icmp ne i64 ${view}, 0`);
|
|
276
|
+
const kindCheck = this.label("elem.view.kind");
|
|
277
|
+
this.terminate(`br i1 ${hasView}, label %${kindCheck}, label %${generic}`);
|
|
278
|
+
this.startBlock(kindCheck);
|
|
279
|
+
const viewLength32 = loadU32(this, viewBase, XT_LAYOUT.objectViewLength);
|
|
280
|
+
const viewLength = reg(this);
|
|
281
|
+
this.emit(` ${viewLength} = zext i32 ${viewLength32} to i64`);
|
|
282
|
+
const kindRaw = loadI16(this, viewBase, XT_LAYOUT.objectTypedKind);
|
|
283
|
+
const kindSet = reg(this);
|
|
284
|
+
this.emit(` ${kindSet} = icmp ne i16 ${kindRaw}, 0`);
|
|
285
|
+
const kind = reg(this);
|
|
286
|
+
this.emit(` ${kind} = add i16 ${kindRaw}, -1`);
|
|
287
|
+
const dispatch = this.label("elem.view.dispatch");
|
|
288
|
+
this.terminate(`br i1 ${kindSet}, label %${dispatch}, label %${generic}`);
|
|
289
|
+
|
|
290
|
+
this.startBlock(dispatch);
|
|
291
|
+
for (const entry of INLINE_READ_KINDS) {
|
|
292
|
+
const matches = reg(this);
|
|
293
|
+
this.emit(` ${matches} = icmp eq i16 ${kind}, ${entry.kind}`);
|
|
294
|
+
const hit = this.label(`elem.k${entry.kind}`);
|
|
295
|
+
const next = this.label("elem.nextkind");
|
|
296
|
+
this.terminate(`br i1 ${matches}, label %${hit}, label %${next}`);
|
|
297
|
+
this.startBlock(hit);
|
|
298
|
+
const { address, end } = viewOffset(this, view, index, entry.width);
|
|
299
|
+
const fits = reg(this);
|
|
300
|
+
this.emit(` ${fits} = icmp ule i64 ${end}, ${viewLength}`);
|
|
301
|
+
const load = this.label("elem.load");
|
|
302
|
+
this.terminate(`br i1 ${fits}, label %${load}, label %${generic}`);
|
|
303
|
+
this.startBlock(load);
|
|
304
|
+
const element = loadTypedElement(this, address, entry.kind);
|
|
305
|
+
this.emit(` store i64 ${element}, i64* ${result}`);
|
|
306
|
+
this.terminate(`br label %${done}`);
|
|
307
|
+
this.startBlock(next);
|
|
308
|
+
}
|
|
309
|
+
this.terminate(`br label %${generic}`);
|
|
310
|
+
|
|
311
|
+
/* -- fallback ---------------------------------------------------------- */
|
|
312
|
+
this.startBlock(generic);
|
|
313
|
+
const fallback = reg(this);
|
|
314
|
+
this.emit(` ${fallback} = call i64 @xt_get_element(i64 ${objectValue}, i64 ${keyValue}, i64* null)`);
|
|
315
|
+
this.emit(` store i64 ${fallback}, i64* ${result}`);
|
|
316
|
+
this.terminate(`br label %${done}`);
|
|
317
|
+
this.startBlock(done);
|
|
318
|
+
const merged = reg(this);
|
|
319
|
+
this.emit(` ${merged} = load i64, i64* ${result}`);
|
|
320
|
+
return merged;
|
|
321
|
+
},
|
|
322
|
+
|
|
323
|
+
emitElementWrite(objectValue: string, keyValue: string, value: string): void {
|
|
324
|
+
const done = this.label("setelem.done");
|
|
325
|
+
const generic = this.label("setelem.generic");
|
|
326
|
+
const numeric = emitIsNumber(this, keyValue);
|
|
327
|
+
const indexPath = this.label("setelem.index");
|
|
328
|
+
this.terminate(`br i1 ${numeric}, label %${indexPath}, label %${generic}`);
|
|
329
|
+
|
|
330
|
+
this.startBlock(indexPath);
|
|
331
|
+
const isIndex = emitIsIndex(this, keyValue);
|
|
332
|
+
const keyIndex = this.label("setelem.index.ok");
|
|
333
|
+
this.terminate(`br i1 ${isIndex}, label %${keyIndex}, label %${generic}`);
|
|
334
|
+
this.startBlock(keyIndex);
|
|
335
|
+
const index = emitIndexOf(this, keyValue);
|
|
336
|
+
|
|
337
|
+
/* -- plain array: an in-range store never changes the length ----------- */
|
|
338
|
+
const isArray = emitHasTag(this, objectValue, XT_INLINE_TAGS.array);
|
|
339
|
+
const arrayHit = this.label("setelem.array.hit");
|
|
340
|
+
const notArray = this.label("setelem.notarray");
|
|
341
|
+
this.terminate(`br i1 ${isArray}, label %${arrayHit}, label %${notArray}`);
|
|
342
|
+
this.startBlock(arrayHit);
|
|
343
|
+
const base = emitPayload(this, objectValue);
|
|
344
|
+
const length32 = loadU32(this, base, XT_LAYOUT.arrayLength);
|
|
345
|
+
const length = reg(this);
|
|
346
|
+
this.emit(` ${length} = zext i32 ${length32} to i64`);
|
|
347
|
+
const inBounds = reg(this);
|
|
348
|
+
this.emit(` ${inBounds} = icmp ult i64 ${index}, ${length}`);
|
|
349
|
+
const arrayStore = this.label("setelem.array.store");
|
|
350
|
+
this.terminate(`br i1 ${inBounds}, label %${arrayStore}, label %${generic}`);
|
|
351
|
+
this.startBlock(arrayStore);
|
|
352
|
+
const slot = arraySlot(this, base, index);
|
|
353
|
+
this.emit(` store i64 ${value}, i64* ${slot}`);
|
|
354
|
+
this.terminate(`br label %${done}`);
|
|
355
|
+
|
|
356
|
+
/* -- typed-array view: float kinds only (integer stores coerce) -------- */
|
|
357
|
+
this.startBlock(notArray);
|
|
358
|
+
const isObject = emitHasTag(this, objectValue, XT_INLINE_TAGS.object);
|
|
359
|
+
const viewCheck = this.label("setelem.view.check");
|
|
360
|
+
this.terminate(`br i1 ${isObject}, label %${viewCheck}, label %${generic}`);
|
|
361
|
+
this.startBlock(viewCheck);
|
|
362
|
+
const viewBase = emitPayload(this, objectValue);
|
|
363
|
+
const view = loadI64(this, viewBase, XT_LAYOUT.objectViewBytes);
|
|
364
|
+
const hasView = reg(this);
|
|
365
|
+
this.emit(` ${hasView} = icmp ne i64 ${view}, 0`);
|
|
366
|
+
const kindCheck = this.label("setelem.kind");
|
|
367
|
+
this.terminate(`br i1 ${hasView}, label %${kindCheck}, label %${generic}`);
|
|
368
|
+
this.startBlock(kindCheck);
|
|
369
|
+
const viewLength32 = loadU32(this, viewBase, XT_LAYOUT.objectViewLength);
|
|
370
|
+
const viewLength = reg(this);
|
|
371
|
+
this.emit(` ${viewLength} = zext i32 ${viewLength32} to i64`);
|
|
372
|
+
const kindRaw = loadI16(this, viewBase, XT_LAYOUT.objectTypedKind);
|
|
373
|
+
const kind = reg(this);
|
|
374
|
+
this.emit(` ${kind} = add i16 ${kindRaw}, -1`);
|
|
375
|
+
/* A non-number value needs the runtime's ToNumber conversion. */
|
|
376
|
+
const valueIsNumber = emitIsNumber(this, value);
|
|
377
|
+
const f32Test = this.label("setelem.f32.test");
|
|
378
|
+
this.terminate(`br i1 ${valueIsNumber}, label %${f32Test}, label %${generic}`);
|
|
379
|
+
|
|
380
|
+
this.startBlock(f32Test);
|
|
381
|
+
const isF32 = reg(this);
|
|
382
|
+
this.emit(` ${isF32} = icmp eq i16 ${kind}, 7`);
|
|
383
|
+
const f32Store = this.label("setelem.f32");
|
|
384
|
+
const f64Test = this.label("setelem.f64.test");
|
|
385
|
+
this.terminate(`br i1 ${isF32}, label %${f32Store}, label %${f64Test}`);
|
|
386
|
+
|
|
387
|
+
this.startBlock(f32Store);
|
|
388
|
+
{
|
|
389
|
+
const { address, end } = viewOffset(this, view, index, 4);
|
|
390
|
+
const fits = reg(this);
|
|
391
|
+
this.emit(` ${fits} = icmp ule i64 ${end}, ${viewLength}`);
|
|
392
|
+
const ok = this.label("setelem.f32.ok");
|
|
393
|
+
this.terminate(`br i1 ${fits}, label %${ok}, label %${generic}`);
|
|
394
|
+
this.startBlock(ok);
|
|
395
|
+
const pointer = reg(this);
|
|
396
|
+
const wide = reg(this);
|
|
397
|
+
const narrowed = reg(this);
|
|
398
|
+
this.emit(` ${pointer} = bitcast i8* ${address} to float*`);
|
|
399
|
+
this.emit(` ${wide} = bitcast i64 ${value} to double`);
|
|
400
|
+
this.emit(` ${narrowed} = fptrunc double ${wide} to float`);
|
|
401
|
+
this.emit(` store float ${narrowed}, float* ${pointer}`);
|
|
402
|
+
this.terminate(`br label %${done}`);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
this.startBlock(f64Test);
|
|
406
|
+
const isF64 = reg(this);
|
|
407
|
+
this.emit(` ${isF64} = icmp eq i16 ${kind}, 8`);
|
|
408
|
+
const f64Store = this.label("setelem.f64");
|
|
409
|
+
this.terminate(`br i1 ${isF64}, label %${f64Store}, label %${generic}`);
|
|
410
|
+
|
|
411
|
+
this.startBlock(f64Store);
|
|
412
|
+
{
|
|
413
|
+
const { address, end } = viewOffset(this, view, index, 8);
|
|
414
|
+
const fits = reg(this);
|
|
415
|
+
this.emit(` ${fits} = icmp ule i64 ${end}, ${viewLength}`);
|
|
416
|
+
const ok = this.label("setelem.f64.ok");
|
|
417
|
+
this.terminate(`br i1 ${fits}, label %${ok}, label %${generic}`);
|
|
418
|
+
this.startBlock(ok);
|
|
419
|
+
const pointer = reg(this);
|
|
420
|
+
const wide = reg(this);
|
|
421
|
+
this.emit(` ${pointer} = bitcast i8* ${address} to double*`);
|
|
422
|
+
this.emit(` ${wide} = bitcast i64 ${value} to double`);
|
|
423
|
+
this.emit(` store double ${wide}, double* ${pointer}`);
|
|
424
|
+
this.terminate(`br label %${done}`);
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
this.startBlock(generic);
|
|
428
|
+
this.emit(` call i64 @xt_set_element(i64 ${objectValue}, i64 ${keyValue}, i64 ${value})`);
|
|
429
|
+
this.terminate(`br label %${done}`);
|
|
430
|
+
this.startBlock(done);
|
|
431
|
+
},
|
|
432
|
+
};
|
|
433
|
+
|
|
@@ -36,6 +36,51 @@ export interface InvocationCallMethods {
|
|
|
36
36
|
emitArguments(this: Generator, args: readonly Expression[]): { argc: string; ptr: string };
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Fixed-arity `Math.<fn>` calls lower to their own runtime entry point instead
|
|
41
|
+
* of `xt_math_call(name, argc, argv)`. The name and arity are known here, so
|
|
42
|
+
* the generated call passes the arguments in registers and the runtime skips
|
|
43
|
+
* the name dispatch and the argument array. A numeric kernel calls these
|
|
44
|
+
* hundreds of times per pixel (the Saltline terrain generator alone executes
|
|
45
|
+
* ~125 million `Math` calls), which made the generic ABI the dominant cost.
|
|
46
|
+
* `min`/`max` stay variadic and keep `xt_math_call`.
|
|
47
|
+
*/
|
|
48
|
+
const MATH_DIRECT: Record<string, { symbol: string; arity: number }> = {
|
|
49
|
+
abs: { symbol: "xt_math1_abs", arity: 1 },
|
|
50
|
+
floor: { symbol: "xt_math1_floor", arity: 1 },
|
|
51
|
+
ceil: { symbol: "xt_math1_ceil", arity: 1 },
|
|
52
|
+
round: { symbol: "xt_math1_round", arity: 1 },
|
|
53
|
+
trunc: { symbol: "xt_math1_trunc", arity: 1 },
|
|
54
|
+
sqrt: { symbol: "xt_math1_sqrt", arity: 1 },
|
|
55
|
+
cbrt: { symbol: "xt_math1_cbrt", arity: 1 },
|
|
56
|
+
exp: { symbol: "xt_math1_exp", arity: 1 },
|
|
57
|
+
log: { symbol: "xt_math1_log", arity: 1 },
|
|
58
|
+
log2: { symbol: "xt_math1_log2", arity: 1 },
|
|
59
|
+
log10: { symbol: "xt_math1_log10", arity: 1 },
|
|
60
|
+
log1p: { symbol: "xt_math1_log1p", arity: 1 },
|
|
61
|
+
expm1: { symbol: "xt_math1_expm1", arity: 1 },
|
|
62
|
+
sinh: { symbol: "xt_math1_sinh", arity: 1 },
|
|
63
|
+
cosh: { symbol: "xt_math1_cosh", arity: 1 },
|
|
64
|
+
tanh: { symbol: "xt_math1_tanh", arity: 1 },
|
|
65
|
+
asinh: { symbol: "xt_math1_asinh", arity: 1 },
|
|
66
|
+
acosh: { symbol: "xt_math1_acosh", arity: 1 },
|
|
67
|
+
atanh: { symbol: "xt_math1_atanh", arity: 1 },
|
|
68
|
+
fround: { symbol: "xt_math1_fround", arity: 1 },
|
|
69
|
+
clz32: { symbol: "xt_math1_clz32", arity: 1 },
|
|
70
|
+
sin: { symbol: "xt_math1_sin", arity: 1 },
|
|
71
|
+
cos: { symbol: "xt_math1_cos", arity: 1 },
|
|
72
|
+
tan: { symbol: "xt_math1_tan", arity: 1 },
|
|
73
|
+
asin: { symbol: "xt_math1_asin", arity: 1 },
|
|
74
|
+
acos: { symbol: "xt_math1_acos", arity: 1 },
|
|
75
|
+
atan: { symbol: "xt_math1_atan", arity: 1 },
|
|
76
|
+
sign: { symbol: "xt_math1_sign", arity: 1 },
|
|
77
|
+
pow: { symbol: "xt_math2_pow", arity: 2 },
|
|
78
|
+
atan2: { symbol: "xt_math2_atan2", arity: 2 },
|
|
79
|
+
hypot: { symbol: "xt_math2_hypot", arity: 2 },
|
|
80
|
+
imul: { symbol: "xt_math2_imul", arity: 2 },
|
|
81
|
+
random: { symbol: "xt_math0_random", arity: 0 },
|
|
82
|
+
};
|
|
83
|
+
|
|
39
84
|
export const invocationCallMethods: InvocationCallMethods = {
|
|
40
85
|
emitCall(node: CallExpression): string {
|
|
41
86
|
const callee = node.expression;
|
|
@@ -87,7 +132,18 @@ export const invocationCallMethods: InvocationCallMethods = {
|
|
|
87
132
|
const name = this.stringValue(access.name.text);
|
|
88
133
|
const args = this.emitArguments(node.arguments);
|
|
89
134
|
const result = this.reg();
|
|
90
|
-
|
|
135
|
+
/* Method dispatch is monomorphic at most sites, so the call carries a
|
|
136
|
+
* three-word inline cache: a shape/slot hit calls the cached method value
|
|
137
|
+
* directly instead of walking the dispatch tables and the prototype
|
|
138
|
+
* chain. See `runtime/xt_containers/access.inc`. */
|
|
139
|
+
this.extraDeclarations.add("declare i64 @xt_call_method_ic(i64, i64, i32, i64*, i64*)");
|
|
140
|
+
const cache = `@mt.${this.icCounter++}`;
|
|
141
|
+
this.globals.push(`${cache} = internal global [3 x i64] zeroinitializer`);
|
|
142
|
+
const slot = this.reg();
|
|
143
|
+
this.emit(` ${slot} = getelementptr [3 x i64], [3 x i64]* ${cache}, i64 0, i64 0`);
|
|
144
|
+
this.emit(
|
|
145
|
+
` ${result} = call i64 @xt_call_method_ic(i64 ${object}, i64 ${name}, i32 ${args.argc}, i64* ${args.ptr}, i64* ${slot})`,
|
|
146
|
+
);
|
|
91
147
|
return result;
|
|
92
148
|
}
|
|
93
149
|
if (callee.kind === SyntaxKind.ElementAccessExpression) {
|
|
@@ -139,7 +195,23 @@ export const invocationCallMethods: InvocationCallMethods = {
|
|
|
139
195
|
this.emit(` ${result} = call i64 @${globalFunction}(i32 ${args.argc}, i64* ${args.ptr})`);
|
|
140
196
|
return result;
|
|
141
197
|
}
|
|
198
|
+
/* A browser global that is really a window method (`addEventListener`):
|
|
199
|
+
* dispatch through the host object so `this` is the window. The builtin
|
|
200
|
+
* table is consulted first — a host that needs to do extra work for a
|
|
201
|
+
* global callable (`requestAnimationFrame` also arms the frame pump)
|
|
202
|
+
* declares a builtin, and that must win over the plain member call. */
|
|
203
|
+
const windowMember = !symbol ? this.globalValues[identifier.text] : undefined;
|
|
142
204
|
const builtin = this.builtins[(callee as Identifier).text];
|
|
205
|
+
if (windowMember?.member !== undefined && !builtin) {
|
|
206
|
+
const host = this.emitGlobalValue({ symbol: windowMember.symbol });
|
|
207
|
+
const name = this.stringValue(windowMember.member);
|
|
208
|
+
const args = this.emitArguments(node.arguments);
|
|
209
|
+
const result = this.reg();
|
|
210
|
+
this.emit(
|
|
211
|
+
` ${result} = call i64 @xt_call_method(i64 ${host}, i64 ${name}, i32 ${args.argc}, i64* ${args.ptr})`,
|
|
212
|
+
);
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
143
215
|
if (!symbol && builtin) {
|
|
144
216
|
this.extraDeclarations.add(
|
|
145
217
|
builtin.returnVoid ? `declare void @${builtin.symbol}(i32, i64*)` : `declare i64 @${builtin.symbol}(i32, i64*)`,
|
|
@@ -190,6 +262,20 @@ export const invocationCallMethods: InvocationCallMethods = {
|
|
|
190
262
|
|
|
191
263
|
if (targetIdentifier && targetIdentifier.text === "Math" && !targetSymbol) {
|
|
192
264
|
if (!MATH_FUNCTIONS.has(method)) return undefined;
|
|
265
|
+
const direct = MATH_DIRECT[method];
|
|
266
|
+
const hasSpread = node.arguments.some((argument) => argument.kind === SyntaxKind.SpreadElement);
|
|
267
|
+
if (direct && !hasSpread && node.arguments.length === direct.arity) {
|
|
268
|
+
const values = node.arguments.map((argument) => this.emitExpression(argument));
|
|
269
|
+
const parameterList = values.map(() => "i64").join(", ");
|
|
270
|
+
/* Numeric literals come back as bare bit patterns (`values.ts` leaves
|
|
271
|
+
* the type to the instruction that consumes them), so every operand is
|
|
272
|
+
* typed here explicitly. */
|
|
273
|
+
const operands = values.map((value) => `i64 ${value}`).join(", ");
|
|
274
|
+
this.extraDeclarations.add(`declare i64 @${direct.symbol}(${parameterList})`);
|
|
275
|
+
const result = this.reg();
|
|
276
|
+
this.emit(` ${result} = call i64 @${direct.symbol}(${operands})`);
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
193
279
|
const name = this.stringValue(method);
|
|
194
280
|
const args = this.emitArguments(node.arguments);
|
|
195
281
|
const result = this.reg();
|