@mirascript/wasm 0.1.62-alpha.9 → 0.1.63
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 +43 -0
- package/lib/wasm.js +9 -10
- package/lib/wasm_bg.wasm +0 -0
- package/package.json +16 -3
package/README.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# @mirascript/wasm
|
|
2
|
+
|
|
3
|
+
`@mirascript/wasm` 提供 MiraScript 编译器的 WebAssembly 封装,适用于浏览器、Web Worker 以及不方便加载原生 Node 模块的环境。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 初始化 WebAssembly 编译器模块
|
|
8
|
+
- 创建底层编译配置对象
|
|
9
|
+
- 提供同步编译接口,输出字节码和诊断信息
|
|
10
|
+
|
|
11
|
+
## 安装
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add @mirascript/wasm
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 基本用法
|
|
18
|
+
|
|
19
|
+
```ts
|
|
20
|
+
import { init, compileSync } from '@mirascript/wasm';
|
|
21
|
+
|
|
22
|
+
await init();
|
|
23
|
+
|
|
24
|
+
const result = compileSync('1 + 2', {
|
|
25
|
+
input_mode: 'Script',
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
console.log(result.diagnostics);
|
|
29
|
+
console.log(result.chunk);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 构建
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pnpm --filter @mirascript/wasm build:dev
|
|
36
|
+
pnpm --filter @mirascript/wasm build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
构建依赖 `wasm-pack` 与 Rust 工具链。
|
|
40
|
+
|
|
41
|
+
## 说明
|
|
42
|
+
|
|
43
|
+
如果你的代码既要在 Node.js 运行,也要在浏览器运行,优先使用 `@mirascript/bindings`,由它自动选择原生或 WebAssembly 实现。
|
package/lib/wasm.js
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
export class CompileResult {
|
|
4
4
|
static __wrap(ptr) {
|
|
5
|
-
ptr = ptr >>> 0;
|
|
6
5
|
const obj = Object.create(CompileResult.prototype);
|
|
7
6
|
obj.__wbg_ptr = ptr;
|
|
8
7
|
CompileResultFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
@@ -69,7 +68,7 @@ export class Config {
|
|
|
69
68
|
}
|
|
70
69
|
constructor() {
|
|
71
70
|
const ret = wasm.config_new();
|
|
72
|
-
this.__wbg_ptr = ret
|
|
71
|
+
this.__wbg_ptr = ret;
|
|
73
72
|
ConfigFinalization.register(this, this.__wbg_ptr, this);
|
|
74
73
|
return this;
|
|
75
74
|
}
|
|
@@ -314,7 +313,7 @@ export class MonacoCompiler {
|
|
|
314
313
|
const len0 = WASM_VECTOR_LEN;
|
|
315
314
|
_assertClass(config, Config);
|
|
316
315
|
const ret = wasm.monacocompiler_new(ptr0, len0, config.__wbg_ptr);
|
|
317
|
-
this.__wbg_ptr = ret
|
|
316
|
+
this.__wbg_ptr = ret;
|
|
318
317
|
MonacoCompilerFinalization.register(this, this.__wbg_ptr, this);
|
|
319
318
|
return this;
|
|
320
319
|
}
|
|
@@ -360,7 +359,7 @@ export function main() {
|
|
|
360
359
|
function __wbg_get_imports() {
|
|
361
360
|
const import0 = {
|
|
362
361
|
__proto__: null,
|
|
363
|
-
|
|
362
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
364
363
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
365
364
|
},
|
|
366
365
|
__wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
|
|
@@ -397,13 +396,13 @@ function __wbg_get_imports() {
|
|
|
397
396
|
|
|
398
397
|
const CompileResultFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
399
398
|
? { register: () => {}, unregister: () => {} }
|
|
400
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_compileresult_free(ptr
|
|
399
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_compileresult_free(ptr, 1));
|
|
401
400
|
const ConfigFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
402
401
|
? { register: () => {}, unregister: () => {} }
|
|
403
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_config_free(ptr
|
|
402
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_config_free(ptr, 1));
|
|
404
403
|
const MonacoCompilerFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
405
404
|
? { register: () => {}, unregister: () => {} }
|
|
406
|
-
: new FinalizationRegistry(ptr => wasm.__wbg_monacocompiler_free(ptr
|
|
405
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_monacocompiler_free(ptr, 1));
|
|
407
406
|
|
|
408
407
|
function addHeapObject(obj) {
|
|
409
408
|
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
@@ -445,8 +444,7 @@ function getDataViewMemory0() {
|
|
|
445
444
|
}
|
|
446
445
|
|
|
447
446
|
function getStringFromWasm0(ptr, len) {
|
|
448
|
-
|
|
449
|
-
return decodeText(ptr, len);
|
|
447
|
+
return decodeText(ptr >>> 0, len);
|
|
450
448
|
}
|
|
451
449
|
|
|
452
450
|
let cachedUint32ArrayMemory0 = null;
|
|
@@ -551,8 +549,9 @@ if (!('encodeInto' in cachedTextEncoder)) {
|
|
|
551
549
|
|
|
552
550
|
let WASM_VECTOR_LEN = 0;
|
|
553
551
|
|
|
554
|
-
let wasmModule, wasm;
|
|
552
|
+
let wasmModule, wasmInstance, wasm;
|
|
555
553
|
function __wbg_finalize_init(instance, module) {
|
|
554
|
+
wasmInstance = instance;
|
|
556
555
|
wasm = instance.exports;
|
|
557
556
|
wasmModule = module;
|
|
558
557
|
cachedDataViewMemory0 = null;
|
package/lib/wasm_bg.wasm
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/wasm",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.63",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "MiraScript compiler for WebAssembly",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"mirascript",
|
|
9
|
+
"wasm",
|
|
10
|
+
"webassembly",
|
|
11
|
+
"compiler",
|
|
12
|
+
"browser"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://mira.cloudpss.net",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/CloudPSS/MiraScript.git",
|
|
18
|
+
"directory": "packages/wasm"
|
|
19
|
+
},
|
|
7
20
|
"type": "module",
|
|
8
21
|
"main": "dist/index.js",
|
|
9
22
|
"types": "dist/index.d.ts",
|
|
@@ -17,9 +30,9 @@
|
|
|
17
30
|
}
|
|
18
31
|
},
|
|
19
32
|
"devDependencies": {
|
|
20
|
-
"@types/node": "^
|
|
33
|
+
"@types/node": "^26.0.1",
|
|
21
34
|
"nodemon": "^3.1.14",
|
|
22
|
-
"@mirascript/constants": "~0.1.
|
|
35
|
+
"@mirascript/constants": "~0.1.63"
|
|
23
36
|
},
|
|
24
37
|
"scripts": {
|
|
25
38
|
"wasm": "wasm-pack build --target web --out-dir ../../packages/wasm/lib --no-pack ../../crates/wasm",
|