koffi 2.0.1 → 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/CMakeLists.txt +2 -9
- package/ChangeLog.md +17 -0
- package/benchmark/atoi_koffi.js +12 -8
- package/benchmark/atoi_napi.js +12 -8
- package/benchmark/atoi_node_ffi.js +11 -10
- package/benchmark/raylib_cc.cc +12 -9
- package/benchmark/raylib_koffi.js +15 -13
- package/benchmark/raylib_node_ffi.js +15 -13
- package/benchmark/raylib_node_raylib.js +14 -11
- 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/changes.md +12 -8
- 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 +1 -1
- package/doc/dist/html/_sources/changes.md.txt +12 -8
- package/doc/dist/html/_sources/functions.md.txt +71 -5
- package/doc/dist/html/_sources/types.md.txt +147 -159
- package/doc/dist/html/benchmarks.html +2 -3
- package/doc/dist/html/changes.html +64 -35
- package/doc/dist/html/contribute.html +2 -3
- package/doc/dist/html/functions.html +73 -12
- package/doc/dist/html/genindex.html +2 -3
- package/doc/dist/html/index.html +6 -7
- package/doc/dist/html/memory.html +2 -3
- package/doc/dist/html/objects.inv +0 -0
- package/doc/dist/html/platforms.html +3 -4
- package/doc/dist/html/search.html +2 -3
- package/doc/dist/html/searchindex.js +1 -1
- package/doc/dist/html/start.html +2 -3
- package/doc/dist/html/types.html +238 -237
- package/doc/functions.md +71 -5
- package/doc/make.bat +1 -1
- package/doc/templates/badges.html +1 -2
- package/doc/types.md +149 -159
- package/package.json +3 -2
- package/qemu/qemu.js +1 -1
- package/src/abi_arm32.cc +208 -102
- package/src/abi_arm64.cc +239 -55
- package/src/abi_riscv64.cc +128 -40
- package/src/abi_x64_sysv.cc +135 -41
- package/src/abi_x64_win.cc +134 -40
- package/src/abi_x86.cc +182 -67
- package/src/call.cc +241 -26
- package/src/call.hh +15 -3
- package/src/ffi.cc +120 -31
- package/src/ffi.hh +19 -0
- package/src/index.js +4 -2
- package/src/parser.cc +3 -5
- package/src/util.cc +44 -1
- package/src/util.hh +4 -0
- package/test/async.js +1 -2
- package/test/callbacks.js +2 -3
- package/test/misc.c +64 -1
- package/test/raylib.js +1 -1
- package/test/sqlite.js +3 -3
- package/test/sync.js +108 -3
- package/build/qemu/2.0.1/koffi_darwin_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_darwin_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_freebsd_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_freebsd_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_freebsd_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_arm32hf.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_riscv64hf64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_linux_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_openbsd_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_openbsd_x64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_win32_arm64.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_win32_ia32.tar.gz +0 -0
- package/build/qemu/2.0.1/koffi_win32_x64.tar.gz +0 -0
package/src/abi_x86.cc
CHANGED
|
@@ -197,6 +197,51 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
197
197
|
*((func->ret.fast ? fast_ptr : args_ptr)++) = (uint32_t)return_ptr;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
+
#define PUSH_INTEGER_32(CType) \
|
|
201
|
+
do { \
|
|
202
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
203
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
204
|
+
return false; \
|
|
205
|
+
} \
|
|
206
|
+
\
|
|
207
|
+
CType v = CopyNumber<CType>(value); \
|
|
208
|
+
*((param.fast ? fast_ptr : args_ptr)++) = (uint32_t)v; \
|
|
209
|
+
} while (false)
|
|
210
|
+
#define PUSH_INTEGER_32_SWAP(CType) \
|
|
211
|
+
do { \
|
|
212
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
213
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
214
|
+
return false; \
|
|
215
|
+
} \
|
|
216
|
+
\
|
|
217
|
+
CType v = CopyNumber<CType>(value); \
|
|
218
|
+
*((param.fast ? fast_ptr : args_ptr)++) = (uint32_t)ReverseBytes(v); \
|
|
219
|
+
} while (false)
|
|
220
|
+
#define PUSH_INTEGER_64(CType) \
|
|
221
|
+
do { \
|
|
222
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
223
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
224
|
+
return false; \
|
|
225
|
+
} \
|
|
226
|
+
\
|
|
227
|
+
CType v = CopyNumber<CType>(value); \
|
|
228
|
+
\
|
|
229
|
+
*(uint64_t *)args_ptr = (uint64_t)v; \
|
|
230
|
+
args_ptr += 2; \
|
|
231
|
+
} while (false)
|
|
232
|
+
#define PUSH_INTEGER_64_SWAP(CType) \
|
|
233
|
+
do { \
|
|
234
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
235
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
|
|
236
|
+
return false; \
|
|
237
|
+
} \
|
|
238
|
+
\
|
|
239
|
+
CType v = CopyNumber<CType>(value); \
|
|
240
|
+
\
|
|
241
|
+
*(uint64_t *)args_ptr = (uint64_t)ReverseBytes(v); \
|
|
242
|
+
args_ptr += 2; \
|
|
243
|
+
} while (false)
|
|
244
|
+
|
|
200
245
|
// Push arguments
|
|
201
246
|
for (Size i = 0; i < func->parameters.len; i++) {
|
|
202
247
|
const ParameterInfo ¶m = func->parameters[i];
|
|
@@ -216,48 +261,20 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
216
261
|
bool b = value.As<Napi::Boolean>();
|
|
217
262
|
*(bool *)((param.fast ? fast_ptr : args_ptr)++) = b;
|
|
218
263
|
} break;
|
|
219
|
-
case PrimitiveKind::Int8:
|
|
220
|
-
case PrimitiveKind::UInt8:
|
|
221
|
-
case PrimitiveKind::Int16:
|
|
222
|
-
case PrimitiveKind::
|
|
223
|
-
case PrimitiveKind::
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
} break;
|
|
232
|
-
case PrimitiveKind::
|
|
233
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
234
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
uint32_t v = CopyNumber<uint32_t>(value);
|
|
239
|
-
*((param.fast ? fast_ptr : args_ptr)++) = v;
|
|
240
|
-
} break;
|
|
241
|
-
case PrimitiveKind::Int64: {
|
|
242
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
243
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
244
|
-
return false;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
int64_t v = CopyNumber<int64_t>(value);
|
|
248
|
-
*(int64_t *)args_ptr = v;
|
|
249
|
-
args_ptr += 2;
|
|
250
|
-
} break;
|
|
251
|
-
case PrimitiveKind::UInt64: {
|
|
252
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
253
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
uint64_t v = CopyNumber<uint64_t>(value);
|
|
258
|
-
*(uint64_t *)args_ptr = v;
|
|
259
|
-
args_ptr += 2;
|
|
260
|
-
} break;
|
|
264
|
+
case PrimitiveKind::Int8: { PUSH_INTEGER_32(int8_t); } break;
|
|
265
|
+
case PrimitiveKind::UInt8: { PUSH_INTEGER_32(uint8_t); } break;
|
|
266
|
+
case PrimitiveKind::Int16: { PUSH_INTEGER_32(int16_t); } break;
|
|
267
|
+
case PrimitiveKind::Int16S: { PUSH_INTEGER_32_SWAP(int16_t); } break;
|
|
268
|
+
case PrimitiveKind::UInt16: { PUSH_INTEGER_32(uint16_t); } break;
|
|
269
|
+
case PrimitiveKind::UInt16S: { PUSH_INTEGER_32_SWAP(uint16_t); } break;
|
|
270
|
+
case PrimitiveKind::Int32: { PUSH_INTEGER_32(int32_t); } break;
|
|
271
|
+
case PrimitiveKind::Int32S: { PUSH_INTEGER_32_SWAP(int32_t); } break;
|
|
272
|
+
case PrimitiveKind::UInt32: { PUSH_INTEGER_32(uint32_t); } break;
|
|
273
|
+
case PrimitiveKind::UInt32S: { PUSH_INTEGER_32_SWAP(uint32_t); } break;
|
|
274
|
+
case PrimitiveKind::Int64: { PUSH_INTEGER_64(int64_t); } break;
|
|
275
|
+
case PrimitiveKind::Int64S: { PUSH_INTEGER_64_SWAP(int64_t); } break;
|
|
276
|
+
case PrimitiveKind::UInt64: { PUSH_INTEGER_64(uint64_t); } break;
|
|
277
|
+
case PrimitiveKind::UInt64S: { PUSH_INTEGER_64_SWAP(uint64_t); } break;
|
|
261
278
|
case PrimitiveKind::String: {
|
|
262
279
|
const char *str;
|
|
263
280
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -359,6 +376,11 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
|
|
|
359
376
|
}
|
|
360
377
|
}
|
|
361
378
|
|
|
379
|
+
#undef PUSH_INTEGER_64_SWAP
|
|
380
|
+
#undef PUSH_INTEGER_64
|
|
381
|
+
#undef PUSH_INTEGER_32_SWAP
|
|
382
|
+
#undef PUSH_INTEGER_32
|
|
383
|
+
|
|
362
384
|
new_sp = mem->stack.end();
|
|
363
385
|
|
|
364
386
|
return true;
|
|
@@ -382,11 +404,17 @@ void CallData::Execute()
|
|
|
382
404
|
case PrimitiveKind::Int8:
|
|
383
405
|
case PrimitiveKind::UInt8:
|
|
384
406
|
case PrimitiveKind::Int16:
|
|
407
|
+
case PrimitiveKind::Int16S:
|
|
385
408
|
case PrimitiveKind::UInt16:
|
|
409
|
+
case PrimitiveKind::UInt16S:
|
|
386
410
|
case PrimitiveKind::Int32:
|
|
411
|
+
case PrimitiveKind::Int32S:
|
|
387
412
|
case PrimitiveKind::UInt32:
|
|
413
|
+
case PrimitiveKind::UInt32S:
|
|
388
414
|
case PrimitiveKind::Int64:
|
|
415
|
+
case PrimitiveKind::Int64S:
|
|
389
416
|
case PrimitiveKind::UInt64:
|
|
417
|
+
case PrimitiveKind::UInt64S:
|
|
390
418
|
case PrimitiveKind::String:
|
|
391
419
|
case PrimitiveKind::String16:
|
|
392
420
|
case PrimitiveKind::Pointer:
|
|
@@ -418,11 +446,17 @@ Napi::Value CallData::Complete()
|
|
|
418
446
|
case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
|
|
419
447
|
case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
|
|
420
448
|
case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
|
|
449
|
+
case PrimitiveKind::Int16S: return Napi::Number::New(env, (double)ReverseBytes(result.i16));
|
|
421
450
|
case PrimitiveKind::UInt16: return Napi::Number::New(env, (double)result.u16);
|
|
451
|
+
case PrimitiveKind::UInt16S: return Napi::Number::New(env, (double)ReverseBytes(result.u16));
|
|
422
452
|
case PrimitiveKind::Int32: return Napi::Number::New(env, (double)result.i32);
|
|
453
|
+
case PrimitiveKind::Int32S: return Napi::Number::New(env, (double)ReverseBytes(result.i32));
|
|
423
454
|
case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
|
|
455
|
+
case PrimitiveKind::UInt32S: return Napi::Number::New(env, (double)ReverseBytes(result.u32));
|
|
424
456
|
case PrimitiveKind::Int64: return NewBigInt(env, result.i64);
|
|
457
|
+
case PrimitiveKind::Int64S: return NewBigInt(env, ReverseBytes(result.i64));
|
|
425
458
|
case PrimitiveKind::UInt64: return NewBigInt(env, result.u64);
|
|
459
|
+
case PrimitiveKind::UInt64S: return NewBigInt(env, ReverseBytes(result.u64));
|
|
426
460
|
case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
|
|
427
461
|
case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
|
|
428
462
|
case PrimitiveKind::Pointer:
|
|
@@ -524,24 +558,52 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
524
558
|
Napi::Value arg = Napi::Number::New(env, d);
|
|
525
559
|
arguments.Append(arg);
|
|
526
560
|
} break;
|
|
561
|
+
case PrimitiveKind::Int16S: {
|
|
562
|
+
int16_t v = *(int16_t *)(args_ptr++);
|
|
563
|
+
double d = (double)ReverseBytes(v);
|
|
564
|
+
|
|
565
|
+
Napi::Value arg = Napi::Number::New(env, d);
|
|
566
|
+
arguments.Append(arg);
|
|
567
|
+
} break;
|
|
527
568
|
case PrimitiveKind::UInt16: {
|
|
528
569
|
double d = (double)*(uint16_t *)(args_ptr++);
|
|
529
570
|
|
|
530
571
|
Napi::Value arg = Napi::Number::New(env, d);
|
|
531
572
|
arguments.Append(arg);
|
|
532
573
|
} break;
|
|
574
|
+
case PrimitiveKind::UInt16S: {
|
|
575
|
+
uint16_t v = *(uint16_t *)(args_ptr++);
|
|
576
|
+
double d = (double)ReverseBytes(v);
|
|
577
|
+
|
|
578
|
+
Napi::Value arg = Napi::Number::New(env, d);
|
|
579
|
+
arguments.Append(arg);
|
|
580
|
+
} break;
|
|
533
581
|
case PrimitiveKind::Int32: {
|
|
534
582
|
double d = (double)*(int32_t *)(args_ptr++);
|
|
535
583
|
|
|
536
584
|
Napi::Value arg = Napi::Number::New(env, d);
|
|
537
585
|
arguments.Append(arg);
|
|
538
586
|
} break;
|
|
587
|
+
case PrimitiveKind::Int32S: {
|
|
588
|
+
int32_t v = *(int32_t *)(args_ptr++);
|
|
589
|
+
double d = (double)ReverseBytes(v);
|
|
590
|
+
|
|
591
|
+
Napi::Value arg = Napi::Number::New(env, d);
|
|
592
|
+
arguments.Append(arg);
|
|
593
|
+
} break;
|
|
539
594
|
case PrimitiveKind::UInt32: {
|
|
540
595
|
double d = (double)*(uint32_t *)(args_ptr++);
|
|
541
596
|
|
|
542
597
|
Napi::Value arg = Napi::Number::New(env, d);
|
|
543
598
|
arguments.Append(arg);
|
|
544
599
|
} break;
|
|
600
|
+
case PrimitiveKind::UInt32S: {
|
|
601
|
+
uint32_t v = *(uint32_t *)(args_ptr++);
|
|
602
|
+
double d = (double)ReverseBytes(v);
|
|
603
|
+
|
|
604
|
+
Napi::Value arg = Napi::Number::New(env, d);
|
|
605
|
+
arguments.Append(arg);
|
|
606
|
+
} break;
|
|
545
607
|
case PrimitiveKind::Int64: {
|
|
546
608
|
int64_t v = *(int64_t *)args_ptr;
|
|
547
609
|
args_ptr += 2;
|
|
@@ -549,6 +611,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
549
611
|
Napi::Value arg = NewBigInt(env, v);
|
|
550
612
|
arguments.Append(arg);
|
|
551
613
|
} break;
|
|
614
|
+
case PrimitiveKind::Int64S: {
|
|
615
|
+
int64_t v = *(int64_t *)args_ptr;
|
|
616
|
+
args_ptr += 2;
|
|
617
|
+
|
|
618
|
+
Napi::Value arg = NewBigInt(env, ReverseBytes(v));
|
|
619
|
+
arguments.Append(arg);
|
|
620
|
+
} break;
|
|
552
621
|
case PrimitiveKind::UInt64: {
|
|
553
622
|
uint64_t v = *(uint64_t *)args_ptr;
|
|
554
623
|
args_ptr += 2;
|
|
@@ -556,6 +625,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
556
625
|
Napi::Value arg = NewBigInt(env, v);
|
|
557
626
|
arguments.Append(arg);
|
|
558
627
|
} break;
|
|
628
|
+
case PrimitiveKind::UInt64S: {
|
|
629
|
+
uint64_t v = *(uint64_t *)args_ptr;
|
|
630
|
+
args_ptr += 2;
|
|
631
|
+
|
|
632
|
+
Napi::Value arg = NewBigInt(env, ReverseBytes(v));
|
|
633
|
+
arguments.Append(arg);
|
|
634
|
+
} break;
|
|
559
635
|
case PrimitiveKind::String: {
|
|
560
636
|
const char *str = *(const char **)(args_ptr++);
|
|
561
637
|
|
|
@@ -632,6 +708,51 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
632
708
|
if (RG_UNLIKELY(env.IsExceptionPending()))
|
|
633
709
|
return;
|
|
634
710
|
|
|
711
|
+
#define RETURN_INTEGER_32(CType) \
|
|
712
|
+
do { \
|
|
713
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
714
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
715
|
+
return; \
|
|
716
|
+
} \
|
|
717
|
+
\
|
|
718
|
+
CType v = CopyNumber<CType>(value); \
|
|
719
|
+
out_reg->eax = (uint32_t)v; \
|
|
720
|
+
} while (false)
|
|
721
|
+
#define RETURN_INTEGER_32_SWAP(CType) \
|
|
722
|
+
do { \
|
|
723
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
724
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
725
|
+
return; \
|
|
726
|
+
} \
|
|
727
|
+
\
|
|
728
|
+
CType v = CopyNumber<CType>(value); \
|
|
729
|
+
out_reg->eax = (uint32_t)ReverseBytes(v); \
|
|
730
|
+
} while (false)
|
|
731
|
+
#define RETURN_INTEGER_64(CType) \
|
|
732
|
+
do { \
|
|
733
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
734
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
735
|
+
return; \
|
|
736
|
+
} \
|
|
737
|
+
\
|
|
738
|
+
CType v = CopyNumber<CType>(value); \
|
|
739
|
+
\
|
|
740
|
+
out_reg->eax = (uint32_t)((uint64_t)v >> 32); \
|
|
741
|
+
out_reg->edx = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
|
|
742
|
+
} while (false)
|
|
743
|
+
#define RETURN_INTEGER_64_SWAP(CType) \
|
|
744
|
+
do { \
|
|
745
|
+
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
|
|
746
|
+
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
|
|
747
|
+
return; \
|
|
748
|
+
} \
|
|
749
|
+
\
|
|
750
|
+
CType v = ReverseBytes(CopyNumber<CType>(value)); \
|
|
751
|
+
\
|
|
752
|
+
out_reg->eax = (uint32_t)((uint64_t)v >> 32); \
|
|
753
|
+
out_reg->edx = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
|
|
754
|
+
} while (false)
|
|
755
|
+
|
|
635
756
|
switch (type->primitive) {
|
|
636
757
|
case PrimitiveKind::Void: {} break;
|
|
637
758
|
case PrimitiveKind::Bool: {
|
|
@@ -643,31 +764,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
643
764
|
bool b = value.As<Napi::Boolean>();
|
|
644
765
|
out_reg->eax = (uint32_t)b;
|
|
645
766
|
} break;
|
|
646
|
-
case PrimitiveKind::Int8:
|
|
647
|
-
case PrimitiveKind::UInt8:
|
|
648
|
-
case PrimitiveKind::Int16:
|
|
649
|
-
case PrimitiveKind::
|
|
650
|
-
case PrimitiveKind::
|
|
651
|
-
case PrimitiveKind::
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
} break;
|
|
660
|
-
case PrimitiveKind::Int64:
|
|
661
|
-
case PrimitiveKind::UInt64: {
|
|
662
|
-
if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
|
|
663
|
-
ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
|
|
664
|
-
return;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
int64_t v = CopyNumber<int64_t>(value);
|
|
668
|
-
out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
|
|
669
|
-
out_reg->edx = (uint32_t)(v << 32);
|
|
670
|
-
} break;
|
|
767
|
+
case PrimitiveKind::Int8: { RETURN_INTEGER_32(int8_t); } break;
|
|
768
|
+
case PrimitiveKind::UInt8: { RETURN_INTEGER_32(uint8_t); } break;
|
|
769
|
+
case PrimitiveKind::Int16: { RETURN_INTEGER_32(int16_t); } break;
|
|
770
|
+
case PrimitiveKind::Int16S: { RETURN_INTEGER_32_SWAP(int16_t); } break;
|
|
771
|
+
case PrimitiveKind::UInt16: { RETURN_INTEGER_32(uint16_t); } break;
|
|
772
|
+
case PrimitiveKind::UInt16S: { RETURN_INTEGER_32_SWAP(uint16_t); } break;
|
|
773
|
+
case PrimitiveKind::Int32: { RETURN_INTEGER_32(int32_t); } break;
|
|
774
|
+
case PrimitiveKind::Int32S: { RETURN_INTEGER_32_SWAP(int32_t); } break;
|
|
775
|
+
case PrimitiveKind::UInt32: { RETURN_INTEGER_32(uint32_t); } break;
|
|
776
|
+
case PrimitiveKind::UInt32S: { RETURN_INTEGER_32_SWAP(uint32_t); } break;
|
|
777
|
+
case PrimitiveKind::Int64: { RETURN_INTEGER_64(int64_t); } break;
|
|
778
|
+
case PrimitiveKind::Int64S: { RETURN_INTEGER_64_SWAP(int64_t); } break;
|
|
779
|
+
case PrimitiveKind::UInt64: { RETURN_INTEGER_64(uint64_t); } break;
|
|
780
|
+
case PrimitiveKind::UInt64S: { RETURN_INTEGER_64_SWAP(uint64_t); } break;
|
|
671
781
|
case PrimitiveKind::String: {
|
|
672
782
|
const char *str;
|
|
673
783
|
if (RG_LIKELY(value.IsString())) {
|
|
@@ -778,6 +888,11 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
|
|
|
778
888
|
case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
|
|
779
889
|
}
|
|
780
890
|
|
|
891
|
+
#undef RETURN_INTEGER_64_SWAP
|
|
892
|
+
#undef RETURN_INTEGER_64
|
|
893
|
+
#undef RETURN_INTEGER_32_SWAP
|
|
894
|
+
#undef RETURN_INTEGER_32
|
|
895
|
+
|
|
781
896
|
err_guard.Disable();
|
|
782
897
|
}
|
|
783
898
|
|