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