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
package/runtime/xt_promise.c
CHANGED
|
@@ -199,6 +199,23 @@ void xt_drain_microtasks(void) {
|
|
|
199
199
|
|
|
200
200
|
xt_value xt_promise_create(void) { return xt_promise_value(xt_promise_new()); }
|
|
201
201
|
|
|
202
|
+
/* Queue a microtask that resumes a suspended async coroutine with an already
|
|
203
|
+
* settled value. Reusing a reaction keeps FIFO order with pending `.then`
|
|
204
|
+
* callbacks (the specification always yields once per `await`). */
|
|
205
|
+
void xt_promise_queue_async_wake(void *asyncPointer, xt_value settled, int rejected) {
|
|
206
|
+
xt_promise *promise = xt_promise_new();
|
|
207
|
+
promise->state = rejected ? XT_PROMISE_REJECTED : XT_PROMISE_FULFILLED;
|
|
208
|
+
promise->value = settled;
|
|
209
|
+
xt_reaction *reaction = (xt_reaction *)malloc(sizeof(xt_reaction));
|
|
210
|
+
if (!reaction) abort();
|
|
211
|
+
reaction->promise = promise;
|
|
212
|
+
reaction->on_fulfilled = XT_UNDEFINED;
|
|
213
|
+
reaction->on_rejected = XT_UNDEFINED;
|
|
214
|
+
reaction->result = NULL;
|
|
215
|
+
reaction->async = asyncPointer;
|
|
216
|
+
xt_microtask_push(reaction);
|
|
217
|
+
}
|
|
218
|
+
|
|
202
219
|
void xt_promise_fulfill(xt_value promise, xt_value value) {
|
|
203
220
|
xt_promise *target = xt_as_promise(promise);
|
|
204
221
|
if (target) xt_promise_resolve_into(target, value);
|
|
@@ -287,9 +304,34 @@ xt_value xt_promise_reject(xt_value value) {
|
|
|
287
304
|
return xt_promise_value(promise);
|
|
288
305
|
}
|
|
289
306
|
|
|
307
|
+
static xt_value xt_promise_with_resolvers_resolve(xt_value thisValue, xt_value env, int32_t argc,
|
|
308
|
+
xt_value *argv) {
|
|
309
|
+
(void)thisValue;
|
|
310
|
+
xt_promise_fulfill(xt_closure_env(env, 0), xt_arg_at(argc, argv, 0));
|
|
311
|
+
return XT_UNDEFINED;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
static xt_value xt_promise_with_resolvers_reject(xt_value thisValue, xt_value env, int32_t argc,
|
|
315
|
+
xt_value *argv) {
|
|
316
|
+
(void)thisValue;
|
|
317
|
+
xt_promise_reject_value(xt_closure_env(env, 0), xt_arg_at(argc, argv, 0));
|
|
318
|
+
return XT_UNDEFINED;
|
|
319
|
+
}
|
|
320
|
+
|
|
290
321
|
xt_value xt_promise_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
291
322
|
const char *fn = xt_string_data(name);
|
|
292
323
|
if (!fn) return XT_UNDEFINED;
|
|
324
|
+
if (strcmp(fn, "withResolvers") == 0) {
|
|
325
|
+
xt_value promise = xt_promise_create();
|
|
326
|
+
xt_value environment[1] = {promise};
|
|
327
|
+
xt_value result = xt_object_new();
|
|
328
|
+
xt_object_set(result, xt_string_from_cstr("promise"), promise);
|
|
329
|
+
xt_object_set(result, xt_string_from_cstr("resolve"),
|
|
330
|
+
xt_closure_new((void *)xt_promise_with_resolvers_resolve, 1, environment));
|
|
331
|
+
xt_object_set(result, xt_string_from_cstr("reject"),
|
|
332
|
+
xt_closure_new((void *)xt_promise_with_resolvers_reject, 1, environment));
|
|
333
|
+
return result;
|
|
334
|
+
}
|
|
293
335
|
if (strcmp(fn, "resolve") == 0) return xt_promise_resolve(xt_arg_at(argc, argv, 0));
|
|
294
336
|
if (strcmp(fn, "reject") == 0) return xt_promise_reject(xt_arg_at(argc, argv, 0));
|
|
295
337
|
if (strcmp(fn, "all") == 0 || strcmp(fn, "allSettled") == 0 || strcmp(fn, "race") == 0 || strcmp(fn, "any") == 0) {
|
|
@@ -321,7 +363,12 @@ xt_value xt_promise_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
|
321
363
|
xt_promise_settle(result, XT_PROMISE_REJECTED, inner->value);
|
|
322
364
|
return xt_promise_value(result);
|
|
323
365
|
}
|
|
324
|
-
xt_value settled
|
|
366
|
+
xt_value settled;
|
|
367
|
+
if (xt_promise_state_of(item) == XT_PROMISE_FULFILLED) {
|
|
368
|
+
settled = xt_promise_value_of(item);
|
|
369
|
+
} else {
|
|
370
|
+
settled = xt_await(item);
|
|
371
|
+
}
|
|
325
372
|
if (strcmp(fn, "any") == 0 || strcmp(fn, "race") == 0) {
|
|
326
373
|
xt_promise_settle(result, XT_PROMISE_FULFILLED, settled);
|
|
327
374
|
return xt_promise_value(result);
|
|
@@ -386,3 +433,18 @@ xt_value xt_promise_method(xt_value target, const char *method, int32_t argc, xt
|
|
|
386
433
|
*handled = 0;
|
|
387
434
|
return XT_UNDEFINED;
|
|
388
435
|
}
|
|
436
|
+
|
|
437
|
+
xt_value xt_queue_microtask(int32_t argc, xt_value *argv) {
|
|
438
|
+
xt_value callback = xt_arg_at(argc, argv, 0);
|
|
439
|
+
if (!XT_IS_FUNCTION(callback)) {
|
|
440
|
+
xt_value message = xt_string_from_cstr("The \"callback\" argument must be of type function");
|
|
441
|
+
xt_throw(xt_type_error_ctor(1, &message));
|
|
442
|
+
return XT_UNDEFINED;
|
|
443
|
+
}
|
|
444
|
+
/* Reuse the promise reaction queue: a settled promise's `then` callback is
|
|
445
|
+
* exactly a microtask, and it keeps FIFO order with pending `.then`s. */
|
|
446
|
+
xt_value promise = xt_promise_resolve(XT_UNDEFINED);
|
|
447
|
+
int handled = 0;
|
|
448
|
+
xt_promise_method(promise, "then", 1, &callback, &handled);
|
|
449
|
+
return XT_UNDEFINED;
|
|
450
|
+
}
|
|
@@ -150,7 +150,7 @@ static xt_value xt_array_reduce(xt_value value, xt_value fn, int32_t hasInitial,
|
|
|
150
150
|
accumulator = array->items[0];
|
|
151
151
|
i = 1;
|
|
152
152
|
} else {
|
|
153
|
-
xt_throw(
|
|
153
|
+
xt_throw(xt_error_from_message("TypeError: Reduce of empty array with no initial value"));
|
|
154
154
|
return XT_UNDEFINED;
|
|
155
155
|
}
|
|
156
156
|
for (; i < array->length; i++) {
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
/* -- method dispatch ------------------------------------------------------ */
|
|
2
2
|
|
|
3
|
+
/* A method that no built-in table recognises must throw, exactly like a
|
|
4
|
+
* missing property called as a function in JavaScript. Returning `undefined`
|
|
5
|
+
* made typos and unimplemented APIs (e.g. `"x".normalize()`) fail silently. */
|
|
6
|
+
static _Noreturn void xt_throw_no_method(const char *type, const char *method) {
|
|
7
|
+
char message[256];
|
|
8
|
+
snprintf(message, sizeof(message), "TypeError: %s has no callable method '%s'", type, method);
|
|
9
|
+
xt_value argument = xt_string_from_cstr(message);
|
|
10
|
+
xt_throw(xt_type_error_ctor(1, &argument));
|
|
11
|
+
abort();
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
static xt_value xt_array_method(xt_value target, const char *method, int32_t argc, xt_value *argv, int *handled) {
|
|
4
15
|
*handled = 1;
|
|
5
16
|
if (strcmp(method, "push") == 0) {
|
|
@@ -92,7 +103,7 @@ static xt_value xt_method_value_invoke(xt_value thisValue, xt_value env, int32_t
|
|
|
92
103
|
snprintf(message, sizeof(message),
|
|
93
104
|
"TypeError: Cannot read properties of undefined (reading '%s')",
|
|
94
105
|
method ? method : "method");
|
|
95
|
-
xt_throw(
|
|
106
|
+
xt_throw(xt_error_from_message(message));
|
|
96
107
|
}
|
|
97
108
|
return xt_call_method(thisValue, name, argc, argv);
|
|
98
109
|
}
|
|
@@ -159,6 +170,18 @@ static const xt_method_spec XT_SET_METHODS[] = {
|
|
|
159
170
|
{"entries", 0}, {"forEach", 1},
|
|
160
171
|
};
|
|
161
172
|
|
|
173
|
+
static const xt_method_spec XT_WEAKMAP_METHODS[] = {
|
|
174
|
+
{"get", 1}, {"set", 2}, {"has", 1}, {"delete", 1},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
static const xt_method_spec XT_WEAKSET_METHODS[] = {
|
|
178
|
+
{"add", 1}, {"has", 1}, {"delete", 1},
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
static const xt_method_spec XT_WEAKREF_METHODS[] = {
|
|
182
|
+
{"deref", 0},
|
|
183
|
+
};
|
|
184
|
+
|
|
162
185
|
static const xt_method_spec XT_REGEXP_METHODS[] = {
|
|
163
186
|
{"test", 1}, {"exec", 1}, {"toString", 0},
|
|
164
187
|
};
|
|
@@ -215,6 +238,12 @@ xt_value xt_method_value(xt_value target, xt_value name) {
|
|
|
215
238
|
known = xt_method_lookup(XT_MAP_METHODS, XT_NAME_COUNT(XT_MAP_METHODS), method, &arity);
|
|
216
239
|
} else if (kind == XT_OBJECT_KIND_SET) {
|
|
217
240
|
known = xt_method_lookup(XT_SET_METHODS, XT_NAME_COUNT(XT_SET_METHODS), method, &arity);
|
|
241
|
+
} else if (kind == XT_OBJECT_KIND_WEAK_MAP) {
|
|
242
|
+
known = xt_method_lookup(XT_WEAKMAP_METHODS, XT_NAME_COUNT(XT_WEAKMAP_METHODS), method, &arity);
|
|
243
|
+
} else if (kind == XT_OBJECT_KIND_WEAK_SET) {
|
|
244
|
+
known = xt_method_lookup(XT_WEAKSET_METHODS, XT_NAME_COUNT(XT_WEAKSET_METHODS), method, &arity);
|
|
245
|
+
} else if (kind == XT_OBJECT_KIND_WEAK_REF) {
|
|
246
|
+
known = xt_method_lookup(XT_WEAKREF_METHODS, XT_NAME_COUNT(XT_WEAKREF_METHODS), method, &arity);
|
|
218
247
|
} else if (kind == XT_OBJECT_KIND_REGEXP) {
|
|
219
248
|
known = xt_method_lookup(XT_REGEXP_METHODS, XT_NAME_COUNT(XT_REGEXP_METHODS), method, &arity);
|
|
220
249
|
} else if (kind == XT_OBJECT_KIND_PROMISE) {
|
|
@@ -240,7 +269,7 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
|
|
|
240
269
|
* resolve it as an ordinary property and call it with `target` as `this`. */
|
|
241
270
|
if (xt_is_symbol(name)) {
|
|
242
271
|
if (target == XT_UNDEFINED || target == XT_NULL) {
|
|
243
|
-
xt_throw(
|
|
272
|
+
xt_throw(xt_error_from_message("TypeError: Cannot read properties of null (reading a Symbol)"));
|
|
244
273
|
}
|
|
245
274
|
xt_value fn = xt_get(target, name);
|
|
246
275
|
if (XT_IS_FUNCTION(fn)) return xt_call_with_this(fn, target, argc, argv);
|
|
@@ -253,7 +282,7 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
|
|
|
253
282
|
* `target` as `this`, instead of silently returning undefined. */
|
|
254
283
|
xt_value fn = xt_get(target, name);
|
|
255
284
|
if (XT_IS_FUNCTION(fn)) return xt_call_with_this(fn, target, argc, argv);
|
|
256
|
-
xt_throw(
|
|
285
|
+
xt_throw(xt_error_from_message("TypeError: value at computed index is not a function"));
|
|
257
286
|
return XT_UNDEFINED;
|
|
258
287
|
}
|
|
259
288
|
if (target == XT_UNDEFINED || target == XT_NULL) {
|
|
@@ -261,13 +290,13 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
|
|
|
261
290
|
char message[256];
|
|
262
291
|
snprintf(message, sizeof(message),
|
|
263
292
|
"TypeError: Cannot read properties of %s (reading '%s')", base, method);
|
|
264
|
-
xt_throw(
|
|
293
|
+
xt_throw(xt_error_from_message(message));
|
|
265
294
|
}
|
|
266
295
|
int handled = 0;
|
|
267
296
|
if (xt_is_symbol(target)) {
|
|
268
297
|
if (strcmp(method, "toString") == 0) return xt_symbol_to_string(target);
|
|
269
298
|
if (strcmp(method, "valueOf") == 0) return target;
|
|
270
|
-
|
|
299
|
+
xt_throw_no_method("symbol", method);
|
|
271
300
|
}
|
|
272
301
|
if (XT_IS_OBJECT(target)) {
|
|
273
302
|
xt_object *obj = (xt_object *)XT_GET_PTR(target);
|
|
@@ -303,7 +332,7 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
|
|
|
303
332
|
{
|
|
304
333
|
char message[256];
|
|
305
334
|
snprintf(message, sizeof(message), "TypeError: object has no callable method '%s'", method);
|
|
306
|
-
xt_throw(
|
|
335
|
+
xt_throw(xt_error_from_message(message));
|
|
307
336
|
}
|
|
308
337
|
return XT_UNDEFINED;
|
|
309
338
|
}
|
|
@@ -360,32 +389,38 @@ xt_value xt_call_method(xt_value target, xt_value name, int32_t argc, xt_value *
|
|
|
360
389
|
{
|
|
361
390
|
char message[256];
|
|
362
391
|
snprintf(message, sizeof(message), "TypeError: function has no callable method '%s'", method);
|
|
363
|
-
xt_throw(
|
|
392
|
+
xt_throw(xt_error_from_message(message));
|
|
364
393
|
}
|
|
365
394
|
return XT_UNDEFINED;
|
|
366
395
|
}
|
|
367
396
|
if (XT_IS_ARRAY(target)) {
|
|
368
397
|
xt_value result = xt_ext_array_method(target, method, argc, argv, &handled);
|
|
369
398
|
if (handled) return result;
|
|
370
|
-
|
|
399
|
+
result = xt_array_method(target, method, argc, argv, &handled);
|
|
400
|
+
if (handled) return result;
|
|
401
|
+
xt_throw_no_method("array", method);
|
|
371
402
|
}
|
|
372
403
|
if (XT_IS_STRING(target)) {
|
|
373
404
|
xt_value result = xt_ext_string_method(target, method, argc, argv, &handled);
|
|
374
405
|
if (handled) return result;
|
|
375
|
-
|
|
406
|
+
result = xt_string_method(target, method, argc, argv, &handled);
|
|
407
|
+
if (handled) return result;
|
|
408
|
+
xt_throw_no_method("string", method);
|
|
376
409
|
}
|
|
377
410
|
if (XT_IS_BIGINT(target)) {
|
|
378
411
|
xt_value result = xt_bigint_method(target, method, argc, argv, &handled);
|
|
379
412
|
if (handled) return result;
|
|
413
|
+
xt_throw_no_method("bigint", method);
|
|
380
414
|
}
|
|
381
415
|
if (XT_IS_NUMBER(target)) {
|
|
382
416
|
xt_value result = xt_ext_number_method(target, method, argc, argv, &handled);
|
|
383
417
|
if (handled) return result;
|
|
418
|
+
xt_throw_no_method("number", method);
|
|
384
419
|
}
|
|
385
420
|
if (target == XT_TRUE || target == XT_FALSE) {
|
|
386
421
|
if (strcmp(method, "toString") == 0) return target == XT_TRUE ? xt_string_from_cstr("true") : xt_string_from_cstr("false");
|
|
387
422
|
if (strcmp(method, "valueOf") == 0) return target;
|
|
388
|
-
|
|
423
|
+
xt_throw_no_method("boolean", method);
|
|
389
424
|
}
|
|
390
|
-
|
|
425
|
+
xt_throw_no_method("value", method);
|
|
391
426
|
}
|
|
@@ -190,7 +190,7 @@ static xt_value xt_string_repeat(xt_value value, xt_value countValue) {
|
|
|
190
190
|
if (!s) return value;
|
|
191
191
|
int32_t count = xt_to_int32(countValue);
|
|
192
192
|
if (count < 0) {
|
|
193
|
-
xt_throw(
|
|
193
|
+
xt_throw(xt_error_from_message("RangeError: Invalid count value"));
|
|
194
194
|
return XT_UNDEFINED;
|
|
195
195
|
}
|
|
196
196
|
xt_string *out = xt_string_alloc((size_t)s->length * (size_t)count);
|
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
/* -- Array statics -------------------------------------------------------- */
|
|
2
2
|
|
|
3
|
+
/* True when `Array.from` should consume the value through the iteration
|
|
4
|
+
* protocol instead of the array-like `length` path. Typed arrays stay on the
|
|
5
|
+
* length path because their indexed properties already work that way. */
|
|
6
|
+
static int xt_array_from_is_iterable(xt_value value) {
|
|
7
|
+
if (xt_is_map(value) || xt_is_set(value) || xt_is_generator(value)) return 1;
|
|
8
|
+
if (XT_IS_OBJECT(value) && xt_typed_array_kind_of(value) < 0) {
|
|
9
|
+
return XT_IS_FUNCTION(xt_object_get(value, xt_symbol_well_known("iterator")));
|
|
10
|
+
}
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
3
14
|
xt_value xt_array_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
4
15
|
const char *fn = xt_string_data(name);
|
|
5
16
|
if (!fn) return XT_UNDEFINED;
|
|
@@ -24,6 +35,20 @@ xt_value xt_array_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
|
24
35
|
if (XT_IS_FUNCTION(mapper)) { xt_value args[2] = {item, xt_number((double)i)}; item = xt_closure_call(mapper, 2, args); }
|
|
25
36
|
xt_array_push(out, item);
|
|
26
37
|
}
|
|
38
|
+
} else if (xt_array_from_is_iterable(source)) {
|
|
39
|
+
/* Map, Set, generators, iterator objects and custom `[Symbol.iterator]`
|
|
40
|
+
* values do not expose a `length`; walk their `next()` protocol instead
|
|
41
|
+
* of silently producing an empty array. */
|
|
42
|
+
xt_value iterator = xt_iter_open(source);
|
|
43
|
+
for (uint32_t i = 0;; i++) {
|
|
44
|
+
if (!xt_truthy(xt_iter_has(iterator, xt_number((double)i)))) break;
|
|
45
|
+
xt_value item = xt_iter_value(iterator, xt_number((double)i));
|
|
46
|
+
if (XT_IS_FUNCTION(mapper)) {
|
|
47
|
+
xt_value args[2] = {item, xt_number((double)i)};
|
|
48
|
+
item = xt_closure_call(mapper, 2, args);
|
|
49
|
+
}
|
|
50
|
+
xt_array_push(out, item);
|
|
51
|
+
}
|
|
27
52
|
} else {
|
|
28
53
|
double length = xt_to_number(xt_get(source, xt_string_from_cstr("length")));
|
|
29
54
|
for (int32_t i = 0; i < (int32_t)length; i++) {
|
|
@@ -85,7 +85,7 @@ static xt_value xt_array_sort(xt_value value, xt_value fn) {
|
|
|
85
85
|
int hasFn = XT_IS_FUNCTION(fn);
|
|
86
86
|
xt_value *scratch = (xt_value *)malloc(sizeof(xt_value) * array->length);
|
|
87
87
|
if (!scratch) {
|
|
88
|
-
xt_throw(
|
|
88
|
+
xt_throw(xt_error_from_message("RangeError: out of memory in Array.prototype.sort"));
|
|
89
89
|
return value;
|
|
90
90
|
}
|
|
91
91
|
xt_array_merge_sort(array->items, scratch, array->length, fn, hasFn);
|
|
@@ -225,7 +225,9 @@ static xt_value xt_array_with(xt_value value, xt_value indexValue, xt_value newV
|
|
|
225
225
|
int32_t index = xt_to_int32(indexValue);
|
|
226
226
|
if (index < 0) index += (int32_t)array->length;
|
|
227
227
|
if (index < 0 || index >= (int32_t)array->length) {
|
|
228
|
-
|
|
228
|
+
xt_value message =
|
|
229
|
+
xt_add(xt_string_from_cstr("RangeError: Invalid index : "), xt_to_string(indexValue));
|
|
230
|
+
xt_throw(xt_error_from_message(xt_string_data(message)));
|
|
229
231
|
return copy;
|
|
230
232
|
}
|
|
231
233
|
array->items[index] = newValue;
|
|
@@ -266,7 +268,7 @@ xt_value xt_ext_array_method(xt_value target, const char *method, int32_t argc,
|
|
|
266
268
|
xt_value acc;
|
|
267
269
|
if (argc >= 2) acc = argv[1];
|
|
268
270
|
else if (array->length > 0) acc = array->items[i--];
|
|
269
|
-
else { xt_throw(
|
|
271
|
+
else { xt_throw(xt_error_from_message("TypeError: Reduce of empty array with no initial value")); return XT_UNDEFINED; }
|
|
270
272
|
for (; i >= 0; i--) {
|
|
271
273
|
xt_value args[4] = {acc, array->items[i], xt_number((double)i), target};
|
|
272
274
|
acc = xt_closure_call(fn, 4, args);
|
|
@@ -2,6 +2,11 @@ xt_value xt_ext_container_method(xt_value target, const char *method, int32_t ar
|
|
|
2
2
|
xt_object *obj = (xt_object *)XT_GET_PTR(target);
|
|
3
3
|
if (obj->header.kind == XT_OBJECT_KIND_MAP) return xt_map_method(target, method, argc, argv, handled);
|
|
4
4
|
if (obj->header.kind == XT_OBJECT_KIND_SET) return xt_set_method(target, method, argc, argv, handled);
|
|
5
|
+
if (obj->header.kind == XT_OBJECT_KIND_WEAK_MAP ||
|
|
6
|
+
obj->header.kind == XT_OBJECT_KIND_WEAK_SET ||
|
|
7
|
+
obj->header.kind == XT_OBJECT_KIND_WEAK_REF) {
|
|
8
|
+
return xt_weak_method(target, method, argc, argv, handled);
|
|
9
|
+
}
|
|
5
10
|
if (obj->header.kind == XT_OBJECT_KIND_DATE) return xt_date_method(target, method, argc, argv, handled);
|
|
6
11
|
if (obj->header.kind == XT_OBJECT_KIND_REGEXP) {
|
|
7
12
|
xt_regexp *regexp = (xt_regexp *)obj;
|
|
@@ -4,11 +4,111 @@ int xt_is_date(xt_value value) {
|
|
|
4
4
|
return XT_IS_OBJECT(value) && ((xt_object *)XT_GET_PTR(value))->header.kind == XT_OBJECT_KIND_DATE;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
/* Parse `YYYY-MM-DD`, optionally followed by `T`/space and
|
|
8
|
+
* `HH:MM[:SS[.mmm]]`, then `Z`, `+HH:MM`/`-HH:MM` (or the HHMM spelling).
|
|
9
|
+
* A date-only value is UTC; a date-time without an offset is local time, which
|
|
10
|
+
* is what ECMAScript specifies. Returns milliseconds since the epoch, or NaN
|
|
11
|
+
* for anything outside this subset. */
|
|
12
|
+
static int xt_date_digits(const char *text, int count, int *out) {
|
|
13
|
+
int value = 0;
|
|
14
|
+
for (int i = 0; i < count; i++) {
|
|
15
|
+
if (text[i] < '0' || text[i] > '9') return 0;
|
|
16
|
+
value = value * 10 + (text[i] - '0');
|
|
17
|
+
}
|
|
18
|
+
*out = value;
|
|
19
|
+
return 1;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static double xt_date_parse_text(const char *text) {
|
|
23
|
+
size_t length = strlen(text);
|
|
24
|
+
size_t i = 0;
|
|
25
|
+
int year = 0, month = 0, day = 0;
|
|
26
|
+
if (length < 10 || !xt_date_digits(text, 4, &year) || text[4] != '-' ||
|
|
27
|
+
!xt_date_digits(text + 5, 2, &month) || text[7] != '-' ||
|
|
28
|
+
!xt_date_digits(text + 8, 2, &day)) {
|
|
29
|
+
return NAN;
|
|
30
|
+
}
|
|
31
|
+
i = 10;
|
|
32
|
+
int hour = 0, minute = 0, second = 0, millis = 0;
|
|
33
|
+
int hasTime = 0;
|
|
34
|
+
if (i < length && (text[i] == 'T' || text[i] == ' ')) {
|
|
35
|
+
hasTime = 1;
|
|
36
|
+
i++;
|
|
37
|
+
if (i + 5 > length || !xt_date_digits(text + i, 2, &hour) || text[i + 2] != ':' ||
|
|
38
|
+
!xt_date_digits(text + i + 3, 2, &minute)) {
|
|
39
|
+
return NAN;
|
|
40
|
+
}
|
|
41
|
+
i += 5;
|
|
42
|
+
if (i + 3 <= length && text[i] == ':') {
|
|
43
|
+
if (!xt_date_digits(text + i + 1, 2, &second)) return NAN;
|
|
44
|
+
i += 3;
|
|
45
|
+
}
|
|
46
|
+
if (i + 4 <= length && text[i] == '.') {
|
|
47
|
+
if (!xt_date_digits(text + i + 1, 3, &millis)) return NAN;
|
|
48
|
+
i += 4;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
int utc = !hasTime;
|
|
52
|
+
int offsetSeconds = 0;
|
|
53
|
+
if (i < length) {
|
|
54
|
+
if (text[i] == 'Z') {
|
|
55
|
+
utc = 1;
|
|
56
|
+
i++;
|
|
57
|
+
} else if (text[i] == '+' || text[i] == '-') {
|
|
58
|
+
int sign = text[i] == '-' ? -1 : 1;
|
|
59
|
+
i++;
|
|
60
|
+
int offsetHour = 0, offsetMinute = 0;
|
|
61
|
+
if (i + 5 <= length && xt_date_digits(text + i, 2, &offsetHour) && text[i + 2] == ':' &&
|
|
62
|
+
xt_date_digits(text + i + 3, 2, &offsetMinute)) {
|
|
63
|
+
i += 5;
|
|
64
|
+
} else if (i + 4 <= length && xt_date_digits(text + i, 2, &offsetHour) &&
|
|
65
|
+
xt_date_digits(text + i + 2, 2, &offsetMinute)) {
|
|
66
|
+
i += 4;
|
|
67
|
+
} else {
|
|
68
|
+
return NAN;
|
|
69
|
+
}
|
|
70
|
+
if (offsetHour > 23 || offsetMinute > 59) return NAN;
|
|
71
|
+
offsetSeconds = sign * (offsetHour * 3600 + offsetMinute * 60);
|
|
72
|
+
utc = 1;
|
|
73
|
+
} else {
|
|
74
|
+
return NAN;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (i != length) return NAN;
|
|
78
|
+
if (month < 1 || month > 12 || day < 1 || day > 31 ||
|
|
79
|
+
hour > 23 || minute > 59 || second > 59) {
|
|
80
|
+
return NAN;
|
|
81
|
+
}
|
|
82
|
+
struct tm tm;
|
|
83
|
+
memset(&tm, 0, sizeof(tm));
|
|
84
|
+
tm.tm_year = year - 1900;
|
|
85
|
+
tm.tm_mon = month - 1;
|
|
86
|
+
tm.tm_mday = day;
|
|
87
|
+
tm.tm_hour = hour;
|
|
88
|
+
tm.tm_min = minute;
|
|
89
|
+
tm.tm_sec = second;
|
|
90
|
+
time_t seconds;
|
|
91
|
+
if (utc) {
|
|
92
|
+
seconds = xt_timegm(&tm);
|
|
93
|
+
} else {
|
|
94
|
+
tm.tm_isdst = -1;
|
|
95
|
+
seconds = mktime(&tm);
|
|
96
|
+
if (seconds == (time_t)-1) return NAN;
|
|
97
|
+
}
|
|
98
|
+
if (utc && offsetSeconds != 0) seconds -= offsetSeconds;
|
|
99
|
+
return (double)seconds * 1000.0 + (double)millis;
|
|
100
|
+
}
|
|
101
|
+
|
|
7
102
|
xt_value xt_date_ctor(int32_t argc, xt_value *argv) {
|
|
8
103
|
xt_date *date = (xt_date *)xt_alloc(sizeof(xt_date), XT_OBJECT_KIND_DATE);
|
|
9
104
|
if (argc == 0) date->time = (double)time(NULL) * 1000.0;
|
|
10
|
-
else if (argc == 1)
|
|
11
|
-
|
|
105
|
+
else if (argc == 1) {
|
|
106
|
+
if (XT_IS_STRING(argv[0])) {
|
|
107
|
+
date->time = xt_date_parse_text(xt_string_data(argv[0]));
|
|
108
|
+
} else {
|
|
109
|
+
date->time = xt_to_number(argv[0]);
|
|
110
|
+
}
|
|
111
|
+
} else {
|
|
12
112
|
struct tm tm;
|
|
13
113
|
memset(&tm, 0, sizeof(tm));
|
|
14
114
|
tm.tm_year = xt_to_int32(argv[0]) - 1900;
|
|
@@ -27,7 +127,11 @@ xt_value xt_date_static(xt_value name, int32_t argc, xt_value *argv) {
|
|
|
27
127
|
const char *fn = xt_string_data(name);
|
|
28
128
|
if (!fn) return XT_UNDEFINED;
|
|
29
129
|
if (strcmp(fn, "now") == 0) return xt_number((double)time(NULL) * 1000.0);
|
|
30
|
-
if (strcmp(fn, "parse") == 0)
|
|
130
|
+
if (strcmp(fn, "parse") == 0) {
|
|
131
|
+
xt_value input = xt_arg_at(argc, argv, 0);
|
|
132
|
+
if (!XT_IS_STRING(input)) return xt_number(NAN);
|
|
133
|
+
return xt_number(xt_date_parse_text(xt_string_data(input)));
|
|
134
|
+
}
|
|
31
135
|
if (strcmp(fn, "UTC") == 0) {
|
|
32
136
|
struct tm tm;
|
|
33
137
|
memset(&tm, 0, sizeof(tm));
|
|
@@ -68,6 +172,10 @@ static xt_value xt_date_method(xt_value target, const char *method, int32_t argc
|
|
|
68
172
|
if (strcmp(name, "getSeconds") == 0) return xt_number(tm.tm_sec);
|
|
69
173
|
if (strcmp(name, "getMilliseconds") == 0) return xt_number(fmod(date->time, 1000.0));
|
|
70
174
|
if (strcmp(method, "toISOString") == 0) {
|
|
175
|
+
if (isnan(date->time)) {
|
|
176
|
+
xt_value message = xt_string_from_cstr("Invalid time value");
|
|
177
|
+
xt_throw(xt_range_error_ctor(1, &message));
|
|
178
|
+
}
|
|
71
179
|
char buffer[64];
|
|
72
180
|
snprintf(buffer, sizeof(buffer), "%04d-%02d-%02dT%02d:%02d:%02d.%03dZ", tm.tm_year + 1900, tm.tm_mon + 1,
|
|
73
181
|
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)fmod(date->time, 1000.0));
|
|
@@ -112,6 +112,30 @@ xt_value xt_error_constructor(xt_value nameValue) {
|
|
|
112
112
|
return closure;
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
/* Build the value thrown by the runtime for an internal "Name: message"
|
|
116
|
+
* string. JavaScript code can observe anything thrown, so internal failures
|
|
117
|
+
* must be real Error instances (`instanceof Error`, `.name`, `.message`,
|
|
118
|
+
* `.stack`), exactly like `new TypeError("...")`; a bare string would make
|
|
119
|
+
* `catch` blocks silently misbehave. User `throw` expressions never go
|
|
120
|
+
* through this helper. */
|
|
121
|
+
xt_value xt_error_from_message(const char *message) {
|
|
122
|
+
const char *separator = strstr(message, ": ");
|
|
123
|
+
if (separator != NULL) {
|
|
124
|
+
size_t nameLength = (size_t)(separator - message);
|
|
125
|
+
char name[24];
|
|
126
|
+
if (nameLength > 0 && nameLength < sizeof(name)) {
|
|
127
|
+
memcpy(name, message, nameLength);
|
|
128
|
+
name[nameLength] = '\0';
|
|
129
|
+
if (xt_error_is_family(name)) {
|
|
130
|
+
xt_value argument = xt_string_from_cstr(separator + 2);
|
|
131
|
+
return xt_make_error(name, 1, &argument);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
xt_value argument = xt_string_from_cstr(message);
|
|
136
|
+
return xt_make_error("Error", 1, &argument);
|
|
137
|
+
}
|
|
138
|
+
|
|
115
139
|
xt_value xt_error_to_string(xt_value error) {
|
|
116
140
|
xt_value name = xt_object_get(error, xt_string_from_cstr("name"));
|
|
117
141
|
xt_value message = xt_object_get(error, xt_string_from_cstr("message"));
|