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
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
#include <fcntl.h>
|
|
24
24
|
#include <io.h>
|
|
25
25
|
#include <process.h>
|
|
26
|
+
#include <windows.h>
|
|
26
27
|
#else
|
|
27
28
|
#include <poll.h>
|
|
28
29
|
#include <sys/wait.h>
|
|
@@ -69,38 +70,115 @@ static xt_value make_result(double status, const char *out, const char *err) {
|
|
|
69
70
|
|
|
70
71
|
#if defined(_WIN32)
|
|
71
72
|
|
|
72
|
-
static char *read_temp(FILE *file) {
|
|
73
|
-
fflush(file);
|
|
74
|
-
if (_fseeki64(file, 0, SEEK_END) != 0) return NULL;
|
|
75
|
-
long long size = _ftelli64(file);
|
|
76
|
-
if (size < 0) return NULL;
|
|
77
|
-
_fseeki64(file, 0, SEEK_SET);
|
|
78
|
-
char *buffer = (char *)malloc((size_t)size + 1);
|
|
79
|
-
if (!buffer) return NULL;
|
|
80
|
-
size_t read = fread(buffer, 1, (size_t)size, file);
|
|
81
|
-
buffer[read] = 0;
|
|
82
|
-
return buffer;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
73
|
/*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
74
|
+
* `spawnSync` captures stdout/stderr through anonymous pipes. Temporary files
|
|
75
|
+
* are deliberately not used: `tmpfile()` creates its file in the root of the
|
|
76
|
+
* current drive on the UCRT, which fails with "Permission denied" on machines
|
|
77
|
+
* where that directory is not writable, and a restricted temp directory makes
|
|
78
|
+
* every `spawnSync` fail as well. Pipes also avoid the pipe-buffer deadlock the
|
|
79
|
+
* old temp-file design was working around, because one reader thread drains
|
|
80
|
+
* each stream while the child runs.
|
|
91
81
|
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
size_t length
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
82
|
+
typedef struct {
|
|
83
|
+
HANDLE read;
|
|
84
|
+
char *data;
|
|
85
|
+
size_t length;
|
|
86
|
+
size_t capacity;
|
|
87
|
+
} CapturePipe;
|
|
88
|
+
|
|
89
|
+
static void capture_append(CapturePipe *pipe, const char *chunk, size_t count) {
|
|
90
|
+
if (pipe->length + count + 1 > pipe->capacity) {
|
|
91
|
+
size_t next = pipe->capacity ? pipe->capacity * 2 : 4096;
|
|
92
|
+
while (next < pipe->length + count + 1) next *= 2;
|
|
93
|
+
char *grown = (char *)realloc(pipe->data, next);
|
|
94
|
+
if (!grown) return;
|
|
95
|
+
pipe->data = grown;
|
|
96
|
+
pipe->capacity = next;
|
|
97
|
+
}
|
|
98
|
+
memcpy(pipe->data + pipe->length, chunk, count);
|
|
99
|
+
pipe->length += count;
|
|
100
|
+
pipe->data[pipe->length] = 0;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
static DWORD WINAPI capture_thread(LPVOID parameter) {
|
|
104
|
+
CapturePipe *pipe = (CapturePipe *)parameter;
|
|
105
|
+
char chunk[4096];
|
|
106
|
+
DWORD got = 0;
|
|
107
|
+
while (ReadFile(pipe->read, chunk, sizeof(chunk), &got, NULL) && got > 0) {
|
|
108
|
+
capture_append(pipe, chunk, (size_t)got);
|
|
109
|
+
}
|
|
110
|
+
return 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static int create_capture_pipe(CapturePipe *pipe, HANDLE *write_end) {
|
|
114
|
+
SECURITY_ATTRIBUTES attributes;
|
|
115
|
+
HANDLE read_handle = NULL;
|
|
116
|
+
HANDLE write_handle = NULL;
|
|
117
|
+
attributes.nLength = sizeof(attributes);
|
|
118
|
+
attributes.lpSecurityDescriptor = NULL;
|
|
119
|
+
attributes.bInheritHandle = TRUE;
|
|
120
|
+
if (!CreatePipe(&read_handle, &write_handle, &attributes, 0)) return 0;
|
|
121
|
+
/* The child inherits the write end only. */
|
|
122
|
+
SetHandleInformation(read_handle, HANDLE_FLAG_INHERIT, 0);
|
|
123
|
+
pipe->read = read_handle;
|
|
124
|
+
pipe->data = NULL;
|
|
125
|
+
pipe->length = 0;
|
|
126
|
+
pipe->capacity = 0;
|
|
127
|
+
*write_end = write_handle;
|
|
128
|
+
return 1;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
static void close_capture_pipe(CapturePipe *pipe) {
|
|
132
|
+
if (pipe->read != NULL) CloseHandle(pipe->read);
|
|
133
|
+
free(pipe->data);
|
|
134
|
+
pipe->read = NULL;
|
|
135
|
+
pipe->data = NULL;
|
|
136
|
+
pipe->length = 0;
|
|
137
|
+
pipe->capacity = 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/* Quote one argument following the CommandLineToArgvW/MSVC rules. */
|
|
141
|
+
static char *append_quoted_argument(char *out, const char *argument) {
|
|
142
|
+
if (*argument != 0 && strpbrk(argument, " \t\n\v\"") == NULL) {
|
|
143
|
+
size_t length = strlen(argument);
|
|
144
|
+
memcpy(out, argument, length);
|
|
145
|
+
return out + length;
|
|
146
|
+
}
|
|
147
|
+
*out++ = '"';
|
|
148
|
+
const char *cursor = argument;
|
|
149
|
+
for (;;) {
|
|
150
|
+
size_t backslashes = 0;
|
|
151
|
+
while (*cursor == '\\') {
|
|
152
|
+
cursor++;
|
|
153
|
+
backslashes++;
|
|
154
|
+
}
|
|
155
|
+
if (*cursor == 0) {
|
|
156
|
+
for (size_t i = 0; i < backslashes * 2; i++) *out++ = '\\';
|
|
157
|
+
*out++ = '"';
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
if (*cursor == '"') {
|
|
161
|
+
for (size_t i = 0; i < backslashes * 2 + 1; i++) *out++ = '\\';
|
|
162
|
+
} else {
|
|
163
|
+
for (size_t i = 0; i < backslashes; i++) *out++ = '\\';
|
|
164
|
+
}
|
|
165
|
+
*out++ = *cursor++;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Build the child command line; every argv element is quoted as needed. */
|
|
170
|
+
static char *build_command_line(char **child_argv, int count) {
|
|
171
|
+
size_t capacity = 1;
|
|
172
|
+
for (int i = 0; i < count; i++) capacity += strlen(child_argv[i]) * 2 + 4;
|
|
173
|
+
char *line = (char *)malloc(capacity);
|
|
174
|
+
if (!line) return NULL;
|
|
175
|
+
char *cursor = line;
|
|
176
|
+
for (int i = 0; i < count; i++) {
|
|
177
|
+
if (i > 0) *cursor++ = ' ';
|
|
178
|
+
cursor = append_quoted_argument(cursor, child_argv[i]);
|
|
179
|
+
}
|
|
180
|
+
*cursor = 0;
|
|
181
|
+
return line;
|
|
104
182
|
}
|
|
105
183
|
|
|
106
184
|
xt_value xt_child_process_spawn_sync(int32_t argc, xt_value *argv) {
|
|
@@ -112,60 +190,82 @@ xt_value xt_child_process_spawn_sync(int32_t argc, xt_value *argv) {
|
|
|
112
190
|
int count = 0;
|
|
113
191
|
char **child_argv = (char **)build_argv(command, args, &count);
|
|
114
192
|
if (!child_argv) return make_result(-1, "", "out of memory");
|
|
115
|
-
char *
|
|
193
|
+
char *command_line = build_command_line(child_argv, count);
|
|
194
|
+
if (!command_line) {
|
|
195
|
+
free(child_argv);
|
|
196
|
+
return make_result(-1, "", "out of memory");
|
|
197
|
+
}
|
|
116
198
|
|
|
117
|
-
|
|
118
|
-
|
|
199
|
+
STARTUPINFOA startup;
|
|
200
|
+
PROCESS_INFORMATION process;
|
|
201
|
+
ZeroMemory(&startup, sizeof(startup));
|
|
202
|
+
ZeroMemory(&process, sizeof(process));
|
|
203
|
+
startup.cb = sizeof(startup);
|
|
119
204
|
|
|
120
205
|
if (option_stdio_inherit(argc > 2 ? argv[2] : XT_UNDEFINED)) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
free(quoted_command);
|
|
206
|
+
BOOL created = CreateProcessA(
|
|
207
|
+
NULL, command_line, NULL, NULL, TRUE, 0, NULL, cwd, &startup, &process);
|
|
208
|
+
free(command_line);
|
|
125
209
|
free(child_argv);
|
|
126
|
-
return make_result(
|
|
210
|
+
if (!created) return make_result(-1, "", "failed to start process");
|
|
211
|
+
WaitForSingleObject(process.hProcess, INFINITE);
|
|
212
|
+
DWORD exit_code = 0;
|
|
213
|
+
GetExitCodeProcess(process.hProcess, &exit_code);
|
|
214
|
+
CloseHandle(process.hThread);
|
|
215
|
+
CloseHandle(process.hProcess);
|
|
216
|
+
return make_result((double)exit_code, "", "");
|
|
127
217
|
}
|
|
128
218
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
219
|
+
CapturePipe out_pipe;
|
|
220
|
+
CapturePipe err_pipe;
|
|
221
|
+
ZeroMemory(&out_pipe, sizeof(out_pipe));
|
|
222
|
+
ZeroMemory(&err_pipe, sizeof(err_pipe));
|
|
223
|
+
HANDLE out_write = NULL;
|
|
224
|
+
HANDLE err_write = NULL;
|
|
225
|
+
if (!create_capture_pipe(&out_pipe, &out_write) || !create_capture_pipe(&err_pipe, &err_write)) {
|
|
226
|
+
if (out_write != NULL) CloseHandle(out_write);
|
|
227
|
+
if (err_write != NULL) CloseHandle(err_write);
|
|
228
|
+
close_capture_pipe(&out_pipe);
|
|
229
|
+
close_capture_pipe(&err_pipe);
|
|
230
|
+
free(command_line);
|
|
133
231
|
free(child_argv);
|
|
134
|
-
|
|
135
|
-
if (err_file) fclose(err_file);
|
|
136
|
-
return make_result(-1, "", "could not create temporary files");
|
|
232
|
+
return make_result(-1, "", "could not create pipes");
|
|
137
233
|
}
|
|
234
|
+
startup.dwFlags = STARTF_USESTDHANDLES;
|
|
235
|
+
startup.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
236
|
+
startup.hStdOutput = out_write;
|
|
237
|
+
startup.hStdError = err_write;
|
|
138
238
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
fflush(stdout);
|
|
143
|
-
fflush(stderr);
|
|
144
|
-
int saved_out = _dup(_fileno(stdout));
|
|
145
|
-
int saved_err = _dup(_fileno(stderr));
|
|
146
|
-
_dup2(_fileno(out_file), _fileno(stdout));
|
|
147
|
-
_dup2(_fileno(err_file), _fileno(stderr));
|
|
148
|
-
|
|
149
|
-
if (cwd) _chdir(cwd);
|
|
150
|
-
intptr_t rc = _spawnvp(_P_WAIT, command, (const char *const *)child_argv);
|
|
151
|
-
if (had_cwd) _chdir(previous);
|
|
152
|
-
fflush(stdout);
|
|
153
|
-
fflush(stderr);
|
|
154
|
-
_dup2(saved_out, _fileno(stdout));
|
|
155
|
-
_dup2(saved_err, _fileno(stderr));
|
|
156
|
-
_close(saved_out);
|
|
157
|
-
_close(saved_err);
|
|
158
|
-
|
|
159
|
-
char *out = read_temp(out_file);
|
|
160
|
-
char *err = read_temp(err_file);
|
|
161
|
-
fclose(out_file);
|
|
162
|
-
fclose(err_file);
|
|
163
|
-
free(quoted_command);
|
|
239
|
+
BOOL created = CreateProcessA(
|
|
240
|
+
NULL, command_line, NULL, NULL, TRUE, 0, NULL, cwd, &startup, &process);
|
|
241
|
+
free(command_line);
|
|
164
242
|
free(child_argv);
|
|
243
|
+
CloseHandle(out_write);
|
|
244
|
+
CloseHandle(err_write);
|
|
245
|
+
if (!created) {
|
|
246
|
+
close_capture_pipe(&out_pipe);
|
|
247
|
+
close_capture_pipe(&err_pipe);
|
|
248
|
+
return make_result(-1, "", "failed to start process");
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
CloseHandle(process.hThread);
|
|
252
|
+
HANDLE threads[2];
|
|
253
|
+
threads[0] = CreateThread(NULL, 0, capture_thread, &out_pipe, 0, NULL);
|
|
254
|
+
threads[1] = CreateThread(NULL, 0, capture_thread, &err_pipe, 0, NULL);
|
|
255
|
+
for (int i = 0; i < 2; i++) {
|
|
256
|
+
if (threads[i] != NULL) WaitForSingleObject(threads[i], INFINITE);
|
|
257
|
+
}
|
|
258
|
+
WaitForSingleObject(process.hProcess, INFINITE);
|
|
259
|
+
DWORD exit_code = 0;
|
|
260
|
+
GetExitCodeProcess(process.hProcess, &exit_code);
|
|
261
|
+
CloseHandle(process.hProcess);
|
|
262
|
+
for (int i = 0; i < 2; i++) {
|
|
263
|
+
if (threads[i] != NULL) CloseHandle(threads[i]);
|
|
264
|
+
}
|
|
165
265
|
|
|
166
|
-
xt_value result = make_result(
|
|
167
|
-
|
|
168
|
-
|
|
266
|
+
xt_value result = make_result((double)exit_code, out_pipe.data, err_pipe.data);
|
|
267
|
+
close_capture_pipe(&out_pipe);
|
|
268
|
+
close_capture_pipe(&err_pipe);
|
|
169
269
|
return result;
|
|
170
270
|
}
|
|
171
271
|
|
package/runtime/rt.h
CHANGED
|
@@ -132,6 +132,8 @@ xt_value xt_function_get_prototype(xt_value fn);
|
|
|
132
132
|
xt_value xt_function_set_generator(xt_value fn);
|
|
133
133
|
/** Mark a closure as an `async` function so calling it starts a coroutine. */
|
|
134
134
|
xt_value xt_function_set_async(xt_value fn);
|
|
135
|
+
/** Mark a closure as an `async function*` (generator + async iterator). */
|
|
136
|
+
xt_value xt_function_set_async_generator(xt_value fn);
|
|
135
137
|
|
|
136
138
|
/* -- conversions ---------------------------------------------------------- */
|
|
137
139
|
int xt_truthy(xt_value v);
|
|
@@ -259,6 +261,8 @@ xt_value xt_child_process_spawn_sync(int32_t argc, xt_value *argv);
|
|
|
259
261
|
xt_value xt_fetch(int32_t argc, xt_value *argv);
|
|
260
262
|
/** Construct a `TypeError` with one message argument (used by `fetch`). */
|
|
261
263
|
xt_value xt_type_error_ctor(int32_t argc, xt_value *argv);
|
|
264
|
+
/** Construct a `RangeError` with one message argument. */
|
|
265
|
+
xt_value xt_range_error_ctor(int32_t argc, xt_value *argv);
|
|
262
266
|
|
|
263
267
|
/* -- promises / async ----------------------------------------------------- */
|
|
264
268
|
xt_value xt_promise_resolve(xt_value value);
|
|
@@ -315,6 +319,12 @@ xt_value xt_set_timeout(int32_t argc, xt_value *argv);
|
|
|
315
319
|
xt_value xt_clear_timeout(int32_t argc, xt_value *argv);
|
|
316
320
|
xt_value xt_set_interval(int32_t argc, xt_value *argv);
|
|
317
321
|
xt_value xt_clear_interval(int32_t argc, xt_value *argv);
|
|
322
|
+
/* `setImmediate` runs on the timer queue with a zero delay; `clearImmediate`
|
|
323
|
+
* is an alias of `clearTimeout` (ids share one namespace). */
|
|
324
|
+
xt_value xt_set_immediate(int32_t argc, xt_value *argv);
|
|
325
|
+
xt_value xt_clear_immediate(int32_t argc, xt_value *argv);
|
|
326
|
+
/* Schedule `callback` on the promise microtask queue (same FIFO as `.then`). */
|
|
327
|
+
xt_value xt_queue_microtask(int32_t argc, xt_value *argv);
|
|
318
328
|
|
|
319
329
|
/* -- global functions ------------------------------------------------------ */
|
|
320
330
|
xt_value xt_parse_int(int32_t argc, xt_value *argv);
|
|
@@ -328,6 +338,8 @@ xt_value xt_decode_uri(int32_t argc, xt_value *argv);
|
|
|
328
338
|
xt_value xt_number_ctor(int32_t argc, xt_value *argv);
|
|
329
339
|
xt_value xt_string_ctor(int32_t argc, xt_value *argv);
|
|
330
340
|
xt_value xt_boolean_ctor(int32_t argc, xt_value *argv);
|
|
341
|
+
/* Deep clone arrays/objects/Map/Set/Date/RegExp/typed arrays. */
|
|
342
|
+
xt_value xt_structured_clone(int32_t argc, xt_value *argv);
|
|
331
343
|
/** `key in obj` (the key is the left operand). */
|
|
332
344
|
xt_value xt_in(xt_value key, xt_value obj);
|
|
333
345
|
/** `delete obj[key]`; removes object properties, clears array elements. */
|
|
@@ -360,6 +372,9 @@ xt_value xt_iter_value(xt_value value, xt_value index);
|
|
|
360
372
|
|
|
361
373
|
/* -- generic member access ------------------------------------------------ */
|
|
362
374
|
xt_value xt_get(xt_value target, xt_value key);
|
|
375
|
+
/** Interned shape/offset inline cache for a property read. `cache` points at
|
|
376
|
+
* two zero-initialised i64 words owned by the generated code. */
|
|
377
|
+
xt_value xt_get_ic(xt_value target, xt_value key, int64_t *cache);
|
|
363
378
|
xt_value xt_set(xt_value target, xt_value key, xt_value value);
|
|
364
379
|
/* Materialise a first-class runtime method value (`arr.map`) as an unbound
|
|
365
380
|
* closure that expects the receiver through `this`. Returns `XT_UNDEFINED` when
|
package/runtime/rt_internal.h
CHANGED
|
@@ -59,6 +59,10 @@
|
|
|
59
59
|
#define XT_OBJECT_KIND_GENERATOR 13
|
|
60
60
|
#define XT_OBJECT_KIND_ITERATOR 14
|
|
61
61
|
#define XT_OBJECT_KIND_ASYNC 15
|
|
62
|
+
#define XT_OBJECT_KIND_ASYNC_ITERATOR 16
|
|
63
|
+
#define XT_OBJECT_KIND_WEAK_MAP 17
|
|
64
|
+
#define XT_OBJECT_KIND_WEAK_SET 18
|
|
65
|
+
#define XT_OBJECT_KIND_WEAK_REF 19
|
|
62
66
|
|
|
63
67
|
/* Common header for every heap object. `flags` bit 0 is the collector's mark
|
|
64
68
|
* bit; it is cleared on every surviving object at the end of a sweep. */
|
|
@@ -111,11 +115,24 @@ typedef struct {
|
|
|
111
115
|
xt_value setter;
|
|
112
116
|
} xt_property;
|
|
113
117
|
|
|
118
|
+
/* Hidden-class descriptor for ordinary objects. Shapes are interned by their
|
|
119
|
+
* (parent, key) transition and never freed, so an object's shape pointer is a
|
|
120
|
+
* stable layout identity. Shape keys are rooted by a collector provider in
|
|
121
|
+
* xt_containers/shapes.inc. */
|
|
122
|
+
typedef struct xt_shape {
|
|
123
|
+
xt_value key;
|
|
124
|
+
uint32_t count;
|
|
125
|
+
struct xt_shape *parent;
|
|
126
|
+
struct xt_shape *next; /* hash-bucket chain */
|
|
127
|
+
struct xt_shape *all_next; /* every shape, for the GC root provider */
|
|
128
|
+
} xt_shape;
|
|
129
|
+
|
|
114
130
|
typedef struct {
|
|
115
131
|
xt_header header;
|
|
116
132
|
uint32_t count;
|
|
117
133
|
uint32_t capacity;
|
|
118
134
|
xt_property *properties;
|
|
135
|
+
xt_shape *shape;
|
|
119
136
|
xt_value prototype;
|
|
120
137
|
uint8_t frozen;
|
|
121
138
|
uint8_t is_array_base;
|
|
@@ -155,6 +172,9 @@ typedef struct {
|
|
|
155
172
|
/* Set on `async` function objects: calling the closure starts a coroutine
|
|
156
173
|
* (see xt_async.c) and immediately returns the promise it resolves. */
|
|
157
174
|
uint8_t is_async;
|
|
175
|
+
/* Set on `async function*` objects. `is_generator` is also set, but the call
|
|
176
|
+
* path checks this flag first so the generator is created in async mode. */
|
|
177
|
+
uint8_t is_async_generator;
|
|
158
178
|
/* Non-NULL for the first-class value of a built-in constructor ("Array",
|
|
159
179
|
* "Map", ...). It lets property access resolve the constructor's statics
|
|
160
180
|
* (`const A = Array; A.isArray(x)`). Points at a static string. */
|
|
@@ -217,12 +237,26 @@ void xt_gc_scan_region(const void *base, size_t bytes);
|
|
|
217
237
|
|
|
218
238
|
/* Kind-specific hooks for allocations with separately allocated sub-objects.
|
|
219
239
|
* Implemented by the translation unit that owns the representation. */
|
|
240
|
+
/* Weak-reference processing. `xt_weak_gc_process_once` marks values whose
|
|
241
|
+
* WeakMap key is already marked and returns 1 when it marked anything (the
|
|
242
|
+
* caller repeats until the ephemeron fixed point). `xt_weak_gc_clear` empties
|
|
243
|
+
* WeakRefs whose target stayed unmarked, and `xt_weak_gc_compact` drops dead
|
|
244
|
+
* WeakMap/WeakSet entries. */
|
|
245
|
+
int xt_weak_gc_process_once(void);
|
|
246
|
+
void xt_weak_gc_clear(void);
|
|
247
|
+
void xt_weak_gc_compact(void);
|
|
248
|
+
/* Mark-state queries used by the weak-reference pass. */
|
|
249
|
+
int xt_gc_value_is_marked(xt_value value);
|
|
250
|
+
/* Iterate every allocation (used by the weak-reference pass). */
|
|
251
|
+
xt_header *xt_gc_heap_head(void);
|
|
252
|
+
|
|
220
253
|
void xt_promise_gc_trace(xt_header *header);
|
|
221
254
|
void xt_promise_gc_release(xt_header *header);
|
|
222
255
|
void xt_generator_gc_trace(xt_header *header);
|
|
223
256
|
void xt_generator_gc_release(xt_header *header);
|
|
224
257
|
void xt_async_gc_trace(xt_header *header);
|
|
225
258
|
void xt_async_gc_release(xt_header *header);
|
|
259
|
+
void xt_async_iterator_gc_trace(xt_header *header);
|
|
226
260
|
|
|
227
261
|
/* Stackful coroutines (xt_coroutine.c). A coroutine owns a private C stack and
|
|
228
262
|
* switches to it with `ucontext`/fibers; `enter` runs until the body calls
|
|
@@ -232,6 +266,9 @@ typedef struct xt_coroutine xt_coroutine;
|
|
|
232
266
|
xt_coroutine *xt_coroutine_create(void (*entry)(void *), void *arg);
|
|
233
267
|
void xt_coroutine_enter(xt_coroutine *co);
|
|
234
268
|
void xt_coroutine_leave(xt_coroutine *co);
|
|
269
|
+
/* The coroutine whose body is currently executing, or NULL on the main stack. */
|
|
270
|
+
xt_coroutine *xt_coroutine_current(void);
|
|
271
|
+
int xt_coroutine_is_current(xt_coroutine *co);
|
|
235
272
|
void xt_coroutine_gc_trace(xt_coroutine *co);
|
|
236
273
|
void xt_coroutine_release(xt_coroutine *co);
|
|
237
274
|
|
|
@@ -320,6 +357,11 @@ void xt_array_reserve(xt_array *array, uint32_t needed);
|
|
|
320
357
|
/* Object helpers used by the standard library. */
|
|
321
358
|
xt_object *xt_as_object(xt_value value);
|
|
322
359
|
xt_property *xt_object_find_property(xt_object *obj, xt_value key);
|
|
360
|
+
/* Hidden-class helpers. `xt_object_shape_changed` rebuilds the shape after a
|
|
361
|
+
* property was inserted out of order or deleted. `xt_shape_empty` stays local
|
|
362
|
+
* to xt_containers.c, which is why it has no prototype here. */
|
|
363
|
+
xt_shape *xt_shape_transition(xt_shape *parent, xt_value key);
|
|
364
|
+
void xt_object_shape_changed(xt_object *obj);
|
|
323
365
|
|
|
324
366
|
/* Property keys are either strings or symbols. */
|
|
325
367
|
xt_value xt_to_property_key(xt_value key);
|
|
@@ -347,6 +389,14 @@ xt_value xt_regexp_split(xt_value value, xt_value regexp, xt_value limit);
|
|
|
347
389
|
xt_value xt_regexp_get_property(xt_value regexp, xt_value key);
|
|
348
390
|
int32_t xt_map_size(xt_value value);
|
|
349
391
|
int32_t xt_set_size(xt_value value);
|
|
392
|
+
/* WeakMap / WeakSet / WeakRef (xt_weak.c). */
|
|
393
|
+
int xt_is_weak_map(xt_value value);
|
|
394
|
+
int xt_is_weak_set(xt_value value);
|
|
395
|
+
int xt_is_weak_ref(xt_value value);
|
|
396
|
+
xt_value xt_weak_map_ctor(int32_t argc, xt_value *argv);
|
|
397
|
+
xt_value xt_weak_set_ctor(int32_t argc, xt_value *argv);
|
|
398
|
+
xt_value xt_weak_ref_ctor(int32_t argc, xt_value *argv);
|
|
399
|
+
xt_value xt_weak_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled);
|
|
350
400
|
/* `for...of` iteration: dispatch over arrays, strings, Maps and Sets. */
|
|
351
401
|
xt_value xt_iter_length(xt_value value);
|
|
352
402
|
xt_value xt_iter_value(xt_value value, xt_value index);
|
|
@@ -357,6 +407,9 @@ xt_value xt_iter_has(xt_value value, xt_value index);
|
|
|
357
407
|
* protocols, or a wrapper around `value[Symbol.iterator]()` otherwise. */
|
|
358
408
|
xt_value xt_iter_open(xt_value value);
|
|
359
409
|
|
|
410
|
+
/* Monotonic clock in fractional milliseconds (xt_loop.c), for `performance.now`. */
|
|
411
|
+
double xt_monotonic_ms(void);
|
|
412
|
+
|
|
360
413
|
/* Stackful generators (xt_generator.c). */
|
|
361
414
|
int xt_is_generator(xt_value value);
|
|
362
415
|
xt_value xt_generator_new(xt_value function, xt_value thisValue, int32_t argc, xt_value *argv);
|
|
@@ -367,6 +420,18 @@ xt_value xt_yield(xt_value value);
|
|
|
367
420
|
xt_value xt_yield_star(xt_value delegate);
|
|
368
421
|
int xt_generator_has_next(xt_value generator);
|
|
369
422
|
xt_value xt_generator_iter_value(xt_value generator);
|
|
423
|
+
/* Async-generator support. `xt_generator_await` handles an `await` inside an
|
|
424
|
+
* async generator and returns 1; it returns 0 when no async generator is
|
|
425
|
+
* running (ordinary/async code handles the await itself). */
|
|
426
|
+
int xt_generator_await(xt_value value, xt_value *result);
|
|
427
|
+
void xt_generator_wake(void *generator, xt_value value, int rejected);
|
|
428
|
+
int xt_is_async_generator(xt_value value);
|
|
429
|
+
/* `[Symbol.asyncIterator]()` for a generator object. */
|
|
430
|
+
xt_value xt_async_iterator_method(void);
|
|
431
|
+
/* `for await...of`: resolve the async iteration protocol once, then pull one
|
|
432
|
+
* step per call. Both return a promise for the step object. */
|
|
433
|
+
xt_value xt_async_iter_open(xt_value value);
|
|
434
|
+
xt_value xt_async_iter_next(xt_value iterator);
|
|
370
435
|
|
|
371
436
|
/* Async coroutines (xt_async.c). Calling an `async` function runs its body on
|
|
372
437
|
* a coroutine that suspends at a pending `await` and resumes when the awaited
|
|
@@ -387,6 +452,8 @@ int xt_promise_state_of(xt_value value);
|
|
|
387
452
|
xt_value xt_promise_value_of(xt_value value);
|
|
388
453
|
/* Register a coroutine to resume when `promise` settles (it must be pending). */
|
|
389
454
|
void xt_promise_add_async_waiter(xt_value promise, void *async);
|
|
455
|
+
/* Queue a microtask that resumes `async` with an already settled value. */
|
|
456
|
+
void xt_promise_queue_async_wake(void *async, xt_value settled, int rejected);
|
|
390
457
|
|
|
391
458
|
/* Exception-frame plumbing shared with the generator runtime. The struct is
|
|
392
459
|
* public so a coroutine can `_setjmp` its own boundary directly (a `setjmp`
|
|
@@ -448,6 +515,29 @@ typedef struct {
|
|
|
448
515
|
uint32_t capacity;
|
|
449
516
|
} xt_set_object;
|
|
450
517
|
|
|
518
|
+
/* Weak collections. Keys (WeakMap/WeakSet) and the target of a WeakRef are
|
|
519
|
+
* deliberately not traced by the collector: `xt_weak_gc_*` in xt_weak.c
|
|
520
|
+
* implements the ephemeron fixed point and clears unreachable refs. */
|
|
521
|
+
typedef struct {
|
|
522
|
+
xt_header header;
|
|
523
|
+
xt_value *keys;
|
|
524
|
+
xt_value *values;
|
|
525
|
+
uint32_t count;
|
|
526
|
+
uint32_t capacity;
|
|
527
|
+
} xt_weak_map;
|
|
528
|
+
|
|
529
|
+
typedef struct {
|
|
530
|
+
xt_header header;
|
|
531
|
+
xt_value *values;
|
|
532
|
+
uint32_t count;
|
|
533
|
+
uint32_t capacity;
|
|
534
|
+
} xt_weak_set;
|
|
535
|
+
|
|
536
|
+
typedef struct {
|
|
537
|
+
xt_header header;
|
|
538
|
+
xt_value target;
|
|
539
|
+
} xt_weak_ref;
|
|
540
|
+
|
|
451
541
|
typedef struct {
|
|
452
542
|
xt_header header;
|
|
453
543
|
double time;
|
|
@@ -468,6 +558,9 @@ xt_value xt_ext_object_method(xt_value target, const char *method, int32_t argc,
|
|
|
468
558
|
|
|
469
559
|
/* Error family helpers (xt_stdlib2.c). */
|
|
470
560
|
xt_value xt_error_to_string(xt_value error);
|
|
561
|
+
/* Turn an internal "TypeError: message" / "RangeError: message" string into a
|
|
562
|
+
* real Error-family value so `catch` observes an Error, not a string. */
|
|
563
|
+
xt_value xt_error_from_message(const char *message);
|
|
471
564
|
xt_value xt_aggregate_error_ctor(int32_t argc, xt_value *argv);
|
|
472
565
|
xt_value xt_ext_container_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled);
|
|
473
566
|
xt_value xt_promise_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled);
|
|
@@ -482,5 +575,18 @@ xt_value xt_arg_at(int32_t argc, xt_value *argv, int32_t index);
|
|
|
482
575
|
/* Typed arrays (xt_typed_array.c). */
|
|
483
576
|
int xt_typed_array_kind_of(xt_value value);
|
|
484
577
|
double xt_typed_array_coerce(int kind, double value);
|
|
578
|
+
/* Buffer-backed element access; the array must be a typed-array value. */
|
|
579
|
+
xt_value xt_typed_array_read(xt_value array, uint32_t index);
|
|
580
|
+
void xt_typed_array_write(xt_value array, uint32_t index, xt_value value);
|
|
581
|
+
xt_value xt_typed_array_buffer_of(xt_value array);
|
|
582
|
+
uint32_t xt_typed_array_byte_offset_of(xt_value array);
|
|
583
|
+
const char *xt_typed_array_name_of(int kind);
|
|
584
|
+
|
|
585
|
+
/* ArrayBuffer helpers (xt_array_buffer.c). */
|
|
586
|
+
int xt_is_array_buffer(xt_value value);
|
|
587
|
+
uint32_t xt_array_buffer_byte_length(xt_value value);
|
|
588
|
+
uint8_t xt_array_buffer_get_byte(xt_value buffer, uint32_t index);
|
|
589
|
+
void xt_array_buffer_set_byte(xt_value buffer, uint32_t index, uint8_t value);
|
|
590
|
+
xt_value xt_array_buffer_ctor(int32_t argc, xt_value *argv);
|
|
485
591
|
|
|
486
592
|
#endif /* XT_RT_INTERNAL_H */
|
package/runtime/xt_alloc.c
CHANGED
|
@@ -303,6 +303,17 @@ void xt_gc_mark_value(xt_value value) {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
|
|
306
|
+
int xt_gc_value_is_marked(xt_value value) {
|
|
307
|
+
if (!(XT_IS_STRING(value) || XT_IS_OBJECT(value) || XT_IS_ARRAY(value) ||
|
|
308
|
+
XT_IS_FUNCTION(value) || XT_IS_BIGINT(value))) {
|
|
309
|
+
return 0;
|
|
310
|
+
}
|
|
311
|
+
xt_header *header = xt_gc_table_lookup((uintptr_t)XT_GET_PTR(value));
|
|
312
|
+
return header != NULL && (header->flags & XT_GC_MARK) != 0;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
xt_header *xt_gc_heap_head(void) { return g_heap_head; }
|
|
316
|
+
|
|
306
317
|
void xt_gc_scan_region(const void *base, size_t bytes) {
|
|
307
318
|
if (!base) return;
|
|
308
319
|
const uint64_t *words = (const uint64_t *)base;
|
|
@@ -392,6 +403,15 @@ static void xt_gc_process(xt_header *header) {
|
|
|
392
403
|
case XT_OBJECT_KIND_ASYNC:
|
|
393
404
|
xt_async_gc_trace(header);
|
|
394
405
|
return;
|
|
406
|
+
case XT_OBJECT_KIND_ASYNC_ITERATOR:
|
|
407
|
+
xt_async_iterator_gc_trace(header);
|
|
408
|
+
return;
|
|
409
|
+
case XT_OBJECT_KIND_WEAK_MAP:
|
|
410
|
+
case XT_OBJECT_KIND_WEAK_SET:
|
|
411
|
+
case XT_OBJECT_KIND_WEAK_REF:
|
|
412
|
+
/* Weak references are not traced; `xt_weak_gc_*` owns the ephemeron
|
|
413
|
+
* fixed point after the ordinary mark phase. */
|
|
414
|
+
return;
|
|
395
415
|
default:
|
|
396
416
|
/* Symbols, regexps, iterators and any future kind whose references live
|
|
397
417
|
* inline: the payload scan covers them. */
|
|
@@ -429,6 +449,13 @@ static void xt_gc_release(xt_header *header) {
|
|
|
429
449
|
case XT_OBJECT_KIND_SET:
|
|
430
450
|
free(((xt_set_object *)header)->values);
|
|
431
451
|
break;
|
|
452
|
+
case XT_OBJECT_KIND_WEAK_MAP:
|
|
453
|
+
free(((xt_weak_map *)header)->keys);
|
|
454
|
+
free(((xt_weak_map *)header)->values);
|
|
455
|
+
break;
|
|
456
|
+
case XT_OBJECT_KIND_WEAK_SET:
|
|
457
|
+
free(((xt_weak_set *)header)->values);
|
|
458
|
+
break;
|
|
432
459
|
case XT_OBJECT_KIND_PROMISE:
|
|
433
460
|
xt_promise_gc_release(header);
|
|
434
461
|
break;
|
|
@@ -478,16 +505,25 @@ void xt_gc_collect(void) {
|
|
|
478
505
|
|
|
479
506
|
xt_gc_table_build();
|
|
480
507
|
xt_gc_mark_roots();
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
508
|
+
/* Ephemeron fixed point: a WeakMap value is reachable only when its key is
|
|
509
|
+
* reachable. Marking a value can reach further keys, so repeat until a pass
|
|
510
|
+
* marks nothing new. WeakRefs are cleared only after this settles, because
|
|
511
|
+
* an ephemeron may still keep their target alive. */
|
|
512
|
+
for (;;) {
|
|
513
|
+
while (g_gray_count > 0) {
|
|
514
|
+
xt_header *header = g_gray[--g_gray_count];
|
|
515
|
+
xt_gc_process(header);
|
|
516
|
+
}
|
|
517
|
+
if (!xt_weak_gc_process_once()) break;
|
|
484
518
|
}
|
|
519
|
+
xt_weak_gc_clear();
|
|
520
|
+
xt_weak_gc_compact();
|
|
485
521
|
|
|
486
522
|
xt_header **link = &g_heap_head;
|
|
487
523
|
xt_header *header = g_heap_head;
|
|
488
|
-
size_t live_by_kind[
|
|
489
|
-
size_t bytes_by_kind[
|
|
490
|
-
for (int i = 0; i <
|
|
524
|
+
size_t live_by_kind[32];
|
|
525
|
+
size_t bytes_by_kind[32];
|
|
526
|
+
for (int i = 0; i < 32; i++) {
|
|
491
527
|
live_by_kind[i] = 0;
|
|
492
528
|
bytes_by_kind[i] = 0;
|
|
493
529
|
}
|
|
@@ -497,7 +533,7 @@ void xt_gc_collect(void) {
|
|
|
497
533
|
header->flags &= (uint8_t)~XT_GC_MARK;
|
|
498
534
|
link = &header->gc_next;
|
|
499
535
|
if (trace) {
|
|
500
|
-
size_t kind = header->kind <
|
|
536
|
+
size_t kind = header->kind < 32 ? header->kind : 0;
|
|
501
537
|
live_by_kind[kind]++;
|
|
502
538
|
bytes_by_kind[kind] += header->size;
|
|
503
539
|
}
|