@mirascript/mirascript 0.1.18 → 0.1.20
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-5AEWM4W6.js → chunk-4T5YE7LC.js} +241 -177
- package/dist/chunk-4T5YE7LC.js.map +6 -0
- package/dist/{chunk-RLWIIOH5.js → chunk-BV5YXQYA.js} +1 -1
- package/dist/{chunk-RLWIIOH5.js.map → chunk-BV5YXQYA.js.map} +1 -1
- package/dist/chunk-OVTSNACH.js +152 -0
- package/dist/chunk-OVTSNACH.js.map +6 -0
- package/dist/{chunk-3BAOZ2P2.js → chunk-ZKL4MRMP.js} +185 -212
- package/dist/chunk-ZKL4MRMP.js.map +6 -0
- package/dist/cli/index.js +6 -5
- package/dist/cli/index.js.map +1 -1
- package/dist/compiler/emit/constants.d.ts +1 -2
- package/dist/compiler/emit/constants.d.ts.map +1 -1
- package/dist/compiler/emit/consts.d.ts +2 -2
- package/dist/compiler/emit/consts.d.ts.map +1 -1
- package/dist/compiler/emit/index.d.ts +2 -3
- package/dist/compiler/emit/index.d.ts.map +1 -1
- package/dist/compiler/emit/sourcemap.d.ts +1 -2
- package/dist/compiler/emit/sourcemap.d.ts.map +1 -1
- package/dist/compiler/emit-script.d.ts +10 -0
- package/dist/compiler/emit-script.d.ts.map +1 -0
- package/dist/compiler/generate-bytecode.d.ts +4 -2
- package/dist/compiler/generate-bytecode.d.ts.map +1 -1
- package/dist/compiler/index.d.ts +1 -6
- package/dist/compiler/index.d.ts.map +1 -1
- package/dist/compiler/load-module.d.ts +2 -0
- package/dist/compiler/load-module.d.ts.map +1 -0
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/constants.d.ts +2 -0
- package/dist/helpers/constants.d.ts.map +1 -1
- package/dist/helpers/serialize.d.ts.map +1 -1
- package/dist/helpers/utils.d.ts.map +1 -1
- package/dist/index.js +6 -11
- package/dist/subtle.d.ts +3 -1
- package/dist/subtle.d.ts.map +1 -1
- package/dist/subtle.js +3 -3
- package/dist/vm/checkpoint.d.ts +1 -1
- package/dist/vm/checkpoint.d.ts.map +1 -1
- package/dist/vm/helpers.d.ts +6 -1
- package/dist/vm/helpers.d.ts.map +1 -1
- package/dist/vm/lib/global/json.d.ts.map +1 -1
- package/dist/vm/lib/global/math-const.d.ts +24 -2
- package/dist/vm/lib/global/math-const.d.ts.map +1 -1
- package/dist/vm/lib/helpers.d.ts +5 -3
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/lib/index.d.ts.map +1 -1
- package/dist/vm/lib/loader.d.ts +12 -5
- package/dist/vm/lib/loader.d.ts.map +1 -1
- package/dist/vm/types/context.d.ts +10 -18
- package/dist/vm/types/context.d.ts.map +1 -1
- package/dist/vm/types/extern.d.ts +1 -1
- package/dist/vm/types/extern.d.ts.map +1 -1
- package/dist/vm/types/module.d.ts +1 -1
- package/dist/vm/types/module.d.ts.map +1 -1
- package/dist/vm/types/wrapper.d.ts +4 -2
- package/dist/vm/types/wrapper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/compiler/emit/constants.ts +1 -2
- package/src/compiler/emit/consts.ts +166 -29
- package/src/compiler/emit/index.ts +40 -32
- package/src/compiler/emit/sourcemap.ts +21 -76
- package/src/compiler/emit-script.ts +30 -0
- package/src/compiler/generate-bytecode.ts +5 -8
- package/src/compiler/index.ts +2 -30
- package/src/compiler/load-module.ts +3 -0
- package/src/helpers/constants.ts +2 -0
- package/src/helpers/serialize.ts +1 -4
- package/src/helpers/utils.ts +2 -7
- package/src/subtle.ts +3 -1
- package/src/vm/checkpoint.ts +42 -17
- package/src/vm/helpers.ts +12 -5
- package/src/vm/lib/global/json.ts +2 -0
- package/src/vm/lib/global/math-const.ts +34 -2
- package/src/vm/lib/helpers.ts +10 -11
- package/src/vm/lib/index.ts +7 -3
- package/src/vm/lib/loader.ts +56 -19
- package/src/vm/types/context.ts +58 -30
- package/src/vm/types/extern.ts +1 -1
- package/src/vm/types/module.ts +1 -1
- package/src/vm/types/wrapper.ts +9 -5
- package/dist/chunk-3BAOZ2P2.js.map +0 -6
- package/dist/chunk-5AEWM4W6.js.map +0 -6
- package/dist/chunk-RIT53WVY.js +0 -1
- package/dist/chunk-RIT53WVY.js.map +0 -6
- package/dist/compiler/emit/globals.d.ts +0 -17
- package/dist/compiler/emit/globals.d.ts.map +0 -1
- package/src/compiler/emit/globals.ts +0 -39
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"math-const.d.ts","sourceRoot":"","sources":["../../../../src/vm/lib/global/math-const.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"math-const.d.ts","sourceRoot":"","sources":["../../../../src/vm/lib/global/math-const.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,EAAE;;8DAGb,CAAC;AACH,eAAO,MAAM,CAAC;;8DAGZ,CAAC;AACH,eAAO,MAAM,OAAO;;8DAGlB,CAAC;AACH,eAAO,MAAM,KAAK;;8DAGhB,CAAC;AACH,eAAO,MAAM,GAAG;;8DAGd,CAAC;AACH,eAAO,MAAM,IAAI;;8DAGf,CAAC;AACH,eAAO,MAAM,KAAK;;8DAGhB,CAAC;AACH,eAAO,MAAM,MAAM;;8DAGjB,CAAC"}
|
package/dist/vm/lib/helpers.d.ts
CHANGED
|
@@ -46,10 +46,12 @@ 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' | 'injectCp'>;
|
|
50
50
|
/** 库函数 */
|
|
51
|
-
export type VmLib<T extends VmFunctionLike = VmFunctionLike> = T
|
|
51
|
+
export type VmLib<T extends VmFunctionLike | VmConst = VmFunctionLike> = (T extends VmFunctionLike ? T : {
|
|
52
|
+
value: T;
|
|
53
|
+
}) & VmLibOption;
|
|
52
54
|
/** 创建库函数 */
|
|
53
|
-
export declare function VmLib<const T extends VmFunctionLike, P extends Record<string, unknown> = Record<never, never>>(
|
|
55
|
+
export declare function VmLib<const T extends VmFunctionLike | VmConst, P extends Record<string, unknown> = Record<never, never>>(value: T, option: VmLibOption, properties?: P): VmLib<T> & P;
|
|
54
56
|
export {};
|
|
55
57
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -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,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AACzC,WAAW;AACX,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAQtD;AAED,gBAAgB;AAChB,wBAAgB,wBAAwB,CACpC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,KAAK,GAAG,CAAC,MAAM,KAAK,CAAC,GACjC,KAAK,CAEP;AACD,gBAAgB;AAChB,wBAAgB,yBAAyB,CACrC,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,KAAK,GAAG,CAAC,MAAM,K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6B;AAC7B,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,GAAG,SAAS,GAC9F,OAAO,CAwBT;AAED,YAAY;AACZ,MAAM,MAAM,WAAW,GAAG,IAAI,CAC1B,gBAAgB,EAChB,SAAS,GAAG,QAAQ,GAAG,YAAY,GAAG,SAAS,GAAG,aAAa,GAAG,UAAU,GAAG,UAAU,CAC5F,CAAC;AACF,UAAU;AACV,MAAM,MAAM,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,OAAO,GAAG,cAAc,IAAI,CAAC,CAAC,SAAS,cAAc,GAAG,CAAC,GAAG;IAAE,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC,GAClH,WAAW,CAAC;AAEhB,YAAY;AACZ,wBAAgB,KAAK,CACjB,KAAK,CAAC,CAAC,SAAS,cAAc,GAAG,OAAO,EACxC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC1D,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAa7D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vm/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/vm/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAC;AAkBvC,eAAO,MAAM,GAAG,EAAE,QAAQ,CAAC,OAAO,MAAM,GAAG,OAAO,IAAI,CAA4D,CAAC"}
|
package/dist/vm/lib/loader.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
|
-
import { VmFunction, VmModule, type VmConst, type VmFunctionLike } from '../types/index.js';
|
|
1
|
+
import { VmFunction, VmModule, type VmConst, type VmFunctionLike, type VmImmutable } from '../types/index.js';
|
|
2
2
|
import type { VmLib } from './helpers.js';
|
|
3
|
+
/** 内置模块 */
|
|
4
|
+
declare class VmBuiltinModule<const T extends Record<string, VmImmutable> = Record<string, VmImmutable>> extends VmModule<T> {
|
|
5
|
+
readonly descriptions: Record<keyof T, string | undefined>;
|
|
6
|
+
constructor(name: string, value: T, descriptions: Record<keyof T, string | undefined>);
|
|
7
|
+
/** @inheritdoc */
|
|
8
|
+
describe(key: string): string | undefined;
|
|
9
|
+
}
|
|
3
10
|
/** 原始值 */
|
|
4
|
-
export type RawValue = VmLib | VmConst |
|
|
11
|
+
export type RawValue = VmLib<VmFunctionLike | VmConst> | VmBuiltinModule;
|
|
5
12
|
/** 包装值 */
|
|
6
|
-
type ToWrappedValue<V extends RawValue> = V extends VmFunctionLike ? VmFunction<
|
|
13
|
+
type ToWrappedValue<V extends RawValue> = V extends VmLib<infer C> ? (C extends VmFunctionLike ? VmFunction<C> : C) : V;
|
|
7
14
|
/** 包装值 */
|
|
8
|
-
export declare function wrapEntry<const T extends RawValue>(name: string, value: T, module: string): ToWrappedValue<T
|
|
15
|
+
export declare function wrapEntry<const T extends RawValue>(name: string, value: T, module: string): [value: ToWrappedValue<T>, description: string | undefined];
|
|
9
16
|
/** 创建模块 */
|
|
10
|
-
export type ToWrappedModule<T extends Record<string, RawValue>> =
|
|
17
|
+
export type ToWrappedModule<T extends Record<string, RawValue>> = VmBuiltinModule<{
|
|
11
18
|
[key in keyof T]: ToWrappedValue<T[key]>;
|
|
12
19
|
}>;
|
|
13
20
|
/** 创建模块 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/vm/lib/loader.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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;AAEvD,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,CAAC,SAAS,cAAc,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;AACxH,UAAU;AACV,wBAAgB,SAAS,CAAC,KAAK,CAAC,CAAC,SAAS,QAAQ,EAC9C,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,CAAC,EACR,MAAM,EAAE,MAAM,GACf,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC,CA0B7D;AAED,WAAW;AACX,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,IAAI,eAAe,CAAC;KAC7E,GAAG,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;CAC3C,CAAC,CAAC;AAEH,WAAW;AACX,wBAAgB,YAAY,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,GAAG,eAAe,CAAC,CAAC,CAAC,CAS/G"}
|
|
@@ -7,7 +7,7 @@ export interface VmContext {
|
|
|
7
7
|
/** 枚举所有 key,仅在 LSP 中使用 */
|
|
8
8
|
keys(): readonly string[];
|
|
9
9
|
/** 描述值,返回 MarkDown 文本,仅在 LSP 中使用 */
|
|
10
|
-
describe
|
|
10
|
+
describe(key: string): string | undefined;
|
|
11
11
|
/**
|
|
12
12
|
* 获取指定 key 的值 `global[key]`
|
|
13
13
|
* @throws {VmError} 如果值不存在则抛出异常
|
|
@@ -19,25 +19,17 @@ export interface VmContext {
|
|
|
19
19
|
/** MiraScript 执行上下文 */
|
|
20
20
|
export type VmContextRecord = Record<string, VmValue>;
|
|
21
21
|
/** MiraScript 执行上下文 */
|
|
22
|
-
export type VmContextRecordLoose = Record<string,
|
|
22
|
+
export type VmContextRecordLoose = Record<string, VmAny>;
|
|
23
23
|
export declare const VM_SHARED_CONTEXT: Record<string, VmImmutable>;
|
|
24
|
+
export declare const VM_SHARED_CONTEXT_DESCRIPTIONS: Record<string, string | undefined>;
|
|
24
25
|
/** 定义在所有 MiraScript 执行上下文中共享的全局变量 */
|
|
25
|
-
export declare function defineVmContextValue(name: string, value: VmImmutable | ((...args: VmAny[]) => VmAny), override?: boolean): void;
|
|
26
|
+
export declare function defineVmContextValue(name: string, value: VmImmutable | ((...args: VmAny[]) => VmAny), override?: boolean, description?: string | null | undefined): void;
|
|
26
27
|
/** 无后备的实现 */
|
|
27
|
-
export declare const DefaultVmContext: VmContext
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
vmValues?: VmContextRecordLoose | null | undefined,
|
|
31
|
-
externValues?: Record<string, unknown> | null | undefined,
|
|
32
|
-
describer?: ((key: string) => string | undefined) | null | undefined
|
|
33
|
-
];
|
|
34
|
-
/** 以工厂函数为后备的实现 */
|
|
35
|
-
type CreateVmContextWithFactory = readonly [
|
|
36
|
-
getter: (key: string) => VmValue | undefined,
|
|
37
|
-
enumerator?: (() => Iterable<string>) | null | undefined,
|
|
38
|
-
describer?: ((key: string) => string | undefined) | null | undefined
|
|
39
|
-
];
|
|
28
|
+
export declare const DefaultVmContext: Readonly<VmContext>;
|
|
29
|
+
/** 获取用于执行脚本的默认执行上下文 */
|
|
30
|
+
export declare function createVmContext(): Readonly<VmContext>;
|
|
40
31
|
/** 创建用于执行脚本的执行上下文 */
|
|
41
|
-
export declare function createVmContext(
|
|
42
|
-
|
|
32
|
+
export declare function createVmContext(vmValues?: VmContextRecordLoose | null, externValues?: Record<string, unknown> | null, describer?: ((key: string) => string | undefined) | null): VmContext;
|
|
33
|
+
/** 创建用于执行脚本的执行上下文 */
|
|
34
|
+
export declare function createVmContext(getter: (key: string) => VmValue | undefined, enumerator?: (() => Iterable<string>) | null, describer?: ((key: string) => string | undefined) | null): VmContext;
|
|
43
35
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/vm/types/context.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AACxD,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAK9D,uB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kB;IAClB,IAAa,IAAI,IAAI,QAAQ,CAE5B;IACD,kBAAkB;IAClB,IAAa,GAAG,IAAI,MAAM,CAqCzB;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/vm/types/module.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,oBAAoB;AACpB,qBAAa,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAE7G,WAAW;IACX,QAAQ,CAAC,IAAI,EAAE,MAAM;;IADrB,WAAW;IACF,IAAI,EAAE,MAAM;IACrB,WAAW;IACX,KAAK,EAAE,CAAC;IAIZ,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAGlC,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIhC,kBAAkB;IACT,IAAI,IAAI,MAAM,EAAE;IAGzB,kBAAkB;IACT,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAGpC,kBAAkB;IAClB,IAAa,IAAI,IAAI,QAAQ,CAE5B;IACD,kBAAkB;IAClB,IAAa,
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../../src/vm/types/module.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEzC,oBAAoB;AACpB,qBAAa,QAAQ,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAE,SAAQ,SAAS,CAAC,CAAC,CAAC;IAE7G,WAAW;IACX,QAAQ,CAAC,IAAI,EAAE,MAAM;;IADrB,WAAW;IACF,IAAI,EAAE,MAAM;IACrB,WAAW;IACX,KAAK,EAAE,CAAC;IAIZ,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAGlC,kBAAkB;IACT,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIhC,kBAAkB;IACT,IAAI,IAAI,MAAM,EAAE;IAGzB,kBAAkB;IACT,IAAI,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAGpC,kBAAkB;IAClB,IAAa,IAAI,IAAI,QAAQ,CAE5B;IACD,kBAAkB;IAClB,IAAa,GAAG,IAAI,MAAM,CAEzB;CACJ"}
|
|
@@ -15,8 +15,10 @@ export declare abstract class VmWrapper<T extends object> {
|
|
|
15
15
|
abstract same(other: VmAny): boolean;
|
|
16
16
|
/** 获取类型 */
|
|
17
17
|
abstract get type(): TypeName;
|
|
18
|
-
/**
|
|
19
|
-
abstract get
|
|
18
|
+
/** 获取当前对象的描述 */
|
|
19
|
+
abstract get tag(): string;
|
|
20
|
+
/** 描述键对应的值 */
|
|
21
|
+
describe(key: string): string | undefined;
|
|
20
22
|
/** Convert the object to JSON */
|
|
21
23
|
toJSON(): undefined;
|
|
22
24
|
/** 转为字符串 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.d.ts","sourceRoot":"","sources":["../../../src/vm/types/wrapper.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAElD;;GAEG;AACH,8BAAsB,SAAS,CAAC,CAAC,SAAS,MAAM;IAChC,QAAQ,CAAC,KAAK,EAAE,CAAC;gBAAR,KAAK,EAAE,CAAC;IAC7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
|
2
2
|
"name": "@mirascript/mirascript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"author": "CloudPSS",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "An expression based scripting language.",
|
|
@@ -36,16 +36,16 @@
|
|
|
36
36
|
"commander": "^14.0.2",
|
|
37
37
|
"source-map-js": "^1.2.1",
|
|
38
38
|
"supports-color": "^10.2.2",
|
|
39
|
-
"@mirascript/bindings": "~0.1.
|
|
39
|
+
"@mirascript/bindings": "~0.1.20"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/node": "^24.10.
|
|
42
|
+
"@types/node": "^24.10.2",
|
|
43
43
|
"@types/sinon": "^21.0.0",
|
|
44
44
|
"ava": "^6.4.1",
|
|
45
45
|
"c8": "^10.1.3",
|
|
46
46
|
"madge": "^8.0.0",
|
|
47
47
|
"sinon": "^21.0.0",
|
|
48
|
-
"type-fest": "^5.
|
|
48
|
+
"type-fest": "^5.3.1"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"watch": "pnpm build:ts --watch",
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export const SCRIPT_PREFIX = `
|
|
2
|
-
export const GLOBAL_HINT = `/* globals */`;
|
|
1
|
+
export const SCRIPT_PREFIX = `return ((global = GlobalFallback()) => { try { CpEnter();`;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { VmPrimitive } from '../../vm/index.js';
|
|
2
|
-
|
|
2
|
+
const { stringify } = JSON;
|
|
3
3
|
/** 将值转为 JS 字面量 */
|
|
4
4
|
export function toJsLiteral(value: VmPrimitive | undefined): string {
|
|
5
5
|
/* c8 ignore next 2 */
|
|
6
6
|
if (value === null) return 'null';
|
|
7
7
|
if (value === undefined) return 'undefined';
|
|
8
8
|
if (typeof value == 'string') {
|
|
9
|
-
return
|
|
9
|
+
return stringify(value);
|
|
10
10
|
}
|
|
11
11
|
// JSON 无法处理 NaN 等特殊数字
|
|
12
12
|
if (value === 0) {
|
|
@@ -16,32 +16,169 @@ export function toJsLiteral(value: VmPrimitive | undefined): string {
|
|
|
16
16
|
return String(value satisfies number | boolean);
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
19
|
+
const DECODER = new TextDecoder();
|
|
20
|
+
const { fromCharCode } = String;
|
|
21
|
+
/** 解码 Ascii */
|
|
22
|
+
function shortStringInJS(buf: Uint8Array, begin: number, length: number): string | undefined {
|
|
23
|
+
if (length < 4) {
|
|
24
|
+
if (length < 2) {
|
|
25
|
+
if (length === 0) return '';
|
|
26
|
+
const a = buf[begin]!;
|
|
27
|
+
if ((a & 0x80) > 0) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
return fromCharCode(a);
|
|
31
|
+
}
|
|
32
|
+
const a = buf[begin++]!;
|
|
33
|
+
const b = buf[begin++]!;
|
|
34
|
+
if ((a & 0x80) > 0 || (b & 0x80) > 0) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (length < 3) return fromCharCode(a, b);
|
|
38
|
+
const c = buf[begin++]!;
|
|
39
|
+
if ((c & 0x80) > 0) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
return fromCharCode(a, b, c);
|
|
43
|
+
}
|
|
44
|
+
const a = buf[begin++]!;
|
|
45
|
+
const b = buf[begin++]!;
|
|
46
|
+
const c = buf[begin++]!;
|
|
47
|
+
const d = buf[begin++]!;
|
|
48
|
+
if ((a & 0x80) > 0 || (b & 0x80) > 0 || (c & 0x80) > 0 || (d & 0x80) > 0) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (length < 6) {
|
|
52
|
+
if (length === 4) return fromCharCode(a, b, c, d);
|
|
53
|
+
const e = buf[begin++]!;
|
|
54
|
+
if ((e & 0x80) > 0) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return fromCharCode(a, b, c, d, e);
|
|
58
|
+
}
|
|
59
|
+
const e = buf[begin++]!;
|
|
60
|
+
const f = buf[begin++]!;
|
|
61
|
+
if ((e & 0x80) > 0 || (f & 0x80) > 0) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (length < 8) {
|
|
65
|
+
if (length < 7) return fromCharCode(a, b, c, d, e, f);
|
|
66
|
+
const g = buf[begin++]!;
|
|
67
|
+
if ((g & 0x80) > 0) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
return fromCharCode(a, b, c, d, e, f, g);
|
|
71
|
+
}
|
|
72
|
+
const g = buf[begin++]!;
|
|
73
|
+
const h = buf[begin++]!;
|
|
74
|
+
if ((g & 0x80) > 0 || (h & 0x80) > 0) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
if (length < 10) {
|
|
78
|
+
if (length === 8) return fromCharCode(a, b, c, d, e, f, g, h);
|
|
79
|
+
const i = buf[begin++]!;
|
|
80
|
+
if ((i & 0x80) > 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i);
|
|
84
|
+
}
|
|
85
|
+
const i = buf[begin++]!;
|
|
86
|
+
const j = buf[begin++]!;
|
|
87
|
+
if ((i & 0x80) > 0 || (j & 0x80) > 0) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (length < 12) {
|
|
91
|
+
if (length < 11) return fromCharCode(a, b, c, d, e, f, g, h, i, j);
|
|
92
|
+
const k = buf[begin++]!;
|
|
93
|
+
if ((k & 0x80) > 0) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k);
|
|
97
|
+
}
|
|
98
|
+
const k = buf[begin++]!;
|
|
99
|
+
const l = buf[begin++]!;
|
|
100
|
+
if ((k & 0x80) > 0 || (l & 0x80) > 0) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (length < 14) {
|
|
104
|
+
if (length === 12) return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l);
|
|
105
|
+
const m = buf[begin++]!;
|
|
106
|
+
if ((m & 0x80) > 0) {
|
|
107
|
+
begin -= 13;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m);
|
|
111
|
+
}
|
|
112
|
+
const m = buf[begin++]!;
|
|
113
|
+
const n = buf[begin++]!;
|
|
114
|
+
if ((m & 0x80) > 0 || (n & 0x80) > 0) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (length < 15) return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n);
|
|
118
|
+
const o = buf[begin++]!;
|
|
119
|
+
if ((o & 0x80) > 0) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
return fromCharCode(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** 解码字符串 */
|
|
126
|
+
function decodeStr(buffer: Uint8Array, offset: number, length: number): string {
|
|
127
|
+
// Fast path for short ascii strings
|
|
128
|
+
if (length < 16) {
|
|
129
|
+
const shortStr = shortStringInJS(buffer, offset, length);
|
|
130
|
+
if (shortStr !== undefined) {
|
|
131
|
+
return shortStr;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
return DECODER.decode(buffer.subarray(offset, offset + length));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** 读取常量表 */
|
|
138
|
+
export function readConsts(constChunk: Uint8Array): VmPrimitive[] {
|
|
139
|
+
const reader = new DataView(constChunk.buffer, constChunk.byteOffset, constChunk.byteLength);
|
|
140
|
+
const consts: VmPrimitive[] = [];
|
|
141
|
+
let offset = 0;
|
|
142
|
+
const length = reader.byteLength;
|
|
143
|
+
while (offset < length) {
|
|
144
|
+
const type = reader.getUint8(offset);
|
|
145
|
+
switch (type) {
|
|
146
|
+
/* c8 ignore next 2 */
|
|
147
|
+
case 0:
|
|
148
|
+
consts.push(null);
|
|
149
|
+
offset += 1;
|
|
150
|
+
break;
|
|
151
|
+
case 1:
|
|
152
|
+
consts.push(true);
|
|
153
|
+
offset += 1;
|
|
154
|
+
break;
|
|
155
|
+
case 2:
|
|
156
|
+
consts.push(false);
|
|
157
|
+
offset += 1;
|
|
158
|
+
break;
|
|
159
|
+
case 3: {
|
|
160
|
+
const ordinal = reader.getInt32(offset + 1, true);
|
|
161
|
+
consts.push(ordinal);
|
|
162
|
+
offset += 5;
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
case 4: {
|
|
166
|
+
const num = reader.getFloat64(offset + 1, true);
|
|
167
|
+
consts.push(num);
|
|
168
|
+
offset += 9;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
case 5: {
|
|
172
|
+
const len = reader.getUint32(offset + 1, true);
|
|
173
|
+
const str = decodeStr(constChunk, offset + 5, len);
|
|
174
|
+
consts.push(str);
|
|
175
|
+
offset += 5 + len;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
/* c8 ignore next 2 */
|
|
179
|
+
default:
|
|
180
|
+
throw new Error(`Unknown constant type: ${type}`);
|
|
181
|
+
}
|
|
46
182
|
}
|
|
183
|
+
return consts;
|
|
47
184
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { OpCode } from '@mirascript/bindings';
|
|
2
|
+
import { toString } from '../../helpers/convert/to-string.js';
|
|
2
3
|
import type { VmPrimitive } from '../../vm/index.js';
|
|
3
4
|
import type { ScriptInput, TranspileOptions } from '../types.js';
|
|
4
5
|
import type { IRange } from '../diagnostic.js';
|
|
5
|
-
import {
|
|
6
|
-
import { readConst, toJsLiteral } from './consts.js';
|
|
6
|
+
import { readConsts, toJsLiteral } from './consts.js';
|
|
7
7
|
import { createSourceMap } from './sourcemap.js';
|
|
8
|
+
import { SCRIPT_PREFIX } from './constants.js';
|
|
8
9
|
|
|
9
10
|
/** 生成代码 */
|
|
10
11
|
export function emit(
|
|
@@ -29,8 +30,6 @@ function createArray<T>(length: number, fn: (index: number) => T): T[] {
|
|
|
29
30
|
return result;
|
|
30
31
|
}
|
|
31
32
|
|
|
32
|
-
const SCRIPT_PREFIX = `'use strict'; return ((global = GlobalFallback()) => { try { CpEnter();`;
|
|
33
|
-
const GLOBAL_HINT = `/* globals */`;
|
|
34
33
|
/** 代码生成 */
|
|
35
34
|
export class Emitter {
|
|
36
35
|
constructor(
|
|
@@ -47,22 +46,21 @@ export class Emitter {
|
|
|
47
46
|
this.constSize = reader.getUint32(8 + this.codeSize, true);
|
|
48
47
|
|
|
49
48
|
this.codeReader = new DataView(chunk.buffer, chunk.byteOffset + 8, this.codeSize);
|
|
50
|
-
this.
|
|
49
|
+
this.constVals = readConsts(
|
|
50
|
+
new Uint8Array(chunk.buffer, chunk.byteOffset + 12 + this.codeSize, this.constSize),
|
|
51
|
+
);
|
|
51
52
|
}
|
|
52
|
-
readonly pretty;
|
|
53
|
+
readonly pretty: boolean;
|
|
53
54
|
readonly chunkSize: number;
|
|
54
55
|
readonly codeSize: number;
|
|
55
|
-
private readonly constReader: DataView;
|
|
56
56
|
/** 读取常量表 */
|
|
57
57
|
private readConsts(): void {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
this.constLits.push(toJsLiteral(constant));
|
|
62
|
-
i += size;
|
|
58
|
+
const { constVals, constLits } = this;
|
|
59
|
+
for (let i = 0, len = constVals.length; i < len; i++) {
|
|
60
|
+
constLits.push(toJsLiteral(constVals[i]));
|
|
63
61
|
}
|
|
64
62
|
}
|
|
65
|
-
readonly constVals: VmPrimitive[]
|
|
63
|
+
readonly constVals: VmPrimitive[];
|
|
66
64
|
readonly constLits: string[] = [];
|
|
67
65
|
|
|
68
66
|
readonly constSize: number;
|
|
@@ -70,6 +68,8 @@ export class Emitter {
|
|
|
70
68
|
private codeOffset = 0;
|
|
71
69
|
private closureCounter = 0;
|
|
72
70
|
private identCounter = 0;
|
|
71
|
+
/** 记录函数声明所在位置 */
|
|
72
|
+
private readonly functions: number[] = [];
|
|
73
73
|
|
|
74
74
|
/** 制造缩进 */
|
|
75
75
|
private ident(len = 0): string {
|
|
@@ -77,10 +77,16 @@ export class Emitter {
|
|
|
77
77
|
return ' '.repeat(this.identCounter + len);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
readonly globals: GlobalMap = new Map();
|
|
81
80
|
/** 读取全局变量 */
|
|
82
|
-
private rg(constIdx: number
|
|
83
|
-
|
|
81
|
+
private rg(constIdx: number): string {
|
|
82
|
+
const constName = this.constVals[constIdx]!;
|
|
83
|
+
let lit;
|
|
84
|
+
if (typeof constName == 'string') {
|
|
85
|
+
lit = this.constLits[constIdx]!;
|
|
86
|
+
} else {
|
|
87
|
+
lit = toJsLiteral(toString(constName, undefined));
|
|
88
|
+
}
|
|
89
|
+
return `global.get(${lit})`;
|
|
84
90
|
}
|
|
85
91
|
|
|
86
92
|
readonly codeLines: string[] = [];
|
|
@@ -327,14 +333,21 @@ export class Emitter {
|
|
|
327
333
|
}
|
|
328
334
|
return `${wv} = null`;
|
|
329
335
|
});
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
336
|
+
let regs = '_';
|
|
337
|
+
for (let i = 1 + argn; i < regn + 1; i++) {
|
|
338
|
+
regs += ',' + this.wv(i, -1);
|
|
339
|
+
}
|
|
333
340
|
const script = startFunc && !varg && argn === 0;
|
|
334
341
|
if (script) {
|
|
335
342
|
code = `${SCRIPT_PREFIX} var ${regs};`;
|
|
336
343
|
} else {
|
|
337
|
-
|
|
344
|
+
if (!this.options.sourceMap) {
|
|
345
|
+
code = `${this.wv(reg)} = Function(null ,(${args.join(', ')}) => { try { CpEnter(); var ${regs};`;
|
|
346
|
+
} else {
|
|
347
|
+
const index = this.functions.length;
|
|
348
|
+
this.functions.push(this.codeLines.length);
|
|
349
|
+
code = `${this.wv(reg)} = Function(fnName_${index} ,(${args.join(', ')}) => { try { CpEnter(); var ${regs};`;
|
|
350
|
+
}
|
|
338
351
|
}
|
|
339
352
|
if (varg) {
|
|
340
353
|
code += ` var ${this.wv(argn, -1)} = Vargs(vargs);`;
|
|
@@ -415,7 +428,7 @@ export class Emitter {
|
|
|
415
428
|
const args = createArray(n, () => read());
|
|
416
429
|
const ns = read();
|
|
417
430
|
const spreads = createArray(ns, () => read());
|
|
418
|
-
const callTarget = opcode === OpCode.Call ? this.rg(func
|
|
431
|
+
const callTarget = opcode === OpCode.Call ? this.rg(func) : this.rv(func);
|
|
419
432
|
code = `${this.wv(reg)} = $Call(${callTarget}, [${args
|
|
420
433
|
.map((a, i) => {
|
|
421
434
|
if (spreads.includes(i)) return `...$ArraySpread(${this.rv(a)})`;
|
|
@@ -520,7 +533,7 @@ export class Emitter {
|
|
|
520
533
|
case OpCode.GetGlobal: {
|
|
521
534
|
reg = read();
|
|
522
535
|
const i = read();
|
|
523
|
-
code = `${this.wv(reg)} = ${this.rg(i
|
|
536
|
+
code = `${this.wv(reg)} = ${this.rg(i)};`;
|
|
524
537
|
break;
|
|
525
538
|
}
|
|
526
539
|
case OpCode.GetGlobalDyn: {
|
|
@@ -705,19 +718,14 @@ export class Emitter {
|
|
|
705
718
|
read(): void {
|
|
706
719
|
this.readConsts();
|
|
707
720
|
this.readCode();
|
|
708
|
-
if (this.globals.size > 0) {
|
|
709
|
-
let globalsInit = '';
|
|
710
|
-
for (const { v } of this.globals.values()) {
|
|
711
|
-
globalsInit += globalsInit ? `, ${v}` : `var ${GLOBAL_HINT} ${v}`;
|
|
712
|
-
}
|
|
713
|
-
this.codeLines[0] += globalsInit + ';';
|
|
714
|
-
}
|
|
715
721
|
this.addSourceMap();
|
|
716
722
|
}
|
|
717
723
|
/** 添加源映射 */
|
|
718
724
|
addSourceMap(): void {
|
|
719
|
-
if (
|
|
720
|
-
|
|
721
|
-
|
|
725
|
+
if (this.options.sourceMap) {
|
|
726
|
+
createSourceMap(this.source, this.sourcemaps, this.codeLines, this.functions, this.options);
|
|
727
|
+
} else {
|
|
728
|
+
this.codeLines.unshift(`'use strict';`);
|
|
729
|
+
}
|
|
722
730
|
}
|
|
723
731
|
}
|