xbintsc 0.6.28 → 0.7.6
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/dist/src/ast/common.d.ts +10 -0
- package/dist/src/binder/declarations.d.ts +1 -0
- package/dist/src/binder/declarations.js +37 -0
- package/dist/src/binder/declarations.js.map +1 -1
- package/dist/src/binder/references.js +12 -0
- package/dist/src/binder/references.js.map +1 -1
- package/dist/src/checker/globals.js +1 -0
- package/dist/src/checker/globals.js.map +1 -1
- package/dist/src/checker/source.js +4 -0
- package/dist/src/checker/source.js.map +1 -1
- package/dist/src/checker/type-system.d.ts +5 -0
- package/dist/src/checker/type-system.js +22 -3
- package/dist/src/checker/type-system.js.map +1 -1
- package/dist/src/cli/help.d.ts +1 -1
- package/dist/src/cli/main.js +15 -3
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/codegen/generator/calls/access.js +29 -11
- package/dist/src/codegen/generator/calls/access.js.map +1 -1
- package/dist/src/codegen/generator/calls/element-inline.d.ts +42 -0
- package/dist/src/codegen/generator/calls/element-inline.js +388 -0
- package/dist/src/codegen/generator/calls/element-inline.js.map +1 -0
- package/dist/src/codegen/generator/calls/invocation.js +95 -1
- package/dist/src/codegen/generator/calls/invocation.js.map +1 -1
- package/dist/src/codegen/generator/calls/super.js +3 -4
- package/dist/src/codegen/generator/calls/super.js.map +1 -1
- package/dist/src/codegen/generator/calls/unwrap.d.ts +18 -0
- package/dist/src/codegen/generator/calls/unwrap.js +45 -0
- package/dist/src/codegen/generator/calls/unwrap.js.map +1 -0
- package/dist/src/codegen/generator/calls.d.ts +3 -1
- package/dist/src/codegen/generator/calls.js +3 -1
- package/dist/src/codegen/generator/calls.js.map +1 -1
- package/dist/src/codegen/generator/debug.js +20 -3
- package/dist/src/codegen/generator/debug.js.map +1 -1
- package/dist/src/codegen/generator/expressions/assignment.js +24 -2
- package/dist/src/codegen/generator/expressions/assignment.js.map +1 -1
- package/dist/src/codegen/generator/expressions/global-values.d.ts +19 -0
- package/dist/src/codegen/generator/expressions/global-values.js +49 -0
- package/dist/src/codegen/generator/expressions/global-values.js.map +1 -0
- package/dist/src/codegen/generator/expressions/module-values.d.ts +6 -0
- package/dist/src/codegen/generator/expressions/module-values.js +51 -17
- package/dist/src/codegen/generator/expressions/module-values.js.map +1 -1
- package/dist/src/codegen/generator/expressions/primary.d.ts +0 -2
- package/dist/src/codegen/generator/expressions/primary.js +13 -29
- package/dist/src/codegen/generator/expressions/primary.js.map +1 -1
- package/dist/src/codegen/generator/expressions.d.ts +2 -1
- package/dist/src/codegen/generator/expressions.js +2 -1
- package/dist/src/codegen/generator/expressions.js.map +1 -1
- package/dist/src/codegen/generator/generator.js +4 -0
- package/dist/src/codegen/generator/generator.js.map +1 -1
- package/dist/src/codegen/generator/layout.d.ts +65 -0
- package/dist/src/codegen/generator/layout.js +50 -0
- package/dist/src/codegen/generator/layout.js.map +1 -0
- package/dist/src/codegen/generator/lookup-tables.d.ts +22 -0
- package/dist/src/codegen/generator/lookup-tables.js +48 -0
- package/dist/src/codegen/generator/lookup-tables.js.map +1 -0
- package/dist/src/codegen/generator/module.js +38 -7
- package/dist/src/codegen/generator/module.js.map +1 -1
- package/dist/src/codegen/generator/state.js +21 -0
- package/dist/src/codegen/generator/state.js.map +1 -1
- package/dist/src/codegen/generator/tables.d.ts +2 -6
- package/dist/src/codegen/generator/tables.js +18 -12
- package/dist/src/codegen/generator/tables.js.map +1 -1
- package/dist/src/diagnostics/diagnostic.js +1 -1
- package/dist/src/diagnostics/diagnostic.js.map +1 -1
- package/dist/src/diagnostics/source-text.d.ts +37 -9
- package/dist/src/diagnostics/source-text.js +124 -23
- package/dist/src/diagnostics/source-text.js.map +1 -1
- package/dist/src/diagnostics/source.d.ts +16 -6
- package/dist/src/diagnostics/source.js +25 -4
- package/dist/src/diagnostics/source.js.map +1 -1
- package/dist/src/driver/build-key.d.ts +14 -0
- package/dist/src/driver/build-key.js +6 -1
- package/dist/src/driver/build-key.js.map +1 -1
- package/dist/src/driver/bundler/commonjs.d.ts +9 -2
- package/dist/src/driver/bundler/commonjs.js +11 -4
- package/dist/src/driver/bundler/commonjs.js.map +1 -1
- package/dist/src/driver/bundler/concatenate.d.ts +20 -0
- package/dist/src/driver/bundler/concatenate.js +79 -8
- package/dist/src/driver/bundler/concatenate.js.map +1 -1
- package/dist/src/driver/bundler/deferred.d.ts +29 -1
- package/dist/src/driver/bundler/deferred.js +114 -5
- package/dist/src/driver/bundler/deferred.js.map +1 -1
- package/dist/src/driver/bundler/dynamic-import.d.ts +6 -0
- package/dist/src/driver/bundler/dynamic-import.js +59 -3
- package/dist/src/driver/bundler/dynamic-import.js.map +1 -1
- package/dist/src/driver/bundler/graph.d.ts +13 -0
- package/dist/src/driver/bundler/graph.js +4 -4
- package/dist/src/driver/bundler/graph.js.map +1 -1
- package/dist/src/driver/bundler/merge.js +43 -13
- package/dist/src/driver/bundler/merge.js.map +1 -1
- package/dist/src/driver/bundler/namespace-object.d.ts +11 -0
- package/dist/src/driver/bundler/namespace-object.js +32 -0
- package/dist/src/driver/bundler/namespace-object.js.map +1 -1
- package/dist/src/driver/bundler/reexport-resolution.js +11 -2
- package/dist/src/driver/bundler/reexport-resolution.js.map +1 -1
- package/dist/src/driver/bundler/symbols.d.ts +4 -0
- package/dist/src/driver/bundler/symbols.js +14 -1
- package/dist/src/driver/bundler/symbols.js.map +1 -1
- package/dist/src/driver/compiler.js +13 -3
- package/dist/src/driver/compiler.js.map +1 -1
- package/dist/src/driver/config.d.ts +1 -1
- package/dist/src/driver/frontend.js +3 -4
- package/dist/src/driver/frontend.js.map +1 -1
- package/dist/src/driver/options.d.ts +1 -4
- package/dist/src/driver/runtime-lib.d.ts +27 -0
- package/dist/src/driver/runtime-lib.js +78 -2
- package/dist/src/driver/runtime-lib.js.map +1 -1
- package/dist/src/driver/runtime-objects.d.ts +1 -1
- package/dist/src/driver/runtime-objects.js +28 -5
- package/dist/src/driver/runtime-objects.js.map +1 -1
- package/dist/src/driver/toolchain.js +28 -5
- package/dist/src/driver/toolchain.js.map +1 -1
- package/dist/src/driver/version.d.ts +1 -1
- package/dist/src/driver/version.js +1 -1
- package/dist/src/driver/version.js.map +1 -1
- package/dist/src/extensions/gui/html.js +42 -10
- package/dist/src/extensions/gui/html.js.map +1 -1
- package/dist/src/extensions/gui/index.js +48 -0
- package/dist/src/extensions/gui/index.js.map +1 -1
- package/dist/src/extensions/node/buffer/index.d.ts +5 -4
- package/dist/src/extensions/node/buffer/index.js +5 -4
- package/dist/src/extensions/node/buffer/index.js.map +1 -1
- package/dist/src/extensions/node/events/index.js +8 -1
- package/dist/src/extensions/node/events/index.js.map +1 -1
- package/dist/src/extensions/node/fs/callbacks.d.ts +9 -0
- package/dist/src/extensions/node/fs/callbacks.js +42 -0
- package/dist/src/extensions/node/fs/callbacks.js.map +1 -0
- package/dist/src/extensions/node/fs/index.d.ts +2 -3
- package/dist/src/extensions/node/fs/index.js +11 -4
- package/dist/src/extensions/node/fs/index.js.map +1 -1
- package/dist/src/extensions/node/process/index.d.ts +10 -3
- package/dist/src/extensions/node/process/index.js +30 -5
- package/dist/src/extensions/node/process/index.js.map +1 -1
- package/dist/src/extensions/registry.d.ts +27 -0
- package/dist/src/extensions/registry.js +13 -4
- package/dist/src/extensions/registry.js.map +1 -1
- package/dist/src/lexer/scanner.d.ts +7 -1
- package/dist/src/lexer/scanner.js +15 -0
- package/dist/src/lexer/scanner.js.map +1 -1
- package/dist/src/parser/context.d.ts +10 -0
- package/dist/src/parser/context.js +42 -3
- package/dist/src/parser/context.js.map +1 -1
- package/dist/src/parser/expressions.js +2 -2
- package/dist/src/parser/expressions.js.map +1 -1
- package/dist/src/parser/helpers.d.ts +8 -0
- package/dist/src/parser/helpers.js +21 -0
- package/dist/src/parser/helpers.js.map +1 -1
- package/dist/src/parser/literals.js +6 -2
- package/dist/src/parser/literals.js.map +1 -1
- package/dist/tests/binder/binder.test.js +43 -0
- package/dist/tests/binder/binder.test.js.map +1 -1
- package/dist/tests/cli/main.test.js +9 -0
- package/dist/tests/cli/main.test.js.map +1 -1
- package/dist/tests/codegen/element-layout.test.d.ts +19 -0
- package/dist/tests/codegen/element-layout.test.js +80 -0
- package/dist/tests/codegen/element-layout.test.js.map +1 -0
- package/dist/tests/codegen/expressions.test.js +25 -0
- package/dist/tests/codegen/expressions.test.js.map +1 -1
- package/dist/tests/codegen/llvm.test.js +28 -0
- package/dist/tests/codegen/llvm.test.js.map +1 -1
- package/dist/tests/diagnostics/diagnostic.test.js +9 -0
- package/dist/tests/diagnostics/diagnostic.test.js.map +1 -1
- package/dist/tests/diagnostics/source-text.test.d.ts +1 -0
- package/dist/tests/diagnostics/source-text.test.js +50 -0
- package/dist/tests/diagnostics/source-text.test.js.map +1 -0
- package/dist/tests/diagnostics/source.test.js +17 -0
- package/dist/tests/diagnostics/source.test.js.map +1 -1
- package/dist/tests/driver/build-key.test.d.ts +1 -0
- package/dist/tests/driver/build-key.test.js +49 -0
- package/dist/tests/driver/build-key.test.js.map +1 -0
- package/dist/tests/driver/bundler-resolve.test.js +12 -0
- package/dist/tests/driver/bundler-resolve.test.js.map +1 -1
- package/dist/tests/driver/commonjs-prelude.test.d.ts +11 -0
- package/dist/tests/driver/commonjs-prelude.test.js +69 -0
- package/dist/tests/driver/commonjs-prelude.test.js.map +1 -0
- package/dist/tests/driver/compiler.test.js +42 -1
- package/dist/tests/driver/compiler.test.js.map +1 -1
- package/dist/tests/driver/html-deferred-cycles.test.d.ts +10 -0
- package/dist/tests/driver/html-deferred-cycles.test.js +75 -0
- package/dist/tests/driver/html-deferred-cycles.test.js.map +1 -0
- package/dist/tests/driver/namespace-type-exports.test.d.ts +9 -0
- package/dist/tests/driver/namespace-type-exports.test.js +59 -0
- package/dist/tests/driver/namespace-type-exports.test.js.map +1 -0
- package/dist/tests/driver/runtime-lib.test.js +49 -1
- package/dist/tests/driver/runtime-lib.test.js.map +1 -1
- package/dist/tests/driver/toolchain.test.js +8 -1
- package/dist/tests/driver/toolchain.test.js.map +1 -1
- package/dist/tests/driver/usage.test.js +2 -1
- package/dist/tests/driver/usage.test.js.map +1 -1
- package/dist/tests/e2e/async-await.test.js +16 -0
- package/dist/tests/e2e/async-await.test.js.map +1 -1
- package/dist/tests/e2e/compile-basics.test.js +53 -0
- package/dist/tests/e2e/compile-basics.test.js.map +1 -1
- package/dist/tests/e2e/compile-builtins.test.js +29 -0
- package/dist/tests/e2e/compile-builtins.test.js.map +1 -1
- package/dist/tests/e2e/compile-deferred-marker.test.d.ts +14 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js +68 -0
- package/dist/tests/e2e/compile-deferred-marker.test.js.map +1 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.d.ts +12 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js +89 -0
- package/dist/tests/e2e/compile-deferred-reexport.test.js.map +1 -0
- package/dist/tests/e2e/compile-error-module.test.d.ts +9 -0
- package/dist/tests/e2e/compile-error-module.test.js +29 -0
- package/dist/tests/e2e/compile-error-module.test.js.map +1 -0
- package/dist/tests/e2e/compile-gc-promises.test.d.ts +11 -0
- package/dist/tests/e2e/compile-gc-promises.test.js +52 -0
- package/dist/tests/e2e/compile-gc-promises.test.js.map +1 -0
- package/dist/tests/e2e/compile-modules.test.js +53 -0
- package/dist/tests/e2e/compile-modules.test.js.map +1 -1
- package/dist/tests/e2e/compile-node-fs-callbacks.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js +46 -0
- package/dist/tests/e2e/compile-node-fs-callbacks.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-inheritance.test.d.ts +6 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js +48 -0
- package/dist/tests/e2e/compile-node-inheritance.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-require.test.d.ts +9 -0
- package/dist/tests/e2e/compile-node-require.test.js +29 -0
- package/dist/tests/e2e/compile-node-require.test.js.map +1 -0
- package/dist/tests/e2e/compile-node-stats.test.d.ts +8 -0
- package/dist/tests/e2e/compile-node-stats.test.js +26 -0
- package/dist/tests/e2e/compile-node-stats.test.js.map +1 -0
- package/dist/tests/e2e/compile-objects-classes.test.js.map +1 -1
- package/dist/tests/e2e/compile-prototype-chain.test.d.ts +8 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js +24 -0
- package/dist/tests/e2e/compile-prototype-chain.test.js.map +1 -0
- package/dist/tests/e2e/compile-proxy.test.d.ts +6 -0
- package/dist/tests/e2e/compile-proxy.test.js +66 -0
- package/dist/tests/e2e/compile-proxy.test.js.map +1 -0
- package/dist/tests/e2e/compile-web-globals.test.d.ts +6 -0
- package/dist/tests/e2e/compile-web-globals.test.js +94 -0
- package/dist/tests/e2e/compile-web-globals.test.js.map +1 -0
- package/dist/tests/e2e/differential-language.test.js +25 -0
- package/dist/tests/e2e/differential-language.test.js.map +1 -1
- package/dist/tests/e2e/differential-values.test.js +59 -0
- package/dist/tests/e2e/differential-values.test.js.map +1 -1
- package/dist/tests/e2e/fetch.test.js +1 -1
- package/dist/tests/e2e/gc.test.js +22 -0
- package/dist/tests/e2e/gc.test.js.map +1 -1
- package/dist/tests/e2e/gui-audio-extra.test.d.ts +12 -0
- package/dist/tests/e2e/gui-audio-extra.test.js +185 -0
- package/dist/tests/e2e/gui-audio-extra.test.js.map +1 -0
- package/dist/tests/e2e/gui-browser.test.js +35 -2
- package/dist/tests/e2e/gui-browser.test.js.map +1 -1
- package/dist/tests/e2e/gui-dom.test.js +88 -0
- package/dist/tests/e2e/gui-dom.test.js.map +1 -1
- package/dist/tests/e2e/gui-script-import-order.test.js +24 -0
- package/dist/tests/e2e/gui-script-import-order.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl-declarations.test.d.ts +13 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js +136 -0
- package/dist/tests/e2e/gui-webgl-declarations.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js +86 -0
- package/dist/tests/e2e/gui-webgl-texture-units.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-blit.test.js +6 -2
- package/dist/tests/e2e/gui-webgl2-blit.test.js.map +1 -1
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.d.ts +12 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js +157 -0
- package/dist/tests/e2e/gui-webgl2-msaa-float.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.d.ts +10 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js +344 -0
- package/dist/tests/e2e/gui-webgl2-msaa.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.d.ts +15 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js +287 -0
- package/dist/tests/e2e/gui-webgl2-target-orientation.test.js.map +1 -0
- package/dist/tests/e2e/gui-webgl2.test.js +59 -1
- package/dist/tests/e2e/gui-webgl2.test.js.map +1 -1
- package/dist/tests/e2e/hang-watchdog.test.d.ts +10 -0
- package/dist/tests/e2e/hang-watchdog.test.js +50 -0
- package/dist/tests/e2e/hang-watchdog.test.js.map +1 -0
- package/dist/tests/e2e/json-stringify-to-json.test.d.ts +10 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js +61 -0
- package/dist/tests/e2e/json-stringify-to-json.test.js.map +1 -0
- package/dist/tests/e2e/method-call-cache.test.d.ts +5 -0
- package/dist/tests/e2e/method-call-cache.test.js +65 -0
- package/dist/tests/e2e/method-call-cache.test.js.map +1 -0
- package/dist/tests/e2e/node-process.test.d.ts +7 -0
- package/dist/tests/e2e/node-process.test.js +50 -0
- package/dist/tests/e2e/node-process.test.js.map +1 -0
- package/dist/tests/e2e/performance-now.test.d.ts +9 -0
- package/dist/tests/e2e/performance-now.test.js +36 -0
- package/dist/tests/e2e/performance-now.test.js.map +1 -0
- package/dist/tests/e2e/property-ic.test.js +33 -0
- package/dist/tests/e2e/property-ic.test.js.map +1 -1
- package/dist/tests/e2e/runtime-coverage-buffer.test.js +31 -0
- package/dist/tests/e2e/runtime-coverage-buffer.test.js.map +1 -1
- package/dist/tests/e2e/shape-interning.test.d.ts +16 -0
- package/dist/tests/e2e/shape-interning.test.js +55 -0
- package/dist/tests/e2e/shape-interning.test.js.map +1 -0
- package/dist/tests/e2e/string-utf16.test.js +9 -0
- package/dist/tests/e2e/string-utf16.test.js.map +1 -1
- package/dist/tests/e2e/typed-array-views.test.js +26 -0
- package/dist/tests/e2e/typed-array-views.test.js.map +1 -1
- package/dist/tests/e2e/url-search-params.test.js +19 -0
- package/dist/tests/e2e/url-search-params.test.js.map +1 -1
- package/dist/tests/e2e/web-streams.test.js +44 -29
- package/dist/tests/e2e/web-streams.test.js.map +1 -1
- package/dist/tests/extensions/gui.test.js +16 -1
- package/dist/tests/extensions/gui.test.js.map +1 -1
- package/dist/tests/helpers.js +1 -0
- package/dist/tests/helpers.js.map +1 -1
- package/dist/tests/parser/expressions.test.js +36 -0
- package/dist/tests/parser/expressions.test.js.map +1 -1
- package/dist/tests/parser/literals.test.js +19 -0
- package/dist/tests/parser/literals.test.js.map +1 -1
- package/dist/tests/parser/statements.test.js +13 -0
- package/dist/tests/parser/statements.test.js.map +1 -1
- package/doc/ai/cli.md +1 -0
- package/doc/ai/contributing.md +8 -5
- package/doc/ai/extensions.md +12 -3
- package/doc/ai/language-support.md +2 -1
- package/doc/ai/troubleshooting.md +14 -0
- package/doc/ai/zh-CN/cli.md +1 -0
- package/doc/ai/zh-CN/contributing.md +6 -3
- package/doc/ai/zh-CN/extensions.md +10 -2
- package/doc/ai/zh-CN/language-support.md +2 -1
- package/doc/ai/zh-CN/troubleshooting.md +12 -0
- package/doc/gui/api.md +26 -4
- package/doc/gui/dom.md +8 -0
- package/doc/gui/known-issues.md +35 -6
- package/doc/gui/runtime.md +16 -1
- package/doc/gui/webgl.md +97 -26
- package/doc/gui-scripts.md +2 -1
- package/doc/gui.md +8 -5
- package/doc/implemented/binder.md +2 -1
- package/doc/implemented/checker.md +14 -0
- package/doc/implemented/codegen.md +7 -0
- package/doc/implemented/lexer.md +1 -1
- package/doc/implemented/modules.md +23 -1
- package/doc/implemented/node/buffer.md +18 -5
- package/doc/implemented/node/fs.md +22 -1
- package/doc/implemented/node/process.md +65 -5
- package/doc/implemented/node.md +7 -1
- package/doc/implemented/operators.md +3 -1
- package/doc/implemented/parser.md +3 -2
- package/doc/implemented/runtime-core.md +13 -2
- package/doc/implemented/stdlib.md +79 -4
- package/doc/implemented/typed-arrays.md +18 -2
- package/doc/unimplemented/classes.md +1 -0
- package/doc/unimplemented/modules.md +1 -0
- package/doc/unimplemented/stdlib.md +2 -1
- package/doc/xbintsc.config.schema.json +5 -0
- package/doc/zh-CN/gui/api.md +19 -5
- package/doc/zh-CN/gui/dom.md +6 -0
- package/doc/zh-CN/gui/known-issues.md +24 -5
- package/doc/zh-CN/gui/runtime.md +13 -1
- package/doc/zh-CN/gui/webgl.md +20 -7
- package/doc/zh-CN/gui-scripts.md +2 -1
- package/doc/zh-CN/gui.md +4 -1
- package/doc/zh-CN/implemented/binder.md +2 -1
- package/doc/zh-CN/implemented/checker.md +10 -0
- package/doc/zh-CN/implemented/codegen.md +7 -0
- package/doc/zh-CN/implemented/lexer.md +1 -1
- package/doc/zh-CN/implemented/modules.md +17 -1
- package/doc/zh-CN/implemented/node/buffer.md +3 -1
- package/doc/zh-CN/implemented/node/fs.md +19 -1
- package/doc/zh-CN/implemented/node/process.md +59 -5
- package/doc/zh-CN/implemented/node.md +1 -1
- package/doc/zh-CN/implemented/operators.md +2 -1
- package/doc/zh-CN/implemented/parser.md +3 -2
- package/doc/zh-CN/implemented/runtime-core.md +10 -2
- package/doc/zh-CN/implemented/stdlib.md +64 -4
- package/doc/zh-CN/implemented/typed-arrays.md +14 -2
- package/doc/zh-CN/unimplemented/classes.md +1 -0
- package/doc/zh-CN/unimplemented/modules.md +1 -0
- package/doc/zh-CN/unimplemented/stdlib.md +2 -1
- package/package.json +7 -7
- package/runtime/ext_gui/audio.cpp +39 -3
- package/runtime/ext_gui/audio_extra.cpp +353 -0
- package/runtime/ext_gui/audio_extra.h +47 -0
- package/runtime/ext_gui/audio_fft.h +76 -0
- package/runtime/ext_gui/audio_internal.h +21 -0
- package/runtime/ext_gui/audio_mixer.cpp +46 -1
- package/runtime/ext_gui/audio_mixer.h +89 -1
- package/runtime/ext_gui/audio_mixer_extra.cpp +126 -0
- package/runtime/ext_gui/audio_nodes.cpp +242 -0
- package/runtime/ext_gui/audio_nodes_internal.h +81 -0
- package/runtime/ext_gui/audio_nodes_spatial.cpp +375 -0
- package/runtime/ext_gui/browser.cpp +9 -0
- package/runtime/ext_gui/browser_screen.cpp +73 -0
- package/runtime/ext_gui/dom_api_canvas.cpp +9 -1
- package/runtime/ext_gui/dom_api_internal.h +3 -0
- package/runtime/ext_gui/dom_api_node.cpp +21 -0
- package/runtime/ext_gui/dom_api_node_read.cpp +29 -0
- package/runtime/ext_gui/dom_api_proto.cpp +3 -0
- package/runtime/ext_gui/dom_api_webgl2.cpp +16 -11
- package/runtime/ext_gui/dom_api_webgl2_msaa.cpp +64 -0
- package/runtime/ext_gui/dom_api_webgl_compressed.cpp +2 -2
- package/runtime/ext_gui/dom_api_webgl_framebuffer.cpp +68 -11
- package/runtime/ext_gui/dom_api_webgl_methods.h +3 -0
- package/runtime/ext_gui/dom_api_webgl_state.cpp +4 -2
- package/runtime/ext_gui/dom_api_webgl_texture.cpp +6 -6
- package/runtime/ext_gui/gui.cpp +6 -1
- package/runtime/ext_gui/gui_engine.h +2 -0
- package/runtime/ext_gui/gui_events.cpp +13 -8
- package/runtime/ext_gui/gui_webgl.cpp +3 -2
- package/runtime/ext_gui/style_ua.cpp +4 -0
- package/runtime/ext_gui/warnings.cpp +1 -1
- package/runtime/ext_gui/webgl.h +102 -7
- package/runtime/ext_gui/webgl_api.h +3 -2
- package/runtime/ext_gui/webgl_blit.cpp +109 -15
- package/runtime/ext_gui/webgl_blit_color.cpp +264 -0
- package/runtime/ext_gui/webgl_blit_depth.cpp +26 -8
- package/runtime/ext_gui/webgl_buffer.cpp +20 -170
- package/runtime/ext_gui/webgl_context.cpp +117 -169
- package/runtime/ext_gui/webgl_draw.cpp +116 -5
- package/runtime/ext_gui/webgl_draw_buffers.cpp +21 -6
- package/runtime/ext_gui/webgl_draw_setup.cpp +1 -0
- package/runtime/ext_gui/webgl_draw_state.h +2 -0
- package/runtime/ext_gui/webgl_feature.cpp +2 -2
- package/runtime/ext_gui/webgl_feature.h +4 -3
- package/runtime/ext_gui/webgl_framebuffer.cpp +346 -0
- package/runtime/ext_gui/webgl_glsl_rewrite.cpp +78 -47
- package/runtime/ext_gui/webgl_objects.h +16 -2
- package/runtime/ext_gui/webgl_pipeline.cpp +1 -1
- package/runtime/ext_gui/webgl_state.cpp +45 -36
- package/runtime/ext_gui/webgl_targets.cpp +440 -0
- package/runtime/ext_gui/webgl_texture.cpp +81 -25
- package/runtime/ext_gui/window.cpp +8 -0
- package/runtime/ext_node/buffer/buffer.c +5 -4
- package/runtime/ext_node/buffer/parts/byte-access.inc +115 -11
- package/runtime/ext_node/buffer/parts/prototype.inc +4 -1
- package/runtime/ext_node/events/events.c +9 -0
- package/runtime/ext_node/fs/callbacks.c +138 -0
- package/runtime/ext_node/fs/fs_ops.c +28 -15
- package/runtime/ext_node/module/module.c +18 -9
- package/runtime/ext_node/process/process.c +117 -32
- package/runtime/ext_node/process/streams.c +370 -0
- package/runtime/ext_node/process/streams.h +20 -0
- package/runtime/rt.h +63 -27
- package/runtime/rt_binary.h +44 -0
- package/runtime/rt_internal.h +61 -69
- package/runtime/rt_object.h +83 -0
- package/runtime/rt_profile.h +45 -0
- package/runtime/xt_alloc.c +154 -181
- package/runtime/xt_array_buffer.c +99 -71
- package/runtime/xt_async_io.c +3 -0
- package/runtime/xt_builtins.c +29 -24
- package/runtime/xt_constructors.c +102 -2
- package/runtime/xt_containers/access.inc +125 -12
- package/runtime/xt_containers/arrays.inc +2 -1
- package/runtime/xt_containers/cstr_cache.inc +56 -0
- package/runtime/xt_containers/function_prototypes.inc +58 -0
- package/runtime/xt_containers/method_cache.inc +121 -0
- package/runtime/xt_containers/object_keys.inc +58 -0
- package/runtime/xt_containers/objects.inc +59 -75
- package/runtime/xt_containers/shapes.inc +153 -8
- package/runtime/xt_containers.c +5 -0
- package/runtime/xt_exit.c +34 -0
- package/runtime/xt_fetch/headers.inc +1 -0
- package/runtime/xt_fetch/response.inc +28 -8
- package/runtime/xt_fetch/webapi.inc +82 -0
- package/runtime/xt_fetch.c +5 -0
- package/runtime/xt_gc_release.c +70 -0
- package/runtime/xt_gc_stack.c +83 -0
- package/runtime/xt_gc_verify.c +136 -0
- package/runtime/xt_intl.c +224 -0
- package/runtime/xt_io/console.inc +66 -0
- package/runtime/xt_io/exception.inc +66 -1
- package/runtime/xt_io/watchdog.inc +101 -0
- package/runtime/xt_io.c +1 -0
- package/runtime/xt_loop.c +23 -3
- package/runtime/xt_module_values.c +82 -0
- package/runtime/xt_pool.c +151 -0
- package/runtime/xt_profile.c +126 -0
- package/runtime/xt_proxy.c +140 -0
- package/runtime/xt_stdlib/dispatch.inc +104 -9
- package/runtime/xt_stdlib/math.inc +272 -57
- package/runtime/xt_stdlib2/date.inc +7 -1
- package/runtime/xt_stdlib2/json.inc +28 -0
- package/runtime/xt_stdlib2/json_stringify.inc +71 -55
- package/runtime/xt_stdlib2/regexp-match.inc +17 -0
- package/runtime/xt_storage/indexed_db.c +4 -1
- package/runtime/xt_structured_clone.c +2 -1
- package/runtime/xt_typed_array/construction.inc +10 -0
- package/runtime/xt_typed_array/elements.inc +43 -23
- package/runtime/xt_url.c +50 -0
- package/runtime/xt_values/constructors.inc +4 -1
- package/runtime/xt_values/strings.inc +3 -1
- package/runtime/xt_web.h +27 -0
- package/runtime/xt_web_abort.c +373 -0
- package/scripts/build-runtime.ts +8 -0
- package/src/ast/common.ts +10 -0
- package/src/binder/declarations.ts +34 -0
- package/src/binder/references.ts +12 -0
- package/src/checker/globals.ts +1 -0
- package/src/checker/source.ts +3 -0
- package/src/checker/type-system.ts +23 -3
- package/src/cli/main.ts +14 -3
- package/src/codegen/generator/calls/access.ts +28 -10
- package/src/codegen/generator/calls/element-inline.ts +433 -0
- package/src/codegen/generator/calls/invocation.ts +99 -1
- package/src/codegen/generator/calls/super.ts +5 -4
- package/src/codegen/generator/calls/unwrap.ts +47 -0
- package/src/codegen/generator/calls.ts +5 -0
- package/src/codegen/generator/debug.ts +21 -3
- package/src/codegen/generator/expressions/assignment.ts +26 -2
- package/src/codegen/generator/expressions/global-values.ts +57 -0
- package/src/codegen/generator/expressions/module-values.ts +57 -19
- package/src/codegen/generator/expressions/primary.ts +13 -36
- package/src/codegen/generator/expressions.ts +3 -0
- package/src/codegen/generator/generator.ts +4 -0
- package/src/codegen/generator/layout.ts +54 -0
- package/src/codegen/generator/lookup-tables.ts +63 -0
- package/src/codegen/generator/module.ts +38 -7
- package/src/codegen/generator/state.ts +22 -0
- package/src/codegen/generator/tables.ts +18 -12
- package/src/diagnostics/diagnostic.ts +1 -1
- package/src/diagnostics/source-text.ts +118 -22
- package/src/diagnostics/source.ts +29 -7
- package/src/driver/build-key.ts +21 -1
- package/src/driver/bundler/commonjs.ts +12 -5
- package/src/driver/bundler/concatenate.ts +96 -12
- package/src/driver/bundler/deferred.ts +122 -6
- package/src/driver/bundler/dynamic-import.ts +75 -2
- package/src/driver/bundler/graph.ts +4 -4
- package/src/driver/bundler/merge.ts +42 -9
- package/src/driver/bundler/namespace-object.ts +44 -0
- package/src/driver/bundler/reexport-resolution.ts +14 -2
- package/src/driver/bundler/symbols.ts +17 -0
- package/src/driver/compiler.ts +14 -3
- package/src/driver/config.ts +1 -1
- package/src/driver/frontend.ts +3 -4
- package/src/driver/options.ts +1 -4
- package/src/driver/runtime-lib.ts +87 -2
- package/src/driver/runtime-objects.ts +28 -5
- package/src/driver/toolchain.ts +28 -5
- package/src/driver/version.ts +1 -1
- package/src/extensions/gui/html.ts +41 -11
- package/src/extensions/gui/index.ts +50 -1
- package/src/extensions/node/buffer/index.ts +5 -4
- package/src/extensions/node/events/index.ts +8 -1
- package/src/extensions/node/fs/callbacks.ts +45 -0
- package/src/extensions/node/fs/index.ts +11 -4
- package/src/extensions/node/process/index.ts +30 -5
- package/src/extensions/registry.ts +41 -4
- package/src/lexer/scanner.ts +16 -1
- package/src/parser/context.ts +39 -3
- package/src/parser/expressions.ts +2 -2
- package/src/parser/helpers.ts +22 -0
- package/src/parser/literals.ts +6 -2
|
@@ -38,8 +38,39 @@ typedef struct {
|
|
|
38
38
|
|
|
39
39
|
static xt_stack_entry g_stack[XT_STACK_MAX_DEPTH];
|
|
40
40
|
static int32_t g_stack_depth = 0;
|
|
41
|
+
/* Bumped on every push/pop so the hang watchdog (`watchdog.inc`) can tell a
|
|
42
|
+
* program that is working from one that is spinning without calling anything. */
|
|
43
|
+
static volatile unsigned long long g_stack_ticks = 0;
|
|
44
|
+
|
|
45
|
+
/* The module whose top-level code is running. Every module of a bundle shares
|
|
46
|
+
* one generated function, so a crash inside a module body would otherwise be
|
|
47
|
+
* reported at the entry file's offsets. Codegen emits one call per module
|
|
48
|
+
* boundary. */
|
|
49
|
+
static const char *g_current_module = NULL;
|
|
50
|
+
|
|
51
|
+
/* Defined in `watchdog.inc`, which is included after this file. */
|
|
52
|
+
static void xt_stack_watchdog_start_once(void);
|
|
53
|
+
|
|
54
|
+
/** Print the shadow stack, innermost frame first (used by the hang watchdog
|
|
55
|
+
* and by hosts that want the JavaScript frames on a fatal signal). */
|
|
56
|
+
static void xt_stack_dump_frames(void) {
|
|
57
|
+
int32_t depth = g_stack_depth;
|
|
58
|
+
if (depth < 0) depth = 0;
|
|
59
|
+
if (depth > XT_STACK_MAX_DEPTH) depth = XT_STACK_MAX_DEPTH;
|
|
60
|
+
for (int32_t index = depth - 1; index >= 0; index--) {
|
|
61
|
+
const xt_stack_entry *entry = &g_stack[index];
|
|
62
|
+
fprintf(stderr, " at %s (%s:%d)\n",
|
|
63
|
+
entry->name && entry->name[0] ? entry->name : "anonymous",
|
|
64
|
+
entry->file && entry->file[0] ? entry->file : "<anonymous>", entry->line);
|
|
65
|
+
}
|
|
66
|
+
if (depth == 0 && g_current_module != NULL) {
|
|
67
|
+
fprintf(stderr, " (no JavaScript frame; module %s)\n", g_current_module);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
41
70
|
|
|
42
71
|
void xt_stack_push(const char *name, const char *file, int32_t line) {
|
|
72
|
+
g_stack_ticks++;
|
|
73
|
+
xt_stack_watchdog_start_once();
|
|
43
74
|
if (g_stack_depth >= XT_STACK_MAX_DEPTH) return;
|
|
44
75
|
xt_stack_entry *entry = &g_stack[g_stack_depth++];
|
|
45
76
|
entry->name = name;
|
|
@@ -48,6 +79,7 @@ void xt_stack_push(const char *name, const char *file, int32_t line) {
|
|
|
48
79
|
}
|
|
49
80
|
|
|
50
81
|
void xt_stack_pop(void) {
|
|
82
|
+
g_stack_ticks++;
|
|
51
83
|
if (g_stack_depth > 0) g_stack_depth--;
|
|
52
84
|
}
|
|
53
85
|
|
|
@@ -64,6 +96,9 @@ void xt_stack_trim(int32_t depth) {
|
|
|
64
96
|
if (depth < g_stack_depth) g_stack_depth = depth;
|
|
65
97
|
}
|
|
66
98
|
|
|
99
|
+
void xt_stack_set_module(const char *name) { g_current_module = name; }
|
|
100
|
+
|
|
101
|
+
|
|
67
102
|
static void xt_stack_append(char **buffer, size_t *length, size_t *capacity, const char *text) {
|
|
68
103
|
size_t count = strlen(text);
|
|
69
104
|
if (*length + count + 1 > *capacity) {
|
|
@@ -90,6 +125,11 @@ xt_value xt_stack_capture(const char *name, const char *message) {
|
|
|
90
125
|
xt_stack_append(&buffer, &length, &capacity, message);
|
|
91
126
|
}
|
|
92
127
|
xt_stack_append(&buffer, &length, &capacity, "\n");
|
|
128
|
+
if (g_current_module != NULL) {
|
|
129
|
+
xt_stack_append(&buffer, &length, &capacity, " module: ");
|
|
130
|
+
xt_stack_append(&buffer, &length, &capacity, g_current_module);
|
|
131
|
+
xt_stack_append(&buffer, &length, &capacity, "\n");
|
|
132
|
+
}
|
|
93
133
|
for (int32_t index = g_stack_depth - 1; index >= 0; index--) {
|
|
94
134
|
const xt_stack_entry *entry = &g_stack[index];
|
|
95
135
|
char line[24];
|
|
@@ -123,6 +163,13 @@ static char g_crash_report[16384];
|
|
|
123
163
|
|
|
124
164
|
static int xt_format_stack(char *out, size_t size) {
|
|
125
165
|
int written = 0;
|
|
166
|
+
/* While a bundle's module bodies run, name the module whose top-level code is
|
|
167
|
+
* executing: every module shares one generated function, so its frames all
|
|
168
|
+
* carry the entry file's coordinates. */
|
|
169
|
+
if (g_current_module != NULL) {
|
|
170
|
+
int count = snprintf(out, size, " module: %s\n", g_current_module);
|
|
171
|
+
if (count > 0) written = count;
|
|
172
|
+
}
|
|
126
173
|
for (int32_t index = g_stack_depth - 1; index >= 0 && written < (int)size; index--) {
|
|
127
174
|
const xt_stack_entry *entry = &g_stack[index];
|
|
128
175
|
int count = snprintf(out + written, size - (size_t)written, " at %s (%s:%d)\n",
|
|
@@ -139,7 +186,24 @@ static int xt_format_stack(char *out, size_t size) {
|
|
|
139
186
|
static LONG WINAPI xt_fatal_exception(EXCEPTION_POINTERS *info) {
|
|
140
187
|
unsigned long code =
|
|
141
188
|
info && info->ExceptionRecord ? (unsigned long)info->ExceptionRecord->ExceptionCode : 0UL;
|
|
142
|
-
int written = snprintf(g_crash_report, sizeof(g_crash_report), "\nxbintsc: fatal exception 0x%08lx\n",
|
|
189
|
+
int written = snprintf(g_crash_report, sizeof(g_crash_report), "\nxbintsc: fatal exception 0x%08lx\n",
|
|
190
|
+
code);
|
|
191
|
+
written += snprintf(g_crash_report + written, sizeof(g_crash_report) - (size_t)written,
|
|
192
|
+
" thread: %s\n", xt_gc_worker_thread ? "I/O worker" : "main");
|
|
193
|
+
/* A fault inside a block the collector already released is a
|
|
194
|
+
* use-after-free; naming the block turns a mystery crash into a lead. */
|
|
195
|
+
if (info && info->ExceptionRecord) {
|
|
196
|
+
unsigned long parameters = (unsigned long)info->ExceptionRecord->NumberParameters;
|
|
197
|
+
uintptr_t access = (uintptr_t)info->ExceptionRecord->ExceptionInformation[0];
|
|
198
|
+
uintptr_t address = (uintptr_t)info->ExceptionRecord->ExceptionInformation[1];
|
|
199
|
+
written += snprintf(g_crash_report + written, sizeof(g_crash_report) - (size_t)written,
|
|
200
|
+
" detail: %lu parameters, access 0x%llx, address 0x%llx\n", parameters,
|
|
201
|
+
(unsigned long long)access, (unsigned long long)address);
|
|
202
|
+
if (address != 0) {
|
|
203
|
+
written += xt_gc_debug_describe(address, g_crash_report + written,
|
|
204
|
+
sizeof(g_crash_report) - (size_t)written);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
143
207
|
written += xt_format_stack(g_crash_report + written, sizeof(g_crash_report) - (size_t)written);
|
|
144
208
|
_write(2, g_crash_report, (unsigned int)written);
|
|
145
209
|
_exit(1);
|
|
@@ -152,6 +216,7 @@ void xt_install_crash_handler(void) { SetUnhandledExceptionFilter(xt_fatal_excep
|
|
|
152
216
|
|
|
153
217
|
static void xt_fatal_signal(int sig) {
|
|
154
218
|
int written = snprintf(g_crash_report, sizeof(g_crash_report), "\nxbintsc: fatal signal %d\n", sig);
|
|
219
|
+
|
|
155
220
|
written += xt_format_stack(g_crash_report + written, sizeof(g_crash_report) - (size_t)written);
|
|
156
221
|
ssize_t ignored = write(STDERR_FILENO, g_crash_report, (size_t)written);
|
|
157
222
|
(void)ignored;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/* ------------------------------------------------------------------------- */
|
|
2
|
+
/* Hang watchdog */
|
|
3
|
+
/* ------------------------------------------------------------------------- */
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* A compiled program that spins — an unexpected infinite loop in user code, a
|
|
7
|
+
* blocking host call, a pathological input — prints nothing at all, and a GUI
|
|
8
|
+
* program merely stops painting. There is no debugger attached and no V8 to
|
|
9
|
+
* request a profile from, so "it hangs" is all the user can report.
|
|
10
|
+
*
|
|
11
|
+
* Setting `XT_STACK_WATCHDOG_MS=<n>` starts a sampler thread that watches the
|
|
12
|
+
* shadow call stack: when no function has been entered or left for `n`
|
|
13
|
+
* milliseconds, it prints the innermost frames (name, file, line). That turns a
|
|
14
|
+
* silent hang into the source location that is spinning.
|
|
15
|
+
*
|
|
16
|
+
* Cost when the variable is unset: one relaxed counter increment per compiled
|
|
17
|
+
* call and nothing else — the thread is not started. The frame array is read
|
|
18
|
+
* from another thread without a lock, which can tear a frame in the middle of
|
|
19
|
+
* an update; that is acceptable for a diagnostic that only runs when asked for.
|
|
20
|
+
* The stack data itself lives in `exception.inc`.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#if !defined(_WIN32)
|
|
24
|
+
#include <pthread.h>
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
static volatile int g_watchdog_started = 0;
|
|
28
|
+
static volatile int g_watchdog_stop = 0;
|
|
29
|
+
|
|
30
|
+
/** Monotonic milliseconds. */
|
|
31
|
+
static unsigned long long xt_watchdog_now_ms(void) {
|
|
32
|
+
#if defined(_WIN32)
|
|
33
|
+
return (unsigned long long)GetTickCount64();
|
|
34
|
+
#else
|
|
35
|
+
struct timespec ts;
|
|
36
|
+
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) return 0;
|
|
37
|
+
return (unsigned long long)ts.tv_sec * 1000ull + (unsigned long long)(ts.tv_nsec / 1000000);
|
|
38
|
+
#endif
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#if defined(_WIN32)
|
|
42
|
+
static unsigned __stdcall xt_watchdog_entry(void *argument) {
|
|
43
|
+
#else
|
|
44
|
+
static void *xt_watchdog_entry(void *argument) {
|
|
45
|
+
#endif
|
|
46
|
+
unsigned long long threshold = (unsigned long long)(uintptr_t)argument;
|
|
47
|
+
unsigned long long interval = threshold / 4;
|
|
48
|
+
if (interval < 20) interval = 20;
|
|
49
|
+
unsigned long long last_ticks = g_stack_ticks;
|
|
50
|
+
unsigned long long idle_since = xt_watchdog_now_ms();
|
|
51
|
+
int sample_all = getenv("XT_STACK_SAMPLE_ALL") != NULL;
|
|
52
|
+
while (!g_watchdog_stop) {
|
|
53
|
+
unsigned long long now;
|
|
54
|
+
#if defined(_WIN32)
|
|
55
|
+
Sleep((DWORD)interval);
|
|
56
|
+
#else
|
|
57
|
+
struct timespec sleep_for;
|
|
58
|
+
sleep_for.tv_sec = (time_t)(interval / 1000);
|
|
59
|
+
sleep_for.tv_nsec = (long)((interval % 1000) * 1000000);
|
|
60
|
+
nanosleep(&sleep_for, NULL);
|
|
61
|
+
#endif
|
|
62
|
+
if (g_watchdog_stop) break;
|
|
63
|
+
now = xt_watchdog_now_ms();
|
|
64
|
+
if (!sample_all && g_stack_ticks != last_ticks) {
|
|
65
|
+
last_ticks = g_stack_ticks;
|
|
66
|
+
idle_since = now;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (!sample_all && now - idle_since < threshold) continue;
|
|
70
|
+
if (sample_all) last_ticks = g_stack_ticks;
|
|
71
|
+
fprintf(stderr, "xt: no JavaScript call for %llu ms, shadow stack:\n", now - idle_since);
|
|
72
|
+
xt_stack_dump_frames();
|
|
73
|
+
fflush(stderr);
|
|
74
|
+
/* Report once per idle period, not once per interval. */
|
|
75
|
+
idle_since = now;
|
|
76
|
+
}
|
|
77
|
+
#if defined(_WIN32)
|
|
78
|
+
return 0;
|
|
79
|
+
#else
|
|
80
|
+
return NULL;
|
|
81
|
+
#endif
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Start the sampler once, if `XT_STACK_WATCHDOG_MS` asks for it. */
|
|
85
|
+
static void xt_stack_watchdog_start_once(void) {
|
|
86
|
+
if (g_watchdog_started) return;
|
|
87
|
+
g_watchdog_started = 1;
|
|
88
|
+
const char *configured = getenv("XT_STACK_WATCHDOG_MS");
|
|
89
|
+
if (configured == NULL || configured[0] == 0) return;
|
|
90
|
+
long ms = strtol(configured, NULL, 10);
|
|
91
|
+
if (ms <= 0) return;
|
|
92
|
+
#if defined(_WIN32)
|
|
93
|
+
uintptr_t handle = _beginthreadex(NULL, 0, xt_watchdog_entry, (void *)(uintptr_t)ms, 0, NULL);
|
|
94
|
+
if (handle != 0) CloseHandle((HANDLE)handle);
|
|
95
|
+
#else
|
|
96
|
+
pthread_t thread;
|
|
97
|
+
if (pthread_create(&thread, NULL, xt_watchdog_entry, (void *)(uintptr_t)ms) == 0) {
|
|
98
|
+
pthread_detach(thread);
|
|
99
|
+
}
|
|
100
|
+
#endif
|
|
101
|
+
}
|
package/runtime/xt_io.c
CHANGED
package/runtime/xt_loop.c
CHANGED
|
@@ -92,9 +92,9 @@ static int64_t xt_loop_now_ms(void) {
|
|
|
92
92
|
#endif
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
/*
|
|
96
|
-
*
|
|
97
|
-
double
|
|
95
|
+
/* Raw fractional monotonic milliseconds: on Windows this is the QPC counter,
|
|
96
|
+
* which counts from machine boot, not from process start. */
|
|
97
|
+
static double xt_raw_monotonic_ms(void) {
|
|
98
98
|
#if defined(_WIN32)
|
|
99
99
|
static LARGE_INTEGER frequency;
|
|
100
100
|
if (frequency.QuadPart == 0) QueryPerformanceFrequency(&frequency);
|
|
@@ -108,6 +108,26 @@ double xt_monotonic_ms(void) {
|
|
|
108
108
|
#endif
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
/* `performance.now()` is relative to the program's own time origin, like a
|
|
112
|
+
* browser's (navigation start) or Node's (process start) — not to machine boot.
|
|
113
|
+
* Before the origin existed, a process started six days into an uptime reported
|
|
114
|
+
* `performance.now() == 521,000,000` on its first call: deltas were still right,
|
|
115
|
+
* so three.js kept working, but every absolute reading was nonsense and any
|
|
116
|
+
* `now() / 1000` (three.js's `clock.elapsedTime`) started at six days. */
|
|
117
|
+
static double g_time_origin_ms = -1.0;
|
|
118
|
+
|
|
119
|
+
void xt_time_init(void) {
|
|
120
|
+
if (g_time_origin_ms < 0.0) g_time_origin_ms = xt_raw_monotonic_ms();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/* Fractional monotonic milliseconds for `performance.now()`. Kept separate from
|
|
124
|
+
* xt_loop_now_ms(), which only needs whole milliseconds for timer deadlines. */
|
|
125
|
+
double xt_monotonic_ms(void) {
|
|
126
|
+
if (g_time_origin_ms < 0.0) g_time_origin_ms = xt_raw_monotonic_ms();
|
|
127
|
+
double elapsed = xt_raw_monotonic_ms() - g_time_origin_ms;
|
|
128
|
+
return elapsed < 0.0 ? 0.0 : elapsed;
|
|
129
|
+
}
|
|
130
|
+
|
|
111
131
|
/* Wall-clock milliseconds since the Unix epoch, for `Date.now()` and
|
|
112
132
|
* `new Date()`. `time(NULL)` only has second resolution, which silently broke
|
|
113
133
|
* elapsed-time math; this keeps the milliseconds the language exposes. */
|
|
@@ -27,3 +27,85 @@ xt_value xt_method_trampoline(xt_value thisValue, xt_value env, int32_t argc, xt
|
|
|
27
27
|
(xt_value (*)(xt_value, int32_t, xt_value *))(uintptr_t)raw;
|
|
28
28
|
return dispatcher(name, argc, argv);
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
/* `import(<expression>)` in a compiled binary.
|
|
32
|
+
*
|
|
33
|
+
* The build links a fixed set of modules; `table` maps every enabled extension
|
|
34
|
+
* module name — bare and with the `node:` prefix — to its namespace object. A
|
|
35
|
+
* specifier that names one of them resolves to that namespace (this is how
|
|
36
|
+
* `import("node:" + "fs")`, the common "load Node built-ins lazily" idiom,
|
|
37
|
+
* works); anything else rejects with a message that names it. */
|
|
38
|
+
xt_value xt_dynamic_import(xt_value table, xt_value specifier) {
|
|
39
|
+
if (XT_IS_STRING(specifier)) {
|
|
40
|
+
xt_value found = xt_get(table, specifier);
|
|
41
|
+
if (found != XT_UNDEFINED && found != XT_NULL) return xt_promise_resolve(found);
|
|
42
|
+
}
|
|
43
|
+
xt_value message = xt_add(
|
|
44
|
+
xt_string_from_cstr("dynamic import of '"),
|
|
45
|
+
xt_add(xt_to_string(specifier),
|
|
46
|
+
xt_string_from_cstr("' is not supported in compiled binaries: "
|
|
47
|
+
"only modules linked into this build can be loaded")));
|
|
48
|
+
xt_value arguments[1];
|
|
49
|
+
arguments[0] = message;
|
|
50
|
+
return xt_promise_reject(xt_error_ctor_by_name(xt_string_from_cstr("Error"), 1, arguments));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Like `xt_fnptr_trampoline`, for a binding declared `void` (the console
|
|
54
|
+
* output methods): call it for its effect and answer `undefined`. */
|
|
55
|
+
xt_value xt_voidptr_trampoline(xt_value thisValue, xt_value env, int32_t argc, xt_value *argv) {
|
|
56
|
+
(void)thisValue;
|
|
57
|
+
xt_value raw = xt_closure_env(env, 0);
|
|
58
|
+
void (*fn)(int32_t, xt_value *) = (void (*)(int32_t, xt_value *))(uintptr_t)raw;
|
|
59
|
+
fn(argc, argv);
|
|
60
|
+
return XT_UNDEFINED;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* `__xt_defer(id, init)`: evaluate `init` once and return its exports.
|
|
64
|
+
*
|
|
65
|
+
* The bundler wraps a module that is only reached through a dynamic import in
|
|
66
|
+
* such a function, so the body runs on the first `import(...)` instead of at
|
|
67
|
+
* startup. The placeholder is published before `init` runs, so a cycle among
|
|
68
|
+
* deferred modules sees the same object rather than recursing. */
|
|
69
|
+
xt_value xt_defer_module(int32_t argc, xt_value *argv) {
|
|
70
|
+
if (argc < 1) return XT_UNDEFINED;
|
|
71
|
+
static xt_value registry = 0;
|
|
72
|
+
if (registry == 0) {
|
|
73
|
+
registry = xt_object_new();
|
|
74
|
+
xt_gc_add_root(®istry);
|
|
75
|
+
}
|
|
76
|
+
xt_value key = xt_to_string(xt_arg(argc, argv, 0));
|
|
77
|
+
|
|
78
|
+
xt_value found = xt_object_get(registry, key);
|
|
79
|
+
if (found != XT_UNDEFINED) return found;
|
|
80
|
+
xt_value exports = xt_object_new();
|
|
81
|
+
xt_object_set(registry, key, exports);
|
|
82
|
+
xt_value init = xt_arg(argc, argv, 1);
|
|
83
|
+
if (XT_IS_FUNCTION(init)) {
|
|
84
|
+
exports = xt_call_with_this(init, XT_UNDEFINED, 0, NULL);
|
|
85
|
+
xt_object_set(registry, key, exports);
|
|
86
|
+
}
|
|
87
|
+
return exports;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/* -- linked-module registry ------------------------------------------------ *
|
|
91
|
+
*
|
|
92
|
+
* A compiled program has no module loader, but the modules linked into it are
|
|
93
|
+
* known: the code generator builds a table mapping every enabled extension
|
|
94
|
+
* module name (bare and `node:`-prefixed) to its namespace object and registers
|
|
95
|
+
* it before the first `createRequire(...)` / computed `import(...)` runs. Both
|
|
96
|
+
* entry points answer from that table instead of failing outright. */
|
|
97
|
+
static xt_value g_module_registry = 0;
|
|
98
|
+
static int g_module_registry_rooted = 0;
|
|
99
|
+
|
|
100
|
+
void xt_module_registry_set(xt_value table) {
|
|
101
|
+
g_module_registry = table;
|
|
102
|
+
if (!g_module_registry_rooted) {
|
|
103
|
+
xt_gc_add_root(&g_module_registry);
|
|
104
|
+
g_module_registry_rooted = 1;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
xt_value xt_module_registry_lookup(xt_value specifier) {
|
|
109
|
+
if (g_module_registry == 0 || !XT_IS_STRING(specifier)) return XT_UNDEFINED;
|
|
110
|
+
return xt_object_get(g_module_registry, specifier);
|
|
111
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — the small-block allocator.
|
|
3
|
+
*
|
|
4
|
+
* The collector in `xt_alloc.c` owns reachability; this unit owns the bytes.
|
|
5
|
+
* Keeping the two apart keeps each file within the repository's size budget and
|
|
6
|
+
* makes the ownership rule explicit: every block either comes from a size-class
|
|
7
|
+
* free list or from `malloc`, and the collector asks this unit to release it.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#include "rt_internal.h"
|
|
11
|
+
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <stdlib.h>
|
|
14
|
+
#include <string.h>
|
|
15
|
+
/* ------------------------------------------------------------------------- */
|
|
16
|
+
/* Small-block pool */
|
|
17
|
+
/* ------------------------------------------------------------------------- */
|
|
18
|
+
|
|
19
|
+
/*
|
|
20
|
+
* Most runtime objects are small — an `xt_object` is ~120 bytes and a closure
|
|
21
|
+
* ~100 — and a scene build creates millions of them. The C allocator charges a
|
|
22
|
+
* lock, a free-list search and zeroing per block, which made object creation
|
|
23
|
+
* the dominant cost of three.js's geometry and level construction. Blocks up
|
|
24
|
+
* to `XT_POOL_SMALL_MAX` are carved out of 1 MiB slabs and recycled through
|
|
25
|
+
* per-class free lists instead; the collector returns a block to its class, so
|
|
26
|
+
* a steady state reuses the same memory.
|
|
27
|
+
*
|
|
28
|
+
* The pool is main-thread only: an I/O worker allocates result values with
|
|
29
|
+
* `calloc` (see `xt_alloc`), and the collector — the only thing that releases
|
|
30
|
+
* blocks — runs on the main thread. Slabs are never returned to the OS; the
|
|
31
|
+
* pool is bounded by the process's peak live set, the same bound the
|
|
32
|
+
* collector's threshold follows.
|
|
33
|
+
*/
|
|
34
|
+
#define XT_POOL_SMALL_MAX 2048
|
|
35
|
+
static const uint16_t xt_pool_sizes[] = {
|
|
36
|
+
16, 32, 48, 64, 80, 96, 112, 128, 160, 192, 224, 256,
|
|
37
|
+
320, 384, 448, 512, 640, 768, 896, 1024, 1280, 1536, 1792, 2048,
|
|
38
|
+
};
|
|
39
|
+
#define XT_POOL_CLASS_COUNT ((int)(sizeof(xt_pool_sizes) / sizeof(xt_pool_sizes[0])))
|
|
40
|
+
static void *g_pool_free[XT_POOL_CLASS_COUNT];
|
|
41
|
+
static unsigned char *g_pool_cursor = NULL;
|
|
42
|
+
static size_t g_pool_left = 0;
|
|
43
|
+
|
|
44
|
+
static int xt_pool_class_of(size_t size) {
|
|
45
|
+
for (int index = 0; index < XT_POOL_CLASS_COUNT; index++) {
|
|
46
|
+
if (size <= (size_t)xt_pool_sizes[index]) return index;
|
|
47
|
+
}
|
|
48
|
+
return -1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** A zeroed block of at least `size` bytes, or NULL when the size is large. */
|
|
52
|
+
void *xt_pool_alloc(size_t size) {
|
|
53
|
+
int cls = xt_pool_class_of(size);
|
|
54
|
+
if (cls < 0) return NULL;
|
|
55
|
+
void *block = g_pool_free[cls];
|
|
56
|
+
if (block != NULL) {
|
|
57
|
+
g_pool_free[cls] = *(void **)block;
|
|
58
|
+
} else {
|
|
59
|
+
size_t need = (size_t)xt_pool_sizes[cls];
|
|
60
|
+
if (g_pool_left < need) {
|
|
61
|
+
size_t chunk = (size_t)1 << 20;
|
|
62
|
+
if (chunk < need) chunk = need;
|
|
63
|
+
g_pool_cursor = (unsigned char *)malloc(chunk);
|
|
64
|
+
if (g_pool_cursor == NULL) return NULL;
|
|
65
|
+
g_pool_left = chunk;
|
|
66
|
+
}
|
|
67
|
+
block = g_pool_cursor;
|
|
68
|
+
g_pool_cursor += need;
|
|
69
|
+
g_pool_left -= need;
|
|
70
|
+
}
|
|
71
|
+
memset(block, 0, size);
|
|
72
|
+
return block;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** Return a block from `xt_pool_alloc` to its class. */
|
|
76
|
+
void xt_pool_free_block(void *block, size_t size) {
|
|
77
|
+
/* Only the main thread owns the pool. A worker never allocates from it, so
|
|
78
|
+
* reaching here on a worker would mean a main-thread block was re-grown
|
|
79
|
+
* there; leaking it is safer than corrupting the free list. */
|
|
80
|
+
if (xt_gc_worker_thread) return;
|
|
81
|
+
int cls = xt_pool_class_of(size);
|
|
82
|
+
if (cls < 0 || block == NULL) return;
|
|
83
|
+
*(void **)block = g_pool_free[cls];
|
|
84
|
+
g_pool_free[cls] = block;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/* ------------------------------------------------------------------------- */
|
|
88
|
+
/* Small-block buffers (property tables, array items) */
|
|
89
|
+
/* ------------------------------------------------------------------------- */
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
* The buffers behind an object's property table and an array's items grow by
|
|
93
|
+
* doubling, so they are allocated outside the collector. They get the same
|
|
94
|
+
* pool treatment through a small private header, which also records where the
|
|
95
|
+
* block came from: a buffer allocated on an I/O worker comes from `malloc` and
|
|
96
|
+
* is released with `free`, while a main-thread buffer is pooled. The 16-byte
|
|
97
|
+
* header keeps the payload 16-byte aligned.
|
|
98
|
+
*/
|
|
99
|
+
typedef struct {
|
|
100
|
+
uint32_t cls;
|
|
101
|
+
uint32_t size;
|
|
102
|
+
uint64_t padding;
|
|
103
|
+
} xt_raw_header;
|
|
104
|
+
|
|
105
|
+
#define XT_RAW_HEADER_SIZE ((size_t)16)
|
|
106
|
+
|
|
107
|
+
void *xt_raw_alloc(size_t size) {
|
|
108
|
+
if (size == 0) size = 1;
|
|
109
|
+
unsigned char *block = NULL;
|
|
110
|
+
if (!xt_gc_worker_thread && size <= XT_POOL_SMALL_MAX) block = (unsigned char *)xt_pool_alloc(size + XT_RAW_HEADER_SIZE);
|
|
111
|
+
if (block == NULL) {
|
|
112
|
+
block = (unsigned char *)malloc(size + XT_RAW_HEADER_SIZE);
|
|
113
|
+
if (block == NULL) {
|
|
114
|
+
fprintf(stderr, "xbintsc: out of memory allocating %zu bytes\n", size);
|
|
115
|
+
abort();
|
|
116
|
+
}
|
|
117
|
+
xt_raw_header *header = (xt_raw_header *)block;
|
|
118
|
+
header->cls = 0xffffffffu;
|
|
119
|
+
header->size = (uint32_t)size;
|
|
120
|
+
header->padding = 0;
|
|
121
|
+
} else {
|
|
122
|
+
xt_raw_header *header = (xt_raw_header *)block;
|
|
123
|
+
header->cls = (uint32_t)xt_pool_class_of(size + XT_RAW_HEADER_SIZE);
|
|
124
|
+
header->size = (uint32_t)size;
|
|
125
|
+
header->padding = 0;
|
|
126
|
+
}
|
|
127
|
+
return block + XT_RAW_HEADER_SIZE;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
void xt_raw_free(void *pointer) {
|
|
131
|
+
if (pointer == NULL) return;
|
|
132
|
+
unsigned char *block = (unsigned char *)pointer - XT_RAW_HEADER_SIZE;
|
|
133
|
+
xt_raw_header *header = (xt_raw_header *)block;
|
|
134
|
+
if (header->cls == 0xffffffffu) {
|
|
135
|
+
free(block);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
xt_pool_free_block(block, (size_t)header->size + XT_RAW_HEADER_SIZE);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
void *xt_raw_realloc(void *pointer, size_t new_size) {
|
|
142
|
+
if (pointer == NULL) return xt_raw_alloc(new_size);
|
|
143
|
+
unsigned char *block = (unsigned char *)pointer - XT_RAW_HEADER_SIZE;
|
|
144
|
+
xt_raw_header *header = (xt_raw_header *)block;
|
|
145
|
+
size_t old_size = (size_t)header->size;
|
|
146
|
+
void *grown = xt_raw_alloc(new_size);
|
|
147
|
+
memcpy(grown, pointer, old_size < new_size ? old_size : new_size);
|
|
148
|
+
xt_raw_free(pointer);
|
|
149
|
+
return grown;
|
|
150
|
+
}
|
|
151
|
+
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* xbintsc runtime — opt-in call counters for performance work.
|
|
3
|
+
*
|
|
4
|
+
* `XT_PROFILE=1` increments one counter per entry of the runtime's hottest
|
|
5
|
+
* helpers and prints the totals at exit. A counter is one branch and one
|
|
6
|
+
* increment, so a profiled run keeps the shape of the workload; pair the counts
|
|
7
|
+
* with a microbenchmark of the same helper to attribute time.
|
|
8
|
+
*
|
|
9
|
+
* This is diagnostics, not a feature: the counters are off unless the variable
|
|
10
|
+
* is set, and the dump goes to stderr.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
#include "rt_internal.h"
|
|
14
|
+
|
|
15
|
+
#include <stdio.h>
|
|
16
|
+
#include <stdlib.h>
|
|
17
|
+
#include <string.h>
|
|
18
|
+
|
|
19
|
+
#define XT_PROFILE_KEY_SLOTS 512
|
|
20
|
+
#define XT_PROFILE_KEY_PROBES 8
|
|
21
|
+
|
|
22
|
+
typedef struct {
|
|
23
|
+
char *key;
|
|
24
|
+
unsigned long long count;
|
|
25
|
+
} xt_profile_key;
|
|
26
|
+
|
|
27
|
+
static xt_profile_key g_keys[XT_PROFILE_KEY_SLOTS];
|
|
28
|
+
static unsigned long long g_alloc_kinds[32];
|
|
29
|
+
|
|
30
|
+
int xt_profile_on = 0;
|
|
31
|
+
unsigned long long xt_profile_calls[XT_PROFILE_COUNT];
|
|
32
|
+
|
|
33
|
+
void xt_profile_note_alloc(int kind) {
|
|
34
|
+
if (!xt_profile_on) return;
|
|
35
|
+
if (kind >= 0 && kind < 32) g_alloc_kinds[kind]++;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void xt_profile_note_cstr(const char *key) {
|
|
39
|
+
if (!xt_profile_on || key == NULL) return;
|
|
40
|
+
uint64_t hash = 1469598103934665603ull;
|
|
41
|
+
for (const char *p = key; *p != '\0'; p++) {
|
|
42
|
+
hash ^= (unsigned char)*p;
|
|
43
|
+
hash *= 1099511628211ull;
|
|
44
|
+
}
|
|
45
|
+
const size_t start = (size_t)(hash & (XT_PROFILE_KEY_SLOTS - 1));
|
|
46
|
+
for (size_t probe = 0; probe < XT_PROFILE_KEY_PROBES; probe++) {
|
|
47
|
+
xt_profile_key *slot = &g_keys[(start + probe) & (XT_PROFILE_KEY_SLOTS - 1)];
|
|
48
|
+
if (slot->key == NULL) {
|
|
49
|
+
const size_t length = strlen(key) + 1;
|
|
50
|
+
char *copy = (char *)malloc(length);
|
|
51
|
+
if (copy == NULL) return;
|
|
52
|
+
memcpy(copy, key, length);
|
|
53
|
+
slot->key = copy;
|
|
54
|
+
slot->count = 1;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (strcmp(slot->key, key) == 0) {
|
|
58
|
+
slot->count++;
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
static const char *const xt_profile_kind_names[32] = {
|
|
65
|
+
"none", "string", "object", "array", "function",
|
|
66
|
+
"promise", "map", "set", "date", "regexp",
|
|
67
|
+
"symbol", "bigint", "error", "generator", "iterator",
|
|
68
|
+
"async", "async-iter", "weak-map", "weak-set", "weak-ref",
|
|
69
|
+
"array-buffer",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
static const char *const xt_profile_names[XT_PROFILE_COUNT] = {
|
|
73
|
+
"alloc",
|
|
74
|
+
"gc",
|
|
75
|
+
"math",
|
|
76
|
+
"set",
|
|
77
|
+
"get-ic",
|
|
78
|
+
"method-ic",
|
|
79
|
+
"object-set",
|
|
80
|
+
"object-insert",
|
|
81
|
+
"object-find",
|
|
82
|
+
"object-reserve",
|
|
83
|
+
"closure-call",
|
|
84
|
+
"array-get",
|
|
85
|
+
"string-cstr",
|
|
86
|
+
"typed-read",
|
|
87
|
+
"typed-write",
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
static void xt_profile_dump(void) {
|
|
91
|
+
if (!xt_profile_on) return;
|
|
92
|
+
for (int i = 0; i < XT_PROFILE_COUNT; i++) {
|
|
93
|
+
if (xt_profile_calls[i] == 0) continue;
|
|
94
|
+
fprintf(stderr, "xt_profile: %-14s %llu\n", xt_profile_names[i], xt_profile_calls[i]);
|
|
95
|
+
}
|
|
96
|
+
for (int kind = 0; kind < 32; kind++) {
|
|
97
|
+
if (g_alloc_kinds[kind] == 0) continue;
|
|
98
|
+
const char *name = kind < (int)(sizeof(xt_profile_kind_names) / sizeof(char *))
|
|
99
|
+
? xt_profile_kind_names[kind]
|
|
100
|
+
: "other";
|
|
101
|
+
fprintf(stderr, "xt_profile: alloc %-12s %llu\n", name, g_alloc_kinds[kind]);
|
|
102
|
+
}
|
|
103
|
+
/* The twenty most frequent C-string property names: each was an allocated
|
|
104
|
+
* xt_string unless the runtime interns it. */
|
|
105
|
+
for (int rank = 0; rank < 20; rank++) {
|
|
106
|
+
long best = -1;
|
|
107
|
+
unsigned long long best_count = 0;
|
|
108
|
+
for (int i = 0; i < XT_PROFILE_KEY_SLOTS; i++) {
|
|
109
|
+
if (g_keys[i].key == NULL || g_keys[i].count == 0) continue;
|
|
110
|
+
if (g_keys[i].count > best_count) {
|
|
111
|
+
best_count = g_keys[i].count;
|
|
112
|
+
best = i;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (best < 0) break;
|
|
116
|
+
fprintf(stderr, "xt_profile: key %-24s %llu\n", g_keys[best].key, g_keys[best].count);
|
|
117
|
+
g_keys[best].count = 0;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
void xt_profile_init(void) {
|
|
122
|
+
const char *env = getenv("XT_PROFILE");
|
|
123
|
+
if (env == NULL || env[0] == '\0' || env[0] == '0') return;
|
|
124
|
+
xt_profile_on = 1;
|
|
125
|
+
atexit(xt_profile_dump);
|
|
126
|
+
}
|