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/doc/make.bat
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
<div style="text-align: center; margin-top: 2em;">
|
|
2
|
-
<a href="https://www.npmjs.com/package/koffi"><img src="https://img.shields.io/badge/NPM-
|
|
2
|
+
<a href="https://www.npmjs.com/package/koffi"><img src="https://img.shields.io/badge/NPM-{{ stable }}-brightgreen" alt="NPM"/></a>
|
|
3
3
|
<a href="https://github.com/Koromix/luigi/tree/master/koffi"><img src="https://img.shields.io/badge/GitHub-Koffi-ff6600" alt="GitHub"/></a>
|
|
4
4
|
</div>
|
package/doc/types.md
CHANGED
|
@@ -58,6 +58,8 @@ let struct2 = koffi.struct({ dummy: koffi.types.long });
|
|
|
58
58
|
|
|
59
59
|
### Endian-sensitive types
|
|
60
60
|
|
|
61
|
+
*New in Koffi 2.1*
|
|
62
|
+
|
|
61
63
|
Koffi defines a bunch of endian-sensitive types, which can be used when dealing with binary data (network payloads, binary file formats, etc.).
|
|
62
64
|
|
|
63
65
|
JS type | C type | Bytes | Signedness | Endianness
|
package/package.json
CHANGED
package/src/abi_arm32.cc
CHANGED
|
@@ -275,6 +275,65 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
275
275
|
*(uint8_t **)(gpr_ptr++) = return_ptr;
|
|
276
276
|
}
|
|
277
277
|
|
|
278
|
+
#define PUSH_INTEGER_32(CType) \
|
|
279
|
+
do { \
|
|
280
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
281
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
282
|
+
return false; \
|
|
283
|
+
} \
|
|
284
|
+
\
|
|
285
|
+
CType v = CopyNumber<CType>(value); \
|
|
286
|
+
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint32_t)v; \
|
|
287
|
+
} while (false)
|
|
288
|
+
#define PUSH_INTEGER_32_SWAP(CType) \
|
|
289
|
+
do { \
|
|
290
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
291
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
292
|
+
return false; \
|
|
293
|
+
} \
|
|
294
|
+
\
|
|
295
|
+
CType v = CopyNumber<CType>(value); \
|
|
296
|
+
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint32_t)ReverseBytes(v); \
|
|
297
|
+
} while (false)
|
|
298
|
+
#define PUSH_INTEGER_64(CType) \
|
|
299
|
+
do { \
|
|
300
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
301
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
302
|
+
return false; \
|
|
303
|
+
} \
|
|
304
|
+
\
|
|
305
|
+
CType v = CopyNumber<CType>(value); \
|
|
306
|
+
\
|
|
307
|
+
if (RG_LIKELY(param.gpr_count)) { \
|
|
308
|
+
gpr_ptr = AlignUp(gpr_ptr, 8); \
|
|
309
|
+
*(uint64_t *)gpr_ptr = (uint64_t)v; \
|
|
310
|
+
gpr_ptr += param.gpr_count; \
|
|
311
|
+
} else { \
|
|
312
|
+
args_ptr = AlignUp(args_ptr, 8); \
|
|
313
|
+
*(uint64_t *)args_ptr = (uint64_t)v; \
|
|
314
|
+
args_ptr += 2; \
|
|
315
|
+
} \
|
|
316
|
+
} while (false)
|
|
317
|
+
#define PUSH_INTEGER_64_SWAP(CType) \
|
|
318
|
+
do { \
|
|
319
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
320
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
321
|
+
return false; \
|
|
322
|
+
} \
|
|
323
|
+
\
|
|
324
|
+
CType v = CopyNumber<CType>(value); \
|
|
325
|
+
\
|
|
326
|
+
if (RG_LIKELY(param.gpr_count)) { \
|
|
327
|
+
gpr_ptr = AlignUp(gpr_ptr, 8); \
|
|
328
|
+
*(uint64_t *)gpr_ptr = (uint64_t)ReverseBytes(v); \
|
|
329
|
+
gpr_ptr += param.gpr_count; \
|
|
330
|
+
} else { \
|
|
331
|
+
args_ptr = AlignUp(args_ptr, 8); \
|
|
332
|
+
*(uint64_t *)args_ptr = (uint64_t)ReverseBytes(v); \
|
|
333
|
+
args_ptr += 2; \
|
|
334
|
+
} \
|
|
335
|
+
} while (false)
|
|
336
|
+
|
|
278
337
|
// Push arguments
|
|
279
338
|
for (Size i = 0; i < func->parameters.len; i++) {
|
|
280
339
|
const ParameterInfo ¶m = func->parameters[i];
|
|
@@ -294,120 +353,20 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
294
353
|
bool b = value.As<Napi::Boolean>();
|
|
295
354
|
*((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint32_t)b;
|
|
296
355
|
} break;
|
|
297
|
-
case PrimitiveKind::Int8:
|
|
298
|
-
case PrimitiveKind::UInt8:
|
|
299
|
-
case PrimitiveKind::Int16:
|
|
300
|
-
case PrimitiveKind::
|
|
301
|
-
case PrimitiveKind::
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
} break;
|
|
310
|
-
case PrimitiveKind::
|
|
311
|
-
case PrimitiveKind::UInt16S:
|
|
312
|
-
case PrimitiveKind::Int32S: {
|
|
313
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
314
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
315
|
-
return false;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
int32_t v = ReverseBytes(CopyNumber<int32_t>(value));
|
|
319
|
-
*(int32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
320
|
-
} break;
|
|
321
|
-
case PrimitiveKind::UInt32: {
|
|
322
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
323
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
324
|
-
return false;
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
uint32_t v = CopyNumber<uint32_t>(value);
|
|
328
|
-
*((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
329
|
-
} break;
|
|
330
|
-
case PrimitiveKind::UInt32S: {
|
|
331
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
332
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
333
|
-
return false;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
uint32_t v = ReverseBytes(CopyNumber<uint32_t>(value));
|
|
337
|
-
*((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
|
|
338
|
-
} break;
|
|
339
|
-
case PrimitiveKind::Int64: {
|
|
340
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
341
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
342
|
-
return false;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
int64_t v = CopyNumber<int64_t>(value);
|
|
346
|
-
|
|
347
|
-
if (RG_LIKELY(param.gpr_count)) {
|
|
348
|
-
gpr_ptr = AlignUp(gpr_ptr, 8);
|
|
349
|
-
*(int64_t *)gpr_ptr = v;
|
|
350
|
-
gpr_ptr += param.gpr_count;
|
|
351
|
-
} else {
|
|
352
|
-
args_ptr = AlignUp(args_ptr, 8);
|
|
353
|
-
*(int64_t *)args_ptr = v;
|
|
354
|
-
args_ptr += 2;
|
|
355
|
-
}
|
|
356
|
-
} break;
|
|
357
|
-
case PrimitiveKind::Int64S: {
|
|
358
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
359
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
int64_t v = ReverseBytes(CopyNumber<int64_t>(value));
|
|
364
|
-
|
|
365
|
-
if (RG_LIKELY(param.gpr_count)) {
|
|
366
|
-
gpr_ptr = AlignUp(gpr_ptr, 8);
|
|
367
|
-
*(int64_t *)gpr_ptr = v;
|
|
368
|
-
gpr_ptr += param.gpr_count;
|
|
369
|
-
} else {
|
|
370
|
-
args_ptr = AlignUp(args_ptr, 8);
|
|
371
|
-
*(int64_t *)args_ptr = v;
|
|
372
|
-
args_ptr += 2;
|
|
373
|
-
}
|
|
374
|
-
} break;
|
|
375
|
-
case PrimitiveKind::UInt64: {
|
|
376
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
377
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
378
|
-
return false;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
382
|
-
|
|
383
|
-
if (RG_LIKELY(param.gpr_count)) {
|
|
384
|
-
gpr_ptr = AlignUp(gpr_ptr, 8);
|
|
385
|
-
*(uint64_t *)gpr_ptr = v;
|
|
386
|
-
gpr_ptr += param.gpr_count;
|
|
387
|
-
} else {
|
|
388
|
-
args_ptr = AlignUp(args_ptr, 8);
|
|
389
|
-
*(uint64_t *)args_ptr = v;
|
|
390
|
-
args_ptr += 2;
|
|
391
|
-
}
|
|
392
|
-
} break;
|
|
393
|
-
case PrimitiveKind::UInt64S: {
|
|
394
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
395
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
396
|
-
return false;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
uint64_t v = ReverseBytes(CopyNumber<uint64_t>(value));
|
|
400
|
-
|
|
401
|
-
if (RG_LIKELY(param.gpr_count)) {
|
|
402
|
-
gpr_ptr = AlignUp(gpr_ptr, 8);
|
|
403
|
-
*(uint64_t *)gpr_ptr = v;
|
|
404
|
-
gpr_ptr += param.gpr_count;
|
|
405
|
-
} else {
|
|
406
|
-
args_ptr = AlignUp(args_ptr, 8);
|
|
407
|
-
*(uint64_t *)args_ptr = v;
|
|
408
|
-
args_ptr += 2;
|
|
409
|
-
}
|
|
410
|
-
} break;
|
|
356
|
+
case PrimitiveKind::Int8: { PUSH_INTEGER_32(int8_t); } break;
|
|
357
|
+
case PrimitiveKind::UInt8: { PUSH_INTEGER_32(uint8_t); } break;
|
|
358
|
+
case PrimitiveKind::Int16: { PUSH_INTEGER_32(int16_t); } break;
|
|
359
|
+
case PrimitiveKind::Int16S: { PUSH_INTEGER_32_SWAP(int16_t); } break;
|
|
360
|
+
case PrimitiveKind::UInt16: { PUSH_INTEGER_32(uint16_t); } break;
|
|
361
|
+
case PrimitiveKind::UInt16S: { PUSH_INTEGER_32_SWAP(uint16_t); } break;
|
|
362
|
+
case PrimitiveKind::Int32: { PUSH_INTEGER_32(int32_t); } break;
|
|
363
|
+
case PrimitiveKind::Int32S: { PUSH_INTEGER_32_SWAP(int32_t); } break;
|
|
364
|
+
case PrimitiveKind::UInt32: { PUSH_INTEGER_32(uint32_t); } break;
|
|
365
|
+
case PrimitiveKind::UInt32S: { PUSH_INTEGER_32_SWAP(uint32_t); } break;
|
|
366
|
+
case PrimitiveKind::Int64: { PUSH_INTEGER_64(int64_t); } break;
|
|
367
|
+
case PrimitiveKind::Int64S: { PUSH_INTEGER_64_SWAP(int64_t); } break;
|
|
368
|
+
case PrimitiveKind::UInt64: { PUSH_INTEGER_64(uint64_t); } break;
|
|
369
|
+
case PrimitiveKind::UInt64S: { PUSH_INTEGER_64_SWAP(uint64_t); } break;
|
|
411
370
|
case PrimitiveKind::String: {
|
|
412
371
|
const char *str;
|
|
413
372
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -540,6 +499,11 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
540
499
|
}
|
|
541
500
|
}
|
|
542
501
|
|
|
502
|
+
#undef PUSH_INTEGER_64_SWAP
|
|
503
|
+
#undef PUSH_INTEGER_64
|
|
504
|
+
#undef PUSH_INTEGER_32_SWAP
|
|
505
|
+
#undef PUSH_INTEGER_32
|
|
506
|
+
|
|
543
507
|
new_sp = mem->stack.end();
|
|
544
508
|
|
|
545
509
|
return true;
|
|
@@ -919,6 +883,51 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
919
883
|
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
920
884
|
return;
|
|
921
885
|
|
|
886
|
+
#define RETURN_INTEGER_32(CType) \
|
|
887
|
+
do { \
|
|
888
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
889
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
890
|
+
return; \
|
|
891
|
+
} \
|
|
892
|
+
\
|
|
893
|
+
CType v = CopyNumber<CType>(value); \
|
|
894
|
+
out_reg->r0 = (uint32_t)v; \
|
|
895
|
+
} while (false)
|
|
896
|
+
#define RETURN_INTEGER_32_SWAP(CType) \
|
|
897
|
+
do { \
|
|
898
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
899
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
900
|
+
return; \
|
|
901
|
+
} \
|
|
902
|
+
\
|
|
903
|
+
CType v = CopyNumber<CType>(value); \
|
|
904
|
+
out_reg->r0 = (uint32_t)ReverseBytes(v); \
|
|
905
|
+
} while (false)
|
|
906
|
+
#define RETURN_INTEGER_64(CType) \
|
|
907
|
+
do { \
|
|
908
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
909
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
910
|
+
return; \
|
|
911
|
+
} \
|
|
912
|
+
\
|
|
913
|
+
CType v = CopyNumber<CType>(value); \
|
|
914
|
+
\
|
|
915
|
+
out_reg->r0 = (uint32_t)((uint64_t)v >> 32); \
|
|
916
|
+
out_reg->r1 = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
|
|
917
|
+
} while (false)
|
|
918
|
+
#define RETURN_INTEGER_64_SWAP(CType) \
|
|
919
|
+
do { \
|
|
920
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
921
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
922
|
+
return; \
|
|
923
|
+
} \
|
|
924
|
+
\
|
|
925
|
+
CType v = ReverseBytes(CopyNumber<CType>(value)); \
|
|
926
|
+
\
|
|
927
|
+
out_reg->r0 = (uint32_t)((uint64_t)v >> 32); \
|
|
928
|
+
out_reg->r1 = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
|
|
929
|
+
} while (false)
|
|
930
|
+
|
|
922
931
|
// Convert the result
|
|
923
932
|
switch (type->primitive) {
|
|
924
933
|
case PrimitiveKind::Void: {} break;
|
|
@@ -931,92 +940,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
931
940
|
bool b = value.As<Napi::Boolean>();
|
|
932
941
|
out_reg->r0 = (uint32_t)b;
|
|
933
942
|
} break;
|
|
934
|
-
case PrimitiveKind::Int8:
|
|
935
|
-
case PrimitiveKind::UInt8:
|
|
936
|
-
case PrimitiveKind::Int16:
|
|
937
|
-
case PrimitiveKind::
|
|
938
|
-
case PrimitiveKind::
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
} break;
|
|
947
|
-
case PrimitiveKind::
|
|
948
|
-
case PrimitiveKind::UInt16S:
|
|
949
|
-
case PrimitiveKind::Int32S: {
|
|
950
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
951
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
952
|
-
return;
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
int32_t v = CopyNumber<int32_t>(value);
|
|
956
|
-
out_reg->r0 = (uint32_t)ReverseBytes(v);
|
|
957
|
-
} break;
|
|
958
|
-
case PrimitiveKind::UInt32: {
|
|
959
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
960
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
961
|
-
return;
|
|
962
|
-
}
|
|
963
|
-
|
|
964
|
-
uint32_t v = CopyNumber<uint32_t>(value);
|
|
965
|
-
out_reg->r0 = v;
|
|
966
|
-
} break;
|
|
967
|
-
case PrimitiveKind::UInt32S: {
|
|
968
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
969
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
|
|
973
|
-
uint32_t v = CopyNumber<uint32_t>(value);
|
|
974
|
-
out_reg->r0 = ReverseBytes(v);
|
|
975
|
-
} break;
|
|
976
|
-
case PrimitiveKind::Int64: {
|
|
977
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
978
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
979
|
-
return;
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
int64_t v = CopyNumber<int64_t>(value);
|
|
983
|
-
|
|
984
|
-
out_reg->r0 = (uint32_t)(v >> 32);
|
|
985
|
-
out_reg->r1 = (uint32_t)((uint64_t)v & 0xFFFFFFFFu);
|
|
986
|
-
} break;
|
|
987
|
-
case PrimitiveKind::Int64S: {
|
|
988
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
989
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
990
|
-
return;
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
int64_t v = ReverseBytes(CopyNumber<int64_t>(value));
|
|
994
|
-
|
|
995
|
-
out_reg->r0 = (uint32_t)(v >> 32);
|
|
996
|
-
out_reg->r1 = (uint32_t)((uint64_t)v & 0xFFFFFFFFu);
|
|
997
|
-
} break;
|
|
998
|
-
case PrimitiveKind::UInt64: {
|
|
999
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
1000
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
1001
|
-
return;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
1005
|
-
|
|
1006
|
-
out_reg->r0 = (uint32_t)(v >> 32);
|
|
1007
|
-
out_reg->r1 = (uint32_t)((uint64_t)v & 0xFFFFFFFFu);
|
|
1008
|
-
} break;
|
|
1009
|
-
case PrimitiveKind::UInt64S: {
|
|
1010
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
1011
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
1012
|
-
return;
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
uint64_t v = ReverseBytes(CopyNumber<uint64_t>(value));
|
|
1016
|
-
|
|
1017
|
-
out_reg->r0 = (uint32_t)(v >> 32);
|
|
1018
|
-
out_reg->r1 = (uint32_t)((uint64_t)v & 0xFFFFFFFFu);
|
|
1019
|
-
} break;
|
|
943
|
+
case PrimitiveKind::Int8: { RETURN_INTEGER_32(int8_t); } break;
|
|
944
|
+
case PrimitiveKind::UInt8: { RETURN_INTEGER_32(uint8_t); } break;
|
|
945
|
+
case PrimitiveKind::Int16: { RETURN_INTEGER_32(int16_t); } break;
|
|
946
|
+
case PrimitiveKind::Int16S: { RETURN_INTEGER_32_SWAP(int16_t); } break;
|
|
947
|
+
case PrimitiveKind::UInt16: { RETURN_INTEGER_32(uint16_t); } break;
|
|
948
|
+
case PrimitiveKind::UInt16S: { RETURN_INTEGER_32_SWAP(uint16_t); } break;
|
|
949
|
+
case PrimitiveKind::Int32: { RETURN_INTEGER_32(int32_t); } break;
|
|
950
|
+
case PrimitiveKind::Int32S: { RETURN_INTEGER_32_SWAP(int32_t); } break;
|
|
951
|
+
case PrimitiveKind::UInt32: { RETURN_INTEGER_32(uint32_t); } break;
|
|
952
|
+
case PrimitiveKind::UInt32S: { RETURN_INTEGER_32_SWAP(uint32_t); } break;
|
|
953
|
+
case PrimitiveKind::Int64: { RETURN_INTEGER_64(int64_t); } break;
|
|
954
|
+
case PrimitiveKind::Int64S: { RETURN_INTEGER_64_SWAP(int64_t); } break;
|
|
955
|
+
case PrimitiveKind::UInt64: { RETURN_INTEGER_64(uint64_t); } break;
|
|
956
|
+
case PrimitiveKind::UInt64S: { RETURN_INTEGER_64_SWAP(uint64_t); } break;
|
|
1020
957
|
case PrimitiveKind::String: {
|
|
1021
958
|
const char *str;
|
|
1022
959
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -1137,6 +1074,11 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
1137
1074
|
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
1138
1075
|
}
|
|
1139
1076
|
|
|
1077
|
+
#undef RETURN_INTEGER_64_SWAP
|
|
1078
|
+
#undef RETURN_INTEGER_64
|
|
1079
|
+
#undef RETURN_INTEGER_32_SWAP
|
|
1080
|
+
#undef RETURN_INTEGER_32
|
|
1081
|
+
|
|
1140
1082
|
err_guard.Disable();
|
|
1141
1083
|
}
|
|
1142
1084
|
|