koffi 2.1.0-beta.1 → 2.1.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/CMakeLists.txt +1 -1
  2. package/ChangeLog.md +17 -0
  3. package/build/qemu/2.1.0-beta.2/koffi_darwin_arm64.tar.gz +0 -0
  4. package/build/qemu/2.1.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
  5. package/build/qemu/2.1.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
  6. package/build/qemu/2.1.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
  7. package/build/qemu/2.1.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
  8. package/build/qemu/2.1.0-beta.2/koffi_linux_arm32hf.tar.gz +0 -0
  9. package/build/qemu/2.1.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
  10. package/build/qemu/2.1.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
  11. package/build/qemu/2.1.0-beta.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  12. package/build/qemu/2.1.0-beta.2/koffi_linux_x64.tar.gz +0 -0
  13. package/build/qemu/2.1.0-beta.2/koffi_openbsd_ia32.tar.gz +0 -0
  14. package/build/qemu/2.1.0-beta.2/koffi_openbsd_x64.tar.gz +0 -0
  15. package/build/qemu/2.1.0-beta.2/koffi_win32_arm64.tar.gz +0 -0
  16. package/build/qemu/2.1.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
  17. package/build/qemu/2.1.0-beta.2/koffi_win32_x64.tar.gz +0 -0
  18. package/doc/functions.md +67 -1
  19. package/doc/templates/badges.html +1 -2
  20. package/doc/types.md +100 -147
  21. package/package.json +1 -1
  22. package/src/abi_arm32.cc +166 -2
  23. package/src/abi_arm64.cc +195 -2
  24. package/src/abi_riscv64.cc +106 -2
  25. package/src/abi_x64_sysv.cc +113 -3
  26. package/src/abi_x64_win.cc +112 -2
  27. package/src/abi_x86.cc +155 -4
  28. package/src/call.cc +199 -0
  29. package/src/ffi.cc +50 -18
  30. package/src/ffi.hh +12 -0
  31. package/build/qemu/2.1.0-beta.1/koffi_darwin_arm64.tar.gz +0 -0
  32. package/build/qemu/2.1.0-beta.1/koffi_darwin_x64.tar.gz +0 -0
  33. package/build/qemu/2.1.0-beta.1/koffi_freebsd_arm64.tar.gz +0 -0
  34. package/build/qemu/2.1.0-beta.1/koffi_freebsd_ia32.tar.gz +0 -0
  35. package/build/qemu/2.1.0-beta.1/koffi_freebsd_x64.tar.gz +0 -0
  36. package/build/qemu/2.1.0-beta.1/koffi_linux_arm32hf.tar.gz +0 -0
  37. package/build/qemu/2.1.0-beta.1/koffi_linux_arm64.tar.gz +0 -0
  38. package/build/qemu/2.1.0-beta.1/koffi_linux_ia32.tar.gz +0 -0
  39. package/build/qemu/2.1.0-beta.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  40. package/build/qemu/2.1.0-beta.1/koffi_linux_x64.tar.gz +0 -0
  41. package/build/qemu/2.1.0-beta.1/koffi_openbsd_ia32.tar.gz +0 -0
  42. package/build/qemu/2.1.0-beta.1/koffi_openbsd_x64.tar.gz +0 -0
  43. package/build/qemu/2.1.0-beta.1/koffi_win32_arm64.tar.gz +0 -0
  44. package/build/qemu/2.1.0-beta.1/koffi_win32_ia32.tar.gz +0 -0
  45. package/build/qemu/2.1.0-beta.1/koffi_win32_x64.tar.gz +0 -0
  46. package/doc/dist/html/.buildinfo +0 -4
  47. package/doc/dist/html/_sources/benchmarks.md.txt +0 -137
  48. package/doc/dist/html/_sources/changes.md.txt +0 -161
  49. package/doc/dist/html/_sources/contribute.md.txt +0 -127
  50. package/doc/dist/html/_sources/functions.md.txt +0 -355
  51. package/doc/dist/html/_sources/index.rst.txt +0 -39
  52. package/doc/dist/html/_sources/memory.md.txt +0 -32
  53. package/doc/dist/html/_sources/platforms.md.txt +0 -31
  54. package/doc/dist/html/_sources/start.md.txt +0 -100
  55. package/doc/dist/html/_sources/types.md.txt +0 -588
  56. package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +0 -134
  57. package/doc/dist/html/_static/basic.css +0 -932
  58. package/doc/dist/html/_static/bench_linux.png +0 -0
  59. package/doc/dist/html/_static/bench_windows.png +0 -0
  60. package/doc/dist/html/_static/custom.css +0 -22
  61. package/doc/dist/html/_static/debug.css +0 -69
  62. package/doc/dist/html/_static/doctools.js +0 -264
  63. package/doc/dist/html/_static/documentation_options.js +0 -14
  64. package/doc/dist/html/_static/file.png +0 -0
  65. package/doc/dist/html/_static/jquery-3.6.0.js +0 -10881
  66. package/doc/dist/html/_static/jquery.js +0 -2
  67. package/doc/dist/html/_static/language_data.js +0 -199
  68. package/doc/dist/html/_static/minus.png +0 -0
  69. package/doc/dist/html/_static/perf_linux_20220623.png +0 -0
  70. package/doc/dist/html/_static/perf_linux_20220623_2.png +0 -0
  71. package/doc/dist/html/_static/perf_windows_20220623.png +0 -0
  72. package/doc/dist/html/_static/perf_windows_20220623_2.png +0 -0
  73. package/doc/dist/html/_static/plus.png +0 -0
  74. package/doc/dist/html/_static/pygments.css +0 -252
  75. package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
  76. package/doc/dist/html/_static/scripts/furo.js +0 -3
  77. package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +0 -7
  78. package/doc/dist/html/_static/scripts/furo.js.map +0 -1
  79. package/doc/dist/html/_static/searchtools.js +0 -531
  80. package/doc/dist/html/_static/skeleton.css +0 -296
  81. package/doc/dist/html/_static/styles/furo-extensions.css +0 -2
  82. package/doc/dist/html/_static/styles/furo-extensions.css.map +0 -1
  83. package/doc/dist/html/_static/styles/furo.css +0 -2
  84. package/doc/dist/html/_static/styles/furo.css.map +0 -1
  85. package/doc/dist/html/_static/underscore-1.13.1.js +0 -2042
  86. package/doc/dist/html/_static/underscore.js +0 -6
  87. package/doc/dist/html/benchmarks.html +0 -572
  88. package/doc/dist/html/changes.html +0 -668
  89. package/doc/dist/html/contribute.html +0 -404
  90. package/doc/dist/html/functions.html +0 -657
  91. package/doc/dist/html/genindex.html +0 -254
  92. package/doc/dist/html/index.html +0 -360
  93. package/doc/dist/html/memory.html +0 -347
  94. package/doc/dist/html/objects.inv +0 -0
  95. package/doc/dist/html/platforms.html +0 -372
  96. package/doc/dist/html/search.html +0 -262
  97. package/doc/dist/html/searchindex.js +0 -1
  98. package/doc/dist/html/start.html +0 -385
  99. package/doc/dist/html/types.html +0 -1097
@@ -247,6 +247,17 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
247
247
  int64_t v = CopyNumber<int64_t>(value);
248
248
  *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
249
249
  } break;
250
+ case PrimitiveKind::Int16S:
251
+ case PrimitiveKind::Int32S:
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;
250
261
  case PrimitiveKind::UInt8:
251
262
  case PrimitiveKind::UInt16:
252
263
  case PrimitiveKind::UInt32:
@@ -259,6 +270,17 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
259
270
  uint64_t v = CopyNumber<uint64_t>(value);
260
271
  *((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
261
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;
262
284
  case PrimitiveKind::String: {
263
285
  const char *str;
264
286
  if (RG_LIKELY(value.IsString())) {
@@ -428,11 +450,17 @@ void CallData::Execute()
428
450
  case PrimitiveKind::Int8:
429
451
  case PrimitiveKind::UInt8:
430
452
  case PrimitiveKind::Int16:
453
+ case PrimitiveKind::Int16S:
431
454
  case PrimitiveKind::UInt16:
455
+ case PrimitiveKind::UInt16S:
432
456
  case PrimitiveKind::Int32:
457
+ case PrimitiveKind::Int32S:
433
458
  case PrimitiveKind::UInt32:
459
+ case PrimitiveKind::UInt32S:
434
460
  case PrimitiveKind::Int64:
461
+ case PrimitiveKind::Int64S:
435
462
  case PrimitiveKind::UInt64:
463
+ case PrimitiveKind::UInt64S:
436
464
  case PrimitiveKind::String:
437
465
  case PrimitiveKind::String16:
438
466
  case PrimitiveKind::Pointer:
@@ -478,11 +506,17 @@ Napi::Value CallData::Complete()
478
506
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
479
507
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
480
508
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
509
+ case PrimitiveKind::Int16S: return Napi::Number::New(env, (double)ReverseBytes(result.i16));
481
510
  case PrimitiveKind::UInt16: return Napi::Number::New(env, (double)result.u16);
511
+ case PrimitiveKind::UInt16S: return Napi::Number::New(env, (double)ReverseBytes(result.u16));
482
512
  case PrimitiveKind::Int32: return Napi::Number::New(env, (double)result.i32);
513
+ case PrimitiveKind::Int32S: return Napi::Number::New(env, (double)ReverseBytes(result.i32));
483
514
  case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
515
+ case PrimitiveKind::UInt32S: return Napi::Number::New(env, (double)ReverseBytes(result.u32));
484
516
  case PrimitiveKind::Int64: return NewBigInt(env, result.i64);
517
+ case PrimitiveKind::Int64S: return NewBigInt(env, ReverseBytes(result.i64));
485
518
  case PrimitiveKind::UInt64: return NewBigInt(env, result.u64);
519
+ case PrimitiveKind::UInt64S: return NewBigInt(env, ReverseBytes(result.u64));
486
520
  case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
487
521
  case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
488
522
  case PrimitiveKind::Pointer:
@@ -576,36 +610,76 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
576
610
  Napi::Value arg = Napi::Number::New(env, d);
577
611
  arguments.Append(arg);
578
612
  } break;
613
+ case PrimitiveKind::Int16S: {
614
+ int16_t v = *(int16_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
615
+ double d = (double)ReverseBytes(v);
616
+
617
+ Napi::Value arg = Napi::Number::New(env, d);
618
+ arguments.Append(arg);
619
+ } break;
579
620
  case PrimitiveKind::UInt16: {
580
621
  double d = (double)*(uint16_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
581
622
 
582
623
  Napi::Value arg = Napi::Number::New(env, d);
583
624
  arguments.Append(arg);
584
625
  } break;
626
+ case PrimitiveKind::UInt16S: {
627
+ uint16_t v = *(uint16_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
628
+ double d = (double)ReverseBytes(v);
629
+
630
+ Napi::Value arg = Napi::Number::New(env, d);
631
+ arguments.Append(arg);
632
+ } break;
585
633
  case PrimitiveKind::Int32: {
586
634
  double d = (double)*(int32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
587
635
 
588
636
  Napi::Value arg = Napi::Number::New(env, d);
589
637
  arguments.Append(arg);
590
638
  } break;
639
+ case PrimitiveKind::Int32S: {
640
+ int32_t v = *(int32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
641
+ double d = (double)ReverseBytes(v);
642
+
643
+ Napi::Value arg = Napi::Number::New(env, d);
644
+ arguments.Append(arg);
645
+ } break;
591
646
  case PrimitiveKind::UInt32: {
592
647
  double d = (double)*(uint32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
593
648
 
594
649
  Napi::Value arg = Napi::Number::New(env, d);
595
650
  arguments.Append(arg);
596
651
  } break;
652
+ case PrimitiveKind::UInt32S: {
653
+ uint32_t v = *(uint32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
654
+ double d = (double)ReverseBytes(v);
655
+
656
+ Napi::Value arg = Napi::Number::New(env, d);
657
+ arguments.Append(arg);
658
+ } break;
597
659
  case PrimitiveKind::Int64: {
598
660
  int64_t v = *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
599
661
 
600
662
  Napi::Value arg = NewBigInt(env, v);
601
663
  arguments.Append(arg);
602
664
  } break;
665
+ case PrimitiveKind::Int64S: {
666
+ int64_t v = *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
667
+
668
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
669
+ arguments.Append(arg);
670
+ } break;
603
671
  case PrimitiveKind::UInt64: {
604
672
  uint64_t v = *(uint64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
605
673
 
606
674
  Napi::Value arg = NewBigInt(env, v);
607
675
  arguments.Append(arg);
608
676
  } break;
677
+ case PrimitiveKind::UInt64S: {
678
+ uint64_t v = *(uint64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
679
+
680
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
681
+ arguments.Append(arg);
682
+ } break;
609
683
  case PrimitiveKind::String: {
610
684
  const char *str = *(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++);
611
685
 
@@ -734,8 +808,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
734
808
  case PrimitiveKind::UInt16:
735
809
  case PrimitiveKind::Int32:
736
810
  case PrimitiveKind::UInt32:
737
- case PrimitiveKind::Int64:
738
- case PrimitiveKind::UInt64: {
811
+ case PrimitiveKind::Int64: {
739
812
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
740
813
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
741
814
  return;
@@ -744,6 +817,37 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
744
817
  int64_t v = CopyNumber<int64_t>(value);
745
818
  out_reg->a0 = (uint64_t)v;
746
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;
747
851
  case PrimitiveKind::String: {
748
852
  const char *str;
749
853
  if (RG_LIKELY(value.IsString())) {
@@ -169,11 +169,17 @@ static Size ClassifyType(const TypeInfo *type, Size offset, Span<RegisterClass>
169
169
  case PrimitiveKind::Int8:
170
170
  case PrimitiveKind::UInt8:
171
171
  case PrimitiveKind::Int16:
172
+ case PrimitiveKind::Int16S:
172
173
  case PrimitiveKind::UInt16:
174
+ case PrimitiveKind::UInt16S:
173
175
  case PrimitiveKind::Int32:
176
+ case PrimitiveKind::Int32S:
174
177
  case PrimitiveKind::UInt32:
178
+ case PrimitiveKind::UInt32S:
175
179
  case PrimitiveKind::Int64:
180
+ case PrimitiveKind::Int64S:
176
181
  case PrimitiveKind::UInt64:
182
+ case PrimitiveKind::UInt64S:
177
183
  case PrimitiveKind::String:
178
184
  case PrimitiveKind::String16:
179
185
  case PrimitiveKind::Pointer:
@@ -332,6 +338,19 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
332
338
  int64_t v = CopyNumber<int64_t>(value);
333
339
  *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
334
340
  } break;
341
+ case PrimitiveKind::Int16S:
342
+ case PrimitiveKind::UInt16S:
343
+ case PrimitiveKind::Int32S:
344
+ case PrimitiveKind::UInt32S:
345
+ case PrimitiveKind::Int64S: {
346
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
347
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
348
+ return false;
349
+ }
350
+
351
+ int64_t v = CopyNumber<int64_t>(value);
352
+ *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = ReverseBytes(v);
353
+ } break;
335
354
  case PrimitiveKind::UInt64: {
336
355
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
337
356
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
@@ -341,6 +360,15 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
341
360
  uint64_t v = CopyNumber<uint64_t>(value);
342
361
  *((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
343
362
  } break;
363
+ case PrimitiveKind::UInt64S: {
364
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
365
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
366
+ return false;
367
+ }
368
+
369
+ uint64_t v = CopyNumber<uint64_t>(value);
370
+ *((param.gpr_count ? gpr_ptr : args_ptr)++) = ReverseBytes(v);
371
+ } break;
344
372
  case PrimitiveKind::String: {
345
373
  const char *str;
346
374
  if (RG_LIKELY(value.IsString())) {
@@ -486,11 +514,17 @@ void CallData::Execute()
486
514
  case PrimitiveKind::Int8:
487
515
  case PrimitiveKind::UInt8:
488
516
  case PrimitiveKind::Int16:
517
+ case PrimitiveKind::Int16S:
489
518
  case PrimitiveKind::UInt16:
519
+ case PrimitiveKind::UInt16S:
490
520
  case PrimitiveKind::Int32:
521
+ case PrimitiveKind::Int32S:
491
522
  case PrimitiveKind::UInt32:
492
- case PrimitiveKind::Int64:
523
+ case PrimitiveKind::UInt32S:
524
+ case PrimitiveKind::Int64:
525
+ case PrimitiveKind::Int64S:
493
526
  case PrimitiveKind::UInt64:
527
+ case PrimitiveKind::UInt64S:
494
528
  case PrimitiveKind::String:
495
529
  case PrimitiveKind::String16:
496
530
  case PrimitiveKind::Pointer:
@@ -536,11 +570,17 @@ Napi::Value CallData::Complete()
536
570
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
537
571
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
538
572
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
573
+ case PrimitiveKind::Int16S: return Napi::Number::New(env, (double)ReverseBytes(result.i16));
539
574
  case PrimitiveKind::UInt16: return Napi::Number::New(env, (double)result.u16);
575
+ case PrimitiveKind::UInt16S: return Napi::Number::New(env, (double)ReverseBytes(result.u16));
540
576
  case PrimitiveKind::Int32: return Napi::Number::New(env, (double)result.i32);
577
+ case PrimitiveKind::Int32S: return Napi::Number::New(env, (double)ReverseBytes(result.i32));
541
578
  case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
579
+ case PrimitiveKind::UInt32S: return Napi::Number::New(env, (double)ReverseBytes(result.u32));
542
580
  case PrimitiveKind::Int64: return NewBigInt(env, result.i64);
581
+ case PrimitiveKind::Int64S: return NewBigInt(env, ReverseBytes(result.i64));
543
582
  case PrimitiveKind::UInt64: return NewBigInt(env, result.u64);
583
+ case PrimitiveKind::UInt64S: return NewBigInt(env, ReverseBytes(result.u64));
544
584
  case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
545
585
  case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
546
586
  case PrimitiveKind::Pointer:
@@ -629,36 +669,76 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
629
669
  Napi::Value arg = Napi::Number::New(env, d);
630
670
  arguments.Append(arg);
631
671
  } break;
672
+ case PrimitiveKind::Int16S: {
673
+ int16_t v = *(int16_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
674
+ double d = (double)ReverseBytes(v);
675
+
676
+ Napi::Value arg = Napi::Number::New(env, d);
677
+ arguments.Append(arg);
678
+ } break;
632
679
  case PrimitiveKind::UInt16: {
633
680
  double d = (double)*(uint16_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
634
681
 
635
682
  Napi::Value arg = Napi::Number::New(env, d);
636
683
  arguments.Append(arg);
637
684
  } break;
685
+ case PrimitiveKind::UInt16S: {
686
+ uint16_t v = *(uint16_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
687
+ double d = (double)ReverseBytes(v);
688
+
689
+ Napi::Value arg = Napi::Number::New(env, d);
690
+ arguments.Append(arg);
691
+ } break;
638
692
  case PrimitiveKind::Int32: {
639
693
  double d = (double)*(int32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
640
694
 
641
695
  Napi::Value arg = Napi::Number::New(env, d);
642
696
  arguments.Append(arg);
643
697
  } break;
698
+ case PrimitiveKind::Int32S: {
699
+ int32_t v = *(int32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
700
+ double d = (double)ReverseBytes(v);
701
+
702
+ Napi::Value arg = Napi::Number::New(env, d);
703
+ arguments.Append(arg);
704
+ } break;
644
705
  case PrimitiveKind::UInt32: {
645
706
  double d = (double)*(uint32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
646
707
 
647
708
  Napi::Value arg = Napi::Number::New(env, d);
648
709
  arguments.Append(arg);
649
710
  } break;
711
+ case PrimitiveKind::UInt32S: {
712
+ uint32_t v = *(uint32_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
713
+ double d = (double)ReverseBytes(v);
714
+
715
+ Napi::Value arg = Napi::Number::New(env, d);
716
+ arguments.Append(arg);
717
+ } break;
650
718
  case PrimitiveKind::Int64: {
651
719
  int64_t v = *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
652
720
 
653
721
  Napi::Value arg = NewBigInt(env, v);
654
722
  arguments.Append(arg);
655
723
  } break;
724
+ case PrimitiveKind::Int64S: {
725
+ int64_t v = *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
726
+
727
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
728
+ arguments.Append(arg);
729
+ } break;
656
730
  case PrimitiveKind::UInt64: {
657
731
  uint64_t v = *(uint64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
658
732
 
659
733
  Napi::Value arg = NewBigInt(env, v);
660
734
  arguments.Append(arg);
661
735
  } break;
736
+ case PrimitiveKind::UInt64S: {
737
+ uint64_t v = *(uint64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++);
738
+
739
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
740
+ arguments.Append(arg);
741
+ } break;
662
742
  case PrimitiveKind::String: {
663
743
  const char *str = *(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++);
664
744
 
@@ -776,8 +856,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
776
856
  case PrimitiveKind::UInt16:
777
857
  case PrimitiveKind::Int32:
778
858
  case PrimitiveKind::UInt32:
779
- case PrimitiveKind::Int64:
780
- case PrimitiveKind::UInt64: {
859
+ case PrimitiveKind::Int64: {
781
860
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
782
861
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
783
862
  return;
@@ -786,6 +865,37 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
786
865
  int64_t v = CopyNumber<int64_t>(value);
787
866
  out_reg->rax = (uint64_t)v;
788
867
  } break;
868
+ case PrimitiveKind::Int16S:
869
+ case PrimitiveKind::UInt16S:
870
+ case PrimitiveKind::Int32S:
871
+ case PrimitiveKind::UInt32S:
872
+ case PrimitiveKind::Int64S: {
873
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
874
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
875
+ return;
876
+ }
877
+
878
+ int64_t v = CopyNumber<int64_t>(value);
879
+ out_reg->rax = (uint64_t)ReverseBytes(v);
880
+ } break;
881
+ case PrimitiveKind::UInt64: {
882
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
883
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
884
+ return;
885
+ }
886
+
887
+ uint64_t v = CopyNumber<uint64_t>(value);
888
+ out_reg->rax = v;
889
+ } break;
890
+ case PrimitiveKind::UInt64S: {
891
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
892
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
893
+ return;
894
+ }
895
+
896
+ uint64_t v = CopyNumber<uint64_t>(value);
897
+ out_reg->rax = ReverseBytes(v);
898
+ } break;
789
899
  case PrimitiveKind::String: {
790
900
  const char *str;
791
901
  if (RG_LIKELY(value.IsString())) {
@@ -176,6 +176,19 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
176
176
  int64_t v = CopyNumber<int64_t>(value);
177
177
  *(int64_t *)(args_ptr++) = v;
178
178
  } break;
179
+ case PrimitiveKind::Int16S:
180
+ case PrimitiveKind::UInt16S:
181
+ case PrimitiveKind::Int32S:
182
+ case PrimitiveKind::UInt32S:
183
+ case PrimitiveKind::Int64S: {
184
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
185
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
186
+ return false;
187
+ }
188
+
189
+ int64_t v = CopyNumber<int64_t>(value);
190
+ *(int64_t *)(args_ptr++) = ReverseBytes(v);
191
+ } break;
179
192
  case PrimitiveKind::UInt64: {
180
193
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
181
194
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
@@ -185,6 +198,15 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
185
198
  uint64_t v = CopyNumber<uint64_t>(value);
186
199
  *(args_ptr++) = v;
187
200
  } break;
201
+ case PrimitiveKind::UInt64S: {
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
+ uint64_t v = CopyNumber<uint64_t>(value);
208
+ *(args_ptr++) = ReverseBytes(v);
209
+ } break;
188
210
  case PrimitiveKind::String: {
189
211
  const char *str;
190
212
  if (RG_LIKELY(value.IsString())) {
@@ -308,11 +330,17 @@ void CallData::Execute()
308
330
  case PrimitiveKind::Int8:
309
331
  case PrimitiveKind::UInt8:
310
332
  case PrimitiveKind::Int16:
333
+ case PrimitiveKind::Int16S:
311
334
  case PrimitiveKind::UInt16:
335
+ case PrimitiveKind::UInt16S:
312
336
  case PrimitiveKind::Int32:
337
+ case PrimitiveKind::Int32S:
313
338
  case PrimitiveKind::UInt32:
339
+ case PrimitiveKind::UInt32S:
314
340
  case PrimitiveKind::Int64:
341
+ case PrimitiveKind::Int64S:
315
342
  case PrimitiveKind::UInt64:
343
+ case PrimitiveKind::UInt64S:
316
344
  case PrimitiveKind::String:
317
345
  case PrimitiveKind::String16:
318
346
  case PrimitiveKind::Pointer:
@@ -344,11 +372,17 @@ Napi::Value CallData::Complete()
344
372
  case PrimitiveKind::Int8: return Napi::Number::New(env, (double)result.i8);
345
373
  case PrimitiveKind::UInt8: return Napi::Number::New(env, (double)result.u8);
346
374
  case PrimitiveKind::Int16: return Napi::Number::New(env, (double)result.i16);
375
+ case PrimitiveKind::Int16S: return Napi::Number::New(env, (double)ReverseBytes(result.i16));
347
376
  case PrimitiveKind::UInt16: return Napi::Number::New(env, (double)result.u16);
377
+ case PrimitiveKind::UInt16S: return Napi::Number::New(env, (double)ReverseBytes(result.u16));
348
378
  case PrimitiveKind::Int32: return Napi::Number::New(env, (double)result.i32);
379
+ case PrimitiveKind::Int32S: return Napi::Number::New(env, (double)ReverseBytes(result.i32));
349
380
  case PrimitiveKind::UInt32: return Napi::Number::New(env, (double)result.u32);
381
+ case PrimitiveKind::UInt32S: return Napi::Number::New(env, (double)ReverseBytes(result.u32));
350
382
  case PrimitiveKind::Int64: return NewBigInt(env, result.i64);
383
+ case PrimitiveKind::Int64S: return NewBigInt(env, ReverseBytes(result.i64));
351
384
  case PrimitiveKind::UInt64: return NewBigInt(env, result.u64);
385
+ case PrimitiveKind::UInt64S: return NewBigInt(env, ReverseBytes(result.u64));
352
386
  case PrimitiveKind::String: return result.ptr ? Napi::String::New(env, (const char *)result.ptr) : env.Null();
353
387
  case PrimitiveKind::String16: return result.ptr ? Napi::String::New(env, (const char16_t *)result.ptr) : env.Null();
354
388
  case PrimitiveKind::Pointer:
@@ -440,6 +474,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
440
474
  Napi::Value arg = Napi::Number::New(env, d);
441
475
  arguments.Append(arg);
442
476
  } break;
477
+ case PrimitiveKind::Int16S: {
478
+ int16_t v = *(int16_t *)(j < 4 ? gpr_ptr + j : args_ptr);
479
+ double d = (double)ReverseBytes(v);
480
+ args_ptr += (j >= 4);
481
+
482
+ Napi::Value arg = Napi::Number::New(env, d);
483
+ arguments.Append(arg);
484
+ } break;
443
485
  case PrimitiveKind::UInt16: {
444
486
  double d = (double)*(uint16_t *)(j < 4 ? gpr_ptr + j : args_ptr);
445
487
  args_ptr += (j >= 4);
@@ -447,6 +489,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
447
489
  Napi::Value arg = Napi::Number::New(env, d);
448
490
  arguments.Append(arg);
449
491
  } break;
492
+ case PrimitiveKind::UInt16S: {
493
+ uint16_t v = *(uint16_t *)(j < 4 ? gpr_ptr + j : args_ptr);
494
+ double d = (double)ReverseBytes(v);
495
+ args_ptr += (j >= 4);
496
+
497
+ Napi::Value arg = Napi::Number::New(env, d);
498
+ arguments.Append(arg);
499
+ } break;
450
500
  case PrimitiveKind::Int32: {
451
501
  double d = (double)*(int32_t *)(j < 4 ? gpr_ptr + j : args_ptr);
452
502
  args_ptr += (j >= 4);
@@ -454,6 +504,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
454
504
  Napi::Value arg = Napi::Number::New(env, d);
455
505
  arguments.Append(arg);
456
506
  } break;
507
+ case PrimitiveKind::Int32S: {
508
+ int32_t v = *(int32_t *)(j < 4 ? gpr_ptr + j : args_ptr);
509
+ double d = (double)ReverseBytes(v);
510
+ args_ptr += (j >= 4);
511
+
512
+ Napi::Value arg = Napi::Number::New(env, d);
513
+ arguments.Append(arg);
514
+ } break;
457
515
  case PrimitiveKind::UInt32: {
458
516
  double d = (double)*(uint32_t *)(j < 4 ? gpr_ptr + j : args_ptr);
459
517
  args_ptr += (j >= 4);
@@ -461,6 +519,14 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
461
519
  Napi::Value arg = Napi::Number::New(env, d);
462
520
  arguments.Append(arg);
463
521
  } break;
522
+ case PrimitiveKind::UInt32S: {
523
+ uint32_t v = *(uint32_t *)(j < 4 ? gpr_ptr + j : args_ptr);
524
+ double d = (double)ReverseBytes(v);
525
+ args_ptr += (j >= 4);
526
+
527
+ Napi::Value arg = Napi::Number::New(env, d);
528
+ arguments.Append(arg);
529
+ } break;
464
530
  case PrimitiveKind::Int64: {
465
531
  int64_t v = *(int64_t *)(j < 4 ? gpr_ptr + j : args_ptr);
466
532
  args_ptr += (j >= 4);
@@ -468,6 +534,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
468
534
  Napi::Value arg = NewBigInt(env, v);
469
535
  arguments.Append(arg);
470
536
  } break;
537
+ case PrimitiveKind::Int64S: {
538
+ int64_t v = *(int64_t *)(j < 4 ? gpr_ptr + j : args_ptr);
539
+ args_ptr += (j >= 4);
540
+
541
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
542
+ arguments.Append(arg);
543
+ } break;
471
544
  case PrimitiveKind::UInt64: {
472
545
  uint64_t v = *(uint64_t *)(j < 4 ? gpr_ptr + j : args_ptr);
473
546
  args_ptr += (j >= 4);
@@ -475,6 +548,13 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
475
548
  Napi::Value arg = NewBigInt(env, v);
476
549
  arguments.Append(arg);
477
550
  } break;
551
+ case PrimitiveKind::UInt64S: {
552
+ uint64_t v = *(uint64_t *)(j < 4 ? gpr_ptr + j : args_ptr);
553
+ args_ptr += (j >= 4);
554
+
555
+ Napi::Value arg = NewBigInt(env, ReverseBytes(v));
556
+ arguments.Append(arg);
557
+ } break;
478
558
  case PrimitiveKind::String: {
479
559
  const char *str = *(const char **)(j < 4 ? gpr_ptr + j : args_ptr);
480
560
  args_ptr += (j >= 4);
@@ -574,8 +654,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
574
654
  case PrimitiveKind::UInt16:
575
655
  case PrimitiveKind::Int32:
576
656
  case PrimitiveKind::UInt32:
577
- case PrimitiveKind::Int64:
578
- case PrimitiveKind::UInt64: {
657
+ case PrimitiveKind::Int64: {
579
658
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
580
659
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
581
660
  return;
@@ -584,6 +663,37 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
584
663
  int64_t v = CopyNumber<int64_t>(value);
585
664
  out_reg->rax = (uint64_t)v;
586
665
  } break;
666
+ case PrimitiveKind::Int16S:
667
+ case PrimitiveKind::UInt16S:
668
+ case PrimitiveKind::Int32S:
669
+ case PrimitiveKind::UInt32S:
670
+ case PrimitiveKind::Int64S: {
671
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
672
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
673
+ return;
674
+ }
675
+
676
+ int64_t v = CopyNumber<int64_t>(value);
677
+ out_reg->rax = (uint64_t)ReverseBytes(v);
678
+ } break;
679
+ case PrimitiveKind::UInt64: {
680
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
681
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
682
+ return;
683
+ }
684
+
685
+ uint64_t v = CopyNumber<uint64_t>(value);
686
+ out_reg->rax = v;
687
+ } break;
688
+ case PrimitiveKind::UInt64S: {
689
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
690
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
691
+ return;
692
+ }
693
+
694
+ uint64_t v = CopyNumber<uint64_t>(value);
695
+ out_reg->rax = ReverseBytes(v);
696
+ } break;
587
697
  case PrimitiveKind::String: {
588
698
  const char *str;
589
699
  if (RG_LIKELY(value.IsString())) {