koffi 1.0.1 → 1.0.4

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 (50) hide show
  1. package/CMakeLists.txt +12 -11
  2. package/README.md +23 -20
  3. package/build/qemu/1.0.4/koffi_darwin_x64.tar.gz +0 -0
  4. package/build/qemu/1.0.4/koffi_freebsd_arm64.tar.gz +0 -0
  5. package/build/qemu/1.0.4/koffi_freebsd_ia32.tar.gz +0 -0
  6. package/build/qemu/1.0.4/koffi_freebsd_x64.tar.gz +0 -0
  7. package/build/qemu/1.0.4/koffi_linux_arm.tar.gz +0 -0
  8. package/build/qemu/1.0.4/koffi_linux_arm64.tar.gz +0 -0
  9. package/build/qemu/1.0.4/koffi_linux_ia32.tar.gz +0 -0
  10. package/build/qemu/1.0.4/koffi_linux_x64.tar.gz +0 -0
  11. package/build/qemu/1.0.4/koffi_win32_ia32.tar.gz +0 -0
  12. package/build/qemu/1.0.4/koffi_win32_x64.tar.gz +0 -0
  13. package/package.json +8 -4
  14. package/qemu/qemu.js +794 -0
  15. package/qemu/registry/machines.json +415 -0
  16. package/qemu/registry/sha256sum.txt +45 -0
  17. package/src/{call_arm32.cc → abi_arm32.cc} +153 -219
  18. package/src/{call_arm32_fwd.S → abi_arm32_fwd.S} +0 -0
  19. package/src/{call_arm64.cc → abi_arm64.cc} +130 -123
  20. package/src/{call_arm64_fwd.S → abi_arm64_fwd.S} +0 -0
  21. package/src/{call_x64_sysv.cc → abi_x64_sysv.cc} +138 -135
  22. package/src/{call_x64_sysv_fwd.S → abi_x64_sysv_fwd.S} +0 -0
  23. package/src/{call_x64_win.cc → abi_x64_win.cc} +107 -99
  24. package/src/{call_x64_win_fwd.asm → abi_x64_win_fwd.asm} +0 -0
  25. package/src/{call_x86.cc → abi_x86.cc} +110 -107
  26. package/src/{call_x86_fwd.S → abi_x86_fwd.S} +0 -0
  27. package/src/{call_x86_fwd.asm → abi_x86_fwd.asm} +0 -0
  28. package/src/call.cc +353 -0
  29. package/src/call.hh +132 -4
  30. package/src/ffi.cc +16 -2
  31. package/src/ffi.hh +8 -12
  32. package/src/util.cc +7 -280
  33. package/src/util.hh +0 -107
  34. package/test/CMakeLists.txt +1 -0
  35. package/test/misc.c +355 -0
  36. package/test/misc.def +3 -0
  37. package/test/misc.js +227 -0
  38. package/test/raylib.js +165 -0
  39. package/test/sqlite.js +104 -0
  40. package/vendor/libcc/libcc.hh +1 -1
  41. package/build/qemu/1.0.1/koffi_darwin_x64.tar.gz +0 -0
  42. package/build/qemu/1.0.1/koffi_freebsd_arm64.tar.gz +0 -0
  43. package/build/qemu/1.0.1/koffi_freebsd_ia32.tar.gz +0 -0
  44. package/build/qemu/1.0.1/koffi_freebsd_x64.tar.gz +0 -0
  45. package/build/qemu/1.0.1/koffi_linux_arm.tar.gz +0 -0
  46. package/build/qemu/1.0.1/koffi_linux_arm64.tar.gz +0 -0
  47. package/build/qemu/1.0.1/koffi_linux_ia32.tar.gz +0 -0
  48. package/build/qemu/1.0.1/koffi_linux_x64.tar.gz +0 -0
  49. package/build/qemu/1.0.1/koffi_win32_ia32.tar.gz +0 -0
  50. package/build/qemu/1.0.1/koffi_win32_x64.tar.gz +0 -0
package/test/misc.c ADDED
@@ -0,0 +1,355 @@
1
+ // This program is free software: you can redistribute it and/or modify
2
+ // it under the terms of the GNU Affero General Public License as published by
3
+ // the Free Software Foundation, either version 3 of the License, or
4
+ // (at your option) any later version.
5
+ //
6
+ // This program is distributed in the hope that it will be useful,
7
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
8
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9
+ // GNU Affero General Public License for more details.
10
+ //
11
+ // You should have received a copy of the GNU Affero General Public License
12
+ // along with this program. If not, see https://www.gnu.org/licenses/.
13
+
14
+ #include <stdlib.h>
15
+ #include <stdio.h>
16
+ #include <inttypes.h>
17
+ #include <string.h>
18
+ #include <stdarg.h>
19
+ #if __has_include(<uchar.h>)
20
+ #include <uchar.h>
21
+ #else
22
+ typedef uint16_t char16_t;
23
+ typedef uint32_t char32_t;
24
+ #endif
25
+
26
+ #ifdef _WIN32
27
+ #define EXPORT __declspec(dllexport)
28
+ #else
29
+ #define EXPORT __attribute__((visibility("default")))
30
+ #endif
31
+ #if defined(_M_IX86) || defined(__i386__)
32
+ #ifdef _MSC_VER
33
+ #define FASTCALL __fastcall
34
+ #define STDCALL __stdcall
35
+ #else
36
+ #define FASTCALL __attribute__((fastcall))
37
+ #define STDCALL __attribute__((stdcall))
38
+ #endif
39
+ #else
40
+ #define FASTCALL
41
+ #define STDCALL
42
+ #endif
43
+
44
+ typedef struct Pack1 {
45
+ int a;
46
+ } Pack1;
47
+ typedef struct Pack2 {
48
+ int a;
49
+ int b;
50
+ } Pack2;
51
+ typedef struct Pack3 {
52
+ int a;
53
+ int b;
54
+ int c;
55
+ } Pack3;
56
+
57
+ typedef struct Float2 {
58
+ float a;
59
+ float b;
60
+ } Float2;
61
+ typedef struct Float3 {
62
+ float a;
63
+ float b;
64
+ float c;
65
+ } Float3;
66
+
67
+ typedef struct Double2 {
68
+ double a;
69
+ double b;
70
+ } Double2;
71
+ typedef struct Double3 {
72
+ double a;
73
+ double b;
74
+ double c;
75
+ } Double3;
76
+
77
+ typedef struct IJK1 { int8_t i; int8_t j; int8_t k; } IJK1;
78
+ typedef struct IJK4 { int32_t i; int32_t j; int32_t k; } IJK4;
79
+ typedef struct IJK8 { int64_t i; int64_t j; int64_t k; } IJK8;
80
+
81
+ typedef struct BFG {
82
+ int8_t a;
83
+ int64_t b;
84
+ signed char c;
85
+ const char *d;
86
+ short e;
87
+ struct {
88
+ float f;
89
+ double g;
90
+ } inner;
91
+ } BFG;
92
+ #pragma pack(push, 1)
93
+ typedef struct PackedBFG {
94
+ int8_t a;
95
+ int64_t b;
96
+ signed char c;
97
+ const char *d;
98
+ short e;
99
+ struct {
100
+ float f;
101
+ double g;
102
+ } inner;
103
+ } PackedBFG;
104
+ #pragma pack(pop)
105
+
106
+ EXPORT void FillPack1(int a, Pack1 *p)
107
+ {
108
+ p->a = a;
109
+ }
110
+
111
+ EXPORT Pack1 RetPack1(int a)
112
+ {
113
+ Pack1 p;
114
+
115
+ p.a = a;
116
+
117
+ return p;
118
+ }
119
+
120
+ EXPORT void FASTCALL AddPack1(int a, Pack1 *p)
121
+ {
122
+ p->a += a;
123
+ }
124
+
125
+ EXPORT void FillPack2(int a, int b, Pack2 *p)
126
+ {
127
+ p->a = a;
128
+ p->b = b;
129
+ }
130
+
131
+ EXPORT Pack2 RetPack2(int a, int b)
132
+ {
133
+ Pack2 p;
134
+
135
+ p.a = a;
136
+ p.b = b;
137
+
138
+ return p;
139
+ }
140
+
141
+ EXPORT void FASTCALL AddPack2(int a, int b, Pack2 *p)
142
+ {
143
+ p->a += a;
144
+ p->b += b;
145
+ }
146
+
147
+ EXPORT void FillPack3(int a, int b, int c, Pack3 *p)
148
+ {
149
+ p->a = a;
150
+ p->b = b;
151
+ p->c = c;
152
+ }
153
+
154
+ EXPORT Pack3 RetPack3(int a, int b, int c)
155
+ {
156
+ Pack3 p;
157
+
158
+ p.a = a;
159
+ p.b = b;
160
+ p.c = c;
161
+
162
+ return p;
163
+ }
164
+
165
+ EXPORT void FASTCALL AddPack3(int a, int b, int c, Pack3 *p)
166
+ {
167
+ p->a += a;
168
+ p->b += b;
169
+ p->c += c;
170
+ }
171
+
172
+ EXPORT Float2 PackFloat2(float a, float b, Float2 *out)
173
+ {
174
+ Float2 ret;
175
+
176
+ ret.a = a;
177
+ ret.b = b;
178
+ *out = ret;
179
+
180
+ return ret;
181
+ }
182
+
183
+ EXPORT Float3 PackFloat3(float a, float b, float c, Float3 *out)
184
+ {
185
+ Float3 ret;
186
+
187
+ ret.a = a;
188
+ ret.b = b;
189
+ ret.c = c;
190
+ *out = ret;
191
+
192
+ return ret;
193
+ }
194
+
195
+ EXPORT Double2 PackDouble2(double a, double b, Double2 *out)
196
+ {
197
+ Double2 ret;
198
+
199
+ ret.a = a;
200
+ ret.b = b;
201
+ *out = ret;
202
+
203
+ return ret;
204
+ }
205
+
206
+ EXPORT Double3 PackDouble3(double a, double b, double c, Double3 *out)
207
+ {
208
+ Double3 ret;
209
+
210
+ ret.a = a;
211
+ ret.b = b;
212
+ ret.c = c;
213
+ *out = ret;
214
+
215
+ return ret;
216
+ }
217
+
218
+ EXPORT int64_t ConcatenateToInt1(int8_t a, int8_t b, int8_t c, int8_t d, int8_t e, int8_t f,
219
+ int8_t g, int8_t h, int8_t i, int8_t j, int8_t k, int8_t l)
220
+ {
221
+ int64_t ret = 100000000000ull * a + 10000000000ull * b + 1000000000ull * c +
222
+ 100000000ull * d + 10000000ull * e + 1000000ull * f +
223
+ 100000ull * g + 10000ull * h + 1000ull * i +
224
+ 100ull * j + 10ull * k + 1ull * l;
225
+ return ret;
226
+ }
227
+
228
+ EXPORT int64_t ConcatenateToInt4(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f,
229
+ int32_t g, int32_t h, int32_t i, int32_t j, int32_t k, int32_t l)
230
+ {
231
+ int64_t ret = 100000000000ull * a + 10000000000ull * b + 1000000000ull * c +
232
+ 100000000ull * d + 10000000ull * e + 1000000ull * f +
233
+ 100000ull * g + 10000ull * h + 1000ull * i +
234
+ 100ull * j + 10ull * k + 1ull * l;
235
+ return ret;
236
+ }
237
+
238
+ EXPORT int64_t ConcatenateToInt8(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f,
239
+ int64_t g, int64_t h, int64_t i, int64_t j, int64_t k, int64_t l)
240
+ {
241
+ int64_t ret = 100000000000ull * a + 10000000000ull * b + 1000000000ull * c +
242
+ 100000000ull * d + 10000000ull * e + 1000000ull * f +
243
+ 100000ull * g + 10000ull * h + 1000ull * i +
244
+ 100ull * j + 10ull * k + 1ull * l;
245
+ return ret;
246
+ }
247
+
248
+ EXPORT const char *ConcatenateToStr1(int8_t a, int8_t b, int8_t c, int8_t d, int8_t e, int8_t f,
249
+ int8_t g, int8_t h, IJK1 ijk, int8_t l)
250
+ {
251
+ static char buf[128];
252
+ snprintf(buf, sizeof(buf), "%d%d%d%d%d%d%d%d%d%d%d%d", a, b, c, d, e, f, g, h, ijk.i, ijk.j, ijk.k, l);
253
+ return buf;
254
+ }
255
+
256
+ EXPORT const char *ConcatenateToStr4(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f,
257
+ int32_t g, int32_t h, IJK4 *ijk, int32_t l)
258
+ {
259
+ static char buf[128];
260
+ snprintf(buf, sizeof(buf), "%d%d%d%d%d%d%d%d%d%d%d%d", a, b, c, d, e, f, g, h, ijk->i, ijk->j, ijk->k, l);
261
+ return buf;
262
+ }
263
+
264
+ EXPORT const char *ConcatenateToStr8(int64_t a, int64_t b, int64_t c, int64_t d, int64_t e, int64_t f,
265
+ int64_t g, int64_t h, IJK8 ijk, int64_t l)
266
+ {
267
+ static char buf[128];
268
+ snprintf(buf, sizeof(buf), "%" PRIi64 "%" PRIi64 "%" PRIi64 "%" PRIi64 "%" PRIi64 "%" PRIi64
269
+ "%" PRIi64 "%" PRIi64 "%" PRIi64 "%" PRIi64 "%" PRIi64 "%" PRIi64,
270
+ a, b, c, d, e, f, g, h, ijk.i, ijk.j, ijk.k, l);
271
+ return buf;
272
+ }
273
+
274
+ EXPORT BFG STDCALL MakeBFG(BFG *p, int x, double y, const char *str)
275
+ {
276
+ BFG bfg;
277
+
278
+ char buf[64];
279
+ snprintf(buf, sizeof(buf), "X/%s/X", str);
280
+
281
+ bfg.a = x;
282
+ bfg.b = x * 2;
283
+ bfg.c = x - 27;
284
+ bfg.d = buf;
285
+ bfg.e = x * 27;
286
+ bfg.inner.f = (float)y * x;
287
+ bfg.inner.g = (double)y - x;
288
+ *p = bfg;
289
+
290
+ return bfg;
291
+ }
292
+
293
+ EXPORT PackedBFG FASTCALL MakePackedBFG(int x, double y, PackedBFG *p, const char *str)
294
+ {
295
+ PackedBFG bfg;
296
+
297
+ char buf[64];
298
+ snprintf(buf, sizeof(buf), "X/%s/X", str);
299
+
300
+ bfg.a = x;
301
+ bfg.b = x * 2;
302
+ bfg.c = x - 27;
303
+ bfg.d = buf;
304
+ bfg.e = x * 27;
305
+ bfg.inner.f = (float)y * x;
306
+ bfg.inner.g = (double)y - x;
307
+ *p = bfg;
308
+
309
+ return bfg;
310
+ }
311
+
312
+ EXPORT const char *ReturnBigString(const char *str)
313
+ {
314
+ static char buf[16 * 1024 * 1024];
315
+
316
+ size_t len = strlen(str);
317
+ memcpy(buf, str, len + 1);
318
+
319
+ return buf;
320
+ }
321
+
322
+ EXPORT const char *PrintFmt(const char *fmt, ...)
323
+ {
324
+ static char buf[256];
325
+
326
+ va_list ap;
327
+ va_start(ap, fmt);
328
+ vsnprintf(buf, sizeof(buf), fmt, ap);
329
+ va_end(ap);
330
+
331
+ return buf;
332
+ }
333
+
334
+ size_t Length16(const char16_t *str)
335
+ {
336
+ size_t len = 0;
337
+ while (str[len]) {
338
+ len++;
339
+ }
340
+ return len;
341
+ }
342
+
343
+ EXPORT const char16_t *Concat16(const char16_t *str1, const char16_t *str2)
344
+ {
345
+ static char16_t buf[1024];
346
+
347
+ size_t len1 = Length16(str1);
348
+ size_t len2 = Length16(str2);
349
+
350
+ memcpy(buf, str1, len1 * 2);
351
+ memcpy(buf + len1, str2, len2 * 2);
352
+ buf[(len1 + len2) * 2] = 0;
353
+
354
+ return buf;
355
+ }
package/test/misc.def ADDED
@@ -0,0 +1,3 @@
1
+ LIBRARY MISC
2
+ EXPORTS
3
+ ReturnBigString @1
package/test/misc.js ADDED
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env node
2
+
3
+ // This program is free software: you can redistribute it and/or modify
4
+ // it under the terms of the GNU Affero General Public License as published by
5
+ // the Free Software Foundation, either version 3 of the License, or
6
+ // (at your option) any later version.
7
+ //
8
+ // This program is distributed in the hope that it will be useful,
9
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ // GNU Affero General Public License for more details.
12
+ //
13
+ // You should have received a copy of the GNU Affero General Public License
14
+ // along with this program. If not, see https://www.gnu.org/licenses/.
15
+
16
+ const koffi = require('./build/koffi.node');
17
+ const assert = require('assert');
18
+ const path = require('path');
19
+
20
+ const Pack1 = koffi.struct('Pack1', {
21
+ a: 'int'
22
+ });
23
+ const Pack2 = koffi.struct('Pack2', {
24
+ a: 'int',
25
+ b: 'int'
26
+ });
27
+ const Pack3 = koffi.struct('Pack3', {
28
+ a: 'int',
29
+ b: 'int',
30
+ c: 'int'
31
+ });
32
+
33
+ const Float2 = koffi.struct('Float2', {
34
+ a: 'float',
35
+ b: 'float'
36
+ });
37
+ const Float3 = koffi.struct('Float3', {
38
+ a: 'float',
39
+ b: 'float',
40
+ c: 'float'
41
+ });
42
+
43
+ const Double2 = koffi.struct('Double2', {
44
+ a: 'double',
45
+ b: 'double'
46
+ });
47
+ const Double3 = koffi.struct('Double3', {
48
+ a: 'double',
49
+ b: 'double',
50
+ c: 'double'
51
+ });
52
+
53
+ const BFG = koffi.struct('BFG', {
54
+ a: 'int8_t',
55
+ b: 'int64_t',
56
+ c: 'char',
57
+ d: 'string',
58
+ e: 'short',
59
+ inner: koffi.struct({
60
+ f: 'float',
61
+ g: 'double'
62
+ })
63
+ });
64
+ const PackedBFG = koffi.pack('PackedBFG', {
65
+ a: 'int8_t',
66
+ b: 'int64_t',
67
+ c: 'char',
68
+ d: 'string',
69
+ e: 'short',
70
+ inner: koffi.pack({
71
+ f: 'float',
72
+ g: 'double'
73
+ })
74
+ });
75
+
76
+ main();
77
+
78
+ async function main() {
79
+ try {
80
+ await test();
81
+ console.log('Success!');
82
+ } catch (err) {
83
+ console.error(err);
84
+ process.exit(1);
85
+ }
86
+ }
87
+
88
+ async function test() {
89
+ let lib_filename = path.dirname(__filename) + '/build/misc' + koffi.extension;
90
+ let lib = koffi.load(lib_filename);
91
+
92
+ const FillPack1 = lib.func('FillPack1', 'void', ['int', koffi.out(koffi.pointer(Pack1))]);
93
+ const RetPack1 = lib.func('RetPack1', Pack1, ['int']);
94
+ const AddPack1 = lib.fastcall('AddPack1', 'void', ['int', koffi.inout(koffi.pointer(Pack1))]);
95
+ const FillPack2 = lib.func('FillPack2', 'void', ['int', 'int', koffi.out(koffi.pointer(Pack2))]);
96
+ const RetPack2 = lib.func('RetPack2', Pack2, ['int', 'int']);
97
+ const AddPack2 = lib.fastcall('AddPack2', 'void', ['int', 'int', koffi.inout(koffi.pointer(Pack2))]);
98
+ const FillPack3 = lib.func('FillPack3', 'void', ['int', 'int', 'int', koffi.out(koffi.pointer(Pack3))]);
99
+ const RetPack3 = lib.func('RetPack3', Pack3, ['int', 'int', 'int']);
100
+ const AddPack3 = lib.fastcall('AddPack3', 'void', ['int', 'int', 'int', koffi.inout(koffi.pointer(Pack3))]);
101
+ const PackFloat2 = lib.func('Float2 PackFloat2(float a, float b, _Out_ Float2 *out)');
102
+ const PackFloat3 = lib.func('Float3 PackFloat3(float a, float b, float c, _Out_ Float3 *out)');
103
+ const PackDouble2 = lib.func('Double2 PackDouble2(double a, double b, _Out_ Double2 *out)');
104
+ const PackDouble3 = lib.func('Double3 PackDouble3(double a, double b, double c, _Out_ Double3 *out)');
105
+ const ConcatenateToInt1 = lib.func('ConcatenateToInt1', 'int64_t', Array(12).fill('int8_t'));
106
+ const ConcatenateToInt4 = lib.func('ConcatenateToInt4', 'int64_t', Array(12).fill('int32_t'));
107
+ const ConcatenateToInt8 = lib.func('ConcatenateToInt8', 'int64_t', Array(12).fill('int64_t'));
108
+ const ConcatenateToStr1 = lib.func('ConcatenateToStr1', 'string', [...Array(8).fill('int8_t'), koffi.struct('IJK1', {i: 'int8_t', j: 'int8_t', k: 'int8_t'}), 'int8_t']);
109
+ const ConcatenateToStr4 = lib.func('ConcatenateToStr4', 'string', [...Array(8).fill('int32_t'), koffi.pointer(koffi.struct('IJK4', {i: 'int32_t', j: 'int32_t', k: 'int32_t'})), 'int32_t']);
110
+ const ConcatenateToStr8 = lib.func('ConcatenateToStr8', 'string', [...Array(8).fill('int64_t'), koffi.struct('IJK8', {i: 'int64_t', j: 'int64_t', k: 'int64_t'}), 'int64_t']);
111
+ const MakeBFG = lib.func('BFG __stdcall MakeBFG(_Out_ BFG *p, int x, double y, const char *str)');
112
+ const MakePackedBFG = lib.func('PackedBFG __fastcall MakePackedBFG(int x, double y, _Out_ PackedBFG *p, const char *str)');
113
+ const ReturnBigString = process.platform == 'win32' ?
114
+ lib.stdcall(1, 'string', ['string']) :
115
+ lib.func('const char * __stdcall ReturnBigString(const char *str)');
116
+ const PrintFmt = lib.func('const char *PrintFmt(const char *fmt, ...)');
117
+ const Concat16 = lib.func('const char16_t *Concat16(const char16_t *str1, const char16_t *str2)')
118
+
119
+ // Simple tests with Pack1
120
+ {
121
+ let p = {};
122
+
123
+ FillPack1(777, p);
124
+ assert.deepEqual(p, { a: 777 });
125
+
126
+ let q = RetPack1(6);
127
+ assert.deepEqual(q, { a: 6 });
128
+
129
+ AddPack1(6, p);
130
+ assert.deepEqual(p, { a: 783 });
131
+ }
132
+
133
+ // Simple tests with Pack2
134
+ {
135
+ let p = {};
136
+
137
+ FillPack2(123, 456, p);
138
+ assert.deepEqual(p, { a: 123, b: 456 });
139
+
140
+ let q = RetPack2(6, 9);
141
+ assert.deepEqual(q, { a: 6, b: 9 });
142
+
143
+ AddPack2(6, 9, p);
144
+ assert.deepEqual(p, { a: 129, b: 465 });
145
+ }
146
+
147
+ // Simple tests with Pack3
148
+ {
149
+ let p = {};
150
+
151
+ FillPack3(1, 2, 3, p);
152
+ assert.deepEqual(p, { a: 1, b: 2, c: 3 });
153
+
154
+ let q = RetPack3(6, 9, -12);
155
+ assert.deepEqual(q, { a: 6, b: 9, c: -12 });
156
+
157
+ AddPack3(6, 9, -12, p);
158
+ assert.deepEqual(p, { a: 7, b: 11, c: -9 });
159
+ }
160
+
161
+ // HFA tests
162
+ {
163
+ let f2p = {};
164
+ let f2 = PackFloat2(1.5, 3.0, f2p);
165
+ assert.deepEqual(f2, { a: 1.5, b: 3.0 });
166
+ assert.deepEqual(f2, f2p);
167
+
168
+ let f3p = {};
169
+ let f3 = PackFloat3(20.0, 30.0, 40.0, f3p);
170
+ assert.deepEqual(f3, { a: 20.0, b: 30.0, c: 40.0 });
171
+ assert.deepEqual(f3, f3p);
172
+
173
+ let d2p = {};
174
+ let d2 = PackDouble2(1.0, 2.0, d2p);
175
+ assert.deepEqual(d2, { a: 1.0, b: 2.0 });
176
+ assert.deepEqual(d2, d2p);
177
+
178
+ let d3p = {};
179
+ let d3 = PackDouble3(0.5, 10.0, 5.0, d3p);
180
+ assert.deepEqual(d3, { a: 0.5, b: 10.0, c: 5.0 });
181
+ assert.deepEqual(d3, d3p);
182
+ }
183
+
184
+ // Many parameters
185
+ {
186
+ assert.equal(ConcatenateToInt1(5, 6, 1, 2, 3, 9, 4, 4, 0, 6, 8, 7), 561239440687n);
187
+ assert.equal(ConcatenateToInt4(5, 6, 1, 2, 3, 9, 4, 4, 0, 6, 8, 7), 561239440687n);
188
+ assert.equal(ConcatenateToInt8(5, 6, 1, 2, 3, 9, 4, 4, 0, 6, 8, 7), 561239440687n);
189
+ assert.equal(ConcatenateToStr1(5, 6, 1, 2, 3, 9, 4, 4, {i: 0, j: 6, k: 8}, 7), '561239440687');
190
+ assert.equal(ConcatenateToStr4(5, 6, 1, 2, 3, 9, 4, 4, {i: 0, j: 6, k: 8}, 7), '561239440687');
191
+ assert.equal(ConcatenateToStr8(5, 6, 1, 2, 3, 9, 4, 4, {i: 0, j: 6, k: 8}, 7), '561239440687');
192
+ }
193
+
194
+ // Big struct
195
+ {
196
+ let out = {};
197
+ let bfg = MakeBFG(out, 2, 7, '__Hello123456789++++foobarFOOBAR!__');
198
+ assert.deepEqual(bfg, { a: 2, b: 4, c: -25, d: 'X/__Hello123456789++++foobarFOOBAR!__/X', e: 54, inner: { f: 14, g: 5 } });
199
+ assert.deepEqual(out, bfg);
200
+ }
201
+
202
+ // Packed struct
203
+ {
204
+ let out = {};
205
+ let bfg = MakePackedBFG(2, 7, out, '__Hello123456789++++foobarFOOBAR!__');
206
+ assert.deepEqual(bfg, { a: 2, b: 4, c: -25, d: 'X/__Hello123456789++++foobarFOOBAR!__/X', e: 54, inner: { f: 14, g: 5 } });
207
+ assert.deepEqual(out, bfg);
208
+ }
209
+
210
+ // Big string
211
+ {
212
+ let str = 'fooBAR!'.repeat(1024 * 1024);
213
+ assert.equal(ReturnBigString(str), str);
214
+ }
215
+
216
+ // Variadic
217
+ {
218
+ let str = PrintFmt('foo %d %g %s', 'int', 200, 'double', 1.5, 'string', 'BAR');
219
+ assert.equal(str, 'foo 200 1.5 BAR');
220
+ }
221
+
222
+ // UTF-16LE strings
223
+ {
224
+ let str = Concat16('Hello ', 'World!');
225
+ assert.equal(str, 'Hello World!');
226
+ }
227
+ }