koffi 2.1.0-beta.2 → 2.1.1

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 (200) hide show
  1. package/ChangeLog.md +11 -4
  2. package/build/qemu/2.1.1/koffi_darwin_arm64.tar.gz +0 -0
  3. package/build/qemu/2.1.1/koffi_darwin_x64.tar.gz +0 -0
  4. package/build/qemu/2.1.1/koffi_freebsd_arm64.tar.gz +0 -0
  5. package/build/qemu/2.1.1/koffi_freebsd_ia32.tar.gz +0 -0
  6. package/build/qemu/2.1.1/koffi_freebsd_x64.tar.gz +0 -0
  7. package/build/qemu/2.1.1/koffi_linux_arm32hf.tar.gz +0 -0
  8. package/build/qemu/2.1.1/koffi_linux_arm64.tar.gz +0 -0
  9. package/build/qemu/2.1.1/koffi_linux_ia32.tar.gz +0 -0
  10. package/build/qemu/2.1.1/koffi_linux_riscv64hf64.tar.gz +0 -0
  11. package/build/qemu/2.1.1/koffi_linux_x64.tar.gz +0 -0
  12. package/build/qemu/2.1.1/koffi_openbsd_ia32.tar.gz +0 -0
  13. package/build/qemu/2.1.1/koffi_openbsd_x64.tar.gz +0 -0
  14. package/build/qemu/2.1.1/koffi_win32_arm64.tar.gz +0 -0
  15. package/build/qemu/2.1.1/koffi_win32_ia32.tar.gz +0 -0
  16. package/build/qemu/2.1.1/koffi_win32_x64.tar.gz +0 -0
  17. package/doc/Makefile +1 -1
  18. package/doc/benchmarks.md +14 -14
  19. package/doc/benchmarks.xlsx +0 -0
  20. package/doc/conf.py +5 -0
  21. package/doc/index.rst +2 -2
  22. package/doc/make.bat +1 -1
  23. package/doc/static/perf_linux_20220812.png +0 -0
  24. package/doc/static/perf_windows_20220812.png +0 -0
  25. package/doc/templates/badges.html +1 -1
  26. package/doc/types.md +12 -12
  27. package/package.json +2 -1
  28. package/qemu/registry/machines.json +2 -2
  29. package/qemu/registry/sha256sum.txt +2 -2
  30. package/src/abi_arm32.cc +158 -248
  31. package/src/abi_arm64.cc +129 -170
  32. package/src/abi_riscv64.cc +92 -140
  33. package/src/abi_x64_sysv.cc +92 -140
  34. package/src/abi_x64_win.cc +92 -140
  35. package/src/abi_x86.cc +144 -212
  36. package/src/call.cc +117 -143
  37. package/src/call.hh +4 -4
  38. package/src/ffi.cc +16 -4
  39. package/src/util.hh +0 -20
  40. package/test/callbacks.js +3 -3
  41. package/test/misc.c +45 -2
  42. package/test/sync.js +83 -2
  43. package/vendor/libcc/libcc.cc +97 -77
  44. package/vendor/libcc/libcc.hh +362 -259
  45. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj +226 -0
  46. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.filters +10 -0
  47. package/vendor/raylib/projects/VS2019-Android/raylib_android/raylib_android.NativeActivity/raylib_android.NativeActivity.vcxproj.user +4 -0
  48. package/vendor/raylib/projects/VS2019-Android/raylib_android.sln +75 -0
  49. package/vendor/raylib/projects/VS2022/examples/audio_module_playing.vcxproj +390 -0
  50. package/vendor/raylib/projects/VS2022/examples/audio_multichannel_sound.vcxproj +390 -0
  51. package/vendor/raylib/projects/VS2022/examples/audio_music_stream.vcxproj +390 -0
  52. package/vendor/raylib/projects/VS2022/examples/audio_raw_stream.vcxproj +390 -0
  53. package/vendor/raylib/projects/VS2022/examples/audio_sound_loading.vcxproj +390 -0
  54. package/vendor/raylib/projects/VS2022/examples/audio_stream_effects.vcxproj +390 -0
  55. package/vendor/raylib/projects/VS2022/examples/core_2d_camera.vcxproj +390 -0
  56. package/vendor/raylib/projects/VS2022/examples/core_2d_camera_mouse_zoom.vcxproj +390 -0
  57. package/vendor/raylib/projects/VS2022/examples/core_2d_camera_platformer.vcxproj +390 -0
  58. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_first_person.vcxproj +390 -0
  59. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_free.vcxproj +390 -0
  60. package/vendor/raylib/projects/VS2022/examples/core_3d_camera_mode.vcxproj +390 -0
  61. package/vendor/raylib/projects/VS2022/examples/core_3d_picking.vcxproj +390 -0
  62. package/vendor/raylib/projects/VS2022/examples/core_basic_screen_manager.vcxproj +390 -0
  63. package/vendor/raylib/projects/VS2022/examples/core_basic_window.vcxproj +390 -0
  64. package/vendor/raylib/projects/VS2022/examples/core_custom_frame_control.vcxproj +390 -0
  65. package/vendor/raylib/projects/VS2022/examples/core_custom_logging.vcxproj +390 -0
  66. package/vendor/raylib/projects/VS2022/examples/core_drop_files.vcxproj +390 -0
  67. package/vendor/raylib/projects/VS2022/examples/core_input_gamepad.vcxproj +387 -0
  68. package/vendor/raylib/projects/VS2022/examples/core_input_gestures.vcxproj +387 -0
  69. package/vendor/raylib/projects/VS2022/examples/core_input_keys.vcxproj +387 -0
  70. package/vendor/raylib/projects/VS2022/examples/core_input_mouse.vcxproj +387 -0
  71. package/vendor/raylib/projects/VS2022/examples/core_input_mouse_wheel.vcxproj +387 -0
  72. package/vendor/raylib/projects/VS2022/examples/core_input_multitouch.vcxproj +387 -0
  73. package/vendor/raylib/projects/VS2022/examples/core_loading_thread.vcxproj +387 -0
  74. package/vendor/raylib/projects/VS2022/examples/core_random_values.vcxproj +387 -0
  75. package/vendor/raylib/projects/VS2022/examples/core_scissor_test.vcxproj +387 -0
  76. package/vendor/raylib/projects/VS2022/examples/core_split_screen.vcxproj +387 -0
  77. package/vendor/raylib/projects/VS2022/examples/core_storage_values.vcxproj +387 -0
  78. package/vendor/raylib/projects/VS2022/examples/core_vr_simulator.vcxproj +387 -0
  79. package/vendor/raylib/projects/VS2022/examples/core_window_flags.vcxproj +387 -0
  80. package/vendor/raylib/projects/VS2022/examples/core_window_letterbox.vcxproj +387 -0
  81. package/vendor/raylib/projects/VS2022/examples/core_window_should_close.vcxproj +390 -0
  82. package/vendor/raylib/projects/VS2022/examples/core_world_screen.vcxproj +387 -0
  83. package/vendor/raylib/projects/VS2022/examples/easings_testbed.vcxproj +387 -0
  84. package/vendor/raylib/projects/VS2022/examples/embedded_files_loading.vcxproj +387 -0
  85. package/vendor/raylib/projects/VS2022/examples/models_animation.vcxproj +387 -0
  86. package/vendor/raylib/projects/VS2022/examples/models_billboard.vcxproj +387 -0
  87. package/vendor/raylib/projects/VS2022/examples/models_box_collisions.vcxproj +387 -0
  88. package/vendor/raylib/projects/VS2022/examples/models_cubicmap.vcxproj +387 -0
  89. package/vendor/raylib/projects/VS2022/examples/models_first_person_maze.vcxproj +387 -0
  90. package/vendor/raylib/projects/VS2022/examples/models_geometric_shapes.vcxproj +387 -0
  91. package/vendor/raylib/projects/VS2022/examples/models_heightmap.vcxproj +387 -0
  92. package/vendor/raylib/projects/VS2022/examples/models_loading.vcxproj +387 -0
  93. package/vendor/raylib/projects/VS2022/examples/models_loading_gltf.vcxproj +387 -0
  94. package/vendor/raylib/projects/VS2022/examples/models_loading_vox.vcxproj +387 -0
  95. package/vendor/raylib/projects/VS2022/examples/models_mesh_generation.vcxproj +387 -0
  96. package/vendor/raylib/projects/VS2022/examples/models_mesh_picking.vcxproj +387 -0
  97. package/vendor/raylib/projects/VS2022/examples/models_orthographic_projection.vcxproj +387 -0
  98. package/vendor/raylib/projects/VS2022/examples/models_rlgl_solar_system.vcxproj +387 -0
  99. package/vendor/raylib/projects/VS2022/examples/models_skybox.vcxproj +387 -0
  100. package/vendor/raylib/projects/VS2022/examples/models_waving_cubes.vcxproj +387 -0
  101. package/vendor/raylib/projects/VS2022/examples/models_yaw_pitch_roll.vcxproj +387 -0
  102. package/vendor/raylib/projects/VS2022/examples/rlgl_compute_shaders.vcxproj +391 -0
  103. package/vendor/raylib/projects/VS2022/examples/rlgl_standalone.vcxproj +391 -0
  104. package/vendor/raylib/projects/VS2022/examples/shaders_basic_lighting.vcxproj +387 -0
  105. package/vendor/raylib/projects/VS2022/examples/shaders_custom_uniform.vcxproj +387 -0
  106. package/vendor/raylib/projects/VS2022/examples/shaders_eratosthenes.vcxproj +387 -0
  107. package/vendor/raylib/projects/VS2022/examples/shaders_fog.vcxproj +387 -0
  108. package/vendor/raylib/projects/VS2022/examples/shaders_hot_reloading.vcxproj +387 -0
  109. package/vendor/raylib/projects/VS2022/examples/shaders_julia_set.vcxproj +387 -0
  110. package/vendor/raylib/projects/VS2022/examples/shaders_mesh_instancing.vcxproj +387 -0
  111. package/vendor/raylib/projects/VS2022/examples/shaders_model_shader.vcxproj +387 -0
  112. package/vendor/raylib/projects/VS2022/examples/shaders_multi_sample2d.vcxproj +387 -0
  113. package/vendor/raylib/projects/VS2022/examples/shaders_palette_switch.vcxproj +387 -0
  114. package/vendor/raylib/projects/VS2022/examples/shaders_postprocessing.vcxproj +387 -0
  115. package/vendor/raylib/projects/VS2022/examples/shaders_raymarching.vcxproj +387 -0
  116. package/vendor/raylib/projects/VS2022/examples/shaders_shapes_textures.vcxproj +387 -0
  117. package/vendor/raylib/projects/VS2022/examples/shaders_simple_mask.vcxproj +387 -0
  118. package/vendor/raylib/projects/VS2022/examples/shaders_spotlight.vcxproj +387 -0
  119. package/vendor/raylib/projects/VS2022/examples/shaders_texture_drawing.vcxproj +387 -0
  120. package/vendor/raylib/projects/VS2022/examples/shaders_texture_waves.vcxproj +387 -0
  121. package/vendor/raylib/projects/VS2022/examples/shapes_basic_shapes.vcxproj +387 -0
  122. package/vendor/raylib/projects/VS2022/examples/shapes_bouncing_ball.vcxproj +387 -0
  123. package/vendor/raylib/projects/VS2022/examples/shapes_collision_area.vcxproj +387 -0
  124. package/vendor/raylib/projects/VS2022/examples/shapes_colors_palette.vcxproj +387 -0
  125. package/vendor/raylib/projects/VS2022/examples/shapes_draw_circle_sector.vcxproj +387 -0
  126. package/vendor/raylib/projects/VS2022/examples/shapes_draw_rectangle_rounded.vcxproj +387 -0
  127. package/vendor/raylib/projects/VS2022/examples/shapes_draw_ring.vcxproj +387 -0
  128. package/vendor/raylib/projects/VS2022/examples/shapes_easings_ball_anim.vcxproj +387 -0
  129. package/vendor/raylib/projects/VS2022/examples/shapes_easings_box_anim.vcxproj +387 -0
  130. package/vendor/raylib/projects/VS2022/examples/shapes_easings_rectangle_array.vcxproj +387 -0
  131. package/vendor/raylib/projects/VS2022/examples/shapes_following_eyes.vcxproj +387 -0
  132. package/vendor/raylib/projects/VS2022/examples/shapes_lines_bezier.vcxproj +387 -0
  133. package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib.vcxproj +387 -0
  134. package/vendor/raylib/projects/VS2022/examples/shapes_logo_raylib_anim.vcxproj +387 -0
  135. package/vendor/raylib/projects/VS2022/examples/shapes_rectangle_scaling.vcxproj +387 -0
  136. package/vendor/raylib/projects/VS2022/examples/text_codepoints_loading.vcxproj +387 -0
  137. package/vendor/raylib/projects/VS2022/examples/text_draw_3d.vcxproj +387 -0
  138. package/vendor/raylib/projects/VS2022/examples/text_font_filters.vcxproj +387 -0
  139. package/vendor/raylib/projects/VS2022/examples/text_font_loading.vcxproj +387 -0
  140. package/vendor/raylib/projects/VS2022/examples/text_font_sdf.vcxproj +387 -0
  141. package/vendor/raylib/projects/VS2022/examples/text_font_spritefont.vcxproj +387 -0
  142. package/vendor/raylib/projects/VS2022/examples/text_format_text.vcxproj +387 -0
  143. package/vendor/raylib/projects/VS2022/examples/text_input_box.vcxproj +387 -0
  144. package/vendor/raylib/projects/VS2022/examples/text_raylib_fonts.vcxproj +387 -0
  145. package/vendor/raylib/projects/VS2022/examples/text_rectangle_bounds.vcxproj +387 -0
  146. package/vendor/raylib/projects/VS2022/examples/text_unicode.vcxproj +387 -0
  147. package/vendor/raylib/projects/VS2022/examples/text_writing_anim.vcxproj +387 -0
  148. package/vendor/raylib/projects/VS2022/examples/textures_background_scrolling.vcxproj +387 -0
  149. package/vendor/raylib/projects/VS2022/examples/textures_blend_modes.vcxproj +387 -0
  150. package/vendor/raylib/projects/VS2022/examples/textures_bunnymark.vcxproj +387 -0
  151. package/vendor/raylib/projects/VS2022/examples/textures_draw_tiled.vcxproj +387 -0
  152. package/vendor/raylib/projects/VS2022/examples/textures_fog_of_war.vcxproj +387 -0
  153. package/vendor/raylib/projects/VS2022/examples/textures_gif_player.vcxproj +387 -0
  154. package/vendor/raylib/projects/VS2022/examples/textures_image_drawing.vcxproj +387 -0
  155. package/vendor/raylib/projects/VS2022/examples/textures_image_generation.vcxproj +387 -0
  156. package/vendor/raylib/projects/VS2022/examples/textures_image_loading.vcxproj +387 -0
  157. package/vendor/raylib/projects/VS2022/examples/textures_image_processing.vcxproj +387 -0
  158. package/vendor/raylib/projects/VS2022/examples/textures_image_text.vcxproj +387 -0
  159. package/vendor/raylib/projects/VS2022/examples/textures_logo_raylib.vcxproj +387 -0
  160. package/vendor/raylib/projects/VS2022/examples/textures_mouse_painting.vcxproj +387 -0
  161. package/vendor/raylib/projects/VS2022/examples/textures_npatch_drawing.vcxproj +387 -0
  162. package/vendor/raylib/projects/VS2022/examples/textures_particles_blending.vcxproj +387 -0
  163. package/vendor/raylib/projects/VS2022/examples/textures_polygon.vcxproj +387 -0
  164. package/vendor/raylib/projects/VS2022/examples/textures_raw_data.vcxproj +387 -0
  165. package/vendor/raylib/projects/VS2022/examples/textures_sprite_anim.vcxproj +387 -0
  166. package/vendor/raylib/projects/VS2022/examples/textures_sprite_button.vcxproj +387 -0
  167. package/vendor/raylib/projects/VS2022/examples/textures_sprite_explosion.vcxproj +387 -0
  168. package/vendor/raylib/projects/VS2022/examples/textures_srcrec_dstrec.vcxproj +387 -0
  169. package/vendor/raylib/projects/VS2022/examples/textures_to_image.vcxproj +387 -0
  170. package/vendor/raylib/projects/VS2022/raylib/raylib.vcxproj +340 -0
  171. package/vendor/raylib/projects/VS2022/raylib.sln +2347 -0
  172. package/build/qemu/2.1.0-beta.2/koffi_darwin_arm64.tar.gz +0 -0
  173. package/build/qemu/2.1.0-beta.2/koffi_darwin_x64.tar.gz +0 -0
  174. package/build/qemu/2.1.0-beta.2/koffi_freebsd_arm64.tar.gz +0 -0
  175. package/build/qemu/2.1.0-beta.2/koffi_freebsd_ia32.tar.gz +0 -0
  176. package/build/qemu/2.1.0-beta.2/koffi_freebsd_x64.tar.gz +0 -0
  177. package/build/qemu/2.1.0-beta.2/koffi_linux_arm32hf.tar.gz +0 -0
  178. package/build/qemu/2.1.0-beta.2/koffi_linux_arm64.tar.gz +0 -0
  179. package/build/qemu/2.1.0-beta.2/koffi_linux_ia32.tar.gz +0 -0
  180. package/build/qemu/2.1.0-beta.2/koffi_linux_riscv64hf64.tar.gz +0 -0
  181. package/build/qemu/2.1.0-beta.2/koffi_linux_x64.tar.gz +0 -0
  182. package/build/qemu/2.1.0-beta.2/koffi_openbsd_ia32.tar.gz +0 -0
  183. package/build/qemu/2.1.0-beta.2/koffi_openbsd_x64.tar.gz +0 -0
  184. package/build/qemu/2.1.0-beta.2/koffi_win32_arm64.tar.gz +0 -0
  185. package/build/qemu/2.1.0-beta.2/koffi_win32_ia32.tar.gz +0 -0
  186. package/build/qemu/2.1.0-beta.2/koffi_win32_x64.tar.gz +0 -0
  187. package/doc/dist/doctrees/benchmarks.doctree +0 -0
  188. package/doc/dist/doctrees/changes.doctree +0 -0
  189. package/doc/dist/doctrees/contribute.doctree +0 -0
  190. package/doc/dist/doctrees/environment.pickle +0 -0
  191. package/doc/dist/doctrees/functions.doctree +0 -0
  192. package/doc/dist/doctrees/index.doctree +0 -0
  193. package/doc/dist/doctrees/memory.doctree +0 -0
  194. package/doc/dist/doctrees/platforms.doctree +0 -0
  195. package/doc/dist/doctrees/start.doctree +0 -0
  196. package/doc/dist/doctrees/types.doctree +0 -0
  197. package/doc/dist/html/_static/perf_linux_20220627.png +0 -0
  198. package/doc/dist/html/_static/perf_linux_20220628.png +0 -0
  199. package/doc/dist/html/_static/perf_windows_20220627.png +0 -0
  200. package/doc/dist/html/_static/perf_windows_20220628.png +0 -0
package/src/abi_arm64.cc CHANGED
@@ -265,6 +265,64 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
265
265
  gpr_ptr[8] = (uint64_t)return_ptr;
266
266
  }
267
267
 
268
+ #ifdef __APPLE__
269
+ #define PUSH_INTEGER(CType) \
270
+ do { \
271
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
272
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
273
+ return false; \
274
+ } \
275
+ \
276
+ CType v = CopyNumber<CType>(value); \
277
+ \
278
+ if (RG_LIKELY(param.gpr_count)) { \
279
+ *(gpr_ptr++) = (uint64_t)v; \
280
+ } else { \
281
+ args_ptr = AlignUp(args_ptr, param.type->align); \
282
+ *args_ptr = (uint64_t)v; \
283
+ args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size); \
284
+ } \
285
+ } while (false)
286
+ #define PUSH_INTEGER_SWAP(CType) \
287
+ do { \
288
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
289
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
290
+ return false; \
291
+ } \
292
+ \
293
+ CType v = CopyNumber<CType>(value); \
294
+ \
295
+ if (RG_LIKELY(param.gpr_count)) { \
296
+ *(gpr_ptr++) = (uint64_t)ReverseBytes(v); \
297
+ } else { \
298
+ args_ptr = AlignUp(args_ptr, param.type->align); \
299
+ *args_ptr = (uint64_t)ReverseBytes(v); \
300
+ args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size); \
301
+ } \
302
+ } while (false)
303
+ #else
304
+ #define PUSH_INTEGER(CType) \
305
+ do { \
306
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
307
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
308
+ return false; \
309
+ } \
310
+ \
311
+ CType v = CopyNumber<CType>(value); \
312
+ *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)v; \
313
+ } while (false)
314
+ #define PUSH_INTEGER_SWAP(CType) \
315
+ do { \
316
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
317
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
318
+ return false; \
319
+ } \
320
+ \
321
+ CType v = CopyNumber<CType>(value); \
322
+ *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)ReverseBytes(v); \
323
+ } while (false)
324
+ #endif
325
+
268
326
  // Push arguments
269
327
  for (Size i = 0; i < func->parameters.len; i++) {
270
328
  const ParameterInfo &param = func->parameters[i];
@@ -277,7 +335,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
277
335
 
278
336
  case PrimitiveKind::Bool: {
279
337
  if (RG_UNLIKELY(!value.IsBoolean())) {
280
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected boolean", GetValueType(instance, value), param.offset + 1);
338
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
281
339
  return false;
282
340
  }
283
341
 
@@ -294,94 +352,24 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
294
352
  *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)b;
295
353
  #endif
296
354
  } break;
297
- case PrimitiveKind::Int8:
298
- case PrimitiveKind::UInt8:
299
- case PrimitiveKind::Int16:
300
- case PrimitiveKind::UInt16:
301
- case PrimitiveKind::Int32:
302
- case PrimitiveKind::UInt32:
303
- case PrimitiveKind::Int64: {
304
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
305
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
306
- return false;
307
- }
308
-
309
- int64_t v = CopyNumber<int64_t>(value);
310
-
311
- #ifdef __APPLE__
312
- if (RG_LIKELY(param.gpr_count)) {
313
- *(int64_t *)(gpr_ptr++) = v;
314
- } else {
315
- args_ptr = AlignUp(args_ptr, param.type->align);
316
- *(int64_t *)args_ptr = v;
317
- args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size);
318
- }
319
- #else
320
- *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
321
- #endif
322
- } break;
323
- case PrimitiveKind::Int16S:
324
- case PrimitiveKind::UInt16S:
325
- case PrimitiveKind::Int32S:
326
- case PrimitiveKind::UInt32S:
327
- case PrimitiveKind::Int64S: {
328
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
329
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
330
- return false;
331
- }
332
-
333
- int64_t v = ReverseBytes(CopyNumber<int64_t>(value));
334
-
335
- #ifdef __APPLE__
336
- if (RG_LIKELY(param.gpr_count)) {
337
- *(int64_t *)(gpr_ptr++) = v;
338
- } else {
339
- args_ptr = AlignUp(args_ptr, param.type->align);
340
- *(int64_t *)args_ptr = v;
341
- args_ptr = (uint64_t *)((uint8_t *)args_ptr + param.type->size);
342
- }
343
- #else
344
- *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
345
- #endif
346
- } break;
347
- case PrimitiveKind::UInt64: {
348
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
349
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
350
- return false;
351
- }
352
-
353
- uint64_t v = CopyNumber<uint64_t>(value);
354
-
355
- #ifdef __APPLE__
356
- args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
357
- #endif
358
- *((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
359
- } break;
360
- case PrimitiveKind::UInt64S: {
361
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
362
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
363
- return false;
364
- }
365
-
366
- uint64_t v = ReverseBytes(CopyNumber<uint64_t>(value));
367
-
368
- #ifdef __APPLE__
369
- args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
370
- #endif
371
- *((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
372
- } break;
355
+ case PrimitiveKind::Int8: { PUSH_INTEGER(int8_t); } break;
356
+ case PrimitiveKind::UInt8: { PUSH_INTEGER(uint8_t); } break;
357
+ case PrimitiveKind::Int16: { PUSH_INTEGER(int16_t); } break;
358
+ case PrimitiveKind::Int16S: { PUSH_INTEGER_SWAP(int16_t); } break;
359
+ case PrimitiveKind::UInt16: { PUSH_INTEGER(uint16_t); } break;
360
+ case PrimitiveKind::UInt16S: { PUSH_INTEGER_SWAP(uint16_t); } break;
361
+ case PrimitiveKind::Int32: { PUSH_INTEGER(int32_t); } break;
362
+ case PrimitiveKind::Int32S: { PUSH_INTEGER_SWAP(int32_t); } break;
363
+ case PrimitiveKind::UInt32: { PUSH_INTEGER(uint32_t); } break;
364
+ case PrimitiveKind::UInt32S: { PUSH_INTEGER_SWAP(uint32_t); } break;
365
+ case PrimitiveKind::Int64: { PUSH_INTEGER(int64_t); } break;
366
+ case PrimitiveKind::Int64S: { PUSH_INTEGER_SWAP(int64_t); } break;
367
+ case PrimitiveKind::UInt64: { PUSH_INTEGER(uint64_t); } break;
368
+ case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
373
369
  case PrimitiveKind::String: {
374
370
  const char *str;
375
- if (RG_LIKELY(value.IsString())) {
376
- str = PushString(value);
377
- if (RG_UNLIKELY(!str))
378
- return false;
379
- } else if (IsNullOrUndefined(value)) {
380
- str = nullptr;
381
- } else {
382
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
371
+ if (RG_UNLIKELY(!PushString(value, &str)))
383
372
  return false;
384
- }
385
373
 
386
374
  #ifdef __APPLE__
387
375
  args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
@@ -390,16 +378,8 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
390
378
  } break;
391
379
  case PrimitiveKind::String16: {
392
380
  const char16_t *str16;
393
- if (RG_LIKELY(value.IsString())) {
394
- str16 = PushString16(value);
395
- if (RG_UNLIKELY(!str16))
396
- return false;
397
- } else if (IsNullOrUndefined(value)) {
398
- str16 = nullptr;
399
- } else {
400
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
381
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
401
382
  return false;
402
- }
403
383
 
404
384
  #ifdef __APPLE__
405
385
  args_ptr = param.gpr_count ? args_ptr : AlignUp(args_ptr, 8);
@@ -408,7 +388,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
408
388
  } break;
409
389
  case PrimitiveKind::Pointer: {
410
390
  void *ptr;
411
- if (RG_UNLIKELY(!PushPointer(value, param, &ptr)))
391
+ if (RG_UNLIKELY(!PushPointer(value, param.type, param.directions, &ptr)))
412
392
  return false;
413
393
 
414
394
  #ifdef __APPLE__
@@ -418,7 +398,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
418
398
  } break;
419
399
  case PrimitiveKind::Record: {
420
400
  if (RG_UNLIKELY(!IsObject(value))) {
421
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), param.offset + 1);
401
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
422
402
  return false;
423
403
  }
424
404
 
@@ -465,7 +445,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
465
445
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
466
446
  case PrimitiveKind::Float32: {
467
447
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
468
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
448
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
469
449
  return false;
470
450
  }
471
451
 
@@ -492,7 +472,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
492
472
  } break;
493
473
  case PrimitiveKind::Float64: {
494
474
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
495
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
475
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
496
476
  return false;
497
477
  }
498
478
 
@@ -525,7 +505,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
525
505
  } else if (IsNullOrUndefined(value)) {
526
506
  ptr = nullptr;
527
507
  } else {
528
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), param.offset + 1, param.type->name);
508
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
529
509
  return false;
530
510
  }
531
511
 
@@ -539,6 +519,9 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
539
519
  }
540
520
  }
541
521
 
522
+ #undef PUSH_INTEGER_SWAP
523
+ #undef PUSH_INTEGER
524
+
542
525
  new_sp = mem->stack.end();
543
526
 
544
527
  return true;
@@ -1075,91 +1058,64 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1075
1058
  if (RG_UNLIKELY(env.IsExceptionPending()))
1076
1059
  return;
1077
1060
 
1061
+ #define RETURN_INTEGER(CType) \
1062
+ do { \
1063
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
1064
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
1065
+ return; \
1066
+ } \
1067
+ \
1068
+ CType v = CopyNumber<CType>(value); \
1069
+ out_reg->x0 = (uint64_t)v; \
1070
+ } while (false)
1071
+ #define RETURN_INTEGER_SWAP(CType) \
1072
+ do { \
1073
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
1074
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
1075
+ return; \
1076
+ } \
1077
+ \
1078
+ CType v = CopyNumber<CType>(value); \
1079
+ out_reg->x0 = (uint64_t)ReverseBytes(v); \
1080
+ } while (false)
1081
+
1078
1082
  // Convert the result
1079
1083
  switch (type->primitive) {
1080
1084
  case PrimitiveKind::Void: {} break;
1081
1085
  case PrimitiveKind::Bool: {
1082
1086
  if (RG_UNLIKELY(!value.IsBoolean())) {
1083
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected boolean", GetValueType(instance, value));
1087
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
1084
1088
  return;
1085
1089
  }
1086
1090
 
1087
1091
  bool b = value.As<Napi::Boolean>();
1088
1092
  out_reg->x0 = (uint64_t)b;
1089
1093
  } break;
1090
- case PrimitiveKind::Int8:
1091
- case PrimitiveKind::UInt8:
1092
- case PrimitiveKind::Int16:
1093
- case PrimitiveKind::UInt16:
1094
- case PrimitiveKind::Int32:
1095
- case PrimitiveKind::UInt32:
1096
- case PrimitiveKind::Int64: {
1097
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1098
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
1099
- return;
1100
- }
1101
-
1102
- int64_t v = CopyNumber<int64_t>(value);
1103
- out_reg->x0 = (uint64_t)v;
1104
- } break;
1105
- case PrimitiveKind::Int16S:
1106
- case PrimitiveKind::UInt16S:
1107
- case PrimitiveKind::Int32S:
1108
- case PrimitiveKind::UInt32S:
1109
- case PrimitiveKind::Int64S: {
1110
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1111
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
1112
- return;
1113
- }
1114
-
1115
- int64_t v = CopyNumber<int64_t>(value);
1116
- out_reg->x0 = (uint64_t)ReverseBytes(v);
1117
- } break;
1118
- case PrimitiveKind::UInt64: {
1119
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1120
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
1121
- return;
1122
- }
1123
-
1124
- uint64_t v = CopyNumber<uint64_t>(value);
1125
- out_reg->x0 = v;
1126
- } break;
1127
- case PrimitiveKind::UInt64S: {
1128
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1129
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
1130
- return;
1131
- }
1132
-
1133
- uint64_t v = CopyNumber<uint64_t>(value);
1134
- out_reg->x0 = ReverseBytes(v);
1135
- } break;
1094
+ case PrimitiveKind::Int8: { RETURN_INTEGER(int8_t); } break;
1095
+ case PrimitiveKind::UInt8: { RETURN_INTEGER(uint8_t); } break;
1096
+ case PrimitiveKind::Int16: { RETURN_INTEGER(int16_t); } break;
1097
+ case PrimitiveKind::Int16S: { RETURN_INTEGER_SWAP(int16_t); } break;
1098
+ case PrimitiveKind::UInt16: { RETURN_INTEGER(uint16_t); } break;
1099
+ case PrimitiveKind::UInt16S: { RETURN_INTEGER_SWAP(uint16_t); } break;
1100
+ case PrimitiveKind::Int32: { RETURN_INTEGER(int32_t); } break;
1101
+ case PrimitiveKind::Int32S: { RETURN_INTEGER_SWAP(int32_t); } break;
1102
+ case PrimitiveKind::UInt32: { RETURN_INTEGER(uint32_t); } break;
1103
+ case PrimitiveKind::UInt32S: { RETURN_INTEGER_SWAP(uint32_t); } break;
1104
+ case PrimitiveKind::Int64: { RETURN_INTEGER(int64_t); } break;
1105
+ case PrimitiveKind::Int64S: { RETURN_INTEGER_SWAP(int64_t); } break;
1106
+ case PrimitiveKind::UInt64: { RETURN_INTEGER(uint64_t); } break;
1107
+ case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
1136
1108
  case PrimitiveKind::String: {
1137
1109
  const char *str;
1138
- if (RG_LIKELY(value.IsString())) {
1139
- str = PushString(value);
1140
- if (RG_UNLIKELY(!str))
1141
- return;
1142
- } else if (IsNullOrUndefined(value)) {
1143
- str = nullptr;
1144
- } else {
1145
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected string", GetValueType(instance, value));
1110
+ if (RG_UNLIKELY(!PushString(value, &str)))
1146
1111
  return;
1147
- }
1148
1112
 
1149
1113
  out_reg->x0 = (uint64_t)str;
1150
1114
  } break;
1151
1115
  case PrimitiveKind::String16: {
1152
1116
  const char16_t *str16;
1153
- if (RG_LIKELY(value.IsString())) {
1154
- str16 = PushString16(value);
1155
- if (RG_UNLIKELY(!str16))
1156
- return;
1157
- } else if (IsNullOrUndefined(value)) {
1158
- str16 = nullptr;
1159
- } else {
1160
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected string", GetValueType(instance, value));
1117
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
1161
1118
  return;
1162
- }
1163
1119
 
1164
1120
  out_reg->x0 = (uint64_t)str16;
1165
1121
  } break;
@@ -1178,7 +1134,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1178
1134
  } else if (IsNullOrUndefined(value)) {
1179
1135
  ptr = nullptr;
1180
1136
  } else {
1181
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected %2", GetValueType(instance, value), type->name);
1137
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
1182
1138
  return;
1183
1139
  }
1184
1140
 
@@ -1186,7 +1142,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1186
1142
  } break;
1187
1143
  case PrimitiveKind::Record: {
1188
1144
  if (RG_UNLIKELY(!IsObject(value))) {
1189
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected object", GetValueType(instance, value));
1145
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
1190
1146
  return;
1191
1147
  }
1192
1148
 
@@ -1205,7 +1161,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1205
1161
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
1206
1162
  case PrimitiveKind::Float32: {
1207
1163
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1208
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
1164
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
1209
1165
  return;
1210
1166
  }
1211
1167
 
@@ -1216,7 +1172,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1216
1172
  } break;
1217
1173
  case PrimitiveKind::Float64: {
1218
1174
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
1219
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
1175
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
1220
1176
  return;
1221
1177
  }
1222
1178
 
@@ -1237,7 +1193,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1237
1193
  } else if (IsNullOrUndefined(value)) {
1238
1194
  ptr = nullptr;
1239
1195
  } else {
1240
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected %2", GetValueType(instance, value), type->name);
1196
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
1241
1197
  return;
1242
1198
  }
1243
1199
 
@@ -1247,6 +1203,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
1247
1203
  case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1248
1204
  }
1249
1205
 
1206
+ #undef RETURN_INTEGER_SWAP
1207
+ #undef RETURN_INTEGER
1208
+
1250
1209
  err_guard.Disable();
1251
1210
  }
1252
1211