@mirascript/mirascript 0.1.78 → 0.1.79

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 (152) hide show
  1. package/dist/{chunk-VNQQF2W7.js → chunk-BPFOJ4Q6.js} +381 -432
  2. package/dist/chunk-BPFOJ4Q6.js.map +6 -0
  3. package/dist/{chunk-BITOQYYQ.js → chunk-LSPCAN32.js} +204 -149
  4. package/dist/chunk-LSPCAN32.js.map +6 -0
  5. package/dist/compiler/emit/constants.d.ts +1 -1
  6. package/dist/compiler/emit/constants.d.ts.map +1 -1
  7. package/dist/compiler/emit/consts.d.ts.map +1 -1
  8. package/dist/compiler/worker.js +1 -1
  9. package/dist/helpers/convert/{to-boolean.d.ts → boolean.d.ts} +1 -1
  10. package/dist/helpers/convert/boolean.d.ts.map +1 -0
  11. package/dist/helpers/convert/{to-format.d.ts → format.d.ts} +1 -1
  12. package/dist/helpers/convert/format.d.ts.map +1 -0
  13. package/dist/helpers/convert/index.d.ts +4 -4
  14. package/dist/helpers/convert/index.d.ts.map +1 -1
  15. package/dist/helpers/convert/{to-number.d.ts → number.d.ts} +1 -1
  16. package/dist/helpers/convert/number.d.ts.map +1 -0
  17. package/dist/helpers/convert/{to-string.d.ts → string.d.ts} +1 -1
  18. package/dist/helpers/convert/string.d.ts.map +1 -0
  19. package/dist/helpers/serialize.d.ts.map +1 -1
  20. package/dist/helpers/types/array-like.d.ts +8 -0
  21. package/dist/helpers/types/array-like.d.ts.map +1 -0
  22. package/dist/helpers/types/basic.d.ts +26 -0
  23. package/dist/helpers/types/basic.d.ts.map +1 -0
  24. package/dist/helpers/types/composed.d.ts +12 -0
  25. package/dist/helpers/types/composed.d.ts.map +1 -0
  26. package/dist/helpers/types/const.d.ts +6 -0
  27. package/dist/helpers/types/const.d.ts.map +1 -0
  28. package/dist/helpers/types/get-type.d.ts +6 -0
  29. package/dist/helpers/types/get-type.d.ts.map +1 -0
  30. package/dist/helpers/types/index.d.ts +6 -0
  31. package/dist/helpers/types/index.d.ts.map +1 -0
  32. package/dist/helpers/types/proto.d.ts +5 -0
  33. package/dist/helpers/types/proto.d.ts.map +1 -0
  34. package/dist/helpers/utils.d.ts.map +1 -1
  35. package/dist/index.js +2 -2
  36. package/dist/subtle.js +3 -3
  37. package/dist/vm/lib/global/json.d.ts +1 -1
  38. package/dist/vm/lib/global/json.d.ts.map +1 -1
  39. package/dist/vm/lib/helpers.d.ts.map +1 -1
  40. package/dist/vm/lib/mod/index.d.ts +1 -1
  41. package/dist/vm/lib/mod/index.d.ts.map +1 -1
  42. package/dist/vm/lib/mod/matrix/bin-ops.d.ts +8 -0
  43. package/dist/vm/lib/mod/matrix/bin-ops.d.ts.map +1 -0
  44. package/dist/vm/lib/mod/matrix/fill.d.ts +6 -0
  45. package/dist/vm/lib/mod/matrix/fill.d.ts.map +1 -0
  46. package/dist/vm/lib/mod/matrix/helpers.d.ts +6 -0
  47. package/dist/vm/lib/mod/matrix/helpers.d.ts.map +1 -0
  48. package/dist/vm/lib/mod/matrix/index.d.ts +6 -0
  49. package/dist/vm/lib/mod/matrix/index.d.ts.map +1 -0
  50. package/dist/vm/lib/mod/matrix/invert.d.ts +3 -0
  51. package/dist/vm/lib/mod/matrix/invert.d.ts.map +1 -0
  52. package/dist/vm/lib/mod/matrix/size.d.ts +2 -0
  53. package/dist/vm/lib/mod/matrix/size.d.ts.map +1 -0
  54. package/dist/vm/lib/mod/matrix/transpose.d.ts +2 -0
  55. package/dist/vm/lib/mod/matrix/transpose.d.ts.map +1 -0
  56. package/dist/vm/operations/array-range.d.ts +3 -3
  57. package/dist/vm/operations/array-range.d.ts.map +1 -1
  58. package/dist/vm/operations/call.d.ts +1 -1
  59. package/dist/vm/operations/call.d.ts.map +1 -1
  60. package/dist/vm/operations/compound.d.ts +1 -13
  61. package/dist/vm/operations/compound.d.ts.map +1 -1
  62. package/dist/vm/operations/index.d.ts +3 -0
  63. package/dist/vm/operations/index.d.ts.map +1 -1
  64. package/dist/vm/operations/iterable.d.ts +6 -0
  65. package/dist/vm/operations/iterable.d.ts.map +1 -0
  66. package/dist/vm/operations/record.d.ts +6 -0
  67. package/dist/vm/operations/record.d.ts.map +1 -0
  68. package/dist/vm/operations/slice.d.ts.map +1 -1
  69. package/dist/vm/operations/spread.d.ts +6 -0
  70. package/dist/vm/operations/spread.d.ts.map +1 -0
  71. package/dist/vm/operations/utils.d.ts.map +1 -1
  72. package/dist/vm/types/extern/access.d.ts +5 -0
  73. package/dist/vm/types/extern/access.d.ts.map +1 -0
  74. package/dist/vm/types/{extern.d.ts → extern/index.d.ts} +3 -3
  75. package/dist/vm/types/extern/index.d.ts.map +1 -0
  76. package/dist/vm/types/extern/tag.d.ts +3 -0
  77. package/dist/vm/types/extern/tag.d.ts.map +1 -0
  78. package/dist/vm/types/extern/utils.d.ts +13 -0
  79. package/dist/vm/types/extern/utils.d.ts.map +1 -0
  80. package/dist/vm/types/index.d.ts +3 -3
  81. package/dist/vm/types/index.d.ts.map +1 -1
  82. package/package.json +4 -4
  83. package/src/compiler/diagnostic.ts +2 -2
  84. package/src/compiler/emit/constants.ts +1 -1
  85. package/src/compiler/emit/consts.ts +0 -1
  86. package/src/compiler/emit/index.ts +1 -1
  87. package/src/compiler/emit/sourcemap.ts +1 -1
  88. package/src/compiler/load-module.ts +5 -1
  89. package/src/helpers/convert/{to-boolean.ts → boolean.ts} +1 -1
  90. package/src/helpers/convert/{to-format.ts → format.ts} +1 -1
  91. package/src/helpers/convert/index.ts +4 -4
  92. package/src/helpers/convert/{to-number.ts → number.ts} +15 -26
  93. package/src/helpers/convert/{to-string.ts → string.ts} +2 -2
  94. package/src/helpers/serialize.ts +42 -36
  95. package/src/helpers/types/array-like.ts +32 -0
  96. package/src/helpers/types/basic.ts +82 -0
  97. package/src/helpers/types/composed.ts +27 -0
  98. package/src/helpers/types/const.ts +44 -0
  99. package/src/helpers/types/get-type.ts +16 -0
  100. package/src/helpers/types/index.ts +5 -0
  101. package/src/helpers/types/proto.ts +21 -0
  102. package/src/helpers/utils.ts +7 -1
  103. package/src/vm/lib/global/sequence/all-any.ts +1 -1
  104. package/src/vm/lib/global/sequence/find.ts +1 -1
  105. package/src/vm/lib/global/sequence/group.ts +1 -1
  106. package/src/vm/lib/global/sequence/map-filter.ts +1 -1
  107. package/src/vm/lib/global/sequence/new.ts +1 -1
  108. package/src/vm/lib/global/sequence/sort.ts +1 -1
  109. package/src/vm/lib/global/sequence/unique.ts +1 -1
  110. package/src/vm/lib/global/sequence/with.ts +1 -1
  111. package/src/vm/lib/global/time.ts +1 -1
  112. package/src/vm/lib/helpers.ts +8 -1
  113. package/src/vm/lib/mod/index.ts +1 -1
  114. package/src/vm/lib/mod/matrix/bin-ops.ts +291 -0
  115. package/src/vm/lib/mod/matrix/fill.ts +109 -0
  116. package/src/vm/lib/mod/matrix/helpers.ts +26 -0
  117. package/src/vm/lib/mod/matrix/index.ts +5 -0
  118. package/src/vm/lib/mod/matrix/invert.ts +122 -0
  119. package/src/vm/lib/mod/matrix/size.ts +15 -0
  120. package/src/vm/lib/mod/matrix/transpose.ts +32 -0
  121. package/src/vm/operations/array-range.ts +15 -27
  122. package/src/vm/operations/call.ts +2 -2
  123. package/src/vm/operations/compound.ts +4 -131
  124. package/src/vm/operations/helpers.ts +1 -1
  125. package/src/vm/operations/index.ts +3 -0
  126. package/src/vm/operations/iterable.ts +40 -0
  127. package/src/vm/operations/record.ts +33 -0
  128. package/src/vm/operations/slice.ts +23 -22
  129. package/src/vm/operations/spread.ts +57 -0
  130. package/src/vm/operations/type-check.ts +1 -1
  131. package/src/vm/operations/utils.ts +45 -37
  132. package/src/vm/types/boundary.ts +2 -2
  133. package/src/vm/types/extern/access.ts +24 -0
  134. package/src/vm/types/extern/index.ts +124 -0
  135. package/src/vm/types/extern/tag.ts +58 -0
  136. package/src/vm/types/extern/utils.ts +55 -0
  137. package/src/vm/types/function.ts +1 -1
  138. package/src/vm/types/index.ts +3 -3
  139. package/dist/chunk-BITOQYYQ.js.map +0 -6
  140. package/dist/chunk-VNQQF2W7.js.map +0 -6
  141. package/dist/helpers/convert/to-boolean.d.ts.map +0 -1
  142. package/dist/helpers/convert/to-format.d.ts.map +0 -1
  143. package/dist/helpers/convert/to-number.d.ts.map +0 -1
  144. package/dist/helpers/convert/to-string.d.ts.map +0 -1
  145. package/dist/helpers/types.d.ts +0 -58
  146. package/dist/helpers/types.d.ts.map +0 -1
  147. package/dist/vm/lib/mod/matrix.d.ts +0 -15
  148. package/dist/vm/lib/mod/matrix.d.ts.map +0 -1
  149. package/dist/vm/types/extern.d.ts.map +0 -1
  150. package/src/helpers/types.ts +0 -283
  151. package/src/vm/lib/mod/matrix.ts +0 -590
  152. package/src/vm/types/extern.ts +0 -197
@@ -1,283 +0,0 @@
1
- import type { VmScript } from '../compiler/index.js';
2
- import type {
3
- VmAny,
4
- VmArray,
5
- VmConst,
6
- VmContext,
7
- VmExtern,
8
- VmFunction,
9
- VmFunctionInfo,
10
- VmFunctionLike,
11
- VmImmutable,
12
- VmModule,
13
- VmPrimitive,
14
- VmRecord,
15
- VmTypeName,
16
- VmValue,
17
- } from '../vm/types/index.js';
18
- import type { VmWrapper } from '../vm/types/wrapper.js';
19
- import {
20
- kVmContext,
21
- kVmExtern,
22
- kVmFunction,
23
- kVmModule,
24
- kVmScript,
25
- kVmWrapper,
26
- VM_ARRAY_MAX_LENGTH,
27
- } from './constants.js';
28
- import { getPrototypeOf, isArray, keys, values } from './utils.js';
29
-
30
- /** 检查是否为 Mirascript 脚本 */
31
- export function isVmScript(value: unknown): value is VmScript {
32
- return typeof value === 'function' && kVmScript in value;
33
- }
34
-
35
- /** 检查是否为执行上下文 */
36
- export function isVmContext(context: unknown): context is VmContext {
37
- return context != null && typeof context == 'object' && kVmContext in context;
38
- }
39
- /** 检查是否为 Mirascript 函数 */
40
- export function isVmFunction<T extends VmFunctionLike>(value: unknown): value is VmFunction<T> {
41
- return typeof value == 'function' && kVmFunction in value;
42
- }
43
- /** 检查是否为 Mirascript 函数,并获取其信息 */
44
- export function getVmFunctionInfo(value: unknown): VmFunctionInfo | undefined {
45
- if (typeof value != 'function') return undefined;
46
- return (value as VmFunction)[kVmFunction];
47
- }
48
- /** 检查值是否为 MiraScript 包装器 */
49
- export function isVmWrapper<T extends object>(value: unknown): value is VmWrapper<T> {
50
- return value != null && typeof value == 'object' && kVmWrapper in value;
51
- }
52
- /** 检查值是否为 Mirascript 模块 */
53
- export function isVmModule<T extends Record<string, VmImmutable>>(value: unknown): value is VmModule<T> {
54
- return value != null && typeof value == 'object' && kVmModule in value;
55
- }
56
- /** 检查值是否为 Mirascript 外部值 */
57
- export function isVmExtern<T extends object>(value: unknown): value is VmExtern<T> {
58
- return value != null && typeof value == 'object' && kVmExtern in value;
59
- }
60
-
61
- /** 检查值是否为 Mirascript 可调用值 */
62
- // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
63
- export function isVmCallable<E extends Function, F extends VmFunctionLike>(
64
- value: unknown,
65
- ): value is VmFunction<F> | VmExtern<E> {
66
- return isVmFunction<F>(value) || (isVmExtern<E>(value) && typeof value.value == 'function');
67
- }
68
-
69
- /** 检查值是否为 Mirascript 原始值 */
70
- export function isVmPrimitive(value: unknown): value is VmPrimitive {
71
- if (value === null || typeof value == 'number' || typeof value == 'string' || typeof value == 'boolean') {
72
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
73
- value as VmPrimitive satisfies typeof value;
74
- value satisfies VmPrimitive;
75
- return true;
76
- }
77
- return false;
78
- }
79
-
80
- /** 检查值是否为 Mirascript 数组 */
81
- export function isVmArray(value: VmAny): value is VmArray {
82
- if (!isArray(value)) return false;
83
- value as VmArray satisfies VmArray;
84
- return true;
85
- }
86
-
87
- /** 检查值是否为 Mirascript 记录 */
88
- export function isVmRecord(value: VmAny): value is VmRecord {
89
- if (value == null || typeof value != 'object') return false;
90
- if (isVmWrapper(value)) return false;
91
- if (isVmArray(value)) return false;
92
- value satisfies VmRecord;
93
- return true;
94
- }
95
-
96
- /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
97
- export function isVmArrayLikeRecordByEntries(entries: ReadonlyArray<readonly [string, unknown]>): boolean {
98
- const { length } = entries;
99
- if (length === 0) return true;
100
- if (length > VM_ARRAY_MAX_LENGTH) return false;
101
- const firstKey = entries[0]![0];
102
- if (firstKey !== '0') return false;
103
- const lastKey = entries[length - 1]![0];
104
- if (lastKey !== String(length - 1)) return false;
105
- return true;
106
- }
107
-
108
- /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
109
- export function isVmArrayLikeRecordByKeys(keys: readonly string[]): boolean {
110
- const { length } = keys;
111
- if (length === 0) return true;
112
- if (length > VM_ARRAY_MAX_LENGTH) return false;
113
- const firstKey = keys[0]!;
114
- if (firstKey !== '0') return false;
115
- const lastKey = keys[length - 1]!;
116
- if (lastKey !== String(length - 1)) return false;
117
- return true;
118
- }
119
-
120
- /** 检查是否为仅包含从 0 开始的连续数字键的 MiraScript 记录 */
121
- export function isVmArrayLikeRecord(value: VmRecord): boolean {
122
- return isVmArrayLikeRecordByKeys(keys(value));
123
- }
124
-
125
- const MAX_DEPTH = 16;
126
- /**
127
- * 检查是否为 Mirascript 数组
128
- */
129
- function isVmArrayDeep(value: readonly unknown[], depth: number): value is VmArray {
130
- // VmArray 应为普通数组
131
- // Array.prototype
132
- const proto1: unknown = getPrototypeOf(value);
133
- if (!isArray(proto1)) return false;
134
- if (!depth) return true;
135
- return value.every((item) => isVmConstInner(item, depth));
136
- }
137
- /**
138
- * 检查是否为 Mirascript 记录
139
- */
140
- function isVmRecordDeep(value: object, depth: number): value is VmRecord {
141
- // VmRecord 应为普通对象或空原型对象
142
- let isRecord;
143
- // Object.prototype
144
- const proto1: unknown = getPrototypeOf(value);
145
- if (proto1 == null) {
146
- isRecord = true;
147
- } else {
148
- // null
149
- const proto2: unknown = getPrototypeOf(proto1);
150
- if (proto2 != null) {
151
- isRecord = false;
152
- } else {
153
- isRecord = 'hasOwnProperty' in value;
154
- }
155
- }
156
- if (!isRecord) return false;
157
- if (!depth) return true;
158
- return values(value).every((value) => isVmConstInner(value, depth));
159
- }
160
- /**
161
- * 检查是否为 Mirascript 值语义值
162
- */
163
- function isVmConstInner(value: unknown, depth: number): value is VmConst {
164
- if (depth++ >= MAX_DEPTH) return false;
165
- switch (typeof value) {
166
- case 'string':
167
- case 'number':
168
- case 'boolean':
169
- case 'undefined': // undefined 在复合类型内部被视为 nil
170
- return true;
171
- case 'object':
172
- if (value == null) return true;
173
- if (isVmWrapper(value)) return false;
174
- if (isArray(value)) {
175
- return isVmArrayDeep(value, depth);
176
- } else {
177
- return isVmRecordDeep(value, depth);
178
- }
179
- case 'function':
180
- case 'bigint':
181
- case 'symbol':
182
- default:
183
- return false; // Other types are not valid
184
- }
185
- }
186
-
187
- /**
188
- * 检查是否为 Mirascript 值语义值
189
- */
190
- export function isVmConst(value: VmAny): value is VmConst;
191
- /**
192
- * 检查是否为 Mirascript 值语义值
193
- */
194
- export function isVmConst(value: unknown, checkDeep: boolean): value is VmConst;
195
- /**
196
- * 检查是否为 Mirascript 值语义值
197
- */
198
- export function isVmConst(value: unknown, checkDeep = false): value is VmConst {
199
- switch (typeof value) {
200
- case 'string':
201
- case 'number':
202
- case 'boolean':
203
- return true;
204
- case 'object':
205
- if (value == null) return true;
206
- if (isVmWrapper(value)) return false;
207
- if (!checkDeep) {
208
- if (isArray(value)) {
209
- return isVmArrayDeep(value, 0);
210
- } else {
211
- return isVmRecordDeep(value, 0);
212
- }
213
- } else {
214
- return isVmConstInner(value, 1);
215
- }
216
- case 'undefined':
217
- case 'function':
218
- case 'bigint':
219
- case 'symbol':
220
- default:
221
- return false; // Other types are not valid
222
- }
223
- }
224
-
225
- /**
226
- * 检查是否为 Mirascript 不可变值
227
- */
228
- export function isVmImmutable(value: VmAny): value is VmImmutable;
229
- /**
230
- * 检查是否为 Mirascript 不可变值
231
- */
232
- export function isVmImmutable(value: unknown, checkDeep: boolean): value is VmImmutable;
233
- /**
234
- * 检查是否为 Mirascript 不可变值
235
- */
236
- export function isVmImmutable(value: unknown, checkDeep = false): value is VmImmutable {
237
- return isVmModule(value) || isVmFunction(value) || isVmConst(value, checkDeep);
238
- }
239
-
240
- /** 检查是否为 Mirascript 值 */
241
- export function isVmAny(value: unknown, checkDeep: boolean): value is VmAny {
242
- switch (typeof value) {
243
- case 'string':
244
- case 'number':
245
- case 'boolean':
246
- case 'undefined':
247
- return true;
248
- case 'object':
249
- if (value == null) return true;
250
- if (isVmWrapper(value)) return true;
251
- return isVmConst(value, checkDeep);
252
- case 'function':
253
- return isVmFunction(value);
254
- case 'bigint':
255
- case 'symbol':
256
- default:
257
- return false; // Other types are not valid
258
- }
259
- }
260
-
261
- /** 检查是否为 Mirascript 合法值 */
262
- export function isVmValue(value: VmAny): value is VmValue;
263
- /** 检查是否为 Mirascript 合法值 */
264
- export function isVmValue(value: unknown, checkDeep: boolean): value is VmValue;
265
- /** 检查是否为 Mirascript 合法值 */
266
- export function isVmValue(value: unknown, checkDeep = false): value is VmValue {
267
- if (value === undefined) return false;
268
- return isVmAny(value, checkDeep);
269
- }
270
-
271
- /** 获取 MiraScript 类型 */
272
- export function getVmType(value: VmValue): VmTypeName;
273
- /** 获取 MiraScript 类型 */
274
- export function getVmType(value: VmAny): VmTypeName | 'uninitialized';
275
- /** 获取 MiraScript 类型 */
276
- export function getVmType(value: VmAny): VmTypeName | 'uninitialized' {
277
- if (value === undefined) return 'uninitialized';
278
- if (value === null) return 'nil';
279
- if (isVmWrapper(value)) return value.type;
280
- if (isVmArray(value)) return 'array';
281
- if (typeof value == 'object') return 'record';
282
- return typeof value as VmTypeName;
283
- }