libchai 0.1.2 → 0.1.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.
- package/README.md +9 -1
- package/{libchai.d.ts → chai.d.ts} +9 -3
- package/{libchai.js → chai.js} +69 -33
- package/chai_bg.wasm +0 -0
- package/package.json +6 -6
- package/libchai_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,15 @@
|
|
|
4
4
|
|
|
5
5
|
## 使用
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
压缩包解压后,根目录中有几个不同的二进制文件:
|
|
8
|
+
|
|
9
|
+
- `chai` 是 macOS 系统上的可执行文件,它是一个通用二进制文件,意味着 x86_64 架构和 arm64 架构的 Mac 电脑都能使用;
|
|
10
|
+
- `chai.exe` 是 Windows 系统上的可执行文件(基于 MinGW);
|
|
11
|
+
- `chai-musl` 和 `chai-gnu` 是 Linux 系统上的可执行文件,分别基于 musl libc 和 glibc
|
|
12
|
+
- 使用 musl libc 的二进制通常兼容性较好
|
|
13
|
+
- 使用 glibc 的二进制要依赖于运行环境中的 glibc,但是通常运行效率较高
|
|
14
|
+
|
|
15
|
+
请根据您的运行环境选用适当的二进制文件。
|
|
8
16
|
|
|
9
17
|
### 输入格式解释及示例
|
|
10
18
|
|
|
@@ -2,9 +2,14 @@
|
|
|
2
2
|
/* eslint-disable */
|
|
3
3
|
/**
|
|
4
4
|
* @param {any} js_input
|
|
5
|
-
* @returns {
|
|
5
|
+
* @returns {any}
|
|
6
6
|
*/
|
|
7
|
-
export function
|
|
7
|
+
export function encode(js_input: any): any;
|
|
8
|
+
/**
|
|
9
|
+
* @param {any} js_input
|
|
10
|
+
* @returns {any}
|
|
11
|
+
*/
|
|
12
|
+
export function evaluate(js_input: any): any;
|
|
8
13
|
/**
|
|
9
14
|
* @param {any} js_input
|
|
10
15
|
* @param {Function} post_message
|
|
@@ -21,8 +26,9 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
|
|
|
21
26
|
export interface InitOutput {
|
|
22
27
|
readonly memory: WebAssembly.Memory;
|
|
23
28
|
readonly __wbg_webinterface_free: (a: number) => void;
|
|
29
|
+
readonly encode: (a: number, b: number) => void;
|
|
24
30
|
readonly evaluate: (a: number, b: number) => void;
|
|
25
|
-
readonly optimize: (a: number, b: number) => void;
|
|
31
|
+
readonly optimize: (a: number, b: number, c: number) => void;
|
|
26
32
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
27
33
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
28
34
|
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
package/{libchai.js → chai.js}
RENAMED
|
@@ -29,6 +29,24 @@ function takeObject(idx) {
|
|
|
29
29
|
return ret;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
33
|
+
|
|
34
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
35
|
+
|
|
36
|
+
let cachedUint8Memory0 = null;
|
|
37
|
+
|
|
38
|
+
function getUint8Memory0() {
|
|
39
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
40
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
41
|
+
}
|
|
42
|
+
return cachedUint8Memory0;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function getStringFromWasm0(ptr, len) {
|
|
46
|
+
ptr = ptr >>> 0;
|
|
47
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
48
|
+
}
|
|
49
|
+
|
|
32
50
|
function isLikeNone(x) {
|
|
33
51
|
return x === undefined || x === null;
|
|
34
52
|
}
|
|
@@ -53,15 +71,6 @@ function getInt32Memory0() {
|
|
|
53
71
|
|
|
54
72
|
let WASM_VECTOR_LEN = 0;
|
|
55
73
|
|
|
56
|
-
let cachedUint8Memory0 = null;
|
|
57
|
-
|
|
58
|
-
function getUint8Memory0() {
|
|
59
|
-
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
60
|
-
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
61
|
-
}
|
|
62
|
-
return cachedUint8Memory0;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
74
|
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
66
75
|
|
|
67
76
|
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
@@ -115,15 +124,6 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
115
124
|
return ptr;
|
|
116
125
|
}
|
|
117
126
|
|
|
118
|
-
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
119
|
-
|
|
120
|
-
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
121
|
-
|
|
122
|
-
function getStringFromWasm0(ptr, len) {
|
|
123
|
-
ptr = ptr >>> 0;
|
|
124
|
-
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
127
|
let cachedBigInt64Memory0 = null;
|
|
128
128
|
|
|
129
129
|
function getBigInt64Memory0() {
|
|
@@ -199,22 +199,41 @@ function debugString(val) {
|
|
|
199
199
|
}
|
|
200
200
|
/**
|
|
201
201
|
* @param {any} js_input
|
|
202
|
-
* @returns {
|
|
202
|
+
* @returns {any}
|
|
203
|
+
*/
|
|
204
|
+
export function encode(js_input) {
|
|
205
|
+
try {
|
|
206
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
207
|
+
wasm.encode(retptr, addHeapObject(js_input));
|
|
208
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
209
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
210
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
211
|
+
if (r2) {
|
|
212
|
+
throw takeObject(r1);
|
|
213
|
+
}
|
|
214
|
+
return takeObject(r0);
|
|
215
|
+
} finally {
|
|
216
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @param {any} js_input
|
|
222
|
+
* @returns {any}
|
|
203
223
|
*/
|
|
204
224
|
export function evaluate(js_input) {
|
|
205
|
-
let deferred1_0;
|
|
206
|
-
let deferred1_1;
|
|
207
225
|
try {
|
|
208
226
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
209
227
|
wasm.evaluate(retptr, addHeapObject(js_input));
|
|
210
228
|
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
211
229
|
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
230
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
231
|
+
if (r2) {
|
|
232
|
+
throw takeObject(r1);
|
|
233
|
+
}
|
|
234
|
+
return takeObject(r0);
|
|
215
235
|
} finally {
|
|
216
236
|
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
217
|
-
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
218
237
|
}
|
|
219
238
|
}
|
|
220
239
|
|
|
@@ -223,7 +242,17 @@ export function evaluate(js_input) {
|
|
|
223
242
|
* @param {Function} post_message
|
|
224
243
|
*/
|
|
225
244
|
export function optimize(js_input, post_message) {
|
|
226
|
-
|
|
245
|
+
try {
|
|
246
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
247
|
+
wasm.optimize(retptr, addHeapObject(js_input), addHeapObject(post_message));
|
|
248
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
249
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
250
|
+
if (r1) {
|
|
251
|
+
throw takeObject(r0);
|
|
252
|
+
}
|
|
253
|
+
} finally {
|
|
254
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
255
|
+
}
|
|
227
256
|
}
|
|
228
257
|
|
|
229
258
|
function handleError(f, args) {
|
|
@@ -308,6 +337,10 @@ function __wbg_get_imports() {
|
|
|
308
337
|
const ret = BigInt.asUintN(64, arg0);
|
|
309
338
|
return addHeapObject(ret);
|
|
310
339
|
};
|
|
340
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
341
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
342
|
+
return addHeapObject(ret);
|
|
343
|
+
};
|
|
311
344
|
imports.wbg.__wbindgen_number_get = function(arg0, arg1) {
|
|
312
345
|
const obj = getObject(arg1);
|
|
313
346
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
@@ -339,10 +372,6 @@ function __wbg_get_imports() {
|
|
|
339
372
|
const ret = getObject(arg0) === undefined;
|
|
340
373
|
return ret;
|
|
341
374
|
};
|
|
342
|
-
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
343
|
-
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
344
|
-
return addHeapObject(ret);
|
|
345
|
-
};
|
|
346
375
|
imports.wbg.__wbg_new_abda76e883ba8a5f = function() {
|
|
347
376
|
const ret = new Error();
|
|
348
377
|
return addHeapObject(ret);
|
|
@@ -392,11 +421,11 @@ function __wbg_get_imports() {
|
|
|
392
421
|
imports.wbg.__wbg_set_9182712abebf82ef = function(arg0, arg1, arg2) {
|
|
393
422
|
getObject(arg0)[takeObject(arg1)] = takeObject(arg2);
|
|
394
423
|
};
|
|
395
|
-
imports.wbg.
|
|
424
|
+
imports.wbg.__wbg_performance_eeefc685c9bc38b4 = function(arg0) {
|
|
396
425
|
const ret = getObject(arg0).performance;
|
|
397
426
|
return addHeapObject(ret);
|
|
398
427
|
};
|
|
399
|
-
imports.wbg.
|
|
428
|
+
imports.wbg.__wbg_now_e0d8ec93dd25766a = function(arg0) {
|
|
400
429
|
const ret = getObject(arg0).now();
|
|
401
430
|
return ret;
|
|
402
431
|
};
|
|
@@ -442,6 +471,10 @@ function __wbg_get_imports() {
|
|
|
442
471
|
const ret = getObject(arg0).length;
|
|
443
472
|
return ret;
|
|
444
473
|
};
|
|
474
|
+
imports.wbg.__wbg_new_ffc6d4d085022169 = function() {
|
|
475
|
+
const ret = new Array();
|
|
476
|
+
return addHeapObject(ret);
|
|
477
|
+
};
|
|
445
478
|
imports.wbg.__wbg_newnoargs_c62ea9419c21fbac = function(arg0, arg1) {
|
|
446
479
|
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
447
480
|
return addHeapObject(ret);
|
|
@@ -502,6 +535,9 @@ function __wbg_get_imports() {
|
|
|
502
535
|
const ret = global.global;
|
|
503
536
|
return addHeapObject(ret);
|
|
504
537
|
}, arguments) };
|
|
538
|
+
imports.wbg.__wbg_set_f2740edb12e318cd = function(arg0, arg1, arg2) {
|
|
539
|
+
getObject(arg0)[arg1 >>> 0] = takeObject(arg2);
|
|
540
|
+
};
|
|
505
541
|
imports.wbg.__wbg_isArray_74fb723e24f76012 = function(arg0) {
|
|
506
542
|
const ret = Array.isArray(getObject(arg0));
|
|
507
543
|
return ret;
|
|
@@ -625,7 +661,7 @@ async function __wbg_init(input) {
|
|
|
625
661
|
if (wasm !== undefined) return wasm;
|
|
626
662
|
|
|
627
663
|
if (typeof input === 'undefined') {
|
|
628
|
-
input = new URL('
|
|
664
|
+
input = new URL('chai_bg.wasm', import.meta.url);
|
|
629
665
|
}
|
|
630
666
|
const imports = __wbg_get_imports();
|
|
631
667
|
|
package/chai_bg.wasm
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
"collaborators": [
|
|
4
4
|
"Songchen Tan <i@tansongchen.com>"
|
|
5
5
|
],
|
|
6
|
-
"version": "0.1.
|
|
6
|
+
"version": "0.1.4",
|
|
7
7
|
"files": [
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
8
|
+
"chai_bg.wasm",
|
|
9
|
+
"chai.js",
|
|
10
|
+
"chai.d.ts"
|
|
11
11
|
],
|
|
12
|
-
"module": "
|
|
13
|
-
"types": "
|
|
12
|
+
"module": "chai.js",
|
|
13
|
+
"types": "chai.d.ts",
|
|
14
14
|
"sideEffects": [
|
|
15
15
|
"./snippets/*"
|
|
16
16
|
]
|
package/libchai_bg.wasm
DELETED
|
Binary file
|