koffi 2.1.0-beta.2 → 2.1.0-beta.3
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/ChangeLog.md +2 -2
- package/build/qemu/2.1.0-beta.3/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.3/koffi_win32_x64.tar.gz +0 -0
- package/doc/Makefile +1 -1
- package/doc/conf.py +5 -0
- package/doc/dist/doctrees/changes.doctree +0 -0
- package/doc/dist/doctrees/environment.pickle +0 -0
- package/doc/dist/doctrees/functions.doctree +0 -0
- package/doc/dist/doctrees/index.doctree +0 -0
- package/doc/dist/doctrees/types.doctree +0 -0
- package/doc/dist/html/.buildinfo +4 -0
- package/doc/dist/html/_sources/benchmarks.md.txt +137 -0
- package/doc/dist/html/_sources/changes.md.txt +161 -0
- package/doc/dist/html/_sources/contribute.md.txt +127 -0
- package/doc/dist/html/_sources/functions.md.txt +421 -0
- package/doc/dist/html/_sources/index.rst.txt +39 -0
- package/doc/dist/html/_sources/memory.md.txt +32 -0
- package/doc/dist/html/_sources/platforms.md.txt +31 -0
- package/doc/dist/html/_sources/start.md.txt +100 -0
- package/doc/dist/html/_sources/types.md.txt +541 -0
- package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +134 -0
- package/doc/dist/html/_static/basic.css +932 -0
- package/doc/dist/html/_static/bench_linux.png +0 -0
- package/doc/dist/html/_static/bench_windows.png +0 -0
- package/doc/dist/html/_static/custom.css +22 -0
- package/doc/dist/html/_static/debug.css +69 -0
- package/doc/dist/html/_static/doctools.js +264 -0
- package/doc/dist/html/_static/documentation_options.js +14 -0
- package/doc/dist/html/_static/file.png +0 -0
- package/doc/dist/html/_static/jquery-3.6.0.js +10881 -0
- package/doc/dist/html/_static/jquery.js +2 -0
- package/doc/dist/html/_static/language_data.js +199 -0
- package/doc/dist/html/_static/minus.png +0 -0
- package/doc/dist/html/_static/perf_linux_20220623.png +0 -0
- package/doc/dist/html/_static/perf_linux_20220623_2.png +0 -0
- package/doc/dist/html/_static/perf_windows_20220623.png +0 -0
- package/doc/dist/html/_static/perf_windows_20220623_2.png +0 -0
- package/doc/dist/html/_static/plus.png +0 -0
- package/doc/dist/html/_static/pygments.css +252 -0
- package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
- package/doc/dist/html/_static/scripts/furo.js +3 -0
- package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +7 -0
- package/doc/dist/html/_static/scripts/furo.js.map +1 -0
- package/doc/dist/html/_static/searchtools.js +531 -0
- package/doc/dist/html/_static/skeleton.css +296 -0
- package/doc/dist/html/_static/styles/furo-extensions.css +2 -0
- package/doc/dist/html/_static/styles/furo-extensions.css.map +1 -0
- package/doc/dist/html/_static/styles/furo.css +2 -0
- package/doc/dist/html/_static/styles/furo.css.map +1 -0
- package/doc/dist/html/_static/underscore-1.13.1.js +2042 -0
- package/doc/dist/html/_static/underscore.js +6 -0
- package/doc/dist/html/benchmarks.html +571 -0
- package/doc/dist/html/changes.html +686 -0
- package/doc/dist/html/contribute.html +403 -0
- package/doc/dist/html/functions.html +718 -0
- package/doc/dist/html/genindex.html +253 -0
- package/doc/dist/html/index.html +359 -0
- package/doc/dist/html/memory.html +346 -0
- package/doc/dist/html/objects.inv +0 -0
- package/doc/dist/html/platforms.html +371 -0
- package/doc/dist/html/search.html +261 -0
- package/doc/dist/html/searchindex.js +1 -0
- package/doc/dist/html/start.html +384 -0
- package/doc/dist/html/types.html +1061 -0
- package/doc/make.bat +1 -1
- package/doc/templates/badges.html +1 -1
- package/doc/types.md +2 -0
- package/package.json +2 -1
- package/src/abi_arm32.cc +142 -200
- package/src/abi_arm64.cc +113 -122
- package/src/abi_riscv64.cc +76 -92
- package/src/abi_x64_sysv.cc +76 -92
- package/src/abi_x64_win.cc +76 -92
- package/src/abi_x86.cc +128 -164
- package/test/misc.c +43 -0
- package/test/sync.js +81 -0
- package/build/qemu/2.1.0-beta.2/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.1.0-beta.2/koffi_win32_x64.tar.gz +0 -0
package/src/abi_arm64.cc
CHANGED
|
@@ -265,6 +265,64 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
265
265
|
gpr_ptr[8] = (uint64_t)return_ptr;
|
|
266
266
|
}
|
|
267
267
|
|
|
268
|
+
#ifdef __APPLE__
|
|
269
|
+
#define PUSH_INTEGER(CType) \
|
|
270
|
+
do { \
|
|
271
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
272
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
273
|
+
return false; \
|
|
274
|
+
} \
|
|
275
|
+
\
|
|
276
|
+
CType v = CopyNumber<CType>(value); \
|
|
277
|
+
\
|
|
278
|
+
if (RG_LIKELY(param.gpr_count)) { \
|
|
279
|
+
*(gpr_ptr++) = (uint64_t)v; \
|
|
280
|
+
} else { \
|
|
281
|
+
args_ptr = AlignUp(args_ptr, param.type->align); \
|
|
282
|
+
*args_ptr = (uint64_t)v; \
|
|
283
|
+
args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size); \
|
|
284
|
+
} \
|
|
285
|
+
} while (false)
|
|
286
|
+
#define PUSH_INTEGER_SWAP(CType) \
|
|
287
|
+
do { \
|
|
288
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
289
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
290
|
+
return false; \
|
|
291
|
+
} \
|
|
292
|
+
\
|
|
293
|
+
CType v = CopyNumber<CType>(value); \
|
|
294
|
+
\
|
|
295
|
+
if (RG_LIKELY(param.gpr_count)) { \
|
|
296
|
+
*(gpr_ptr++) = (uint64_t)ReverseBytes(v); \
|
|
297
|
+
} else { \
|
|
298
|
+
args_ptr = AlignUp(args_ptr, param.type->align); \
|
|
299
|
+
*args_ptr = (uint64_t)ReverseBytes(v); \
|
|
300
|
+
args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size); \
|
|
301
|
+
} \
|
|
302
|
+
} while (false)
|
|
303
|
+
#else
|
|
304
|
+
#define PUSH_INTEGER(CType) \
|
|
305
|
+
do { \
|
|
306
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
307
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
308
|
+
return false; \
|
|
309
|
+
} \
|
|
310
|
+
\
|
|
311
|
+
CType v = CopyNumber<CType>(value); \
|
|
312
|
+
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)v; \
|
|
313
|
+
} while (false)
|
|
314
|
+
#define PUSH_INTEGER_SWAP(CType) \
|
|
315
|
+
do { \
|
|
316
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
317
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
318
|
+
return false; \
|
|
319
|
+
} \
|
|
320
|
+
\
|
|
321
|
+
CType v = CopyNumber<CType>(value); \
|
|
322
|
+
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)ReverseBytes(v); \
|
|
323
|
+
} while (false)
|
|
324
|
+
#endif
|
|
325
|
+
|
|
268
326
|
// Push arguments
|
|
269
327
|
for (Size i = 0; i < func->parameters.len; i++) {
|
|
270
328
|
const ParameterInfo ¶m = func->parameters[i];
|
|
@@ -294,82 +352,20 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
294
352
|
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)b;
|
|
295
353
|
#endif
|
|
296
354
|
} break;
|
|
297
|
-
case PrimitiveKind::Int8:
|
|
298
|
-
case PrimitiveKind::UInt8:
|
|
299
|
-
case PrimitiveKind::Int16:
|
|
300
|
-
case PrimitiveKind::
|
|
301
|
-
case PrimitiveKind::
|
|
302
|
-
case PrimitiveKind::
|
|
303
|
-
case PrimitiveKind::
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
#ifdef __APPLE__
|
|
312
|
-
if (RG_LIKELY(param.gpr_count)) {
|
|
313
|
-
*(int64_t *)(gpr_ptr++) = v;
|
|
314
|
-
} else {
|
|
315
|
-
args_ptr = AlignUp(args_ptr, param.type->align);
|
|
316
|
-
*(int64_t *)args_ptr = v;
|
|
317
|
-
args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size);
|
|
318
|
-
}
|
|
319
|
-
#else
|
|
320
|
-
*(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
321
|
-
#endif
|
|
322
|
-
} break;
|
|
323
|
-
case PrimitiveKind::Int16S:
|
|
324
|
-
case PrimitiveKind::UInt16S:
|
|
325
|
-
case PrimitiveKind::Int32S:
|
|
326
|
-
case PrimitiveKind::UInt32S:
|
|
327
|
-
case PrimitiveKind::Int64S: {
|
|
328
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
329
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
int64_t v = ReverseBytes(CopyNumber<int64_t>(value));
|
|
334
|
-
|
|
335
|
-
#ifdef __APPLE__
|
|
336
|
-
if (RG_LIKELY(param.gpr_count)) {
|
|
337
|
-
*(int64_t *)(gpr_ptr++) = v;
|
|
338
|
-
} else {
|
|
339
|
-
args_ptr = AlignUp(args_ptr, param.type->align);
|
|
340
|
-
*(int64_t *)args_ptr = v;
|
|
341
|
-
args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size);
|
|
342
|
-
}
|
|
343
|
-
#else
|
|
344
|
-
*(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
345
|
-
#endif
|
|
346
|
-
} break;
|
|
347
|
-
case PrimitiveKind::UInt64: {
|
|
348
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
349
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
350
|
-
return false;
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
354
|
-
|
|
355
|
-
#ifdef __APPLE__
|
|
356
|
-
args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
|
|
357
|
-
#endif
|
|
358
|
-
*((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
359
|
-
} break;
|
|
360
|
-
case PrimitiveKind::UInt64S: {
|
|
361
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
362
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
363
|
-
return false;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
uint64_t v = ReverseBytes(CopyNumber<uint64_t>(value));
|
|
367
|
-
|
|
368
|
-
#ifdef __APPLE__
|
|
369
|
-
args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
|
|
370
|
-
#endif
|
|
371
|
-
*((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
372
|
-
} break;
|
|
355
|
+
case PrimitiveKind::Int8: { PUSH_INTEGER(int8_t); } break;
|
|
356
|
+
case PrimitiveKind::UInt8: { PUSH_INTEGER(uint8_t); } break;
|
|
357
|
+
case PrimitiveKind::Int16: { PUSH_INTEGER(int16_t); } break;
|
|
358
|
+
case PrimitiveKind::Int16S: { PUSH_INTEGER_SWAP(int16_t); } break;
|
|
359
|
+
case PrimitiveKind::UInt16: { PUSH_INTEGER(uint16_t); } break;
|
|
360
|
+
case PrimitiveKind::UInt16S: { PUSH_INTEGER_SWAP(uint16_t); } break;
|
|
361
|
+
case PrimitiveKind::Int32: { PUSH_INTEGER(int32_t); } break;
|
|
362
|
+
case PrimitiveKind::Int32S: { PUSH_INTEGER_SWAP(int32_t); } break;
|
|
363
|
+
case PrimitiveKind::UInt32: { PUSH_INTEGER(uint32_t); } break;
|
|
364
|
+
case PrimitiveKind::UInt32S: { PUSH_INTEGER_SWAP(uint32_t); } break;
|
|
365
|
+
case PrimitiveKind::Int64: { PUSH_INTEGER(int64_t); } break;
|
|
366
|
+
case PrimitiveKind::Int64S: { PUSH_INTEGER_SWAP(int64_t); } break;
|
|
367
|
+
case PrimitiveKind::UInt64: { PUSH_INTEGER(uint64_t); } break;
|
|
368
|
+
case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
|
|
373
369
|
case PrimitiveKind::String: {
|
|
374
370
|
const char *str;
|
|
375
371
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -539,6 +535,9 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
539
535
|
}
|
|
540
536
|
}
|
|
541
537
|
|
|
538
|
+
#undef PUSH_INTEGER_SWAP
|
|
539
|
+
#undef PUSH_INTEGER
|
|
540
|
+
|
|
542
541
|
new_sp = mem->stack.end();
|
|
543
542
|
|
|
544
543
|
return true;
|
|
@@ -1075,6 +1074,27 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
1075
1074
|
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
1076
1075
|
return;
|
|
1077
1076
|
|
|
1077
|
+
#define RETURN_INTEGER(CType) \
|
|
1078
|
+
do { \
|
|
1079
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
1080
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
1081
|
+
return; \
|
|
1082
|
+
} \
|
|
1083
|
+
\
|
|
1084
|
+
CType v = CopyNumber<CType>(value); \
|
|
1085
|
+
out_reg->x0 = (uint64_t)v; \
|
|
1086
|
+
} while (false)
|
|
1087
|
+
#define RETURN_INTEGER_SWAP(CType) \
|
|
1088
|
+
do { \
|
|
1089
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
1090
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
1091
|
+
return; \
|
|
1092
|
+
} \
|
|
1093
|
+
\
|
|
1094
|
+
CType v = CopyNumber<CType>(value); \
|
|
1095
|
+
out_reg->x0 = (uint64_t)ReverseBytes(v); \
|
|
1096
|
+
} while (false)
|
|
1097
|
+
|
|
1078
1098
|
// Convert the result
|
|
1079
1099
|
switch (type->primitive) {
|
|
1080
1100
|
case PrimitiveKind::Void: {} break;
|
|
@@ -1087,52 +1107,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
1087
1107
|
bool b = value.As<Napi::Boolean>();
|
|
1088
1108
|
out_reg->x0 = (uint64_t)b;
|
|
1089
1109
|
} break;
|
|
1090
|
-
case PrimitiveKind::Int8:
|
|
1091
|
-
case PrimitiveKind::UInt8:
|
|
1092
|
-
case PrimitiveKind::Int16:
|
|
1093
|
-
case PrimitiveKind::
|
|
1094
|
-
case PrimitiveKind::
|
|
1095
|
-
case PrimitiveKind::
|
|
1096
|
-
case PrimitiveKind::
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
} break;
|
|
1105
|
-
case PrimitiveKind::Int16S:
|
|
1106
|
-
case PrimitiveKind::UInt16S:
|
|
1107
|
-
case PrimitiveKind::Int32S:
|
|
1108
|
-
case PrimitiveKind::UInt32S:
|
|
1109
|
-
case PrimitiveKind::Int64S: {
|
|
1110
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
1111
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
1112
|
-
return;
|
|
1113
|
-
}
|
|
1114
|
-
|
|
1115
|
-
int64_t v = CopyNumber<int64_t>(value);
|
|
1116
|
-
out_reg->x0 = (uint64_t)ReverseBytes(v);
|
|
1117
|
-
} break;
|
|
1118
|
-
case PrimitiveKind::UInt64: {
|
|
1119
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
1120
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
|
|
1124
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
1125
|
-
out_reg->x0 = v;
|
|
1126
|
-
} break;
|
|
1127
|
-
case PrimitiveKind::UInt64S: {
|
|
1128
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
1129
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
1130
|
-
return;
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
1134
|
-
out_reg->x0 = ReverseBytes(v);
|
|
1135
|
-
} break;
|
|
1110
|
+
case PrimitiveKind::Int8: { RETURN_INTEGER(int8_t); } break;
|
|
1111
|
+
case PrimitiveKind::UInt8: { RETURN_INTEGER(uint8_t); } break;
|
|
1112
|
+
case PrimitiveKind::Int16: { RETURN_INTEGER(int16_t); } break;
|
|
1113
|
+
case PrimitiveKind::Int16S: { RETURN_INTEGER_SWAP(int16_t); } break;
|
|
1114
|
+
case PrimitiveKind::UInt16: { RETURN_INTEGER(uint16_t); } break;
|
|
1115
|
+
case PrimitiveKind::UInt16S: { RETURN_INTEGER_SWAP(uint16_t); } break;
|
|
1116
|
+
case PrimitiveKind::Int32: { RETURN_INTEGER(int32_t); } break;
|
|
1117
|
+
case PrimitiveKind::Int32S: { RETURN_INTEGER_SWAP(int32_t); } break;
|
|
1118
|
+
case PrimitiveKind::UInt32: { RETURN_INTEGER(uint32_t); } break;
|
|
1119
|
+
case PrimitiveKind::UInt32S: { RETURN_INTEGER_SWAP(uint32_t); } break;
|
|
1120
|
+
case PrimitiveKind::Int64: { RETURN_INTEGER(int64_t); } break;
|
|
1121
|
+
case PrimitiveKind::Int64S: { RETURN_INTEGER_SWAP(int64_t); } break;
|
|
1122
|
+
case PrimitiveKind::UInt64: { RETURN_INTEGER(uint64_t); } break;
|
|
1123
|
+
case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
|
|
1136
1124
|
case PrimitiveKind::String: {
|
|
1137
1125
|
const char *str;
|
|
1138
1126
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -1247,6 +1235,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
1247
1235
|
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
1248
1236
|
}
|
|
1249
1237
|
|
|
1238
|
+
#undef RETURN_INTEGER_SWAP
|
|
1239
|
+
#undef RETURN_INTEGER
|
|
1240
|
+
|
|
1250
1241
|
err_guard.Disable();
|
|
1251
1242
|
}
|
|
1252
1243
|
|
package/src/abi_riscv64.cc
CHANGED
|
@@ -216,6 +216,27 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
216
216
|
*(uint8_t **)(gpr_ptr++) = return_ptr;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
+
#define PUSH_INTEGER(CType) \
|
|
220
|
+
do { \
|
|
221
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
222
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
223
|
+
return false; \
|
|
224
|
+
} \
|
|
225
|
+
\
|
|
226
|
+
CType v = CopyNumber<CType>(value); \
|
|
227
|
+
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)v; \
|
|
228
|
+
} while (false)
|
|
229
|
+
#define PUSH_INTEGER_SWAP(CType) \
|
|
230
|
+
do { \
|
|
231
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
232
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
233
|
+
return false; \
|
|
234
|
+
} \
|
|
235
|
+
\
|
|
236
|
+
CType v = CopyNumber<CType>(value); \
|
|
237
|
+
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)ReverseBytes(v); \
|
|
238
|
+
} while (false)
|
|
239
|
+
|
|
219
240
|
// Push arguments
|
|
220
241
|
for (Size i = 0; i < func->parameters.len; i++) {
|
|
221
242
|
const ParameterInfo ¶m = func->parameters[i];
|
|
@@ -235,52 +256,20 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
235
256
|
bool b = value.As<Napi::Boolean>();
|
|
236
257
|
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)b;
|
|
237
258
|
} break;
|
|
238
|
-
case PrimitiveKind::Int8:
|
|
239
|
-
case PrimitiveKind::
|
|
240
|
-
case PrimitiveKind::
|
|
241
|
-
case PrimitiveKind::
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
} break;
|
|
250
|
-
case PrimitiveKind::
|
|
251
|
-
case PrimitiveKind::
|
|
252
|
-
case PrimitiveKind::Int64S: {
|
|
253
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
254
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
255
|
-
return false;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
int64_t v = CopyNumber<int64_t>(value);
|
|
259
|
-
*(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = ReverseBytes(v);
|
|
260
|
-
} break;
|
|
261
|
-
case PrimitiveKind::UInt8:
|
|
262
|
-
case PrimitiveKind::UInt16:
|
|
263
|
-
case PrimitiveKind::UInt32:
|
|
264
|
-
case PrimitiveKind::UInt64: {
|
|
265
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
266
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
267
|
-
return false;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
271
|
-
*((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
272
|
-
} break;
|
|
273
|
-
case PrimitiveKind::UInt16S:
|
|
274
|
-
case PrimitiveKind::UInt32S:
|
|
275
|
-
case PrimitiveKind::UInt64S: {
|
|
276
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
277
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
282
|
-
*((param.gpr_count ? gpr_ptr : args_ptr)++) = ReverseBytes(v);
|
|
283
|
-
} break;
|
|
259
|
+
case PrimitiveKind::Int8: { PUSH_INTEGER(int8_t); } break;
|
|
260
|
+
case PrimitiveKind::UInt8: { PUSH_INTEGER(uint8_t); } break;
|
|
261
|
+
case PrimitiveKind::Int16: { PUSH_INTEGER(int16_t); } break;
|
|
262
|
+
case PrimitiveKind::Int16S: { PUSH_INTEGER_SWAP(int16_t); } break;
|
|
263
|
+
case PrimitiveKind::UInt16: { PUSH_INTEGER(uint16_t); } break;
|
|
264
|
+
case PrimitiveKind::UInt16S: { PUSH_INTEGER_SWAP(uint16_t); } break;
|
|
265
|
+
case PrimitiveKind::Int32: { PUSH_INTEGER(int32_t); } break;
|
|
266
|
+
case PrimitiveKind::Int32S: { PUSH_INTEGER_SWAP(int32_t); } break;
|
|
267
|
+
case PrimitiveKind::UInt32: { PUSH_INTEGER(uint32_t); } break;
|
|
268
|
+
case PrimitiveKind::UInt32S: { PUSH_INTEGER_SWAP(uint32_t); } break;
|
|
269
|
+
case PrimitiveKind::Int64: { PUSH_INTEGER(int64_t); } break;
|
|
270
|
+
case PrimitiveKind::Int64S: { PUSH_INTEGER_SWAP(int64_t); } break;
|
|
271
|
+
case PrimitiveKind::UInt64: { PUSH_INTEGER(uint64_t); } break;
|
|
272
|
+
case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
|
|
284
273
|
case PrimitiveKind::String: {
|
|
285
274
|
const char *str;
|
|
286
275
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -427,6 +416,9 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
427
416
|
}
|
|
428
417
|
}
|
|
429
418
|
|
|
419
|
+
#undef PUSH_INTEGER_SWAP
|
|
420
|
+
#undef PUSH_INTEGER
|
|
421
|
+
|
|
430
422
|
new_sp = mem->stack.end();
|
|
431
423
|
|
|
432
424
|
return true;
|
|
@@ -790,6 +782,27 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
790
782
|
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
791
783
|
return;
|
|
792
784
|
|
|
785
|
+
#define RETURN_INTEGER(CType) \
|
|
786
|
+
do { \
|
|
787
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
788
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
789
|
+
return; \
|
|
790
|
+
} \
|
|
791
|
+
\
|
|
792
|
+
CType v = CopyNumber<CType>(value); \
|
|
793
|
+
out_reg->a0 = (uint64_t)v; \
|
|
794
|
+
} while (false)
|
|
795
|
+
#define RETURN_INTEGER_SWAP(CType) \
|
|
796
|
+
do { \
|
|
797
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
798
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
799
|
+
return; \
|
|
800
|
+
} \
|
|
801
|
+
\
|
|
802
|
+
CType v = CopyNumber<CType>(value); \
|
|
803
|
+
out_reg->a0 = (uint64_t)ReverseBytes(v); \
|
|
804
|
+
} while (false)
|
|
805
|
+
|
|
793
806
|
// Convert the result
|
|
794
807
|
switch (type->primitive) {
|
|
795
808
|
case PrimitiveKind::Void: {} break;
|
|
@@ -802,52 +815,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
802
815
|
bool b = value.As<Napi::Boolean>();
|
|
803
816
|
out_reg->a0 = (uint64_t)b;
|
|
804
817
|
} break;
|
|
805
|
-
case PrimitiveKind::Int8:
|
|
806
|
-
case PrimitiveKind::UInt8:
|
|
807
|
-
case PrimitiveKind::Int16:
|
|
808
|
-
case PrimitiveKind::
|
|
809
|
-
case PrimitiveKind::
|
|
810
|
-
case PrimitiveKind::
|
|
811
|
-
case PrimitiveKind::
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
} break;
|
|
820
|
-
case PrimitiveKind::Int16S:
|
|
821
|
-
case PrimitiveKind::UInt16S:
|
|
822
|
-
case PrimitiveKind::Int32S:
|
|
823
|
-
case PrimitiveKind::UInt32S:
|
|
824
|
-
case PrimitiveKind::Int64S: {
|
|
825
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
826
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
827
|
-
return;
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
int64_t v = CopyNumber<int64_t>(value);
|
|
831
|
-
out_reg->a0 = (uint64_t)ReverseBytes(v);
|
|
832
|
-
} break;
|
|
833
|
-
case PrimitiveKind::UInt64: {
|
|
834
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
835
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
836
|
-
return;
|
|
837
|
-
}
|
|
838
|
-
|
|
839
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
840
|
-
out_reg->a0 = v;
|
|
841
|
-
} break;
|
|
842
|
-
case PrimitiveKind::UInt64S: {
|
|
843
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
844
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
845
|
-
return;
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
849
|
-
out_reg->a0 = ReverseBytes(v);
|
|
850
|
-
} break;
|
|
818
|
+
case PrimitiveKind::Int8: { RETURN_INTEGER(int8_t); } break;
|
|
819
|
+
case PrimitiveKind::UInt8: { RETURN_INTEGER(uint8_t); } break;
|
|
820
|
+
case PrimitiveKind::Int16: { RETURN_INTEGER(int16_t); } break;
|
|
821
|
+
case PrimitiveKind::Int16S: { RETURN_INTEGER_SWAP(int16_t); } break;
|
|
822
|
+
case PrimitiveKind::UInt16: { RETURN_INTEGER(uint16_t); } break;
|
|
823
|
+
case PrimitiveKind::UInt16S: { RETURN_INTEGER_SWAP(uint16_t); } break;
|
|
824
|
+
case PrimitiveKind::Int32: { RETURN_INTEGER(int32_t); } break;
|
|
825
|
+
case PrimitiveKind::Int32S: { RETURN_INTEGER_SWAP(int32_t); } break;
|
|
826
|
+
case PrimitiveKind::UInt32: { RETURN_INTEGER(uint32_t); } break;
|
|
827
|
+
case PrimitiveKind::UInt32S: { RETURN_INTEGER_SWAP(uint32_t); } break;
|
|
828
|
+
case PrimitiveKind::Int64: { RETURN_INTEGER(int64_t); } break;
|
|
829
|
+
case PrimitiveKind::Int64S: { RETURN_INTEGER_SWAP(int64_t); } break;
|
|
830
|
+
case PrimitiveKind::UInt64: { RETURN_INTEGER(uint64_t); } break;
|
|
831
|
+
case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
|
|
851
832
|
case PrimitiveKind::String: {
|
|
852
833
|
const char *str;
|
|
853
834
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -961,6 +942,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
961
942
|
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
962
943
|
}
|
|
963
944
|
|
|
945
|
+
#undef RETURN_INTEGER_SWAP
|
|
946
|
+
#undef RETURN_INTEGER
|
|
947
|
+
|
|
964
948
|
err_guard.Disable();
|
|
965
949
|
}
|
|
966
950
|
|