xbintsc 0.3.87 → 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 +23 -11
- package/README.md +11 -9
- package/README.zh-CN.md +7 -7
- 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 +17 -4
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/closures.js +13 -1
- package/dist/src/codegen/generator/calls/closures.js.map +1 -1
- package/dist/src/codegen/generator/calls/invocation.js +4 -3
- package/dist/src/codegen/generator/calls/invocation.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 +11 -1
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/module.d.ts +0 -1
- package/dist/src/codegen/generator/module.js +10 -17
- 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 +27 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/statements/control-flow.js +2 -7
- 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.d.ts +9 -0
- package/dist/src/codegen/generator/tables.js +100 -3
- 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 -230
- 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/closures.test.js +8 -0
- package/dist/tests/codegen/closures.test.js.map +1 -1
- 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-await.test.d.ts +10 -0
- package/dist/tests/e2e/async-await.test.js +247 -0
- package/dist/tests/e2e/async-await.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-coverage-globals.test.js +46 -0
- package/dist/tests/e2e/runtime-coverage-globals.test.js.map +1 -1
- 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/string-utf16.test.d.ts +6 -0
- package/dist/tests/e2e/string-utf16.test.js +133 -0
- package/dist/tests/e2e/string-utf16.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 +26 -21
- package/doc/ai/extensions.md +12 -9
- package/doc/ai/language-support.md +26 -19
- package/doc/ai/troubleshooting.md +15 -12
- 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 +19 -18
- package/doc/ai/zh-CN/extensions.md +10 -7
- package/doc/ai/zh-CN/language-support.md +26 -20
- package/doc/ai/zh-CN/troubleshooting.md +12 -10
- 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 -352
- 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 -274
- 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 -347
- 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 -236
- 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 +47 -0
- package/runtime/rt_internal.h +205 -10
- package/runtime/xt_alloc.c +49 -7
- package/runtime/xt_array_buffer.c +284 -0
- package/runtime/xt_async.c +222 -0
- package/runtime/xt_bigint/helpers.inc +3 -3
- package/runtime/xt_builtins.c +59 -51
- package/runtime/xt_constructors.c +399 -0
- package/runtime/xt_containers/access.inc +195 -14
- package/runtime/xt_containers/arrays.inc +26 -2
- package/runtime/xt_containers/objects.inc +226 -5
- package/runtime/xt_containers/shapes.inc +71 -0
- package/runtime/xt_containers.c +1 -0
- package/runtime/xt_coroutine.c +229 -0
- package/runtime/xt_generator.c +325 -167
- package/runtime/xt_io/inspect.inc +147 -2
- package/runtime/xt_loop.c +35 -4
- package/runtime/xt_performance.c +37 -0
- package/runtime/xt_promise.c +125 -18
- package/runtime/xt_stdlib/arrays.inc +1 -1
- package/runtime/xt_stdlib/dispatch.inc +64 -13
- package/runtime/xt_stdlib/strings.inc +74 -17
- package/runtime/xt_stdlib2/array-statics.inc +28 -3
- 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 +35 -0
- package/runtime/xt_stdlib2/json.inc +353 -33
- package/runtime/xt_stdlib2/number-string-statics.inc +24 -15
- package/runtime/xt_stdlib2/objects.inc +123 -1
- package/runtime/xt_stdlib2/regexp-match.inc +2 -2
- package/runtime/xt_stdlib2/set.inc +7 -1
- package/runtime/xt_stdlib2/strings.inc +70 -40
- 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 +78 -7
- package/runtime/xt_typed_array/elements.inc +159 -0
- package/runtime/xt_typed_array/methods.inc +21 -5
- package/runtime/xt_typed_array.c +11 -10
- package/runtime/xt_url.c +375 -0
- package/runtime/xt_values/arithmetic.inc +2 -2
- package/runtime/xt_values/constructors.inc +8 -0
- package/runtime/xt_values/conversions.inc +1 -1
- package/runtime/xt_values/strings.inc +19 -3
- package/runtime/xt_values/utf16.inc +340 -0
- package/runtime/xt_values.c +1 -0
- 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 +17 -4
- package/src/codegen/generator/calls/closures.ts +12 -1
- package/src/codegen/generator/calls/invocation.ts +4 -3
- package/src/codegen/generator/context.ts +23 -3
- package/src/codegen/generator/expressions/operators.ts +27 -13
- package/src/codegen/generator/expressions/primary.ts +10 -1
- package/src/codegen/generator/module.ts +10 -19
- package/src/codegen/generator/numeric.ts +85 -11
- package/src/codegen/generator/state.ts +27 -0
- package/src/codegen/generator/statements/control-flow.ts +2 -6
- package/src/codegen/generator/statements/loops.ts +50 -16
- package/src/codegen/generator/tables.ts +110 -3
- 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 -324
- 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
|
@@ -21,7 +21,7 @@ static xt_value xt_ta_proto(int kind) {
|
|
|
21
21
|
xt_ta_define(proto, "fill", (void *)xt_ta_method_fill);
|
|
22
22
|
xt_ta_define(proto, "set", (void *)xt_ta_method_set);
|
|
23
23
|
xt_ta_define(proto, "slice", (void *)xt_ta_method_slice);
|
|
24
|
-
xt_ta_define(proto, "subarray", (void *)
|
|
24
|
+
xt_ta_define(proto, "subarray", (void *)xt_ta_method_subarray);
|
|
25
25
|
xt_ta_define(proto, "join", (void *)xt_ta_method_join);
|
|
26
26
|
xt_ta_define(proto, "toString", (void *)xt_ta_method_to_string);
|
|
27
27
|
xt_ta_define(proto, "toLocaleString", (void *)xt_ta_method_to_string);
|
|
@@ -43,18 +43,30 @@ static xt_value xt_ta_proto(int kind) {
|
|
|
43
43
|
xt_ta_define(proto, "keys", (void *)xt_ta_method_keys);
|
|
44
44
|
xt_ta_define(proto, "values", (void *)xt_ta_method_values);
|
|
45
45
|
xt_ta_define(proto, "entries", (void *)xt_ta_method_entries);
|
|
46
|
+
xt_value constructor = xt_builtin_constructor(xt_string_from_cstr(xt_ta_names[kind]));
|
|
47
|
+
if (constructor != XT_UNDEFINED) {
|
|
48
|
+
xt_object_set(proto, xt_string_from_cstr("constructor"), constructor);
|
|
49
|
+
}
|
|
46
50
|
return proto;
|
|
47
51
|
}
|
|
48
52
|
|
|
49
|
-
static xt_value
|
|
53
|
+
static xt_value xt_ta_view(int kind, xt_value buffer, uint32_t byteOffset, uint32_t length) {
|
|
50
54
|
xt_value array = xt_object_new_with_proto(xt_ta_proto(kind));
|
|
51
55
|
xt_object_set(array, xt_string_from_cstr("length"), xt_number((double)length));
|
|
52
|
-
xt_object_set(array, xt_string_from_cstr("byteLength"),
|
|
53
|
-
|
|
54
|
-
|
|
56
|
+
xt_object_set(array, xt_string_from_cstr("byteLength"),
|
|
57
|
+
xt_number((double)length * xt_ta_bytes[kind]));
|
|
58
|
+
xt_object_set(array, xt_string_from_cstr("byteOffset"), xt_number((double)byteOffset));
|
|
59
|
+
xt_object_set(array, xt_ta_buffer_key(), buffer);
|
|
60
|
+
xt_object_set(array, xt_ta_offset_key(), xt_number((double)byteOffset));
|
|
55
61
|
return array;
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
static xt_value xt_ta_new(int kind, uint32_t length) {
|
|
65
|
+
xt_value byteLength = xt_number((double)length * xt_ta_bytes[kind]);
|
|
66
|
+
xt_value buffer = xt_array_buffer_ctor(1, &byteLength);
|
|
67
|
+
return xt_ta_view(kind, buffer, 0, length);
|
|
68
|
+
}
|
|
69
|
+
|
|
58
70
|
/* Length of any value a typed array can be built from, or 0 when it is not
|
|
59
71
|
* array-like (strings/iterables are intentionally not treated as element
|
|
60
72
|
* sources yet). */
|
|
@@ -64,7 +76,7 @@ static int xt_ta_length_of(xt_value value, uint32_t *out) {
|
|
|
64
76
|
return 1;
|
|
65
77
|
}
|
|
66
78
|
if (XT_IS_STRING(value)) {
|
|
67
|
-
*out = xt_as_string(value)
|
|
79
|
+
*out = xt_string_code_point_count(xt_as_string(value));
|
|
68
80
|
return 1;
|
|
69
81
|
}
|
|
70
82
|
if (xt_typed_array_kind_of(value) >= 0) {
|
|
@@ -86,8 +98,10 @@ static xt_value xt_ta_from_value(int kind, xt_value value, xt_value mapFn, xt_va
|
|
|
86
98
|
uint32_t length = 0;
|
|
87
99
|
if (!xt_ta_length_of(value, &length)) length = 0;
|
|
88
100
|
xt_value array = xt_ta_new(kind, length);
|
|
101
|
+
xt_string *sourceString = XT_IS_STRING(value) ? xt_as_string(value) : NULL;
|
|
89
102
|
for (uint32_t i = 0; i < length; i++) {
|
|
90
|
-
xt_value item =
|
|
103
|
+
xt_value item = sourceString ? xt_string_code_point_value(sourceString, (int32_t)i)
|
|
104
|
+
: xt_get(value, xt_number((double)i));
|
|
91
105
|
if (haveMap) {
|
|
92
106
|
xt_value args[3] = {item, xt_number((double)i), array};
|
|
93
107
|
item = xt_call_with_this(mapFn, thisArg, 3, args);
|
|
@@ -100,6 +114,28 @@ static xt_value xt_ta_from_value(int kind, xt_value value, xt_value mapFn, xt_va
|
|
|
100
114
|
static xt_value xt_ta_ctor_impl(int kind, int32_t argc, xt_value *argv) {
|
|
101
115
|
if (argc == 0) return xt_ta_new(kind, 0);
|
|
102
116
|
xt_value argument = argv[0];
|
|
117
|
+
if (xt_is_array_buffer(argument)) {
|
|
118
|
+
uint32_t bufferLength = xt_array_buffer_byte_length(argument);
|
|
119
|
+
double rawOffset = argc > 1 ? xt_to_number(argv[1]) : 0;
|
|
120
|
+
uint32_t offset = rawOffset > 0 ? (uint32_t)rawOffset : 0;
|
|
121
|
+
uint32_t width = (uint32_t)xt_ta_bytes[kind];
|
|
122
|
+
if (offset % width != 0 || offset > bufferLength) {
|
|
123
|
+
xt_value message = xt_string_from_cstr("start offset is not aligned or out of bounds");
|
|
124
|
+
xt_throw(xt_range_error_ctor(1, &message));
|
|
125
|
+
}
|
|
126
|
+
uint32_t length;
|
|
127
|
+
if (argc > 2 && argv[2] != XT_UNDEFINED) {
|
|
128
|
+
double rawLength = xt_to_number(argv[2]);
|
|
129
|
+
length = rawLength > 0 ? (uint32_t)rawLength : 0;
|
|
130
|
+
} else {
|
|
131
|
+
length = (bufferLength - offset) / width;
|
|
132
|
+
}
|
|
133
|
+
if (length > (bufferLength - offset) / width) {
|
|
134
|
+
xt_value message = xt_string_from_cstr("Invalid typed array length");
|
|
135
|
+
xt_throw(xt_range_error_ctor(1, &message));
|
|
136
|
+
}
|
|
137
|
+
return xt_ta_view(kind, argument, offset, length);
|
|
138
|
+
}
|
|
103
139
|
/* Objects (arrays / typed arrays / array-likes / iterables) are copied
|
|
104
140
|
* element-wise; every other argument is a length via `ToIndex`. */
|
|
105
141
|
if (XT_IS_ARRAY(argument) || XT_IS_OBJECT(argument)) {
|
|
@@ -140,3 +176,38 @@ XT_TA_CTOR(i32, XT_TA_I32)
|
|
|
140
176
|
XT_TA_CTOR(f32, XT_TA_F32)
|
|
141
177
|
XT_TA_CTOR(f64, XT_TA_F64)
|
|
142
178
|
|
|
179
|
+
/* Dispatch by constructor name, used when a typed-array constructor is a
|
|
180
|
+
* first-class value (`const T = Uint8Array; new T(4)`). */
|
|
181
|
+
static int xt_ta_kind_from_name(const char *name) {
|
|
182
|
+
if (!name) return -1;
|
|
183
|
+
if (strcmp(name, "Uint8Array") == 0) return XT_TA_U8;
|
|
184
|
+
if (strcmp(name, "Int8Array") == 0) return XT_TA_I8;
|
|
185
|
+
if (strcmp(name, "Uint8ClampedArray") == 0) return XT_TA_U8C;
|
|
186
|
+
if (strcmp(name, "Uint16Array") == 0) return XT_TA_U16;
|
|
187
|
+
if (strcmp(name, "Int16Array") == 0) return XT_TA_I16;
|
|
188
|
+
if (strcmp(name, "Uint32Array") == 0) return XT_TA_U32;
|
|
189
|
+
if (strcmp(name, "Int32Array") == 0) return XT_TA_I32;
|
|
190
|
+
if (strcmp(name, "Float32Array") == 0) return XT_TA_F32;
|
|
191
|
+
if (strcmp(name, "Float64Array") == 0) return XT_TA_F64;
|
|
192
|
+
return -1;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
xt_value xt_typed_array_ctor_by_name(xt_value nameValue, int32_t argc, xt_value *argv) {
|
|
196
|
+
int kind = xt_ta_kind_from_name(XT_IS_STRING(nameValue) ? xt_string_data(nameValue) : NULL);
|
|
197
|
+
if (kind < 0) return XT_UNDEFINED;
|
|
198
|
+
return xt_ta_ctor_impl(kind, argc, argv);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
xt_value xt_typed_array_static_by_name(xt_value nameValue, xt_value method, int32_t argc,
|
|
202
|
+
xt_value *argv) {
|
|
203
|
+
int kind = xt_ta_kind_from_name(XT_IS_STRING(nameValue) ? xt_string_data(nameValue) : NULL);
|
|
204
|
+
if (kind < 0) return XT_UNDEFINED;
|
|
205
|
+
return xt_ta_static_impl(kind, method, argc, argv);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
xt_value xt_typed_array_prototype(xt_value nameValue) {
|
|
209
|
+
int kind = xt_ta_kind_from_name(XT_IS_STRING(nameValue) ? xt_string_data(nameValue) : NULL);
|
|
210
|
+
if (kind < 0) return XT_UNDEFINED;
|
|
211
|
+
return xt_ta_proto(kind);
|
|
212
|
+
}
|
|
213
|
+
|
|
@@ -53,6 +53,158 @@ int xt_typed_array_kind_of(xt_value value) {
|
|
|
53
53
|
return -1;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
+
const char *xt_typed_array_name_of(int kind) {
|
|
57
|
+
if (kind < 0 || kind >= XT_TA_KIND_COUNT) return NULL;
|
|
58
|
+
return xt_ta_names[kind];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* -- buffer-backed views -------------------------------------------------- */
|
|
62
|
+
|
|
63
|
+
/* The backing ArrayBuffer and byte offset live under private symbols, so a
|
|
64
|
+
* typed array's observable own properties stay `length`/`byteLength`/
|
|
65
|
+
* `byteOffset` plus `.buffer` (handled in access.inc). */
|
|
66
|
+
static xt_value xt_ta_buffer_key_value = XT_UNDEFINED;
|
|
67
|
+
static xt_value xt_ta_offset_key_value = XT_UNDEFINED;
|
|
68
|
+
|
|
69
|
+
static xt_value xt_ta_buffer_key(void) {
|
|
70
|
+
if (!xt_is_symbol(xt_ta_buffer_key_value)) {
|
|
71
|
+
xt_ta_buffer_key_value = xt_symbol_new(xt_string_from_cstr("__typedArrayBuffer"));
|
|
72
|
+
xt_gc_add_root(&xt_ta_buffer_key_value);
|
|
73
|
+
}
|
|
74
|
+
return xt_ta_buffer_key_value;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static xt_value xt_ta_offset_key(void) {
|
|
78
|
+
if (!xt_is_symbol(xt_ta_offset_key_value)) {
|
|
79
|
+
xt_ta_offset_key_value = xt_symbol_new(xt_string_from_cstr("__typedArrayOffset"));
|
|
80
|
+
xt_gc_add_root(&xt_ta_offset_key_value);
|
|
81
|
+
}
|
|
82
|
+
return xt_ta_offset_key_value;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
xt_value xt_typed_array_buffer_of(xt_value array) {
|
|
86
|
+
if (xt_typed_array_kind_of(array) < 0) return XT_UNDEFINED;
|
|
87
|
+
return xt_object_get(array, xt_ta_buffer_key());
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
uint32_t xt_typed_array_byte_offset_of(xt_value array) {
|
|
91
|
+
if (xt_typed_array_kind_of(array) < 0) return 0;
|
|
92
|
+
return (uint32_t)xt_to_number(xt_object_get(array, xt_ta_offset_key()));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
xt_value xt_typed_array_read(xt_value array, uint32_t index) {
|
|
96
|
+
int kind = xt_typed_array_kind_of(array);
|
|
97
|
+
if (kind < 0) return XT_UNDEFINED;
|
|
98
|
+
xt_value buffer = xt_typed_array_buffer_of(array);
|
|
99
|
+
if (!xt_is_array_buffer(buffer)) {
|
|
100
|
+
char key[24];
|
|
101
|
+
snprintf(key, sizeof(key), "%u", index);
|
|
102
|
+
return xt_object_get_cstr(array, key);
|
|
103
|
+
}
|
|
104
|
+
uint32_t width = (uint32_t)xt_ta_bytes[kind];
|
|
105
|
+
uint32_t offset = xt_typed_array_byte_offset_of(array) + index * width;
|
|
106
|
+
if (offset + width > xt_array_buffer_byte_length(buffer)) return XT_UNDEFINED;
|
|
107
|
+
uint8_t raw[8];
|
|
108
|
+
for (uint32_t i = 0; i < width; i++) raw[i] = xt_array_buffer_get_byte(buffer, offset + i);
|
|
109
|
+
switch (kind) {
|
|
110
|
+
case XT_TA_U8:
|
|
111
|
+
return xt_number((double)raw[0]);
|
|
112
|
+
case XT_TA_I8:
|
|
113
|
+
return xt_number((double)(int8_t)raw[0]);
|
|
114
|
+
case XT_TA_U8C:
|
|
115
|
+
return xt_number((double)raw[0]);
|
|
116
|
+
case XT_TA_U16: {
|
|
117
|
+
uint16_t value;
|
|
118
|
+
memcpy(&value, raw, sizeof(value));
|
|
119
|
+
return xt_number((double)value);
|
|
120
|
+
}
|
|
121
|
+
case XT_TA_I16: {
|
|
122
|
+
int16_t value;
|
|
123
|
+
memcpy(&value, raw, sizeof(value));
|
|
124
|
+
return xt_number((double)value);
|
|
125
|
+
}
|
|
126
|
+
case XT_TA_U32: {
|
|
127
|
+
uint32_t value;
|
|
128
|
+
memcpy(&value, raw, sizeof(value));
|
|
129
|
+
return xt_number((double)value);
|
|
130
|
+
}
|
|
131
|
+
case XT_TA_I32: {
|
|
132
|
+
int32_t value;
|
|
133
|
+
memcpy(&value, raw, sizeof(value));
|
|
134
|
+
return xt_number((double)value);
|
|
135
|
+
}
|
|
136
|
+
case XT_TA_F32: {
|
|
137
|
+
float value;
|
|
138
|
+
memcpy(&value, raw, sizeof(value));
|
|
139
|
+
return xt_number((double)value);
|
|
140
|
+
}
|
|
141
|
+
default: {
|
|
142
|
+
double value;
|
|
143
|
+
memcpy(&value, raw, sizeof(value));
|
|
144
|
+
return xt_number(value);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
void xt_typed_array_write(xt_value array, uint32_t index, xt_value value) {
|
|
150
|
+
int kind = xt_typed_array_kind_of(array);
|
|
151
|
+
if (kind < 0) return;
|
|
152
|
+
xt_value buffer = xt_typed_array_buffer_of(array);
|
|
153
|
+
if (!xt_is_array_buffer(buffer)) {
|
|
154
|
+
char key[24];
|
|
155
|
+
snprintf(key, sizeof(key), "%u", index);
|
|
156
|
+
xt_object_set(array, xt_string_from_cstr(key),
|
|
157
|
+
xt_number(xt_typed_array_coerce(kind, xt_to_number(value))));
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
uint32_t width = (uint32_t)xt_ta_bytes[kind];
|
|
161
|
+
uint32_t offset = xt_typed_array_byte_offset_of(array) + index * width;
|
|
162
|
+
if (offset + width > xt_array_buffer_byte_length(buffer)) return;
|
|
163
|
+
double coerced = xt_typed_array_coerce(kind, xt_to_number(value));
|
|
164
|
+
uint8_t raw[8];
|
|
165
|
+
memset(raw, 0, sizeof(raw));
|
|
166
|
+
switch (kind) {
|
|
167
|
+
case XT_TA_U8:
|
|
168
|
+
case XT_TA_U8C:
|
|
169
|
+
raw[0] = (uint8_t)coerced;
|
|
170
|
+
break;
|
|
171
|
+
case XT_TA_I8:
|
|
172
|
+
raw[0] = (uint8_t)(int8_t)coerced;
|
|
173
|
+
break;
|
|
174
|
+
case XT_TA_U16: {
|
|
175
|
+
uint16_t stored = (uint16_t)coerced;
|
|
176
|
+
memcpy(raw, &stored, sizeof(stored));
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
case XT_TA_I16: {
|
|
180
|
+
int16_t stored = (int16_t)coerced;
|
|
181
|
+
memcpy(raw, &stored, sizeof(stored));
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
case XT_TA_U32: {
|
|
185
|
+
uint32_t stored = (uint32_t)coerced;
|
|
186
|
+
memcpy(raw, &stored, sizeof(stored));
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case XT_TA_I32: {
|
|
190
|
+
int32_t stored = (int32_t)coerced;
|
|
191
|
+
memcpy(raw, &stored, sizeof(stored));
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
case XT_TA_F32: {
|
|
195
|
+
float stored = (float)coerced;
|
|
196
|
+
memcpy(raw, &stored, sizeof(stored));
|
|
197
|
+
break;
|
|
198
|
+
}
|
|
199
|
+
default: {
|
|
200
|
+
double stored = coerced;
|
|
201
|
+
memcpy(raw, &stored, sizeof(stored));
|
|
202
|
+
break;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
for (uint32_t i = 0; i < width; i++) xt_array_buffer_set_byte(buffer, offset + i, raw[i]);
|
|
206
|
+
}
|
|
207
|
+
|
|
56
208
|
/* -- element storage ------------------------------------------------------ */
|
|
57
209
|
|
|
58
210
|
static uint32_t xt_ta_length(xt_value array) {
|
|
@@ -62,12 +214,19 @@ static uint32_t xt_ta_length(xt_value array) {
|
|
|
62
214
|
}
|
|
63
215
|
|
|
64
216
|
static xt_value xt_ta_element(xt_value array, uint32_t index) {
|
|
217
|
+
if (xt_is_array_buffer(xt_typed_array_buffer_of(array))) {
|
|
218
|
+
return xt_typed_array_read(array, index);
|
|
219
|
+
}
|
|
65
220
|
char key[24];
|
|
66
221
|
snprintf(key, sizeof(key), "%u", index);
|
|
67
222
|
return xt_object_get_cstr(array, key);
|
|
68
223
|
}
|
|
69
224
|
|
|
70
225
|
static void xt_ta_store(xt_value array, int kind, uint32_t index, double value) {
|
|
226
|
+
if (xt_is_array_buffer(xt_typed_array_buffer_of(array))) {
|
|
227
|
+
xt_typed_array_write(array, index, xt_number(value));
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
71
230
|
char key[24];
|
|
72
231
|
snprintf(key, sizeof(key), "%u", index);
|
|
73
232
|
xt_object_set(array, xt_string_from_cstr(key), xt_number(xt_typed_array_coerce(kind, value)));
|
|
@@ -24,7 +24,7 @@ static xt_value xt_ta_method_set(xt_value self, xt_value env, int32_t argc, xt_v
|
|
|
24
24
|
if (!xt_ta_length_of(source, &sourceLength)) return XT_UNDEFINED;
|
|
25
25
|
int32_t offset = argc > 1 ? xt_to_int32(argv[1]) : 0;
|
|
26
26
|
if (offset < 0 || offset + (int32_t)sourceLength > (int32_t)xt_ta_length(self)) {
|
|
27
|
-
xt_throw(
|
|
27
|
+
xt_throw(xt_error_from_message("RangeError: offset is out of bounds"));
|
|
28
28
|
return XT_UNDEFINED;
|
|
29
29
|
}
|
|
30
30
|
for (uint32_t i = 0; i < sourceLength; i++) {
|
|
@@ -47,6 +47,20 @@ static xt_value xt_ta_method_slice(xt_value self, xt_value env, int32_t argc, xt
|
|
|
47
47
|
return out;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
static xt_value xt_ta_method_subarray(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
51
|
+
(void)env;
|
|
52
|
+
int kind = xt_typed_array_kind_of(self);
|
|
53
|
+
if (kind < 0) return XT_UNDEFINED;
|
|
54
|
+
xt_value buffer = xt_typed_array_buffer_of(self);
|
|
55
|
+
if (!xt_is_array_buffer(buffer)) return xt_ta_method_slice(self, env, argc, argv);
|
|
56
|
+
int32_t length = (int32_t)xt_ta_length(self);
|
|
57
|
+
int32_t start = xt_ta_relative(argc > 0 && argv[0] != XT_UNDEFINED ? xt_to_int32(argv[0]) : 0, length);
|
|
58
|
+
int32_t end = xt_ta_relative(argc > 1 && argv[1] != XT_UNDEFINED ? xt_to_int32(argv[1]) : length, length);
|
|
59
|
+
if (end < start) end = start;
|
|
60
|
+
uint32_t offset = xt_typed_array_byte_offset_of(self) + (uint32_t)start * (uint32_t)xt_ta_bytes[kind];
|
|
61
|
+
return xt_ta_view(kind, buffer, offset, (uint32_t)(end - start));
|
|
62
|
+
}
|
|
63
|
+
|
|
50
64
|
static xt_value xt_ta_method_join(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
51
65
|
(void)env;
|
|
52
66
|
xt_value separator = argc > 0 && argv[0] != XT_UNDEFINED ? xt_to_string(argv[0]) : xt_string_from_cstr(",");
|
|
@@ -137,14 +151,16 @@ static xt_value xt_ta_method_filter(xt_value self, xt_value env, int32_t argc, x
|
|
|
137
151
|
xt_value callback = xt_arg_at(argc, argv, 0);
|
|
138
152
|
xt_value thisArg = xt_arg_at(argc, argv, 1);
|
|
139
153
|
int32_t length = (int32_t)xt_ta_length(self);
|
|
140
|
-
|
|
154
|
+
/* A fixed-length buffer cannot grow, so collect matches first and build the
|
|
155
|
+
* result typed array from that array. */
|
|
156
|
+
xt_value matches = xt_array_new(0, NULL);
|
|
141
157
|
for (int32_t i = 0; i < length; i++) {
|
|
142
158
|
xt_value args[3] = {xt_ta_element(self, (uint32_t)i), xt_number((double)i), self};
|
|
143
159
|
if (xt_truthy(xt_call_with_this(callback, thisArg, 3, args))) {
|
|
144
|
-
|
|
160
|
+
xt_array_push(matches, xt_ta_element(self, (uint32_t)i));
|
|
145
161
|
}
|
|
146
162
|
}
|
|
147
|
-
return
|
|
163
|
+
return xt_ta_from_value(kind, matches, XT_UNDEFINED, XT_UNDEFINED, 0);
|
|
148
164
|
}
|
|
149
165
|
|
|
150
166
|
static xt_value xt_ta_method_every(xt_value self, xt_value env, int32_t argc, xt_value *argv) {
|
|
@@ -208,7 +224,7 @@ static xt_value xt_ta_method_reduce(xt_value self, xt_value env, int32_t argc, x
|
|
|
208
224
|
accumulator = xt_ta_element(self, 0);
|
|
209
225
|
index = 1;
|
|
210
226
|
} else {
|
|
211
|
-
xt_throw(
|
|
227
|
+
xt_throw(xt_error_from_message("TypeError: Reduce of empty array with no initial value"));
|
|
212
228
|
return XT_UNDEFINED;
|
|
213
229
|
}
|
|
214
230
|
for (; index < length; index++) {
|
package/runtime/xt_typed_array.c
CHANGED
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
2
|
* xbintsc runtime - typed arrays.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `new Uint8Array(2)[0] = 300`
|
|
8
|
-
* `Float32Array` round-trips through
|
|
9
|
-
*
|
|
10
|
-
* There is no shared `ArrayBuffer` backing store: `slice` / `subarray` return
|
|
11
|
-
* independent copies and the `.buffer` property is not exposed. That matches
|
|
12
|
-
* xbintsc's runtime, which has no distinct binary value type (strings are
|
|
13
|
-
* UTF-8 byte arrays and `Buffer` is likewise a property bag).
|
|
4
|
+
* A TypedArray is a view over an `ArrayBuffer`: its elements live in the
|
|
5
|
+
* buffer's bytes at `byteOffset`, and `length` / `byteLength` describe the
|
|
6
|
+
* window. `subarray` shares that buffer; `slice` copies into a new one.
|
|
7
|
+
* Every write is coerced to the element type, so `new Uint8Array(2)[0] = 300`
|
|
8
|
+
* stores 44 exactly like ECMAScript and a `Float32Array` round-trips through
|
|
9
|
+
* single precision.
|
|
14
10
|
*/
|
|
15
11
|
|
|
16
12
|
#include "rt_internal.h"
|
|
@@ -34,6 +30,10 @@ enum {
|
|
|
34
30
|
};
|
|
35
31
|
|
|
36
32
|
static const int xt_ta_bytes[XT_TA_KIND_COUNT] = {1, 1, 1, 2, 2, 4, 4, 4, 8};
|
|
33
|
+
static const char *const xt_ta_names[XT_TA_KIND_COUNT] = {
|
|
34
|
+
"Uint8Array", "Int8Array", "Uint8ClampedArray", "Uint16Array", "Int16Array",
|
|
35
|
+
"Uint32Array", "Int32Array", "Float32Array", "Float64Array",
|
|
36
|
+
};
|
|
37
37
|
|
|
38
38
|
static xt_value xt_ta_protos[XT_TA_KIND_COUNT];
|
|
39
39
|
|
|
@@ -42,6 +42,7 @@ static xt_value xt_ta_protos[XT_TA_KIND_COUNT];
|
|
|
42
42
|
static xt_value xt_ta_method_fill(xt_value, xt_value, int32_t, xt_value *);
|
|
43
43
|
static xt_value xt_ta_method_set(xt_value, xt_value, int32_t, xt_value *);
|
|
44
44
|
static xt_value xt_ta_method_slice(xt_value, xt_value, int32_t, xt_value *);
|
|
45
|
+
static xt_value xt_ta_method_subarray(xt_value, xt_value, int32_t, xt_value *);
|
|
45
46
|
static xt_value xt_ta_method_join(xt_value, xt_value, int32_t, xt_value *);
|
|
46
47
|
static xt_value xt_ta_method_to_string(xt_value, xt_value, int32_t, xt_value *);
|
|
47
48
|
static xt_value xt_ta_method_index_of(xt_value, xt_value, int32_t, xt_value *);
|