xbintsc 0.5.6 → 0.5.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +16 -8
- package/README.md +8 -7
- package/README.zh-CN.md +6 -6
- package/dist/src/binder/declarations.js +14 -3
- package/dist/src/binder/declarations.js.map +1 -1
- package/dist/src/cli/hints.js +7 -1
- package/dist/src/cli/hints.js.map +1 -1
- package/dist/src/cli/main.js +115 -15
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/cli/watch.d.ts +25 -0
- package/dist/src/cli/watch.js +93 -0
- package/dist/src/cli/watch.js.map +1 -0
- package/dist/src/codegen/generator/calls/access.js +11 -2
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/closures.js +12 -4
- package/dist/src/codegen/generator/calls/closures.js.map +1 -1
- package/dist/src/codegen/generator/context.d.ts +8 -0
- package/dist/src/codegen/generator/context.js +22 -3
- package/dist/src/codegen/generator/context.js.map +1 -1
- package/dist/src/codegen/generator/expressions/operators.js +17 -15
- package/dist/src/codegen/generator/expressions/operators.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.js +5 -0
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/module.js +0 -7
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/numeric.d.ts +6 -3
- package/dist/src/codegen/generator/numeric.js +54 -11
- package/dist/src/codegen/generator/numeric.js.map +1 -1
- package/dist/src/codegen/generator/state.js +23 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/statements/control-flow.js +1 -4
- package/dist/src/codegen/generator/statements/control-flow.js.map +1 -1
- package/dist/src/codegen/generator/statements/loops.js +48 -16
- package/dist/src/codegen/generator/statements/loops.js.map +1 -1
- package/dist/src/codegen/generator/tables.js +26 -1
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.d.ts +3 -1
- package/dist/src/diagnostics/diagnostic.js +23 -3
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/driver/app-artifacts.d.ts +42 -0
- package/dist/src/driver/app-artifacts.js +53 -0
- package/dist/src/driver/app-artifacts.js.map +1 -0
- package/dist/src/driver/build-key.d.ts +29 -0
- package/dist/src/driver/build-key.js +35 -0
- package/dist/src/driver/build-key.js.map +1 -0
- package/dist/src/driver/bundler/graph.js +61 -12
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +7 -1
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/compiler.d.ts +10 -67
- package/dist/src/driver/compiler.js +94 -233
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +3 -0
- package/dist/src/driver/config.js +8 -0
- package/dist/src/driver/config.js.map +1 -1
- package/dist/src/driver/frontend.d.ts +37 -0
- package/dist/src/driver/frontend.js +92 -0
- package/dist/src/driver/frontend.js.map +1 -0
- package/dist/src/driver/index.d.ts +1 -1
- package/dist/src/driver/index.js.map +1 -1
- package/dist/src/driver/options.d.ts +64 -0
- package/dist/src/driver/options.js +9 -0
- package/dist/src/driver/options.js.map +1 -0
- package/dist/src/driver/runtime-objects.d.ts +38 -0
- package/dist/src/driver/runtime-objects.js +111 -0
- package/dist/src/driver/runtime-objects.js.map +1 -0
- package/dist/src/driver/toolchain-provider.d.ts +4 -0
- package/dist/src/driver/toolchain-provider.js +4 -0
- package/dist/src/driver/toolchain-provider.js.map +1 -1
- package/dist/src/driver/toolchain.d.ts +32 -1
- package/dist/src/driver/toolchain.js +115 -11
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +12 -0
- package/dist/src/driver/version.js +13 -0
- package/dist/src/driver/version.js.map +1 -0
- package/dist/src/driver/win-icon.d.ts +7 -9
- package/dist/src/driver/win-icon.js +37 -35
- package/dist/src/driver/win-icon.js.map +1 -1
- package/dist/src/parser/declarations/classes.js +5 -0
- package/dist/src/parser/declarations/classes.js.map +1 -1
- package/dist/src/parser/declarations/functions.js +13 -1
- package/dist/src/parser/declarations/functions.js.map +1 -1
- package/dist/src/parser/modules.js +8 -3
- package/dist/src/parser/modules.js.map +1 -1
- package/dist/src/parser/parser.d.ts +1 -0
- package/dist/src/parser/parser.js +23 -0
- package/dist/src/parser/parser.js.map +1 -1
- package/dist/tests/cli/check.test.d.ts +6 -0
- package/dist/tests/cli/check.test.js +68 -0
- package/dist/tests/cli/check.test.js.map +1 -0
- package/dist/tests/cli/main.test.js +19 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/cli/watch.test.d.ts +6 -0
- package/dist/tests/cli/watch.test.js +72 -0
- package/dist/tests/cli/watch.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +15 -3
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +16 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +8 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/docs/structure.test.d.ts +1 -0
- package/dist/tests/docs/structure.test.js +92 -0
- package/dist/tests/docs/structure.test.js.map +1 -0
- package/dist/tests/driver/compiler.test.js +6 -0
- package/dist/tests/driver/compiler.test.js.map +1 -1
- package/dist/tests/driver/config.test.js +9 -0
- package/dist/tests/driver/config.test.js.map +1 -1
- package/dist/tests/driver/icon.test.js +19 -32
- package/dist/tests/driver/icon.test.js.map +1 -1
- package/dist/tests/driver/invalid-input.test.d.ts +10 -0
- package/dist/tests/driver/invalid-input.test.js +29 -0
- package/dist/tests/driver/invalid-input.test.js.map +1 -0
- package/dist/tests/driver/modules.test.js +42 -3
- package/dist/tests/driver/modules.test.js.map +1 -1
- package/dist/tests/driver/toolchain-provider.test.js +27 -1
- package/dist/tests/driver/toolchain-provider.test.js.map +1 -1
- package/dist/tests/driver/toolchain.test.js +60 -2
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/e2e/array-buffer.test.d.ts +5 -0
- package/dist/tests/e2e/array-buffer.test.js +38 -0
- package/dist/tests/e2e/array-buffer.test.js.map +1 -0
- package/dist/tests/e2e/array-from-iterables.test.d.ts +7 -0
- package/dist/tests/e2e/array-from-iterables.test.js +34 -0
- package/dist/tests/e2e/array-from-iterables.test.js.map +1 -0
- package/dist/tests/e2e/array-symbol-iterator.test.d.ts +8 -0
- package/dist/tests/e2e/array-symbol-iterator.test.js +42 -0
- package/dist/tests/e2e/array-symbol-iterator.test.js.map +1 -0
- package/dist/tests/e2e/async-generators.test.d.ts +1 -0
- package/dist/tests/e2e/async-generators.test.js +154 -0
- package/dist/tests/e2e/async-generators.test.js.map +1 -0
- package/dist/tests/e2e/await-ordering.test.d.ts +5 -0
- package/dist/tests/e2e/await-ordering.test.js +37 -0
- package/dist/tests/e2e/await-ordering.test.js.map +1 -0
- package/dist/tests/e2e/compile-builtins.test.js +1 -1
- package/dist/tests/e2e/compile-modules.test.js +7 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/date-parse.test.d.ts +8 -0
- package/dist/tests/e2e/date-parse.test.js +38 -0
- package/dist/tests/e2e/date-parse.test.js.map +1 -0
- package/dist/tests/e2e/default-anonymous-exports.test.d.ts +7 -0
- package/dist/tests/e2e/default-anonymous-exports.test.js +23 -0
- package/dist/tests/e2e/default-anonymous-exports.test.js.map +1 -0
- package/dist/tests/e2e/globals-microtask.test.d.ts +9 -0
- package/dist/tests/e2e/globals-microtask.test.js +37 -0
- package/dist/tests/e2e/globals-microtask.test.js.map +1 -0
- package/dist/tests/e2e/gui-media.test.js +8 -1
- package/dist/tests/e2e/gui-media.test.js.map +1 -1
- package/dist/tests/e2e/inspect-builtins.test.d.ts +10 -0
- package/dist/tests/e2e/inspect-builtins.test.js +43 -0
- package/dist/tests/e2e/inspect-builtins.test.js.map +1 -0
- package/dist/tests/e2e/json-builtin-objects.test.d.ts +9 -0
- package/dist/tests/e2e/json-builtin-objects.test.js +23 -0
- package/dist/tests/e2e/json-builtin-objects.test.js.map +1 -0
- package/dist/tests/e2e/json-circular.test.d.ts +6 -0
- package/dist/tests/e2e/json-circular.test.js +43 -0
- package/dist/tests/e2e/json-circular.test.js.map +1 -0
- package/dist/tests/e2e/json-parse-reviver.test.d.ts +6 -0
- package/dist/tests/e2e/json-parse-reviver.test.js +29 -0
- package/dist/tests/e2e/json-parse-reviver.test.js.map +1 -0
- package/dist/tests/e2e/json-stringify-replacer.test.d.ts +6 -0
- package/dist/tests/e2e/json-stringify-replacer.test.js +27 -0
- package/dist/tests/e2e/json-stringify-replacer.test.js.map +1 -0
- package/dist/tests/e2e/json-stringify-space.test.d.ts +6 -0
- package/dist/tests/e2e/json-stringify-space.test.js +23 -0
- package/dist/tests/e2e/json-stringify-space.test.js.map +1 -0
- package/dist/tests/e2e/method-dispatch-errors.test.d.ts +9 -0
- package/dist/tests/e2e/method-dispatch-errors.test.js +38 -0
- package/dist/tests/e2e/method-dispatch-errors.test.js.map +1 -0
- package/dist/tests/e2e/native-extensions.test.js +1 -1
- package/dist/tests/e2e/native-extensions.test.js.map +1 -1
- package/dist/tests/e2e/promise-with-resolvers.test.d.ts +5 -0
- package/dist/tests/e2e/promise-with-resolvers.test.js +20 -0
- package/dist/tests/e2e/promise-with-resolvers.test.js.map +1 -0
- package/dist/tests/e2e/property-descriptors.test.d.ts +5 -0
- package/dist/tests/e2e/property-descriptors.test.js +25 -0
- package/dist/tests/e2e/property-descriptors.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.d.ts +1 -0
- package/dist/tests/e2e/property-ic.test.js +55 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -0
- package/dist/tests/e2e/runtime-errors.test.d.ts +10 -0
- package/dist/tests/e2e/runtime-errors.test.js +52 -0
- package/dist/tests/e2e/runtime-errors.test.js.map +1 -0
- package/dist/tests/e2e/structured-clone.test.d.ts +6 -0
- package/dist/tests/e2e/structured-clone.test.js +49 -0
- package/dist/tests/e2e/structured-clone.test.js.map +1 -0
- package/dist/tests/e2e/text-codec.test.d.ts +6 -0
- package/dist/tests/e2e/text-codec.test.js +24 -0
- package/dist/tests/e2e/text-codec.test.js.map +1 -0
- package/dist/tests/e2e/typed-array-views.test.d.ts +6 -0
- package/dist/tests/e2e/typed-array-views.test.js +39 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -0
- package/dist/tests/e2e/url-search-params.test.d.ts +5 -0
- package/dist/tests/e2e/url-search-params.test.js +30 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -0
- package/dist/tests/e2e/weak-collections.test.d.ts +1 -0
- package/dist/tests/e2e/weak-collections.test.js +88 -0
- package/dist/tests/e2e/weak-collections.test.js.map +1 -0
- package/dist/tests/parser/declarations.test.js +12 -0
- package/dist/tests/parser/declarations.test.js.map +1 -1
- package/dist/tests/parser/module-syntax.test.js +9 -0
- package/dist/tests/parser/module-syntax.test.js.map +1 -1
- package/dist/tests/parser/parser.test.js +7 -0
- package/dist/tests/parser/parser.test.js.map +1 -1
- package/dist/tests/version.test.js +5 -1
- package/dist/tests/version.test.js.map +1 -1
- package/doc/ai/README.md +4 -3
- package/doc/ai/cli.md +41 -0
- package/doc/ai/contributing.md +18 -15
- package/doc/ai/extensions.md +9 -7
- package/doc/ai/language-support.md +17 -13
- package/doc/ai/troubleshooting.md +11 -9
- package/doc/ai/zh-CN/README.md +3 -2
- package/doc/ai/zh-CN/cli.md +35 -0
- package/doc/ai/zh-CN/contributing.md +15 -14
- package/doc/ai/zh-CN/extensions.md +8 -6
- package/doc/ai/zh-CN/language-support.md +17 -14
- package/doc/ai/zh-CN/troubleshooting.md +9 -8
- package/doc/gui/build.md +13 -4
- package/doc/gui/known-issues.md +9 -5
- package/doc/gui/rendering.md +3 -1
- package/doc/gui.md +4 -3
- package/doc/icon.md +5 -4
- package/doc/implemented/async.md +38 -0
- package/doc/implemented/binder.md +13 -0
- package/doc/implemented/cli.md +47 -0
- package/doc/implemented/codegen.md +33 -0
- package/doc/implemented/collections.md +26 -0
- package/doc/implemented/driver.md +19 -0
- package/doc/implemented/extensions.md +19 -0
- package/doc/implemented/fetch.md +12 -0
- package/doc/implemented/lexer.md +23 -0
- package/doc/implemented/modules.md +28 -0
- package/doc/implemented/node/assert.md +17 -0
- package/doc/implemented/node/buffer.md +29 -0
- package/doc/implemented/node/child-process.md +29 -0
- package/doc/implemented/node/crypto.md +9 -0
- package/doc/implemented/node/dgram.md +15 -0
- package/doc/implemented/node/events.md +37 -0
- package/doc/implemented/node/fs-promises.md +38 -0
- package/doc/implemented/node/fs.md +112 -0
- package/doc/implemented/node/http.md +21 -0
- package/doc/implemented/node/net.md +17 -0
- package/doc/implemented/node/os.md +22 -0
- package/doc/implemented/node/path.md +33 -0
- package/doc/implemented/node/process.md +23 -0
- package/doc/implemented/node/querystring.md +20 -0
- package/doc/implemented/node/stream-promises.md +8 -0
- package/doc/implemented/node/stream.md +19 -0
- package/doc/implemented/node/test.md +10 -0
- package/doc/implemented/node/url.md +8 -0
- package/doc/implemented/node/util.md +25 -0
- package/doc/implemented/node/worker-threads.md +10 -0
- package/doc/implemented/node/zlib.md +8 -0
- package/doc/implemented/node.md +48 -0
- package/doc/implemented/operators.md +38 -0
- package/doc/implemented/parser.md +58 -0
- package/doc/implemented/pipeline.md +28 -0
- package/doc/implemented/runtime-core.md +32 -0
- package/doc/implemented/stdlib.md +78 -0
- package/doc/implemented/strings.md +27 -0
- package/doc/implemented/tests.md +10 -0
- package/doc/implemented/typed-arrays.md +26 -0
- package/doc/implemented/value-model.md +18 -0
- package/doc/implemented.md +54 -355
- package/doc/node-implemented.md +3 -585
- package/doc/node-unimplemented.md +3 -164
- package/doc/requirements.md +23 -8
- package/doc/unimplemented/classes.md +22 -0
- package/doc/unimplemented/deviations.md +27 -0
- package/doc/unimplemented/expressions.md +26 -0
- package/doc/unimplemented/functions.md +21 -0
- package/doc/unimplemented/modules.md +22 -0
- package/doc/unimplemented/node/async.md +17 -0
- package/doc/unimplemented/node/bun.md +9 -0
- package/doc/unimplemented/node/fs-promises.md +16 -0
- package/doc/unimplemented/node/fs.md +31 -0
- package/doc/unimplemented/node/globals.md +23 -0
- package/doc/unimplemented/node/modules.md +21 -0
- package/doc/unimplemented/node.md +21 -0
- package/doc/unimplemented/statements.md +18 -0
- package/doc/unimplemented/stdlib.md +54 -0
- package/doc/unimplemented/toolchain.md +14 -0
- package/doc/unimplemented/types.md +12 -0
- package/doc/unimplemented.md +18 -275
- package/doc/xbintsc.config.schema.json +12 -0
- package/doc/zh-CN/gui/build.md +11 -3
- package/doc/zh-CN/gui/known-issues.md +9 -4
- package/doc/zh-CN/gui/rendering.md +2 -1
- package/doc/zh-CN/gui.md +3 -2
- package/doc/zh-CN/icon.md +5 -4
- package/doc/zh-CN/implemented/async.md +38 -0
- package/doc/zh-CN/implemented/binder.md +13 -0
- package/doc/zh-CN/implemented/cli.md +46 -0
- package/doc/zh-CN/implemented/codegen.md +33 -0
- package/doc/zh-CN/implemented/collections.md +26 -0
- package/doc/zh-CN/implemented/driver.md +19 -0
- package/doc/zh-CN/implemented/extensions.md +19 -0
- package/doc/zh-CN/implemented/fetch.md +12 -0
- package/doc/zh-CN/implemented/lexer.md +23 -0
- package/doc/zh-CN/implemented/modules.md +28 -0
- package/doc/zh-CN/implemented/node/assert.md +17 -0
- package/doc/zh-CN/implemented/node/buffer.md +25 -0
- package/doc/zh-CN/implemented/node/child-process.md +27 -0
- package/doc/zh-CN/implemented/node/crypto.md +9 -0
- package/doc/zh-CN/implemented/node/dgram.md +15 -0
- package/doc/zh-CN/implemented/node/events.md +36 -0
- package/doc/zh-CN/implemented/node/fs-promises.md +27 -0
- package/doc/zh-CN/implemented/node/fs.md +105 -0
- package/doc/zh-CN/implemented/node/http.md +17 -0
- package/doc/zh-CN/implemented/node/net.md +17 -0
- package/doc/zh-CN/implemented/node/os.md +21 -0
- package/doc/zh-CN/implemented/node/path.md +26 -0
- package/doc/zh-CN/implemented/node/process.md +23 -0
- package/doc/zh-CN/implemented/node/querystring.md +20 -0
- package/doc/zh-CN/implemented/node/stream-promises.md +8 -0
- package/doc/zh-CN/implemented/node/stream.md +15 -0
- package/doc/zh-CN/implemented/node/test.md +10 -0
- package/doc/zh-CN/implemented/node/url.md +8 -0
- package/doc/zh-CN/implemented/node/util.md +25 -0
- package/doc/zh-CN/implemented/node/worker-threads.md +9 -0
- package/doc/zh-CN/implemented/node/zlib.md +8 -0
- package/doc/zh-CN/implemented/node.md +45 -0
- package/doc/zh-CN/implemented/operators.md +38 -0
- package/doc/zh-CN/implemented/parser.md +58 -0
- package/doc/zh-CN/implemented/pipeline.md +25 -0
- package/doc/zh-CN/implemented/runtime-core.md +31 -0
- package/doc/zh-CN/implemented/stdlib.md +76 -0
- package/doc/zh-CN/implemented/strings.md +27 -0
- package/doc/zh-CN/implemented/tests.md +10 -0
- package/doc/zh-CN/implemented/typed-arrays.md +26 -0
- package/doc/zh-CN/implemented/value-model.md +18 -0
- package/doc/zh-CN/implemented.md +50 -350
- package/doc/zh-CN/node-implemented.md +4 -531
- package/doc/zh-CN/node-unimplemented.md +4 -139
- package/doc/zh-CN/plan-require-node-modules.md +4 -4
- package/doc/zh-CN/requirements.md +20 -6
- package/doc/zh-CN/unimplemented/classes.md +22 -0
- package/doc/zh-CN/unimplemented/deviations.md +24 -0
- package/doc/zh-CN/unimplemented/expressions.md +24 -0
- package/doc/zh-CN/unimplemented/functions.md +21 -0
- package/doc/zh-CN/unimplemented/modules.md +19 -0
- package/doc/zh-CN/unimplemented/node/async.md +17 -0
- package/doc/zh-CN/unimplemented/node/bun.md +8 -0
- package/doc/zh-CN/unimplemented/node/fs-promises.md +12 -0
- package/doc/zh-CN/unimplemented/node/fs.md +24 -0
- package/doc/zh-CN/unimplemented/node/globals.md +14 -0
- package/doc/zh-CN/unimplemented/node/modules.md +15 -0
- package/doc/zh-CN/unimplemented/node.md +18 -0
- package/doc/zh-CN/unimplemented/statements.md +15 -0
- package/doc/zh-CN/unimplemented/stdlib.md +54 -0
- package/doc/zh-CN/unimplemented/toolchain.md +14 -0
- package/doc/zh-CN/unimplemented/types.md +11 -0
- package/doc/zh-CN/unimplemented.md +14 -237
- package/llms.txt +32 -4
- package/package.json +1 -1
- package/runtime/ext_gui/renderer_shaders.h +2 -2
- package/runtime/ext_gui/stb_image.h +1 -17
- package/runtime/ext_node/child_process/child_process.c +173 -73
- package/runtime/rt.h +15 -0
- package/runtime/rt_internal.h +106 -0
- package/runtime/xt_alloc.c +43 -7
- package/runtime/xt_array_buffer.c +284 -0
- package/runtime/xt_async.c +46 -21
- package/runtime/xt_bigint/helpers.inc +3 -3
- package/runtime/xt_builtins.c +21 -17
- package/runtime/xt_constructors.c +12 -2
- package/runtime/xt_containers/access.inc +148 -3
- package/runtime/xt_containers/objects.inc +26 -2
- package/runtime/xt_containers/shapes.inc +71 -0
- package/runtime/xt_containers.c +1 -0
- package/runtime/xt_coroutine.c +17 -0
- package/runtime/xt_generator.c +299 -10
- package/runtime/xt_io/inspect.inc +112 -0
- package/runtime/xt_loop.c +35 -4
- package/runtime/xt_performance.c +37 -0
- package/runtime/xt_promise.c +63 -1
- package/runtime/xt_stdlib/arrays.inc +1 -1
- package/runtime/xt_stdlib/dispatch.inc +46 -11
- package/runtime/xt_stdlib/strings.inc +1 -1
- package/runtime/xt_stdlib2/array-statics.inc +25 -0
- package/runtime/xt_stdlib2/arrays.inc +5 -3
- package/runtime/xt_stdlib2/container.inc +5 -0
- package/runtime/xt_stdlib2/date.inc +111 -3
- package/runtime/xt_stdlib2/error.inc +24 -0
- package/runtime/xt_stdlib2/json.inc +310 -19
- package/runtime/xt_stdlib2/number-string-statics.inc +1 -1
- package/runtime/xt_stdlib2/objects.inc +122 -0
- package/runtime/xt_stdlib2/set.inc +1 -1
- package/runtime/xt_structured_clone.c +159 -0
- package/runtime/xt_symbol.c +2 -2
- package/runtime/xt_text_codec.c +69 -0
- package/runtime/xt_typed_array/construction.inc +35 -5
- package/runtime/xt_typed_array/elements.inc +159 -0
- package/runtime/xt_typed_array/methods.inc +21 -5
- package/runtime/xt_typed_array.c +7 -10
- package/runtime/xt_url.c +375 -0
- package/runtime/xt_values/arithmetic.inc +2 -2
- package/runtime/xt_values/conversions.inc +1 -1
- package/runtime/xt_weak.c +281 -0
- package/scripts/build-gui.ts +133 -60
- package/scripts/check-version.ts +3 -3
- package/src/binder/declarations.ts +14 -3
- package/src/cli/hints.ts +8 -1
- package/src/cli/main.ts +119 -18
- package/src/cli/watch.ts +101 -0
- package/src/codegen/generator/calls/access.ts +10 -2
- package/src/codegen/generator/calls/closures.ts +12 -4
- package/src/codegen/generator/context.ts +23 -3
- package/src/codegen/generator/expressions/operators.ts +27 -13
- package/src/codegen/generator/expressions/primary.ts +4 -0
- package/src/codegen/generator/module.ts +0 -7
- package/src/codegen/generator/numeric.ts +85 -11
- package/src/codegen/generator/state.ts +23 -0
- package/src/codegen/generator/statements/control-flow.ts +1 -4
- package/src/codegen/generator/statements/loops.ts +50 -16
- package/src/codegen/generator/tables.ts +26 -1
- package/src/diagnostics/diagnostic.ts +23 -3
- package/src/driver/app-artifacts.ts +77 -0
- package/src/driver/build-key.ts +55 -0
- package/src/driver/bundler/graph.ts +63 -13
- package/src/driver/bundler/merge.ts +4 -1
- package/src/driver/compiler.ts +93 -327
- package/src/driver/config.ts +11 -0
- package/src/driver/frontend.ts +120 -0
- package/src/driver/index.ts +0 -1
- package/src/driver/options.ts +70 -0
- package/src/driver/runtime-objects.ts +133 -0
- package/src/driver/toolchain-provider.ts +4 -0
- package/src/driver/toolchain.ts +154 -10
- package/src/driver/version.ts +12 -0
- package/src/driver/win-icon.ts +36 -36
- package/src/parser/declarations/classes.ts +4 -0
- package/src/parser/declarations/functions.ts +12 -1
- package/src/parser/modules.ts +8 -4
- package/src/parser/parser.ts +28 -0
|
@@ -6,8 +6,8 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
6
6
|
权威细节(始终最新、篇幅长得多):
|
|
7
7
|
|
|
8
8
|
- [../../zh-CN/implemented.md](../../zh-CN/implemented.md) —— 所有已实现能力,按编译器阶段组织
|
|
9
|
-
- [../../zh-CN/unimplemented.md](../../zh-CN/unimplemented.md) ——
|
|
10
|
-
- [../../zh-CN/node
|
|
9
|
+
- [../../zh-CN/unimplemented.md](../../zh-CN/unimplemented.md) —— 不支持的语法、行为偏差,按领域分页
|
|
10
|
+
- [../../zh-CN/implemented/node.md](../../zh-CN/implemented/node.md) / [../../zh-CN/unimplemented/node.md](../../zh-CN/unimplemented/node.md) —— Node 扩展
|
|
11
11
|
|
|
12
12
|
## 图例
|
|
13
13
|
|
|
@@ -60,7 +60,7 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
60
60
|
| `#private` 字段/方法/静态成员 | ⚠️ | 以字面量 `#x` 键存储;不做访问控制;父子类同名可能互相覆盖 |
|
|
61
61
|
| `enum`/`const enum` | ✅ | 正向 + 反向映射 |
|
|
62
62
|
| `private`/`protected`/`public`/`readonly`/`abstract`/`implements` | — | 被擦除,无访问控制 |
|
|
63
|
-
| 生成器 `function*`、`yield`、`yield*` | ✅ |
|
|
63
|
+
| 生成器 `function*`、`yield`、`yield*` | ✅ | 同步与 `async function*`;支持 `for await...of` 与 `Symbol.asyncIterator` |
|
|
64
64
|
| `arguments` 对象 | ✅ | 隐式提供;箭头函数看到的是自己的参数 |
|
|
65
65
|
| 参数个数校验 | 🚫 | 从不校验,虽然 `fn.length` 会报声明元数 |
|
|
66
66
|
|
|
@@ -68,11 +68,13 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
68
68
|
|
|
69
69
|
| 特性 | 状态 | 说明 |
|
|
70
70
|
| --- | --- | --- |
|
|
71
|
-
| `async`/`await`、`Promise`、`Promise.all` | ✅ | 真实挂起:async 函数体运行在栈式协程上,等待**未 settle** 的 Promise 时暂停,settle
|
|
71
|
+
| `async`/`await`、`Promise`、`Promise.all` | ✅ | 真实挂起:async 函数体运行在栈式协程上,等待**未 settle** 的 Promise 时暂停,settle 后恢复。每次 `await` 都会让出一次,已 settle 的值或非 Promise 也会像 Node 一样排入微任务 |
|
|
72
72
|
| `setTimeout` 与回调 | ✅ | 定时器运行在核心事件循环上;`await new Promise(r => setTimeout(r, ms))` 可用 |
|
|
73
|
+
| `queueMicrotask` / `setImmediate` / `performance.now` | ✅ | 微任务与 Promise 共用 FIFO 队列;`setImmediate` 是零延迟定时器,返回数字 id;`performance.now` 返回单调递增的毫秒小数 |
|
|
73
74
|
| 套接字/服务端(`http`、`net`、`dgram`) | ✅ | 回调在事件循环上执行,可以 settle 你正在 await 的 Promise(测试含 `net`/`http` 示例) |
|
|
74
75
|
| `fs/promises` | ⚠️ | 可以 await,但每次调用仍先同步完成 I/O 再 settle,I/O 期间不会让出 |
|
|
75
|
-
|
|
|
76
|
+
| worker 线程 | 🚫 | worker 是子进程 |
|
|
77
|
+
| `async` 生成器 | ✅ | 可在 `await` 与 `yield` 处挂起;每次 `.next()` 返回 Promise;支持 `for await...of` |
|
|
76
78
|
|
|
77
79
|
## 类型:解析后擦除
|
|
78
80
|
|
|
@@ -91,7 +93,7 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
91
93
|
|
|
92
94
|
## 标准库
|
|
93
95
|
|
|
94
|
-
已实现:`Math`、`JSON`、`Date`、`RegExp`、`Map`、`Set`、`WeakMap`/`WeakSet`、
|
|
96
|
+
已实现:`Math`、`JSON`、`Date`、`RegExp`、`Map`、`Set`、`WeakMap`/`WeakSet`/`WeakRef`、
|
|
95
97
|
`Symbol`、`Error` 家族、`BigInt`、`Array`/`String`/`Number`/`Object` 方法、TypedArray、
|
|
96
98
|
带捕获组的 `String.prototype.match`/`split`/`replace`、不可变数组方法
|
|
97
99
|
(`toReversed`、`toSorted`、`toSpliced`、`with`)、全局 URI 函数、
|
|
@@ -100,12 +102,13 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
100
102
|
|
|
101
103
|
| 缺失或行为不同 | 状态 |
|
|
102
104
|
| --- | --- |
|
|
103
|
-
| `String.prototype.normalize
|
|
105
|
+
| `String.prototype.normalize` | 🚫 |
|
|
106
|
+
| `structuredClone` | ✅ 数组、对象、Map、Set、Date、RegExp 与类型化数组 |
|
|
104
107
|
| `Error.stack` 采集 | ⚠️ 函数级帧(名称/文件/行号),没有列号;生成器函数体不产生帧 |
|
|
105
108
|
| 全局 RegExp `lastIndex` | ⚠️ `/g`、`/y` 下 `test`/`exec` 忽略它 |
|
|
106
109
|
| 稀疏数组空洞、数组越界 | ⚠️ 不区分空洞;越界读得 `undefined` |
|
|
107
110
|
|
|
108
|
-
完整列表见
|
|
111
|
+
完整列表见[未实现:标准库](../../unimplemented/stdlib.md)。
|
|
109
112
|
|
|
110
113
|
## 模块
|
|
111
114
|
|
|
@@ -115,9 +118,9 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
115
118
|
| 相对路径多文件打包 | ✅ | `./helper.js` 会解析到 `helper.ts` |
|
|
116
119
|
| `import * as ns`、默认导入与具名导入 | ✅ | |
|
|
117
120
|
| Node 内置模块 | ✅ | 仅在 `--ext node` 下——见 [extensions.md](./extensions.md) |
|
|
118
|
-
| 裸第三方 npm 包 |
|
|
119
|
-
| `require()` / CommonJS |
|
|
120
|
-
| 循环依赖 | 🚫 | |
|
|
121
|
+
| 裸第三方 npm 包 | ⚠️ | 从 `node_modules` 解析并作为源码打包(ESM 和 CommonJS 均支持);运行时不做包查找,循环依赖会被拒绝 |
|
|
122
|
+
| `require()` / CommonJS | ⚠️ | 在自己的源码里会被拒绝并提示改用 `import`;`node_modules` 内的 CommonJS 包由打包器处理 |
|
|
123
|
+
| 循环依赖 | 🚫 | 仅限值导入;`import type` / `export type` 会被擦除,不构成依赖边 |
|
|
121
124
|
| 实时绑定 | ⚠️ | 导入与命名空间成员都是快照 |
|
|
122
125
|
| `__dirname`、`__filename` | 🚫 | 请使用 `import.meta.dirname` / `import.meta.filename` |
|
|
123
126
|
|
|
@@ -129,14 +132,14 @@ xbintsc 编译 TypeScript 的一个**实用子集**。本页用来判断你能
|
|
|
129
132
|
| 正则 Unicode 匹配 | ⚠️ 引擎按字节工作:字面量 `中` 仍能匹配,但 `.` 与字符类每次只消费一个字节,`\d`/`\w` 仍是 ASCII。匹配偏移(`match.index`、`search`、替换回调)按 UTF-16 码元报告 |
|
|
130
133
|
| 数字格式化与强转 | ✅ 与 Node 一致(`toFixed`、`toPrecision`、十六/八/二进制解析) |
|
|
131
134
|
| `BigInt` | ✅ 已实现 |
|
|
132
|
-
| 垃圾回收 | ✅ 非移动标记清扫;显式根 + C 栈保守扫描;单线程、stop-the-world
|
|
135
|
+
| 垃圾回收 | ✅ 非移动标记清扫;显式根 + C 栈保守扫描;单线程、stop-the-world。`WeakMap`/`WeakSet` 键使用 ephemeron 不动点,`WeakRef` 目标不可达时清空;保守栈上的残留字可能延迟清空 |
|
|
133
136
|
| 线程 | 🚫 单线程;`worker_threads` 只存在于 Node 扩展中 |
|
|
134
137
|
|
|
135
138
|
## 平台
|
|
136
139
|
|
|
137
140
|
构建目标覆盖 macOS、Linux、Windows 的 x64 与 arm64。Windows 上是 **MSVC ABI**,
|
|
138
|
-
clang
|
|
139
|
-
|
|
141
|
+
编译器必须是面向 MSVC 的 clang(Visual Studio 自带的 LLVM 即可)——见
|
|
142
|
+
[../../zh-CN/requirements.md](../../zh-CN/requirements.md)。需要 clang **16 或更新**。
|
|
140
143
|
|
|
141
144
|
## 写大程序之前
|
|
142
145
|
|
|
@@ -47,10 +47,10 @@ export xbintsc_CLANG=/usr/lib/llvm-18/bin/clang
|
|
|
47
47
|
xbintsc run app.ts --ext node
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
### `module '<pkg>' is not supported:
|
|
50
|
+
### `module '<pkg>' is not supported: expected a Node built-in (with --ext node), a relative .ts/.js file, or a package in node_modules`
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
一个既没有被已启用扩展认领、也没能在 `node_modules` 里解析到的裸导入。检查包名和它的
|
|
53
|
+
`exports`/`main` 字段,或改用 `node` 扩展提供的 Node 内置模块;可打包的范围见
|
|
54
54
|
[extensions.md](./extensions.md)。
|
|
55
55
|
|
|
56
56
|
### ``CommonJS `require()` is not supported``
|
|
@@ -91,9 +91,10 @@ clang 自身失败。抛出的消息包含完整的 clang 命令与 stderr——
|
|
|
91
91
|
第一行。常见原因:
|
|
92
92
|
|
|
93
93
|
- 工具链太旧(见上文);
|
|
94
|
-
- Windows
|
|
95
|
-
|
|
96
|
-
Tools
|
|
94
|
+
- Windows 上解析到的 clang 找不到 MSVC/SDK 头文件或库。`xbintsc doctor` 会显示
|
|
95
|
+
编译器及其目标;优先使用 Visual Studio 自带的 LLVM,它会自行定位 SDK。如果你的
|
|
96
|
+
安装仍需要显式导入环境,请在 **x64 Native Tools Command Prompt for VS 2022**
|
|
97
|
+
(ARM64 机器上是 **ARM64 Native Tools**)里运行,或先导入环境:
|
|
97
98
|
```powershell
|
|
98
99
|
& "$env:ProgramFiles\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvarsall.bat" x64
|
|
99
100
|
```
|
|
@@ -110,8 +111,8 @@ clang 自身失败。抛出的消息包含完整的 clang 命令与 stderr——
|
|
|
110
111
|
### `Icon file not found` / 图标工具缺失
|
|
111
112
|
|
|
112
113
|
`--icon`/`app.icon` 的路径相对配置文件目录解析。Windows 上嵌入 PE 图标需要
|
|
113
|
-
`llvm-rc
|
|
114
|
-
|
|
114
|
+
`llvm-rc`(随 LLVM 一起安装);`doctor` 会报告解析到的工具,只有在确实请求了
|
|
115
|
+
图标时缺失才是致命错误。
|
|
115
116
|
|
|
116
117
|
## 怎么看堆栈
|
|
117
118
|
|
package/doc/gui/build.md
CHANGED
|
@@ -19,10 +19,19 @@
|
|
|
19
19
|
- `src/extensions/gui/index.ts` exposes the archive through `nativeObjects()`
|
|
20
20
|
(via `findRuntimeLibrary`, so `.a`/`.lib` both work) and the OS frameworks
|
|
21
21
|
through `linkerFlags()`.
|
|
22
|
+
- `scripts/build-gui.ts` compiles with the *same* clang the driver resolves
|
|
23
|
+
(`src/driver/toolchain-provider.ts`); on Windows that is the MSVC-targeting
|
|
24
|
+
LLVM bundled with Visual Studio, and its sibling `clang++`/`llvm-ar` are used
|
|
25
|
+
for CMake, the engine and the archive merge. There are no `gcc`/`g++`
|
|
26
|
+
fallbacks, and Windows always uses `llvm-ar`, so the archive cannot mix object
|
|
27
|
+
formats or C++ runtimes. The Visual Studio toolchain is found by absolute
|
|
28
|
+
path, so no developer prompt is required. On Windows SDL_GPU selects the
|
|
29
|
+
Vulkan backend; no DXIL/`dxc` toolchain is needed.
|
|
22
30
|
- CI builds `gui.a` before assembling the release archive so it ships inside
|
|
23
31
|
`runtime/lib/<slug>/` (the release tarball copies the whole `runtime/` tree).
|
|
24
32
|
The archive is built and the example is run on Linux (under Xvfb, with the
|
|
25
|
-
lavapipe software Vulkan driver) and macOS; Windows is provisional
|
|
33
|
+
lavapipe software Vulkan driver) and macOS; Windows is provisional because the
|
|
34
|
+
hosted runners have no GPU/Vulkan driver.
|
|
26
35
|
- The existing cache fingerprint already hashes `nativeObjects()` contents, so
|
|
27
36
|
rebuilding `gui.a` invalidates cached binaries automatically.
|
|
28
37
|
- CMake build trees live *next to* their sources (`vendor/sdl-build`,
|
|
@@ -60,9 +69,9 @@ working directory, so run it from the repository root:
|
|
|
60
69
|
Set `XT_GUI_AUTOCLOSE_MS=<n>` to close all windows after `n` milliseconds,
|
|
61
70
|
which the e2e test (`tests/e2e/gui-*.test.ts`) uses to run headlessly.
|
|
62
71
|
|
|
63
|
-
Those suites are skipped on Windows by default (the archive is built
|
|
64
|
-
|
|
65
|
-
`xbintsc_GUI_TESTS=1`:
|
|
72
|
+
Those suites are skipped on Windows by default (the archive is built and runs
|
|
73
|
+
locally through Vulkan, but CI runners have no GPU driver to run it). With a
|
|
74
|
+
`gui.lib` and a working GPU, opt in with `xbintsc_GUI_TESTS=1`:
|
|
66
75
|
|
|
67
76
|
```bat
|
|
68
77
|
set xbintsc_GUI_TESTS=1
|
package/doc/gui/known-issues.md
CHANGED
|
@@ -57,14 +57,17 @@
|
|
|
57
57
|
collide: `LNK2038: mismatch detected for 'RuntimeLibrary'` plus a wall of
|
|
58
58
|
`LNK2005: already defined`, surfaced as `clang: linker command failed with exit
|
|
59
59
|
code 1169`. `src/extensions/gui/index.ts` now lists only the OS libraries
|
|
60
|
-
(`user32`, `gdi32`, `d3d12`, …).
|
|
61
|
-
MSVC
|
|
60
|
+
(`user32`, `gdi32`, `d3d12`, …). `scripts/build-gui.ts` resolves the same
|
|
61
|
+
MSVC-targeting clang as the driver (the LLVM bundled with Visual Studio when
|
|
62
|
+
no newer one is on `PATH`), so a developer prompt is not required.
|
|
62
63
|
- Windows: an MSVC-compatible `gui.lib` (COFF objects + `ar -M`/`llvm-ar`) is
|
|
63
64
|
produced by `scripts/build-gui.ts` but is not validated in CI, so the Windows
|
|
64
65
|
step is provisional (the job stays green) and `package` skips it. Building and
|
|
65
66
|
running `examples/gui/pelican-svg` and `examples/gui/pelican-bike` on a
|
|
66
|
-
developer machine works.
|
|
67
|
-
|
|
67
|
+
developer machine works. SDL_GPU selects the **Vulkan** backend there
|
|
68
|
+
(`win.driver()` reports `"vulkan"`), so the archive needs no DXIL/`dxc`
|
|
69
|
+
toolchain; the hosted Windows runners have no GPU/Vulkan driver, which is why
|
|
70
|
+
the CI run stays provisional.
|
|
68
71
|
- **Media on Windows:** the media decoders (FFmpeg) are only built and merged
|
|
69
72
|
into the POSIX `gui.a`; the Windows `gui.lib` is produced without them, so
|
|
70
73
|
`<video>`/`<audio>` are inert there (failures fire `error`). Enabling it needs
|
|
@@ -75,4 +78,5 @@
|
|
|
75
78
|
and embedded, so the non-Metal path no longer skips geometry. DXIL remains
|
|
76
79
|
unusable on **SDL 3.2.10**: its D3D12 backend rejects any graphics pipeline
|
|
77
80
|
whose shaders declare a uniform buffer, and the engine passes the viewport that
|
|
78
|
-
way.
|
|
81
|
+
way. This does not affect Windows in practice because SDL_GPU selects Vulkan
|
|
82
|
+
there; re-check after an SDL upgrade if the D3D12 path is ever forced.
|
package/doc/gui/rendering.md
CHANGED
|
@@ -43,7 +43,9 @@ its own GPU scissor rectangle (scaled to device pixels), so painter order and
|
|
|
43
43
|
Note that SDL 3.2.10's Direct3D 12 backend cannot create a graphics pipeline
|
|
44
44
|
whose shaders declare a uniform buffer (it fails with `E_INVALIDARG`); the
|
|
45
45
|
engine passes the viewport that way, so the DXIL path is built but not usable
|
|
46
|
-
until that is resolved upstream.
|
|
46
|
+
until that is resolved upstream. Windows does not hit this: SDL_GPU selects the
|
|
47
|
+
Vulkan backend there (confirmed by `win.driver()`), which consumes the SPIR-V
|
|
48
|
+
blobs.
|
|
47
49
|
- A **rounded-rectangle distance field** in the shape fragment shader gives
|
|
48
50
|
antialiased fills; the vertex carries `position`, `local`, `half extents`,
|
|
49
51
|
`radius` and colour, and a viewport-size push constant does the projection.
|
package/doc/gui.md
CHANGED
|
@@ -179,9 +179,10 @@ engine were Rust.
|
|
|
179
179
|
`runtime/`).
|
|
180
180
|
- `vendor/` (SDL3/FreeType/HarfBuzz, the slow part) is cached per OS/arch,
|
|
181
181
|
keyed by `scripts/build-gui.ts`.
|
|
182
|
-
- Windows (build + run) stays provisional
|
|
183
|
-
`gui.lib` and
|
|
184
|
-
|
|
182
|
+
- Windows (build + run) stays provisional in CI: the MSVC-compatible
|
|
183
|
+
`gui.lib` builds and runs locally through SDL_GPU's Vulkan backend, but the
|
|
184
|
+
hosted runners have no GPU/Vulkan driver. A failure is logged without
|
|
185
|
+
annotating the run (see [Open questions](./gui/known-issues.md#open-questions)).
|
|
185
186
|
8. **M8 — interactive DOM** ✅
|
|
186
187
|
- Element/document handles with stable identity, read/write properties via
|
|
187
188
|
runtime accessors, traversal/attributes/queries, mutation with lazy
|
package/doc/icon.md
CHANGED
|
@@ -160,7 +160,8 @@ does).
|
|
|
160
160
|
|
|
161
161
|
- `src/cli/main.ts`: `--icon`, `--bundle`, `--app-name`, `--app-id`, `--config`,
|
|
162
162
|
`--no-config`; merged with the config (`mergeAppConfig`).
|
|
163
|
-
- `src/driver/
|
|
163
|
+
- `src/driver/options.ts`: `BuildOptions.icon` and `BuildOptions.app` (assembled
|
|
164
|
+
into the cache key by `src/driver/build-key.ts`).
|
|
164
165
|
- The icon **content hash** and the packaging options are part of the
|
|
165
166
|
executable `cacheKey`, so changing the icon rebuilds.
|
|
166
167
|
- The icon object and (on win32) the resource object are appended to the link
|
|
@@ -175,8 +176,8 @@ does).
|
|
|
175
176
|
1. A PNG input is wrapped in a minimal ICO container (`ICONDIR` +
|
|
176
177
|
`ICONDIRENTRY` pointing at the PNG payload); Vista+ accepts PNG-in-ICO.
|
|
177
178
|
2. A `.rc` (`1 ICON "icon-<hash>.ico"`) is written next to it in the cache.
|
|
178
|
-
3. `llvm-rc /fo app.res app.rc` (
|
|
179
|
-
`
|
|
179
|
+
3. `llvm-rc /fo app.res app.rc` (next to the resolved clang, or on `PATH`).
|
|
180
|
+
`llvm-rc` is probed with `/?` — it has no `--version`. Override it with
|
|
180
181
|
`xbintsc_RC`.
|
|
181
182
|
4. If no resource compiler exists, the build continues with the runtime icon only
|
|
182
183
|
(a cosmetic feature never hard-fails a build).
|
|
@@ -234,7 +235,7 @@ ELF has no icon convention. The only in-binary use is the runtime window icon
|
|
|
234
235
|
|
|
235
236
|
- `tests/driver/config.test.ts` — parse/validate, discovery, path resolution.
|
|
236
237
|
- `tests/driver/icon.test.ts` — format sniffing, generated C, ICO conversion,
|
|
237
|
-
icon object caching, `llvm-rc
|
|
238
|
+
icon object caching, `llvm-rc` command lines, mac bundle layout and
|
|
238
239
|
fallbacks, and `build()` integration (icon objects linked, missing icon ⇒
|
|
239
240
|
`DiagnosticCode.IOError`).
|
|
240
241
|
- `tests/e2e/icon.test.ts` — compiles a real GUI program with `app.icon`,
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# Async, promises and generators
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/async.md)
|
|
4
|
+
|
|
5
|
+
Location: `runtime/xt_async.c`, `runtime/xt_coroutine.c`, `runtime/xt_promise.c`,
|
|
6
|
+
`runtime/xt_generator.c`, `runtime/xt_loop.c`, `runtime/xt_performance.c`.
|
|
7
|
+
|
|
8
|
+
## async / await
|
|
9
|
+
|
|
10
|
+
- `async` closures are marked with `xt_function_set_async`; calling one runs the body on a stackful coroutine (`xt_coroutine.c`, `xt_async.c`) and immediately returns a promise.
|
|
11
|
+
- The body runs synchronously until the first `await` of a pending promise, then suspends; settlement queues a microtask that resumes the coroutine.
|
|
12
|
+
- An exception that escapes the body rejects that promise instead of throwing synchronously.
|
|
13
|
+
- `await` on a non-promise or settled promise keeps the synchronous fast path and raises on rejection.
|
|
14
|
+
- Each `async` call owns a private stack and swaps its `try` frame stack and GC stack region, so `await` survives `try`/`finally`, loops and closures. A promise settled from a timer, a socket callback or another coroutine resumes the suspended body on the microtask queue.
|
|
15
|
+
|
|
16
|
+
## async generators
|
|
17
|
+
|
|
18
|
+
- `async function*` closures are marked with `xt_function_set_async_generator`; each `.next()` / `.throw()` / `.return()` enqueues a request and returns a promise.
|
|
19
|
+
- The body runs on the generator coroutine and may suspend at either `yield` or `await`; `xt_generator_await` parks it on the awaited promise and leaves the current request pending until the next yield or completion.
|
|
20
|
+
- `for await...of` lowers to `xt_async_iter_open` / `xt_async_iter_next` + `xt_await`, so it consumes both async iterables and the synchronous iteration protocol. `Symbol.asyncIterator` is supported.
|
|
21
|
+
|
|
22
|
+
## Generators
|
|
23
|
+
|
|
24
|
+
- `function*` / `yield` / `yield*`, with `.next()` / `.throw()` / `.return()`, is implemented on the same stackful-coroutine runtime.
|
|
25
|
+
- `for...of`, spread and delegation are supported.
|
|
26
|
+
|
|
27
|
+
## Promise
|
|
28
|
+
|
|
29
|
+
- Microtask queue (`xt_microtasks`); `xt_promise_ctor/resolve/reject/static` (including `withResolvers`), instance `then` / `catch` / `finally`.
|
|
30
|
+
- `xt_drain_microtasks` empties the queue at program exit, and the event loop drains it between callbacks.
|
|
31
|
+
- `xt_await` queues a microtask for a non-promise or settled value, and suspends the running async coroutine on a pending promise until it settles.
|
|
32
|
+
|
|
33
|
+
## Timers and the event loop
|
|
34
|
+
|
|
35
|
+
- `setTimeout` / `clearTimeout` / `setInterval` / `clearInterval` / `setImmediate` / `clearImmediate` / `queueMicrotask` and `performance.now` (monotonic fractional milliseconds).
|
|
36
|
+
- Timers use numeric ids; `Timeout` / `Immediate` objects are not implemented.
|
|
37
|
+
- A promise settled from a timer can be awaited: the async body suspends on the pending promise and resumes when the timer fires. Sockets and servers (`net`, `http`, `dgram`) deliver their callbacks on the same loop.
|
|
38
|
+
- `fetch` is blocking and `fs/promises` performs its I/O synchronously before settling — see [Runtime deviations](../unimplemented/deviations.md). Async generator cleanup limits are listed on the same page.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Name binding and scopes (Binder)
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/binder.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/binder/binder.ts`
|
|
6
|
+
|
|
7
|
+
- Scope kinds: module, function, block, `for`, `catch`
|
|
8
|
+
- Symbol kinds: `var` / `let` / `const` / `function` / `parameter` / `class` / `interface` / `type` / `enum` / `import` / `namespace`
|
|
9
|
+
- `var` and function declarations hoist to the function scope; `let` / `const` stay block-scoped
|
|
10
|
+
- Identifier → declaration resolution; unresolved identifier collection (`CannotFindName`)
|
|
11
|
+
- Closure capture analysis: outer variables referenced by an inner function are marked `captured` / `boxed`, and capture indices are threaded through intermediate closures
|
|
12
|
+
- Parameters are registered as local symbols; the self-name of a named function expression is registered as `const`
|
|
13
|
+
- Type-only declarations (interface / type alias) do not participate in value capture
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# CLI and programmatic API
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/cli.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/cli/main.ts`, `src/index.ts`, `bin/xbintsc.js`
|
|
6
|
+
|
|
7
|
+
## CLI commands
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
xbintsc build <file.ts> [options] compile to a native binary
|
|
11
|
+
xbintsc run <file.ts> [-- args] compile and run
|
|
12
|
+
xbintsc emit <file.ts> print LLVM IR
|
|
13
|
+
xbintsc version print the version
|
|
14
|
+
xbintsc help help
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## CLI options
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
-o, --output <path> Output path
|
|
21
|
+
--out <dir> Output directory (default: build/)
|
|
22
|
+
--emit <kind> exe | obj | ir (default: exe)
|
|
23
|
+
-O0..-O3 Optimization level (default: -O2)
|
|
24
|
+
--ext <names> Comma separated extensions (e.g. node)
|
|
25
|
+
--ext-native <m> Register a C++/Rust extension from a JSON manifest
|
|
26
|
+
--config <path> Use a project config (default: xbintsc.config.json)
|
|
27
|
+
--no-config Do not read any project config
|
|
28
|
+
--icon <path> Embed an application icon (PNG/ICO/ICNS)
|
|
29
|
+
--bundle macOS: also produce a .app bundle
|
|
30
|
+
--app-name <name> Bundle / display name
|
|
31
|
+
--app-id <id> macOS bundle identifier (e.g. com.example.demo)
|
|
32
|
+
--force Ignore the incremental cache
|
|
33
|
+
--verbose Print progress information
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Programmatic API
|
|
37
|
+
|
|
38
|
+
```ts
|
|
39
|
+
import { build, compileString } from "xbintsc";
|
|
40
|
+
|
|
41
|
+
const { ir } = compileString("console.log(1 + 1);");
|
|
42
|
+
const result = build("program.ts", { emit: "exe", outDir: "build" });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The option and result types (`BuildOptions`, `BuildResult`, `EmitKind`,
|
|
46
|
+
`PhaseTiming`) live in `src/driver/options.ts` and are re-exported from
|
|
47
|
+
`src/driver/compiler.ts` / `xbintsc`.
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# LLVM IR code generation (Codegen)
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/codegen.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/codegen/llvm.ts`
|
|
6
|
+
|
|
7
|
+
- Emits LLVM IR text (`.ll`); no custom register allocation (relies on `alloca` + mem2reg).
|
|
8
|
+
- Statement / block boundary values live in `alloca`; conditionals and short-circuits materialize into temporary slots instead of `phi`.
|
|
9
|
+
- Property reads are inline-cached per source site: each access owns a zeroed `[2 x i64]` global (`@ic.N`) passed to `xt_get_ic`. Ordinary objects carry an interned hidden-class shape (`xt_shape`, a `(parent, key)` transition tree) and the cache stores `(shape, property index)`, so a hit is a shape-pointer compare plus one key check instead of a linear property scan. Inserts/deletes and integer-key reordering rebuild or transition the shape, which invalidates stale caches; arrays, functions and containers fall back to `xt_get`.
|
|
10
|
+
- Numeric operators keep the inline two-double fast path; operands that are numeric literals skip their tag check. Conditions whose expression is a comparison, `in`, `instanceof` or `!` are already boolean tags, so codegen emits `icmp eq i64 value, XT_TRUE` instead of calling `xt_truthy` (this removes the call from the hot loop condition).
|
|
11
|
+
- Control flow: `if` / `while` / `do` / `for` / `for...of` / `for...in`, `switch`, `try/catch/finally`, `break` / `continue` / `return`.
|
|
12
|
+
- `for...of` and spread iterate arrays, strings, typed arrays, `Map`, `Set`, generators and any object exposing `[Symbol.iterator]()` through `xt_iter_open` → `xt_iter_has` / `xt_iter_value` (`Map` yields `[key, value]` pairs); a non-iterable throws `TypeError`. Arrays also expose a stable `Array.prototype[Symbol.iterator]`; calling it returns an iterator object with `next()` that is itself iterable.
|
|
13
|
+
- `switch` tests each `case` with strict equality, executes on a hit, and falls through until `break`.
|
|
14
|
+
- `try/catch/finally` is implemented with a runtime `_setjmp` frame: `xt_try_enter` pushes, `_setjmp` catches, `xt_throw` long-jumps. The IR passes the caller's frame address (`@llvm.frameaddress(0)`) as the second `_setjmp` argument, matching clang's MSVC lowering: the Windows UCRT `_setjmp` stores that frame in `_JUMP_BUFFER.Frame` and `longjmp` feeds it to `RtlUnwind`, so omitting it made `longjmp` unwind to a bogus target (`STATUS_BAD_FUNCTION_TABLE`). `_setjmp` is used rather than the exported `setjmp` symbol, whose Windows ABI is an incompatible two-argument routine. Functions containing `try` force local variables to stay in memory (inline-asm escape points) so values survive a long jump.
|
|
15
|
+
- `for...in` reuses `xt_object_keys` to enumerate keys (arrays / strings yield string indices).
|
|
16
|
+
- Expressions:
|
|
17
|
+
- Identifiers, numbers, BigInt (arbitrary precision), strings, templates, booleans, `null`, `undefined`, `arguments`
|
|
18
|
+
- Arithmetic / comparison / logical / short-circuit / conditional / bitwise / unary (including `typeof` `void`) / prefix-postfix increment-decrement / compound assignment / logical assignment
|
|
19
|
+
- Array literals (including spread `[...]`), object literals (including shorthand / methods / object spread `{...obj}`)
|
|
20
|
+
- Typed arrays, `ArrayBuffer`, `DataView`, `TextEncoder` / `TextDecoder`: see [Typed arrays and binary data](./typed-arrays.md) and [Strings and text](./strings.md)
|
|
21
|
+
- Property access (with a `length` special case, `Math` constants), element access, calls
|
|
22
|
+
- First-class built-in constructors (`const A = Array`, `const M = Map`, `const E = TypeError`, typed arrays): a bare reference lowers to `xt_builtin_constructor`, giving a cached function with `name` / `length`, a `prototype`, and its statics (`A.isArray`, `A.from`, `M.prototype`, ...). Calling or `new`-ing an alias dispatches to the same runtime constructor, and `x instanceof A` walks the shared prototype chain.
|
|
23
|
+
- Optional chaining `?.` / `?.[]` / `?.()`: nullish check short-circuits to `undefined`
|
|
24
|
+
- `delete`, `in`, `instanceof`
|
|
25
|
+
- `this` (saved to the function's `%saved.this`; arrow functions read from an environment slot), `super` (`super.x` / `super(...)`), `new`, `await`
|
|
26
|
+
- Closures (arrow functions / function expressions) and capture environment construction
|
|
27
|
+
- Classes: constructor closure + prototype object, stored in an LLVM global (`@class.<id>`); instance fields are initialized before the constructor body; `static` members live in the constructor's property bag; `extends` sets up the prototype chain; `super(...)` is invoked through a hidden `__ctor` on the prototype.
|
|
28
|
+
- `async` / `async function*`: closures are marked with `xt_function_set_async` / `xt_function_set_async_generator` and run on stackful coroutines — see [Async, promises and generators](./async.md).
|
|
29
|
+
- Standard library calls dispatch through `xt_call_method` / `xt_math_call` / `xt_object_*` and the per-constructor `xt_*` entry points; the surface is listed in [Standard library](./stdlib.md).
|
|
30
|
+
- Global string pool (`@.str.N` private constants, UTF-8 escaped).
|
|
31
|
+
- Builtin calls: `console.log` / `info` / `warn` / `error`, `Math.*`, `Object.*`, array / string methods, global functions, extension builtins (uniform `(argc, argv)` ABI).
|
|
32
|
+
- `main` entry point (returns 0, calls the module function, then drains microtasks and runs the event loop until no timers or descriptors remain).
|
|
33
|
+
- Unsupported nodes uniformly report `UnsupportedFeature`; they never crash.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Collections
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/collections.md)
|
|
4
|
+
|
|
5
|
+
Location: `runtime/xt_stdlib2/container.inc` (Map / Set) and
|
|
6
|
+
`runtime/xt_weak.c` (WeakMap / WeakSet / WeakRef).
|
|
7
|
+
|
|
8
|
+
## Map and Set
|
|
9
|
+
|
|
10
|
+
- `new Map()` / `new Map(iterable)` and `new Set()` / `new Set(iterable)`.
|
|
11
|
+
- `Map`: `size`, `get` / `set` / `has` / `delete` / `clear` / `forEach` / `keys` / `values` / `entries`.
|
|
12
|
+
- `Set`: `size`, `add` / `has` / `delete` / `clear` / `forEach` / `values` / `keys` / `entries`.
|
|
13
|
+
- `for...of` and spread iterate them through `[Symbol.iterator]`; a `Map` yields `[key, value]` pairs, and `keys` / `values` / `entries` return arrays in insertion order.
|
|
14
|
+
- `Object.keys` / `values` / `entries` do not see collection internals.
|
|
15
|
+
- `structuredClone` supports `Map` and `Set`, preserving cycles and shared references.
|
|
16
|
+
|
|
17
|
+
## WeakMap, WeakSet and WeakRef
|
|
18
|
+
|
|
19
|
+
- `WeakMap`: `get` / `set` / `has` / `delete`; `WeakSet`: `add` / `has` / `delete`; `WeakRef`: `deref()`.
|
|
20
|
+
- Keys (and `WeakRef` targets) do not keep their referents alive: `WeakMap` / `WeakSet` keys are **ephemerons** (a value is retained only while its key is reachable) and a `WeakRef` target is cleared when it becomes unreachable.
|
|
21
|
+
- The stack scan is conservative, so a stale stack word can delay clearing a weak target. The full GC description is in [Runtime deviations](../unimplemented/deviations.md) and [Unimplemented: toolchain](../unimplemented/toolchain.md).
|
|
22
|
+
|
|
23
|
+
## Iteration
|
|
24
|
+
|
|
25
|
+
- Any object exposing `[Symbol.iterator]()` is iterable in `for...of` and spread. `Array.prototype[Symbol.iterator]` is stable, and calling it returns an iterator object with `next()` that is itself iterable.
|
|
26
|
+
- Iteration is described further in [Codegen](./codegen.md#llvm-ir-code-generation-codegen) and [Symbol](./stdlib.md#symbol).
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Driver, incremental compilation and toolchain
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/driver.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/driver/compiler.ts` (orchestration), `src/driver/frontend.ts`,
|
|
6
|
+
`src/driver/build-key.ts`, `src/driver/runtime-objects.ts`,
|
|
7
|
+
`src/driver/app-artifacts.ts`, `src/driver/cache.ts`, `src/driver/toolchain.ts`,
|
|
8
|
+
`src/driver/paths.ts`, `src/driver/version.ts`.
|
|
9
|
+
|
|
10
|
+
- Compilation pipeline: read source → module bundling (`src/driver/modules.ts`, when the entry contains `import`/`export`) → parse → bind/check → IR → object file → link.
|
|
11
|
+
- Incremental cache: keyed on "compiler version + source hash + emit kind + optimization level + LTO/PGO mode + platform + extension fingerprint (names, linker flags, native object contents)"; if the artifacts exist and are fresh, the build is skipped. `--pgo-use` always rebuilds because the profile data can change without the source. The key is assembled in `src/driver/build-key.ts`.
|
|
12
|
+
- C runtime and extension sources are cached as object files by content hash and compiled only once (the cache key includes the LTO/PGO flags). `RUNTIME_SOURCES` in `src/driver/runtime-objects.ts` lists the core translation units.
|
|
13
|
+
- Toolchain wrapper: locates `clang` (overridable with `xbintsc_CLANG`), compiles IR, compiles C, links.
|
|
14
|
+
- LTO (`--lto` / `"lto": true`): the program and runtime compile to LLVM bitcode (`-flto`) and link with `-fuse-ld=lld`; lld is required.
|
|
15
|
+
- PGO (`--pgo-generate[=dir]` then `--pgo-use[=dir]`, or `"pgo"` / `"pgoDir"`): the generated IR and runtime C are instrumented with `-fprofile-generate=<dir>`; after running the instrumented binary, `--pgo-use` merges `.profraw` files with `llvm-profdata` (preferring the copy next to clang, overridable with `xbintsc_LLVM_PROFDATA`) and rebuilds with `-fprofile-use=<dir>`.
|
|
16
|
+
- Link flags: `-lm` is added automatically on non-Windows; extensions may append extra link flags.
|
|
17
|
+
- Project config (`src/driver/config.ts`, `xbintsc.config.json`): `entry`, `outDir`, `output`, `optimize`, `lto`, `pgo`, `pgoDir`, `extensions`, `extNative`, `force` and `app` (`name`, `icon`, `bundle`, `bundleId`). Discovered by walking up from the entry/cwd, overridable with `--config`, disabled with `--no-config`; every path resolves against the config directory; CLI flags win over config values.
|
|
18
|
+
- Application icon (`src/driver/icon.ts`, `win-icon.ts`, `mac-bundle.ts`, `--icon`/`app.icon`): PNG/ICO/ICNS is embedded as `xt_app_icon_*` symbols, synthesized into a PE resource via `llvm-rc` on Windows, and packaged into `Foo.app` (with `AppIcon.icns` via `sips`/`iconutil`) on macOS. The `gui` extension calls `SDL_SetWindowIcon` from the embedded bytes. `xbintsc_RC` overrides the resource compiler.
|
|
19
|
+
- Compiler version: `COMPILER_VERSION` lives in `src/driver/version.ts` and is part of the cache key. The pre-commit hook bumps it (together with `package.json`) only on `main`/`master`, so feature branches never touch the version files.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Extension mechanism
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/extensions.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/registry.ts`, `src/extensions/node/`
|
|
6
|
+
|
|
7
|
+
- An extension is a plain object: `runtimeSources()` (extra C sources), `linkerFlags()` (extra link flags), `builtins()` (global identifier → runtime symbol, uniform `(argc, argv)` ABI) and `modules()` (import specifier → named exports / namespace).
|
|
8
|
+
- `ExtensionRegistry`: register / unregister / lookup / aggregate builtins, modules, runtime sources and link flags.
|
|
9
|
+
- The built-in core extension `core`: exposes `print` (mapped to `xt_println`), always registered.
|
|
10
|
+
- The Node extension `node`:
|
|
11
|
+
- Modular organisation: `src/extensions/node/fs/` + `runtime/ext_node/fs/read_file.c`
|
|
12
|
+
- Exposes importable modules (`fs`, `fs/promises`, `path`, `os`, `process`, ...) under both bare and `node:`-prefixed specifiers; `import { readFileSync } from "fs"` resolves to `xt_node_read_text_file`, and `path`/`os`/`process` map exports onto the namespace dispatchers.
|
|
13
|
+
- Adding a new module only requires a new directory plus a C implementation; the core compiler never changes.
|
|
14
|
+
- Native C++/Rust extensions (`src/extensions/native.ts`, `--ext-native`):
|
|
15
|
+
- `nativeObjects()` links pre-built objects/static archives that expose `extern "C"` symbols with the `(argc, argv)` ABI; a JSON manifest maps them onto builtins/modules (`linkerFlags` / `linkerFlagsByPlatform` cover C++/Rust runtimes).
|
|
16
|
+
- Authoring helpers live in `runtime/xt_ext.h` (C/C++) and `runtime/xt_ext.rs` (Rust); runnable projects are under `examples/extensions/`.
|
|
17
|
+
- The driver links the artifacts verbatim and the incremental cache fingerprints their contents, so a rebuilt library invalidates the cached binary.
|
|
18
|
+
- CI builds both language examples on Linux, macOS and Windows; on Windows the system clang links with the MSVC ABI (C++ `-lmsvcprt`, Rust `*-pc-windows-msvc` plus the Windows system libraries).
|
|
19
|
+
- Node module coverage is documented in [Node extension](./node.md).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# fetch
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/fetch.md)
|
|
4
|
+
|
|
5
|
+
Location: `runtime/xt_fetch.c`.
|
|
6
|
+
|
|
7
|
+
- Global `fetch(input, init)` is a blocking HTTP/1.1 client whose promise is already settled (the exchange happens synchronously; it is not scheduled on the reactor).
|
|
8
|
+
- It accepts `http://` URLs only — `https://` rejects with a `TypeError` because no TLS backend is linked.
|
|
9
|
+
- Options: `method`, `headers` (plain object or `Headers`), `body` and `redirect` (`follow` / `manual` / `error`); up to 20 redirects are followed, and a 301/302/303 switches POST to GET.
|
|
10
|
+
- The resolved `Response`-shaped object exposes `ok` / `status` / `statusText` / `url` / `headers` plus `text()` / `json()` / `arrayBuffer()` / `bytes()` / `clone()`.
|
|
11
|
+
- `Headers` is case-insensitive with `get` / `has` / `set` / `append` / `delete` / `keys` / `values` / `entries` / `forEach` / `getSetCookie`.
|
|
12
|
+
- Invalid URLs and network failures reject with a `TypeError`.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# Lexer
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/lexer.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/lexer/scanner.ts`, `src/lexer/token.ts`
|
|
6
|
+
|
|
7
|
+
- Full token classification: identifiers, keywords, private identifiers, numbers, strings, templates, regex (scanning), all punctuation and operators.
|
|
8
|
+
- Full keyword table: `abstract any as asserts async await bigint boolean break case catch class const constructor continue debugger declare default delete do else enum export extends false finally for from function get if implements import in infer instanceof interface is keyof let module namespace never new null number object package private protected public readonly return satisfies set static string super switch symbol this throw true try type typeof undefined unique unknown var void while with yield`
|
|
9
|
+
- Numeric literals:
|
|
10
|
+
- Decimal, `0x` hex, `0o` octal, `0b` binary
|
|
11
|
+
- Underscore separators `1_000_000`
|
|
12
|
+
- Fractions, exponents `1.5e3`
|
|
13
|
+
- BigInt literals (`10n`, `0xFFn`) evaluate to arbitrary-precision integers (arithmetic, bitwise, shifts, comparisons, `toString(radix)`, `BigInt()` / `BigInt.asIntN` / `BigInt.asUintN`)
|
|
14
|
+
- BigInt literal values are parsed exactly into `bigint` (never routed through `Number`), so the token / AST value of a literal beyond 2^53 keeps full precision
|
|
15
|
+
- String literals:
|
|
16
|
+
- Single / double quotes
|
|
17
|
+
- Escapes: `\n \t \r \b \f \0 \\ \' \"`, `\xHH`, `\uHHHH`, `\u{...}`
|
|
18
|
+
- Template literals (lexer level): no-substitution templates, `TemplateHead`, `TemplateMiddle`, `TemplateTail`, with `${}` and escapes.
|
|
19
|
+
- Regex literal scanning (`/pattern/flags`), distinguishing division `/`.
|
|
20
|
+
- Private identifiers `#name`.
|
|
21
|
+
- Comments: line `//` and block `/* */` (with unterminated diagnostics).
|
|
22
|
+
- Newline and whitespace tracking (for ASI), BOM / CRLF normalization (`SourceFile`).
|
|
23
|
+
- Lexical diagnostics: unterminated string / template / comment, illegal character, illegal number, illegal escape.
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Module system
|
|
2
|
+
|
|
3
|
+
> Part of [Implemented syntax and features](../implemented.md) · [简体中文](../zh-CN/implemented/modules.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/parser/parser.ts` (syntax), `src/driver/modules.ts` (bundling),
|
|
6
|
+
`src/driver/frontend.ts` (`parseEntry`).
|
|
7
|
+
|
|
8
|
+
## Syntax
|
|
9
|
+
|
|
10
|
+
- `import default, { named } from "..."`, `import * as ns from "..."` (namespace imports of relative modules are lowered to a synthetic object literal; extension modules such as `path` are also supported), `import "./side-effect"`, `import type`
|
|
11
|
+
- `export default`, `export { a as b }`, `export *`, `export =`
|
|
12
|
+
- Import attributes (`with` / `assert`)
|
|
13
|
+
|
|
14
|
+
## Runtime semantics
|
|
15
|
+
|
|
16
|
+
- The **runtime semantics** of `import` / `export` are handled at the driver layer by `src/driver/modules.ts`: it recursively resolves relative dependencies *and* bare `node_modules` packages (following `exports` / `module` / `main` and package subpaths), renames top-level symbols with a per-module prefix, rewrites references, merges into a single file and rebinds.
|
|
17
|
+
- Packages may be ESM or CommonJS: a CommonJS file under `node_modules` gets a synthetic `module`/`exports` pair, its `require` calls are lowered to the bundled dependency's exports, and its statically-detected exports are exposed to ESM importers. `require()` outside `node_modules` is still rejected with a hint to use `import`. Circular dependencies error out.
|
|
18
|
+
- A `.js`-family specifier resolves to its `.ts` source, and TypeScript suffixes are preferred over JavaScript siblings when the specifier omits the extension; plain `.js` / `.jsx` / `.mjs` / `.cjs` sources are bundled directly.
|
|
19
|
+
- Imported bindings and namespace members are snapshots at module-evaluation time (no live bindings) — see [Unimplemented: module system](../unimplemented/modules.md).
|
|
20
|
+
- Type-only imports and re-exports (`import type { T } from "..."`, `import { type T } from "..."`, `export type { T } from "..."`) are erased. They are **not** module edges: the target is not loaded or bundled, and a type-only cycle between modules is not a circular dependency. Use a side-effect import (`import "./mod"`) when a module must be evaluated without binding a name.
|
|
21
|
+
|
|
22
|
+
## import.meta
|
|
23
|
+
|
|
24
|
+
- `import.meta.url` / `.dirname` / `.filename`, resolved from the running executable's path.
|
|
25
|
+
|
|
26
|
+
## Extension modules
|
|
27
|
+
|
|
28
|
+
- Extension modules (such as `fs`) are importable by bare or `node:`-prefixed specifier and resolve to their runtime entries; see [Extensions](./extensions.md).
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# `assert`
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/assert.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/node/assert/index.ts`, `runtime/ext_node/assert/assert.c`
|
|
6
|
+
|
|
7
|
+
`assert.ok` / `fail` / `equal` / `notEqual` / `strictEqual` / `notStrictEqual` /
|
|
8
|
+
`deepEqual` / `notDeepEqual` / `deepStrictEqual` / `notDeepStrictEqual` /
|
|
9
|
+
`throws` / `doesNotThrow` / `rejects` / `doesNotReject` / `match` /
|
|
10
|
+
`doesNotMatch` / `ifError`.
|
|
11
|
+
|
|
12
|
+
Named imports and the namespace form both dispatch through `xt_assert_static`:
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import assert from "node:assert";
|
|
16
|
+
assert.strictEqual(1 + 1, 2);
|
|
17
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# `buffer`
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/buffer.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/node/buffer/index.ts`, `runtime/ext_node/buffer/buffer.c`
|
|
6
|
+
|
|
7
|
+
xbintsc has no native binary value type, so `Buffer` is represented as a
|
|
8
|
+
**plain object**: each byte is a numeric property `"0".."n-1"`, plus a `length`
|
|
9
|
+
property, sharing the `xt_buffer_proto()` prototype that provides instance
|
|
10
|
+
methods. `xt_node_is_buffer` / `xt_node_buffer_bytes` let other modules access
|
|
11
|
+
bytes across modules.
|
|
12
|
+
|
|
13
|
+
| Static method | Notes |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `Buffer.from(value[, encoding])` | construct from a string (hex / base64 / utf8), array or Buffer |
|
|
16
|
+
| `Buffer.alloc(size[, fill])` | allocate and fill |
|
|
17
|
+
| `Buffer.allocUnsafe(size)` | allocate |
|
|
18
|
+
| `Buffer.isBuffer(value)` | test |
|
|
19
|
+
| `Buffer.byteLength(value[, encoding])` | byte length |
|
|
20
|
+
| `Buffer.concat(list[, totalLength])` | concatenate |
|
|
21
|
+
| `Buffer.compare(a, b)` | compare |
|
|
22
|
+
|
|
23
|
+
Instance methods: `toString([encoding])`, `toJSON()`, `slice(start, end)`, `subarray(...)`, `equals(other)`, `compare(other)`, `copy(target[, targetStart, sourceStart, sourceEnd])`, `write(string[, offset[, length[, encoding]]])`, `fill(value)`, `reverse()`, `indexOf(value)`, `lastIndexOf(value)`, `includes(value)`, `keys()`, `values()`, plus `readUInt8/UInt16LE/UInt16BE/UInt32LE/UInt32BE`, `writeUInt8/UInt16LE/UInt16BE/UInt32LE/UInt32BE`.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
const buf = Buffer.from("hello");
|
|
27
|
+
console.log(buf.toString(), buf.length); // hello 5
|
|
28
|
+
console.log(Buffer.alloc(4, 65).toString()); // AAAA
|
|
29
|
+
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# `child_process`
|
|
2
|
+
|
|
3
|
+
> Part of [Node extension: implemented](../node.md) · [简体中文](../../zh-CN/implemented/node/child-process.md)
|
|
4
|
+
|
|
5
|
+
Location: `src/extensions/node/child_process/index.ts`, `runtime/ext_node/child_process/child_process.c`
|
|
6
|
+
|
|
7
|
+
`spawnSync(command, args[, options])` runs a program to completion and returns
|
|
8
|
+
`{ status, stdout, stderr }`. `options.cwd` sets the working directory and
|
|
9
|
+
`options.stdio: "inherit"` hands the child the parent's stdout/stderr (used by
|
|
10
|
+
`xbintsc run`, so a compiled program's output streams live); otherwise
|
|
11
|
+
stdout/stderr are captured as UTF-8 strings.
|
|
12
|
+
|
|
13
|
+
| Option | Notes |
|
|
14
|
+
| --- | --- |
|
|
15
|
+
| `cwd` | working directory for the child |
|
|
16
|
+
| `stdio: "inherit"` | share the parent's stdout/stderr instead of capturing |
|
|
17
|
+
| `encoding` | accepted and ignored (output is always decoded as UTF-8) |
|
|
18
|
+
|
|
19
|
+
On Windows the child is launched with `CreateProcess` and its stdout/stderr are
|
|
20
|
+
drained through anonymous pipes by reader threads. No temporary files are used,
|
|
21
|
+
so a locked-down `%TEMP%` cannot break `spawnSync`, and output larger than a pipe
|
|
22
|
+
buffer cannot deadlock.
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { spawnSync } from "child_process";
|
|
26
|
+
|
|
27
|
+
const result = spawnSync("clang", ["--version"], { encoding: "utf8" });
|
|
28
|
+
console.log(result.status, result.stdout.split("\n")[0]);
|
|
29
|
+
```
|