@mirascript/mirascript 0.1.41 → 0.1.43
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/dist/{chunk-43TX2QFV.js → chunk-DNM6YMFU.js} +165 -99
- package/dist/chunk-DNM6YMFU.js.map +6 -0
- package/dist/index.js +1 -1
- package/dist/subtle.js +1 -1
- package/dist/vm/lib/global/debug.d.ts +47 -9
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/json.d.ts.map +1 -1
- package/dist/vm/lib/helpers.d.ts +1 -1
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/lib/loader.d.ts.map +1 -1
- package/dist/vm/operations/helpers.d.ts.map +1 -1
- package/dist/vm/types/context.d.ts.map +1 -1
- package/dist/vm/types/function.d.ts +11 -7
- package/dist/vm/types/function.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/vm/lib/global/debug.ts +145 -51
- package/src/vm/lib/global/json.ts +0 -2
- package/src/vm/lib/helpers.ts +1 -2
- package/src/vm/lib/loader.ts +3 -3
- package/src/vm/operations/helpers.ts +2 -3
- package/src/vm/types/context.ts +1 -0
- package/src/vm/types/function.ts +35 -23
- package/dist/chunk-43TX2QFV.js.map +0 -6
|
@@ -5,20 +5,58 @@ type SerializeFormat =
|
|
|
5
5
|
''
|
|
6
6
|
/** 以 `%` 开头的格式占位符 */
|
|
7
7
|
| `%${string}`;
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
/** 格式化结果 */
|
|
9
|
+
interface FormatResult {
|
|
10
|
+
/** 模板字符串数组 */
|
|
11
|
+
templates: readonly string[];
|
|
12
|
+
/** 值数组,长度为 {@link templates}.length - 1 */
|
|
13
|
+
values: readonly VmAny[];
|
|
14
|
+
/** 格式化字符串数组,与 {@link values} 一一对应 */
|
|
15
|
+
formats: readonly SerializeFormat[];
|
|
16
|
+
}
|
|
17
|
+
/** 打印输出选项 */
|
|
18
|
+
interface PrintOptions {
|
|
19
|
+
/** 输出时的固定前缀 */
|
|
20
|
+
prefix: readonly [prefix: string, ...additional: readonly string[]];
|
|
21
|
+
/**
|
|
22
|
+
* 序列化函数
|
|
23
|
+
* @param arg 要序列化的值
|
|
24
|
+
* @param format 序列化格式
|
|
25
|
+
* @returns 序列化后的字符串,或 null 表示直接将原值传递给控制台
|
|
26
|
+
*/
|
|
27
|
+
serializer: (this: PrintOptions, arg: VmAny, format: SerializeFormat) => string | null | PromiseLike<string>;
|
|
28
|
+
/** 格式化函数 */
|
|
29
|
+
formatter: (this: PrintOptions, args: readonly VmAny[]) => FormatResult;
|
|
30
|
+
/** 输出函数 */
|
|
31
|
+
printer: (this: PrintOptions, format: FormatResult) => void;
|
|
32
|
+
}
|
|
15
33
|
export declare const debug_print: ((...args: readonly (import("../../types/index.js").VmValue | undefined)[]) => void) & import("../helpers.js").VmLibOption & {
|
|
34
|
+
printer: (this: PrintOptions, format: FormatResult) => void;
|
|
35
|
+
/** 输出时的固定前缀 */
|
|
16
36
|
prefix: readonly [prefix: string, ...additional: readonly string[]];
|
|
17
|
-
|
|
37
|
+
/**
|
|
38
|
+
* 序列化函数
|
|
39
|
+
* @param arg 要序列化的值
|
|
40
|
+
* @param format 序列化格式
|
|
41
|
+
* @returns 序列化后的字符串,或 null 表示直接将原值传递给控制台
|
|
42
|
+
*/
|
|
43
|
+
serializer: (this: PrintOptions, arg: VmAny, format: SerializeFormat) => string | null | PromiseLike<string>;
|
|
44
|
+
/** 格式化函数 */
|
|
45
|
+
formatter: (this: PrintOptions, args: readonly VmAny[]) => FormatResult;
|
|
18
46
|
};
|
|
19
47
|
export declare const panic: ((message: VmAny) => never) & import("../helpers.js").VmLibOption & {
|
|
48
|
+
printer: (this: PrintOptions, format: FormatResult) => void;
|
|
49
|
+
/** 输出时的固定前缀 */
|
|
20
50
|
prefix: readonly [prefix: string, ...additional: readonly string[]];
|
|
21
|
-
|
|
51
|
+
/**
|
|
52
|
+
* 序列化函数
|
|
53
|
+
* @param arg 要序列化的值
|
|
54
|
+
* @param format 序列化格式
|
|
55
|
+
* @returns 序列化后的字符串,或 null 表示直接将原值传递给控制台
|
|
56
|
+
*/
|
|
57
|
+
serializer: (this: PrintOptions, arg: VmAny, format: SerializeFormat) => string | null | PromiseLike<string>;
|
|
58
|
+
/** 格式化函数 */
|
|
59
|
+
formatter: (this: PrintOptions, args: readonly VmAny[]) => FormatResult;
|
|
22
60
|
};
|
|
23
61
|
export {};
|
|
24
62
|
//# sourceMappingURL=debug.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../../src/vm/lib/global/debug.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,YAAY;AACZ,KAAK,eAAe;AAChB,cAAc;AACZ,EAAE;AACJ,qBAAqB;GACnB,IAAI,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../../../../src/vm/lib/global/debug.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAGlD,YAAY;AACZ,KAAK,eAAe;AAChB,cAAc;AACZ,EAAE;AACJ,qBAAqB;GACnB,IAAI,MAAM,EAAE,CAAC;AAOnB,YAAY;AACZ,UAAU,YAAY;IAClB,cAAc;IACd,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,2CAA2C;IAC3C,MAAM,EAAE,SAAS,KAAK,EAAE,CAAC;IACzB,qCAAqC;IACrC,OAAO,EAAE,SAAS,eAAe,EAAE,CAAC;CACvC;AA4HD,aAAa;AACb,UAAU,YAAY;IAClB,eAAe;IACf,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,EAAE,SAAS,MAAM,EAAE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|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../../src/vm/lib/global/json.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../../../../src/vm/lib/global/json.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,OAAO,4IAoBnB,CAAC;AAEF,eAAO,MAAM,SAAS,yfAiBrB,CAAC"}
|
package/dist/vm/lib/helpers.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ export declare function map(data: VmConst,
|
|
|
46
46
|
/** 返回 `undefined` 表示跳过该元素 */
|
|
47
47
|
mapper: (value: VmConst, index: number | string | null, data: VmConst) => VmConst | undefined): VmConst;
|
|
48
48
|
/** 库函数选项 */
|
|
49
|
-
export type VmLibOption = Pick<VmFunctionOption, 'summary' | 'params' | 'paramsType' | 'returns' | 'returnsType' | 'examples' | '
|
|
49
|
+
export type VmLibOption = Pick<VmFunctionOption, 'summary' | 'params' | 'paramsType' | 'returns' | 'returnsType' | 'examples' | 'deprecated'>;
|
|
50
50
|
/** 库函数 */
|
|
51
51
|
export type VmLib<T extends VmFunctionLike | VmConst = VmFunctionLike> = (T extends VmFunctionLike ? T : {
|
|
52
52
|
value: T;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/vm/lib/helpers.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACR,QAAQ,EACR,UAAU,EACV,KAAK,EACL,OAAO,EACP,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,cAAc,EACd,gBAAgB,EACnB,MAAM,mBAAmB,CAAC;AAG3B,WAAW;AACX,wBAAgB,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,KAAK,CAGnF;AACD,WAAW;AACX,KAAK,UAAU,GAA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KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAa7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/vm/lib/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EACV,QAAQ,EACR,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,WAAW,EACnB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/vm/lib/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAEH,UAAU,EACV,QAAQ,EACR,KAAK,OAAO,EACZ,KAAK,cAAc,EACnB,KAAK,WAAW,EACnB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAE1C,WAAW;AACX,cAAM,eAAe,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAE,SAAQ,QAAQ,CAAC,CAAC,CAAC;IAI5G,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;gBAF1D,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,EACC,YAAY,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAI9D,kBAAkB;IACT,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAGrD;AAED,UAAU;AACV,MAAM,MAAM,QAAQ,GAAG,KAAK,CAAC,cAAc,GAAG,OAAO,CAAC,GAAG,eAAe,CAAC;AACzE,UAAU;AACV,KAAK,cAAc,CAAC,CAAC,SAAS,QAAQ,IAAI,CAAC,SAAS,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,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+1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/vm/types/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAK9D,uBAAuB;AACvB,MAAM,WAAW,SAAS;IACtB,YAAY;IACZ,QAAQ,CAAC,CAAC,UAAU,CAAC,EAAE,IAAI,CAAC;IAC5B,0BAA0B;IAC1B,IAAI,IAAI,SAAS,MAAM,EAAE,CAAC;IAC1B,oCAAoC;IACpC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;IAC1C;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC1B,oCAAoC;IACpC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC7B;AACD,uBAAuB;AACvB,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACpD,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAgB,CAAC;AAC3E,eAAO,MAAM,8BAA8B,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAgB,CAAC;AAS/F,qCAAqC;AACrC,wBAAgB,oBAAoB,CAChC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,GAAG,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,KAAK,CAAC,EAClD,QAAQ,UAAQ,EAChB,WAAW,GAAE,MAAM,GAAG,IAAI,GAAG,SAAqB,GACnD,IAAI,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/vm/types/context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;A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,EAAE,CAAC,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,EAC5C,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI,GACzD,SAAS,CAAC;AACb,qBAAqB;AACrB,wBAAgB,eAAe,CAC3B,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI,EACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,EAC7C,SAAS,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GAAG,IAAI,GACzD,SAAS,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DiagnosticCode } from '@mirascript/constants';
|
|
2
2
|
import { kVmFunction } from '../../helpers/constants.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type VmAny, type VmValue } from './index.js';
|
|
4
|
+
import type { VmLib } from '../lib/helpers.js';
|
|
4
5
|
/**
|
|
5
6
|
* Mirascript 函数签名
|
|
6
7
|
*
|
|
@@ -12,7 +13,7 @@ export type VmFunction<T extends VmFunctionLike = VmFunctionLike> = T & {
|
|
|
12
13
|
readonly [kVmFunction]: VmFunctionInfo;
|
|
13
14
|
};
|
|
14
15
|
/** Mirascript 函数信息 */
|
|
15
|
-
export
|
|
16
|
+
export type VmFunctionInfo = {
|
|
16
17
|
/** 完整名称 */
|
|
17
18
|
readonly fullName: string;
|
|
18
19
|
/** 是否为库函数 */
|
|
@@ -36,11 +37,14 @@ export interface VmFunctionInfo {
|
|
|
36
37
|
use?: string;
|
|
37
38
|
message: DiagnosticCode;
|
|
38
39
|
};
|
|
39
|
-
}
|
|
40
|
+
};
|
|
40
41
|
/** Mirascript 函数创建选项 */
|
|
41
|
-
export type VmFunctionOption = Partial<Omit<VmFunctionInfo, 'original'
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
export type VmFunctionOption = Partial<Omit<VmFunctionInfo, 'original'>> & {
|
|
43
|
+
/** 函数名称 */
|
|
44
|
+
readonly name?: string | null | undefined;
|
|
45
|
+
/** 是否注入检查点 */
|
|
46
|
+
readonly injectCp?: boolean;
|
|
47
|
+
};
|
|
44
48
|
/** 创建 Mirascript 函数 */
|
|
45
|
-
export declare function VmFunction<T extends VmFunctionLike>(fn: T, option?: VmFunctionOption): VmFunction<T>;
|
|
49
|
+
export declare function VmFunction<T extends VmFunctionLike>(fn: T, option?: VmFunctionOption | VmFunction | VmLib<T>): VmFunction<T>;
|
|
46
50
|
//# sourceMappingURL=function.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../src/vm/types/function.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAA8B,MAAM,4BAA4B,CAAC;AACrF,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"function.d.ts","sourceRoot":"","sources":["../../../src/vm/types/function.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAA8B,MAAM,4BAA4B,CAAC;AACrF,OAAO,EAAgB,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAGpE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C;;;;GAIG;AAEH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,IAAI,EAAE,aAAa,CAAC,OAAO,GAAG,SAAS,CAAC,KAAK,KAAK,GAAG,IAAI,CAAC;AAE3F,oBAAoB;AACpB,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,cAAc,GAAG,cAAc,IAAI,CAAC,GAAG;IAAE,QAAQ,CAAC,CAA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AU,GAAG,KAAK,CAAC,CAAC,CAAM,GACtD,UAAU,CAAC,CAAC,CAAC,CA6Cf"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mirascript/mirascript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.43",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "An expression based scripting language.",
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"@cloudpss/worker": "^0.1.10",
|
|
30
30
|
"source-map-js": "^1.2.1",
|
|
31
31
|
"supports-color": "^10.2.2",
|
|
32
|
-
"@mirascript/bindings": "~0.1.
|
|
33
|
-
"@mirascript/constants": "~0.1.
|
|
32
|
+
"@mirascript/bindings": "~0.1.43",
|
|
33
|
+
"@mirascript/constants": "~0.1.43"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@types/node": "^25.0
|
|
36
|
+
"@types/node": "^25.1.0",
|
|
37
37
|
"ava": "^6.4.1",
|
|
38
38
|
"c8": "^10.1.3",
|
|
39
39
|
"tinybench": "^6.0.0",
|
|
@@ -10,78 +10,172 @@ type SerializeFormat =
|
|
|
10
10
|
| ''
|
|
11
11
|
/** 以 `%` 开头的格式占位符 */
|
|
12
12
|
| `%${string}`;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @param arg 要序列化的值
|
|
16
|
-
* @param format 序列化格式
|
|
17
|
-
* @returns 序列化后的字符串,或 null 表示直接将原值传递给控制台
|
|
18
|
-
*/
|
|
13
|
+
|
|
14
|
+
/** 默认的序列化函数 */
|
|
19
15
|
function defaultSerializer(arg: VmAny, format: SerializeFormat): string | null {
|
|
20
16
|
return null;
|
|
21
17
|
}
|
|
22
18
|
|
|
19
|
+
/** 格式化结果 */
|
|
20
|
+
interface FormatResult {
|
|
21
|
+
/** 模板字符串数组 */
|
|
22
|
+
templates: readonly string[];
|
|
23
|
+
/** 值数组,长度为 {@link templates}.length - 1 */
|
|
24
|
+
values: readonly VmAny[];
|
|
25
|
+
/** 格式化字符串数组,与 {@link values} 一一对应 */
|
|
26
|
+
formats: readonly SerializeFormat[];
|
|
27
|
+
}
|
|
28
|
+
|
|
23
29
|
/** 序列化值 */
|
|
24
|
-
function serializeValue(
|
|
30
|
+
function serializeValue(
|
|
31
|
+
options: PrintOptions,
|
|
32
|
+
arg: VmAny,
|
|
33
|
+
format: SerializeFormat,
|
|
34
|
+
): string | null | PromiseLike<string> {
|
|
35
|
+
const { serializer } = options;
|
|
25
36
|
if (serializer == null || serializer === defaultSerializer) {
|
|
26
37
|
return defaultSerializer(arg, format);
|
|
27
38
|
}
|
|
28
39
|
try {
|
|
29
|
-
return serializer(arg, format);
|
|
40
|
+
return serializer.call(options, arg, format);
|
|
30
41
|
} catch {
|
|
31
42
|
return defaultSerializer(arg, format);
|
|
32
43
|
}
|
|
33
44
|
}
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
/** 构造格式化字符串 */
|
|
47
|
+
function buildFormatString(
|
|
48
|
+
options: PrintOptions,
|
|
49
|
+
args: readonly VmAny[],
|
|
50
|
+
): readonly [format: string, values: readonly VmAny[]] {
|
|
51
|
+
const [prefix, ...additional] = options.prefix;
|
|
52
|
+
if (args.length <= 1 || typeof args[0] != 'string') {
|
|
53
|
+
return [prefix || '', [...additional, ...args]];
|
|
54
|
+
} else {
|
|
44
55
|
const [arg0, ...argsRest] = args;
|
|
45
|
-
const format = `${prefix || ''} ${arg0}`;
|
|
46
56
|
const values = [...additional, ...argsRest];
|
|
57
|
+
if (!prefix) {
|
|
58
|
+
return [arg0, argsRest];
|
|
59
|
+
} else {
|
|
60
|
+
return [`${prefix} ${arg0}`, values];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** 默认的格式化函数 */
|
|
66
|
+
const printFormatter: PrintOptions['formatter'] = function (args) {
|
|
67
|
+
const [format, values] = buildFormatString(this, args);
|
|
68
|
+
const templates: string[] = [];
|
|
69
|
+
const formats: SerializeFormat[] = [];
|
|
70
|
+
let valIndex = 0;
|
|
71
|
+
if (format.includes('%')) {
|
|
47
72
|
const parts = format.split(/(%[%\w])/g);
|
|
48
|
-
const messageToConsole: string[] = [];
|
|
49
|
-
const valuesToConsole: unknown[] = [];
|
|
50
|
-
let valIndex = 0;
|
|
51
73
|
for (let i = 0; i < parts.length; i++) {
|
|
52
74
|
if (i % 2 === 0) {
|
|
53
75
|
// Regular string part
|
|
54
|
-
|
|
76
|
+
templates.push(parts[i]!);
|
|
55
77
|
continue;
|
|
56
78
|
}
|
|
57
79
|
// Specifier part
|
|
58
|
-
|
|
59
|
-
if (specifier === '%%') {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
messageToConsole.push(specifier);
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
const arg = values[valIndex++]!;
|
|
67
|
-
const f = serializeValue(arg, specifier as SerializeFormat, serializer);
|
|
68
|
-
if (f != null) {
|
|
69
|
-
messageToConsole.push('%s');
|
|
70
|
-
valuesToConsole.push(f);
|
|
80
|
+
let specifier = parts[i]!;
|
|
81
|
+
if (specifier === '%%' || valIndex >= values.length) {
|
|
82
|
+
if (specifier === '%%') specifier = '%';
|
|
83
|
+
if (!templates.length) {
|
|
84
|
+
templates.push(specifier);
|
|
71
85
|
} else {
|
|
72
|
-
|
|
73
|
-
valuesToConsole.push(arg);
|
|
86
|
+
templates[templates.length - 1] += specifier;
|
|
74
87
|
}
|
|
88
|
+
continue;
|
|
75
89
|
}
|
|
90
|
+
formats.push(specifier as SerializeFormat);
|
|
91
|
+
valIndex++;
|
|
76
92
|
}
|
|
93
|
+
} else if (format) {
|
|
94
|
+
templates.push(format);
|
|
95
|
+
}
|
|
96
|
+
// Append any remaining arguments separated by spaces
|
|
97
|
+
if (valIndex < values.length) {
|
|
98
|
+
if (templates.length) {
|
|
99
|
+
templates[templates.length - 1] += ' ';
|
|
100
|
+
} else {
|
|
101
|
+
templates.push('');
|
|
102
|
+
}
|
|
103
|
+
for (let i = valIndex; i < values.length; i++) {
|
|
104
|
+
formats.push('');
|
|
105
|
+
templates.push(i < values.length - 1 ? ' ' : '');
|
|
106
|
+
}
|
|
107
|
+
valIndex++;
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
templates,
|
|
111
|
+
values,
|
|
112
|
+
formats,
|
|
113
|
+
};
|
|
114
|
+
};
|
|
77
115
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
116
|
+
/** 默认的输出函数 */
|
|
117
|
+
const createPrinter = (consoleMethod: (...args: unknown[]) => void): PrintOptions['printer'] => {
|
|
118
|
+
return function ({ templates, formats, values }: FormatResult) {
|
|
119
|
+
let format = '';
|
|
120
|
+
const formattedValues: unknown[] = [];
|
|
121
|
+
let needAwait = false;
|
|
122
|
+
for (let i = 0; i < templates.length; i++) {
|
|
123
|
+
format += templates[i]!;
|
|
124
|
+
if (i < values.length) {
|
|
125
|
+
const f = formats[i] ?? '';
|
|
126
|
+
const v = values[i]!;
|
|
127
|
+
const serialized = serializeValue(this, v, f);
|
|
128
|
+
if (serialized == null) {
|
|
129
|
+
format += f || (typeof v == 'string' ? '%s' : '%o');
|
|
130
|
+
formattedValues.push(v);
|
|
131
|
+
} else if (typeof serialized == 'string') {
|
|
132
|
+
format += '%s';
|
|
133
|
+
formattedValues.push(serialized);
|
|
134
|
+
} else {
|
|
135
|
+
needAwait = true;
|
|
136
|
+
format += '%s';
|
|
137
|
+
formattedValues.push(serialized);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
82
140
|
}
|
|
83
|
-
|
|
84
|
-
|
|
141
|
+
if (!needAwait) {
|
|
142
|
+
consoleMethod(format, ...formattedValues);
|
|
143
|
+
} else {
|
|
144
|
+
void Promise.all(formattedValues).then((resolvedValues) => {
|
|
145
|
+
consoleMethod(format, ...resolvedValues);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/** 打印输出选项 */
|
|
152
|
+
interface PrintOptions {
|
|
153
|
+
/** 输出时的固定前缀 */
|
|
154
|
+
prefix: readonly [prefix: string, ...additional: readonly string[]];
|
|
155
|
+
/**
|
|
156
|
+
* 序列化函数
|
|
157
|
+
* @param arg 要序列化的值
|
|
158
|
+
* @param format 序列化格式
|
|
159
|
+
* @returns 序列化后的字符串,或 null 表示直接将原值传递给控制台
|
|
160
|
+
*/
|
|
161
|
+
serializer: (this: PrintOptions, arg: VmAny, format: SerializeFormat) => string | null | PromiseLike<string>;
|
|
162
|
+
/** 格式化函数 */
|
|
163
|
+
formatter: (this: PrintOptions, args: readonly VmAny[]) => FormatResult;
|
|
164
|
+
/** 输出函数 */
|
|
165
|
+
printer: (this: PrintOptions, format: FormatResult) => void;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const printOptions: PrintOptions = {
|
|
169
|
+
prefix: ['MiraScript'] as readonly [prefix: string, ...additional: readonly string[]],
|
|
170
|
+
serializer: defaultSerializer,
|
|
171
|
+
formatter: printFormatter,
|
|
172
|
+
printer: () => undefined,
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export const debug_print = VmLib(
|
|
176
|
+
(...args) => {
|
|
177
|
+
const formatResult = debug_print.formatter(args);
|
|
178
|
+
debug_print.printer(formatResult);
|
|
85
179
|
},
|
|
86
180
|
{
|
|
87
181
|
summary: '打印调试信息到控制台',
|
|
@@ -91,17 +185,16 @@ export const debug_print = VmLib(
|
|
|
91
185
|
examples: ['debug_print("value:", 42);'],
|
|
92
186
|
},
|
|
93
187
|
{
|
|
94
|
-
|
|
95
|
-
|
|
188
|
+
...printOptions,
|
|
189
|
+
// eslint-disable-next-line no-console
|
|
190
|
+
printer: createPrinter(console.log),
|
|
96
191
|
},
|
|
97
192
|
);
|
|
98
193
|
|
|
99
194
|
export const panic = VmLib(
|
|
100
195
|
(message: VmAny) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// eslint-disable-next-line no-console
|
|
104
|
-
else console.error(...panic.prefix, serializeValue(message, '', panic.serializer) ?? message);
|
|
196
|
+
const formatResult = message === undefined ? panic.formatter([]) : panic.formatter([message]);
|
|
197
|
+
panic.printer(formatResult);
|
|
105
198
|
const mgsStr = toString(message, null);
|
|
106
199
|
const error = !mgsStr ? 'panic' : 'panic: ' + mgsStr;
|
|
107
200
|
throw new VmError(error, undefined);
|
|
@@ -114,8 +207,9 @@ export const panic = VmLib(
|
|
|
114
207
|
examples: ['panic("boom");'],
|
|
115
208
|
},
|
|
116
209
|
{
|
|
117
|
-
|
|
118
|
-
|
|
210
|
+
...printOptions,
|
|
211
|
+
// eslint-disable-next-line no-console
|
|
212
|
+
printer: createPrinter(console.error),
|
|
119
213
|
},
|
|
120
214
|
);
|
|
121
215
|
|
|
@@ -21,7 +21,6 @@ export const to_json = VmLib(
|
|
|
21
21
|
paramsType: { data: 'any' },
|
|
22
22
|
returnsType: 'string',
|
|
23
23
|
examples: ['to_json([1, 2, 3]) // "[1,2,3]"'],
|
|
24
|
-
injectCp: true,
|
|
25
24
|
},
|
|
26
25
|
);
|
|
27
26
|
|
|
@@ -41,6 +40,5 @@ export const from_json = VmLib(
|
|
|
41
40
|
paramsType: { json: 'string', fallback: 'any' },
|
|
42
41
|
returnsType: 'any',
|
|
43
42
|
examples: [`from_json('{"a":1}') // (a: 1)`],
|
|
44
|
-
injectCp: true,
|
|
45
43
|
},
|
|
46
44
|
);
|
package/src/vm/lib/helpers.ts
CHANGED
|
@@ -274,7 +274,7 @@ export function map(
|
|
|
274
274
|
/** 库函数选项 */
|
|
275
275
|
export type VmLibOption = Pick<
|
|
276
276
|
VmFunctionOption,
|
|
277
|
-
'summary' | 'params' | 'paramsType' | 'returns' | 'returnsType' | 'examples' | '
|
|
277
|
+
'summary' | 'params' | 'paramsType' | 'returns' | 'returnsType' | 'examples' | 'deprecated'
|
|
278
278
|
>;
|
|
279
279
|
/** 库函数 */
|
|
280
280
|
export type VmLib<T extends VmFunctionLike | VmConst = VmFunctionLike> = (T extends VmFunctionLike ? T : { value: T }) &
|
|
@@ -295,7 +295,6 @@ export function VmLib<
|
|
|
295
295
|
ret.returnsType = option.returnsType;
|
|
296
296
|
ret.summary = option.summary;
|
|
297
297
|
ret.examples = option.examples;
|
|
298
|
-
ret.injectCp = option.injectCp ?? false;
|
|
299
298
|
ret.deprecated = option.deprecated ?? undefined;
|
|
300
299
|
return ret as VmLib<T> & P;
|
|
301
300
|
}
|
package/src/vm/lib/loader.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
} from '../types/index.js';
|
|
9
9
|
import { create, defineProperty, entries } from '../../helpers/utils.js';
|
|
10
10
|
|
|
11
|
-
import type { VmLib
|
|
11
|
+
import type { VmLib } from './helpers.js';
|
|
12
12
|
|
|
13
13
|
/** 内置模块 */
|
|
14
14
|
class VmBuiltinModule<const T extends Record<string, VmImmutable> = Record<string, VmImmutable>> extends VmModule<T> {
|
|
@@ -53,10 +53,10 @@ export function wrapEntry<const T extends RawValue>(
|
|
|
53
53
|
}
|
|
54
54
|
return [
|
|
55
55
|
VmFunction(value, {
|
|
56
|
+
...value,
|
|
56
57
|
isLib: true,
|
|
57
|
-
injectCp:
|
|
58
|
+
injectCp: false,
|
|
58
59
|
fullName: `${module}.${name}`,
|
|
59
|
-
...(value as VmLibOption),
|
|
60
60
|
}) as ToWrappedValue<T>,
|
|
61
61
|
value.summary || undefined,
|
|
62
62
|
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { create,
|
|
1
|
+
import { create, isFinite } from '../../helpers/utils.js';
|
|
2
2
|
import { VM_ARRAY_MAX_LENGTH, VM_FUNCTION_ANONYMOUS_NAME } from '../../helpers/constants.js';
|
|
3
3
|
import { isVmConst } from '../../helpers/types.js';
|
|
4
4
|
import type { VmFunctionLike } from '../types/function.js';
|
|
@@ -25,8 +25,7 @@ export function $ElOpt(key: string, value: VmAny): VmConst {
|
|
|
25
25
|
|
|
26
26
|
/** 构造函数和函数表达式 */
|
|
27
27
|
export function $Fn<T extends VmFunctionLike>(name: string | null | undefined, fn: T): VmFunction<T> {
|
|
28
|
-
|
|
29
|
-
return VmFunction(fn, { isLib: false, injectCp: false });
|
|
28
|
+
return VmFunction(fn, { isLib: false, injectCp: false, name: name || VM_FUNCTION_ANONYMOUS_NAME });
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
/** 读取闭包上值 */
|
package/src/vm/types/context.ts
CHANGED
package/src/vm/types/function.ts
CHANGED
|
@@ -2,9 +2,10 @@ import type { Writable } from 'type-fest';
|
|
|
2
2
|
import type { DiagnosticCode } from '@mirascript/constants';
|
|
3
3
|
import { defineProperty } from '../../helpers/utils.js';
|
|
4
4
|
import { kVmFunction, VM_FUNCTION_ANONYMOUS_NAME } from '../../helpers/constants.js';
|
|
5
|
-
import type
|
|
5
|
+
import { isVmFunction, type VmAny, type VmValue } from './index.js';
|
|
6
6
|
import { fromVmFunctionProxy } from './boundary.js';
|
|
7
7
|
import { CpEnter, CpExit } from '../checkpoint.js';
|
|
8
|
+
import type { VmLib } from '../lib/helpers.js';
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Mirascript 函数签名
|
|
@@ -18,7 +19,7 @@ export type VmFunctionLike = (...args: ReadonlyArray<VmValue | undefined>) => Vm
|
|
|
18
19
|
export type VmFunction<T extends VmFunctionLike = VmFunctionLike> = T & { readonly [kVmFunction]: VmFunctionInfo };
|
|
19
20
|
|
|
20
21
|
/** Mirascript 函数信息 */
|
|
21
|
-
export
|
|
22
|
+
export type VmFunctionInfo = {
|
|
22
23
|
/** 完整名称 */
|
|
23
24
|
readonly fullName: string;
|
|
24
25
|
/** 是否为库函数 */
|
|
@@ -39,17 +40,21 @@ export interface VmFunctionInfo {
|
|
|
39
40
|
readonly original?: VmFunctionLike;
|
|
40
41
|
/** 标记为弃用 */
|
|
41
42
|
readonly deprecated?: { use?: string; message: DiagnosticCode };
|
|
42
|
-
}
|
|
43
|
+
};
|
|
43
44
|
|
|
44
45
|
/** Mirascript 函数创建选项 */
|
|
45
|
-
export type VmFunctionOption = Partial<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
export type VmFunctionOption = Partial<Omit<VmFunctionInfo, 'original'>> & {
|
|
47
|
+
/** 函数名称 */
|
|
48
|
+
readonly name?: string | null | undefined;
|
|
49
|
+
/** 是否注入检查点 */
|
|
50
|
+
readonly injectCp?: boolean;
|
|
51
|
+
};
|
|
50
52
|
|
|
51
53
|
/** 创建 Mirascript 函数 */
|
|
52
|
-
export function VmFunction<T extends VmFunctionLike>(
|
|
54
|
+
export function VmFunction<T extends VmFunctionLike>(
|
|
55
|
+
fn: T,
|
|
56
|
+
option: VmFunctionOption | VmFunction | VmLib<T> = {},
|
|
57
|
+
): VmFunction<T> {
|
|
53
58
|
if (typeof fn != 'function') {
|
|
54
59
|
throw new TypeError('Invalid function');
|
|
55
60
|
}
|
|
@@ -57,19 +62,28 @@ export function VmFunction<T extends VmFunctionLike>(fn: T, option: VmFunctionOp
|
|
|
57
62
|
const exists = fromVmFunctionProxy(fn);
|
|
58
63
|
// 如果已经是 VmFunction,则直接返回
|
|
59
64
|
if (exists) return exists;
|
|
65
|
+
let opt: VmFunctionOption;
|
|
66
|
+
if (isVmFunction(option)) {
|
|
67
|
+
opt = option[kVmFunction];
|
|
68
|
+
} else if (typeof option == 'function') {
|
|
69
|
+
opt = { ...option, isLib: true } satisfies VmFunctionOption;
|
|
70
|
+
} else {
|
|
71
|
+
opt = option;
|
|
72
|
+
}
|
|
60
73
|
|
|
61
74
|
const info: Writable<VmFunctionInfo> = {
|
|
62
|
-
fullName:
|
|
63
|
-
isLib:
|
|
64
|
-
summary:
|
|
65
|
-
params:
|
|
66
|
-
paramsType:
|
|
67
|
-
returns:
|
|
68
|
-
returnsType:
|
|
69
|
-
examples:
|
|
70
|
-
deprecated:
|
|
75
|
+
fullName: opt.fullName ?? (fn.name === VM_FUNCTION_ANONYMOUS_NAME ? '' : fn.name),
|
|
76
|
+
isLib: opt.isLib ?? false,
|
|
77
|
+
summary: opt.summary || undefined,
|
|
78
|
+
params: opt.params,
|
|
79
|
+
paramsType: opt.paramsType,
|
|
80
|
+
returns: opt.returns || undefined,
|
|
81
|
+
returnsType: opt.returnsType || undefined,
|
|
82
|
+
examples: opt.examples?.length ? opt.examples : undefined,
|
|
83
|
+
deprecated: opt.deprecated ?? undefined,
|
|
71
84
|
};
|
|
72
|
-
|
|
85
|
+
const name = opt.name ?? fn.name;
|
|
86
|
+
if (opt.injectCp) {
|
|
73
87
|
const original = fn;
|
|
74
88
|
info.original = original;
|
|
75
89
|
fn = ((...args) => {
|
|
@@ -81,10 +95,8 @@ export function VmFunction<T extends VmFunctionLike>(fn: T, option: VmFunctionOp
|
|
|
81
95
|
CpExit();
|
|
82
96
|
}
|
|
83
97
|
}) as typeof fn;
|
|
84
|
-
defineProperty(fn, 'name', { value: original.name });
|
|
85
98
|
}
|
|
86
|
-
defineProperty(fn,
|
|
87
|
-
|
|
88
|
-
});
|
|
99
|
+
defineProperty(fn, 'name', { value: name, configurable: true });
|
|
100
|
+
defineProperty(fn, kVmFunction, { value: Object.freeze(info) });
|
|
89
101
|
return fn as VmFunction<T>;
|
|
90
102
|
}
|