@mirascript/wasm 0.1.64 → 0.1.70
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 +11 -11
- package/lib/wasm.d.ts +9 -9
- package/lib/wasm.js +41 -98
- package/lib/wasm_bg.wasm +0 -0
- package/lib/wasm_bg.wasm.d.ts +9 -9
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
# @mirascript/wasm
|
|
2
2
|
|
|
3
|
-
`@mirascript/wasm` 提供 MiraScript 编译器的 WebAssembly 封装,适用于浏览器、Web Worker
|
|
3
|
+
`@mirascript/wasm` 提供 MiraScript 编译器的 WebAssembly 封装,适用于浏览器、Web Worker 和其他不便使用原生模块的环境。
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## 能力概览
|
|
6
6
|
|
|
7
|
-
- 初始化 WebAssembly
|
|
8
|
-
-
|
|
9
|
-
-
|
|
7
|
+
- 初始化 WebAssembly 编译模块
|
|
8
|
+
- 提供同步编译接口
|
|
9
|
+
- 返回编译产物与诊断信息
|
|
10
10
|
|
|
11
11
|
## 安装
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
pnpm add @mirascript/wasm
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
##
|
|
17
|
+
## 快速开始
|
|
18
18
|
|
|
19
19
|
```ts
|
|
20
20
|
import { init, compileSync } from '@mirascript/wasm';
|
|
@@ -29,6 +29,10 @@ console.log(result.diagnostics);
|
|
|
29
29
|
console.log(result.chunk);
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
## 使用建议
|
|
33
|
+
|
|
34
|
+
如果项目需要同时兼容 Node.js 与浏览器,优先使用 `@mirascript/bindings` 统一加载入口。
|
|
35
|
+
|
|
32
36
|
## 构建
|
|
33
37
|
|
|
34
38
|
```bash
|
|
@@ -36,8 +40,4 @@ pnpm --filter @mirascript/wasm build:dev
|
|
|
36
40
|
pnpm --filter @mirascript/wasm build
|
|
37
41
|
```
|
|
38
42
|
|
|
39
|
-
构建依赖 `wasm-pack
|
|
40
|
-
|
|
41
|
-
## 说明
|
|
42
|
-
|
|
43
|
-
如果你的代码既要在 Node.js 运行,也要在浏览器运行,优先使用 `@mirascript/bindings`,由它自动选择原生或 WebAssembly 实现。
|
|
43
|
+
构建依赖 Rust 工具链与 `wasm-pack`。
|
package/lib/wasm.d.ts
CHANGED
|
@@ -80,12 +80,12 @@ export interface InitOutput {
|
|
|
80
80
|
readonly __wbg_compileresult_free: (a: number, b: number) => void;
|
|
81
81
|
readonly __wbg_monacocompiler_free: (a: number, b: number) => void;
|
|
82
82
|
readonly compile: (a: number, b: number, c: number) => number;
|
|
83
|
-
readonly compileresult_chunk: (a: number
|
|
84
|
-
readonly compileresult_diagnostics: (a: number
|
|
83
|
+
readonly compileresult_chunk: (a: number) => [number, number];
|
|
84
|
+
readonly compileresult_diagnostics: (a: number) => [number, number];
|
|
85
85
|
readonly main: () => void;
|
|
86
|
-
readonly monacocompiler_diagnostics: (a: number
|
|
87
|
-
readonly monacocompiler_emit: (a: number
|
|
88
|
-
readonly monacocompiler_format: (a: number
|
|
86
|
+
readonly monacocompiler_diagnostics: (a: number) => [number, number];
|
|
87
|
+
readonly monacocompiler_emit: (a: number) => [number, number];
|
|
88
|
+
readonly monacocompiler_format: (a: number) => [number, number];
|
|
89
89
|
readonly monacocompiler_new: (a: number, b: number, c: number) => number;
|
|
90
90
|
readonly monacocompiler_parse: (a: number) => number;
|
|
91
91
|
readonly compile_buffer: (a: number, b: number, c: number) => number;
|
|
@@ -111,10 +111,10 @@ export interface InitOutput {
|
|
|
111
111
|
readonly __wbg_set_config_input_mode: (a: number, b: number) => void;
|
|
112
112
|
readonly __wbg_set_config_trivia: (a: number, b: number) => void;
|
|
113
113
|
readonly config_new: () => number;
|
|
114
|
-
readonly
|
|
115
|
-
readonly
|
|
116
|
-
readonly
|
|
117
|
-
readonly
|
|
114
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
115
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
116
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
117
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
118
118
|
readonly __wbindgen_start: () => void;
|
|
119
119
|
}
|
|
120
120
|
|
package/lib/wasm.js
CHANGED
|
@@ -21,36 +21,22 @@ export class CompileResult {
|
|
|
21
21
|
* @returns {Uint8Array | undefined}
|
|
22
22
|
*/
|
|
23
23
|
chunk() {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
let v1;
|
|
30
|
-
if (r0 !== 0) {
|
|
31
|
-
v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
32
|
-
wasm.__wbindgen_export(r0, r1 * 1, 1);
|
|
33
|
-
}
|
|
34
|
-
return v1;
|
|
35
|
-
} finally {
|
|
36
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
24
|
+
const ret = wasm.compileresult_chunk(this.__wbg_ptr);
|
|
25
|
+
let v1;
|
|
26
|
+
if (ret[0] !== 0) {
|
|
27
|
+
v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
28
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
37
29
|
}
|
|
30
|
+
return v1;
|
|
38
31
|
}
|
|
39
32
|
/**
|
|
40
33
|
* @returns {Uint32Array}
|
|
41
34
|
*/
|
|
42
35
|
diagnostics() {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
48
|
-
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
|
49
|
-
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
|
50
|
-
return v1;
|
|
51
|
-
} finally {
|
|
52
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
53
|
-
}
|
|
36
|
+
const ret = wasm.compileresult_diagnostics(this.__wbg_ptr);
|
|
37
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
38
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
39
|
+
return v1;
|
|
54
40
|
}
|
|
55
41
|
}
|
|
56
42
|
if (Symbol.dispose) CompileResult.prototype[Symbol.dispose] = CompileResult.prototype.free;
|
|
@@ -254,62 +240,41 @@ export class MonacoCompiler {
|
|
|
254
240
|
* @returns {Uint32Array}
|
|
255
241
|
*/
|
|
256
242
|
diagnostics() {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
262
|
-
var v1 = getArrayU32FromWasm0(r0, r1).slice();
|
|
263
|
-
wasm.__wbindgen_export(r0, r1 * 4, 4);
|
|
264
|
-
return v1;
|
|
265
|
-
} finally {
|
|
266
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
267
|
-
}
|
|
243
|
+
const ret = wasm.monacocompiler_diagnostics(this.__wbg_ptr);
|
|
244
|
+
var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
|
|
245
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
|
|
246
|
+
return v1;
|
|
268
247
|
}
|
|
269
248
|
/**
|
|
270
249
|
* @returns {Uint8Array | undefined}
|
|
271
250
|
*/
|
|
272
251
|
emit() {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
let v1;
|
|
279
|
-
if (r0 !== 0) {
|
|
280
|
-
v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
281
|
-
wasm.__wbindgen_export(r0, r1 * 1, 1);
|
|
282
|
-
}
|
|
283
|
-
return v1;
|
|
284
|
-
} finally {
|
|
285
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
252
|
+
const ret = wasm.monacocompiler_emit(this.__wbg_ptr);
|
|
253
|
+
let v1;
|
|
254
|
+
if (ret[0] !== 0) {
|
|
255
|
+
v1 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
256
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
286
257
|
}
|
|
258
|
+
return v1;
|
|
287
259
|
}
|
|
288
260
|
/**
|
|
289
261
|
* @returns {string | undefined}
|
|
290
262
|
*/
|
|
291
263
|
format() {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
let v1;
|
|
298
|
-
if (r0 !== 0) {
|
|
299
|
-
v1 = getStringFromWasm0(r0, r1).slice();
|
|
300
|
-
wasm.__wbindgen_export(r0, r1 * 1, 1);
|
|
301
|
-
}
|
|
302
|
-
return v1;
|
|
303
|
-
} finally {
|
|
304
|
-
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
264
|
+
const ret = wasm.monacocompiler_format(this.__wbg_ptr);
|
|
265
|
+
let v1;
|
|
266
|
+
if (ret[0] !== 0) {
|
|
267
|
+
v1 = getStringFromWasm0(ret[0], ret[1]).slice();
|
|
268
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
305
269
|
}
|
|
270
|
+
return v1;
|
|
306
271
|
}
|
|
307
272
|
/**
|
|
308
273
|
* @param {string} input
|
|
309
274
|
* @param {Config} config
|
|
310
275
|
*/
|
|
311
276
|
constructor(input, config) {
|
|
312
|
-
const ptr0 = passStringToWasm0(input, wasm.
|
|
277
|
+
const ptr0 = passStringToWasm0(input, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
313
278
|
const len0 = WASM_VECTOR_LEN;
|
|
314
279
|
_assertClass(config, Config);
|
|
315
280
|
const ret = wasm.monacocompiler_new(ptr0, len0, config.__wbg_ptr);
|
|
@@ -333,7 +298,7 @@ if (Symbol.dispose) MonacoCompiler.prototype[Symbol.dispose] = MonacoCompiler.pr
|
|
|
333
298
|
* @returns {CompileResult}
|
|
334
299
|
*/
|
|
335
300
|
export function compile(script, config) {
|
|
336
|
-
const ptr0 = passStringToWasm0(script, wasm.
|
|
301
|
+
const ptr0 = passStringToWasm0(script, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
337
302
|
const len0 = WASM_VECTOR_LEN;
|
|
338
303
|
_assertClass(config, Config);
|
|
339
304
|
const ret = wasm.compile(ptr0, len0, config.__wbg_ptr);
|
|
@@ -346,7 +311,7 @@ export function compile(script, config) {
|
|
|
346
311
|
* @returns {CompileResult}
|
|
347
312
|
*/
|
|
348
313
|
export function compile_buffer(script, config) {
|
|
349
|
-
const ptr0 = passArray8ToWasm0(script, wasm.
|
|
314
|
+
const ptr0 = passArray8ToWasm0(script, wasm.__wbindgen_malloc);
|
|
350
315
|
const len0 = WASM_VECTOR_LEN;
|
|
351
316
|
_assertClass(config, Config);
|
|
352
317
|
const ret = wasm.compile_buffer(ptr0, len0, config.__wbg_ptr);
|
|
@@ -370,22 +335,28 @@ function __wbg_get_imports() {
|
|
|
370
335
|
deferred0_1 = arg1;
|
|
371
336
|
console.error(getStringFromWasm0(arg0, arg1));
|
|
372
337
|
} finally {
|
|
373
|
-
wasm.
|
|
338
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
374
339
|
}
|
|
375
340
|
},
|
|
376
341
|
__wbg_new_227d7c05414eb861: function() {
|
|
377
342
|
const ret = new Error();
|
|
378
|
-
return
|
|
343
|
+
return ret;
|
|
379
344
|
},
|
|
380
345
|
__wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
|
|
381
|
-
const ret =
|
|
382
|
-
const ptr1 = passStringToWasm0(ret, wasm.
|
|
346
|
+
const ret = arg1.stack;
|
|
347
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
383
348
|
const len1 = WASM_VECTOR_LEN;
|
|
384
349
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
385
350
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
386
351
|
},
|
|
387
|
-
|
|
388
|
-
|
|
352
|
+
__wbindgen_init_externref_table: function() {
|
|
353
|
+
const table = wasm.__wbindgen_externrefs;
|
|
354
|
+
const offset = table.grow(4);
|
|
355
|
+
table.set(0, undefined);
|
|
356
|
+
table.set(offset + 0, undefined);
|
|
357
|
+
table.set(offset + 1, null);
|
|
358
|
+
table.set(offset + 2, true);
|
|
359
|
+
table.set(offset + 3, false);
|
|
389
360
|
},
|
|
390
361
|
};
|
|
391
362
|
return {
|
|
@@ -404,27 +375,12 @@ const MonacoCompilerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
404
375
|
? { register: () => {}, unregister: () => {} }
|
|
405
376
|
: new FinalizationRegistry(ptr => wasm.__wbg_monacocompiler_free(ptr, 1));
|
|
406
377
|
|
|
407
|
-
function addHeapObject(obj) {
|
|
408
|
-
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
409
|
-
const idx = heap_next;
|
|
410
|
-
heap_next = heap[idx];
|
|
411
|
-
|
|
412
|
-
heap[idx] = obj;
|
|
413
|
-
return idx;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
378
|
function _assertClass(instance, klass) {
|
|
417
379
|
if (!(instance instanceof klass)) {
|
|
418
380
|
throw new Error(`expected instance of ${klass.name}`);
|
|
419
381
|
}
|
|
420
382
|
}
|
|
421
383
|
|
|
422
|
-
function dropObject(idx) {
|
|
423
|
-
if (idx < 1028) return;
|
|
424
|
-
heap[idx] = heap_next;
|
|
425
|
-
heap_next = idx;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
384
|
function getArrayU32FromWasm0(ptr, len) {
|
|
429
385
|
ptr = ptr >>> 0;
|
|
430
386
|
return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
|
|
@@ -463,13 +419,6 @@ function getUint8ArrayMemory0() {
|
|
|
463
419
|
return cachedUint8ArrayMemory0;
|
|
464
420
|
}
|
|
465
421
|
|
|
466
|
-
function getObject(idx) { return heap[idx]; }
|
|
467
|
-
|
|
468
|
-
let heap = new Array(1024).fill(undefined);
|
|
469
|
-
heap.push(undefined, null, true, false);
|
|
470
|
-
|
|
471
|
-
let heap_next = heap.length;
|
|
472
|
-
|
|
473
422
|
function passArray8ToWasm0(arg, malloc) {
|
|
474
423
|
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
475
424
|
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
@@ -514,12 +463,6 @@ function passStringToWasm0(arg, malloc, realloc) {
|
|
|
514
463
|
return ptr;
|
|
515
464
|
}
|
|
516
465
|
|
|
517
|
-
function takeObject(idx) {
|
|
518
|
-
const ret = getObject(idx);
|
|
519
|
-
dropObject(idx);
|
|
520
|
-
return ret;
|
|
521
|
-
}
|
|
522
|
-
|
|
523
466
|
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
524
467
|
cachedTextDecoder.decode();
|
|
525
468
|
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
package/lib/wasm_bg.wasm
CHANGED
|
Binary file
|
package/lib/wasm_bg.wasm.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ export const memory: WebAssembly.Memory;
|
|
|
4
4
|
export const __wbg_compileresult_free: (a: number, b: number) => void;
|
|
5
5
|
export const __wbg_monacocompiler_free: (a: number, b: number) => void;
|
|
6
6
|
export const compile: (a: number, b: number, c: number) => number;
|
|
7
|
-
export const compileresult_chunk: (a: number
|
|
8
|
-
export const compileresult_diagnostics: (a: number
|
|
7
|
+
export const compileresult_chunk: (a: number) => [number, number];
|
|
8
|
+
export const compileresult_diagnostics: (a: number) => [number, number];
|
|
9
9
|
export const main: () => void;
|
|
10
|
-
export const monacocompiler_diagnostics: (a: number
|
|
11
|
-
export const monacocompiler_emit: (a: number
|
|
12
|
-
export const monacocompiler_format: (a: number
|
|
10
|
+
export const monacocompiler_diagnostics: (a: number) => [number, number];
|
|
11
|
+
export const monacocompiler_emit: (a: number) => [number, number];
|
|
12
|
+
export const monacocompiler_format: (a: number) => [number, number];
|
|
13
13
|
export const monacocompiler_new: (a: number, b: number, c: number) => number;
|
|
14
14
|
export const monacocompiler_parse: (a: number) => number;
|
|
15
15
|
export const compile_buffer: (a: number, b: number, c: number) => number;
|
|
@@ -35,8 +35,8 @@ export const __wbg_set_config_diagnostic_warning: (a: number, b: number) => void
|
|
|
35
35
|
export const __wbg_set_config_input_mode: (a: number, b: number) => void;
|
|
36
36
|
export const __wbg_set_config_trivia: (a: number, b: number) => void;
|
|
37
37
|
export const config_new: () => number;
|
|
38
|
-
export const
|
|
39
|
-
export const
|
|
40
|
-
export const
|
|
41
|
-
export const
|
|
38
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
39
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
40
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
41
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
42
42
|
export const __wbindgen_start: () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/wasm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.70",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "MiraScript compiler for WebAssembly",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@types/node": "^26.
|
|
33
|
+
"@types/node": "^26.1.1",
|
|
34
34
|
"nodemon": "^3.1.14",
|
|
35
|
-
"@mirascript/constants": "~0.1.
|
|
35
|
+
"@mirascript/constants": "~0.1.70"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"wasm": "wasm-pack build --target web --out-dir ../../packages/wasm/lib --no-pack ../../crates/wasm",
|