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.
Files changed (104) hide show
  1. package/ChangeLog.md +2 -2
  2. package/build/qemu/2.1.0-beta.3/koffi_darwin_arm64.tar.gz +0 -0
  3. package/build/qemu/2.1.0-beta.3/koffi_darwin_x64.tar.gz +0 -0
  4. package/build/qemu/2.1.0-beta.3/koffi_freebsd_arm64.tar.gz +0 -0
  5. package/build/qemu/2.1.0-beta.3/koffi_freebsd_ia32.tar.gz +0 -0
  6. package/build/qemu/2.1.0-beta.3/koffi_freebsd_x64.tar.gz +0 -0
  7. package/build/qemu/2.1.0-beta.3/koffi_linux_arm32hf.tar.gz +0 -0
  8. package/build/qemu/2.1.0-beta.3/koffi_linux_arm64.tar.gz +0 -0
  9. package/build/qemu/2.1.0-beta.3/koffi_linux_ia32.tar.gz +0 -0
  10. package/build/qemu/2.1.0-beta.3/koffi_linux_riscv64hf64.tar.gz +0 -0
  11. package/build/qemu/2.1.0-beta.3/koffi_linux_x64.tar.gz +0 -0
  12. package/build/qemu/2.1.0-beta.3/koffi_openbsd_ia32.tar.gz +0 -0
  13. package/build/qemu/2.1.0-beta.3/koffi_openbsd_x64.tar.gz +0 -0
  14. package/build/qemu/2.1.0-beta.3/koffi_win32_arm64.tar.gz +0 -0
  15. package/build/qemu/2.1.0-beta.3/koffi_win32_ia32.tar.gz +0 -0
  16. package/build/qemu/2.1.0-beta.3/koffi_win32_x64.tar.gz +0 -0
  17. package/doc/Makefile +1 -1
  18. package/doc/conf.py +5 -0
  19. package/doc/dist/doctrees/changes.doctree +0 -0
  20. package/doc/dist/doctrees/environment.pickle +0 -0
  21. package/doc/dist/doctrees/functions.doctree +0 -0
  22. package/doc/dist/doctrees/index.doctree +0 -0
  23. package/doc/dist/doctrees/types.doctree +0 -0
  24. package/doc/dist/html/.buildinfo +4 -0
  25. package/doc/dist/html/_sources/benchmarks.md.txt +137 -0
  26. package/doc/dist/html/_sources/changes.md.txt +161 -0
  27. package/doc/dist/html/_sources/contribute.md.txt +127 -0
  28. package/doc/dist/html/_sources/functions.md.txt +421 -0
  29. package/doc/dist/html/_sources/index.rst.txt +39 -0
  30. package/doc/dist/html/_sources/memory.md.txt +32 -0
  31. package/doc/dist/html/_sources/platforms.md.txt +31 -0
  32. package/doc/dist/html/_sources/start.md.txt +100 -0
  33. package/doc/dist/html/_sources/types.md.txt +541 -0
  34. package/doc/dist/html/_static/_sphinx_javascript_frameworks_compat.js +134 -0
  35. package/doc/dist/html/_static/basic.css +932 -0
  36. package/doc/dist/html/_static/bench_linux.png +0 -0
  37. package/doc/dist/html/_static/bench_windows.png +0 -0
  38. package/doc/dist/html/_static/custom.css +22 -0
  39. package/doc/dist/html/_static/debug.css +69 -0
  40. package/doc/dist/html/_static/doctools.js +264 -0
  41. package/doc/dist/html/_static/documentation_options.js +14 -0
  42. package/doc/dist/html/_static/file.png +0 -0
  43. package/doc/dist/html/_static/jquery-3.6.0.js +10881 -0
  44. package/doc/dist/html/_static/jquery.js +2 -0
  45. package/doc/dist/html/_static/language_data.js +199 -0
  46. package/doc/dist/html/_static/minus.png +0 -0
  47. package/doc/dist/html/_static/perf_linux_20220623.png +0 -0
  48. package/doc/dist/html/_static/perf_linux_20220623_2.png +0 -0
  49. package/doc/dist/html/_static/perf_windows_20220623.png +0 -0
  50. package/doc/dist/html/_static/perf_windows_20220623_2.png +0 -0
  51. package/doc/dist/html/_static/plus.png +0 -0
  52. package/doc/dist/html/_static/pygments.css +252 -0
  53. package/doc/dist/html/_static/scripts/furo-extensions.js +0 -0
  54. package/doc/dist/html/_static/scripts/furo.js +3 -0
  55. package/doc/dist/html/_static/scripts/furo.js.LICENSE.txt +7 -0
  56. package/doc/dist/html/_static/scripts/furo.js.map +1 -0
  57. package/doc/dist/html/_static/searchtools.js +531 -0
  58. package/doc/dist/html/_static/skeleton.css +296 -0
  59. package/doc/dist/html/_static/styles/furo-extensions.css +2 -0
  60. package/doc/dist/html/_static/styles/furo-extensions.css.map +1 -0
  61. package/doc/dist/html/_static/styles/furo.css +2 -0
  62. package/doc/dist/html/_static/styles/furo.css.map +1 -0
  63. package/doc/dist/html/_static/underscore-1.13.1.js +2042 -0
  64. package/doc/dist/html/_static/underscore.js +6 -0
  65. package/doc/dist/html/benchmarks.html +571 -0
  66. package/doc/dist/html/changes.html +686 -0
  67. package/doc/dist/html/contribute.html +403 -0
  68. package/doc/dist/html/functions.html +718 -0
  69. package/doc/dist/html/genindex.html +253 -0
  70. package/doc/dist/html/index.html +359 -0
  71. package/doc/dist/html/memory.html +346 -0
  72. package/doc/dist/html/objects.inv +0 -0
  73. package/doc/dist/html/platforms.html +371 -0
  74. package/doc/dist/html/search.html +261 -0
  75. package/doc/dist/html/searchindex.js +1 -0
  76. package/doc/dist/html/start.html +384 -0
  77. package/doc/dist/html/types.html +1061 -0
  78. package/doc/make.bat +1 -1
  79. package/doc/templates/badges.html +1 -1
  80. package/doc/types.md +2 -0
  81. package/package.json +2 -1
  82. package/src/abi_arm32.cc +142 -200
  83. package/src/abi_arm64.cc +113 -122
  84. package/src/abi_riscv64.cc +76 -92
  85. package/src/abi_x64_sysv.cc +76 -92
  86. package/src/abi_x64_win.cc +76 -92
  87. package/src/abi_x86.cc +128 -164
  88. package/test/misc.c +43 -0
  89. package/test/sync.js +81 -0
  90. package/build/qemu/2.1.0-beta.2/koffi_darwin_arm64.tar.gz +0 -0
  91. package/build/qemu/2.1.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
  92. package/build/qemu/2.1.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
  93. package/build/qemu/2.1.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
  94. package/build/qemu/2.1.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
  95. package/build/qemu/2.1.0-beta.2/koffi_linux_arm32hf.tar.gz +0 -0
  96. package/build/qemu/2.1.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
  97. package/build/qemu/2.1.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
  98. package/build/qemu/2.1.0-beta.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  99. package/build/qemu/2.1.0-beta.2/koffi_linux_x64.tar.gz +0 -0
  100. package/build/qemu/2.1.0-beta.2/koffi_openbsd_ia32.tar.gz +0 -0
  101. package/build/qemu/2.1.0-beta.2/koffi_openbsd_x64.tar.gz +0 -0
  102. package/build/qemu/2.1.0-beta.2/koffi_win32_arm64.tar.gz +0 -0
  103. package/build/qemu/2.1.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
  104. package/build/qemu/2.1.0-beta.2/koffi_win32_x64.tar.gz +0 -0
@@ -304,6 +304,27 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
304
304
  *(uint8_t **)(gpr_ptr++) = return_ptr;
305
305
  }
306
306
 
307
+ #define PUSH_INTEGER(CType) \
308
+ do { \
309
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
310
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
311
+ return false; \
312
+ } \
313
+ \
314
+ CType v = CopyNumber<CType>(value); \
315
+ *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)v; \
316
+ } while (false)
317
+ #define PUSH_INTEGER_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
+ *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)ReverseBytes(v); \
326
+ } while (false)
327
+
307
328
  // Push arguments
308
329
  for (Size i = 0; i < func->parameters.len; i++) {
309
330
  const ParameterInfo &param = func->parameters[i];
@@ -323,52 +344,20 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
323
344
  bool b = value.As<Napi::Boolean>();
324
345
  *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)b;
325
346
  } break;
326
- case PrimitiveKind::Int8:
327
- case PrimitiveKind::UInt8:
328
- case PrimitiveKind::Int16:
329
- case PrimitiveKind::UInt16:
330
- case PrimitiveKind::Int32:
331
- case PrimitiveKind::UInt32:
332
- case PrimitiveKind::Int64: {
333
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
334
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
335
- return false;
336
- }
337
-
338
- int64_t v = CopyNumber<int64_t>(value);
339
- *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
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;
354
- case PrimitiveKind::UInt64: {
355
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
356
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
357
- return false;
358
- }
359
-
360
- uint64_t v = CopyNumber<uint64_t>(value);
361
- *((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
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;
347
+ case PrimitiveKind::Int8: { PUSH_INTEGER(int8_t); } break;
348
+ case PrimitiveKind::UInt8: { PUSH_INTEGER(uint8_t); } break;
349
+ case PrimitiveKind::Int16: { PUSH_INTEGER(int16_t); } break;
350
+ case PrimitiveKind::Int16S: { PUSH_INTEGER_SWAP(int16_t); } break;
351
+ case PrimitiveKind::UInt16: { PUSH_INTEGER(uint16_t); } break;
352
+ case PrimitiveKind::UInt16S: { PUSH_INTEGER_SWAP(uint16_t); } break;
353
+ case PrimitiveKind::Int32: { PUSH_INTEGER(int32_t); } break;
354
+ case PrimitiveKind::Int32S: { PUSH_INTEGER_SWAP(int32_t); } break;
355
+ case PrimitiveKind::UInt32: { PUSH_INTEGER(uint32_t); } break;
356
+ case PrimitiveKind::UInt32S: { PUSH_INTEGER_SWAP(uint32_t); } break;
357
+ case PrimitiveKind::Int64: { PUSH_INTEGER(int64_t); } break;
358
+ case PrimitiveKind::Int64S: { PUSH_INTEGER_SWAP(int64_t); } break;
359
+ case PrimitiveKind::UInt64: { PUSH_INTEGER(uint64_t); } break;
360
+ case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
372
361
  case PrimitiveKind::String: {
373
362
  const char *str;
374
363
  if (RG_LIKELY(value.IsString())) {
@@ -491,6 +480,9 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
491
480
  }
492
481
  }
493
482
 
483
+ #undef PUSH_INTEGER_SWAP
484
+ #undef PUSH_INTEGER
485
+
494
486
  new_sp = mem->stack.end();
495
487
 
496
488
  return true;
@@ -838,6 +830,27 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
838
830
  if (RG_UNLIKELY(env.IsExceptionPending()))
839
831
  return;
840
832
 
833
+ #define RETURN_INTEGER(CType) \
834
+ do { \
835
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
836
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
837
+ return; \
838
+ } \
839
+ \
840
+ CType v = CopyNumber<CType>(value); \
841
+ out_reg->rax = (uint64_t)v; \
842
+ } while (false)
843
+ #define RETURN_INTEGER_SWAP(CType) \
844
+ do { \
845
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
846
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
847
+ return; \
848
+ } \
849
+ \
850
+ CType v = CopyNumber<CType>(value); \
851
+ out_reg->rax = (uint64_t)ReverseBytes(v); \
852
+ } while (false)
853
+
841
854
  // Convert the result
842
855
  switch (type->primitive) {
843
856
  case PrimitiveKind::Void: {} break;
@@ -850,52 +863,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
850
863
  bool b = value.As<Napi::Boolean>();
851
864
  out_reg->rax = (uint64_t)b;
852
865
  } break;
853
- case PrimitiveKind::Int8:
854
- case PrimitiveKind::UInt8:
855
- case PrimitiveKind::Int16:
856
- case PrimitiveKind::UInt16:
857
- case PrimitiveKind::Int32:
858
- case PrimitiveKind::UInt32:
859
- case PrimitiveKind::Int64: {
860
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
861
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
862
- return;
863
- }
864
-
865
- int64_t v = CopyNumber<int64_t>(value);
866
- out_reg->rax = (uint64_t)v;
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;
866
+ case PrimitiveKind::Int8: { RETURN_INTEGER(int8_t); } break;
867
+ case PrimitiveKind::UInt8: { RETURN_INTEGER(uint8_t); } break;
868
+ case PrimitiveKind::Int16: { RETURN_INTEGER(int16_t); } break;
869
+ case PrimitiveKind::Int16S: { RETURN_INTEGER_SWAP(int16_t); } break;
870
+ case PrimitiveKind::UInt16: { RETURN_INTEGER(uint16_t); } break;
871
+ case PrimitiveKind::UInt16S: { RETURN_INTEGER_SWAP(uint16_t); } break;
872
+ case PrimitiveKind::Int32: { RETURN_INTEGER(int32_t); } break;
873
+ case PrimitiveKind::Int32S: { RETURN_INTEGER_SWAP(int32_t); } break;
874
+ case PrimitiveKind::UInt32: { RETURN_INTEGER(uint32_t); } break;
875
+ case PrimitiveKind::UInt32S: { RETURN_INTEGER_SWAP(uint32_t); } break;
876
+ case PrimitiveKind::Int64: { RETURN_INTEGER(int64_t); } break;
877
+ case PrimitiveKind::Int64S: { RETURN_INTEGER_SWAP(int64_t); } break;
878
+ case PrimitiveKind::UInt64: { RETURN_INTEGER(uint64_t); } break;
879
+ case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
899
880
  case PrimitiveKind::String: {
900
881
  const char *str;
901
882
  if (RG_LIKELY(value.IsString())) {
@@ -1026,6 +1007,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1026
1007
  case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1027
1008
  }
1028
1009
 
1010
+ #undef RETURN_INTEGER_SWAP
1011
+ #undef RETURN_INTEGER
1012
+
1029
1013
  err_guard.Disable();
1030
1014
  }
1031
1015
 
@@ -141,6 +141,27 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
141
141
  *(uint8_t **)(args_ptr++) = return_ptr;
142
142
  }
143
143
 
144
+ #define PUSH_INTEGER(CType) \
145
+ do { \
146
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
147
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
148
+ return false; \
149
+ } \
150
+ \
151
+ CType v = CopyNumber<CType>(value); \
152
+ *(args_ptr++) = (uint64_t)v; \
153
+ } while (false)
154
+ #define PUSH_INTEGER_SWAP(CType) \
155
+ do { \
156
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
157
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1); \
158
+ return false; \
159
+ } \
160
+ \
161
+ CType v = CopyNumber<CType>(value); \
162
+ *(args_ptr++) = (uint64_t)ReverseBytes(v); \
163
+ } while (false)
164
+
144
165
  // Push arguments
145
166
  for (Size i = 0; i < func->parameters.len; i++) {
146
167
  const ParameterInfo &param = func->parameters[i];
@@ -161,52 +182,20 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
161
182
 
162
183
  *(bool *)(args_ptr++) = b;
163
184
  } break;
164
- case PrimitiveKind::Int8:
165
- case PrimitiveKind::UInt8:
166
- case PrimitiveKind::Int16:
167
- case PrimitiveKind::UInt16:
168
- case PrimitiveKind::Int32:
169
- case PrimitiveKind::UInt32:
170
- case PrimitiveKind::Int64: {
171
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
172
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
173
- return false;
174
- }
175
-
176
- int64_t v = CopyNumber<int64_t>(value);
177
- *(int64_t *)(args_ptr++) = v;
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;
192
- case PrimitiveKind::UInt64: {
193
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
194
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
195
- return false;
196
- }
197
-
198
- uint64_t v = CopyNumber<uint64_t>(value);
199
- *(args_ptr++) = v;
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;
185
+ case PrimitiveKind::Int8: { PUSH_INTEGER(int8_t); } break;
186
+ case PrimitiveKind::UInt8: { PUSH_INTEGER(uint8_t); } break;
187
+ case PrimitiveKind::Int16: { PUSH_INTEGER(int16_t); } break;
188
+ case PrimitiveKind::Int16S: { PUSH_INTEGER_SWAP(int16_t); } break;
189
+ case PrimitiveKind::UInt16: { PUSH_INTEGER(uint16_t); } break;
190
+ case PrimitiveKind::UInt16S: { PUSH_INTEGER_SWAP(uint16_t); } break;
191
+ case PrimitiveKind::Int32: { PUSH_INTEGER(int32_t); } break;
192
+ case PrimitiveKind::Int32S: { PUSH_INTEGER_SWAP(int32_t); } break;
193
+ case PrimitiveKind::UInt32: { PUSH_INTEGER(uint32_t); } break;
194
+ case PrimitiveKind::UInt32S: { PUSH_INTEGER_SWAP(uint32_t); } break;
195
+ case PrimitiveKind::Int64: { PUSH_INTEGER(int64_t); } break;
196
+ case PrimitiveKind::Int64S: { PUSH_INTEGER_SWAP(int64_t); } break;
197
+ case PrimitiveKind::UInt64: { PUSH_INTEGER(uint64_t); } break;
198
+ case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
210
199
  case PrimitiveKind::String: {
211
200
  const char *str;
212
201
  if (RG_LIKELY(value.IsString())) {
@@ -308,6 +297,9 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
308
297
  }
309
298
  }
310
299
 
300
+ #undef PUSH_INTEGER_SWAP
301
+ #undef PUSH_INTEGER
302
+
311
303
  new_sp = mem->stack.end();
312
304
 
313
305
  return true;
@@ -637,6 +629,27 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
637
629
  if (RG_UNLIKELY(env.IsExceptionPending()))
638
630
  return;
639
631
 
632
+ #define RETURN_INTEGER(CType) \
633
+ do { \
634
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
635
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
636
+ return; \
637
+ } \
638
+ \
639
+ CType v = CopyNumber<CType>(value); \
640
+ out_reg->rax = (uint64_t)v; \
641
+ } while (false)
642
+ #define RETURN_INTEGER_SWAP(CType) \
643
+ do { \
644
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
645
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value)); \
646
+ return; \
647
+ } \
648
+ \
649
+ CType v = CopyNumber<CType>(value); \
650
+ out_reg->rax = (uint64_t)ReverseBytes(v); \
651
+ } while (false)
652
+
640
653
  switch (type->primitive) {
641
654
  case PrimitiveKind::Void: {} break;
642
655
  case PrimitiveKind::Bool: {
@@ -648,52 +661,20 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
648
661
  bool b = value.As<Napi::Boolean>();
649
662
  out_reg->rax = (uint64_t)b;
650
663
  } break;
651
- case PrimitiveKind::Int8:
652
- case PrimitiveKind::UInt8:
653
- case PrimitiveKind::Int16:
654
- case PrimitiveKind::UInt16:
655
- case PrimitiveKind::Int32:
656
- case PrimitiveKind::UInt32:
657
- case PrimitiveKind::Int64: {
658
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
659
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
660
- return;
661
- }
662
-
663
- int64_t v = CopyNumber<int64_t>(value);
664
- out_reg->rax = (uint64_t)v;
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;
664
+ case PrimitiveKind::Int8: { RETURN_INTEGER(int8_t); } break;
665
+ case PrimitiveKind::UInt8: { RETURN_INTEGER(uint8_t); } break;
666
+ case PrimitiveKind::Int16: { RETURN_INTEGER(int16_t); } break;
667
+ case PrimitiveKind::Int16S: { RETURN_INTEGER_SWAP(int16_t); } break;
668
+ case PrimitiveKind::UInt16: { RETURN_INTEGER(uint16_t); } break;
669
+ case PrimitiveKind::UInt16S: { RETURN_INTEGER_SWAP(uint16_t); } break;
670
+ case PrimitiveKind::Int32: { RETURN_INTEGER(int32_t); } break;
671
+ case PrimitiveKind::Int32S: { RETURN_INTEGER_SWAP(int32_t); } break;
672
+ case PrimitiveKind::UInt32: { RETURN_INTEGER(uint32_t); } break;
673
+ case PrimitiveKind::UInt32S: { RETURN_INTEGER_SWAP(uint32_t); } break;
674
+ case PrimitiveKind::Int64: { RETURN_INTEGER(int64_t); } break;
675
+ case PrimitiveKind::Int64S: { RETURN_INTEGER_SWAP(int64_t); } break;
676
+ case PrimitiveKind::UInt64: { RETURN_INTEGER(uint64_t); } break;
677
+ case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
697
678
  case PrimitiveKind::String: {
698
679
  const char *str;
699
680
  if (RG_LIKELY(value.IsString())) {
@@ -806,6 +787,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
806
787
  case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
807
788
  }
808
789
 
790
+ #undef RETURN_INTEGER_SWAP
791
+ #undef RETURN_INTEGER
792
+
809
793
  err_guard.Disable();
810
794
  }
811
795