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
@@ -216,6 +216,27 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
216
216
  *(uint8_t **)(gpr_ptr++) = return_ptr;
217
217
  }
218
218
 
219
+ #define PUSH_INTEGER(CType) \
220
+ do { \
221
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
222
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
223
+ return false; \
224
+ } \
225
+ \
226
+ CType v = CopyNumber<CType>(value); \
227
+ *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)v; \
228
+ } while (false)
229
+ #define PUSH_INTEGER_SWAP(CType) \
230
+ do { \
231
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
232
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
233
+ return false; \
234
+ } \
235
+ \
236
+ CType v = CopyNumber<CType>(value); \
237
+ *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)ReverseBytes(v); \
238
+ } while (false)
239
+
219
240
  // Push arguments
220
241
  for (Size i = 0; i < func->parameters.len; i++) {
221
242
  const ParameterInfo &param = func->parameters[i];
@@ -228,99 +249,51 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
228
249
 
229
250
  case PrimitiveKind::Bool: {
230
251
  if (RG_UNLIKELY(!value.IsBoolean())) {
231
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected boolean", GetValueType(instance, value), param.offset + 1);
252
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
232
253
  return false;
233
254
  }
234
255
 
235
256
  bool b = value.As<Napi::Boolean>();
236
257
  *((param.gpr_count ? gpr_ptr : args_ptr)++) = (uint64_t)b;
237
258
  } break;
238
- case PrimitiveKind::Int8:
239
- case PrimitiveKind::Int16:
240
- case PrimitiveKind::Int32:
241
- case PrimitiveKind::Int64: {
242
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
243
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
244
- return false;
245
- }
246
-
247
- int64_t v = CopyNumber<int64_t>(value);
248
- *(int64_t *)((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
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;
261
- case PrimitiveKind::UInt8:
262
- case PrimitiveKind::UInt16:
263
- case PrimitiveKind::UInt32:
264
- case PrimitiveKind::UInt64: {
265
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
266
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
267
- return false;
268
- }
269
-
270
- uint64_t v = CopyNumber<uint64_t>(value);
271
- *((param.gpr_count ? gpr_ptr : args_ptr)++) = v;
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;
259
+ case PrimitiveKind::Int8: { PUSH_INTEGER(int8_t); } break;
260
+ case PrimitiveKind::UInt8: { PUSH_INTEGER(uint8_t); } break;
261
+ case PrimitiveKind::Int16: { PUSH_INTEGER(int16_t); } break;
262
+ case PrimitiveKind::Int16S: { PUSH_INTEGER_SWAP(int16_t); } break;
263
+ case PrimitiveKind::UInt16: { PUSH_INTEGER(uint16_t); } break;
264
+ case PrimitiveKind::UInt16S: { PUSH_INTEGER_SWAP(uint16_t); } break;
265
+ case PrimitiveKind::Int32: { PUSH_INTEGER(int32_t); } break;
266
+ case PrimitiveKind::Int32S: { PUSH_INTEGER_SWAP(int32_t); } break;
267
+ case PrimitiveKind::UInt32: { PUSH_INTEGER(uint32_t); } break;
268
+ case PrimitiveKind::UInt32S: { PUSH_INTEGER_SWAP(uint32_t); } break;
269
+ case PrimitiveKind::Int64: { PUSH_INTEGER(int64_t); } break;
270
+ case PrimitiveKind::Int64S: { PUSH_INTEGER_SWAP(int64_t); } break;
271
+ case PrimitiveKind::UInt64: { PUSH_INTEGER(uint64_t); } break;
272
+ case PrimitiveKind::UInt64S: { PUSH_INTEGER_SWAP(uint64_t); } break;
284
273
  case PrimitiveKind::String: {
285
274
  const char *str;
286
- if (RG_LIKELY(value.IsString())) {
287
- str = PushString(value);
288
- if (RG_UNLIKELY(!str))
289
- return false;
290
- } else if (IsNullOrUndefined(value)) {
291
- str = nullptr;
292
- } else {
293
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
275
+ if (RG_UNLIKELY(!PushString(value, &str)))
294
276
  return false;
295
- }
296
277
 
297
278
  *(const char **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str;
298
279
  } break;
299
280
  case PrimitiveKind::String16: {
300
281
  const char16_t *str16;
301
- if (RG_LIKELY(value.IsString())) {
302
- str16 = PushString16(value);
303
- if (RG_UNLIKELY(!str16))
304
- return false;
305
- } else if (IsNullOrUndefined(value)) {
306
- str16 = nullptr;
307
- } else {
308
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
282
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
309
283
  return false;
310
- }
311
284
 
312
285
  *(const char16_t **)((param.gpr_count ? gpr_ptr : args_ptr)++) = str16;
313
286
  } break;
314
287
  case PrimitiveKind::Pointer: {
315
288
  void *ptr;
316
- if (RG_UNLIKELY(!PushPointer(value, param, &ptr)))
289
+ if (RG_UNLIKELY(!PushPointer(value, param.type, param.directions, &ptr)))
317
290
  return false;
318
291
 
319
292
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
320
293
  } break;
321
294
  case PrimitiveKind::Record: {
322
295
  if (RG_UNLIKELY(!IsObject(value))) {
323
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), param.offset + 1);
296
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
324
297
  return false;
325
298
  }
326
299
 
@@ -369,7 +342,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
369
342
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
370
343
  case PrimitiveKind::Float32: {
371
344
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
372
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
345
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
373
346
  return false;
374
347
  }
375
348
 
@@ -388,7 +361,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
388
361
  } break;
389
362
  case PrimitiveKind::Float64: {
390
363
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
391
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
364
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
392
365
  return false;
393
366
  }
394
367
 
@@ -416,7 +389,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
416
389
  } else if (IsNullOrUndefined(value)) {
417
390
  ptr = nullptr;
418
391
  } else {
419
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), param.offset + 1, param.type->name);
392
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
420
393
  return false;
421
394
  }
422
395
 
@@ -427,6 +400,9 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
427
400
  }
428
401
  }
429
402
 
403
+ #undef PUSH_INTEGER_SWAP
404
+ #undef PUSH_INTEGER
405
+
430
406
  new_sp = mem->stack.end();
431
407
 
432
408
  return true;
@@ -790,91 +766,64 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
790
766
  if (RG_UNLIKELY(env.IsExceptionPending()))
791
767
  return;
792
768
 
769
+ #define RETURN_INTEGER(CType) \
770
+ do { \
771
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
772
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
773
+ return; \
774
+ } \
775
+ \
776
+ CType v = CopyNumber<CType>(value); \
777
+ out_reg->a0 = (uint64_t)v; \
778
+ } while (false)
779
+ #define RETURN_INTEGER_SWAP(CType) \
780
+ do { \
781
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
782
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
783
+ return; \
784
+ } \
785
+ \
786
+ CType v = CopyNumber<CType>(value); \
787
+ out_reg->a0 = (uint64_t)ReverseBytes(v); \
788
+ } while (false)
789
+
793
790
  // Convert the result
794
791
  switch (type->primitive) {
795
792
  case PrimitiveKind::Void: {} break;
796
793
  case PrimitiveKind::Bool: {
797
794
  if (RG_UNLIKELY(!value.IsBoolean())) {
798
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected boolean", GetValueType(instance, value));
795
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
799
796
  return;
800
797
  }
801
798
 
802
799
  bool b = value.As<Napi::Boolean>();
803
800
  out_reg->a0 = (uint64_t)b;
804
801
  } break;
805
- case PrimitiveKind::Int8:
806
- case PrimitiveKind::UInt8:
807
- case PrimitiveKind::Int16:
808
- case PrimitiveKind::UInt16:
809
- case PrimitiveKind::Int32:
810
- case PrimitiveKind::UInt32:
811
- case PrimitiveKind::Int64: {
812
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
813
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
814
- return;
815
- }
816
-
817
- int64_t v = CopyNumber<int64_t>(value);
818
- out_reg->a0 = (uint64_t)v;
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;
802
+ case PrimitiveKind::Int8: { RETURN_INTEGER(int8_t); } break;
803
+ case PrimitiveKind::UInt8: { RETURN_INTEGER(uint8_t); } break;
804
+ case PrimitiveKind::Int16: { RETURN_INTEGER(int16_t); } break;
805
+ case PrimitiveKind::Int16S: { RETURN_INTEGER_SWAP(int16_t); } break;
806
+ case PrimitiveKind::UInt16: { RETURN_INTEGER(uint16_t); } break;
807
+ case PrimitiveKind::UInt16S: { RETURN_INTEGER_SWAP(uint16_t); } break;
808
+ case PrimitiveKind::Int32: { RETURN_INTEGER(int32_t); } break;
809
+ case PrimitiveKind::Int32S: { RETURN_INTEGER_SWAP(int32_t); } break;
810
+ case PrimitiveKind::UInt32: { RETURN_INTEGER(uint32_t); } break;
811
+ case PrimitiveKind::UInt32S: { RETURN_INTEGER_SWAP(uint32_t); } break;
812
+ case PrimitiveKind::Int64: { RETURN_INTEGER(int64_t); } break;
813
+ case PrimitiveKind::Int64S: { RETURN_INTEGER_SWAP(int64_t); } break;
814
+ case PrimitiveKind::UInt64: { RETURN_INTEGER(uint64_t); } break;
815
+ case PrimitiveKind::UInt64S: { RETURN_INTEGER_SWAP(uint64_t); } break;
851
816
  case PrimitiveKind::String: {
852
817
  const char *str;
853
- if (RG_LIKELY(value.IsString())) {
854
- str = PushString(value);
855
- if (RG_UNLIKELY(!str))
856
- return;
857
- } else if (IsNullOrUndefined(value)) {
858
- str = nullptr;
859
- } else {
860
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected string", GetValueType(instance, value));
818
+ if (RG_UNLIKELY(!PushString(value, &str)))
861
819
  return;
862
- }
863
820
 
864
821
  out_reg->a0 = (uint64_t)str;
865
822
  } break;
866
823
  case PrimitiveKind::String16: {
867
824
  const char16_t *str16;
868
- if (RG_LIKELY(value.IsString())) {
869
- str16 = PushString16(value);
870
- if (RG_UNLIKELY(!str16))
871
- return;
872
- } else if (IsNullOrUndefined(value)) {
873
- str16 = nullptr;
874
- } else {
875
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected string", GetValueType(instance, value));
825
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
876
826
  return;
877
- }
878
827
 
879
828
  out_reg->a0 = (uint64_t)str16;
880
829
  } break;
@@ -893,7 +842,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
893
842
  } else if (IsNullOrUndefined(value)) {
894
843
  ptr = nullptr;
895
844
  } else {
896
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected %2", GetValueType(instance, value), type->name);
845
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
897
846
  return;
898
847
  }
899
848
 
@@ -901,7 +850,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
901
850
  } break;
902
851
  case PrimitiveKind::Record: {
903
852
  if (RG_UNLIKELY(!IsObject(value))) {
904
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected object", GetValueType(instance, value));
853
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
905
854
  return;
906
855
  }
907
856
 
@@ -920,7 +869,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
920
869
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
921
870
  case PrimitiveKind::Float32: {
922
871
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
923
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
872
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
924
873
  return;
925
874
  }
926
875
 
@@ -930,7 +879,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
930
879
  } break;
931
880
  case PrimitiveKind::Float64: {
932
881
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
933
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
882
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
934
883
  return;
935
884
  }
936
885
 
@@ -951,7 +900,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
951
900
  } else if (IsNullOrUndefined(value)) {
952
901
  ptr = nullptr;
953
902
  } else {
954
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected %2", GetValueType(instance, value), type->name);
903
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
955
904
  return;
956
905
  }
957
906
 
@@ -961,6 +910,9 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
961
910
  case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
962
911
  }
963
912
 
913
+ #undef RETURN_INTEGER_SWAP
914
+ #undef RETURN_INTEGER
915
+
964
916
  err_guard.Disable();
965
917
  }
966
918