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_url.c
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — URLSearchParams.
|
|
3
|
+
*
|
|
4
|
+
* The query string is stored as an array of [key, value] pairs under an
|
|
5
|
+
* internal `__entries` property. Methods are closures on the instance, so the
|
|
6
|
+
* same object model as the rest of the runtime applies. Values are stored
|
|
7
|
+
* decoded and encoded with application/x-www-form-urlencoded rules when
|
|
8
|
+
* serialized (`+` for spaces, percent escapes for everything else).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include "rt_internal.h"
|
|
12
|
+
|
|
13
|
+
#include <ctype.h>
|
|
14
|
+
#include <stdlib.h>
|
|
15
|
+
#include <string.h>
|
|
16
|
+
|
|
17
|
+
static int xt_url_unreserved(unsigned char c) {
|
|
18
|
+
return (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') ||
|
|
19
|
+
c == '*' || c == '-' || c == '.' || c == '_';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static xt_value xt_url_encode(xt_value value) {
|
|
23
|
+
xt_value text = xt_to_string(value);
|
|
24
|
+
xt_string *string = xt_as_string(text);
|
|
25
|
+
const char *bytes = xt_string_bytes(string);
|
|
26
|
+
size_t capacity = string->length * 3 + 1;
|
|
27
|
+
char *out = (char *)malloc(capacity);
|
|
28
|
+
if (!out) abort();
|
|
29
|
+
size_t written = 0;
|
|
30
|
+
for (uint32_t i = 0; i < string->length; i++) {
|
|
31
|
+
unsigned char c = (unsigned char)bytes[i];
|
|
32
|
+
if (c == ' ') {
|
|
33
|
+
out[written++] = '+';
|
|
34
|
+
} else if (xt_url_unreserved(c)) {
|
|
35
|
+
out[written++] = (char)c;
|
|
36
|
+
} else {
|
|
37
|
+
static const char hex[] = "0123456789ABCDEF";
|
|
38
|
+
out[written++] = '%';
|
|
39
|
+
out[written++] = hex[c >> 4];
|
|
40
|
+
out[written++] = hex[c & 0x0f];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
xt_value result = xt_string_new(out, written);
|
|
44
|
+
free(out);
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static int xt_url_hex(char c) {
|
|
49
|
+
if (c >= '0' && c <= '9') return c - '0';
|
|
50
|
+
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
51
|
+
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
static xt_value xt_url_decode(const char *data, size_t length) {
|
|
56
|
+
char *out = (char *)malloc(length == 0 ? 1 : length);
|
|
57
|
+
if (!out) abort();
|
|
58
|
+
size_t written = 0;
|
|
59
|
+
for (size_t i = 0; i < length; i++) {
|
|
60
|
+
char c = data[i];
|
|
61
|
+
if (c == '+') {
|
|
62
|
+
out[written++] = ' ';
|
|
63
|
+
} else if (c == '%' && i + 2 < length) {
|
|
64
|
+
int high = xt_url_hex(data[i + 1]);
|
|
65
|
+
int low = xt_url_hex(data[i + 2]);
|
|
66
|
+
if (high >= 0 && low >= 0) {
|
|
67
|
+
out[written++] = (char)((high << 4) | low);
|
|
68
|
+
i += 2;
|
|
69
|
+
} else {
|
|
70
|
+
out[written++] = c;
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
out[written++] = c;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
xt_value result = xt_string_new(out, written);
|
|
77
|
+
free(out);
|
|
78
|
+
return result;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static xt_value xt_url_entries(xt_value params) {
|
|
82
|
+
xt_value entries = xt_get(params, xt_string_from_cstr("__entries"));
|
|
83
|
+
if (!XT_IS_ARRAY(entries)) {
|
|
84
|
+
entries = xt_array_new(0, NULL);
|
|
85
|
+
xt_object_set(params, xt_string_from_cstr("__entries"), entries);
|
|
86
|
+
}
|
|
87
|
+
return entries;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static void xt_url_set_size(xt_value params) {
|
|
91
|
+
xt_array *entries = xt_as_array(xt_url_entries(params));
|
|
92
|
+
xt_object_set(params, xt_string_from_cstr("size"), xt_number((double)entries->length));
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
static void xt_url_append_pair(xt_value entries, xt_value key, xt_value value) {
|
|
96
|
+
xt_value pair = xt_array_new(0, NULL);
|
|
97
|
+
xt_array_push(pair, key);
|
|
98
|
+
xt_array_push(pair, value);
|
|
99
|
+
xt_array_push(entries, pair);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
static xt_value xt_url_string_at(xt_value text, size_t start, size_t length) {
|
|
103
|
+
xt_string *string = xt_as_string(text);
|
|
104
|
+
const char *bytes = xt_string_bytes(string);
|
|
105
|
+
return xt_string_new(bytes + start, length);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/* Split a query string on `&`, then each item on the first `=`; decode both
|
|
109
|
+
* halves and append them. A leading `?` is ignored. */
|
|
110
|
+
static void xt_url_parse_into(xt_value params, xt_value input) {
|
|
111
|
+
xt_value text = xt_to_string(input);
|
|
112
|
+
xt_string *string = xt_as_string(text);
|
|
113
|
+
const char *bytes = xt_string_bytes(string);
|
|
114
|
+
size_t length = string->length;
|
|
115
|
+
size_t start = (length > 0 && bytes[0] == '?') ? 1 : 0;
|
|
116
|
+
xt_value entries = xt_url_entries(params);
|
|
117
|
+
while (start <= length) {
|
|
118
|
+
size_t end = start;
|
|
119
|
+
while (end < length && bytes[end] != '&') end++;
|
|
120
|
+
if (end > start) {
|
|
121
|
+
size_t equals = start;
|
|
122
|
+
while (equals < end && bytes[equals] != '=') equals++;
|
|
123
|
+
xt_value key = xt_url_decode(bytes + start, equals - start);
|
|
124
|
+
xt_value value = equals < end ? xt_url_decode(bytes + equals + 1, end - equals - 1)
|
|
125
|
+
: xt_string_from_cstr("");
|
|
126
|
+
xt_url_append_pair(entries, key, value);
|
|
127
|
+
}
|
|
128
|
+
if (end >= length) break;
|
|
129
|
+
start = end + 1;
|
|
130
|
+
}
|
|
131
|
+
xt_url_set_size(params);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static void xt_url_ctor_from_value(xt_value params, xt_value source) {
|
|
135
|
+
if (source == XT_UNDEFINED) return;
|
|
136
|
+
if (XT_IS_STRING(source)) {
|
|
137
|
+
xt_url_parse_into(params, source);
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (XT_IS_ARRAY(source)) {
|
|
141
|
+
xt_value entries = xt_url_entries(params);
|
|
142
|
+
xt_array *pairs = xt_as_array(source);
|
|
143
|
+
for (uint32_t i = 0; i < pairs->length; i++) {
|
|
144
|
+
xt_array *pair = xt_as_array(pairs->items[i]);
|
|
145
|
+
if (pair && pair->length >= 1) {
|
|
146
|
+
xt_value value = pair->length >= 2 ? pair->items[1] : xt_string_from_cstr("");
|
|
147
|
+
xt_url_append_pair(entries, xt_to_string(pair->items[0]), xt_to_string(value));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
xt_url_set_size(params);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (XT_IS_OBJECT(source)) {
|
|
154
|
+
xt_value existing = xt_get(source, xt_string_from_cstr("__entries"));
|
|
155
|
+
if (XT_IS_ARRAY(existing)) {
|
|
156
|
+
xt_value entries = xt_url_entries(params);
|
|
157
|
+
xt_array *pairs = xt_as_array(existing);
|
|
158
|
+
for (uint32_t i = 0; i < pairs->length; i++) {
|
|
159
|
+
xt_array *pair = xt_as_array(pairs->items[i]);
|
|
160
|
+
if (pair && pair->length >= 2) xt_url_append_pair(entries, pair->items[0], pair->items[1]);
|
|
161
|
+
}
|
|
162
|
+
xt_url_set_size(params);
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
xt_value keys = xt_object_keys(source);
|
|
166
|
+
xt_array *list = xt_as_array(keys);
|
|
167
|
+
if (!list) return;
|
|
168
|
+
xt_value entries = xt_url_entries(params);
|
|
169
|
+
for (uint32_t i = 0; i < list->length; i++) {
|
|
170
|
+
xt_value key = list->items[i];
|
|
171
|
+
xt_url_append_pair(entries, xt_to_string(key), xt_to_string(xt_object_get(source, key)));
|
|
172
|
+
}
|
|
173
|
+
xt_url_set_size(params);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/* -- methods -------------------------------------------------------------- */
|
|
178
|
+
|
|
179
|
+
static xt_value xt_url_method_append(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
180
|
+
(void)env;
|
|
181
|
+
xt_value entries = xt_url_entries(thisValue);
|
|
182
|
+
xt_url_append_pair(entries, xt_to_string(xt_arg_at(argc, argv, 0)),
|
|
183
|
+
xt_to_string(xt_arg_at(argc, argv, 1)));
|
|
184
|
+
xt_url_set_size(thisValue);
|
|
185
|
+
return XT_UNDEFINED;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
static int xt_url_key_equals(xt_value pair, xt_value key) {
|
|
189
|
+
xt_array *items = xt_as_array(pair);
|
|
190
|
+
return items && items->length >= 2 && xt_value_equals(items->items[0], key);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
static xt_value xt_url_method_get(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
194
|
+
(void)env;
|
|
195
|
+
xt_value key = xt_to_string(xt_arg_at(argc, argv, 0));
|
|
196
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
197
|
+
for (uint32_t i = 0; i < entries->length; i++) {
|
|
198
|
+
if (xt_url_key_equals(entries->items[i], key)) return ((xt_array *)XT_GET_PTR(entries->items[i]))->items[1];
|
|
199
|
+
}
|
|
200
|
+
return XT_NULL;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
static xt_value xt_url_method_get_all(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
204
|
+
(void)env;
|
|
205
|
+
xt_value key = xt_to_string(xt_arg_at(argc, argv, 0));
|
|
206
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
207
|
+
xt_value result = xt_array_new(0, NULL);
|
|
208
|
+
for (uint32_t i = 0; i < entries->length; i++) {
|
|
209
|
+
if (xt_url_key_equals(entries->items[i], key)) {
|
|
210
|
+
xt_array_push(result, ((xt_array *)XT_GET_PTR(entries->items[i]))->items[1]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
static xt_value xt_url_method_has(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
217
|
+
(void)env;
|
|
218
|
+
xt_value key = xt_to_string(xt_arg_at(argc, argv, 0));
|
|
219
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
220
|
+
for (uint32_t i = 0; i < entries->length; i++) {
|
|
221
|
+
if (xt_url_key_equals(entries->items[i], key)) return XT_TRUE;
|
|
222
|
+
}
|
|
223
|
+
return XT_FALSE;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
static xt_value xt_url_method_delete(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
227
|
+
(void)env;
|
|
228
|
+
xt_value key = xt_to_string(xt_arg_at(argc, argv, 0));
|
|
229
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
230
|
+
uint32_t write = 0;
|
|
231
|
+
for (uint32_t read = 0; read < entries->length; read++) {
|
|
232
|
+
if (!xt_url_key_equals(entries->items[read], key)) entries->items[write++] = entries->items[read];
|
|
233
|
+
}
|
|
234
|
+
entries->length = write;
|
|
235
|
+
xt_url_set_size(thisValue);
|
|
236
|
+
return XT_UNDEFINED;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
static xt_value xt_url_method_set(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
240
|
+
(void)env;
|
|
241
|
+
xt_value key = xt_to_string(xt_arg_at(argc, argv, 0));
|
|
242
|
+
xt_value value = xt_to_string(xt_arg_at(argc, argv, 1));
|
|
243
|
+
xt_value entriesValue = xt_url_entries(thisValue);
|
|
244
|
+
xt_array *entries = xt_as_array(entriesValue);
|
|
245
|
+
uint32_t write = 0;
|
|
246
|
+
int replaced = 0;
|
|
247
|
+
for (uint32_t read = 0; read < entries->length; read++) {
|
|
248
|
+
if (xt_url_key_equals(entries->items[read], key)) {
|
|
249
|
+
if (!replaced) {
|
|
250
|
+
((xt_array *)XT_GET_PTR(entries->items[read]))->items[1] = value;
|
|
251
|
+
entries->items[write++] = entries->items[read];
|
|
252
|
+
replaced = 1;
|
|
253
|
+
}
|
|
254
|
+
continue;
|
|
255
|
+
}
|
|
256
|
+
entries->items[write++] = entries->items[read];
|
|
257
|
+
}
|
|
258
|
+
entries->length = write;
|
|
259
|
+
if (!replaced) xt_url_append_pair(entriesValue, key, value);
|
|
260
|
+
xt_url_set_size(thisValue);
|
|
261
|
+
return XT_UNDEFINED;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
static xt_value xt_url_method_sort(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
265
|
+
(void)env;
|
|
266
|
+
(void)argc;
|
|
267
|
+
(void)argv;
|
|
268
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
269
|
+
for (uint32_t i = 1; i < entries->length; i++) {
|
|
270
|
+
xt_value current = entries->items[i];
|
|
271
|
+
xt_array *currentPair = xt_as_array(current);
|
|
272
|
+
uint32_t j = i;
|
|
273
|
+
while (j > 0) {
|
|
274
|
+
xt_array *previousPair = xt_as_array(entries->items[j - 1]);
|
|
275
|
+
if (strcmp(xt_string_bytes(xt_as_string(previousPair->items[0])),
|
|
276
|
+
xt_string_bytes(xt_as_string(currentPair->items[0]))) <= 0)
|
|
277
|
+
break;
|
|
278
|
+
entries->items[j] = entries->items[j - 1];
|
|
279
|
+
j--;
|
|
280
|
+
}
|
|
281
|
+
entries->items[j] = current;
|
|
282
|
+
}
|
|
283
|
+
return XT_UNDEFINED;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
static xt_value xt_url_method_to_string(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
287
|
+
(void)env;
|
|
288
|
+
(void)argc;
|
|
289
|
+
(void)argv;
|
|
290
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
291
|
+
xt_value out = xt_string_from_cstr("");
|
|
292
|
+
for (uint32_t i = 0; i < entries->length; i++) {
|
|
293
|
+
xt_array *pair = xt_as_array(entries->items[i]);
|
|
294
|
+
if (!pair || pair->length < 2) continue;
|
|
295
|
+
if (i > 0) out = xt_add(out, xt_string_from_cstr("&"));
|
|
296
|
+
out = xt_add(out, xt_url_encode(pair->items[0]));
|
|
297
|
+
out = xt_add(out, xt_string_from_cstr("="));
|
|
298
|
+
out = xt_add(out, xt_url_encode(pair->items[1]));
|
|
299
|
+
}
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
static xt_value xt_url_method_for_each(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
304
|
+
(void)env;
|
|
305
|
+
xt_value callback = xt_arg_at(argc, argv, 0);
|
|
306
|
+
if (!XT_IS_FUNCTION(callback)) return XT_UNDEFINED;
|
|
307
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
308
|
+
for (uint32_t i = 0; i < entries->length; i++) {
|
|
309
|
+
xt_array *pair = xt_as_array(entries->items[i]);
|
|
310
|
+
if (!pair || pair->length < 2) continue;
|
|
311
|
+
xt_value args[3] = {pair->items[1], pair->items[0], thisValue};
|
|
312
|
+
xt_closure_call(callback, 3, args);
|
|
313
|
+
}
|
|
314
|
+
return XT_UNDEFINED;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
static xt_value xt_url_method_keys(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
318
|
+
(void)env;
|
|
319
|
+
(void)argc;
|
|
320
|
+
(void)argv;
|
|
321
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
322
|
+
xt_value result = xt_array_new(0, NULL);
|
|
323
|
+
for (uint32_t i = 0; i < entries->length; i++) {
|
|
324
|
+
xt_array *pair = xt_as_array(entries->items[i]);
|
|
325
|
+
if (pair && pair->length >= 1) xt_array_push(result, pair->items[0]);
|
|
326
|
+
}
|
|
327
|
+
return result;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
static xt_value xt_url_method_values(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
331
|
+
(void)env;
|
|
332
|
+
(void)argc;
|
|
333
|
+
(void)argv;
|
|
334
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
335
|
+
xt_value result = xt_array_new(0, NULL);
|
|
336
|
+
for (uint32_t i = 0; i < entries->length; i++) {
|
|
337
|
+
xt_array *pair = xt_as_array(entries->items[i]);
|
|
338
|
+
if (pair && pair->length >= 2) xt_array_push(result, pair->items[1]);
|
|
339
|
+
}
|
|
340
|
+
return result;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
static xt_value xt_url_method_entries(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
344
|
+
(void)env;
|
|
345
|
+
(void)argc;
|
|
346
|
+
(void)argv;
|
|
347
|
+
xt_value result = xt_array_new(0, NULL);
|
|
348
|
+
xt_array *entries = xt_as_array(xt_url_entries(thisValue));
|
|
349
|
+
for (uint32_t i = 0; i < entries->length; i++) xt_array_push(result, entries->items[i]);
|
|
350
|
+
return result;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
static void xt_url_install(xt_value params, const char *name, void *fn) {
|
|
354
|
+
xt_object_set(params, xt_string_from_cstr(name), xt_closure_new(fn, 0, NULL));
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
xt_value xt_url_search_params_ctor(int32_t argc, xt_value *argv) {
|
|
358
|
+
xt_value params = xt_object_new();
|
|
359
|
+
xt_object_set(params, xt_string_from_cstr("__entries"), xt_array_new(0, NULL));
|
|
360
|
+
xt_object_set(params, xt_string_from_cstr("size"), xt_number(0));
|
|
361
|
+
xt_url_install(params, "append", (void *)xt_url_method_append);
|
|
362
|
+
xt_url_install(params, "delete", (void *)xt_url_method_delete);
|
|
363
|
+
xt_url_install(params, "get", (void *)xt_url_method_get);
|
|
364
|
+
xt_url_install(params, "getAll", (void *)xt_url_method_get_all);
|
|
365
|
+
xt_url_install(params, "has", (void *)xt_url_method_has);
|
|
366
|
+
xt_url_install(params, "set", (void *)xt_url_method_set);
|
|
367
|
+
xt_url_install(params, "sort", (void *)xt_url_method_sort);
|
|
368
|
+
xt_url_install(params, "toString", (void *)xt_url_method_to_string);
|
|
369
|
+
xt_url_install(params, "forEach", (void *)xt_url_method_for_each);
|
|
370
|
+
xt_url_install(params, "keys", (void *)xt_url_method_keys);
|
|
371
|
+
xt_url_install(params, "values", (void *)xt_url_method_values);
|
|
372
|
+
xt_url_install(params, "entries", (void *)xt_url_method_entries);
|
|
373
|
+
xt_url_ctor_from_value(params, xt_arg_at(argc, argv, 0));
|
|
374
|
+
return params;
|
|
375
|
+
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
/* ------------------------------------------------------------------------- */
|
|
4
4
|
|
|
5
5
|
static void xt_throw_mixed_bigint(void) {
|
|
6
|
-
xt_throw(
|
|
6
|
+
xt_throw(xt_error_from_message("TypeError: Cannot mix BigInt and other types, use explicit conversions"));
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/* ToPrimitive for the operators: arrays/objects/functions stringify (their
|
|
@@ -143,7 +143,7 @@ xt_value xt_shr(xt_value a, xt_value b) {
|
|
|
143
143
|
|
|
144
144
|
xt_value xt_ushr(xt_value a, xt_value b) {
|
|
145
145
|
if (XT_IS_BIGINT(a) || XT_IS_BIGINT(b)) {
|
|
146
|
-
xt_throw(
|
|
146
|
+
xt_throw(xt_error_from_message("TypeError: BigInts have no unsigned right shift, use >> instead"));
|
|
147
147
|
return XT_UNDEFINED;
|
|
148
148
|
}
|
|
149
149
|
return xt_number((double)(uint32_t)((uint32_t)xt_to_int32(a) >> (xt_to_int32(b) & 31)));
|
|
@@ -94,7 +94,7 @@ xt_value xt_to_string(xt_value v) {
|
|
|
94
94
|
}
|
|
95
95
|
if (XT_IS_FUNCTION(v)) return xt_string_from_cstr("function () { [native code] }");
|
|
96
96
|
if (xt_is_symbol(v)) {
|
|
97
|
-
xt_throw(
|
|
97
|
+
xt_throw(xt_error_from_message("TypeError: Cannot convert a Symbol value to a string"));
|
|
98
98
|
}
|
|
99
99
|
if (XT_IS_OBJECT(v) &&
|
|
100
100
|
((xt_object *)XT_GET_PTR(v))->header.kind == XT_OBJECT_KIND_ERROR) {
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — weak collections.
|
|
3
|
+
*
|
|
4
|
+
* `WeakMap`, `WeakSet` and `WeakRef` are the only values whose references the
|
|
5
|
+
* mark-sweep collector must *not* follow unconditionally. Their keys (and the
|
|
6
|
+
* target of a WeakRef) are excluded from the ordinary trace; instead the
|
|
7
|
+
* collector runs an ephemeron fixed point after marking:
|
|
8
|
+
*
|
|
9
|
+
* repeat
|
|
10
|
+
* for every live WeakMap entry whose key is marked:
|
|
11
|
+
* mark the value
|
|
12
|
+
* until nothing new is marked
|
|
13
|
+
*
|
|
14
|
+
* A value is therefore retained only while its key is otherwise reachable, and
|
|
15
|
+
* a key/value cycle that is only reachable through the WeakMap is collected.
|
|
16
|
+
* WeakRef targets that stay unmarked after that fixed point are cleared.
|
|
17
|
+
*
|
|
18
|
+
* WeakMap/WeakSet entries are removed at sweep time, so a later `has()` never
|
|
19
|
+
* observes a key whose object has been collected.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "rt_internal.h"
|
|
23
|
+
|
|
24
|
+
#include <stdlib.h>
|
|
25
|
+
#include <string.h>
|
|
26
|
+
|
|
27
|
+
static int xt_is_weak_target(xt_value value) {
|
|
28
|
+
return XT_IS_OBJECT(value) || XT_IS_ARRAY(value) || XT_IS_FUNCTION(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static void xt_weak_key_error(void) {
|
|
32
|
+
xt_throw(xt_error_from_message("TypeError: Invalid value used as weak map key"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
int xt_is_weak_map(xt_value value) {
|
|
36
|
+
return XT_IS_OBJECT(value) &&
|
|
37
|
+
((xt_header *)XT_GET_PTR(value))->kind == XT_OBJECT_KIND_WEAK_MAP;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
int xt_is_weak_set(xt_value value) {
|
|
41
|
+
return XT_IS_OBJECT(value) &&
|
|
42
|
+
((xt_header *)XT_GET_PTR(value))->kind == XT_OBJECT_KIND_WEAK_SET;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
int xt_is_weak_ref(xt_value value) {
|
|
46
|
+
return XT_IS_OBJECT(value) &&
|
|
47
|
+
((xt_header *)XT_GET_PTR(value))->kind == XT_OBJECT_KIND_WEAK_REF;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* -- WeakMap -------------------------------------------------------------- */
|
|
51
|
+
|
|
52
|
+
static int32_t xt_weak_map_index(xt_weak_map *map, xt_value key) {
|
|
53
|
+
for (uint32_t i = 0; i < map->count; i++) {
|
|
54
|
+
if (xt_value_equals(map->keys[i], key)) return (int32_t)i;
|
|
55
|
+
}
|
|
56
|
+
return -1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
static void xt_weak_map_set(xt_weak_map *map, xt_value key, xt_value value) {
|
|
60
|
+
int32_t index = xt_weak_map_index(map, key);
|
|
61
|
+
if (index >= 0) {
|
|
62
|
+
map->values[index] = value;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (map->count >= map->capacity) {
|
|
66
|
+
uint32_t capacity = map->capacity == 0 ? 8 : map->capacity * 2;
|
|
67
|
+
map->keys = (xt_value *)realloc(map->keys, sizeof(xt_value) * capacity);
|
|
68
|
+
map->values = (xt_value *)realloc(map->values, sizeof(xt_value) * capacity);
|
|
69
|
+
if (!map->keys || !map->values) abort();
|
|
70
|
+
map->capacity = capacity;
|
|
71
|
+
}
|
|
72
|
+
map->keys[map->count] = key;
|
|
73
|
+
map->values[map->count] = value;
|
|
74
|
+
map->count++;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static int xt_weak_map_delete(xt_weak_map *map, xt_value key) {
|
|
78
|
+
int32_t index = xt_weak_map_index(map, key);
|
|
79
|
+
if (index < 0) return 0;
|
|
80
|
+
for (uint32_t i = (uint32_t)index + 1; i < map->count; i++) {
|
|
81
|
+
map->keys[i - 1] = map->keys[i];
|
|
82
|
+
map->values[i - 1] = map->values[i];
|
|
83
|
+
}
|
|
84
|
+
map->count--;
|
|
85
|
+
return 1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
xt_value xt_weak_map_ctor(int32_t argc, xt_value *argv) {
|
|
89
|
+
xt_weak_map *map = (xt_weak_map *)xt_alloc(sizeof(xt_weak_map), XT_OBJECT_KIND_WEAK_MAP);
|
|
90
|
+
map->keys = NULL;
|
|
91
|
+
map->values = NULL;
|
|
92
|
+
map->count = 0;
|
|
93
|
+
map->capacity = 0;
|
|
94
|
+
xt_value iterable = xt_arg_at(argc, argv, 0);
|
|
95
|
+
if (XT_IS_ARRAY(iterable)) {
|
|
96
|
+
xt_array *array = (xt_array *)XT_GET_PTR(iterable);
|
|
97
|
+
for (uint32_t i = 0; i < array->length; i++) {
|
|
98
|
+
xt_array *pair = xt_as_array(array->items[i]);
|
|
99
|
+
if (!pair || pair->length < 2) {
|
|
100
|
+
xt_throw(xt_error_from_message("TypeError: Iterator value is not an entry object"));
|
|
101
|
+
return XT_UNDEFINED;
|
|
102
|
+
}
|
|
103
|
+
if (!xt_is_weak_target(pair->items[0])) {
|
|
104
|
+
xt_weak_key_error();
|
|
105
|
+
return XT_UNDEFINED;
|
|
106
|
+
}
|
|
107
|
+
xt_weak_map_set(map, pair->items[0], pair->items[1]);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return XT_FROM_PTR(XT_TAG_OBJECT, map);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/* -- WeakSet -------------------------------------------------------------- */
|
|
114
|
+
|
|
115
|
+
static int32_t xt_weak_set_index(xt_weak_set *set, xt_value value) {
|
|
116
|
+
for (uint32_t i = 0; i < set->count; i++) {
|
|
117
|
+
if (xt_value_equals(set->values[i], value)) return (int32_t)i;
|
|
118
|
+
}
|
|
119
|
+
return -1;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
static void xt_weak_set_add(xt_weak_set *set, xt_value value) {
|
|
123
|
+
if (xt_weak_set_index(set, value) >= 0) return;
|
|
124
|
+
if (set->count >= set->capacity) {
|
|
125
|
+
uint32_t capacity = set->capacity == 0 ? 8 : set->capacity * 2;
|
|
126
|
+
set->values = (xt_value *)realloc(set->values, sizeof(xt_value) * capacity);
|
|
127
|
+
if (!set->values) abort();
|
|
128
|
+
set->capacity = capacity;
|
|
129
|
+
}
|
|
130
|
+
set->values[set->count++] = value;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static int xt_weak_set_delete(xt_weak_set *set, xt_value value) {
|
|
134
|
+
int32_t index = xt_weak_set_index(set, value);
|
|
135
|
+
if (index < 0) return 0;
|
|
136
|
+
for (uint32_t i = (uint32_t)index + 1; i < set->count; i++) {
|
|
137
|
+
set->values[i - 1] = set->values[i];
|
|
138
|
+
}
|
|
139
|
+
set->count--;
|
|
140
|
+
return 1;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
xt_value xt_weak_set_ctor(int32_t argc, xt_value *argv) {
|
|
144
|
+
xt_weak_set *set = (xt_weak_set *)xt_alloc(sizeof(xt_weak_set), XT_OBJECT_KIND_WEAK_SET);
|
|
145
|
+
set->values = NULL;
|
|
146
|
+
set->count = 0;
|
|
147
|
+
set->capacity = 0;
|
|
148
|
+
xt_value iterable = xt_arg_at(argc, argv, 0);
|
|
149
|
+
if (XT_IS_ARRAY(iterable)) {
|
|
150
|
+
xt_array *array = (xt_array *)XT_GET_PTR(iterable);
|
|
151
|
+
for (uint32_t i = 0; i < array->length; i++) {
|
|
152
|
+
if (!xt_is_weak_target(array->items[i])) {
|
|
153
|
+
xt_weak_key_error();
|
|
154
|
+
return XT_UNDEFINED;
|
|
155
|
+
}
|
|
156
|
+
xt_weak_set_add(set, array->items[i]);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return XT_FROM_PTR(XT_TAG_OBJECT, set);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/* -- WeakRef -------------------------------------------------------------- */
|
|
163
|
+
|
|
164
|
+
xt_value xt_weak_ref_ctor(int32_t argc, xt_value *argv) {
|
|
165
|
+
xt_value target = xt_arg_at(argc, argv, 0);
|
|
166
|
+
if (!xt_is_weak_target(target)) {
|
|
167
|
+
xt_throw(xt_error_from_message("TypeError: WeakRef target must be an object"));
|
|
168
|
+
return XT_UNDEFINED;
|
|
169
|
+
}
|
|
170
|
+
xt_weak_ref *ref = (xt_weak_ref *)xt_alloc(sizeof(xt_weak_ref), XT_OBJECT_KIND_WEAK_REF);
|
|
171
|
+
ref->target = target;
|
|
172
|
+
return XT_FROM_PTR(XT_TAG_OBJECT, ref);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
xt_value xt_weak_method(xt_value target, const char *method, int32_t argc, xt_value *argv,
|
|
176
|
+
int *handled) {
|
|
177
|
+
*handled = 1;
|
|
178
|
+
if (xt_is_weak_map(target)) {
|
|
179
|
+
xt_weak_map *map = (xt_weak_map *)XT_GET_PTR(target);
|
|
180
|
+
xt_value key = xt_arg_at(argc, argv, 0);
|
|
181
|
+
if (strcmp(method, "set") == 0) {
|
|
182
|
+
if (!xt_is_weak_target(key)) {
|
|
183
|
+
xt_weak_key_error();
|
|
184
|
+
return XT_UNDEFINED;
|
|
185
|
+
}
|
|
186
|
+
xt_weak_map_set(map, key, xt_arg_at(argc, argv, 1));
|
|
187
|
+
return target;
|
|
188
|
+
}
|
|
189
|
+
if (strcmp(method, "get") == 0) {
|
|
190
|
+
if (!xt_is_weak_target(key)) return XT_UNDEFINED;
|
|
191
|
+
int32_t index = xt_weak_map_index(map, key);
|
|
192
|
+
return index >= 0 ? map->values[index] : XT_UNDEFINED;
|
|
193
|
+
}
|
|
194
|
+
if (strcmp(method, "has") == 0) {
|
|
195
|
+
return xt_bool(xt_is_weak_target(key) && xt_weak_map_index(map, key) >= 0);
|
|
196
|
+
}
|
|
197
|
+
if (strcmp(method, "delete") == 0) {
|
|
198
|
+
return xt_bool(xt_is_weak_target(key) && xt_weak_map_delete(map, key));
|
|
199
|
+
}
|
|
200
|
+
} else if (xt_is_weak_set(target)) {
|
|
201
|
+
xt_weak_set *set = (xt_weak_set *)XT_GET_PTR(target);
|
|
202
|
+
xt_value value = xt_arg_at(argc, argv, 0);
|
|
203
|
+
if (strcmp(method, "add") == 0) {
|
|
204
|
+
if (!xt_is_weak_target(value)) {
|
|
205
|
+
xt_weak_key_error();
|
|
206
|
+
return XT_UNDEFINED;
|
|
207
|
+
}
|
|
208
|
+
xt_weak_set_add(set, value);
|
|
209
|
+
return target;
|
|
210
|
+
}
|
|
211
|
+
if (strcmp(method, "has") == 0) {
|
|
212
|
+
return xt_bool(xt_is_weak_target(value) && xt_weak_set_index(set, value) >= 0);
|
|
213
|
+
}
|
|
214
|
+
if (strcmp(method, "delete") == 0) {
|
|
215
|
+
return xt_bool(xt_is_weak_target(value) && xt_weak_set_delete(set, value));
|
|
216
|
+
}
|
|
217
|
+
} else if (xt_is_weak_ref(target)) {
|
|
218
|
+
if (strcmp(method, "deref") == 0) return ((xt_weak_ref *)XT_GET_PTR(target))->target;
|
|
219
|
+
}
|
|
220
|
+
*handled = 0;
|
|
221
|
+
return XT_UNDEFINED;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/* -- collector integration ------------------------------------------------ */
|
|
225
|
+
|
|
226
|
+
static int xt_weak_heap_value(xt_value value) {
|
|
227
|
+
return XT_IS_STRING(value) || XT_IS_OBJECT(value) || XT_IS_ARRAY(value) ||
|
|
228
|
+
XT_IS_FUNCTION(value) || XT_IS_BIGINT(value);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
int xt_weak_gc_process_once(void) {
|
|
232
|
+
int changed = 0;
|
|
233
|
+
for (xt_header *header = xt_gc_heap_head(); header; header = header->gc_next) {
|
|
234
|
+
if ((header->flags & XT_GC_MARK) == 0) continue;
|
|
235
|
+
if (header->kind != XT_OBJECT_KIND_WEAK_MAP) continue;
|
|
236
|
+
xt_weak_map *map = (xt_weak_map *)header;
|
|
237
|
+
for (uint32_t i = 0; i < map->count; i++) {
|
|
238
|
+
if (!xt_gc_value_is_marked(map->keys[i])) continue;
|
|
239
|
+
xt_value value = map->values[i];
|
|
240
|
+
if (!xt_weak_heap_value(value)) continue;
|
|
241
|
+
if (xt_gc_value_is_marked(value)) continue;
|
|
242
|
+
xt_gc_mark_value(value);
|
|
243
|
+
changed = 1;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return changed;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
void xt_weak_gc_clear(void) {
|
|
250
|
+
for (xt_header *header = xt_gc_heap_head(); header; header = header->gc_next) {
|
|
251
|
+
if ((header->flags & XT_GC_MARK) == 0) continue;
|
|
252
|
+
if (header->kind != XT_OBJECT_KIND_WEAK_REF) continue;
|
|
253
|
+
xt_weak_ref *ref = (xt_weak_ref *)header;
|
|
254
|
+
if (!xt_gc_value_is_marked(ref->target)) ref->target = XT_UNDEFINED;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
void xt_weak_gc_compact(void) {
|
|
259
|
+
for (xt_header *header = xt_gc_heap_head(); header; header = header->gc_next) {
|
|
260
|
+
if ((header->flags & XT_GC_MARK) == 0) continue;
|
|
261
|
+
if (header->kind == XT_OBJECT_KIND_WEAK_MAP) {
|
|
262
|
+
xt_weak_map *map = (xt_weak_map *)header;
|
|
263
|
+
uint32_t write = 0;
|
|
264
|
+
for (uint32_t read = 0; read < map->count; read++) {
|
|
265
|
+
if (!xt_gc_value_is_marked(map->keys[read])) continue;
|
|
266
|
+
map->keys[write] = map->keys[read];
|
|
267
|
+
map->values[write] = map->values[read];
|
|
268
|
+
write++;
|
|
269
|
+
}
|
|
270
|
+
map->count = write;
|
|
271
|
+
} else if (header->kind == XT_OBJECT_KIND_WEAK_SET) {
|
|
272
|
+
xt_weak_set *set = (xt_weak_set *)header;
|
|
273
|
+
uint32_t write = 0;
|
|
274
|
+
for (uint32_t read = 0; read < set->count; read++) {
|
|
275
|
+
if (!xt_gc_value_is_marked(set->values[read])) continue;
|
|
276
|
+
set->values[write++] = set->values[read];
|
|
277
|
+
}
|
|
278
|
+
set->count = write;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|