koffi 2.14.0 → 2.14.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 (51) hide show
  1. package/CHANGELOG.md +7 -1
  2. package/README.md +1 -1
  3. package/build/koffi/darwin_arm64/koffi.node +0 -0
  4. package/build/koffi/darwin_x64/koffi.node +0 -0
  5. package/build/koffi/freebsd_arm64/koffi.node +0 -0
  6. package/build/koffi/freebsd_ia32/koffi.node +0 -0
  7. package/build/koffi/freebsd_x64/koffi.node +0 -0
  8. package/build/koffi/linux_arm64/koffi.node +0 -0
  9. package/build/koffi/linux_armhf/koffi.node +0 -0
  10. package/build/koffi/linux_ia32/koffi.node +0 -0
  11. package/build/koffi/linux_loong64/koffi.node +0 -0
  12. package/build/koffi/linux_riscv64d/koffi.node +0 -0
  13. package/build/koffi/linux_x64/koffi.node +0 -0
  14. package/build/koffi/musl_arm64/koffi.node +0 -0
  15. package/build/koffi/musl_x64/koffi.node +0 -0
  16. package/build/koffi/openbsd_ia32/koffi.node +0 -0
  17. package/build/koffi/openbsd_x64/koffi.node +0 -0
  18. package/build/koffi/win32_arm64/koffi.node +0 -0
  19. package/build/koffi/win32_ia32/koffi.node +0 -0
  20. package/build/koffi/win32_x64/koffi.node +0 -0
  21. package/doc/pages/index.md +43 -4
  22. package/doc/pages/platforms.md +8 -19
  23. package/doc/pages.ini +0 -7
  24. package/doc/static/perf_windows.png +0 -0
  25. package/index.js +3 -2
  26. package/indirect.js +3 -2
  27. package/package.json +3 -2
  28. package/src/cnoke/src/builder.js +1 -2
  29. package/src/core/base/base.cc +791 -555
  30. package/src/core/base/base.hh +577 -450
  31. package/src/core/base/crc.inc +1 -1
  32. package/src/core/base/crc_gen.py +1 -1
  33. package/src/core/base/unicode.inc +1 -1
  34. package/src/core/base/unicode_gen.py +1 -1
  35. package/src/koffi/src/abi_arm32.cc +24 -24
  36. package/src/koffi/src/abi_arm64.cc +29 -29
  37. package/src/koffi/src/abi_riscv64.cc +27 -27
  38. package/src/koffi/src/abi_x64_sysv.cc +29 -29
  39. package/src/koffi/src/abi_x64_win.cc +20 -20
  40. package/src/koffi/src/abi_x86.cc +26 -26
  41. package/src/koffi/src/call.cc +82 -236
  42. package/src/koffi/src/call.hh +6 -6
  43. package/src/koffi/src/ffi.cc +60 -60
  44. package/src/koffi/src/ffi.hh +9 -9
  45. package/src/koffi/src/parser.cc +2 -2
  46. package/src/koffi/src/parser.hh +1 -1
  47. package/src/koffi/src/trampolines/prototypes.inc +1 -1
  48. package/src/koffi/src/util.cc +43 -43
  49. package/src/koffi/src/util.hh +5 -5
  50. package/src/koffi/src/win32.cc +5 -5
  51. package/src/koffi/src/win32.hh +1 -1
@@ -21,7 +21,7 @@
21
21
 
22
22
  // This file is autogenerated by crc_gen.py
23
23
 
24
- namespace RG {
24
+ namespace K {
25
25
 
26
26
  static const uint32_t Crc32Table[256] = {
27
27
  0x00000000u, 0x77073096u, 0xEE0E612Cu, 0x990951BAu, 0x076DC419u, 0x706AF48Fu,
@@ -97,7 +97,7 @@ if __name__ == "__main__":
97
97
 
98
98
  // This file is autogenerated by crc_gen.py
99
99
 
100
- namespace RG {{
100
+ namespace K {{
101
101
 
102
102
  ''')
103
103
 
@@ -22,7 +22,7 @@
22
22
  // This file is autogenerated by unicode_gen.py
23
23
  // Version: DerivedCoreProperties-16.0.0.txt -- Date: 2024-05-31, 18:09:32 GMT
24
24
 
25
- namespace RG {
25
+ namespace K {
26
26
 
27
27
  static const int32_t WcWidthNull[] = {
28
28
  0x000AD, 0x000AE, 0x00300, 0x00370, 0x00483, 0x0048A, 0x00591, 0x005BE, 0x005BF, 0x005C0,
@@ -135,7 +135,7 @@ def write_header(version, wcwidth, xid, f):
135
135
  // This file is autogenerated by unicode_gen.py
136
136
  // Version: {version}
137
137
 
138
- namespace RG {{
138
+ namespace K {{
139
139
 
140
140
  static const int32_t WcWidthNull[] = {{""")
141
141
  for i, v in enumerate(wcwidth.null):
@@ -30,7 +30,7 @@
30
30
  #include <signal.h>
31
31
  #include <setjmp.h>
32
32
 
33
- namespace RG {
33
+ namespace K {
34
34
 
35
35
  struct HfaRet {
36
36
  double d0;
@@ -110,7 +110,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
110
110
 
111
111
  for (ParameterInfo &param: func->parameters) {
112
112
  switch (param.type->primitive) {
113
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
113
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
114
114
 
115
115
  case PrimitiveKind::Bool:
116
116
  case PrimitiveKind::Int8:
@@ -176,7 +176,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
176
176
  }
177
177
  }
178
178
  } break;
179
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
179
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
180
180
  case PrimitiveKind::Float32:
181
181
  case PrimitiveKind::Float64: {
182
182
  #if defined(__ARM_PCS_VFP)
@@ -206,7 +206,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
206
206
  }
207
207
  } break;
208
208
 
209
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
209
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
210
210
  }
211
211
 
212
212
  func->args_size += AlignLen(param.type->size, 16);
@@ -300,12 +300,12 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
300
300
  // Push arguments
301
301
  for (Size i = 0; i < func->parameters.len; i++) {
302
302
  const ParameterInfo &param = func->parameters[i];
303
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
303
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
304
304
 
305
305
  Napi::Value value = info[param.offset];
306
306
 
307
307
  switch (param.type->primitive) {
308
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
308
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
309
309
 
310
310
  case PrimitiveKind::Bool: {
311
311
  if (!value.IsBoolean()) [[unlikely]] {
@@ -372,7 +372,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
372
372
  return false;
373
373
  vec_ptr += param.vec_count;
374
374
  } else if (param.gpr_count) {
375
- RG_ASSERT(param.type->align <= 8);
375
+ K_ASSERT(param.type->align <= 8);
376
376
 
377
377
  int16_t align = (param.type->align <= 4) ? 4 : 8;
378
378
  gpr_ptr = AlignUp(gpr_ptr, align);
@@ -391,7 +391,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
391
391
  args_ptr += (param.type->size + 3) / 4;
392
392
  }
393
393
  } break;
394
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
394
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
395
395
  case PrimitiveKind::Float32: {
396
396
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
397
397
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -437,7 +437,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
437
437
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
438
438
  } break;
439
439
 
440
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
440
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
441
441
  }
442
442
  }
443
443
 
@@ -487,16 +487,16 @@ void CallData::Execute(const FunctionInfo *func, void *native)
487
487
  case PrimitiveKind::Union: {
488
488
  if (func->ret.vec_count) {
489
489
  HfaRet ret = PERFORM_CALL(DDDD);
490
- memcpy(&result.buf, &ret, RG_SIZE(ret));
490
+ memcpy(&result.buf, &ret, K_SIZE(ret));
491
491
  } else {
492
492
  result.u64 = PERFORM_CALL(GG);
493
493
  }
494
494
  } break;
495
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
495
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
496
496
  case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
497
497
  case PrimitiveKind::Float64: { result.d = PERFORM_CALL(DDDD).d0; } break;
498
498
 
499
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
499
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
500
500
  }
501
501
 
502
502
  #undef PERFORM_CALL
@@ -504,7 +504,7 @@ void CallData::Execute(const FunctionInfo *func, void *native)
504
504
 
505
505
  Napi::Value CallData::Complete(const FunctionInfo *func)
506
506
  {
507
- RG_DEFER {
507
+ K_DEFER {
508
508
  PopOutArguments();
509
509
 
510
510
  if (func->ret.type->dispose) {
@@ -551,14 +551,14 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
551
551
  Napi::Object obj = DecodeObject(env, ptr, func->ret.type);
552
552
  return obj;
553
553
  } break;
554
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
554
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
555
555
  case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
556
556
  case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
557
557
 
558
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
558
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
559
559
  }
560
560
 
561
- RG_UNREACHABLE();
561
+ K_UNREACHABLE();
562
562
  }
563
563
 
564
564
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_stack, BackRegisters *out_reg)
@@ -578,7 +578,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
578
578
  uint8_t *return_ptr = proto->ret.use_memory ? (uint8_t *)gpr_ptr[0] : nullptr;
579
579
  gpr_ptr += proto->ret.use_memory;
580
580
 
581
- RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
581
+ K_DEFER_N(err_guard) { memset(out_reg, 0, K_SIZE(*out_reg)); };
582
582
 
583
583
  if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
584
584
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
@@ -592,10 +592,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
592
592
  // Convert to JS arguments
593
593
  for (Size i = 0; i < proto->parameters.len; i++) {
594
594
  const ParameterInfo &param = proto->parameters[i];
595
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
595
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
596
596
 
597
597
  switch (param.type->primitive) {
598
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
598
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
599
599
 
600
600
  case PrimitiveKind::Bool: {
601
601
  bool b = *(bool *)((param.gpr_count ? gpr_ptr : args_ptr)++);
@@ -754,7 +754,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
754
754
 
755
755
  vec_ptr += param.vec_count;
756
756
  } else if (param.gpr_count) {
757
- RG_ASSERT(param.type->align <= 8);
757
+ K_ASSERT(param.type->align <= 8);
758
758
 
759
759
  int16_t gpr_size = param.gpr_count * 4;
760
760
  int16_t align = (param.type->align <= 4) ? 4 : 8;
@@ -789,7 +789,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
789
789
  args_ptr += (param.type->size + 3) / 4;
790
790
  }
791
791
  } break;
792
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
792
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
793
793
  case PrimitiveKind::Float32: {
794
794
  float f;
795
795
  if (param.vec_count) [[likely]] {
@@ -822,7 +822,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
822
822
  arguments.Append(arg);
823
823
  } break;
824
824
 
825
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
825
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
826
826
  }
827
827
  }
828
828
 
@@ -974,7 +974,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
974
974
  PushObject(obj, type, (uint8_t *)&out_reg->r0);
975
975
  }
976
976
  } break;
977
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
977
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
978
978
  case PrimitiveKind::Float32: {
979
979
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
980
980
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -1022,7 +1022,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1022
1022
  out_reg->r0 = (uint32_t)ptr;
1023
1023
  } break;
1024
1024
 
1025
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1025
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
1026
1026
  }
1027
1027
 
1028
1028
  #undef RETURN_INTEGER_64_SWAP
@@ -31,7 +31,7 @@
31
31
 
32
32
  #include <napi.h>
33
33
 
34
- namespace RG {
34
+ namespace K {
35
35
 
36
36
  struct HfaInfo {
37
37
  int count;
@@ -143,7 +143,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
143
143
 
144
144
  for (ParameterInfo &param: func->parameters) {
145
145
  switch (param.type->primitive) {
146
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
146
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
147
147
 
148
148
  case PrimitiveKind::Bool:
149
149
  case PrimitiveKind::Int8:
@@ -233,7 +233,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
233
233
  param.use_memory = true;
234
234
  }
235
235
  } break;
236
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
236
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
237
237
  case PrimitiveKind::Float32:
238
238
  case PrimitiveKind::Float64: {
239
239
  #if defined(_WIN32)
@@ -255,7 +255,7 @@ bool AnalyseFunction(Napi::Env, InstanceData *, FunctionInfo *func)
255
255
  }
256
256
  } break;
257
257
 
258
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
258
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
259
259
  }
260
260
  }
261
261
 
@@ -356,12 +356,12 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
356
356
  // Push arguments
357
357
  for (Size i = 0; i < func->parameters.len; i++) {
358
358
  const ParameterInfo &param = func->parameters[i];
359
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
359
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
360
360
 
361
361
  Napi::Value value = info[param.offset];
362
362
 
363
363
  switch (param.type->primitive) {
364
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
364
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
365
365
 
366
366
  case PrimitiveKind::Bool: {
367
367
  if (!value.IsBoolean()) [[unlikely]] {
@@ -455,7 +455,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
455
455
  vec_ptr += param.vec_count;
456
456
  } else if (!param.use_memory) {
457
457
  if (param.gpr_count) {
458
- RG_ASSERT(param.type->align <= 8);
458
+ K_ASSERT(param.type->align <= 8);
459
459
 
460
460
  if (!PushObject(obj, param.type, (uint8_t *)gpr_ptr))
461
461
  return false;
@@ -472,8 +472,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
472
472
  uint8_t *ptr = AllocHeap(param.type->size, 16);
473
473
 
474
474
  if (param.gpr_count) {
475
- RG_ASSERT(param.gpr_count == 1);
476
- RG_ASSERT(param.vec_count == 0);
475
+ K_ASSERT(param.gpr_count == 1);
476
+ K_ASSERT(param.vec_count == 0);
477
477
 
478
478
  *(uint8_t **)(gpr_ptr++) = ptr;
479
479
  } else {
@@ -487,7 +487,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
487
487
  return false;
488
488
  }
489
489
  } break;
490
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
490
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
491
491
  case PrimitiveKind::Float32: {
492
492
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
493
493
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -547,7 +547,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
547
547
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
548
548
  } break;
549
549
 
550
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
550
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
551
551
  }
552
552
  }
553
553
 
@@ -565,7 +565,7 @@ void CallData::Execute(const FunctionInfo *func, void *native)
565
565
  TEB *teb = GetTEB();
566
566
 
567
567
  // Restore previous stack limits at the end
568
- RG_DEFER_C(exception_list = teb->ExceptionList,
568
+ K_DEFER_C(exception_list = teb->ExceptionList,
569
569
  base = teb->StackBase,
570
570
  limit = teb->StackLimit,
571
571
  dealloc = teb->DeallocationStack,
@@ -623,19 +623,19 @@ void CallData::Execute(const FunctionInfo *func, void *native)
623
623
  case PrimitiveKind::Union: {
624
624
  if (func->ret.gpr_count) {
625
625
  X0X1Ret ret = PERFORM_CALL(GG);
626
- memcpy(&result.buf, &ret, RG_SIZE(ret));
626
+ memcpy(&result.buf, &ret, K_SIZE(ret));
627
627
  } else if (func->ret.vec_count) {
628
628
  HfaRet ret = PERFORM_CALL(DDDD);
629
- memcpy(&result.buf, &ret, RG_SIZE(ret));
629
+ memcpy(&result.buf, &ret, K_SIZE(ret));
630
630
  } else {
631
631
  PERFORM_CALL(GG);
632
632
  }
633
633
  } break;
634
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
634
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
635
635
  case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
636
636
  case PrimitiveKind::Float64: { result.d = PERFORM_CALL(DDDD).d0; } break;
637
637
 
638
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
638
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
639
639
  }
640
640
 
641
641
  #undef PERFORM_CALL
@@ -643,7 +643,7 @@ void CallData::Execute(const FunctionInfo *func, void *native)
643
643
 
644
644
  Napi::Value CallData::Complete(const FunctionInfo *func)
645
645
  {
646
- RG_DEFER {
646
+ K_DEFER {
647
647
  PopOutArguments();
648
648
 
649
649
  if (func->ret.type->dispose) {
@@ -699,14 +699,14 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
699
699
  return obj;
700
700
  }
701
701
  } break;
702
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
702
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
703
703
  case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
704
704
  case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
705
705
 
706
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
706
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
707
707
  }
708
708
 
709
- RG_UNREACHABLE();
709
+ K_UNREACHABLE();
710
710
  }
711
711
 
712
712
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_stack, BackRegisters *out_reg)
@@ -718,7 +718,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
718
718
  TEB *teb = GetTEB();
719
719
 
720
720
  // Restore previous stack limits at the end
721
- RG_DEFER_C(base = teb->StackBase,
721
+ K_DEFER_C(base = teb->StackBase,
722
722
  limit = teb->StackLimit,
723
723
  dealloc = teb->DeallocationStack) {
724
724
  teb->StackBase = base;
@@ -743,7 +743,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
743
743
 
744
744
  uint8_t *return_ptr = proto->ret.use_memory ? (uint8_t *)gpr_ptr[8] : nullptr;
745
745
 
746
- RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
746
+ K_DEFER_N(err_guard) { memset(out_reg, 0, K_SIZE(*out_reg)); };
747
747
 
748
748
  if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
749
749
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
@@ -757,10 +757,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
757
757
  // Convert to JS arguments
758
758
  for (Size i = 0; i < proto->parameters.len; i++) {
759
759
  const ParameterInfo &param = proto->parameters[i];
760
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
760
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
761
761
 
762
762
  switch (param.type->primitive) {
763
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
763
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
764
764
 
765
765
  case PrimitiveKind::Bool: {
766
766
  #if defined(__APPLE__)
@@ -1078,7 +1078,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1078
1078
  vec_ptr += param.vec_count;
1079
1079
  } else if (!param.use_memory) {
1080
1080
  if (param.gpr_count) {
1081
- RG_ASSERT(param.type->align <= 8);
1081
+ K_ASSERT(param.type->align <= 8);
1082
1082
 
1083
1083
  Napi::Object obj = DecodeObject(env, (uint8_t *)gpr_ptr, param.type);
1084
1084
  arguments.Append(obj);
@@ -1103,7 +1103,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1103
1103
  arguments.Append(obj);
1104
1104
  }
1105
1105
  } break;
1106
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
1106
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
1107
1107
  case PrimitiveKind::Float32: {
1108
1108
  float f;
1109
1109
  if (param.vec_count) [[likely]] {
@@ -1145,7 +1145,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1145
1145
  arguments.Append(arg);
1146
1146
  } break;
1147
1147
 
1148
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1148
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
1149
1149
  }
1150
1150
  }
1151
1151
 
@@ -1276,7 +1276,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1276
1276
  PushObject(obj, type, (uint8_t *)&out_reg->x0);
1277
1277
  }
1278
1278
  } break;
1279
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
1279
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
1280
1280
  case PrimitiveKind::Float32: {
1281
1281
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
1282
1282
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -1318,7 +1318,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
1318
1318
  out_reg->x0 = (uint64_t)ptr;
1319
1319
  } break;
1320
1320
 
1321
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
1321
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
1322
1322
  }
1323
1323
 
1324
1324
  #undef RETURN_INTEGER_SWAP
@@ -28,7 +28,7 @@
28
28
 
29
29
  #include <napi.h>
30
30
 
31
- namespace RG {
31
+ namespace K {
32
32
 
33
33
  struct A0A1Ret {
34
34
  uint64_t a0;
@@ -208,12 +208,12 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
208
208
  // Push arguments
209
209
  for (Size i = 0; i < func->parameters.len; i++) {
210
210
  const ParameterInfo &param = func->parameters[i];
211
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
211
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
212
212
 
213
213
  Napi::Value value = info[param.offset];
214
214
 
215
215
  switch (param.type->primitive) {
216
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
216
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
217
217
 
218
218
  case PrimitiveKind::Bool: {
219
219
  if (!value.IsBoolean()) [[unlikely]] {
@@ -276,7 +276,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
276
276
  Napi::Object obj = value.As<Napi::Object>();
277
277
 
278
278
  if (!param.use_memory) {
279
- RG_ASSERT(param.type->size <= 16);
279
+ K_ASSERT(param.type->size <= 16);
280
280
 
281
281
  uint64_t regs[2] = { 0xFFFFFFFFFFFFFFFFull, 0xFFFFFFFFFFFFFFFFull };
282
282
  {
@@ -303,7 +303,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
303
303
  *(gpr_ptr++) = regs[1];
304
304
  }
305
305
  } else {
306
- RG_ASSERT(param.type->align <= 8);
306
+ K_ASSERT(param.type->align <= 8);
307
307
 
308
308
  MemCpy(args_ptr, regs, param.type->size);
309
309
  args_ptr += (param.type->size + 7) / 8;
@@ -312,8 +312,8 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
312
312
  uint8_t *ptr = AllocHeap(param.type->size, 16);
313
313
 
314
314
  if (param.gpr_count) {
315
- RG_ASSERT(param.gpr_count == 1);
316
- RG_ASSERT(param.vec_count == 0);
315
+ K_ASSERT(param.gpr_count == 1);
316
+ K_ASSERT(param.vec_count == 0);
317
317
 
318
318
  *(uint8_t **)(gpr_ptr++) = ptr;
319
319
  } else {
@@ -324,7 +324,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
324
324
  return false;
325
325
  }
326
326
  } break;
327
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
327
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
328
328
  case PrimitiveKind::Float32: {
329
329
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
330
330
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -368,7 +368,7 @@ bool CallData::Prepare(const FunctionInfo *func, const Napi::CallbackInfo &info)
368
368
  *(void **)((param.gpr_count ? gpr_ptr : args_ptr)++) = ptr;
369
369
  } break;
370
370
 
371
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
371
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
372
372
  }
373
373
  }
374
374
 
@@ -416,23 +416,23 @@ void CallData::Execute(const FunctionInfo *func, void *native)
416
416
  case PrimitiveKind::Union: {
417
417
  if (func->ret.gpr_first && !func->ret.vec_count) {
418
418
  A0A1Ret ret = PERFORM_CALL(GG);
419
- memcpy(&result.buf, &ret, RG_SIZE(ret));
419
+ memcpy(&result.buf, &ret, K_SIZE(ret));
420
420
  } else if (func->ret.gpr_first) {
421
421
  A0Fa0Ret ret = PERFORM_CALL(GD);
422
- memcpy(&result.buf, &ret, RG_SIZE(ret));
422
+ memcpy(&result.buf, &ret, K_SIZE(ret));
423
423
  } else if (func->ret.vec_count == 2) {
424
424
  Fa0Fa1Ret ret = PERFORM_CALL(DD);
425
- memcpy(&result.buf, &ret, RG_SIZE(ret));
425
+ memcpy(&result.buf, &ret, K_SIZE(ret));
426
426
  } else {
427
427
  Fa0A0Ret ret = PERFORM_CALL(DG);
428
- memcpy(&result.buf, &ret, RG_SIZE(ret));
428
+ memcpy(&result.buf, &ret, K_SIZE(ret));
429
429
  }
430
430
  } break;
431
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
431
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
432
432
  case PrimitiveKind::Float32: { result.f = PERFORM_CALL(F); } break;
433
433
  case PrimitiveKind::Float64: { result.d = PERFORM_CALL(DD).fa0; } break;
434
434
 
435
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
435
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
436
436
  }
437
437
 
438
438
  #undef PERFORM_CALL
@@ -440,7 +440,7 @@ void CallData::Execute(const FunctionInfo *func, void *native)
440
440
 
441
441
  Napi::Value CallData::Complete(const FunctionInfo *func)
442
442
  {
443
- RG_DEFER {
443
+ K_DEFER {
444
444
  PopOutArguments();
445
445
 
446
446
  if (func->ret.type->dispose) {
@@ -492,14 +492,14 @@ Napi::Value CallData::Complete(const FunctionInfo *func)
492
492
  return obj;
493
493
  }
494
494
  } break;
495
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
495
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
496
496
  case PrimitiveKind::Float32: return Napi::Number::New(env, (double)result.f);
497
497
  case PrimitiveKind::Float64: return Napi::Number::New(env, result.d);
498
498
 
499
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
499
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
500
500
  }
501
501
 
502
- RG_UNREACHABLE();
502
+ K_UNREACHABLE();
503
503
  }
504
504
 
505
505
  void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_stack, BackRegisters *out_reg)
@@ -519,7 +519,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
519
519
  uint8_t *return_ptr = proto->ret.use_memory ? (uint8_t *)gpr_ptr[0] : nullptr;
520
520
  gpr_ptr += proto->ret.use_memory;
521
521
 
522
- RG_DEFER_N(err_guard) { memset(out_reg, 0, RG_SIZE(*out_reg)); };
522
+ K_DEFER_N(err_guard) { memset(out_reg, 0, K_SIZE(*out_reg)); };
523
523
 
524
524
  if (trampoline.generation >= 0 && trampoline.generation != (int32_t)mem->generation) [[unlikely]] {
525
525
  ThrowError<Napi::Error>(env, "Cannot use non-registered callback beyond FFI call");
@@ -533,10 +533,10 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
533
533
  // Convert to JS arguments
534
534
  for (Size i = 0; i < proto->parameters.len; i++) {
535
535
  const ParameterInfo &param = proto->parameters[i];
536
- RG_ASSERT(param.directions >= 1 && param.directions <= 3);
536
+ K_ASSERT(param.directions >= 1 && param.directions <= 3);
537
537
 
538
538
  switch (param.type->primitive) {
539
- case PrimitiveKind::Void: { RG_UNREACHABLE(); } break;
539
+ case PrimitiveKind::Void: { K_UNREACHABLE(); } break;
540
540
 
541
541
  case PrimitiveKind::Bool: {
542
542
  bool b = *(bool *)((param.gpr_count ? gpr_ptr : args_ptr)++);
@@ -688,7 +688,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
688
688
  regs[0] = *(vec_ptr++);
689
689
  regs[1] = *((param.gpr_count ? gpr_ptr : vec_ptr)++);
690
690
  } else {
691
- RG_ASSERT(param.type->align <= 8);
691
+ K_ASSERT(param.type->align <= 8);
692
692
 
693
693
  MemCpy(regs, args_ptr, param.type->size);
694
694
  args_ptr += (param.type->size + 7) / 8;
@@ -706,7 +706,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
706
706
  arguments.Append(obj);
707
707
  }
708
708
  } break;
709
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
709
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
710
710
  case PrimitiveKind::Float32: {
711
711
  float f;
712
712
  if (param.vec_count) [[likely]] {
@@ -734,7 +734,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
734
734
  arguments.Append(arg);
735
735
  } break;
736
736
 
737
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
737
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
738
738
  }
739
739
  }
740
740
 
@@ -880,7 +880,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
880
880
  }
881
881
  }
882
882
  } break;
883
- case PrimitiveKind::Array: { RG_UNREACHABLE(); } break;
883
+ case PrimitiveKind::Array: { K_UNREACHABLE(); } break;
884
884
  case PrimitiveKind::Float32: {
885
885
  if (!value.IsNumber() && !value.IsBigInt()) [[unlikely]] {
886
886
  ThrowError<Napi::TypeError>(env, "Unexpected %1 value, expected number", GetValueType(instance, value));
@@ -921,7 +921,7 @@ void CallData::Relay(Size idx, uint8_t *own_sp, uint8_t *caller_sp, bool switch_
921
921
  out_reg->a0 = (uint64_t)ptr;
922
922
  } break;
923
923
 
924
- case PrimitiveKind::Prototype: { RG_UNREACHABLE(); } break;
924
+ case PrimitiveKind::Prototype: { K_UNREACHABLE(); } break;
925
925
  }
926
926
 
927
927
  #undef RETURN_INTEGER_SWAP