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
|
@@ -35,9 +35,131 @@ static xt_value xt_object_group_by(xt_value value, xt_value fn) {
|
|
|
35
35
|
return result;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
+
/* -- property descriptors ------------------------------------------------- */
|
|
39
|
+
|
|
40
|
+
/* `attr` defaults for `defineProperty` are all false; literal properties are
|
|
41
|
+
* all true. Store the bits per key under a symbol so the flag table stays out
|
|
42
|
+
* of Object.keys / JSON. Writable/enumerable are reported truthfully, but the
|
|
43
|
+
* runtime does not enforce them on later writes or enumeration yet. */
|
|
44
|
+
static xt_value xt_object_descriptor_flags_key_value = XT_UNDEFINED;
|
|
45
|
+
|
|
46
|
+
static xt_value xt_object_descriptor_flags_key(void) {
|
|
47
|
+
if (!xt_is_symbol(xt_object_descriptor_flags_key_value)) {
|
|
48
|
+
xt_object_descriptor_flags_key_value =
|
|
49
|
+
xt_symbol_new(xt_string_from_cstr("__propertyDescriptorFlags"));
|
|
50
|
+
xt_gc_add_root(&xt_object_descriptor_flags_key_value);
|
|
51
|
+
}
|
|
52
|
+
return xt_object_descriptor_flags_key_value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static xt_value xt_object_descriptor_flags(xt_value target) {
|
|
56
|
+
if (!XT_IS_OBJECT(target)) return XT_UNDEFINED;
|
|
57
|
+
xt_value flags = xt_object_get(target, xt_object_descriptor_flags_key());
|
|
58
|
+
if (!XT_IS_OBJECT(flags)) {
|
|
59
|
+
flags = xt_object_new();
|
|
60
|
+
xt_object_set(target, xt_object_descriptor_flags_key(), flags);
|
|
61
|
+
}
|
|
62
|
+
return flags;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static int xt_object_descriptor_mask(xt_value target, xt_value key) {
|
|
66
|
+
if (!XT_IS_OBJECT(target)) return 7;
|
|
67
|
+
xt_value flags = xt_object_get(target, xt_object_descriptor_flags_key());
|
|
68
|
+
if (!XT_IS_OBJECT(flags)) return 7;
|
|
69
|
+
xt_value mask = xt_object_get(flags, key);
|
|
70
|
+
return mask == XT_UNDEFINED ? 7 : xt_to_int32(mask);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static xt_value xt_object_data_descriptor(xt_value value, int enumerable, int configurable,
|
|
74
|
+
int writable) {
|
|
75
|
+
xt_value descriptor = xt_object_new();
|
|
76
|
+
xt_object_set(descriptor, xt_string_from_cstr("value"), value);
|
|
77
|
+
xt_object_set(descriptor, xt_string_from_cstr("writable"), xt_bool(writable));
|
|
78
|
+
xt_object_set(descriptor, xt_string_from_cstr("enumerable"), xt_bool(enumerable));
|
|
79
|
+
xt_object_set(descriptor, xt_string_from_cstr("configurable"), xt_bool(configurable));
|
|
80
|
+
return descriptor;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
static xt_value xt_object_get_own_property_descriptor(xt_value target, xt_value key) {
|
|
84
|
+
if (XT_IS_ARRAY(target)) {
|
|
85
|
+
if (XT_IS_STRING(key) && xt_as_string(key)->length == 6 &&
|
|
86
|
+
memcmp(xt_string_bytes(xt_as_string(key)), "length", 6) == 0) {
|
|
87
|
+
return xt_object_data_descriptor(xt_array_length(target), 0, 0, 1);
|
|
88
|
+
}
|
|
89
|
+
xt_value item = xt_get(target, key);
|
|
90
|
+
if (item != XT_UNDEFINED) return xt_object_data_descriptor(item, 1, 1, 1);
|
|
91
|
+
return XT_UNDEFINED;
|
|
92
|
+
}
|
|
93
|
+
if (!XT_IS_OBJECT(target)) return XT_UNDEFINED;
|
|
94
|
+
xt_object *object = (xt_object *)XT_GET_PTR(target);
|
|
95
|
+
if (object->header.kind != XT_OBJECT_KIND_OBJECT && object->header.kind != XT_OBJECT_KIND_ERROR) {
|
|
96
|
+
return XT_UNDEFINED;
|
|
97
|
+
}
|
|
98
|
+
xt_property *property = xt_object_find_property(object, xt_to_property_key(key));
|
|
99
|
+
if (!property) return XT_UNDEFINED;
|
|
100
|
+
int mask = xt_object_descriptor_mask(target, key);
|
|
101
|
+
if (property->getter != XT_UNDEFINED || property->setter != XT_UNDEFINED) {
|
|
102
|
+
xt_value descriptor = xt_object_new();
|
|
103
|
+
if (property->getter != XT_UNDEFINED) {
|
|
104
|
+
xt_object_set(descriptor, xt_string_from_cstr("get"), property->getter);
|
|
105
|
+
}
|
|
106
|
+
if (property->setter != XT_UNDEFINED) {
|
|
107
|
+
xt_object_set(descriptor, xt_string_from_cstr("set"), property->setter);
|
|
108
|
+
}
|
|
109
|
+
xt_object_set(descriptor, xt_string_from_cstr("enumerable"), xt_bool((mask & 2) != 0));
|
|
110
|
+
xt_object_set(descriptor, xt_string_from_cstr("configurable"), xt_bool((mask & 4) != 0));
|
|
111
|
+
return descriptor;
|
|
112
|
+
}
|
|
113
|
+
return xt_object_data_descriptor(property->value, (mask & 2) != 0, (mask & 4) != 0,
|
|
114
|
+
(mask & 1) != 0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
static xt_value xt_object_define_property(xt_value target, xt_value key, xt_value descriptor) {
|
|
118
|
+
if (!XT_IS_OBJECT(descriptor)) return target;
|
|
119
|
+
int writable = xt_truthy(xt_object_get(descriptor, xt_string_from_cstr("writable")));
|
|
120
|
+
int enumerable = xt_truthy(xt_object_get(descriptor, xt_string_from_cstr("enumerable")));
|
|
121
|
+
int configurable = xt_truthy(xt_object_get(descriptor, xt_string_from_cstr("configurable")));
|
|
122
|
+
int mask = (writable ? 1 : 0) | (enumerable ? 2 : 0) | (configurable ? 4 : 0);
|
|
123
|
+
xt_value flags = xt_object_descriptor_flags(target);
|
|
124
|
+
if (XT_IS_OBJECT(flags)) xt_object_set(flags, key, xt_number((double)mask));
|
|
125
|
+
xt_value getter = xt_object_get(descriptor, xt_string_from_cstr("get"));
|
|
126
|
+
xt_value setter = xt_object_get(descriptor, xt_string_from_cstr("set"));
|
|
127
|
+
if (getter != XT_UNDEFINED || setter != XT_UNDEFINED) {
|
|
128
|
+
if (getter != XT_UNDEFINED) xt_object_define_getter(target, key, getter);
|
|
129
|
+
if (setter != XT_UNDEFINED) xt_object_define_setter(target, key, setter);
|
|
130
|
+
return target;
|
|
131
|
+
}
|
|
132
|
+
if (xt_object_has_own(descriptor, xt_string_from_cstr("value"))) {
|
|
133
|
+
xt_set(target, key, xt_object_get(descriptor, xt_string_from_cstr("value")));
|
|
134
|
+
}
|
|
135
|
+
return target;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
static xt_value xt_object_get_own_property_descriptors(xt_value target) {
|
|
139
|
+
xt_value result = xt_object_new();
|
|
140
|
+
xt_value names = xt_object_own_property_names(target);
|
|
141
|
+
xt_array *keys = xt_as_array(names);
|
|
142
|
+
if (!keys) return result;
|
|
143
|
+
for (uint32_t i = 0; i < keys->length; i++) {
|
|
144
|
+
xt_value descriptor = xt_object_get_own_property_descriptor(target, keys->items[i]);
|
|
145
|
+
if (descriptor != XT_UNDEFINED) xt_object_set(result, keys->items[i], descriptor);
|
|
146
|
+
}
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
|
|
38
150
|
xt_value xt_object_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
39
151
|
const char *fn = xt_string_data(name);
|
|
40
152
|
if (!fn) return XT_UNDEFINED;
|
|
153
|
+
if (strcmp(fn, "getOwnPropertyDescriptor") == 0) {
|
|
154
|
+
return xt_object_get_own_property_descriptor(xt_arg_at(argc, argv, 0), xt_arg_at(argc, argv, 1));
|
|
155
|
+
}
|
|
156
|
+
if (strcmp(fn, "getOwnPropertyDescriptors") == 0) {
|
|
157
|
+
return xt_object_get_own_property_descriptors(xt_arg_at(argc, argv, 0));
|
|
158
|
+
}
|
|
159
|
+
if (strcmp(fn, "defineProperty") == 0) {
|
|
160
|
+
return xt_object_define_property(xt_arg_at(argc, argv, 0), xt_arg_at(argc, argv, 1),
|
|
161
|
+
xt_arg_at(argc, argv, 2));
|
|
162
|
+
}
|
|
41
163
|
if (strcmp(fn, "keys") == 0) return xt_object_keys(xt_arg_at(argc, argv, 0));
|
|
42
164
|
if (strcmp(fn, "getOwnPropertyNames") == 0) return xt_object_own_property_names(xt_arg_at(argc, argv, 0));
|
|
43
165
|
if (strcmp(fn, "getOwnPropertySymbols") == 0) return xt_object_own_property_symbols(xt_arg_at(argc, argv, 0));
|
|
@@ -64,7 +186,7 @@ xt_value xt_object_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
|
64
186
|
}
|
|
65
187
|
if (strcmp(fn, "create") == 0) {
|
|
66
188
|
xt_value proto = xt_arg_at(argc, argv, 0);
|
|
67
|
-
return xt_object_new_with_proto(proto == XT_NULL ?
|
|
189
|
+
return xt_object_new_with_proto(proto == XT_NULL ? XT_NULL : proto);
|
|
68
190
|
}
|
|
69
191
|
return XT_UNDEFINED;
|
|
70
192
|
}
|
|
@@ -203,7 +203,7 @@ xt_value xt_regexp_exec(xt_value target, xt_value input) {
|
|
|
203
203
|
}
|
|
204
204
|
xt_array_push(out, groupValue);
|
|
205
205
|
}
|
|
206
|
-
xt_set(out, xt_string_from_cstr("index"), xt_number((double)matches[0].rm_so));
|
|
206
|
+
xt_set(out, xt_string_from_cstr("index"), xt_number((double)xt_string_unit_offset(text, matches[0].rm_so)));
|
|
207
207
|
xt_set(out, xt_string_from_cstr("input"), textValue);
|
|
208
208
|
xt_set(out, xt_string_from_cstr("groups"), XT_UNDEFINED);
|
|
209
209
|
free(matches);
|
|
@@ -351,7 +351,7 @@ xt_value xt_regexp_replace(xt_value value, xt_value regexpValue, xt_value replac
|
|
|
351
351
|
}
|
|
352
352
|
xt_array_push(argArray, groupValue);
|
|
353
353
|
}
|
|
354
|
-
xt_array_push(argArray, xt_number((double)start));
|
|
354
|
+
xt_array_push(argArray, xt_number((double)xt_string_unit_offset(text, start)));
|
|
355
355
|
xt_array_push(argArray, xt_to_string(value));
|
|
356
356
|
xt_value produced = xt_closure_call(replacementValue, jsTotal + 3, xt_as_array(argArray)->items);
|
|
357
357
|
xt_string *producedText = xt_as_string(xt_to_string(produced));
|
|
@@ -17,6 +17,8 @@ int32_t xt_set_size(xt_value value) {
|
|
|
17
17
|
xt_value xt_iter_length(xt_value value) {
|
|
18
18
|
if (xt_is_map(value)) return xt_number((double)xt_map_size(value));
|
|
19
19
|
if (xt_is_set(value)) return xt_number((double)xt_set_size(value));
|
|
20
|
+
/* Strings iterate by code point, not by UTF-16 unit. */
|
|
21
|
+
if (XT_IS_STRING(value)) return xt_number((double)xt_string_code_point_count(xt_as_string(value)));
|
|
20
22
|
return xt_array_length(value);
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -53,7 +55,7 @@ xt_value xt_iter_open(xt_value value) {
|
|
|
53
55
|
return XT_FROM_PTR(XT_TAG_OBJECT, state);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
|
-
xt_throw(
|
|
58
|
+
xt_throw(xt_error_from_message("TypeError: value is not iterable"));
|
|
57
59
|
return XT_UNDEFINED;
|
|
58
60
|
}
|
|
59
61
|
|
|
@@ -70,12 +72,16 @@ xt_value xt_iter_has(xt_value value, xt_value index) {
|
|
|
70
72
|
if (xt_is_generator(value)) return xt_bool(xt_generator_has_next(value));
|
|
71
73
|
if (xt_is_map(value)) return xt_bool(xt_to_int32(index) < xt_map_size(value));
|
|
72
74
|
if (xt_is_set(value)) return xt_bool(xt_to_int32(index) < xt_set_size(value));
|
|
75
|
+
if (XT_IS_STRING(value))
|
|
76
|
+
return xt_bool(xt_to_int32(index) <
|
|
77
|
+
(int32_t)xt_string_code_point_count(xt_as_string(value)));
|
|
73
78
|
return xt_bool(xt_to_int32(index) < xt_to_int32(xt_array_length(value)));
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
xt_value xt_iter_value(xt_value value, xt_value index) {
|
|
77
82
|
if (xt_is_iterator_state(value)) return ((xt_iterator_state *)XT_GET_PTR(value))->cached;
|
|
78
83
|
if (xt_is_generator(value)) return xt_generator_iter_value(value);
|
|
84
|
+
if (XT_IS_STRING(value)) return xt_string_code_point_value(xt_as_string(value), xt_to_int32(index));
|
|
79
85
|
if (xt_is_map(value)) {
|
|
80
86
|
xt_map *map = (xt_map *)XT_GET_PTR(value);
|
|
81
87
|
int64_t i = (int64_t)xt_to_int32(index);
|
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
/* -- string methods ------------------------------------------------------- */
|
|
2
2
|
|
|
3
|
+
/* `padStart`/`padEnd` measure the target length in UTF-16 code units and may
|
|
4
|
+
* cut the pad string through a surrogate pair. */
|
|
3
5
|
static xt_value xt_string_pad(xt_value value, xt_value lengthValue, xt_value padValue, int start) {
|
|
4
6
|
xt_string *s = xt_as_string(value);
|
|
5
7
|
if (!s) return value;
|
|
6
8
|
int32_t target = xt_to_int32(lengthValue);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
int32_t units = (int32_t)xt_string_utf16_length(s);
|
|
10
|
+
if (target <= units) return value;
|
|
11
|
+
xt_value padSymbol = padValue == XT_UNDEFINED ? xt_string_from_cstr(" ") : padValue;
|
|
12
|
+
xt_string *pad = xt_as_string(xt_to_string(padSymbol));
|
|
9
13
|
if (!pad || pad->length == 0) return value;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
memcpy(mutable, text, s->length);
|
|
21
|
-
for (size_t i = 0; i < needed; i++) mutable[s->length + i] = padBytes[i % pad->length];
|
|
14
|
+
int32_t padUnits = (int32_t)xt_string_utf16_length(pad);
|
|
15
|
+
if (padUnits <= 0) return value;
|
|
16
|
+
uint32_t needed = (uint32_t)(target - units);
|
|
17
|
+
xt_value padding = xt_string_from_cstr("");
|
|
18
|
+
uint32_t filled = 0;
|
|
19
|
+
while (filled < needed) {
|
|
20
|
+
uint32_t remaining = needed - filled;
|
|
21
|
+
int32_t chunk = remaining < (uint32_t)padUnits ? (int32_t)remaining : padUnits;
|
|
22
|
+
padding = xt_add(padding, xt_string_slice_units(pad, 0, chunk));
|
|
23
|
+
filled += (uint32_t)chunk;
|
|
22
24
|
}
|
|
23
|
-
return
|
|
25
|
+
return start ? xt_add(padding, value) : xt_add(value, padding);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
28
|
static xt_value xt_string_trim_side(xt_value value, int start) {
|
|
@@ -37,10 +39,11 @@ static xt_value xt_string_trim_side(xt_value value, int start) {
|
|
|
37
39
|
static xt_value xt_string_at(xt_value value, xt_value indexValue) {
|
|
38
40
|
xt_string *s = xt_as_string(value);
|
|
39
41
|
if (!s) return XT_UNDEFINED;
|
|
42
|
+
int32_t units = (int32_t)xt_string_utf16_length(s);
|
|
40
43
|
int32_t index = indexValue == XT_UNDEFINED ? 0 : xt_to_int32(indexValue);
|
|
41
|
-
if (index < 0) index +=
|
|
42
|
-
if (index < 0 ||
|
|
43
|
-
return
|
|
44
|
+
if (index < 0) index += units;
|
|
45
|
+
if (index < 0 || index >= units) return XT_UNDEFINED;
|
|
46
|
+
return xt_string_unit_value(s, index);
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
static xt_value xt_string_replace_all(xt_value value, xt_value searchValue, xt_value replacementValue) {
|
|
@@ -49,7 +52,18 @@ static xt_value xt_string_replace_all(xt_value value, xt_value searchValue, xt_v
|
|
|
49
52
|
if (!s) return value;
|
|
50
53
|
xt_string *search = xt_as_string(xt_to_string(searchValue));
|
|
51
54
|
xt_string *replacement = xt_as_string(xt_to_string(replacementValue));
|
|
52
|
-
if (!search || search->length == 0)
|
|
55
|
+
if (!search || search->length == 0) {
|
|
56
|
+
/* An empty search inserts the replacement before every UTF-16 code unit
|
|
57
|
+
* and once at the end. */
|
|
58
|
+
int32_t units = (int32_t)xt_string_utf16_length(s);
|
|
59
|
+
xt_value replacementText = xt_to_string(replacementValue);
|
|
60
|
+
xt_value result = replacementText;
|
|
61
|
+
for (int32_t i = 0; i < units; i++) {
|
|
62
|
+
result = xt_add(result, xt_string_unit_value(s, i));
|
|
63
|
+
result = xt_add(result, replacementText);
|
|
64
|
+
}
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
53
67
|
const char *text = xt_string_bytes(s);
|
|
54
68
|
const char *needle = xt_string_bytes(search);
|
|
55
69
|
const char *repl = xt_string_bytes(replacement);
|
|
@@ -74,6 +88,33 @@ static xt_value xt_string_replace_all(xt_value value, xt_value searchValue, xt_v
|
|
|
74
88
|
return result;
|
|
75
89
|
}
|
|
76
90
|
|
|
91
|
+
/* `limit` is a UTF-16 index; the last possible match starts at or before it. */
|
|
92
|
+
static xt_value xt_string_last_index_of(xt_string *s, xt_string *needle, int32_t limit) {
|
|
93
|
+
if (!s || !needle) return xt_number(-1);
|
|
94
|
+
const char *text = xt_string_bytes(s);
|
|
95
|
+
const char *need = xt_string_bytes(needle);
|
|
96
|
+
int32_t units = (int32_t)xt_string_utf16_length(s);
|
|
97
|
+
if (limit < 0) limit = 0;
|
|
98
|
+
if (limit > units) limit = units;
|
|
99
|
+
if (needle->length == 0) return xt_number((double)limit);
|
|
100
|
+
/* The low half of a surrogate pair is a match candidate of its own, but a
|
|
101
|
+
* byte search from the pair start cannot see it. */
|
|
102
|
+
if (!xt_string_is_boundary(s, limit)) {
|
|
103
|
+
xt_string *tail = xt_as_string(xt_string_slice_units(s, limit, units));
|
|
104
|
+
if (needle->length <= tail->length &&
|
|
105
|
+
memcmp(xt_string_bytes(tail), need, needle->length) == 0)
|
|
106
|
+
return xt_number((double)limit);
|
|
107
|
+
}
|
|
108
|
+
if (needle->length > s->length) return xt_number(-1);
|
|
109
|
+
int32_t i = xt_string_byte_offset(s, limit);
|
|
110
|
+
if (i > (int32_t)s->length - (int32_t)needle->length) i = (int32_t)s->length - (int32_t)needle->length;
|
|
111
|
+
for (; i >= 0; i--) {
|
|
112
|
+
if (((unsigned char)text[i] & 0xC0) == 0x80) continue; /* not a code-point boundary */
|
|
113
|
+
if (memcmp(text + i, need, needle->length) == 0) return xt_number((double)xt_string_unit_offset(s, i));
|
|
114
|
+
}
|
|
115
|
+
return xt_number(-1);
|
|
116
|
+
}
|
|
117
|
+
|
|
77
118
|
xt_value xt_ext_string_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled) {
|
|
78
119
|
*handled = 1;
|
|
79
120
|
if (strcmp(method, "at") == 0) return xt_string_at(target, xt_arg_at(argc, argv, 0));
|
|
@@ -93,34 +134,22 @@ xt_value xt_ext_string_method(xt_value target, const char *method, int32_t argc,
|
|
|
93
134
|
xt_value regexp = xt_arg_at(argc, argv, 0);
|
|
94
135
|
if (xt_is_regexp(regexp)) {
|
|
95
136
|
int32_t start = 0;
|
|
96
|
-
if (xt_regexp_find(regexp, target, 0, &start, NULL))
|
|
137
|
+
if (xt_regexp_find(regexp, target, 0, &start, NULL)) {
|
|
138
|
+
xt_string *text = xt_as_string(xt_to_string(target));
|
|
139
|
+
return xt_number((double)xt_string_unit_offset(text, start));
|
|
140
|
+
}
|
|
97
141
|
return xt_number(-1);
|
|
98
142
|
}
|
|
99
143
|
*handled = 0;
|
|
100
144
|
return XT_UNDEFINED;
|
|
101
145
|
}
|
|
102
|
-
if (strcmp(method, "replaceAll") == 0) {
|
|
103
|
-
xt_value searchValue = xt_arg_at(argc, argv, 0);
|
|
104
|
-
if (xt_is_regexp(searchValue)) return xt_regexp_replace(target, searchValue, xt_arg_at(argc, argv, 1));
|
|
105
|
-
*handled = 0;
|
|
106
|
-
return XT_UNDEFINED;
|
|
107
|
-
}
|
|
108
146
|
if (strcmp(method, "lastIndexOf") == 0) {
|
|
109
147
|
xt_string *s = xt_as_string(target);
|
|
110
148
|
xt_string *needle = xt_as_string(xt_to_string(xt_arg_at(argc, argv, 0)));
|
|
111
149
|
if (!s || !needle) return xt_number(-1);
|
|
112
|
-
int32_t limit = (argc >= 2 && argv[1] != XT_UNDEFINED) ? xt_to_int32(argv[1])
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
if (nlen == 0) return xt_number((double)(limit < 0 ? 0 : limit));
|
|
116
|
-
const char *text = xt_string_bytes(s);
|
|
117
|
-
const char *need = xt_string_bytes(needle);
|
|
118
|
-
int32_t i = limit;
|
|
119
|
-
if (i > (int32_t)s->length - nlen) i = (int32_t)s->length - nlen;
|
|
120
|
-
for (; i >= 0; i--) {
|
|
121
|
-
if (memcmp(text + i, need, (size_t)nlen) == 0) return xt_number((double)i);
|
|
122
|
-
}
|
|
123
|
-
return xt_number(-1);
|
|
150
|
+
int32_t limit = (argc >= 2 && argv[1] != XT_UNDEFINED) ? xt_to_int32(argv[1])
|
|
151
|
+
: (int32_t)xt_string_utf16_length(s);
|
|
152
|
+
return xt_string_last_index_of(s, needle, limit);
|
|
124
153
|
}
|
|
125
154
|
if (strcmp(method, "localeCompare") == 0) {
|
|
126
155
|
xt_string *a = xt_as_string(target);
|
|
@@ -132,8 +161,9 @@ xt_value xt_ext_string_method(xt_value target, const char *method, int32_t argc,
|
|
|
132
161
|
xt_string *s = xt_as_string(target);
|
|
133
162
|
if (!s) return XT_UNDEFINED;
|
|
134
163
|
int32_t index = xt_to_int32(xt_arg_at(argc, argv, 0));
|
|
135
|
-
|
|
136
|
-
|
|
164
|
+
int32_t code = xt_string_code_point_at(s, index);
|
|
165
|
+
if (code < 0) return XT_UNDEFINED;
|
|
166
|
+
return xt_number((double)code);
|
|
137
167
|
}
|
|
138
168
|
if (strcmp(method, "valueOf") == 0 || strcmp(method, "toString") == 0) return target;
|
|
139
169
|
*handled = 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
|
+
}
|