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_x86.cc CHANGED
@@ -197,6 +197,51 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
197
197
  *((func->ret.fast ? fast_ptr : args_ptr)++) = (uint32_t)return_ptr;
198
198
  }
199
199
 
200
+ #define PUSH_INTEGER_32(CType) \
201
+ do { \
202
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
203
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
204
+ return false; \
205
+ } \
206
+ \
207
+ CType v = CopyNumber<CType>(value); \
208
+ *((param.fast ? fast_ptr : args_ptr)++) = (uint32_t)v; \
209
+ } while (false)
210
+ #define PUSH_INTEGER_32_SWAP(CType) \
211
+ do { \
212
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
213
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
214
+ return false; \
215
+ } \
216
+ \
217
+ CType v = CopyNumber<CType>(value); \
218
+ *((param.fast ? fast_ptr : args_ptr)++) = (uint32_t)ReverseBytes(v); \
219
+ } while (false)
220
+ #define PUSH_INTEGER_64(CType) \
221
+ do { \
222
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
223
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
224
+ return false; \
225
+ } \
226
+ \
227
+ CType v = CopyNumber<CType>(value); \
228
+ \
229
+ *(uint64_t *)args_ptr = (uint64_t)v; \
230
+ args_ptr += 2; \
231
+ } while (false)
232
+ #define PUSH_INTEGER_64_SWAP(CType) \
233
+ do { \
234
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
235
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
236
+ return false; \
237
+ } \
238
+ \
239
+ CType v = CopyNumber<CType>(value); \
240
+ \
241
+ *(uint64_t *)args_ptr = (uint64_t)ReverseBytes(v); \
242
+ args_ptr += 2; \
243
+ } while (false)
244
+
200
245
  // Push arguments
201
246
  for (Size i = 0; i < func->parameters.len; i++) {
202
247
  const ParameterInfo &param = func->parameters[i];
@@ -209,135 +254,51 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
209
254
 
210
255
  case PrimitiveKind::Bool: {
211
256
  if (RG_UNLIKELY(!value.IsBoolean())) {
212
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected boolean", GetValueType(instance, value), param.offset + 1);
257
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
213
258
  return false;
214
259
  }
215
260
 
216
261
  bool b = value.As<Napi::Boolean>();
217
262
  *(bool *)((param.fast ? fast_ptr : args_ptr)++) = b;
218
263
  } break;
219
- case PrimitiveKind::Int8:
220
- case PrimitiveKind::UInt8:
221
- case PrimitiveKind::Int16:
222
- case PrimitiveKind::UInt16:
223
- case PrimitiveKind::Int32: {
224
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
225
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
226
- return false;
227
- }
228
-
229
- int32_t v = CopyNumber<int32_t>(value);
230
- *(int32_t *)((param.fast ? fast_ptr : args_ptr)++) = v;
231
- } break;
232
- case PrimitiveKind::Int16S:
233
- case PrimitiveKind::UInt16S:
234
- case PrimitiveKind::Int32S: {
235
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
236
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
237
- return false;
238
- }
239
-
240
- int32_t v = CopyNumber<int32_t>(value);
241
- *(int32_t *)((param.fast ? fast_ptr : args_ptr)++) = ReverseBytes(v);
242
- } break;
243
- case PrimitiveKind::UInt32: {
244
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
245
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
246
- return false;
247
- }
248
-
249
- uint32_t v = CopyNumber<uint32_t>(value);
250
- *((param.fast ? fast_ptr : args_ptr)++) = v;
251
- } break;
252
- case PrimitiveKind::UInt32S: {
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
- uint32_t v = CopyNumber<uint32_t>(value);
259
- *((param.fast ? fast_ptr : args_ptr)++) = ReverseBytes(v);
260
- } break;
261
- case PrimitiveKind::Int64: {
262
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
263
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
264
- return false;
265
- }
266
-
267
- int64_t v = CopyNumber<int64_t>(value);
268
- *(int64_t *)args_ptr = v;
269
- args_ptr += 2;
270
- } break;
271
- case PrimitiveKind::Int64S: {
272
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
273
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
274
- return false;
275
- }
276
-
277
- int64_t v = CopyNumber<int64_t>(value);
278
- *(int64_t *)args_ptr = ReverseBytes(v);
279
- args_ptr += 2;
280
- } break;
281
- case PrimitiveKind::UInt64: {
282
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
283
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
284
- return false;
285
- }
286
-
287
- uint64_t v = CopyNumber<uint64_t>(value);
288
- *(uint64_t *)args_ptr = v;
289
- args_ptr += 2;
290
- } break;
291
- case PrimitiveKind::UInt64S: {
292
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
293
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
294
- return false;
295
- }
296
-
297
- uint64_t v = CopyNumber<uint64_t>(value);
298
- *(uint64_t *)args_ptr = ReverseBytes(v);
299
- args_ptr += 2;
300
- } break;
264
+ case PrimitiveKind::Int8: { PUSH_INTEGER_32(int8_t); } break;
265
+ case PrimitiveKind::UInt8: { PUSH_INTEGER_32(uint8_t); } break;
266
+ case PrimitiveKind::Int16: { PUSH_INTEGER_32(int16_t); } break;
267
+ case PrimitiveKind::Int16S: { PUSH_INTEGER_32_SWAP(int16_t); } break;
268
+ case PrimitiveKind::UInt16: { PUSH_INTEGER_32(uint16_t); } break;
269
+ case PrimitiveKind::UInt16S: { PUSH_INTEGER_32_SWAP(uint16_t); } break;
270
+ case PrimitiveKind::Int32: { PUSH_INTEGER_32(int32_t); } break;
271
+ case PrimitiveKind::Int32S: { PUSH_INTEGER_32_SWAP(int32_t); } break;
272
+ case PrimitiveKind::UInt32: { PUSH_INTEGER_32(uint32_t); } break;
273
+ case PrimitiveKind::UInt32S: { PUSH_INTEGER_32_SWAP(uint32_t); } break;
274
+ case PrimitiveKind::Int64: { PUSH_INTEGER_64(int64_t); } break;
275
+ case PrimitiveKind::Int64S: { PUSH_INTEGER_64_SWAP(int64_t); } break;
276
+ case PrimitiveKind::UInt64: { PUSH_INTEGER_64(uint64_t); } break;
277
+ case PrimitiveKind::UInt64S: { PUSH_INTEGER_64_SWAP(uint64_t); } break;
301
278
  case PrimitiveKind::String: {
302
279
  const char *str;
303
- if (RG_LIKELY(value.IsString())) {
304
- str = PushString(value);
305
- if (RG_UNLIKELY(!str))
306
- return false;
307
- } else if (IsNullOrUndefined(value)) {
308
- str = nullptr;
309
- } else {
310
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
280
+ if (RG_UNLIKELY(!PushString(value, &str)))
311
281
  return false;
312
- }
313
282
 
314
283
  *(const char **)((param.fast ? fast_ptr : args_ptr)++) = str;
315
284
  } break;
316
285
  case PrimitiveKind::String16: {
317
286
  const char16_t *str16;
318
- if (RG_LIKELY(value.IsString())) {
319
- str16 = PushString16(value);
320
- if (RG_UNLIKELY(!str16))
321
- return false;
322
- } else if (IsNullOrUndefined(value)) {
323
- str16 = nullptr;
324
- } else {
325
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected string", GetValueType(instance, value), param.offset + 1);
287
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
326
288
  return false;
327
- }
328
289
 
329
290
  *(const char16_t **)((param.fast ? fast_ptr : args_ptr)++) = str16;
330
291
  } break;
331
292
  case PrimitiveKind::Pointer: {
332
293
  void *ptr;
333
- if (RG_UNLIKELY(!PushPointer(value, param, &ptr)))
294
+ if (RG_UNLIKELY(!PushPointer(value, param.type, param.directions, &ptr)))
334
295
  return false;
335
296
 
336
297
  *(void **)((param.fast ? fast_ptr : args_ptr)++) = ptr;
337
298
  } break;
338
299
  case PrimitiveKind::Record: {
339
300
  if (RG_UNLIKELY(!IsObject(value))) {
340
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected object", GetValueType(instance, value), param.offset + 1);
301
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
341
302
  return false;
342
303
  }
343
304
 
@@ -357,7 +318,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
357
318
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
358
319
  case PrimitiveKind::Float32: {
359
320
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
360
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
321
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
361
322
  return false;
362
323
  }
363
324
 
@@ -366,7 +327,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
366
327
  } break;
367
328
  case PrimitiveKind::Float64: {
368
329
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
369
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected number", GetValueType(instance, value), param.offset + 1);
330
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
370
331
  return false;
371
332
  }
372
333
 
@@ -388,7 +349,7 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
388
349
  } else if (IsNullOrUndefined(value)) {
389
350
  ptr = nullptr;
390
351
  } else {
391
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for argument %2, expected %3", GetValueType(instance, value), param.offset + 1, param.type->name);
352
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), param.type->name);
392
353
  return false;
393
354
  }
394
355
 
@@ -399,6 +360,11 @@ bool CallData::Prepare(const Napi::CallbackInfo &info)
399
360
  }
400
361
  }
401
362
 
363
+ #undef PUSH_INTEGER_64_SWAP
364
+ #undef PUSH_INTEGER_64
365
+ #undef PUSH_INTEGER_32_SWAP
366
+ #undef PUSH_INTEGER_32
367
+
402
368
  new_sp = mem->stack.end();
403
369
 
404
370
  return true;
@@ -726,126 +692,87 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
726
692
  if (RG_UNLIKELY(env.IsExceptionPending()))
727
693
  return;
728
694
 
695
+ #define RETURN_INTEGER_32(CType) \
696
+ do { \
697
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
698
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
699
+ return; \
700
+ } \
701
+ \
702
+ CType v = CopyNumber<CType>(value); \
703
+ out_reg->eax = (uint32_t)v; \
704
+ } while (false)
705
+ #define RETURN_INTEGER_32_SWAP(CType) \
706
+ do { \
707
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
708
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
709
+ return; \
710
+ } \
711
+ \
712
+ CType v = CopyNumber<CType>(value); \
713
+ out_reg->eax = (uint32_t)ReverseBytes(v); \
714
+ } while (false)
715
+ #define RETURN_INTEGER_64(CType) \
716
+ do { \
717
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
718
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
719
+ return; \
720
+ } \
721
+ \
722
+ CType v = CopyNumber<CType>(value); \
723
+ \
724
+ out_reg->eax = (uint32_t)((uint64_t)v >> 32); \
725
+ out_reg->edx = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
726
+ } while (false)
727
+ #define RETURN_INTEGER_64_SWAP(CType) \
728
+ do { \
729
+ if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) { \
730
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value)); \
731
+ return; \
732
+ } \
733
+ \
734
+ CType v = ReverseBytes(CopyNumber<CType>(value)); \
735
+ \
736
+ out_reg->eax = (uint32_t)((uint64_t)v >> 32); \
737
+ out_reg->edx = (uint32_t)((uint64_t)v & 0xFFFFFFFFu); \
738
+ } while (false)
739
+
729
740
  switch (type->primitive) {
730
741
  case PrimitiveKind::Void: {} break;
731
742
  case PrimitiveKind::Bool: {
732
743
  if (RG_UNLIKELY(!value.IsBoolean())) {
733
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected boolean", GetValueType(instance, value));
744
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected boolean", GetValueType(instance, value));
734
745
  return;
735
746
  }
736
747
 
737
748
  bool b = value.As<Napi::Boolean>();
738
749
  out_reg->eax = (uint32_t)b;
739
750
  } break;
740
- case PrimitiveKind::Int8:
741
- case PrimitiveKind::UInt8:
742
- case PrimitiveKind::Int16:
743
- case PrimitiveKind::UInt16:
744
- case PrimitiveKind::Int32: {
745
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
746
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
747
- return;
748
- }
749
-
750
- int32_t v = CopyNumber<int32_t>(value);
751
- out_reg->eax = (uint32_t)v;
752
- } break;
753
- case PrimitiveKind::Int16S:
754
- case PrimitiveKind::UInt16S:
755
- case PrimitiveKind::Int32S: {
756
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
757
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
758
- return;
759
- }
760
-
761
- int32_t v = CopyNumber<int32_t>(value);
762
- out_reg->eax = (uint32_t)ReverseBytes(v);
763
- } break;
764
- case PrimitiveKind::UInt32: {
765
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
766
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
767
- return;
768
- }
769
-
770
- uint32_t v = CopyNumber<uint32_t>(value);
771
- out_reg->eax = v;
772
- } break;
773
- case PrimitiveKind::UInt32S: {
774
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
775
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
776
- return;
777
- }
778
-
779
- uint32_t v = CopyNumber<uint32_t>(value);
780
- out_reg->eax = ReverseBytes(v);
781
- } break;
782
- case PrimitiveKind::Int64: {
783
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
784
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
785
- return;
786
- }
787
-
788
- int64_t v = CopyNumber<int64_t>(value);
789
- out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
790
- out_reg->edx = (uint32_t)(v << 32);
791
- } break;
792
- case PrimitiveKind::Int64S: {
793
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
794
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
795
- return;
796
- }
797
-
798
- int64_t v = ReverseBytes(CopyNumber<int64_t>(value));
799
- out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
800
- out_reg->edx = (uint32_t)(v << 32);
801
- } break;
802
- case PrimitiveKind::UInt64: {
803
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
804
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
805
- return;
806
- }
807
-
808
- uint64_t v = CopyNumber<uint64_t>(value);
809
- out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
810
- out_reg->edx = (uint32_t)(v << 32);
811
- } break;
812
- case PrimitiveKind::UInt64S: {
813
- if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
814
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
815
- return;
816
- }
817
-
818
- uint64_t v = ReverseBytes(CopyNumber<uint64_t>(value));
819
- out_reg->eax = (uint32_t)(v & 0xFFFFFFFFul);
820
- out_reg->edx = (uint32_t)(v << 32);
821
- } break;
751
+ case PrimitiveKind::Int8: { RETURN_INTEGER_32(int8_t); } break;
752
+ case PrimitiveKind::UInt8: { RETURN_INTEGER_32(uint8_t); } break;
753
+ case PrimitiveKind::Int16: { RETURN_INTEGER_32(int16_t); } break;
754
+ case PrimitiveKind::Int16S: { RETURN_INTEGER_32_SWAP(int16_t); } break;
755
+ case PrimitiveKind::UInt16: { RETURN_INTEGER_32(uint16_t); } break;
756
+ case PrimitiveKind::UInt16S: { RETURN_INTEGER_32_SWAP(uint16_t); } break;
757
+ case PrimitiveKind::Int32: { RETURN_INTEGER_32(int32_t); } break;
758
+ case PrimitiveKind::Int32S: { RETURN_INTEGER_32_SWAP(int32_t); } break;
759
+ case PrimitiveKind::UInt32: { RETURN_INTEGER_32(uint32_t); } break;
760
+ case PrimitiveKind::UInt32S: { RETURN_INTEGER_32_SWAP(uint32_t); } break;
761
+ case PrimitiveKind::Int64: { RETURN_INTEGER_64(int64_t); } break;
762
+ case PrimitiveKind::Int64S: { RETURN_INTEGER_64_SWAP(int64_t); } break;
763
+ case PrimitiveKind::UInt64: { RETURN_INTEGER_64(uint64_t); } break;
764
+ case PrimitiveKind::UInt64S: { RETURN_INTEGER_64_SWAP(uint64_t); } break;
822
765
  case PrimitiveKind::String: {
823
766
  const char *str;
824
- if (RG_LIKELY(value.IsString())) {
825
- str = PushString(value);
826
- if (RG_UNLIKELY(!str))
827
- return;
828
- } else if (IsNullOrUndefined(value)) {
829
- str = nullptr;
830
- } else {
831
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected string", GetValueType(instance, value));
767
+ if (RG_UNLIKELY(!PushString(value, &str)))
832
768
  return;
833
- }
834
769
 
835
770
  out_reg->eax = (uint32_t)str;
836
771
  } break;
837
772
  case PrimitiveKind::String16: {
838
773
  const char16_t *str16;
839
- if (RG_LIKELY(value.IsString())) {
840
- str16 = PushString16(value);
841
- if (RG_UNLIKELY(!str16))
842
- return;
843
- } else if (IsNullOrUndefined(value)) {
844
- str16 = nullptr;
845
- } else {
846
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected string", GetValueType(instance, value));
774
+ if (RG_UNLIKELY(!PushString16(value, &str16)))
847
775
  return;
848
- }
849
776
 
850
777
  out_reg->eax = (uint32_t)str16;
851
778
  } break;
@@ -864,7 +791,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
864
791
  } else if (IsNullOrUndefined(value)) {
865
792
  ptr = nullptr;
866
793
  } else {
867
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected %2", GetValueType(instance, value), type->name);
794
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
868
795
  return;
869
796
  }
870
797
 
@@ -872,7 +799,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
872
799
  } break;
873
800
  case PrimitiveKind::Record: {
874
801
  if (RG_UNLIKELY(!IsObject(value))) {
875
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected object", GetValueType(instance, value));
802
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected object", GetValueType(instance, value));
876
803
  return;
877
804
  }
878
805
 
@@ -889,7 +816,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
889
816
  case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
890
817
  case PrimitiveKind::Float32: {
891
818
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
892
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
819
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
893
820
  return;
894
821
  }
895
822
 
@@ -898,7 +825,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
898
825
  } break;
899
826
  case PrimitiveKind::Float64: {
900
827
  if (RG_UNLIKELY(!value.IsNumber() && !value.IsBigInt())) {
901
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected number", GetValueType(instance, value));
828
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
902
829
  return;
903
830
  }
904
831
 
@@ -919,7 +846,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
919
846
  } else if (IsNullOrUndefined(value)) {
920
847
  ptr = nullptr;
921
848
  } else {
922
- ThrowError<Napi::TypeError>(env, "Unexpected %1 value for return value, expected %2", GetValueType(instance, value), type->name);
849
+ ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected %2", GetValueType(instance, value), type->name);
923
850
  return;
924
851
  }
925
852
 
@@ -929,6 +856,11 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, BackRegister
929
856
  case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
930
857
  }
931
858
 
859
+ #undef RETURN_INTEGER_64_SWAP
860
+ #undef RETURN_INTEGER_64
861
+ #undef RETURN_INTEGER_32_SWAP
862
+ #undef RETURN_INTEGER_32
863
+
932
864
  err_guard.Disable();
933
865
  }
934
866