@mirascript/mirascript 0.1.13 → 0.1.15

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.
Files changed (86) hide show
  1. package/dist/chunk-JVFUK7AN.js +2324 -0
  2. package/dist/chunk-JVFUK7AN.js.map +6 -0
  3. package/dist/{chunk-IKSSUVRE.js → chunk-NT235HY3.js} +97 -1264
  4. package/dist/chunk-NT235HY3.js.map +6 -0
  5. package/dist/cli/index.js +8 -7
  6. package/dist/cli/index.js.map +1 -1
  7. package/dist/compiler/emit.d.ts.map +1 -1
  8. package/dist/compiler/worker.js +1 -1
  9. package/dist/helpers/constants.d.ts +5 -0
  10. package/dist/helpers/constants.d.ts.map +1 -1
  11. package/dist/helpers/serialize.d.ts +2 -2
  12. package/dist/helpers/serialize.d.ts.map +1 -1
  13. package/dist/index.js +15 -9
  14. package/dist/subtle.d.ts +1 -1
  15. package/dist/subtle.d.ts.map +1 -1
  16. package/dist/subtle.js +7 -7
  17. package/dist/vm/lib/_helpers.d.ts +8 -8
  18. package/dist/vm/lib/global/debug.d.ts +1 -1
  19. package/dist/vm/lib/global/json.d.ts +2 -2
  20. package/dist/vm/lib/global/json.d.ts.map +1 -1
  21. package/dist/vm/lib/global/mod/matrix.d.ts +1 -1
  22. package/dist/vm/lib/global/mod/matrix.d.ts.map +1 -1
  23. package/dist/vm/lib/global/sequence/all-any.d.ts +2 -2
  24. package/dist/vm/lib/global/sequence/entries.d.ts +4 -4
  25. package/dist/vm/lib/global/sequence/find.d.ts +2 -2
  26. package/dist/vm/lib/global/sequence/repeat.d.ts +1 -1
  27. package/dist/vm/lib/global/sequence/with.d.ts +1 -1
  28. package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
  29. package/dist/vm/lib/global/sequence/zip.d.ts +1 -1
  30. package/dist/vm/operations.d.ts +4 -2
  31. package/dist/vm/operations.d.ts.map +1 -1
  32. package/dist/vm/types/any.d.ts +10 -0
  33. package/dist/vm/types/any.d.ts.map +1 -0
  34. package/dist/vm/types/array.d.ts +12 -0
  35. package/dist/vm/types/array.d.ts.map +1 -0
  36. package/dist/vm/types/callable.d.ts +5 -0
  37. package/dist/vm/types/callable.d.ts.map +1 -0
  38. package/dist/vm/types/const.d.ts +15 -0
  39. package/dist/vm/types/const.d.ts.map +1 -0
  40. package/dist/vm/types/context.d.ts +8 -3
  41. package/dist/vm/types/context.d.ts.map +1 -1
  42. package/dist/vm/types/extern.d.ts +1 -1
  43. package/dist/vm/types/extern.d.ts.map +1 -1
  44. package/dist/vm/types/immutable.d.ts +15 -0
  45. package/dist/vm/types/immutable.d.ts.map +1 -0
  46. package/dist/vm/types/index.d.ts +17 -47
  47. package/dist/vm/types/index.d.ts.map +1 -1
  48. package/dist/vm/types/primitive.d.ts +7 -0
  49. package/dist/vm/types/primitive.d.ts.map +1 -0
  50. package/dist/vm/types/record.d.ts +20 -0
  51. package/dist/vm/types/record.d.ts.map +1 -0
  52. package/dist/vm/types/value.d.ts +14 -0
  53. package/dist/vm/types/value.d.ts.map +1 -0
  54. package/dist/vm/types/wrapper.d.ts +1 -1
  55. package/dist/vm/types/wrapper.d.ts.map +1 -1
  56. package/package.json +2 -2
  57. package/src/compiler/compile-fast.ts +1 -1
  58. package/src/compiler/emit.ts +131 -17
  59. package/src/helpers/constants.ts +6 -1
  60. package/src/helpers/serialize.ts +35 -15
  61. package/src/subtle.ts +1 -1
  62. package/src/vm/lib/_helpers.ts +8 -8
  63. package/src/vm/lib/global/sequence/entries.ts +2 -2
  64. package/src/vm/lib/global/sequence/find.ts +4 -4
  65. package/src/vm/lib/global/sequence/map-filter.ts +3 -3
  66. package/src/vm/lib/global/sequence/with.ts +1 -1
  67. package/src/vm/lib/global/sequence/zip.ts +1 -1
  68. package/src/vm/lib/global/time.ts +3 -3
  69. package/src/vm/operations.ts +7 -7
  70. package/src/vm/types/any.ts +33 -0
  71. package/src/vm/types/array.ts +19 -0
  72. package/src/vm/types/callable.ts +10 -0
  73. package/src/vm/types/{checker.ts → const.ts} +7 -55
  74. package/src/vm/types/context.ts +25 -6
  75. package/src/vm/types/extern.ts +19 -5
  76. package/src/vm/types/immutable.ts +22 -0
  77. package/src/vm/types/index.ts +31 -83
  78. package/src/vm/types/primitive.ts +14 -0
  79. package/src/vm/types/record.ts +53 -0
  80. package/src/vm/types/value.ts +22 -0
  81. package/src/vm/types/wrapper.ts +1 -1
  82. package/dist/chunk-AGIXQM52.js +0 -916
  83. package/dist/chunk-AGIXQM52.js.map +0 -6
  84. package/dist/chunk-IKSSUVRE.js.map +0 -6
  85. package/dist/vm/types/checker.d.ts +0 -30
  86. package/dist/vm/types/checker.d.ts.map +0 -1
@@ -1,39 +1,8 @@
1
- import { isArray } from '../../helpers/utils.js';
2
- import { isVmExtern, VmExtern } from './extern.js';
3
- import { isVmFunction, VmFunction } from './function.js';
4
- import { VmModule, isVmModule } from './module.js';
5
- import { isVmWrapper } from './wrapper.js';
6
-
7
- /** Mirascript 原始值 */
8
- export type VmPrimitive = null | string | number | boolean;
9
- /**
10
- * Mirascript 记录
11
- * 仅拥有且可枚举的字符串键视作存在
12
- * 字段值 `undefined` 和 `null` 均视作 `nil`
13
- */
14
- export type VmRecord = {
15
- readonly [key: string]: VmConst | undefined;
16
- };
17
- /**
18
- * Mirascript 数组
19
- * 数组中的 `undefined`、`null` 及 <empty slot> 均视作 `nil`
20
- */
21
- export type VmArray = ReadonlyArray<VmConst | undefined>;
22
-
23
- /** Mirascript 虚拟机内的值语义值 */
24
- export type VmConst = VmPrimitive | VmRecord | VmArray;
25
-
26
- /** Mirascript 虚拟机内的不可变值 */
27
- export type VmImmutable = VmConst | VmFunction | VmModule;
28
-
29
- /** Mirascript 虚拟机内的合法值 */
30
- export type VmValue = VmImmutable | VmExtern;
31
-
32
- /** Mirascript 虚拟机内的未初始化变量 */
33
- export type VmUninitialized = undefined;
34
-
35
- /** Mirascript 虚拟机内的值(包括未初始化变量) */
36
- export type VmAny = VmValue | VmUninitialized;
1
+ import type { VmArray } from './array.js';
2
+ import type { VmExtern } from './extern.js';
3
+ import type { VmFunction } from './function.js';
4
+ import type { VmModule } from './module.js';
5
+ import type { VmRecord } from './record.js';
37
6
 
38
7
  /** 类型名称 */
39
8
  export type TypeName = keyof VmValueMap;
@@ -60,53 +29,32 @@ export interface VmValueMap {
60
29
  module: VmModule;
61
30
  }
62
31
 
63
- /**
64
- * 检查值是否为 Mirascript 数组
65
- */
66
- export function isVmArray(value: VmAny): value is VmArray {
67
- if (!isArray(value)) return false;
68
- value as VmArray satisfies VmArray;
69
- return true;
70
- }
71
-
72
- /**
73
- * 检查值是否为 Mirascript 记录
74
- */
75
- export function isVmRecord(value: VmAny): value is VmRecord {
76
- if (value == null || typeof value !== 'object') return false;
77
- if (isVmWrapper(value)) return false;
78
- if (isVmArray(value)) return false;
79
- value satisfies VmRecord;
80
- return true;
81
- }
82
-
83
- /**
84
- * 检查值是否为 Mirascript 原始值
85
- */
86
- export function isVmPrimitive(value: unknown): value is VmPrimitive {
87
- if (value === null || typeof value == 'number' || typeof value == 'string' || typeof value == 'boolean') {
88
- value as VmPrimitive satisfies typeof value;
89
- value satisfies VmPrimitive;
90
- return true;
91
- }
92
- return false;
93
- }
94
-
95
- export { VmFunction, isVmFunction, VmExtern, isVmExtern, VmModule, isVmModule, isVmWrapper };
96
32
  export { wrapToVmValue, unwrapFromVmValue, toVmFunctionProxy, fromVmFunctionProxy } from './boundary.js';
97
-
98
- /** 检查值是否为 Mirascript 可调用值 */
99
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
100
- export function isVmCallable(value: unknown): value is VmFunction | VmExtern<Function> {
101
- return isVmFunction(value) || (isVmExtern(value) && typeof value.value == 'function');
102
- }
103
-
104
- export { getVmFunctionInfo, type VmFunctionInfo, type VmFunctionLike, type VmFunctionOption } from './function.js';
105
-
106
33
  export { type VmContext, type VmSharedContext, isVmContext, defineVmContextValue, createVmContext } from './context.js';
107
-
108
34
  export { type VmScript, isVmScript } from './script.js';
109
-
110
- export { isVmAny, isVmConst, isVmImmutable, isVmValue } from './checker.js';
111
-
112
- export const VM_ARRAY_MAX_LENGTH = 2 ** 31 - 1;
35
+ export { isVmCallable } from './callable.js';
36
+
37
+ export { type VmArray, VM_ARRAY_MAX_LENGTH, isVmArray } from './array.js';
38
+ export {
39
+ type VmRecord,
40
+ isVmRecord,
41
+ isVmArrayLikeRecord,
42
+ isVmArrayLikeRecordByEntires,
43
+ isVmArrayLikeRecordByKeys,
44
+ } from './record.js';
45
+ export { type VmPrimitive, isVmPrimitive } from './primitive.js';
46
+ export { type VmConst, isVmConst } from './const.js';
47
+ export { type VmImmutable, isVmImmutable } from './immutable.js';
48
+ export { VmExtern, isVmExtern } from './extern.js';
49
+ export {
50
+ VmFunction,
51
+ isVmFunction,
52
+ getVmFunctionInfo,
53
+ type VmFunctionInfo,
54
+ type VmFunctionLike,
55
+ type VmFunctionOption,
56
+ } from './function.js';
57
+ export { VmModule, isVmModule } from './module.js';
58
+ export { isVmWrapper } from './wrapper.js';
59
+ export { type VmValue, isVmValue } from './value.js';
60
+ export { type VmAny, type VmUninitialized, isVmAny } from './any.js';
@@ -0,0 +1,14 @@
1
+ /** Mirascript 原始值 */
2
+ export type VmPrimitive = null | number | string | boolean;
3
+
4
+ /**
5
+ * 检查值是否为 Mirascript 原始值
6
+ */
7
+ export function isVmPrimitive(value: unknown): value is VmPrimitive {
8
+ if (value === null || typeof value == 'number' || typeof value == 'string' || typeof value == 'boolean') {
9
+ value as VmPrimitive satisfies typeof value;
10
+ value satisfies VmPrimitive;
11
+ return true;
12
+ }
13
+ return false;
14
+ }
@@ -0,0 +1,53 @@
1
+ import { keys } from '../../helpers/utils.js';
2
+ import { isVmArray, VM_ARRAY_MAX_LENGTH } from './array.js';
3
+ import { isVmWrapper, type VmAny, type VmConst } from './index.js';
4
+
5
+ /**
6
+ * Mirascript 记录
7
+ * 仅拥有且可枚举的字符串键视作存在
8
+ * 字段值 `undefined` 和 `null` 均视作 `nil`
9
+ */
10
+ // eslint-disable-next-line @typescript-eslint/consistent-indexed-object-style
11
+ export type VmRecord = {
12
+ readonly [key: string]: VmConst | undefined;
13
+ };
14
+
15
+ /**
16
+ * 检查值是否为 Mirascript 记录
17
+ */
18
+ export function isVmRecord(value: VmAny): value is VmRecord {
19
+ if (value == null || typeof value !== 'object') return false;
20
+ if (isVmWrapper(value)) return false;
21
+ if (isVmArray(value)) return false;
22
+ value satisfies VmRecord;
23
+ return true;
24
+ }
25
+
26
+ /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
27
+ export function isVmArrayLikeRecordByEntires(entries: ReadonlyArray<readonly [string, unknown]>): boolean {
28
+ const { length } = entries;
29
+ if (length === 0) return true;
30
+ if (length > VM_ARRAY_MAX_LENGTH) return false;
31
+ const firstKey = entries[0]![0];
32
+ if (firstKey !== '0') return false;
33
+ const lastKey = entries[length - 1]![0];
34
+ if (lastKey !== String(length - 1)) return false;
35
+ return true;
36
+ }
37
+
38
+ /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
39
+ export function isVmArrayLikeRecordByKeys(keys: readonly string[]): boolean {
40
+ const { length } = keys;
41
+ if (length === 0) return true;
42
+ if (length > VM_ARRAY_MAX_LENGTH) return false;
43
+ const firstKey = keys[0]!;
44
+ if (firstKey !== '0') return false;
45
+ const lastKey = keys[length - 1]!;
46
+ if (lastKey !== String(length - 1)) return false;
47
+ return true;
48
+ }
49
+
50
+ /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
51
+ export function isVmArrayLikeRecord(value: VmRecord): boolean {
52
+ return isVmArrayLikeRecordByKeys(keys(value));
53
+ }
@@ -0,0 +1,22 @@
1
+ import { isVmAny, type VmAny } from './any.js';
2
+ import type { VmExtern } from './extern.js';
3
+ import type { VmImmutable } from './immutable.js';
4
+
5
+ /** Mirascript 虚拟机内的合法值 */
6
+ export type VmValue = VmImmutable | VmExtern;
7
+
8
+ /**
9
+ * 检查是否为 Mirascript 合法值
10
+ */
11
+ export function isVmValue(value: VmAny): value is VmValue;
12
+ /**
13
+ * 检查是否为 Mirascript 合法值
14
+ */
15
+ export function isVmValue(value: unknown, checkDeep: boolean): value is VmValue;
16
+ /**
17
+ * 检查是否为 Mirascript 合法值
18
+ */
19
+ export function isVmValue(value: unknown, checkDeep = false): value is VmValue {
20
+ if (value === undefined) return false;
21
+ return isVmAny(value, checkDeep);
22
+ }
@@ -22,7 +22,7 @@ export abstract class VmWrapper<T extends object> {
22
22
  return undefined;
23
23
  }
24
24
  /** 转为字符串 */
25
- toString(): string {
25
+ toString(useBraces: boolean): string {
26
26
  const { type, describe } = this;
27
27
  if (!describe) return `<${type}>`;
28
28
  return `<${type} ${describe}>`;