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
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — `structuredClone`.
|
|
3
|
+
*
|
|
4
|
+
* Deep-clones arrays, plain objects, Map, Set, Date, RegExp and typed arrays,
|
|
5
|
+
* preserving shared references and cycles. Functions, symbols, promises,
|
|
6
|
+
* generators and iterators cannot be cloned, matching the platform API.
|
|
7
|
+
*
|
|
8
|
+
* The clone table maps source pointer -> clone. It lives on the C stack for
|
|
9
|
+
* the duration of the call; every clone is also reachable from its parent (or
|
|
10
|
+
* the current frame) while it is being filled, so the conservative stack scan
|
|
11
|
+
* keeps it alive across the allocations that happen during cloning.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
#include "rt_internal.h"
|
|
15
|
+
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
#include <stdlib.h>
|
|
18
|
+
#include <string.h>
|
|
19
|
+
|
|
20
|
+
typedef struct {
|
|
21
|
+
xt_value source;
|
|
22
|
+
xt_value clone;
|
|
23
|
+
} xt_clone_entry;
|
|
24
|
+
|
|
25
|
+
typedef struct {
|
|
26
|
+
xt_clone_entry *entries;
|
|
27
|
+
uint32_t count;
|
|
28
|
+
uint32_t capacity;
|
|
29
|
+
} xt_clone_context;
|
|
30
|
+
|
|
31
|
+
static _Noreturn void xt_clone_fail(const char *kind) {
|
|
32
|
+
char message[160];
|
|
33
|
+
snprintf(message, sizeof(message), "%s could not be cloned.", kind);
|
|
34
|
+
xt_value argument = xt_string_from_cstr(message);
|
|
35
|
+
xt_throw(xt_type_error_ctor(1, &argument));
|
|
36
|
+
abort();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
static xt_value xt_clone_lookup(xt_clone_context *context, xt_value source) {
|
|
40
|
+
for (uint32_t i = 0; i < context->count; i++) {
|
|
41
|
+
if (context->entries[i].source == source) return context->entries[i].clone;
|
|
42
|
+
}
|
|
43
|
+
return XT_UNDEFINED;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
static void xt_clone_remember(xt_clone_context *context, xt_value source, xt_value clone) {
|
|
47
|
+
if (context->count >= context->capacity) {
|
|
48
|
+
uint32_t capacity = context->capacity == 0 ? 8 : context->capacity * 2;
|
|
49
|
+
xt_clone_entry *entries =
|
|
50
|
+
(xt_clone_entry *)realloc(context->entries, sizeof(xt_clone_entry) * capacity);
|
|
51
|
+
if (!entries) abort();
|
|
52
|
+
context->entries = entries;
|
|
53
|
+
context->capacity = capacity;
|
|
54
|
+
}
|
|
55
|
+
context->entries[context->count].source = source;
|
|
56
|
+
context->entries[context->count].clone = clone;
|
|
57
|
+
context->count++;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
static xt_value xt_clone_value(xt_clone_context *context, xt_value value) {
|
|
61
|
+
if (value == XT_UNDEFINED || value == XT_NULL || XT_IS_BOOL(value) || XT_IS_NUMBER(value) ||
|
|
62
|
+
XT_IS_STRING(value) || XT_IS_BIGINT(value)) {
|
|
63
|
+
return value;
|
|
64
|
+
}
|
|
65
|
+
if (XT_IS_FUNCTION(value)) xt_clone_fail("function");
|
|
66
|
+
if (xt_is_symbol(value)) xt_clone_fail("symbol");
|
|
67
|
+
|
|
68
|
+
xt_value existing = xt_clone_lookup(context, value);
|
|
69
|
+
if (existing != XT_UNDEFINED) return existing;
|
|
70
|
+
|
|
71
|
+
/* A typed array's own `slice` already produces an element-wise copy of the
|
|
72
|
+
* same concrete type. */
|
|
73
|
+
if (xt_typed_array_kind_of(value) >= 0) {
|
|
74
|
+
return xt_call_method(value, xt_string_from_cstr("slice"), 0, NULL);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (XT_IS_ARRAY(value)) {
|
|
78
|
+
xt_value clone = xt_array_new(0, NULL);
|
|
79
|
+
xt_clone_remember(context, value, clone);
|
|
80
|
+
xt_array *array = xt_as_array(value);
|
|
81
|
+
for (uint32_t i = 0; i < array->length; i++) {
|
|
82
|
+
xt_array_push(clone, xt_clone_value(context, array->items[i]));
|
|
83
|
+
}
|
|
84
|
+
return clone;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (!XT_IS_OBJECT(value)) xt_clone_fail("value");
|
|
88
|
+
xt_object *object = (xt_object *)XT_GET_PTR(value);
|
|
89
|
+
|
|
90
|
+
if (object->header.kind == XT_OBJECT_KIND_MAP) {
|
|
91
|
+
xt_map *map = (xt_map *)object;
|
|
92
|
+
xt_value clone = xt_map_ctor(0, NULL);
|
|
93
|
+
xt_clone_remember(context, value, clone);
|
|
94
|
+
for (uint32_t i = 0; i < map->count; i++) {
|
|
95
|
+
xt_value args[2] = {xt_clone_value(context, map->keys[i]),
|
|
96
|
+
xt_clone_value(context, map->values[i])};
|
|
97
|
+
xt_call_method(clone, xt_string_from_cstr("set"), 2, args);
|
|
98
|
+
}
|
|
99
|
+
return clone;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (object->header.kind == XT_OBJECT_KIND_SET) {
|
|
103
|
+
xt_set_object *set = (xt_set_object *)object;
|
|
104
|
+
xt_value clone = xt_set_ctor(0, NULL);
|
|
105
|
+
xt_clone_remember(context, value, clone);
|
|
106
|
+
for (uint32_t i = 0; i < set->count; i++) {
|
|
107
|
+
xt_value args[1] = {xt_clone_value(context, set->values[i])};
|
|
108
|
+
xt_call_method(clone, xt_string_from_cstr("add"), 1, args);
|
|
109
|
+
}
|
|
110
|
+
return clone;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (object->header.kind == XT_OBJECT_KIND_DATE) {
|
|
114
|
+
xt_value time = xt_call_method(value, xt_string_from_cstr("getTime"), 0, NULL);
|
|
115
|
+
xt_value clone = xt_date_ctor(1, &time);
|
|
116
|
+
xt_clone_remember(context, value, clone);
|
|
117
|
+
return clone;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (object->header.kind == XT_OBJECT_KIND_REGEXP) {
|
|
121
|
+
xt_value args[2] = {xt_get(value, xt_string_from_cstr("source")),
|
|
122
|
+
xt_get(value, xt_string_from_cstr("flags"))};
|
|
123
|
+
xt_value clone = xt_regexp_ctor(2, args);
|
|
124
|
+
xt_clone_remember(context, value, clone);
|
|
125
|
+
return clone;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (object->header.kind == XT_OBJECT_KIND_PROMISE) xt_clone_fail("Promise");
|
|
129
|
+
if (object->header.kind == XT_OBJECT_KIND_WEAK_MAP) xt_clone_fail("WeakMap");
|
|
130
|
+
if (object->header.kind == XT_OBJECT_KIND_WEAK_SET) xt_clone_fail("WeakSet");
|
|
131
|
+
if (object->header.kind == XT_OBJECT_KIND_WEAK_REF) xt_clone_fail("WeakRef");
|
|
132
|
+
if (object->header.kind == XT_OBJECT_KIND_GENERATOR) xt_clone_fail("generator");
|
|
133
|
+
if (object->header.kind == XT_OBJECT_KIND_ITERATOR) xt_clone_fail("iterator");
|
|
134
|
+
if (object->header.kind == XT_OBJECT_KIND_ASYNC) xt_clone_fail("async function");
|
|
135
|
+
|
|
136
|
+
/* Plain objects and Errors are cloned as data: own enumerable string keys,
|
|
137
|
+
* no prototype. That is what the platform algorithm does for ordinary
|
|
138
|
+
* objects and class instances. */
|
|
139
|
+
if (object->header.kind != XT_OBJECT_KIND_OBJECT && object->header.kind != XT_OBJECT_KIND_ERROR) {
|
|
140
|
+
xt_clone_fail("value");
|
|
141
|
+
}
|
|
142
|
+
xt_value clone = xt_object_new();
|
|
143
|
+
xt_clone_remember(context, value, clone);
|
|
144
|
+
xt_value keys = xt_object_keys(value);
|
|
145
|
+
xt_array *keyArray = xt_as_array(keys);
|
|
146
|
+
if (!keyArray) return clone;
|
|
147
|
+
for (uint32_t i = 0; i < keyArray->length; i++) {
|
|
148
|
+
xt_value key = keyArray->items[i];
|
|
149
|
+
xt_object_set(clone, key, xt_clone_value(context, xt_object_get(value, key)));
|
|
150
|
+
}
|
|
151
|
+
return clone;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
xt_value xt_structured_clone(int32_t argc, xt_value *argv) {
|
|
155
|
+
xt_clone_context context = {NULL, 0, 0};
|
|
156
|
+
xt_value clone = xt_clone_value(&context, xt_arg_at(argc, argv, 0));
|
|
157
|
+
free(context.entries);
|
|
158
|
+
return clone;
|
|
159
|
+
}
|
package/runtime/xt_symbol.c
CHANGED
|
@@ -89,7 +89,7 @@ xt_value xt_symbol_description(xt_value value) {
|
|
|
89
89
|
xt_value xt_symbol_to_string(xt_value value) {
|
|
90
90
|
xt_symbol_data *symbol = xt_as_symbol(value);
|
|
91
91
|
if (!symbol) {
|
|
92
|
-
xt_throw(
|
|
92
|
+
xt_throw(xt_error_from_message(
|
|
93
93
|
"TypeError: Symbol.prototype.toString requires that 'this' be a Symbol"));
|
|
94
94
|
}
|
|
95
95
|
xt_string *description =
|
|
@@ -129,7 +129,7 @@ xt_value xt_symbol_for(xt_value key) {
|
|
|
129
129
|
|
|
130
130
|
xt_value xt_symbol_key_for(xt_value value) {
|
|
131
131
|
if (!xt_is_symbol(value)) {
|
|
132
|
-
xt_throw(
|
|
132
|
+
xt_throw(xt_error_from_message("TypeError: Symbol.keyFor requires a symbol"));
|
|
133
133
|
}
|
|
134
134
|
if (g_symbol_registry == XT_UNDEFINED) return XT_UNDEFINED;
|
|
135
135
|
xt_value keys = xt_object_keys(g_symbol_registry);
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — TextEncoder / TextDecoder.
|
|
3
|
+
*
|
|
4
|
+
* Strings are stored as UTF-8 (lone surrogate halves as WTF-8), so encoding is
|
|
5
|
+
* a byte copy and decoding is a byte copy back. The constructors return plain
|
|
6
|
+
* objects holding the method closures, which is the same shape the rest of the
|
|
7
|
+
* runtime uses for first-class methods.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "rt_internal.h"
|
|
11
|
+
|
|
12
|
+
#include <stdlib.h>
|
|
13
|
+
|
|
14
|
+
static xt_value xt_text_encoder_encode(xt_value thisValue, xt_value env, int32_t argc,
|
|
15
|
+
xt_value *argv) {
|
|
16
|
+
(void)thisValue;
|
|
17
|
+
(void)env;
|
|
18
|
+
xt_value input = xt_arg_at(argc, argv, 0);
|
|
19
|
+
/* `encode()` with no argument encodes the empty string, like the web API. */
|
|
20
|
+
xt_value text = input == XT_UNDEFINED ? xt_string_from_cstr("") : xt_to_string(input);
|
|
21
|
+
xt_string *string = xt_as_string(text);
|
|
22
|
+
const char *bytes = xt_string_bytes(string);
|
|
23
|
+
xt_value length = xt_number((double)string->length);
|
|
24
|
+
xt_value array = xt_typed_array_ctor_by_name(xt_string_from_cstr("Uint8Array"), 1, &length);
|
|
25
|
+
for (uint32_t i = 0; i < string->length; i++) {
|
|
26
|
+
xt_set(array, xt_number((double)i), xt_number((double)(unsigned char)bytes[i]));
|
|
27
|
+
}
|
|
28
|
+
return array;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static xt_value xt_text_decoder_decode(xt_value thisValue, xt_value env, int32_t argc,
|
|
32
|
+
xt_value *argv) {
|
|
33
|
+
(void)thisValue;
|
|
34
|
+
(void)env;
|
|
35
|
+
xt_value input = xt_arg_at(argc, argv, 0);
|
|
36
|
+
if (input == XT_UNDEFINED) return xt_string_from_cstr("");
|
|
37
|
+
uint32_t length = (uint32_t)xt_to_number(xt_get(input, xt_string_from_cstr("length")));
|
|
38
|
+
char *bytes = (char *)malloc(length == 0 ? 1 : length);
|
|
39
|
+
if (!bytes) abort();
|
|
40
|
+
for (uint32_t i = 0; i < length; i++) {
|
|
41
|
+
double byte = xt_to_number(xt_get(input, xt_number((double)i)));
|
|
42
|
+
bytes[i] = (char)((int)byte & 0xff);
|
|
43
|
+
}
|
|
44
|
+
xt_value result = xt_string_new(bytes, length);
|
|
45
|
+
free(bytes);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
xt_value xt_text_encoder_ctor(int32_t argc, xt_value *argv) {
|
|
50
|
+
(void)argc;
|
|
51
|
+
(void)argv;
|
|
52
|
+
xt_value encoder = xt_object_new();
|
|
53
|
+
xt_object_set(encoder, xt_string_from_cstr("encode"),
|
|
54
|
+
xt_closure_new((void *)xt_text_encoder_encode, 0, NULL));
|
|
55
|
+
xt_object_set(encoder, xt_string_from_cstr("encoding"), xt_string_from_cstr("utf-8"));
|
|
56
|
+
return encoder;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
xt_value xt_text_decoder_ctor(int32_t argc, xt_value *argv) {
|
|
60
|
+
(void)argv;
|
|
61
|
+
xt_value decoder = xt_object_new();
|
|
62
|
+
xt_object_set(decoder, xt_string_from_cstr("decode"),
|
|
63
|
+
xt_closure_new((void *)xt_text_decoder_decode, 0, NULL));
|
|
64
|
+
/* The only supported encoding is UTF-8; report the canonical label even when
|
|
65
|
+
* the caller passed "utf8" (as TextDecoder does). */
|
|
66
|
+
(void)argc;
|
|
67
|
+
xt_object_set(decoder, xt_string_from_cstr("encoding"), xt_string_from_cstr("utf-8"));
|
|
68
|
+
return decoder;
|
|
69
|
+
}
|
|
@@ -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);
|
|
@@ -50,15 +50,23 @@ static xt_value xt_ta_proto(int kind) {
|
|
|
50
50
|
return proto;
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
static xt_value
|
|
53
|
+
static xt_value xt_ta_view(int kind, xt_value buffer, uint32_t byteOffset, uint32_t length) {
|
|
54
54
|
xt_value array = xt_object_new_with_proto(xt_ta_proto(kind));
|
|
55
55
|
xt_object_set(array, xt_string_from_cstr("length"), xt_number((double)length));
|
|
56
|
-
xt_object_set(array, xt_string_from_cstr("byteLength"),
|
|
57
|
-
|
|
58
|
-
|
|
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));
|
|
59
61
|
return array;
|
|
60
62
|
}
|
|
61
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
|
+
|
|
62
70
|
/* Length of any value a typed array can be built from, or 0 when it is not
|
|
63
71
|
* array-like (strings/iterables are intentionally not treated as element
|
|
64
72
|
* sources yet). */
|
|
@@ -106,6 +114,28 @@ static xt_value xt_ta_from_value(int kind, xt_value value, xt_value mapFn, xt_va
|
|
|
106
114
|
static xt_value xt_ta_ctor_impl(int kind, int32_t argc, xt_value *argv) {
|
|
107
115
|
if (argc == 0) return xt_ta_new(kind, 0);
|
|
108
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
|
+
}
|
|
109
139
|
/* Objects (arrays / typed arrays / array-likes / iterables) are copied
|
|
110
140
|
* element-wise; every other argument is a length via `ToIndex`. */
|
|
111
141
|
if (XT_IS_ARRAY(argument) || XT_IS_OBJECT(argument)) {
|
|
@@ -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"
|
|
@@ -46,6 +42,7 @@ static xt_value xt_ta_protos[XT_TA_KIND_COUNT];
|
|
|
46
42
|
static xt_value xt_ta_method_fill(xt_value, xt_value, int32_t, xt_value *);
|
|
47
43
|
static xt_value xt_ta_method_set(xt_value, xt_value, int32_t, xt_value *);
|
|
48
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 *);
|
|
49
46
|
static xt_value xt_ta_method_join(xt_value, xt_value, int32_t, xt_value *);
|
|
50
47
|
static xt_value xt_ta_method_to_string(xt_value, xt_value, int32_t, xt_value *);
|
|
51
48
|
static xt_value xt_ta_method_index_of(xt_value, xt_value, int32_t, xt_value *);
|