xbintsc 0.7.0 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/ast/common.d.ts +10 -0
- package/dist/src/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 +48 -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/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 +35 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- package/dist/tests/e2e/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 +26 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/known-issues.md +35 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/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 +19 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/known-issues.md +24 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/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 +9 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_internal.h +3 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +3 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +6 -1
- package/runtime/ext_gui/gui_engine.h +2 -0
- package/runtime/ext_gui/gui_events.cpp +13 -8
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +20 -170
- package/runtime/ext_gui/webgl_context.cpp +117 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_objects.h +16 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +8 -0
- package/runtime/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/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 +50 -1
- package/src/extensions/registry.ts +20 -0
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extension-provided global values.
|
|
3
|
+
*
|
|
4
|
+
* An extension names a global (`window`, `document`, `Image`, `location`) and
|
|
5
|
+
* the runtime getter that produces it; this group turns such a name into a
|
|
6
|
+
* value, including the two richer shapes:
|
|
7
|
+
*
|
|
8
|
+
* - a global that is a *member of a host object* (`location` off the window),
|
|
9
|
+
* so a browser global that only exists as a window property is still live;
|
|
10
|
+
* - `console`, which is both a namespace at call sites and a first-class
|
|
11
|
+
* object as a value (`console.error.bind(console)`).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { GlobalValue } from "../../../extensions/registry.js";
|
|
15
|
+
import type { Generator } from "../generator.js";
|
|
16
|
+
|
|
17
|
+
export interface GlobalValueMethods {
|
|
18
|
+
emitGlobalValue(this: Generator, value: GlobalValue): string;
|
|
19
|
+
emitConsoleObject(this: Generator): string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const globalValueMethods: GlobalValueMethods = {
|
|
23
|
+
/**
|
|
24
|
+
* Read an extension-provided global (`window`, `document`, `new Image()`).
|
|
25
|
+
* The getter is a normal runtime call with the uniform ABI; the optional
|
|
26
|
+
* argument is how one getter serves a whole family of host types.
|
|
27
|
+
*/
|
|
28
|
+
emitGlobalValue(value: GlobalValue): string {
|
|
29
|
+
this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
|
|
30
|
+
let argc = "0";
|
|
31
|
+
let pointer = "i64* null";
|
|
32
|
+
if (value.argument !== undefined) {
|
|
33
|
+
const argument = this.stringValue(value.argument);
|
|
34
|
+
const slot = `%gval${this.current.allocas.length}`;
|
|
35
|
+
this.current.allocas.push(`${slot} = alloca i64, i32 1`);
|
|
36
|
+
const cell = this.reg();
|
|
37
|
+
this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
|
|
38
|
+
this.emit(` store i64 ${argument}, i64* ${cell}`);
|
|
39
|
+
argc = "1";
|
|
40
|
+
pointer = `i64* ${slot}`;
|
|
41
|
+
}
|
|
42
|
+
const result = this.reg();
|
|
43
|
+
this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
|
|
44
|
+
if (value.member === undefined) return result;
|
|
45
|
+
/* A browser global that lives on the window object (`location`): read it
|
|
46
|
+
* off the host object so a getter runs and answers a live value. */
|
|
47
|
+
const name = this.stringValue(value.member);
|
|
48
|
+
return this.runtimeCall("xt_get", [result, name]);
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
/** The global `console` object (see `runtime/xt_io/console.inc`). */
|
|
52
|
+
emitConsoleObject(): string {
|
|
53
|
+
const result = this.reg();
|
|
54
|
+
this.emit(` ${result} = call i64 @xt_console_object(i32 0, i64* null)`);
|
|
55
|
+
return result;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
@@ -41,7 +41,6 @@ import {
|
|
|
41
41
|
NAMESPACE_VALUES,
|
|
42
42
|
WEB_GLOBALS,
|
|
43
43
|
} from "../tables.js";
|
|
44
|
-
import type { GlobalValue } from "../../../extensions/registry.js";
|
|
45
44
|
import type { Generator } from "../generator.js";
|
|
46
45
|
import { newCalleeName } from "../calls/unwrap.js";
|
|
47
46
|
|
|
@@ -57,7 +56,6 @@ export interface PrimaryExpressionMethods {
|
|
|
57
56
|
*/
|
|
58
57
|
emitTypeOf(this: Generator, operand: Expression): string;
|
|
59
58
|
globalTypeOf(this: Generator, name: string): string | undefined;
|
|
60
|
-
emitGlobalValue(this: Generator, value: GlobalValue): string;
|
|
61
59
|
emitFunctionValue(this: Generator, symbol: SymbolInfo): string;
|
|
62
60
|
emitTemplate(this: Generator, node: TemplateLiteral): string;
|
|
63
61
|
emitTaggedTemplate(this: Generator, node: TaggedTemplateExpression): string;
|
|
@@ -294,7 +292,10 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
294
292
|
case "Infinity":
|
|
295
293
|
return numberLiteral(Infinity);
|
|
296
294
|
case "console":
|
|
297
|
-
|
|
295
|
+
/* `console` is a namespace at call sites (`console.log(...)`) and a
|
|
296
|
+
* first-class object as a value: `const log = console.log`,
|
|
297
|
+
* `console.error.bind(console)`, `const { warn } = console`. */
|
|
298
|
+
return this.emitConsoleObject();
|
|
298
299
|
case "arguments": {
|
|
299
300
|
const argc = this.reg();
|
|
300
301
|
this.emit(` ${argc} = load i32, i32* %saved.argc`);
|
|
@@ -375,30 +376,6 @@ export const primaryExpressionMethods: PrimaryExpressionMethods = {
|
|
|
375
376
|
}
|
|
376
377
|
},
|
|
377
378
|
|
|
378
|
-
/**
|
|
379
|
-
* Read an extension-provided global (`window`, `document`, `new Image()`).
|
|
380
|
-
* The getter is a normal runtime call with the uniform ABI; the optional
|
|
381
|
-
* argument is how one getter serves a whole family of host types.
|
|
382
|
-
*/
|
|
383
|
-
emitGlobalValue(value: GlobalValue): string {
|
|
384
|
-
this.extraDeclarations.add(`declare i64 @${value.symbol}(i32, i64*)`);
|
|
385
|
-
let argc = "0";
|
|
386
|
-
let pointer = "i64* null";
|
|
387
|
-
if (value.argument !== undefined) {
|
|
388
|
-
const argument = this.stringValue(value.argument);
|
|
389
|
-
const slot = `%gval${this.current.allocas.length}`;
|
|
390
|
-
this.current.allocas.push(`${slot} = alloca i64, i32 1`);
|
|
391
|
-
const cell = this.reg();
|
|
392
|
-
this.emit(` ${cell} = getelementptr i64, i64* ${slot}, i32 0`);
|
|
393
|
-
this.emit(` store i64 ${argument}, i64* ${cell}`);
|
|
394
|
-
argc = "1";
|
|
395
|
-
pointer = `i64* ${slot}`;
|
|
396
|
-
}
|
|
397
|
-
const result = this.reg();
|
|
398
|
-
this.emit(` ${result} = call i64 @${value.symbol}(i32 ${argc}, ${pointer})`);
|
|
399
|
-
return result;
|
|
400
|
-
},
|
|
401
|
-
|
|
402
379
|
emitFunctionValue(symbol: SymbolInfo): string {
|
|
403
380
|
const fn = implementationFunctionInfo(this.binding, symbol);
|
|
404
381
|
if (!fn) return i64(XT_UNDEFINED);
|
|
@@ -9,12 +9,14 @@
|
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
11
|
import { primaryExpressionMethods, type PrimaryExpressionMethods } from "./expressions/primary.js";
|
|
12
|
+
import { globalValueMethods, type GlobalValueMethods } from "./expressions/global-values.js";
|
|
12
13
|
import { moduleValueExpressionMethods, type ModuleValueExpressionMethods } from "./expressions/module-values.js";
|
|
13
14
|
import { operatorExpressionMethods, type OperatorExpressionMethods } from "./expressions/operators.js";
|
|
14
15
|
import { assignmentExpressionMethods, type AssignmentExpressionMethods } from "./expressions/assignment.js";
|
|
15
16
|
|
|
16
17
|
export interface ExpressionMethods
|
|
17
18
|
extends PrimaryExpressionMethods,
|
|
19
|
+
GlobalValueMethods,
|
|
18
20
|
ModuleValueExpressionMethods,
|
|
19
21
|
OperatorExpressionMethods,
|
|
20
22
|
AssignmentExpressionMethods {}
|
|
@@ -22,6 +24,7 @@ export interface ExpressionMethods
|
|
|
22
24
|
export const expressionMethods: ExpressionMethods = Object.assign(
|
|
23
25
|
{},
|
|
24
26
|
primaryExpressionMethods,
|
|
27
|
+
globalValueMethods,
|
|
25
28
|
moduleValueExpressionMethods,
|
|
26
29
|
operatorExpressionMethods,
|
|
27
30
|
assignmentExpressionMethods,
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Byte offsets into the runtime's container structs that generated code reads
|
|
3
|
+
* directly.
|
|
4
|
+
*
|
|
5
|
+
* The element fast path (`element-inline.ts`) skips the generic dispatch by
|
|
6
|
+
* looking at a value's tag and then loading the fields it needs — an array's
|
|
7
|
+
* `items`/`length`, a typed-array view's `view_bytes`/`view_length`/kind — out of
|
|
8
|
+
* the object header. That only works if the compiler knows the layout, so these
|
|
9
|
+
* constants mirror `runtime/rt_object.h`; `tests/codegen/element-layout.test.ts`
|
|
10
|
+
* compiles a C probe against the runtime header and fails when the two drift
|
|
11
|
+
* apart.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { XT_ARRAY, XT_NUMBER_MASK, XT_OBJECT, XT_TAG_MASK } from "../values.js";
|
|
15
|
+
|
|
16
|
+
export const XT_LAYOUT = {
|
|
17
|
+
/** `xt_header` size: the payload starts here in every heap object. */
|
|
18
|
+
headerSize: 16,
|
|
19
|
+
/** `xt_array.length` (uint32). */
|
|
20
|
+
arrayLength: 16,
|
|
21
|
+
/** `xt_array.items` (i64 pointer to the element vector). */
|
|
22
|
+
arrayItems: 24,
|
|
23
|
+
/** `xt_object.reserved2` (uint16): a typed-array view's `kind + 1`. */
|
|
24
|
+
objectTypedKind: 50,
|
|
25
|
+
/** `xt_object.view_bytes` (i64 raw pointer): the view's first element. */
|
|
26
|
+
objectViewBytes: 96,
|
|
27
|
+
/** `xt_object.view_length` (uint32): bytes available from `view_bytes`. */
|
|
28
|
+
objectViewLength: 104,
|
|
29
|
+
} as const;
|
|
30
|
+
|
|
31
|
+
/** Tags and masks the inline guards compare against (`runtime/rt.h`). */
|
|
32
|
+
export const XT_INLINE_TAGS = {
|
|
33
|
+
tagMask: XT_TAG_MASK,
|
|
34
|
+
numberMask: XT_NUMBER_MASK,
|
|
35
|
+
array: XT_ARRAY,
|
|
36
|
+
object: XT_OBJECT,
|
|
37
|
+
} as const;
|
|
38
|
+
|
|
39
|
+
/** Typed-array element kinds, in `XT_TA_*` order (`runtime/xt_typed_array.c`). */
|
|
40
|
+
export const XT_TYPED_KINDS = [
|
|
41
|
+
{ name: "Uint8Array", width: 1 },
|
|
42
|
+
{ name: "Int8Array", width: 1 },
|
|
43
|
+
{ name: "Uint8ClampedArray", width: 1 },
|
|
44
|
+
{ name: "Uint16Array", width: 2 },
|
|
45
|
+
{ name: "Int16Array", width: 2 },
|
|
46
|
+
{ name: "Uint32Array", width: 4 },
|
|
47
|
+
{ name: "Int32Array", width: 4 },
|
|
48
|
+
{ name: "Float32Array", width: 4 },
|
|
49
|
+
{ name: "Float64Array", width: 8 },
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
/** Index of `Float32Array` / `Float64Array` in {@link XT_TYPED_KINDS}. */
|
|
53
|
+
export const XT_KIND_F32 = 7;
|
|
54
|
+
export const XT_KIND_F64 = 8;
|
|
@@ -375,6 +375,9 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
375
375
|
"declare i64 @xt_symbol_static(i64, i32, i64*)",
|
|
376
376
|
"declare i64 @xt_symbol_get(i64)",
|
|
377
377
|
"declare i64 @xt_get(i64, i64)",
|
|
378
|
+
"declare i64 @xt_get_element(i64, i64, i64*)",
|
|
379
|
+
"declare i64 @xt_set_element(i64, i64, i64)",
|
|
380
|
+
"declare double @llvm.trunc.f64(double)",
|
|
378
381
|
"declare i64 @xt_get_ic(i64, i64, i64*)",
|
|
379
382
|
"declare i64 @xt_set(i64, i64, i64)",
|
|
380
383
|
"declare i64 @xt_box_new(i64)",
|
|
@@ -395,4 +398,6 @@ export const RUNTIME_DECLARATIONS: readonly string[] = [
|
|
|
395
398
|
"declare void @xt_console_info(i32, i64*)",
|
|
396
399
|
"declare void @xt_console_warn(i32, i64*)",
|
|
397
400
|
"declare void @xt_console_error(i32, i64*)",
|
|
401
|
+
"declare i64 @xt_console_object(i32, i64*)",
|
|
398
402
|
];
|
|
403
|
+
|
|
@@ -120,7 +120,7 @@ export function formatDiagnostic(d: Diagnostic, source?: SourceFile): string {
|
|
|
120
120
|
if (source && d.start !== undefined) {
|
|
121
121
|
const { line, column } = source.positionAt(d.start);
|
|
122
122
|
location = `${source.fileName}:${line}:${column}`;
|
|
123
|
-
const lineText = source.
|
|
123
|
+
const lineText = source.lineText(line);
|
|
124
124
|
const end = d.end ?? d.start;
|
|
125
125
|
const endCol = source.positionAt(end).column;
|
|
126
126
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Source text is a byte sequence.
|
|
2
|
+
* Source text is a byte sequence, one code unit per UTF-8 byte.
|
|
3
3
|
*
|
|
4
4
|
* A compiled string is a sequence of UTF-8 bytes (`"e".length` is 1 for an
|
|
5
5
|
* accent and 4 for an emoji - see doc/ai/language-support.md), and the compiler
|
|
@@ -7,26 +7,116 @@
|
|
|
7
7
|
* file's own bytes, one per code unit, and the runtime has no UTF-8 decoder to
|
|
8
8
|
* change that. A host whose strings are UTF-16 must be given the text in the
|
|
9
9
|
* same shape, or the same program emits different bytes depending on which
|
|
10
|
-
* generation of the compiler read it
|
|
11
|
-
* up double-encoded and broke the self-hosting fixpoint.
|
|
10
|
+
* generation of the compiler read it.
|
|
12
11
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* The conversion is explicit at the boundary:
|
|
13
|
+
*
|
|
14
|
+
* - `sourceTextBytes(hostText)` UTF-8 encodes text a host decoded for us (a
|
|
15
|
+
* `compileString` argument, a test fixture);
|
|
16
|
+
* - `sourceTextFromBytes(fileBytes)` keeps a file's bytes as they are, which is
|
|
17
|
+
* the only correct reading for a source file on either host;
|
|
18
|
+
* - `readSourceText(path)` reads a UTF-8 source file through the second one.
|
|
19
|
+
*
|
|
20
|
+
* There is deliberately no "does this string look like text?" heuristic: a
|
|
21
|
+
* Latin-1-range character such as `é` has the same code unit (`0xE9`) whether
|
|
22
|
+
* it was decoded from UTF-8 or is a raw byte, and guessing wrong emitted it as
|
|
23
|
+
* a single invalid byte instead of the two-byte UTF-8 sequence.
|
|
16
24
|
*/
|
|
17
25
|
|
|
26
|
+
import { readFileSync } from "node:fs";
|
|
27
|
+
|
|
18
28
|
/**
|
|
19
|
-
* The UTF-8 bytes of
|
|
20
|
-
*
|
|
21
|
-
*
|
|
29
|
+
* The UTF-8 bytes of host text, one code unit each.
|
|
30
|
+
*
|
|
31
|
+
* Use this only for text a host decoded (a string literal in a test, a
|
|
32
|
+
* `compileString` argument). A file's bytes must go through
|
|
33
|
+
* {@link sourceTextFromBytes}; encoding those again doubles the non-ASCII
|
|
34
|
+
* sequence and breaks the self-hosting fixpoint.
|
|
22
35
|
*/
|
|
23
36
|
export function sourceTextBytes(text: string): string {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
return stripBom(encodeUtf8(text));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Internal source text from a file's raw bytes.
|
|
42
|
+
*
|
|
43
|
+
* `readFileSync` returns a `Buffer` on Node and a byte string (one code unit
|
|
44
|
+
* per byte) in a self-hosted xbintsc; both arrive here. A UTF-8 BOM is dropped
|
|
45
|
+
* so positions match the scanner's normalized text.
|
|
46
|
+
*/
|
|
47
|
+
export function sourceTextFromBytes(bytes: Uint8Array | string): string {
|
|
48
|
+
return stripBom(typeof bytes === "string" ? bytes : bytesToString(bytes));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Read a UTF-8 source file as internal (byte-string) text. */
|
|
52
|
+
export function readSourceText(path: string): string {
|
|
53
|
+
const data: Uint8Array | string = readFileSync(path);
|
|
54
|
+
return sourceTextFromBytes(data);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Decode internal byte text back to host text for display (diagnostics).
|
|
59
|
+
*
|
|
60
|
+
* Invalid sequences decode to U+FFFD, which is what a terminal would show for
|
|
61
|
+
* a malformed byte; the parser never consumes the result.
|
|
62
|
+
*/
|
|
63
|
+
export function decodeSourceBytes(bytes: string): string {
|
|
64
|
+
const chunks: string[] = [];
|
|
65
|
+
const units: number[] = [];
|
|
66
|
+
let index = 0;
|
|
67
|
+
while (index < bytes.length) {
|
|
68
|
+
const lead = bytes.charCodeAt(index) & 0xff;
|
|
69
|
+
if (lead < 0x80) {
|
|
70
|
+
units.push(lead);
|
|
71
|
+
index += 1;
|
|
72
|
+
} else if ((lead & 0xe0) === 0xc0) {
|
|
73
|
+
const b1 = bytes.charCodeAt(index + 1);
|
|
74
|
+
if ((b1 & 0xc0) === 0x80) {
|
|
75
|
+
units.push(((lead & 0x1f) << 6) | (b1 & 0x3f));
|
|
76
|
+
index += 2;
|
|
77
|
+
} else {
|
|
78
|
+
units.push(0xfffd);
|
|
79
|
+
index += 1;
|
|
80
|
+
}
|
|
81
|
+
} else if ((lead & 0xf0) === 0xe0) {
|
|
82
|
+
const b1 = bytes.charCodeAt(index + 1);
|
|
83
|
+
const b2 = bytes.charCodeAt(index + 2);
|
|
84
|
+
if ((b1 & 0xc0) === 0x80 && (b2 & 0xc0) === 0x80) {
|
|
85
|
+
units.push(((lead & 0x0f) << 12) | ((b1 & 0x3f) << 6) | (b2 & 0x3f));
|
|
86
|
+
index += 3;
|
|
87
|
+
} else {
|
|
88
|
+
units.push(0xfffd);
|
|
89
|
+
index += 1;
|
|
90
|
+
}
|
|
91
|
+
} else if ((lead & 0xf8) === 0xf0) {
|
|
92
|
+
const b1 = bytes.charCodeAt(index + 1);
|
|
93
|
+
const b2 = bytes.charCodeAt(index + 2);
|
|
94
|
+
const b3 = bytes.charCodeAt(index + 3);
|
|
95
|
+
if ((b1 & 0xc0) === 0x80 && (b2 & 0xc0) === 0x80 && (b3 & 0xc0) === 0x80) {
|
|
96
|
+
let code = ((lead & 0x07) << 18) | ((b1 & 0x3f) << 12) | ((b2 & 0x3f) << 6) | (b3 & 0x3f);
|
|
97
|
+
if (code > 0x10ffff) code = 0xfffd;
|
|
98
|
+
if (code >= 0x10000) {
|
|
99
|
+
code -= 0x10000;
|
|
100
|
+
units.push(0xd800 + (code >> 10), 0xdc00 + (code & 0x3ff));
|
|
101
|
+
} else {
|
|
102
|
+
units.push(code);
|
|
103
|
+
}
|
|
104
|
+
index += 4;
|
|
105
|
+
} else {
|
|
106
|
+
units.push(0xfffd);
|
|
107
|
+
index += 1;
|
|
108
|
+
}
|
|
109
|
+
} else {
|
|
110
|
+
units.push(0xfffd);
|
|
111
|
+
index += 1;
|
|
112
|
+
}
|
|
113
|
+
if (units.length >= 512) flushUnits(units, chunks);
|
|
114
|
+
}
|
|
115
|
+
flushUnits(units, chunks);
|
|
116
|
+
return chunks.join("");
|
|
27
117
|
}
|
|
28
118
|
|
|
29
|
-
/** Encode text as UTF-8
|
|
119
|
+
/** Encode host text as a UTF-8 byte string. */
|
|
30
120
|
function encodeUtf8(text: string): string {
|
|
31
121
|
const chunks: string[] = [];
|
|
32
122
|
const units: number[] = [];
|
|
@@ -57,17 +147,23 @@ function encodeUtf8(text: string): string {
|
|
|
57
147
|
return chunks.join("");
|
|
58
148
|
}
|
|
59
149
|
|
|
60
|
-
/**
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
150
|
+
/** One code unit per byte of a file buffer. */
|
|
151
|
+
function bytesToString(bytes: Uint8Array): string {
|
|
152
|
+
const chunks: string[] = [];
|
|
153
|
+
const units: number[] = [];
|
|
154
|
+
for (let index = 0; index < bytes.length; index++) {
|
|
155
|
+
units.push(bytes[index]!);
|
|
156
|
+
if (units.length >= 512) flushUnits(units, chunks);
|
|
64
157
|
}
|
|
65
|
-
|
|
158
|
+
flushUnits(units, chunks);
|
|
159
|
+
return chunks.join("");
|
|
66
160
|
}
|
|
67
161
|
|
|
68
|
-
/** Whether
|
|
69
|
-
function
|
|
70
|
-
return text.charCodeAt(0) === 0xef && text.charCodeAt(1) === 0xbb && text.charCodeAt(2) === 0xbf
|
|
162
|
+
/** Whether the text starts with the UTF-8 encoding of a BOM. */
|
|
163
|
+
function stripBom(text: string): string {
|
|
164
|
+
return text.charCodeAt(0) === 0xef && text.charCodeAt(1) === 0xbb && text.charCodeAt(2) === 0xbf
|
|
165
|
+
? text.slice(3)
|
|
166
|
+
: text;
|
|
71
167
|
}
|
|
72
168
|
|
|
73
169
|
/** Append the pending code units as one chunk of the byte string. */
|
|
@@ -75,4 +171,4 @@ function flushUnits(units: number[], chunks: string[]): void {
|
|
|
75
171
|
if (units.length === 0) return;
|
|
76
172
|
chunks.push(String.fromCharCode(...units));
|
|
77
173
|
units.length = 0;
|
|
78
|
-
}
|
|
174
|
+
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Source file abstraction: owns the raw text plus a line-offset index so
|
|
3
|
-
* positions (
|
|
2
|
+
* Source file abstraction: owns the raw byte text plus a line-offset index so
|
|
3
|
+
* that positions (byte offsets) can be mapped back to line/column pairs for
|
|
4
4
|
* diagnostics and for incremental-compilation fingerprints.
|
|
5
|
+
*
|
|
6
|
+
* `text` is the compiler's internal representation: UTF-8 bytes, one code unit
|
|
7
|
+
* per byte (see `source-text.ts`). Offsets in the AST and diagnostics are
|
|
8
|
+
* indexes into that byte string. `positionAt` reports the line and the column
|
|
9
|
+
* a reader sees, so the column is counted in UTF-16 code units after decoding
|
|
10
|
+
* the line prefix; the raw byte column would drift from an editor's column as
|
|
11
|
+
* soon as a line contains non-ASCII text.
|
|
5
12
|
*/
|
|
6
13
|
|
|
14
|
+
import { decodeSourceBytes } from "./source-text.js";
|
|
15
|
+
|
|
7
16
|
export interface LineAndColumn {
|
|
8
17
|
/** 1-based line number. */
|
|
9
18
|
readonly line: number;
|
|
10
|
-
/** 1-based column number (UTF-16 code units). */
|
|
19
|
+
/** 1-based column number (UTF-16 code units, as an editor counts). */
|
|
11
20
|
readonly column: number;
|
|
12
21
|
}
|
|
13
22
|
|
|
14
23
|
/**
|
|
15
|
-
* A text position. `offset` is a
|
|
16
|
-
*
|
|
24
|
+
* A text position. `offset` is a byte index into the source's internal UTF-8
|
|
25
|
+
* representation (`SourceFile.text`), not a UTF-16 code-unit index.
|
|
17
26
|
*/
|
|
18
27
|
export interface TextPosition {
|
|
19
28
|
readonly offset: number;
|
|
@@ -26,6 +35,7 @@ export interface TextRange {
|
|
|
26
35
|
|
|
27
36
|
export class SourceFile {
|
|
28
37
|
readonly fileName: string;
|
|
38
|
+
/** Internal UTF-8 byte text: one code unit per byte. */
|
|
29
39
|
readonly text: string;
|
|
30
40
|
/** Content hash used by the incremental compiler. */
|
|
31
41
|
readonly hash: string;
|
|
@@ -34,6 +44,8 @@ export class SourceFile {
|
|
|
34
44
|
constructor(fileName: string, text: string) {
|
|
35
45
|
this.fileName = fileName;
|
|
36
46
|
// Normalize BOM and line endings so downstream stages only deal with "\n".
|
|
47
|
+
// A file read through `readSourceText` already dropped the byte BOM; a
|
|
48
|
+
// host text argument may still carry the U+FEFF code unit.
|
|
37
49
|
const normalized = text.charCodeAt(0) === 0xfeff ? text.slice(1) : text;
|
|
38
50
|
this.text = normalized.replace(/\r\n?/g, "\n");
|
|
39
51
|
this.hash = hashText(this.text);
|
|
@@ -66,10 +78,20 @@ export class SourceFile {
|
|
|
66
78
|
if (starts[mid]! <= clamped) lo = mid;
|
|
67
79
|
else hi = mid - 1;
|
|
68
80
|
}
|
|
69
|
-
|
|
81
|
+
const prefix = this.text.slice(starts[lo]!, clamped);
|
|
82
|
+
return { line: lo + 1, column: decodeSourceBytes(prefix).length + 1 };
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The display text of a 1-based line, without its trailing newline. */
|
|
86
|
+
lineText(line: number): string {
|
|
87
|
+
const starts = this.getLineStarts();
|
|
88
|
+
if (line < 1 || line > starts.length) return "";
|
|
89
|
+
const start = starts[line - 1]!;
|
|
90
|
+
const next = line < starts.length ? starts[line]! - 1 : this.text.length;
|
|
91
|
+
return decodeSourceBytes(this.text.slice(start, next));
|
|
70
92
|
}
|
|
71
93
|
|
|
72
|
-
/** Extract the raw source text covered by a range. */
|
|
94
|
+
/** Extract the raw source text covered by a range (internal byte text). */
|
|
73
95
|
slice(range: TextRange): string {
|
|
74
96
|
return this.text.slice(range.start, range.end);
|
|
75
97
|
}
|
package/src/driver/build-key.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface CacheKeyInput {
|
|
|
27
27
|
readonly sourceText: string;
|
|
28
28
|
readonly emit: string;
|
|
29
29
|
readonly optimize: string;
|
|
30
|
+
/** Host architecture; a shared cache must not serve an x64 binary to arm64. */
|
|
31
|
+
readonly arch: string;
|
|
30
32
|
readonly registry: ExtensionRegistry;
|
|
31
33
|
readonly runtimeDir: string;
|
|
32
34
|
readonly icon?: IconInfo;
|
|
@@ -41,11 +43,24 @@ export interface CacheKeyInput {
|
|
|
41
43
|
readonly pgoDir: string;
|
|
42
44
|
/** Active optional link features; they change which objects/archives link. */
|
|
43
45
|
readonly features?: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* The compiler the build will invoke. `undefined` for `emit: "ir"`, which
|
|
48
|
+
* needs no toolchain. A different clang/SDK produces a different binary, so
|
|
49
|
+
* it must invalidate the cache.
|
|
50
|
+
*/
|
|
51
|
+
readonly toolchain?: CacheKeyToolchain;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** The toolchain inputs that change the linked output. */
|
|
55
|
+
export interface CacheKeyToolchain {
|
|
56
|
+
readonly clang: string;
|
|
57
|
+
readonly sdkRoot?: string;
|
|
58
|
+
readonly linkerArgs: readonly string[];
|
|
44
59
|
}
|
|
45
60
|
|
|
46
61
|
/** Hash every input that can change the produced binary. */
|
|
47
62
|
export function buildCacheKey(input: CacheKeyInput): string {
|
|
48
|
-
const { app, icon, pgo, storage } = input;
|
|
63
|
+
const { app, icon, pgo, storage, toolchain } = input;
|
|
49
64
|
return hashParts([
|
|
50
65
|
COMPILER_VERSION,
|
|
51
66
|
compilerFingerprint(),
|
|
@@ -53,6 +68,10 @@ export function buildCacheKey(input: CacheKeyInput): string {
|
|
|
53
68
|
input.emit,
|
|
54
69
|
input.optimize,
|
|
55
70
|
process.platform,
|
|
71
|
+
input.arch,
|
|
72
|
+
toolchain?.clang ?? "",
|
|
73
|
+
toolchain?.sdkRoot ?? "",
|
|
74
|
+
[...(toolchain?.linkerArgs ?? [])].join(" "),
|
|
56
75
|
registryFingerprint(input.registry),
|
|
57
76
|
runtimeFingerprint(input.runtimeDir),
|
|
58
77
|
vendoredRuntimeFingerprint(input.runtimeDir),
|
|
@@ -60,6 +79,7 @@ export function buildCacheKey(input: CacheKeyInput): string {
|
|
|
60
79
|
app.name ?? "",
|
|
61
80
|
String(app.bundle ?? false),
|
|
62
81
|
app.bundleId ?? "",
|
|
82
|
+
String(app.console === true),
|
|
63
83
|
storage.backend,
|
|
64
84
|
storage.path,
|
|
65
85
|
String(input.debug),
|
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
type VariableDeclarationList,
|
|
25
25
|
} from "../../ast/nodes.js";
|
|
26
26
|
import { SymbolKind } from "../../binder/binder.js";
|
|
27
|
+
import type { AssetSourceRange } from "../../extensions/registry.js";
|
|
27
28
|
import {
|
|
28
29
|
assignmentStatement,
|
|
29
30
|
deferredAliasDeclarations,
|
|
@@ -78,17 +79,22 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
78
79
|
* src="app.js">` body, say. Nodes inside such a span keep that file, so a
|
|
79
80
|
* diagnostic points at real source and a plain-`.js` script stays exempt
|
|
80
81
|
* from the type checker. */
|
|
81
|
-
const originOf = (record: ModuleRecord, node: Node):
|
|
82
|
+
const originOf = (record: ModuleRecord, node: Node): AssetSourceRange | undefined => {
|
|
82
83
|
const ranges = record.originRanges;
|
|
83
|
-
if (ranges === undefined) return
|
|
84
|
+
if (ranges === undefined) return undefined;
|
|
84
85
|
for (const range of ranges) {
|
|
85
|
-
if (node.start >= range.start && node.end <= range.end) return range
|
|
86
|
+
if (node.start >= range.start && node.end <= range.end) return range;
|
|
86
87
|
}
|
|
87
|
-
return
|
|
88
|
+
return undefined;
|
|
88
89
|
};
|
|
90
|
+
/* Inline `<script>` bodies in an HTML page are JavaScript unless the tag says
|
|
91
|
+
* otherwise; the checker must not infer types from them. */
|
|
92
|
+
const untypedNodes = new Set<object>();
|
|
89
93
|
const trackOrigin = (record: ModuleRecord, root: Node): void => {
|
|
90
94
|
const visit = (node: Node): void => {
|
|
91
|
-
|
|
95
|
+
const range = originOf(record, node);
|
|
96
|
+
origins.set(node, range?.file ?? record.path);
|
|
97
|
+
if (range?.untyped) untypedNodes.add(node);
|
|
92
98
|
const fields = node as unknown as Record<string, unknown>;
|
|
93
99
|
for (const key of Object.keys(fields)) {
|
|
94
100
|
if (key === "kind" || key === "start" || key === "end" || key === "text" || key === "value" || key === "raw") {
|
|
@@ -254,6 +260,7 @@ export function concatenateModules(options: ConcatenateOptions): SourceFileNode
|
|
|
254
260
|
statements: merged,
|
|
255
261
|
fileName: first.path,
|
|
256
262
|
origins,
|
|
263
|
+
...(untypedNodes.size > 0 ? { untypedNodes } : {}),
|
|
257
264
|
moduleTexts: new Map(records.map((record) => [record.path, record.text])),
|
|
258
265
|
modulePrefixes: records.map((record) => record.prefix),
|
|
259
266
|
text: records.map((record) => record.text).join("\n"),
|
|
@@ -9,7 +9,7 @@ import { SyntaxKind, type ExportDeclaration, type ImportDeclaration, type NamedE
|
|
|
9
9
|
import { bind } from "../../binder/binder.js";
|
|
10
10
|
import { DiagnosticBag, DiagnosticCode } from "../../diagnostics/diagnostic.js";
|
|
11
11
|
import { SourceFile } from "../../diagnostics/source.js";
|
|
12
|
-
import {
|
|
12
|
+
import { sourceTextFromBytes } from "../../diagnostics/source-text.js";
|
|
13
13
|
import { Parser } from "../../parser/parser.js";
|
|
14
14
|
import type { AssetLoader } from "../../extensions/registry.js";
|
|
15
15
|
import { classifyDependency } from "./resolve.js";
|
|
@@ -103,7 +103,7 @@ export function loadGraph(
|
|
|
103
103
|
const fileBytes = readFileSync(path);
|
|
104
104
|
const raw = loader?.binary === true
|
|
105
105
|
? fileBytes.toString("latin1")
|
|
106
|
-
:
|
|
106
|
+
: sourceTextFromBytes(fileBytes);
|
|
107
107
|
let text = raw;
|
|
108
108
|
let originRanges: readonly OriginRange[] | undefined;
|
|
109
109
|
if (loader) {
|
|
@@ -115,9 +115,15 @@ export function bundleModules(
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
} else if (!declaration.exportClause && declaration.moduleSpecifier) {
|
|
118
|
-
// `export * from "..."`: copy every re-exported name.
|
|
118
|
+
// `export * from "..."`: copy every re-exported name. A star export
|
|
119
|
+
// never re-exports `default`; the module's own default must win.
|
|
119
120
|
const dependency = dependencyOf(record, declaration.moduleSpecifier.value);
|
|
120
|
-
if (dependency)
|
|
121
|
+
if (dependency) {
|
|
122
|
+
for (const [name, value] of dependency.exports) {
|
|
123
|
+
if (name === "default") continue;
|
|
124
|
+
record.exports.set(name, value);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
121
127
|
} else if (declaration.exportClause?.kind === SyntaxKind.NamespaceImport && declaration.moduleSpecifier) {
|
|
122
128
|
// `export * as ns from "..."`: re-export the dependency's namespace.
|
|
123
129
|
const nsName = (declaration.exportClause as { name: Identifier }).name.text;
|
|
@@ -198,9 +204,10 @@ export function bundleModules(
|
|
|
198
204
|
}
|
|
199
205
|
} else if (!clause) {
|
|
200
206
|
/* `export * from "./dep"`: alias every runtime export the deferred
|
|
201
|
-
* dependency contributes, so our own wrapper can return them.
|
|
207
|
+
* dependency contributes, so our own wrapper can return them.
|
|
208
|
+
* `default` is not part of a star export. */
|
|
202
209
|
for (const [name, target] of dependency.exports) {
|
|
203
|
-
if (!target) continue;
|
|
210
|
+
if (name === "default" || !target) continue;
|
|
204
211
|
const alias = deferredAliasName(record, aliases.length, `re_${name}`);
|
|
205
212
|
aliases.push({
|
|
206
213
|
name: alias,
|
|
@@ -64,6 +64,8 @@ export function resolveReexports(
|
|
|
64
64
|
}
|
|
65
65
|
} else if (!clause) {
|
|
66
66
|
for (const [name, value] of dependency.exports) {
|
|
67
|
+
// `export *` re-exports named exports only, never `default`.
|
|
68
|
+
if (name === "default") continue;
|
|
67
69
|
if (record.exports.get(name) !== value) {
|
|
68
70
|
record.exports.set(name, value);
|
|
69
71
|
changed = true;
|