@psnext/slingcli 2.4.20260526-1 → 2.4.20260527-2

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.
Files changed (227) hide show
  1. package/bin/sling.js +4 -1
  2. package/node_modules/@aws-sdk/core/package.json +2 -2
  3. package/node_modules/@aws-sdk/credential-provider-env/package.json +2 -2
  4. package/node_modules/@aws-sdk/credential-provider-http/dist-cjs/fromHttp/fromHttp.js +12 -6
  5. package/node_modules/@aws-sdk/credential-provider-http/dist-es/fromHttp/fromHttp.js +12 -6
  6. package/node_modules/@aws-sdk/credential-provider-http/package.json +3 -2
  7. package/node_modules/@aws-sdk/credential-provider-ini/package.json +9 -9
  8. package/node_modules/@aws-sdk/credential-provider-login/package.json +3 -3
  9. package/node_modules/@aws-sdk/credential-provider-node/package.json +7 -7
  10. package/node_modules/@aws-sdk/credential-provider-process/package.json +2 -2
  11. package/node_modules/@aws-sdk/credential-provider-sso/node_modules/@aws-sdk/token-providers/package.json +3 -3
  12. package/node_modules/@aws-sdk/credential-provider-sso/package.json +4 -4
  13. package/node_modules/@aws-sdk/credential-provider-web-identity/package.json +3 -3
  14. package/node_modules/@aws-sdk/middleware-websocket/package.json +2 -2
  15. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/cognito-identity/index.js +1 -1
  16. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/signin/index.js +1 -1
  17. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso/index.js +1 -1
  18. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sso-oidc/index.js +1 -1
  19. package/node_modules/@aws-sdk/nested-clients/dist-cjs/submodules/sts/index.js +1 -1
  20. package/node_modules/@aws-sdk/nested-clients/package.json +3 -3
  21. package/node_modules/@aws-sdk/signature-v4-multi-region/package.json +1 -2
  22. package/node_modules/@aws-sdk/xml-builder/package.json +2 -2
  23. package/node_modules/@earendil-works/pi-agent-core/dist/harness/compaction/compaction.js +18 -24
  24. package/node_modules/@earendil-works/pi-agent-core/package.json +2 -2
  25. package/node_modules/@earendil-works/pi-ai/dist/cli.js +14 -0
  26. package/node_modules/@earendil-works/pi-ai/dist/models.generated.js +73 -58
  27. package/node_modules/@earendil-works/pi-ai/dist/providers/amazon-bedrock.js +2 -1
  28. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +8 -22
  29. package/node_modules/@earendil-works/pi-ai/dist/providers/azure-openai-responses.js +1 -1
  30. package/node_modules/@earendil-works/pi-ai/dist/providers/images/openrouter.js +1 -1
  31. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-codex-responses.js +60 -40
  32. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-completions.js +1 -1
  33. package/node_modules/@earendil-works/pi-ai/dist/providers/openai-responses.js +1 -1
  34. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/device-code.js +55 -0
  35. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/github-copilot.js +45 -69
  36. package/node_modules/@earendil-works/pi-ai/dist/utils/oauth/index.js +1 -0
  37. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +5 -2
  38. package/node_modules/@earendil-works/pi-ai/package.json +4 -3
  39. package/node_modules/@earendil-works/pi-coding-agent/dist/cli/file-processor.js +2 -3
  40. package/node_modules/@earendil-works/pi-coding-agent/dist/config.js +18 -12
  41. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-runtime.js +2 -1
  42. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session-services.js +3 -2
  43. package/node_modules/@earendil-works/pi-coding-agent/dist/core/agent-session.js +8 -2
  44. package/node_modules/@earendil-works/pi-coding-agent/dist/core/auth-storage.js +2 -1
  45. package/node_modules/@earendil-works/pi-coding-agent/dist/core/compaction/compaction.js +18 -24
  46. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/index.js +8 -6
  47. package/node_modules/@earendil-works/pi-coding-agent/dist/core/export-html/template.js +6 -3
  48. package/node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js +12 -29
  49. package/node_modules/@earendil-works/pi-coding-agent/dist/core/model-registry.js +5 -1
  50. package/node_modules/@earendil-works/pi-coding-agent/dist/core/output-guard.js +52 -22
  51. package/node_modules/@earendil-works/pi-coding-agent/dist/core/package-manager.js +63 -36
  52. package/node_modules/@earendil-works/pi-coding-agent/dist/core/prompt-templates.js +6 -20
  53. package/node_modules/@earendil-works/pi-coding-agent/dist/core/resource-loader.js +38 -31
  54. package/node_modules/@earendil-works/pi-coding-agent/dist/core/sdk.js +9 -4
  55. package/node_modules/@earendil-works/pi-coding-agent/dist/core/session-manager.js +32 -24
  56. package/node_modules/@earendil-works/pi-coding-agent/dist/core/settings-manager.js +6 -13
  57. package/node_modules/@earendil-works/pi-coding-agent/dist/core/skills.js +8 -22
  58. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/bash.js +54 -53
  59. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit-diff.js +8 -1
  60. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/edit.js +44 -81
  61. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/file-mutation-queue.js +27 -12
  62. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/find.js +2 -3
  63. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/grep.js +3 -3
  64. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/ls.js +5 -5
  65. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/output-accumulator.js +9 -3
  66. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/path-utils.js +39 -21
  67. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/read.js +9 -8
  68. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/truncate.js +12 -2
  69. package/node_modules/@earendil-works/pi-coding-agent/dist/core/tools/write.js +20 -35
  70. package/node_modules/@earendil-works/pi-coding-agent/dist/main.js +5 -6
  71. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/config-selector.js +1 -1
  72. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/footer.js +14 -5
  73. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/login-dialog.js +29 -4
  74. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/components/user-message.js +1 -1
  75. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/interactive-mode.js +4 -4
  76. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js +37 -28
  77. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-client.js +64 -7
  78. package/node_modules/@earendil-works/pi-coding-agent/dist/modes/rpc/rpc-mode.js +15 -3
  79. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/clipboard-native.js +14 -8
  80. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-core.js +124 -0
  81. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize-worker.js +31 -0
  82. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/image-resize.js +75 -115
  83. package/node_modules/@earendil-works/pi-coding-agent/dist/utils/paths.js +33 -7
  84. package/node_modules/@earendil-works/pi-coding-agent/npm-shrinkwrap.json +13 -26
  85. package/node_modules/@earendil-works/pi-coding-agent/package.json +6 -6
  86. package/node_modules/@earendil-works/pi-tui/dist/components/editor.js +40 -55
  87. package/node_modules/@earendil-works/pi-tui/dist/components/input.js +2 -2
  88. package/node_modules/@earendil-works/pi-tui/dist/components/markdown.js +12 -2
  89. package/node_modules/@earendil-works/pi-tui/dist/native-modifiers.js +53 -0
  90. package/node_modules/@earendil-works/pi-tui/dist/terminal-image.js +4 -1
  91. package/node_modules/@earendil-works/pi-tui/dist/terminal.js +38 -16
  92. package/node_modules/@earendil-works/pi-tui/dist/utils.js +19 -12
  93. package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-arm64/darwin-modifiers.node +0 -0
  94. package/node_modules/@earendil-works/pi-tui/native/darwin/prebuilds/darwin-x64/darwin-modifiers.node +0 -0
  95. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-arm64/win32-console-mode.node +0 -0
  96. package/node_modules/@earendil-works/pi-tui/native/win32/prebuilds/win32-x64/win32-console-mode.node +0 -0
  97. package/node_modules/@earendil-works/pi-tui/package.json +3 -5
  98. package/node_modules/@smithy/node-http-handler/package.json +2 -2
  99. package/package.json +6 -6
  100. package/slingshot/index.js +246 -244
  101. package/node_modules/koffi/CHANGELOG.md +0 -1093
  102. package/node_modules/koffi/LICENSE.txt +0 -22
  103. package/node_modules/koffi/README.md +0 -43
  104. package/node_modules/koffi/build/koffi/darwin_arm64/koffi.node +0 -0
  105. package/node_modules/koffi/build/koffi/darwin_x64/koffi.node +0 -0
  106. package/node_modules/koffi/build/koffi/freebsd_arm64/koffi.node +0 -0
  107. package/node_modules/koffi/build/koffi/freebsd_ia32/koffi.node +0 -0
  108. package/node_modules/koffi/build/koffi/freebsd_x64/koffi.node +0 -0
  109. package/node_modules/koffi/build/koffi/linux_arm64/koffi.node +0 -0
  110. package/node_modules/koffi/build/koffi/linux_armhf/koffi.node +0 -0
  111. package/node_modules/koffi/build/koffi/linux_ia32/koffi.node +0 -0
  112. package/node_modules/koffi/build/koffi/linux_loong64/koffi.node +0 -0
  113. package/node_modules/koffi/build/koffi/linux_riscv64d/koffi.node +0 -0
  114. package/node_modules/koffi/build/koffi/linux_x64/koffi.node +0 -0
  115. package/node_modules/koffi/build/koffi/musl_arm64/koffi.node +0 -0
  116. package/node_modules/koffi/build/koffi/musl_x64/koffi.node +0 -0
  117. package/node_modules/koffi/build/koffi/openbsd_ia32/koffi.node +0 -0
  118. package/node_modules/koffi/build/koffi/openbsd_x64/koffi.node +0 -0
  119. package/node_modules/koffi/build/koffi/win32_arm64/koffi.exp +0 -0
  120. package/node_modules/koffi/build/koffi/win32_arm64/koffi.lib +0 -0
  121. package/node_modules/koffi/build/koffi/win32_arm64/koffi.node +0 -0
  122. package/node_modules/koffi/build/koffi/win32_ia32/koffi.exp +0 -0
  123. package/node_modules/koffi/build/koffi/win32_ia32/koffi.lib +0 -0
  124. package/node_modules/koffi/build/koffi/win32_ia32/koffi.node +0 -0
  125. package/node_modules/koffi/build/koffi/win32_x64/koffi.exp +0 -0
  126. package/node_modules/koffi/build/koffi/win32_x64/koffi.lib +0 -0
  127. package/node_modules/koffi/build/koffi/win32_x64/koffi.node +0 -0
  128. package/node_modules/koffi/doc/benchmarks.md +0 -126
  129. package/node_modules/koffi/doc/callbacks.md +0 -210
  130. package/node_modules/koffi/doc/contribute.md +0 -148
  131. package/node_modules/koffi/doc/functions.md +0 -250
  132. package/node_modules/koffi/doc/index.md +0 -61
  133. package/node_modules/koffi/doc/input.md +0 -471
  134. package/node_modules/koffi/doc/migration.md +0 -159
  135. package/node_modules/koffi/doc/misc.md +0 -180
  136. package/node_modules/koffi/doc/output.md +0 -305
  137. package/node_modules/koffi/doc/packaging.md +0 -88
  138. package/node_modules/koffi/doc/platforms.md +0 -36
  139. package/node_modules/koffi/doc/pointers.md +0 -328
  140. package/node_modules/koffi/doc/start.md +0 -118
  141. package/node_modules/koffi/doc/unions.md +0 -186
  142. package/node_modules/koffi/doc/variables.md +0 -102
  143. package/node_modules/koffi/index.d.ts +0 -288
  144. package/node_modules/koffi/index.js +0 -634
  145. package/node_modules/koffi/indirect.js +0 -533
  146. package/node_modules/koffi/lib/native/base/base.cc +0 -11015
  147. package/node_modules/koffi/lib/native/base/base.hh +0 -6003
  148. package/node_modules/koffi/lib/native/base/crc.inc +0 -2214
  149. package/node_modules/koffi/lib/native/base/crc_gen.py +0 -72
  150. package/node_modules/koffi/lib/native/base/mimetypes.inc +0 -1248
  151. package/node_modules/koffi/lib/native/base/mimetypes_gen.py +0 -58
  152. package/node_modules/koffi/lib/native/base/tower.cc +0 -821
  153. package/node_modules/koffi/lib/native/base/tower.hh +0 -81
  154. package/node_modules/koffi/lib/native/base/unicode.inc +0 -408
  155. package/node_modules/koffi/lib/native/base/unicode_gen.py +0 -152
  156. package/node_modules/koffi/package.json +0 -38
  157. package/node_modules/koffi/src/cnoke/LICENSE.txt +0 -22
  158. package/node_modules/koffi/src/cnoke/README.md +0 -99
  159. package/node_modules/koffi/src/cnoke/assets/FindCNoke.cmake +0 -127
  160. package/node_modules/koffi/src/cnoke/assets/toolchains.json +0 -126
  161. package/node_modules/koffi/src/cnoke/assets/win_delay_hook.c +0 -36
  162. package/node_modules/koffi/src/cnoke/cnoke.js +0 -170
  163. package/node_modules/koffi/src/cnoke/package.json +0 -24
  164. package/node_modules/koffi/src/cnoke/src/builder.js +0 -511
  165. package/node_modules/koffi/src/cnoke/src/index.js +0 -10
  166. package/node_modules/koffi/src/cnoke/src/tools.js +0 -407
  167. package/node_modules/koffi/src/koffi/CMakeLists.txt +0 -182
  168. package/node_modules/koffi/src/koffi/src/abi_arm32.cc +0 -1018
  169. package/node_modules/koffi/src/koffi/src/abi_arm32_asm.S +0 -169
  170. package/node_modules/koffi/src/koffi/src/abi_arm64.cc +0 -1295
  171. package/node_modules/koffi/src/koffi/src/abi_arm64_asm.S +0 -195
  172. package/node_modules/koffi/src/koffi/src/abi_arm64_asm.asm +0 -174
  173. package/node_modules/koffi/src/koffi/src/abi_loong64.cc +0 -5
  174. package/node_modules/koffi/src/koffi/src/abi_loong64_asm.S +0 -204
  175. package/node_modules/koffi/src/koffi/src/abi_riscv64.cc +0 -915
  176. package/node_modules/koffi/src/koffi/src/abi_riscv64_asm.S +0 -203
  177. package/node_modules/koffi/src/koffi/src/abi_x64_sysv.cc +0 -939
  178. package/node_modules/koffi/src/koffi/src/abi_x64_sysv_asm.S +0 -231
  179. package/node_modules/koffi/src/koffi/src/abi_x64_win.cc +0 -715
  180. package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.S +0 -166
  181. package/node_modules/koffi/src/koffi/src/abi_x64_win_asm.asm +0 -192
  182. package/node_modules/koffi/src/koffi/src/abi_x86.cc +0 -860
  183. package/node_modules/koffi/src/koffi/src/abi_x86_asm.S +0 -193
  184. package/node_modules/koffi/src/koffi/src/abi_x86_asm.asm +0 -177
  185. package/node_modules/koffi/src/koffi/src/call.cc +0 -1326
  186. package/node_modules/koffi/src/koffi/src/call.hh +0 -179
  187. package/node_modules/koffi/src/koffi/src/errno.inc +0 -462
  188. package/node_modules/koffi/src/koffi/src/ffi.cc +0 -2702
  189. package/node_modules/koffi/src/koffi/src/ffi.hh +0 -354
  190. package/node_modules/koffi/src/koffi/src/init.js +0 -105
  191. package/node_modules/koffi/src/koffi/src/parser.cc +0 -220
  192. package/node_modules/koffi/src/koffi/src/parser.hh +0 -54
  193. package/node_modules/koffi/src/koffi/src/util.cc +0 -1807
  194. package/node_modules/koffi/src/koffi/src/util.hh +0 -221
  195. package/node_modules/koffi/src/koffi/src/uv.cc +0 -193
  196. package/node_modules/koffi/src/koffi/src/uv.def +0 -10
  197. package/node_modules/koffi/src/koffi/src/uv.hh +0 -40
  198. package/node_modules/koffi/src/koffi/src/win32.cc +0 -198
  199. package/node_modules/koffi/src/koffi/src/win32.hh +0 -119
  200. package/node_modules/koffi/src/koffi/tools/write_trampolines.js +0 -77
  201. package/node_modules/koffi/vendor/node-addon-api/LICENSE.md +0 -9
  202. package/node_modules/koffi/vendor/node-addon-api/README.md +0 -95
  203. package/node_modules/koffi/vendor/node-addon-api/napi-inl.deprecated.h +0 -186
  204. package/node_modules/koffi/vendor/node-addon-api/napi-inl.h +0 -7033
  205. package/node_modules/koffi/vendor/node-addon-api/napi.h +0 -3309
  206. package/node_modules/koffi/vendor/node-api-headers/LICENSE +0 -21
  207. package/node_modules/koffi/vendor/node-api-headers/README.md +0 -95
  208. package/node_modules/koffi/vendor/node-api-headers/def/js_native_api.def +0 -125
  209. package/node_modules/koffi/vendor/node-api-headers/def/node_api.def +0 -157
  210. package/node_modules/koffi/vendor/node-api-headers/include/js_native_api.h +0 -591
  211. package/node_modules/koffi/vendor/node-api-headers/include/js_native_api_types.h +0 -210
  212. package/node_modules/koffi/vendor/node-api-headers/include/node_api.h +0 -265
  213. package/node_modules/koffi/vendor/node-api-headers/include/node_api_types.h +0 -58
  214. package/node_modules/koffi/vendor/node-api-headers/include/uv/aix.h +0 -32
  215. package/node_modules/koffi/vendor/node-api-headers/include/uv/bsd.h +0 -34
  216. package/node_modules/koffi/vendor/node-api-headers/include/uv/darwin.h +0 -61
  217. package/node_modules/koffi/vendor/node-api-headers/include/uv/errno.h +0 -483
  218. package/node_modules/koffi/vendor/node-api-headers/include/uv/linux.h +0 -34
  219. package/node_modules/koffi/vendor/node-api-headers/include/uv/os390.h +0 -33
  220. package/node_modules/koffi/vendor/node-api-headers/include/uv/posix.h +0 -31
  221. package/node_modules/koffi/vendor/node-api-headers/include/uv/sunos.h +0 -44
  222. package/node_modules/koffi/vendor/node-api-headers/include/uv/threadpool.h +0 -37
  223. package/node_modules/koffi/vendor/node-api-headers/include/uv/tree.h +0 -521
  224. package/node_modules/koffi/vendor/node-api-headers/include/uv/unix.h +0 -512
  225. package/node_modules/koffi/vendor/node-api-headers/include/uv/version.h +0 -43
  226. package/node_modules/koffi/vendor/node-api-headers/include/uv/win.h +0 -698
  227. package/node_modules/koffi/vendor/node-api-headers/include/uv.h +0 -1990
@@ -1,860 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- // SPDX-FileCopyrightText: 2025 Niels Martignène <niels.martignene@protonmail.com>
3
-
4
- #if defined(__i386__) || defined(_M_IX86)
5
-
6
- #include "lib/native/base/base.hh"
7
- #include "ffi.hh"
8
- #include "call.hh"
9
- #include "util.hh"
10
- #if defined(_WIN32)
11
- #include "win32.hh"
12
- #endif
13
-
14
- #include <napi.h>
15
-
16
- namespace K {
17
-
18
- struct BackRegisters {
19
- uint32_t eax;
20
- uint32_t edx;
21
- union {
22
- double d;
23
- float f;
24
- } x87;
25
- int ret_type;
26
- int ret_pop;
27
- };
28
-
29
- extern "C" uint64_t ForwardCallG(const void *func, uint8_t *sp, uint8_t **out_old_sp);
30
- extern "C" float ForwardCallF(const void *func, uint8_t *sp, uint8_t **out_old_sp);
31
- extern "C" double ForwardCallD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
32
- extern "C" uint64_t ForwardCallRG(const void *func, uint8_t *sp, uint8_t **out_old_sp);
33
- extern "C" float ForwardCallRF(const void *func, uint8_t *sp, uint8_t **out_old_sp);
34
- extern "C" double ForwardCallRD(const void *func, uint8_t *sp, uint8_t **out_old_sp);
35
-
36
- bool AnalyseFunction(Napi::Env env, InstanceData *instance, FunctionInfo *func)
37
- {
38
- if (!func->lib && func->convention != CallConvention::Cdecl &&
39
- func->convention != CallConvention::Stdcall) {
40
- ThrowError<Napi::Error>(env, "Only Cdecl and Stdcall callbacks are supported");
41
- return false;
42
- }
43
-
44
- int fast = (func->convention == CallConvention::Fastcall) ? 2 :
45
- (func->convention == CallConvention::Thiscall) ? 1 : 0;
46
- func->fast = fast;
47
-
48
- if (func->ret.type->primitive != PrimitiveKind::Record &&
49
- func->ret.type->primitive != PrimitiveKind::Union) {
50
- func->ret.trivial = true;
51
- #if defined(_WIN32) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
52
- } else {
53
- func->ret.trivial = IsRegularSize(func->ret.type->size, 8);
54
-
55
- #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
56
- if (func->ret.type->members.len == 1) {
57
- const RecordMember &member = func->ret.type->members[0];
58
-
59
- if (member.type->primitive == PrimitiveKind::Float32) {
60
- func->ret.fast = 1;
61
- } else if (member.type->primitive == PrimitiveKind::Float64) {
62
- func->ret.fast = 2;
63
- }
64
- }
65
- #endif
66
- #endif
67
- }
68
- #if !defined(_WIN32)
69
- if (fast && !func->ret.trivial) {
70
- func->ret.fast = 1;
71
- fast--;
72
- }
73
- #endif
74
-
75
- Size params_size = 0;
76
- for (ParameterInfo &param: func->parameters) {
77
- if (fast && param.type->size <= 4) {
78
- param.fast = 1;
79
- fast--;
80
- }
81
-
82
- params_size += std::max(4, AlignLen(param.type->size, 4));
83
- }
84
- func->args_size = params_size + 4 * !func->ret.trivial;
85
-
86
- switch (func->convention) {
87
- case CallConvention::Cdecl: {
88
- func->decorated_name = Fmt(&instance->str_alloc, "_%1", func->name).ptr;
89
- } break;
90
- case CallConvention::Stdcall: {
91
- K_ASSERT(!func->variadic);
92
- func->decorated_name = Fmt(&instance->str_alloc, "_%1@%2", func->name, params_size).ptr;
93
- } break;
94
- case CallConvention::Fastcall: {
95
- K_ASSERT(!func->variadic);
96
- func->decorated_name = Fmt(&instance->str_alloc, "@%1@%2", func->name, params_size).ptr;
97
- func->args_size += 16;
98
- } break;
99
- case CallConvention::Thiscall: {
100
- K_ASSERT(!func->variadic);
101
- func->args_size += 16;
102
- } break;
103
- }
104
-
105
- return true;
106
- }
107
-
108
- bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
109
- {
110
- uint32_t *args_ptr = nullptr;
111
- uint32_t *fast_ptr = nullptr;
112
-
113
- // Pass return value in register or through memory
114
- if (!AllocStack(func->args_size, 16, &args_ptr)) [[unlikely]]
115
- return false;
116
- if (func->fast) {
117
- fast_ptr = args_ptr;
118
- args_ptr += 4;
119
- }
120
- if (!func->ret.trivial) {
121
- return_ptr = AllocHeap(func->ret.type->size, 16);
122
- *((func->ret.fast ? fast_ptr : args_ptr)++) = (uint32_t)return_ptr;
123
- }
124
-
125
- #define PUSH_INTEGER_32(CType) \
126
- do { \
127
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
128
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
129
- return false; \
130
- } \
131
- \
132
- CType v = GetNumber<CType>(value); \
133
- *((param.fast ? fast_ptr : args_ptr)++) = (uint32_t)v; \
134
- } while (false)
135
- #define PUSH_INTEGER_32_SWAP(CType) \
136
- do { \
137
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
138
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
139
- return false; \
140
- } \
141
- \
142
- CType v = GetNumber<CType>(value); \
143
- *((param.fast ? fast_ptr : args_ptr)++) = (uint32_t)ReverseBytes(v); \
144
- } while (false)
145
- #define PUSH_INTEGER_64(CType) \
146
- do { \
147
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
148
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
149
- return false; \
150
- } \
151
- \
152
- CType v = GetNumber<CType>(value); \
153
- \
154
- *(uint64_t *)args_ptr = (uint64_t)v; \
155
- args_ptr += 2; \
156
- } while (false)
157
- #define PUSH_INTEGER_64_SWAP(CType) \
158
- do { \
159
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
160
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
161
- return false; \
162
- } \
163
- \
164
- CType v = GetNumber<CType>(value); \
165
- \
166
- *(uint64_t *)args_ptr = (uint64_t)ReverseBytes(v); \
167
- args_ptr += 2; \
168
- } while (false)
169
-
170
- // Push arguments
171
- for (Size i = 0; i < func->parameters.len; i++) {
172
- const ParameterInfo &param = func->parameters[i];
173
- K_ASSERT(param.directions >= 1 && param.directions <= 3);
174
-
175
- Napi::Value value = info[param.offset];
176
-
177
- switch (param.type->primitive) {
178
- case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
179
-
180
- case PrimitiveKind::Bool: {
181
- if (!value.IsBoolean()) [[unlikely]] {
182
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
183
- return false;
184
- }
185
-
186
- bool b = value.As<Napi::Boolean>();
187
- *(bool *)((param.fast ? fast_ptr : args_ptr)++) = b;
188
- } break;
189
- case PrimitiveKind::Int8: { PUSH_INTEGER_32(int8_t); } break;
190
- case PrimitiveKind::UInt8: { PUSH_INTEGER_32(uint8_t); } break;
191
- case PrimitiveKind::Int16: { PUSH_INTEGER_32(int16_t); } break;
192
- case PrimitiveKind::Int16S: { PUSH_INTEGER_32_SWAP(int16_t); } break;
193
- case PrimitiveKind::UInt16: { PUSH_INTEGER_32(uint16_t); } break;
194
- case PrimitiveKind::UInt16S: { PUSH_INTEGER_32_SWAP(uint16_t); } break;
195
- case PrimitiveKind::Int32: { PUSH_INTEGER_32(int32_t); } break;
196
- case PrimitiveKind::Int32S: { PUSH_INTEGER_32_SWAP(int32_t); } break;
197
- case PrimitiveKind::UInt32: { PUSH_INTEGER_32(uint32_t); } break;
198
- case PrimitiveKind::UInt32S: { PUSH_INTEGER_32_SWAP(uint32_t); } break;
199
- case PrimitiveKind::Int64: { PUSH_INTEGER_64(int64_t); } break;
200
- case PrimitiveKind::Int64S: { PUSH_INTEGER_64_SWAP(int64_t); } break;
201
- case PrimitiveKind::UInt64: { PUSH_INTEGER_64(uint64_t); } break;
202
- case PrimitiveKind::UInt64S: { PUSH_INTEGER_64_SWAP(uint64_t); } break;
203
- case PrimitiveKind::String: {
204
- const char *str;
205
- if (!PushString(value, param.directions, &str)) [[unlikely]]
206
- return false;
207
-
208
- *(const char **)((param.fast ? fast_ptr : args_ptr)++) = str;
209
- } break;
210
- case PrimitiveKind::String16: {
211
- const char16_t *str16;
212
- if (!PushString16(value, param.directions, &str16)) [[unlikely]]
213
- return false;
214
-
215
- *(const char16_t **)((param.fast ? fast_ptr : args_ptr)++) = str16;
216
- } break;
217
- case PrimitiveKind::String32: {
218
- const char32_t *str32;
219
- if (!PushString32(value, param.directions, &str32)) [[unlikely]]
220
- return false;
221
-
222
- *(const char32_t **)((param.fast ? fast_ptr : args_ptr)++) = str32;
223
- } break;
224
- case PrimitiveKind::Pointer: {
225
- void *ptr;
226
- if (!PushPointer(value, param.type, param.directions, &ptr)) [[unlikely]]
227
- return false;
228
-
229
- *(void **)((param.fast ? fast_ptr : args_ptr)++) = ptr;
230
- } break;
231
- case PrimitiveKind::Record:
232
- case PrimitiveKind::Union: {
233
- if (!IsObject(value)) [[unlikely]] {
234
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
235
- return false;
236
- }
237
-
238
- Napi::Object obj = value.As<Napi::Object>();
239
-
240
- if (param.fast) {
241
- uint8_t *ptr = (uint8_t *)(fast_ptr++);
242
- if (!PushObject(obj, param.type, ptr))
243
- return false;
244
- } else {
245
- uint8_t *ptr = (uint8_t *)args_ptr;
246
- if (!PushObject(obj, param.type, ptr))
247
- return false;
248
- args_ptr = (uint32_t *)AlignUp(ptr + param.type->size, 4);
249
- }
250
- } break;
251
- case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
252
- case PrimitiveKind::Float32: {
253
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
254
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
255
- return false;
256
- }
257
-
258
- float f = GetNumber<float>(value);
259
- *(float *)((param.fast ? fast_ptr : args_ptr)++) = f;
260
- } break;
261
- case PrimitiveKind::Float64: {
262
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
263
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
264
- return false;
265
- }
266
-
267
- double d = GetNumber<double>(value);
268
- *(double *)args_ptr = d;
269
- args_ptr += 2;
270
- } break;
271
- case PrimitiveKind::Callback: {
272
- void *ptr;
273
- if (!PushCallback(value, param.type, &ptr)) [[unlikely]]
274
- return false;
275
-
276
- *(void **)((param.fast ? fast_ptr : args_ptr)++) = ptr;
277
- } break;
278
-
279
- case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
280
- }
281
- }
282
-
283
- #undef PUSH_INTEGER_64_SWAP
284
- #undef PUSH_INTEGER_64
285
- #undef PUSH_INTEGER_32_SWAP
286
- #undef PUSH_INTEGER_32
287
-
288
- new_sp = mem->stack.end();
289
-
290
- return true;
291
- }
292
-
293
- void CallData::Execute(const FunctionInfo *func, void *native)
294
- {
295
- #if defined(_WIN32)
296
- TEB *teb = GetTEB();
297
-
298
- // Restore previous stack limits at the end
299
- K_DEFER_C(exception_list = teb->ExceptionList,
300
- base = teb->StackBase,
301
- limit = teb->StackLimit,
302
- dealloc = teb->DeallocationStack,
303
- guaranteed = teb->GuaranteedStackBytes,
304
- stfs = teb->SameTebFlags) {
305
- teb->ExceptionList = exception_list;
306
- teb->StackBase = base;
307
- teb->StackLimit = limit;
308
- teb->DeallocationStack = dealloc;
309
- teb->GuaranteedStackBytes = guaranteed;
310
- teb->SameTebFlags = stfs;
311
-
312
- instance->last_error = teb->LastErrorValue;
313
- };
314
-
315
- // Adjust stack limits so SEH works correctly
316
- teb->ExceptionList = mem->stack0.end() - K_SIZE(SehFrame);
317
- teb->StackBase = mem->stack0.end();
318
- teb->StackLimit = mem->stack0.ptr;
319
- teb->DeallocationStack = mem->stack0.ptr;
320
- teb->GuaranteedStackBytes = 0;
321
- teb->SameTebFlags &= ~0x200;
322
-
323
- teb->LastErrorValue = instance->last_error;
324
- #endif
325
-
326
- #define PERFORM_CALL(Suffix) \
327
- ([&]() { \
328
- auto ret = (func->fast ? ForwardCallR ## Suffix(native, new_sp, &old_sp) \
329
- : ForwardCall ## Suffix(native, new_sp, &old_sp)); \
330
- return ret; \
331
- })()
332
-
333
- // Execute and convert return value
334
- switch (func->ret.type->primitive) {
335
- case PrimitiveKind::Void:
336
- case PrimitiveKind::Bool:
337
- case PrimitiveKind::Int8:
338
- case PrimitiveKind::UInt8:
339
- case PrimitiveKind::Int16:
340
- case PrimitiveKind::Int16S:
341
- case PrimitiveKind::UInt16:
342
- case PrimitiveKind::UInt16S:
343
- case PrimitiveKind::Int32:
344
- case PrimitiveKind::Int32S:
345
- case PrimitiveKind::UInt32:
346
- case PrimitiveKind::UInt32S:
347
- case PrimitiveKind::Int64:
348
- case PrimitiveKind::Int64S:
349
- case PrimitiveKind::UInt64:
350
- case PrimitiveKind::UInt64S:
351
- case PrimitiveKind::String:
352
- case PrimitiveKind::String16:
353
- case PrimitiveKind::String32:
354
- case PrimitiveKind::Pointer:
355
- case PrimitiveKind::Callback: { result.u64 = PERFORM_CALL(G); } break;
356
- #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
357
- case PrimitiveKind::Record:
358
- case PrimitiveKind::Union: {
359
- if (!func->ret.fast) {
360
- result.u64 = PERFORM_CALL(G);
361
- } else if (func->ret.fast == 1) {
362
- result.f = PERFORM_CALL(F);
363
- } else if (func->ret.fast == 2) {
364
- result.d = PERFORM_CALL(D);
365
- } else {
366
- K_UNREACHABLE();
367
- }
368
- } break;
369
- #else
370
- case PrimitiveKind::Record:
371
- case PrimitiveKind::Union: { result.u64 = PERFORM_CALL(G); } break;
372
- #endif
373
- case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
374
- case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
375
- case PrimitiveKind::Float64: { result.d = PERFORM_CALL(D); } break;
376
-
377
- case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
378
- }
379
-
380
- #undef PERFORM_CALL
381
- }
382
-
383
- Napi::Value CallData::Complete(const FunctionInfo *func)
384
- {
385
- K_DEFER {
386
- PopOutArguments();
387
-
388
- if (func->ret.type->dispose) {
389
- func->ret.type->dispose(env, func->ret.type, result.ptr);
390
- }
391
- };
392
-
393
- switch (func->ret.type->primitive) {
394
- case PrimitiveKind::Void: return env.Undefined();
395
- case PrimitiveKind::Bool: return Napi::Boolean::New(env, result.u8 & 0x1);
396
- case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
397
- case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
398
- case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
399
- case PrimitiveKind::Int16S: return Napi::Number::New(env, (double)ReverseBytes(result.i16));
400
- case PrimitiveKind::UInt16: return Napi::Number::New(env, (double)result.u16);
401
- case PrimitiveKind::UInt16S: return Napi::Number::New(env, (double)ReverseBytes(result.u16));
402
- case PrimitiveKind::Int32: return Napi::Number::New(env, (double)result.i32);
403
- case PrimitiveKind::Int32S: return Napi::Number::New(env, (double)ReverseBytes(result.i32));
404
- case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
405
- case PrimitiveKind::UInt32S: return Napi::Number::New(env, (double)ReverseBytes(result.u32));
406
- case PrimitiveKind::Int64: return NewBigInt(env, result.i64);
407
- case PrimitiveKind::Int64S: return NewBigInt(env, ReverseBytes(result.i64));
408
- case PrimitiveKind::UInt64: return NewBigInt(env, result.u64);
409
- case PrimitiveKind::UInt64S: return NewBigInt(env, ReverseBytes(result.u64));
410
- case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
411
- case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
412
- case PrimitiveKind::String32: return result.ptr ? MakeStringFromUTF32(env, (const char32_t *)result.ptr) : env.Null();
413
- case PrimitiveKind::Pointer:
414
- case PrimitiveKind::Callback: {
415
- if (result.ptr) {
416
- Napi::External<void> external = Napi::External<void>::New(env, result.ptr);
417
- SetValueTag(external, func->ret.type->ref.marker);
418
-
419
- return external;
420
- } else {
421
- return env.Null();
422
- }
423
- } break;
424
- case PrimitiveKind::Record:
425
- case PrimitiveKind::Union: {
426
- const uint8_t *ptr = return_ptr ? (const uint8_t *)return_ptr
427
- : (const uint8_t *)&result.buf;
428
-
429
- Napi::Object obj = DecodeObject(env, ptr, func->ret.type);
430
- return obj;
431
- } break;
432
- case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
433
- case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
434
- case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
435
-
436
- case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
437
- }
438
-
439
- K_UNREACHABLE();
440
- }
441
-
442
- void CallData::Relay(Size idx, uint8_t *sp)
443
- {
444
- const TrampolineInfo &trampoline = shared.trampolines[idx];
445
-
446
- uint8_t *caller_sp = sp + 48;
447
- BackRegisters *out_reg = (BackRegisters *)(sp + 16);
448
-
449
- const FunctionInfo *proto = trampoline.proto;
450
- Napi::Function func = trampoline.func.Value();
451
-
452
- uint32_t *args_ptr = (uint32_t *)caller_sp;
453
-
454
- uint8_t *return_ptr = !proto->ret.trivial ? (uint8_t *)args_ptr[0] : nullptr;
455
- args_ptr += !proto->ret.trivial;
456
-
457
- if (proto->convention == CallConvention::Stdcall) {
458
- out_reg->ret_pop = (int)proto->args_size;
459
- } else {
460
- #if defined(_WIN32)
461
- out_reg->ret_pop = 0;
462
- #else
463
- out_reg->ret_pop = return_ptr ? 4 : 0;
464
- #endif
465
- }
466
-
467
- K_DEFER_N(err_guard) {
468
- int pop = out_reg->ret_pop;
469
- memset(out_reg, 0, K_SIZE(*out_reg));
470
- out_reg->ret_type = 0;
471
- out_reg->ret_pop = pop;
472
- };
473
-
474
- LocalArray<napi_value, MaxParameters + 1> arguments;
475
-
476
- arguments.Append(!trampoline.recv.IsEmpty() ? trampoline.recv.Value() : env.Undefined());
477
-
478
- // Convert to JS arguments
479
- for (Size i = 0; i < proto->parameters.len; i++) {
480
- const ParameterInfo &param = proto->parameters[i];
481
- K_ASSERT(param.directions >= 1 && param.directions <= 3);
482
-
483
- switch (param.type->primitive) {
484
- case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
485
-
486
- case PrimitiveKind::Bool: {
487
- bool b = *(bool *)(args_ptr++);
488
-
489
- Napi::Value arg = Napi::Boolean::New(env, b);
490
- arguments.Append(arg);
491
- } break;
492
- case PrimitiveKind::Int8: {
493
- double d = (double)*(int8_t *)(args_ptr++);
494
-
495
- Napi::Value arg = Napi::Number::New(env, d);
496
- arguments.Append(arg);
497
- } break;
498
- case PrimitiveKind::UInt8: {
499
- double d = (double)*(uint8_t *)(args_ptr++);
500
-
501
- Napi::Value arg = Napi::Number::New(env, d);
502
- arguments.Append(arg);
503
- } break;
504
- case PrimitiveKind::Int16: {
505
- double d = (double)*(int16_t *)(args_ptr++);
506
-
507
- Napi::Value arg = Napi::Number::New(env, d);
508
- arguments.Append(arg);
509
- } break;
510
- case PrimitiveKind::Int16S: {
511
- int16_t v = *(int16_t *)(args_ptr++);
512
- double d = (double)ReverseBytes(v);
513
-
514
- Napi::Value arg = Napi::Number::New(env, d);
515
- arguments.Append(arg);
516
- } break;
517
- case PrimitiveKind::UInt16: {
518
- double d = (double)*(uint16_t *)(args_ptr++);
519
-
520
- Napi::Value arg = Napi::Number::New(env, d);
521
- arguments.Append(arg);
522
- } break;
523
- case PrimitiveKind::UInt16S: {
524
- uint16_t v = *(uint16_t *)(args_ptr++);
525
- double d = (double)ReverseBytes(v);
526
-
527
- Napi::Value arg = Napi::Number::New(env, d);
528
- arguments.Append(arg);
529
- } break;
530
- case PrimitiveKind::Int32: {
531
- double d = (double)*(int32_t *)(args_ptr++);
532
-
533
- Napi::Value arg = Napi::Number::New(env, d);
534
- arguments.Append(arg);
535
- } break;
536
- case PrimitiveKind::Int32S: {
537
- int32_t v = *(int32_t *)(args_ptr++);
538
- double d = (double)ReverseBytes(v);
539
-
540
- Napi::Value arg = Napi::Number::New(env, d);
541
- arguments.Append(arg);
542
- } break;
543
- case PrimitiveKind::UInt32: {
544
- double d = (double)*(uint32_t *)(args_ptr++);
545
-
546
- Napi::Value arg = Napi::Number::New(env, d);
547
- arguments.Append(arg);
548
- } break;
549
- case PrimitiveKind::UInt32S: {
550
- uint32_t v = *(uint32_t *)(args_ptr++);
551
- double d = (double)ReverseBytes(v);
552
-
553
- Napi::Value arg = Napi::Number::New(env, d);
554
- arguments.Append(arg);
555
- } break;
556
- case PrimitiveKind::Int64: {
557
- int64_t v = *(int64_t *)args_ptr;
558
- args_ptr += 2;
559
-
560
- Napi::Value arg = NewBigInt(env, v);
561
- arguments.Append(arg);
562
- } break;
563
- case PrimitiveKind::Int64S: {
564
- int64_t v = *(int64_t *)args_ptr;
565
- args_ptr += 2;
566
-
567
- Napi::Value arg = NewBigInt(env, ReverseBytes(v));
568
- arguments.Append(arg);
569
- } break;
570
- case PrimitiveKind::UInt64: {
571
- uint64_t v = *(uint64_t *)args_ptr;
572
- args_ptr += 2;
573
-
574
- Napi::Value arg = NewBigInt(env, v);
575
- arguments.Append(arg);
576
- } break;
577
- case PrimitiveKind::UInt64S: {
578
- uint64_t v = *(uint64_t *)args_ptr;
579
- args_ptr += 2;
580
-
581
- Napi::Value arg = NewBigInt(env, ReverseBytes(v));
582
- arguments.Append(arg);
583
- } break;
584
- case PrimitiveKind::String: {
585
- const char *str = *(const char **)(args_ptr++);
586
-
587
- Napi::Value arg = str ? Napi::String::New(env, str) : env.Null();
588
- arguments.Append(arg);
589
-
590
- if (param.type->dispose) {
591
- param.type->dispose(env, param.type, str);
592
- }
593
- } break;
594
- case PrimitiveKind::String16: {
595
- const char16_t *str16 = *(const char16_t **)(args_ptr++);
596
-
597
- Napi::Value arg = str16 ? Napi::String::New(env, str16) : env.Null();
598
- arguments.Append(arg);
599
-
600
- if (param.type->dispose) {
601
- param.type->dispose(env, param.type, str16);
602
- }
603
- } break;
604
- case PrimitiveKind::String32: {
605
- const char32_t *str32 = *(const char32_t **)(args_ptr++);
606
-
607
- Napi::Value arg = str32 ? MakeStringFromUTF32(env, str32) : env.Null();
608
- arguments.Append(arg);
609
- } break;
610
- case PrimitiveKind::Pointer:
611
- case PrimitiveKind::Callback: {
612
- void *ptr2 = *(void **)(args_ptr++);
613
-
614
- if (ptr2) {
615
- Napi::External<void> external = Napi::External<void>::New(env, ptr2);
616
- SetValueTag(external, param.type->ref.marker);
617
-
618
- arguments.Append(external);
619
- } else {
620
- arguments.Append(env.Null());
621
- }
622
-
623
- if (param.type->dispose) {
624
- param.type->dispose(env, param.type, ptr2);
625
- }
626
- } break;
627
- case PrimitiveKind::Record:
628
- case PrimitiveKind::Union: {
629
- K_ASSERT(!param.fast);
630
-
631
- uint8_t *ptr = (uint8_t *)args_ptr;
632
-
633
- Napi::Object obj2 = DecodeObject(env, ptr, param.type);
634
- arguments.Append(obj2);
635
-
636
- args_ptr = (uint32_t *)AlignUp(ptr + param.type->size, 4);
637
- } break;
638
- case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
639
- case PrimitiveKind::Float32: {
640
- float f = *(float *)(args_ptr++);
641
-
642
- Napi::Value arg = Napi::Number::New(env, (double)f);
643
- arguments.Append(arg);
644
- } break;
645
- case PrimitiveKind::Float64: {
646
- double d = *(double *)args_ptr;
647
- args_ptr += 2;
648
-
649
- Napi::Value arg = Napi::Number::New(env, d);
650
- arguments.Append(arg);
651
- } break;
652
-
653
- case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
654
- }
655
- }
656
-
657
- const TypeInfo *type = proto->ret.type;
658
-
659
- // Make the call!
660
- Napi::Value value = func.Call(arguments[0], arguments.len - 1, arguments.data + 1);
661
-
662
- if (env.IsExceptionPending()) [[unlikely]]
663
- return;
664
-
665
- #define RETURN_INTEGER_32(CType) \
666
- do { \
667
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
668
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
669
- return; \
670
- } \
671
- \
672
- CType v = GetNumber<CType>(value); \
673
- out_reg->eax = (uint32_t)v; \
674
- out_reg->ret_type = 0; \
675
- } while (false)
676
- #define RETURN_INTEGER_32_SWAP(CType) \
677
- do { \
678
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
679
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
680
- return; \
681
- } \
682
- \
683
- CType v = GetNumber<CType>(value); \
684
- out_reg->eax = (uint32_t)ReverseBytes(v); \
685
- out_reg->ret_type = 0; \
686
- } while (false)
687
- #define RETURN_INTEGER_64(CType) \
688
- do { \
689
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
690
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
691
- return; \
692
- } \
693
- \
694
- CType v = GetNumber<CType>(value); \
695
- \
696
- out_reg->eax = (uint32_t)((uint64_t)v >> 32); \
697
- out_reg->edx = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
698
- out_reg->ret_type = 0; \
699
- } while (false)
700
- #define RETURN_INTEGER_64_SWAP(CType) \
701
- do { \
702
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] { \
703
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
704
- return; \
705
- } \
706
- \
707
- CType v = ReverseBytes(GetNumber<CType>(value)); \
708
- \
709
- out_reg->eax = (uint32_t)((uint64_t)v >> 32); \
710
- out_reg->edx = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
711
- out_reg->ret_type = 0; \
712
- } while (false)
713
-
714
- switch (type->primitive) {
715
- case PrimitiveKind::Void: { out_reg->ret_type = 0; } break;
716
- case PrimitiveKind::Bool: {
717
- if (!value.IsBoolean()) [[unlikely]] {
718
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
719
- return;
720
- }
721
-
722
- bool b = value.As<Napi::Boolean>();
723
- out_reg->eax = (uint32_t)b;
724
- out_reg->ret_type = 0;
725
- } break;
726
- case PrimitiveKind::Int8: { RETURN_INTEGER_32(int8_t); } break;
727
- case PrimitiveKind::UInt8: { RETURN_INTEGER_32(uint8_t); } break;
728
- case PrimitiveKind::Int16: { RETURN_INTEGER_32(int16_t); } break;
729
- case PrimitiveKind::Int16S: { RETURN_INTEGER_32_SWAP(int16_t); } break;
730
- case PrimitiveKind::UInt16: { RETURN_INTEGER_32(uint16_t); } break;
731
- case PrimitiveKind::UInt16S: { RETURN_INTEGER_32_SWAP(uint16_t); } break;
732
- case PrimitiveKind::Int32: { RETURN_INTEGER_32(int32_t); } break;
733
- case PrimitiveKind::Int32S: { RETURN_INTEGER_32_SWAP(int32_t); } break;
734
- case PrimitiveKind::UInt32: { RETURN_INTEGER_32(uint32_t); } break;
735
- case PrimitiveKind::UInt32S: { RETURN_INTEGER_32_SWAP(uint32_t); } break;
736
- case PrimitiveKind::Int64: { RETURN_INTEGER_64(int64_t); } break;
737
- case PrimitiveKind::Int64S: { RETURN_INTEGER_64_SWAP(int64_t); } break;
738
- case PrimitiveKind::UInt64: { RETURN_INTEGER_64(uint64_t); } break;
739
- case PrimitiveKind::UInt64S: { RETURN_INTEGER_64_SWAP(uint64_t); } break;
740
- case PrimitiveKind::String: {
741
- const char *str;
742
- if (!PushString(value, 1, &str)) [[unlikely]]
743
- return;
744
-
745
- out_reg->eax = (uint32_t)str;
746
- out_reg->ret_type = 0;
747
- } break;
748
- case PrimitiveKind::String16: {
749
- const char16_t *str16;
750
- if (!PushString16(value, 1, &str16)) [[unlikely]]
751
- return;
752
-
753
- out_reg->eax = (uint32_t)str16;
754
- out_reg->ret_type = 0;
755
- } break;
756
- case PrimitiveKind::String32: {
757
- const char32_t *str32;
758
- if (!PushString32(value, 1, &str32)) [[unlikely]]
759
- return;
760
-
761
- out_reg->eax = (uint32_t)str32;
762
- out_reg->ret_type = 0;
763
- } break;
764
- case PrimitiveKind::Pointer: {
765
- uint8_t *ptr;
766
-
767
- if (CheckValueTag(value, type->ref.marker)) {
768
- ptr = value.As<Napi::External<uint8_t>>().Data();
769
- } else if (IsObject(value) && (type->ref.type->primitive == PrimitiveKind::Record ||
770
- type->ref.type->primitive == PrimitiveKind::Union)) {
771
- Napi::Object obj = value.As<Napi::Object>();
772
-
773
- ptr = AllocHeap(type->ref.type->size, 16);
774
-
775
- if (!PushObject(obj, type->ref.type, ptr))
776
- return;
777
- } else if (IsNullOrUndefined(value)) {
778
- ptr = nullptr;
779
- } else {
780
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
781
- return;
782
- }
783
-
784
- out_reg->eax = (uint32_t)ptr;
785
- out_reg->ret_type = 0;
786
- } break;
787
- case PrimitiveKind::Record:
788
- case PrimitiveKind::Union: {
789
- if (!IsObject(value)) [[unlikely]] {
790
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
791
- return;
792
- }
793
-
794
- Napi::Object obj = value.As<Napi::Object>();
795
-
796
- if (return_ptr) {
797
- if (!PushObject(obj, type, return_ptr))
798
- return;
799
- out_reg->eax = (uint32_t)return_ptr;
800
- } else {
801
- PushObject(obj, type, (uint8_t *)&out_reg->eax);
802
- }
803
-
804
- out_reg->ret_type = 0;
805
- } break;
806
- case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
807
- case PrimitiveKind::Float32: {
808
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
809
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
810
- return;
811
- }
812
-
813
- out_reg->x87.f = GetNumber<float>(value);
814
- out_reg->ret_type = 1;
815
- } break;
816
- case PrimitiveKind::Float64: {
817
- if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
818
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
819
- return;
820
- }
821
-
822
- out_reg->x87.d = GetNumber<double>(value);
823
- out_reg->ret_type = 2;
824
- } break;
825
- case PrimitiveKind::Callback: {
826
- void *ptr;
827
-
828
- if (value.IsFunction()) {
829
- Napi::Function func2 = value.As<Napi::Function>();
830
-
831
- ptr = ReserveTrampoline(type->ref.proto, func2);
832
- if (!ptr) [[unlikely]]
833
- return;
834
- } else if (CheckValueTag(value, type->ref.marker)) {
835
- ptr = value.As<Napi::External<void>>().Data();
836
- } else if (IsNullOrUndefined(value)) {
837
- ptr = nullptr;
838
- } else {
839
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
840
- return;
841
- }
842
-
843
- out_reg->eax = (uint32_t)ptr;
844
- out_reg->ret_type = 0;
845
- } break;
846
-
847
- case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
848
- }
849
-
850
- #undef RETURN_INTEGER_64_SWAP
851
- #undef RETURN_INTEGER_64
852
- #undef RETURN_INTEGER_32_SWAP
853
- #undef RETURN_INTEGER_32
854
-
855
- err_guard.Disable();
856
- }
857
-
858
- }
859
-
860
- #endif