@mirascript/mirascript 0.1.76 → 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 (182) hide show
  1. package/dist/{chunk-ZRLBJK6A.js → chunk-BPFOJ4Q6.js} +499 -470
  2. package/dist/chunk-BPFOJ4Q6.js.map +6 -0
  3. package/dist/{chunk-VI74OKFU.js → chunk-LSPCAN32.js} +291 -226
  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/emit/index.d.ts.map +1 -1
  9. package/dist/compiler/emit-script.d.ts.map +1 -1
  10. package/dist/compiler/worker.js +1 -1
  11. package/dist/helpers/convert/{to-boolean.d.ts → boolean.d.ts} +1 -1
  12. package/dist/helpers/convert/boolean.d.ts.map +1 -0
  13. package/dist/helpers/convert/{to-format.d.ts → format.d.ts} +1 -1
  14. package/dist/helpers/convert/format.d.ts.map +1 -0
  15. package/dist/helpers/convert/index.d.ts +4 -4
  16. package/dist/helpers/convert/index.d.ts.map +1 -1
  17. package/dist/helpers/convert/{to-number.d.ts → number.d.ts} +1 -1
  18. package/dist/helpers/convert/number.d.ts.map +1 -0
  19. package/dist/helpers/convert/{to-string.d.ts → string.d.ts} +3 -1
  20. package/dist/helpers/convert/string.d.ts.map +1 -0
  21. package/dist/helpers/error.d.ts +1 -0
  22. package/dist/helpers/error.d.ts.map +1 -1
  23. package/dist/helpers/serialize.d.ts.map +1 -1
  24. package/dist/helpers/types/array-like.d.ts +8 -0
  25. package/dist/helpers/types/array-like.d.ts.map +1 -0
  26. package/dist/helpers/types/basic.d.ts +26 -0
  27. package/dist/helpers/types/basic.d.ts.map +1 -0
  28. package/dist/helpers/types/composed.d.ts +12 -0
  29. package/dist/helpers/types/composed.d.ts.map +1 -0
  30. package/dist/helpers/types/const.d.ts +6 -0
  31. package/dist/helpers/types/const.d.ts.map +1 -0
  32. package/dist/helpers/types/get-type.d.ts +6 -0
  33. package/dist/helpers/types/get-type.d.ts.map +1 -0
  34. package/dist/helpers/types/index.d.ts +6 -0
  35. package/dist/helpers/types/index.d.ts.map +1 -0
  36. package/dist/helpers/types/proto.d.ts +5 -0
  37. package/dist/helpers/types/proto.d.ts.map +1 -0
  38. package/dist/helpers/utils.d.ts +9 -0
  39. package/dist/helpers/utils.d.ts.map +1 -1
  40. package/dist/index.js +3 -3
  41. package/dist/index.js.map +1 -1
  42. package/dist/subtle.js +3 -3
  43. package/dist/vm/lib/global/debug.d.ts.map +1 -1
  44. package/dist/vm/lib/global/json.d.ts +3 -2
  45. package/dist/vm/lib/global/json.d.ts.map +1 -1
  46. package/dist/vm/lib/global/math/tgamma.d.ts.map +1 -1
  47. package/dist/vm/lib/global/sequence/entries.d.ts +1 -1
  48. package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
  49. package/dist/vm/lib/global/sequence/fold.d.ts +3 -0
  50. package/dist/vm/lib/global/sequence/fold.d.ts.map +1 -0
  51. package/dist/vm/lib/global/sequence/group.d.ts +3 -0
  52. package/dist/vm/lib/global/sequence/group.d.ts.map +1 -0
  53. package/dist/vm/lib/global/sequence/index.d.ts +2 -0
  54. package/dist/vm/lib/global/sequence/index.d.ts.map +1 -1
  55. package/dist/vm/lib/global/sequence/new.d.ts.map +1 -1
  56. package/dist/vm/lib/global/sequence/zip.d.ts +2 -2
  57. package/dist/vm/lib/global/sequence/zip.d.ts.map +1 -1
  58. package/dist/vm/lib/helpers.d.ts +2 -2
  59. package/dist/vm/lib/helpers.d.ts.map +1 -1
  60. package/dist/vm/lib/mod/index.d.ts +1 -1
  61. package/dist/vm/lib/mod/index.d.ts.map +1 -1
  62. package/dist/vm/lib/mod/matrix/bin-ops.d.ts +8 -0
  63. package/dist/vm/lib/mod/matrix/bin-ops.d.ts.map +1 -0
  64. package/dist/vm/lib/mod/matrix/fill.d.ts +6 -0
  65. package/dist/vm/lib/mod/matrix/fill.d.ts.map +1 -0
  66. package/dist/vm/lib/mod/matrix/helpers.d.ts +6 -0
  67. package/dist/vm/lib/mod/matrix/helpers.d.ts.map +1 -0
  68. package/dist/vm/lib/mod/matrix/index.d.ts +6 -0
  69. package/dist/vm/lib/mod/matrix/index.d.ts.map +1 -0
  70. package/dist/vm/lib/mod/matrix/invert.d.ts +3 -0
  71. package/dist/vm/lib/mod/matrix/invert.d.ts.map +1 -0
  72. package/dist/vm/lib/mod/matrix/size.d.ts +2 -0
  73. package/dist/vm/lib/mod/matrix/size.d.ts.map +1 -0
  74. package/dist/vm/lib/mod/matrix/transpose.d.ts +2 -0
  75. package/dist/vm/lib/mod/matrix/transpose.d.ts.map +1 -0
  76. package/dist/vm/operations/array-range.d.ts +3 -3
  77. package/dist/vm/operations/array-range.d.ts.map +1 -1
  78. package/dist/vm/operations/call.d.ts +1 -1
  79. package/dist/vm/operations/call.d.ts.map +1 -1
  80. package/dist/vm/operations/compound.d.ts +1 -13
  81. package/dist/vm/operations/compound.d.ts.map +1 -1
  82. package/dist/vm/operations/index.d.ts +3 -0
  83. package/dist/vm/operations/index.d.ts.map +1 -1
  84. package/dist/vm/operations/iterable.d.ts +6 -0
  85. package/dist/vm/operations/iterable.d.ts.map +1 -0
  86. package/dist/vm/operations/record.d.ts +6 -0
  87. package/dist/vm/operations/record.d.ts.map +1 -0
  88. package/dist/vm/operations/slice.d.ts.map +1 -1
  89. package/dist/vm/operations/spread.d.ts +6 -0
  90. package/dist/vm/operations/spread.d.ts.map +1 -0
  91. package/dist/vm/operations/utils.d.ts.map +1 -1
  92. package/dist/vm/types/extern/access.d.ts +5 -0
  93. package/dist/vm/types/extern/access.d.ts.map +1 -0
  94. package/dist/vm/types/{extern.d.ts → extern/index.d.ts} +3 -3
  95. package/dist/vm/types/extern/index.d.ts.map +1 -0
  96. package/dist/vm/types/extern/tag.d.ts +3 -0
  97. package/dist/vm/types/extern/tag.d.ts.map +1 -0
  98. package/dist/vm/types/extern/utils.d.ts +13 -0
  99. package/dist/vm/types/extern/utils.d.ts.map +1 -0
  100. package/dist/vm/types/index.d.ts +3 -3
  101. package/dist/vm/types/index.d.ts.map +1 -1
  102. package/package.json +6 -6
  103. package/src/compiler/compile-fast.ts +1 -1
  104. package/src/compiler/diagnostic.ts +2 -2
  105. package/src/compiler/emit/constants.ts +1 -1
  106. package/src/compiler/emit/consts.ts +0 -1
  107. package/src/compiler/emit/index.ts +1 -7
  108. package/src/compiler/emit/sourcemap.ts +1 -1
  109. package/src/compiler/emit-script.ts +1 -0
  110. package/src/compiler/load-module.ts +5 -1
  111. package/src/helpers/convert/{to-boolean.ts → boolean.ts} +1 -1
  112. package/src/helpers/convert/{to-format.ts → format.ts} +1 -1
  113. package/src/helpers/convert/index.ts +4 -4
  114. package/src/helpers/convert/{to-number.ts → number.ts} +16 -32
  115. package/src/helpers/convert/{to-string.ts → string.ts} +5 -4
  116. package/src/helpers/error.ts +3 -1
  117. package/src/helpers/serialize.ts +45 -44
  118. package/src/helpers/types/array-like.ts +32 -0
  119. package/src/helpers/types/basic.ts +82 -0
  120. package/src/helpers/types/composed.ts +27 -0
  121. package/src/helpers/types/const.ts +44 -0
  122. package/src/helpers/types/get-type.ts +16 -0
  123. package/src/helpers/types/index.ts +5 -0
  124. package/src/helpers/types/proto.ts +21 -0
  125. package/src/helpers/utils.ts +33 -0
  126. package/src/vm/lib/global/debug.ts +4 -8
  127. package/src/vm/lib/global/json.ts +21 -9
  128. package/src/vm/lib/global/math/tgamma.ts +8 -14
  129. package/src/vm/lib/global/sequence/all-any.ts +1 -1
  130. package/src/vm/lib/global/sequence/entries.ts +6 -1
  131. package/src/vm/lib/global/sequence/find.ts +1 -1
  132. package/src/vm/lib/global/sequence/fold.ts +30 -0
  133. package/src/vm/lib/global/sequence/group.ts +37 -0
  134. package/src/vm/lib/global/sequence/index.ts +2 -0
  135. package/src/vm/lib/global/sequence/map-filter.ts +3 -3
  136. package/src/vm/lib/global/sequence/new.ts +9 -3
  137. package/src/vm/lib/global/sequence/sort.ts +1 -1
  138. package/src/vm/lib/global/sequence/unique.ts +1 -1
  139. package/src/vm/lib/global/sequence/with.ts +5 -5
  140. package/src/vm/lib/global/sequence/zip.ts +21 -10
  141. package/src/vm/lib/global/time.ts +1 -1
  142. package/src/vm/lib/helpers.ts +12 -5
  143. package/src/vm/lib/mod/index.ts +1 -1
  144. package/src/vm/lib/mod/matrix/bin-ops.ts +291 -0
  145. package/src/vm/lib/mod/matrix/fill.ts +109 -0
  146. package/src/vm/lib/mod/matrix/helpers.ts +26 -0
  147. package/src/vm/lib/mod/matrix/index.ts +5 -0
  148. package/src/vm/lib/mod/matrix/invert.ts +122 -0
  149. package/src/vm/lib/mod/matrix/size.ts +15 -0
  150. package/src/vm/lib/mod/matrix/transpose.ts +32 -0
  151. package/src/vm/operations/array-range.ts +15 -27
  152. package/src/vm/operations/call.ts +2 -2
  153. package/src/vm/operations/compound.ts +5 -125
  154. package/src/vm/operations/helpers.ts +1 -1
  155. package/src/vm/operations/index.ts +3 -0
  156. package/src/vm/operations/iterable.ts +40 -0
  157. package/src/vm/operations/record.ts +33 -0
  158. package/src/vm/operations/slice.ts +23 -22
  159. package/src/vm/operations/spread.ts +57 -0
  160. package/src/vm/operations/type-check.ts +1 -1
  161. package/src/vm/operations/utils.ts +45 -37
  162. package/src/vm/types/boundary.ts +2 -2
  163. package/src/vm/types/extern/access.ts +24 -0
  164. package/src/vm/types/extern/index.ts +124 -0
  165. package/src/vm/types/extern/tag.ts +58 -0
  166. package/src/vm/types/extern/utils.ts +55 -0
  167. package/src/vm/types/function.ts +1 -1
  168. package/src/vm/types/index.ts +3 -3
  169. package/dist/chunk-VI74OKFU.js.map +0 -6
  170. package/dist/chunk-ZRLBJK6A.js.map +0 -6
  171. package/dist/helpers/convert/to-boolean.d.ts.map +0 -1
  172. package/dist/helpers/convert/to-format.d.ts.map +0 -1
  173. package/dist/helpers/convert/to-number.d.ts.map +0 -1
  174. package/dist/helpers/convert/to-string.d.ts.map +0 -1
  175. package/dist/helpers/types.d.ts +0 -58
  176. package/dist/helpers/types.d.ts.map +0 -1
  177. package/dist/vm/lib/mod/matrix.d.ts +0 -15
  178. package/dist/vm/lib/mod/matrix.d.ts.map +0 -1
  179. package/dist/vm/types/extern.d.ts.map +0 -1
  180. package/src/helpers/types.ts +0 -283
  181. package/src/vm/lib/mod/matrix.ts +0 -590
  182. package/src/vm/types/extern.ts +0 -197
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  DiagnosticCode,
3
- NegativeInfinity,
4
3
  NotNumber,
5
4
  PositiveInfinity,
6
5
  VM_ARRAY_MAX_LENGTH,
@@ -20,6 +19,7 @@ import {
20
19
  fromEntries,
21
20
  getOwnPropertyNames,
22
21
  getPrototypeOf,
22
+ getRecord,
23
23
  getVmType,
24
24
  hasOwn,
25
25
  hasOwnEnumerable,
@@ -48,122 +48,19 @@ import {
48
48
  keys,
49
49
  keysLength,
50
50
  parseDiagnostics,
51
+ setRecord,
52
+ toBoolean,
53
+ toFormat,
54
+ toNumber,
51
55
  toString,
52
56
  values
53
- } from "./chunk-VI74OKFU.js";
57
+ } from "./chunk-LSPCAN32.js";
54
58
 
55
59
  // src/compiler/load-module.ts
56
60
  import { loadModule } from "@mirascript/bindings";
57
- await loadModule();
58
-
59
- // src/helpers/convert/index.ts
60
- var convert_exports = {};
61
- __export(convert_exports, {
62
- toBoolean: () => toBoolean,
63
- toFormat: () => toFormat,
64
- toNumber: () => toNumber,
65
- toString: () => toString
66
- });
67
-
68
- // src/helpers/convert/to-number.ts
69
- function parseNumericLiteral(value) {
70
- if (value === "") return null;
71
- const ch0 = value.charAt(0);
72
- if (ch0 < "0" || ch0 > "9") {
73
- return null;
74
- }
75
- if (/^0[bB][01]+$/.test(value)) {
76
- const num2 = Number.parseInt(value.slice(2), 2);
77
- return isNaN(num2) ? null : num2;
78
- }
79
- if (/^0[oO][0-7]+$/.test(value)) {
80
- const num2 = Number.parseInt(value.slice(2), 8);
81
- return isNaN(num2) ? null : num2;
82
- }
83
- if (/^0[xX][0-9a-fA-F]+$/.test(value)) {
84
- const num2 = Number.parseInt(value.slice(2), 16);
85
- return isNaN(num2) ? null : num2;
86
- }
87
- if (/^[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?$/.test(value)) {
88
- const num2 = Number.parseFloat(value);
89
- return isNaN(num2) ? null : num2;
90
- }
91
- return null;
92
- }
93
- function stringToNumber(value) {
94
- value = value.trim();
95
- if (value === "") return null;
96
- if (value === "inf" || value === "+inf" || value === "Infinity" || value === "+Infinity") {
97
- return PositiveInfinity;
98
- }
99
- if (value === "-inf" || value === "-Infinity") {
100
- return NegativeInfinity;
101
- }
102
- if (value === "nan" || value === "NaN") {
103
- return NotNumber;
104
- }
105
- if (value.startsWith("-")) {
106
- const num2 = parseNumericLiteral(value.slice(1));
107
- if (num2 !== null) return -num2;
108
- return null;
109
- } else if (value.startsWith("+")) {
110
- return parseNumericLiteral(value.slice(1));
111
- } else {
112
- return parseNumericLiteral(value);
113
- }
114
- }
115
- function toNumber(value, fallback) {
116
- if (typeof value === "number") return value;
117
- if (typeof value == "boolean") return value ? 1 : 0;
118
- if (typeof value == "string") {
119
- const num2 = stringToNumber(value);
120
- if (num2 !== null) return num2;
121
- }
122
- if (fallback === void 0) {
123
- throw new VmError(`Failed to convert value to number: ${display(value)}`, NotNumber);
124
- }
125
- return fallback;
126
- }
127
-
128
- // src/helpers/convert/to-format.ts
129
- function formatNumber(finite) {
130
- if (finite === 0) return "0";
131
- const s2 = finite.toString();
132
- let ps;
133
- const abs3 = Math.abs(finite);
134
- if (abs3 >= 1e3 || abs3 < 1e-3) {
135
- const ps1 = finite.toExponential();
136
- const ps2 = finite.toExponential(5);
137
- ps = ps1.length < ps2.length ? ps1 : ps2;
138
- } else {
139
- ps = finite.toPrecision(6);
140
- }
141
- return ps.length < s2.length ? ps : s2;
142
- }
143
- function toFormat(value, format2) {
144
- const f = format2 == null ? "" : format2.trim();
145
- if (typeof value == "number") {
146
- if (!isFinite(value)) {
147
- return toString(value, void 0);
148
- }
149
- if (/^\.\d+$/.test(f)) {
150
- let digits = Math.trunc(Number(f.slice(1)));
151
- if (!(digits <= 100)) digits = 100;
152
- return value.toFixed(digits);
153
- } else {
154
- return formatNumber(value);
155
- }
156
- }
157
- return toString(value, void 0);
158
- }
159
-
160
- // src/helpers/convert/to-boolean.ts
161
- function toBoolean(value, fallback) {
162
- if (typeof value === "boolean") return value;
163
- if (fallback === void 0) {
164
- throw new VmError(`Failed to convert value to boolean: ${display(value)}`, false);
165
- }
166
- return fallback;
61
+ try {
62
+ await loadModule();
63
+ } catch (error) {
167
64
  }
168
65
 
169
66
  // src/vm/types/wrapper.ts
@@ -298,13 +195,11 @@ function unwrapFromVmValue(value, bindThisArg = true) {
298
195
  return bindThisArg ? bindThis(f.value, f.thisArg) : f.value;
299
196
  }
300
197
 
301
- // src/vm/types/extern.ts
198
+ // src/vm/types/extern/tag.ts
302
199
  var ObjectPrototype = Object.prototype;
303
- var ObjectToString = ObjectPrototype.toString;
304
- var FunctionToString = Function.prototype.toString;
305
- var ArrayToString = Array.prototype.toString;
306
- var ArrayMap = Array.prototype.map;
307
- var TypedArrayToString = Uint8Array.prototype.toString;
200
+ function getJsObjectTag(value) {
201
+ return ObjectPrototype.toString.call(value).slice(8, -1);
202
+ }
308
203
  function classNameOf(kls) {
309
204
  const { displayName } = kls;
310
205
  if (typeof displayName === "string" && displayName.trim()) {
@@ -316,6 +211,94 @@ function classNameOf(kls) {
316
211
  }
317
212
  return null;
318
213
  }
214
+ function getTag(value) {
215
+ const tag = getJsObjectTag(value);
216
+ if (tag === "Function") {
217
+ if ("prototype" in value && typeof value.prototype == "object") {
218
+ const className = classNameOf(value);
219
+ if (!className) return `class`;
220
+ return `class ${className}`;
221
+ }
222
+ return `function`;
223
+ }
224
+ if (tag === "AsyncFunction") {
225
+ return `async function`;
226
+ }
227
+ if (tag === "GeneratorFunction") {
228
+ return `function*`;
229
+ }
230
+ if (tag === "AsyncGeneratorFunction") {
231
+ return `async function*`;
232
+ }
233
+ if (tag === "Object") {
234
+ const proto = getPrototypeOf(value);
235
+ if (proto === ObjectPrototype) {
236
+ return "Object";
237
+ }
238
+ if (proto == null) {
239
+ return "Object: null prototype";
240
+ }
241
+ if (typeof proto.constructor === "function") {
242
+ return classNameOf(proto.constructor) ?? "Object";
243
+ }
244
+ }
245
+ return tag;
246
+ }
247
+
248
+ // src/vm/types/extern/utils.ts
249
+ function isArrayLike(value) {
250
+ return isArray(value) || ArrayBuffer.isView(value) && "length" in value;
251
+ }
252
+ function getKeys(value, includeNonEnumerable) {
253
+ if (!includeNonEnumerable) {
254
+ const keys5 = [];
255
+ for (const key in value) {
256
+ keys5.push(key);
257
+ }
258
+ return keys5;
259
+ }
260
+ const keys4 = /* @__PURE__ */ new Set();
261
+ let e2 = value;
262
+ while (e2 != null && (typeof e2 == "object" || typeof e2 == "function")) {
263
+ for (const key of getOwnPropertyNames(e2)) {
264
+ keys4.add(key);
265
+ }
266
+ e2 = getPrototypeOf(e2);
267
+ }
268
+ return Array.from(keys4);
269
+ }
270
+ var ObjectToString = Object.prototype.toString;
271
+ var FunctionToString = Function.prototype.toString;
272
+ var ArrayToString = Array.prototype.toString;
273
+ var TypedArrayToString = Uint8Array.prototype.toString;
274
+ function hasCustomToString(value) {
275
+ const { toString: toString2 } = value;
276
+ if (typeof toString2 != "function") return false;
277
+ if (toString2 === ObjectToString || toString2 === FunctionToString || toString2 === ArrayToString || toString2 === TypedArrayToString)
278
+ return false;
279
+ return true;
280
+ }
281
+
282
+ // src/vm/types/extern/access.ts
283
+ var pFunction = Function.prototype;
284
+ var pArray = Array.prototype;
285
+ var pObject = Object.prototype;
286
+ function canAccessProperty(value, key, read) {
287
+ if (key.startsWith("_")) return false;
288
+ if (typeof value == "function" && (key === "prototype" || key === "arguments" || key === "caller")) return false;
289
+ if (hasOwn(value, key)) return true;
290
+ if (!read) return true;
291
+ if (!(key in value)) return false;
292
+ if (key === "constructor") return false;
293
+ const prop = value[key];
294
+ if (key in pFunction && prop === pFunction[key]) return false;
295
+ if (key in pArray && prop === pArray[key]) return false;
296
+ if (key in pObject && prop === pObject[key]) return false;
297
+ return true;
298
+ }
299
+
300
+ // src/vm/types/extern/index.ts
301
+ var ArrayMap = Array.prototype.map;
319
302
  var VmExtern = class extends VmWrapper {
320
303
  constructor(value, thisArg = null) {
321
304
  super(value);
@@ -326,18 +309,7 @@ var VmExtern = class extends VmWrapper {
326
309
  * This method will be used in {@link get}, {@link set}, {@link has}, and {@link keys} methods
327
310
  */
328
311
  access(key, read) {
329
- if (key.startsWith("_")) return false;
330
- if (typeof this.value == "function" && (key === "prototype" || key === "arguments" || key === "caller"))
331
- return false;
332
- if (hasOwn(this.value, key)) return true;
333
- if (!read) return true;
334
- if (!(key in this.value)) return false;
335
- if (key === "constructor") return false;
336
- const prop = this.value[key];
337
- if (key in Function.prototype && prop === Function.prototype[key]) return false;
338
- if (key in Array.prototype && prop === Array.prototype[key]) return false;
339
- if (key in Object.prototype && prop === Object.prototype[key]) return false;
340
- return true;
312
+ return canAccessProperty(this.value, key, read);
341
313
  }
342
314
  /** 决定是否对属性进行包装 */
343
315
  assumeVmValue(value, key) {
@@ -379,23 +351,8 @@ var VmExtern = class extends VmWrapper {
379
351
  }
380
352
  /** @inheritdoc */
381
353
  keys(includeNonEnumerable = false) {
382
- if (!includeNonEnumerable) {
383
- const keys4 = [];
384
- for (const key in this.value) {
385
- if (this.access(key, true)) keys4.push(key);
386
- }
387
- return keys4;
388
- } else {
389
- const keys4 = /* @__PURE__ */ new Set();
390
- let e2 = this.value;
391
- while (e2 != null && (typeof e2 == "object" || typeof e2 == "function")) {
392
- for (const key of getOwnPropertyNames(e2)) {
393
- keys4.add(key);
394
- }
395
- e2 = getPrototypeOf(e2);
396
- }
397
- return Array.from(keys4).filter((key) => this.access(key, true));
398
- }
354
+ const keys4 = getKeys(this.value, includeNonEnumerable);
355
+ return keys4.filter((key) => this.access(key, true));
399
356
  }
400
357
  /** @inheritdoc */
401
358
  same(other) {
@@ -408,15 +365,14 @@ var VmExtern = class extends VmWrapper {
408
365
  * By default, this method returns true if the wrapped value is an Array or a TypedArray.
409
366
  */
410
367
  isArrayLike() {
411
- return isArray(this.value) || ArrayBuffer.isView(this.value) && "length" in this.value;
368
+ return isArrayLike(this.value);
412
369
  }
413
370
  /** @inheritdoc */
414
371
  toString(useBraces) {
415
- const { toString: toString2 } = this.value;
416
- if (typeof toString2 != "function" || toString2 === ObjectToString || toString2 === FunctionToString) {
417
- return super.toString(useBraces);
372
+ if (hasCustomToString(this.value)) {
373
+ return String(this.value);
418
374
  }
419
- if ((toString2 === ArrayToString || toString2 === TypedArrayToString) && this.isArrayLike()) {
375
+ if (this.isArrayLike()) {
420
376
  const mapped = ArrayMap.call(this.value, (item) => {
421
377
  if (item === void 0) return "";
422
378
  return innerToString(wrapToVmValue(item ?? null, null, null), true);
@@ -425,7 +381,7 @@ var VmExtern = class extends VmWrapper {
425
381
  if (useBraces) return `[${str}]`;
426
382
  return str;
427
383
  }
428
- return String(this.value);
384
+ return super.toString(useBraces);
429
385
  }
430
386
  /** @inheritdoc */
431
387
  get type() {
@@ -433,32 +389,9 @@ var VmExtern = class extends VmWrapper {
433
389
  }
434
390
  /** @inheritdoc */
435
391
  get tag() {
436
- const tag = ObjectToString.call(this.value).slice(8, -1);
392
+ const tag = getTag(this.value);
437
393
  if (this.isArrayLike()) {
438
394
  return `${tag}(${this.value.length})`;
439
- } else if (tag === "Object") {
440
- const proto = getPrototypeOf(this.value);
441
- if (proto === ObjectPrototype) {
442
- return "Object";
443
- }
444
- if (proto == null) {
445
- return "Object: null prototype";
446
- }
447
- if (typeof proto.constructor === "function") {
448
- return classNameOf(proto.constructor) ?? "Object";
449
- }
450
- } else if (tag === "Function" && "prototype" in this.value && typeof this.value.prototype == "object") {
451
- const className = classNameOf(this.value);
452
- if (!className) return `class`;
453
- return `class ${className}`;
454
- } else if (tag === "Function") {
455
- return `function`;
456
- } else if (tag === "AsyncFunction") {
457
- return `async function`;
458
- } else if (tag === "GeneratorFunction") {
459
- return `function*`;
460
- } else if (tag === "AsyncGeneratorFunction") {
461
- return `async function*`;
462
395
  }
463
396
  return tag;
464
397
  }
@@ -888,42 +821,48 @@ var overloadNumberString = (a, b) => {
888
821
  if (typeof a == "string" || typeof b == "string") return false;
889
822
  return true;
890
823
  };
824
+ var isArraySame = (a, b) => {
825
+ const len2 = a.length;
826
+ if (len2 !== b.length) return false;
827
+ for (let i = 0; i < len2; i++) {
828
+ if (!isSame(a[i] ?? null, b[i] ?? null)) {
829
+ return false;
830
+ }
831
+ }
832
+ return true;
833
+ };
834
+ var isRecordSame = (a, b) => {
835
+ const aKeys = keys(a);
836
+ const bKeys = keys(b);
837
+ const len2 = aKeys.length;
838
+ if (len2 !== bKeys.length) return false;
839
+ if (len2 === 0) return true;
840
+ for (let i = 0; i < len2; i++) {
841
+ const key = aKeys[i];
842
+ const av = a[key] ?? null;
843
+ const bv = getRecord(b, key);
844
+ if (bv === void 0) return false;
845
+ if (!isSame(av, bv)) return false;
846
+ }
847
+ return true;
848
+ };
891
849
  var isSame = (a, b) => {
892
850
  if (typeof a == "number" && typeof b == "number") {
893
851
  return a === b || isNaN(a) && isNaN(b);
894
852
  }
895
853
  if (a === b) return true;
896
854
  if (a == null || typeof a != "object" || b == null || typeof b != "object") return false;
897
- if (isVmWrapper(a)) return a.same(b);
898
- if (isVmWrapper(b)) return b.same(a);
899
- if (isVmArray(a) && isVmArray(b)) {
900
- const len2 = a.length;
901
- if (len2 !== b.length) {
902
- return false;
903
- }
904
- for (let i = 0; i < len2; i++) {
905
- if (!isSame(a[i] ?? null, b[i] ?? null)) {
906
- return false;
907
- }
908
- }
909
- return true;
855
+ const aType = getVmType(a);
856
+ const bType = getVmType(b);
857
+ if (aType !== bType) return false;
858
+ if (aType === "array") {
859
+ return isArraySame(a, b);
910
860
  }
911
- if (!isVmArray(a) && !isVmArray(b)) {
912
- const aKeys = keys(a);
913
- const bKeys = keys(b);
914
- const len2 = aKeys.length;
915
- if (len2 !== bKeys.length) return false;
916
- if (len2 === 0) return true;
917
- let i = len2;
918
- while (i--) {
919
- const key = aKeys[i];
920
- if (!hasOwnEnumerable(b, key)) return false;
921
- const av = a[key] ?? null;
922
- const bv = b[key] ?? null;
923
- if (!isSame(av, bv)) return false;
924
- }
925
- return true;
861
+ if (aType === "record") {
862
+ return isRecordSame(a, b);
926
863
  }
864
+ if (isVmWrapper(a)) return a.same(b);
865
+ if (isVmWrapper(b)) return b.same(a);
927
866
  return false;
928
867
  };
929
868
 
@@ -1051,32 +990,32 @@ var $Nsame = (a, b) => {
1051
990
  var { ceil } = Math;
1052
991
  var { slice } = Array.prototype;
1053
992
  var sliceCore = (value, start, end, exclusive) => {
993
+ $AssertInit(value);
994
+ $AssertInit(start);
995
+ $AssertInit(end);
996
+ if (!isVmArray(value)) {
997
+ throw new VmError(`Expected array, got ${display(value)}`, []);
998
+ }
1054
999
  const { length } = value;
1055
- if (isNaN(start)) start = 0;
1056
- else if (start < 0) start = length + start;
1057
- if (isNaN(end)) end = exclusive ? length : length - 1;
1058
- else if (end < 0) end = length + end;
1059
- start = ceil(start);
1060
- if (exclusive || !isSafeInteger(end)) {
1061
- end = ceil(end);
1000
+ let s2 = start != null ? toNumber(start) : 0;
1001
+ let e2 = end != null ? toNumber(end) : length - (exclusive ? 0 : 1);
1002
+ if (isNaN(s2)) s2 = 0;
1003
+ else if (s2 < 0) s2 = length + s2;
1004
+ if (isNaN(e2)) e2 = exclusive ? length : length - 1;
1005
+ else if (e2 < 0) e2 = length + e2;
1006
+ s2 = ceil(s2);
1007
+ if (exclusive || !isSafeInteger(e2)) {
1008
+ e2 = ceil(e2);
1062
1009
  } else {
1063
- end = end + 1;
1010
+ e2 = e2 + 1;
1064
1011
  }
1065
- return slice.call(value, start, end);
1012
+ return slice.call(value, s2, e2);
1066
1013
  };
1067
1014
  var $Slice = (value, start, end) => {
1068
- $AssertInit(value);
1069
- if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
1070
- const s2 = start != null ? $ToNumber(start) : 0;
1071
- const e2 = end != null ? $ToNumber(end) : value.length - 1;
1072
- return sliceCore(value, s2, e2, false);
1015
+ return sliceCore(value, start, end, false);
1073
1016
  };
1074
1017
  var $SliceExclusive = (value, start, end) => {
1075
- $AssertInit(value);
1076
- if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
1077
- const s2 = start != null ? $ToNumber(start) : 0;
1078
- const e2 = end != null ? $ToNumber(end) : value.length;
1079
- return sliceCore(value, s2, e2, true);
1018
+ return sliceCore(value, start, end, true);
1080
1019
  };
1081
1020
 
1082
1021
  // src/vm/operations/helpers.ts
@@ -1112,23 +1051,6 @@ var $GlobalFallback = () => {
1112
1051
  // src/vm/operations/compound.ts
1113
1052
  var { trunc } = Math;
1114
1053
  var { at } = Array.prototype;
1115
- var $In = (value, iterable) => {
1116
- $AssertInit(value);
1117
- $AssertInit(iterable);
1118
- if (iterable == null) return false;
1119
- if (typeof iterable != "object") return false;
1120
- if (isVmArray(iterable)) {
1121
- if (value == null) {
1122
- for (const item of iterable) if (item == null) return true;
1123
- return false;
1124
- }
1125
- if (isVmPrimitive(value)) return iterable.includes(value);
1126
- return iterable.some((item = null) => isSame(item, value));
1127
- }
1128
- const key = toString(value, void 0);
1129
- if (isVmWrapper(iterable)) return iterable.has(key);
1130
- return hasOwnEnumerable(iterable, key);
1131
- };
1132
1054
  var $Length = (value) => {
1133
1055
  $AssertInit(value);
1134
1056
  if (isVmArray(value)) return value.length;
@@ -1136,31 +1058,6 @@ var $Length = (value) => {
1136
1058
  if (isVmWrapper(value)) return value.keys().length;
1137
1059
  throw new VmError(`Value has no length: ${display(value)}`, 0);
1138
1060
  };
1139
- var $Omit = (value, omitted) => {
1140
- $AssertInit(value);
1141
- if (!isVmRecord(value)) return {};
1142
- const result = {};
1143
- const valueKeys = keys(value);
1144
- const omittedSet = new Set(omitted.map($ToString));
1145
- for (const key of valueKeys) {
1146
- if (!omittedSet.has(key)) {
1147
- result[key] = value[key] ?? null;
1148
- }
1149
- }
1150
- return result;
1151
- };
1152
- var $Pick = (value, picked) => {
1153
- $AssertInit(value);
1154
- if (!isVmRecord(value)) return {};
1155
- const result = {};
1156
- for (const key of picked) {
1157
- const k = $ToString(key);
1158
- if (hasOwnEnumerable(value, k)) {
1159
- result[k] = value[k] ?? null;
1160
- }
1161
- }
1162
- return result;
1163
- };
1164
1061
  var $Has = (obj, key) => {
1165
1062
  $AssertInit(obj);
1166
1063
  const pk = $ToString(key);
@@ -1189,8 +1086,7 @@ var $Get = (obj, key) => {
1189
1086
  }
1190
1087
  return obj.get(pk) ?? null;
1191
1088
  }
1192
- if (!hasOwnEnumerable(obj, pk)) return null;
1193
- return $El(obj[pk] ?? null);
1089
+ return $El(getRecord(obj, pk) ?? null);
1194
1090
  };
1195
1091
  var $Set = (obj, key, value) => {
1196
1092
  $AssertInit(obj);
@@ -1199,13 +1095,8 @@ var $Set = (obj, key, value) => {
1199
1095
  if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${display(obj)}`, void 0);
1200
1096
  obj.set(pk, value);
1201
1097
  };
1202
- var $Iterable = (value) => {
1203
- $AssertInit(value);
1204
- if (isVmWrapper(value)) return value.keys();
1205
- if (isVmArray(value)) return value;
1206
- if (value != null && typeof value == "object") return keys(value);
1207
- throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
1208
- };
1098
+
1099
+ // src/vm/operations/spread.ts
1209
1100
  var $RecordSpread = (record) => {
1210
1101
  $AssertInit(record);
1211
1102
  if (record == null || isVmRecord(record)) return record;
@@ -1253,41 +1144,82 @@ var $ArraySpread = (array) => {
1253
1144
  throw new VmError(`Expected array, iterable extern or nil, got ${display(array)}`, []);
1254
1145
  };
1255
1146
 
1256
- // src/vm/operations/array-range.ts
1257
- var assertArrayLength = (len2) => {
1258
- if (len2 > VM_ARRAY_MAX_LENGTH) {
1259
- throw new RangeError(`Array length exceeds maximum limit of ${VM_ARRAY_MAX_LENGTH}`);
1147
+ // src/vm/operations/record.ts
1148
+ var $Omit = (value, omitted) => {
1149
+ $AssertInit(value);
1150
+ if (!isVmRecord(value)) return {};
1151
+ const result = {};
1152
+ const valueKeys = keys(value);
1153
+ const omittedSet = new Set(omitted.map(String));
1154
+ for (const key of valueKeys) {
1155
+ if (!omittedSet.has(key)) {
1156
+ setRecord(result, key, value[key]);
1157
+ }
1260
1158
  }
1159
+ return result;
1261
1160
  };
1262
- var isEmptyRange = (start, end) => {
1263
- return !isFinite(start) || !isFinite(end) || start > end;
1161
+ var $Pick = (value, picked) => {
1162
+ $AssertInit(value);
1163
+ if (!isVmRecord(value)) return {};
1164
+ const result = {};
1165
+ for (const key of picked) {
1166
+ const k = String(key);
1167
+ if (hasOwnEnumerable(value, k)) {
1168
+ setRecord(result, k, value[k]);
1169
+ }
1170
+ }
1171
+ return result;
1264
1172
  };
1265
- var $ArrayRange = (start, end) => {
1266
- const s2 = $ToNumber(start);
1267
- const e2 = $ToNumber(end);
1268
- if (isEmptyRange(s2, e2)) return [];
1269
- const n = Math.floor(e2 - s2 + 1);
1270
- assertArrayLength(n);
1271
- const arr = [];
1272
- arr.length = n;
1273
- for (let i = 0; i < n; i++) {
1274
- arr[i] = s2 + i;
1173
+
1174
+ // src/vm/operations/iterable.ts
1175
+ var $In = (value, iterable) => {
1176
+ $AssertInit(value);
1177
+ $AssertInit(iterable);
1178
+ if (iterable == null) return false;
1179
+ if (typeof iterable != "object") return false;
1180
+ if (isVmArray(iterable)) {
1181
+ if (value == null) {
1182
+ for (const item of iterable) if (item == null) return true;
1183
+ return false;
1184
+ }
1185
+ if (isVmPrimitive(value)) return iterable.includes(value);
1186
+ return iterable.some((item = null) => isSame(item, value));
1275
1187
  }
1276
- return arr;
1188
+ const key = toString(value, void 0);
1189
+ if (isVmWrapper(iterable)) return iterable.has(key);
1190
+ return hasOwnEnumerable(iterable, key);
1277
1191
  };
1278
- var $ArrayRangeExclusive = (start, end) => {
1192
+ var $Iterable = (value) => {
1193
+ $AssertInit(value);
1194
+ if (isVmWrapper(value)) return value.keys();
1195
+ if (isVmArray(value)) return value;
1196
+ if (value != null && typeof value == "object") return keys(value);
1197
+ throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
1198
+ };
1199
+
1200
+ // src/vm/operations/array-range.ts
1201
+ var makeArray = (start, end, exclusive) => {
1279
1202
  const s2 = $ToNumber(start);
1280
1203
  const e2 = $ToNumber(end);
1281
- if (isEmptyRange(s2, e2)) return [];
1282
- const n = Math.ceil(e2 - s2);
1283
- assertArrayLength(n);
1204
+ if (!isFinite(s2) || !isFinite(e2) || s2 > e2) {
1205
+ return [];
1206
+ }
1207
+ const n = exclusive ? Math.ceil(e2 - s2) : Math.floor(e2 - s2 + 1);
1208
+ if (n > VM_ARRAY_MAX_LENGTH) {
1209
+ throw new RangeError(`Array length exceeds maximum limit of ${VM_ARRAY_MAX_LENGTH}`);
1210
+ }
1284
1211
  const arr = [];
1285
- arr.length = n;
1286
1212
  for (let i = 0; i < n; i++) {
1287
1213
  arr[i] = s2 + i;
1288
1214
  }
1289
1215
  return arr;
1290
1216
  };
1217
+ var $ArrayRange = (start, end) => {
1218
+ return makeArray(start, end, false);
1219
+ };
1220
+ var $ArrayRangeExclusive = (start, end) => {
1221
+ return makeArray(start, end, true);
1222
+ };
1291
1223
 
1292
1224
  // src/compiler/create-script.ts
1293
1225
  function wrapScript(source, mode, script) {
@@ -1387,9 +1319,11 @@ __export(global_exports, {
1387
1319
  find: () => find,
1388
1320
  flatten: () => flatten,
1389
1321
  floor: () => floor,
1322
+ fold: () => fold,
1390
1323
  format: () => format,
1391
1324
  from_json: () => from_json,
1392
1325
  gamma: () => gamma,
1326
+ group_by: () => group_by,
1393
1327
  hypot: () => hypot,
1394
1328
  join: () => join,
1395
1329
  keys: () => keys3,
@@ -1398,7 +1332,7 @@ __export(global_exports, {
1398
1332
  log10: () => log10,
1399
1333
  log1p: () => log1p,
1400
1334
  log2: () => log2,
1401
- map: () => map2,
1335
+ map: () => map,
1402
1336
  max: () => max,
1403
1337
  min: () => min2,
1404
1338
  new_array: () => new_array,
@@ -1482,7 +1416,7 @@ function expectNumber(name, value) {
1482
1416
  }
1483
1417
  return v;
1484
1418
  }
1485
- function expectNumberRange(name, value, min3, max2) {
1419
+ function expectNumberRange(name, value, min3, max3) {
1486
1420
  const v = expectNumber(name, value);
1487
1421
  if (!isFinite(v)) {
1488
1422
  throwError(`${describeParam(name)} is not a finite number: ${display(value)}`, NotNumber);
@@ -1490,18 +1424,18 @@ function expectNumberRange(name, value, min3, max2) {
1490
1424
  if (v < min3) {
1491
1425
  throwError(`${describeParam(name)} is less than minimum value ${min3}: ${display(value)}`, min3);
1492
1426
  }
1493
- if (v > max2) {
1494
- throwError(`${describeParam(name)} is greater than maximum value ${max2}: ${display(value)}`, max2);
1427
+ if (v > max3) {
1428
+ throwError(`${describeParam(name)} is greater than maximum value ${max3}: ${display(value)}`, max3);
1495
1429
  }
1496
1430
  return v;
1497
1431
  }
1498
- function expectIntegerRange(name, value, min3, max2) {
1432
+ function expectIntegerRange(name, value, min3, max3) {
1499
1433
  const i = expectInteger(name, value);
1500
1434
  if (i < min3) {
1501
1435
  throwError(`${describeParam(name)} is less than minimum value ${min3}: ${display(value)}`, min3);
1502
1436
  }
1503
- if (i > max2) {
1504
- throwError(`${describeParam(name)} is greater than maximum value ${max2}: ${display(value)}`, max2);
1437
+ if (i > max3) {
1438
+ throwError(`${describeParam(name)} is greater than maximum value ${max3}: ${display(value)}`, max3);
1505
1439
  }
1506
1440
  return i;
1507
1441
  }
@@ -1578,7 +1512,7 @@ function arrayLen(len2) {
1578
1512
  }
1579
1513
  return len2;
1580
1514
  }
1581
- function map(data, mapper) {
1515
+ function iterate(data, mapper) {
1582
1516
  if (isVmPrimitive(data)) {
1583
1517
  return mapper(data, null, data) ?? null;
1584
1518
  }
@@ -2195,7 +2129,7 @@ var withInner = (obj, key, keyIndex, value) => {
2195
2129
  result[index] = withInner(result[index], key, keyIndex + 1, value);
2196
2130
  } else {
2197
2131
  const prop = toString(k, void 0);
2198
- result[prop] = withInner(result[prop], key, keyIndex + 1, value);
2132
+ setRecord(result, prop, withInner(result[prop], key, keyIndex + 1, value));
2199
2133
  }
2200
2134
  return result;
2201
2135
  };
@@ -2256,12 +2190,12 @@ var _with = VmLib(
2256
2190
  if (isVmArray(key)) {
2257
2191
  const firstKey = key[0];
2258
2192
  prop = toString(firstKey, void 0);
2259
- val = withInner(result[prop], key, 1, value);
2193
+ val = withInner(getRecord(result, prop), key, 1, value);
2260
2194
  } else {
2261
2195
  prop = toString(key, void 0);
2262
2196
  val = value;
2263
2197
  }
2264
- result[prop] = val;
2198
+ setRecord(result, prop, val);
2265
2199
  }
2266
2200
  return result;
2267
2201
  }
@@ -2334,8 +2268,13 @@ var entries2 = VmLib(
2334
2268
  arr.push({ 0: i, 1: data[i] ?? null });
2335
2269
  }
2336
2270
  return arr;
2271
+ } else {
2272
+ const arr = [];
2273
+ for (const [key, value] of entries(data)) {
2274
+ arr.push({ 0: key, 1: value ?? null });
2275
+ }
2276
+ return arr;
2337
2277
  }
2338
- return entries(data).map(([key, value]) => ({ 0: key, 1: value ?? null }));
2339
2278
  },
2340
2279
  {
2341
2280
  summary: "返回数组或记录的键值对列表",
@@ -2369,13 +2308,13 @@ var len = VmLib(
2369
2308
  function mapImplWrapped(data, fnName, fn, mapper) {
2370
2309
  expectConst("data", data, null);
2371
2310
  expectCallable(fnName, fn, data);
2372
- return map(data, (value, index, data2) => {
2311
+ return iterate(data, (value, index, data2) => {
2373
2312
  const ret = mapper(fn, value, index, data2);
2374
2313
  if (ret === void 0 || isVmConst(ret)) return ret;
2375
2314
  return null;
2376
2315
  });
2377
2316
  }
2378
- var map2 = VmLib(
2317
+ var map = VmLib(
2379
2318
  (data, f) => mapImplWrapped(data, "f", f, (fn, value, key, data2) => $Call(fn, [value, key, data2])),
2380
2319
  {
2381
2320
  summary: "对数组或记录中的每个元素应用函数,并返回结果",
@@ -2517,14 +2456,24 @@ var zip = VmLib(
2517
2456
  }
2518
2457
  if (length === 0) return [];
2519
2458
  const result = [];
2520
- const isArr = isVmArray(data);
2521
- for (let i = 0; i < length; i++) {
2522
- Cp();
2523
- const obj = isArr ? [] : {};
2524
- for (const { 0: key, 1: arr } of ets) {
2525
- obj[key] = arr[i] ?? null;
2459
+ if (isVmArray(data)) {
2460
+ for (let i = 0; i < length; i++) {
2461
+ Cp();
2462
+ const obj = [];
2463
+ for (const { 0: key, 1: arr } of ets) {
2464
+ obj[key] = arr[i] ?? null;
2465
+ }
2466
+ result.push(obj);
2467
+ }
2468
+ } else {
2469
+ for (let i = 0; i < length; i++) {
2470
+ Cp();
2471
+ const obj = {};
2472
+ for (const { 0: key, 1: arr } of ets) {
2473
+ setRecord(obj, key, arr[i]);
2474
+ }
2475
+ result.push(obj);
2526
2476
  }
2527
- result.push(obj);
2528
2477
  }
2529
2478
  return result;
2530
2479
  },
@@ -2803,8 +2752,8 @@ var repeat = VmLib(
2803
2752
 
2804
2753
  // src/vm/lib/global/sequence/new.ts
2805
2754
  var new_record = VmLib(
2806
- (size2, generator) => {
2807
- const n = expectIntegerRange("size", size2, 0, PositiveInfinity);
2755
+ (size3, generator) => {
2756
+ const n = expectIntegerRange("size", size3, 0, PositiveInfinity);
2808
2757
  expectCallable("generator", generator, null);
2809
2758
  const result = {};
2810
2759
  for (let i = 0; i < n; i++) {
@@ -2812,7 +2761,7 @@ var new_record = VmLib(
2812
2761
  if (entry == null) continue;
2813
2762
  const key = $Get(entry, 0);
2814
2763
  const value = $El($Get(entry, 1));
2815
- result[toString(key)] = value;
2764
+ setRecord(result, toString(key), value);
2816
2765
  }
2817
2766
  return result;
2818
2767
  },
@@ -2850,6 +2799,66 @@ var new_array = VmLib(
2850
2799
  }
2851
2800
  );
2852
2801
 
2802
+ // src/vm/lib/global/sequence/fold.ts
2803
+ var fold = VmLib(
2804
+ (data, initial, f) => {
2805
+ required("initial", initial, null);
2806
+ expectConst("data", data, null);
2807
+ expectCallable("f", f, data);
2808
+ let acc = initial;
2809
+ iterate(data, (value, index, data2) => {
2810
+ acc = $Call(f, [acc, value, index, data2]);
2811
+ });
2812
+ return acc;
2813
+ },
2814
+ {
2815
+ summary: "对数组或记录中的每个元素应用函数,并返回累积结果",
2816
+ params: {
2817
+ data: { type: "array | record", description: "要折叠的数组或记录" },
2818
+ initial: { type: "any", description: "初始累积值" },
2819
+ f: {
2820
+ type: "fn(acc: type(initial), value: any, key: number | string, input: type(data)) -> type(initial)",
2821
+ description: "应用于每个元素的函数"
2822
+ }
2823
+ },
2824
+ returns: { type: "type(initial)" },
2825
+ examples: ["fold([1, 2, 3], 0, fn (acc, x) { acc + x }) // 6"]
2826
+ }
2827
+ );
2828
+
2829
+ // src/vm/lib/global/sequence/group.ts
2830
+ var group_by = VmLib(
2831
+ (data, key) => {
2832
+ expectArray("data", data, null);
2833
+ expectCallable("key", key, data);
2834
+ const result = /* @__PURE__ */ new Map();
2835
+ const len2 = data.length;
2836
+ for (let i = 0; i < len2; i++) {
2837
+ const v = data[i] ?? null;
2838
+ const k = toString($Call(key, [v, i, data]), void 0);
2839
+ let arr = result.get(k);
2840
+ if (!arr) {
2841
+ arr = [];
2842
+ result.set(k, arr);
2843
+ }
2844
+ arr.push(v);
2845
+ }
2846
+ return fromEntries(result);
2847
+ },
2848
+ {
2849
+ summary: "根据指定的键函数对数组进行分组",
2850
+ params: {
2851
+ data: { type: "array", description: "要分组的数组" },
2852
+ key: {
2853
+ type: "fn(value: any, index: number, arr: type(data)) -> string",
2854
+ description: "用于生成分组键的函数"
2855
+ }
2856
+ },
2857
+ returns: { type: "record" },
2858
+ examples: ['group_by([1, 2, 3, 4], fn { it % 2 }) // ("0": [2, 4], "1": [1, 3])']
2859
+ }
2860
+ );
2861
+
2853
2862
  // src/vm/lib/global/debug.ts
2854
2863
  import supportsColor from "supports-color";
2855
2864
  function defaultSerializer(arg, format2) {
@@ -2857,7 +2866,7 @@ function defaultSerializer(arg, format2) {
2857
2866
  }
2858
2867
  function serializeValue(options, arg, format2) {
2859
2868
  const { serializer } = options;
2860
- if (serializer == null || serializer === defaultSerializer) {
2869
+ if (serializer === defaultSerializer || serializer === null) {
2861
2870
  return defaultSerializer(arg, format2);
2862
2871
  }
2863
2872
  try {
@@ -2927,11 +2936,7 @@ var printParser = function(args) {
2927
2936
  templates.push(i < values4.length - 1 ? " " : "");
2928
2937
  }
2929
2938
  }
2930
- return {
2931
- templates,
2932
- values: values4,
2933
- formats
2934
- };
2939
+ return { templates, values: values4, formats };
2935
2940
  };
2936
2941
  var printFormatter = function({
2937
2942
  templates,
@@ -3032,15 +3037,26 @@ var { parse, stringify } = JSON;
3032
3037
  var to_json = VmLib(
3033
3038
  (data) => {
3034
3039
  required("data", data, null);
3035
- if (isVmExtern(data) || isVmModule(data)) {
3036
- try {
3037
- return stringify(data.value) ?? null;
3038
- } catch (ex) {
3039
- rethrowError("Failed to convert extern to JSON", ex, "{}");
3040
- }
3041
- }
3042
3040
  if (typeof data == "function") return null;
3043
- return stringify(data);
3041
+ return stringify(data, (key, value) => {
3042
+ if (typeof value == "function") {
3043
+ return void 0;
3044
+ }
3045
+ if (isVmModule(value)) {
3046
+ return value.value;
3047
+ }
3048
+ if (isVmExtern(value)) {
3049
+ const extern = value.value;
3050
+ if ("toJSON" in extern && typeof extern.toJSON == "function") {
3051
+ return extern.toJSON();
3052
+ }
3053
+ if (typeof extern == "function") {
3054
+ return void 0;
3055
+ }
3056
+ return extern;
3057
+ }
3058
+ return value;
3059
+ });
3044
3060
  },
3045
3061
  {
3046
3062
  summary: "将数据转换为 JSON 字符串",
@@ -3389,7 +3405,7 @@ __export(mod_exports, {
3389
3405
  matrix: () => matrix_exports
3390
3406
  });
3391
3407
 
3392
- // src/vm/lib/mod/matrix.ts
3408
+ // src/vm/lib/mod/matrix/index.ts
3393
3409
  var matrix_exports = {};
3394
3410
  __export(matrix_exports, {
3395
3411
  add: () => add2,
@@ -3401,12 +3417,14 @@ __export(matrix_exports, {
3401
3417
  invert: () => invert,
3402
3418
  multiply: () => multiply,
3403
3419
  ones: () => ones,
3404
- size: () => size,
3420
+ size: () => size2,
3405
3421
  subtract: () => subtract,
3406
3422
  transpose: () => transpose,
3407
3423
  zeros: () => zeros
3408
3424
  });
3409
- function sizeImpl(matrix) {
3425
+
3426
+ // src/vm/lib/mod/matrix/helpers.ts
3427
+ function size(matrix) {
3410
3428
  if (!isVmArray(matrix)) return [];
3411
3429
  if (matrix.length === 0) return [0];
3412
3430
  const numRows = matrix.length;
@@ -3423,46 +3441,12 @@ function sizeImpl(matrix) {
3423
3441
  function num(v) {
3424
3442
  return toNumber(v, void 0);
3425
3443
  }
3426
- var size = VmLib(
3427
- (matrix) => {
3428
- required("matrix", matrix, []);
3429
- return sizeImpl(matrix);
3430
- },
3431
- {
3432
- summary: "获取矩阵尺寸",
3433
- params: { matrix: { type: "any[][]", description: "要获取尺寸的矩阵" } },
3434
- returns: { type: "[number, number]" },
3435
- examples: ["matrix.size([[1, 2], [3, 4]]) // [2, 2]"]
3436
- }
3437
- );
3438
- var transpose = VmLib(
3439
- (matrix) => {
3440
- required("matrix", matrix, []);
3441
- const [numRows, numCols] = sizeImpl(matrix);
3442
- if (numRows == null || numCols == null) return matrix;
3443
- const transposed = [];
3444
- for (let j = 0; j < numCols; j++) {
3445
- Cp();
3446
- const tj = [];
3447
- for (let i = 0; i < numRows; i++) {
3448
- const row = matrix[i] ?? null;
3449
- const item = row?.[j] ?? null;
3450
- tj[i] = item;
3451
- }
3452
- transposed[j] = tj;
3453
- }
3454
- return transposed;
3455
- },
3456
- {
3457
- summary: "转置矩阵",
3458
- params: { matrix: { type: "any[][]", description: "要转置的矩阵" } },
3459
- returns: { type: "any[][]" },
3460
- examples: ["matrix.transpose([[1, 2], [3, 4]]) // [[1, 3], [2, 4]]"]
3461
- }
3462
- );
3444
+
3445
+ // src/vm/lib/mod/matrix/bin-ops.ts
3446
+ var { max: max2 } = Math;
3463
3447
  function entrywiseImpl(a, b, f, vvf, mmf, vmf, mvf) {
3464
- let [ar, ac] = sizeImpl(a);
3465
- let [br, bc] = sizeImpl(b);
3448
+ let [ar, ac] = size(a);
3449
+ let [br, bc] = size(b);
3466
3450
  if (ar == null) {
3467
3451
  if (br == null) {
3468
3452
  return f(a, b);
@@ -3513,7 +3497,7 @@ function entrywiseImpl(a, b, f, vvf, mmf, vmf, mvf) {
3513
3497
  if (vvf != null) {
3514
3498
  return vvf(a, b, ar, br);
3515
3499
  }
3516
- const rr2 = Math.max(ar, br);
3500
+ const rr2 = max2(ar, br);
3517
3501
  const result2 = [];
3518
3502
  for (let r = 0; r < rr2; r++) {
3519
3503
  const aItem = a[r] ?? null;
@@ -3541,8 +3525,8 @@ function entrywiseImpl(a, b, f, vvf, mmf, vmf, mvf) {
3541
3525
  if (mmf != null) {
3542
3526
  return mmf(a, b, ar, ac, br, bc);
3543
3527
  }
3544
- const rr = Math.max(ar, br);
3545
- const rc = Math.max(ac, bc);
3528
+ const rr = max2(ar, br);
3529
+ const rc = max2(ac, bc);
3546
3530
  const result = [];
3547
3531
  for (let r = 0; r < rr; r++) {
3548
3532
  const rRow = [];
@@ -3651,7 +3635,7 @@ var multiply = VmLib(
3651
3635
  b,
3652
3636
  $Mul,
3653
3637
  (a2, b2, al, bl) => {
3654
- const l = Math.max(al, bl);
3638
+ const l = max2(al, bl);
3655
3639
  let s2 = 0;
3656
3640
  for (let i = 0; i < l; i++) {
3657
3641
  s2 += num(a2[i]) * num(b2[i]);
@@ -3710,12 +3694,111 @@ var multiply = VmLib(
3710
3694
  examples: ["matrix.multiply([[1, 2], [3, 4]], [5, 6]) // [17, 39]"]
3711
3695
  }
3712
3696
  );
3697
+
3698
+ // src/vm/lib/mod/matrix/fill.ts
3699
+ function filled(size3, value) {
3700
+ const s2 = getNumbers(size3);
3701
+ if (s2.length === 0) return [];
3702
+ while (s2.length > 0) {
3703
+ const repeat2 = arrayLen(s2.pop());
3704
+ Cp();
3705
+ const data = [];
3706
+ data.length = repeat2;
3707
+ data.fill(value);
3708
+ value = data;
3709
+ }
3710
+ return value;
3711
+ }
3712
+ var zeros = VmLib((...size3) => filled(size3, 0), {
3713
+ summary: "创建一个全零的矩阵",
3714
+ params: { "..size": { type: "number[]", description: "矩阵的维度" } },
3715
+ returns: { type: "number[][]" },
3716
+ examples: ["matrix.zeros(2, 3) // [[0, 0, 0], [0, 0, 0]]"]
3717
+ });
3718
+ var ones = VmLib((...size3) => filled(size3, 1), {
3719
+ summary: "创建一个全一的矩阵",
3720
+ params: { "..size": { type: "number[]", description: "矩阵的维度" } },
3721
+ returns: { type: "number[][]" },
3722
+ examples: ["matrix.ones(2, 2) // [[1, 1], [1, 1]]"]
3723
+ });
3724
+ var identity = VmLib(
3725
+ (...size3) => {
3726
+ let s2 = getNumbers(size3);
3727
+ if (s2.length === 0) return [];
3728
+ if (s2.length > 2) throwError("Invalid matrix size", []);
3729
+ if (s2.length === 1) s2 = [s2[0], s2[0]];
3730
+ const m = arrayLen(s2[0]);
3731
+ const n = arrayLen(s2[1]);
3732
+ const ret = [];
3733
+ for (let i = 0; i < m; i++) {
3734
+ const row = [];
3735
+ ret[i] = row;
3736
+ row.length = n;
3737
+ row.fill(0);
3738
+ if (i < n) row[i] = 1;
3739
+ }
3740
+ return ret;
3741
+ },
3742
+ {
3743
+ summary: "创建一个单位矩阵",
3744
+ params: { "..size": { type: "[number] | [number, number]", description: "矩阵的维度" } },
3745
+ returns: { type: "number[][]" },
3746
+ examples: ["matrix.identity(3) // [[1, 0, 0], [0, 1, 0], [0, 0, 1]]"]
3747
+ }
3748
+ );
3749
+ var diagonal = VmLib(
3750
+ (x, k = 0) => {
3751
+ expectArray("x", x, []);
3752
+ const fk = expectInteger("k", k);
3753
+ if (x.every((e2) => isArray(e2))) {
3754
+ const diag = [];
3755
+ for (let i = 0; i < x.length; i++) {
3756
+ const row = x[i];
3757
+ const r = i + fk;
3758
+ if (r < 0) continue;
3759
+ if (!row || r >= row.length) break;
3760
+ diag.push(row[r] ?? null);
3761
+ }
3762
+ return diag;
3763
+ }
3764
+ const l = x.length;
3765
+ const m = arrayLen(fk < 0 ? l - fk : l);
3766
+ const n = arrayLen(fk > 0 ? l + fk : l);
3767
+ const result = [];
3768
+ for (let i = 0; i < m; i++) {
3769
+ const row = [];
3770
+ result[i] = row;
3771
+ row.length = n;
3772
+ row.fill(0);
3773
+ for (let j = 0; j < n; j++) {
3774
+ if (i + fk === j) {
3775
+ row[j] = x[fk >= 0 ? i : j] ?? null;
3776
+ }
3777
+ }
3778
+ }
3779
+ return result;
3780
+ },
3781
+ {
3782
+ summary: "创建一个对角矩阵或获取矩阵的对角线",
3783
+ params: {
3784
+ x: { type: "number[] | number[][]", description: "对角线元素或要获取对角线的矩阵" },
3785
+ k: { type: "number", description: "对角线偏移量,默认为 0" }
3786
+ },
3787
+ returns: { type: "number[][] | number[]" },
3788
+ examples: [
3789
+ "matrix.diagonal([1, 2, 3]) // [[1, 0, 0], [0, 2, 0], [0, 0, 3]]",
3790
+ "matrix.diagonal([[1, 2], [3, 4]]) // [1, 4]"
3791
+ ]
3792
+ }
3793
+ );
3794
+
3795
+ // src/vm/lib/mod/matrix/invert.ts
3713
3796
  var invert = VmLib(
3714
3797
  (a) => {
3715
3798
  expectConst("a", a, null);
3716
- const [rows, cols] = sizeImpl(a);
3799
+ const [rows, cols] = size(a);
3717
3800
  if (rows == null) return 1 / num(a);
3718
- if (cols == null) return map(a, (v) => 1 / num(v));
3801
+ if (cols == null) return iterate(a, (v) => 1 / num(v));
3719
3802
  if (rows !== cols) throwError(`Matrix must be square`, a);
3720
3803
  const m = a;
3721
3804
  if (rows === 1) {
@@ -3800,99 +3883,46 @@ var invert = VmLib(
3800
3883
  examples: ["matrix.invert([[1, 2], [3, 4]]) // [[-2, 1], [1.5, -0.5]]"]
3801
3884
  }
3802
3885
  );
3803
- function filled(size2, value) {
3804
- const s2 = getNumbers(size2);
3805
- if (s2.length === 0) return [];
3806
- while (s2.length > 0) {
3807
- const repeat2 = arrayLen(s2.pop());
3808
- Cp();
3809
- const data = [];
3810
- data.length = repeat2;
3811
- data.fill(value);
3812
- value = data;
3813
- }
3814
- return value;
3815
- }
3816
- var zeros = VmLib((...size2) => filled(size2, 0), {
3817
- summary: "创建一个全零的矩阵",
3818
- params: { "..size": { type: "number[]", description: "矩阵的维度" } },
3819
- returns: { type: "number[][]" },
3820
- examples: ["matrix.zeros(2, 3) // [[0, 0, 0], [0, 0, 0]]"]
3821
- });
3822
- var ones = VmLib((...size2) => filled(size2, 1), {
3823
- summary: "创建一个全一的矩阵",
3824
- params: { "..size": { type: "number[]", description: "矩阵的维度" } },
3825
- returns: { type: "number[][]" },
3826
- examples: ["matrix.ones(2, 2) // [[1, 1], [1, 1]]"]
3827
- });
3828
- var identity = VmLib(
3829
- (...size2) => {
3830
- let s2 = getNumbers(size2);
3831
- if (s2.length === 0) return [];
3832
- if (s2.length > 2) throwError("Invalid matrix size", []);
3833
- if (s2.length === 1) s2 = [s2[0], s2[0]];
3834
- const m = arrayLen(s2[0]);
3835
- const n = arrayLen(s2[1]);
3836
- const ret = [];
3837
- for (let i = 0; i < m; i++) {
3838
- const row = [];
3839
- ret[i] = row;
3840
- row.length = n;
3841
- row.fill(0);
3842
- if (i < n) row[i] = 1;
3843
- }
3844
- return ret;
3886
+
3887
+ // src/vm/lib/mod/matrix/size.ts
3888
+ var size2 = VmLib(
3889
+ (matrix) => {
3890
+ required("matrix", matrix, []);
3891
+ return size(matrix);
3845
3892
  },
3846
3893
  {
3847
- summary: "创建一个单位矩阵",
3848
- params: { "..size": { type: "[number] | [number, number]", description: "矩阵的维度" } },
3849
- returns: { type: "number[][]" },
3850
- examples: ["matrix.identity(3) // [[1, 0, 0], [0, 1, 0], [0, 0, 1]]"]
3894
+ summary: "获取矩阵尺寸",
3895
+ params: { matrix: { type: "any[][]", description: "要获取尺寸的矩阵" } },
3896
+ returns: { type: "[number, number]" },
3897
+ examples: ["matrix.size([[1, 2], [3, 4]]) // [2, 2]"]
3851
3898
  }
3852
3899
  );
3853
- var diagonal = VmLib(
3854
- (x, k = 0) => {
3855
- expectArray("x", x, []);
3856
- const fk = expectInteger("k", k);
3857
- if (x.every((e2) => isArray(e2))) {
3858
- const diag = [];
3859
- for (let i = 0; i < x.length; i++) {
3860
- const row = x[i];
3861
- const r = i + fk;
3862
- if (r < 0) continue;
3863
- if (!row || r >= row.length) break;
3864
- diag.push(row[r] ?? null);
3865
- }
3866
- return diag;
3867
- }
3868
- const l = x.length;
3869
- const m = arrayLen(fk < 0 ? l - fk : l);
3870
- const n = arrayLen(fk > 0 ? l + fk : l);
3871
- const result = [];
3872
- for (let i = 0; i < m; i++) {
3873
- const row = [];
3874
- result[i] = row;
3875
- row.length = n;
3876
- row.fill(0);
3877
- for (let j = 0; j < n; j++) {
3878
- if (i + fk === j) {
3879
- row[j] = x[fk >= 0 ? i : j] ?? null;
3880
- }
3900
+
3901
+ // src/vm/lib/mod/matrix/transpose.ts
3902
+ var transpose = VmLib(
3903
+ (matrix) => {
3904
+ required("matrix", matrix, []);
3905
+ const [numRows, numCols] = size(matrix);
3906
+ if (numRows == null || numCols == null) return matrix;
3907
+ const m = matrix;
3908
+ const transposed = [];
3909
+ for (let j = 0; j < numCols; j++) {
3910
+ Cp();
3911
+ const tj = [];
3912
+ for (let i = 0; i < numRows; i++) {
3913
+ const row = m[i] ?? null;
3914
+ const item = row?.[j] ?? null;
3915
+ tj[i] = item;
3881
3916
  }
3917
+ transposed[j] = tj;
3882
3918
  }
3883
- return result;
3919
+ return transposed;
3884
3920
  },
3885
3921
  {
3886
- summary: "创建一个对角矩阵或获取矩阵的对角线",
3887
- params: {
3888
- x: { type: "number[] | number[][]", description: "对角线元素或要获取对角线的矩阵" },
3889
- k: { type: "number", description: "对角线偏移量,默认为 0" }
3890
- },
3891
- returns: { type: "number[][] | number[]" },
3892
- examples: [
3893
- "matrix.diagonal([1, 2, 3]) // [[1, 0, 0], [0, 2, 0], [0, 0, 3]]",
3894
- "matrix.diagonal([[1, 2], [3, 4]]) // [1, 4]"
3895
- ]
3922
+ summary: "转置矩阵",
3923
+ params: { matrix: { type: "any[][]", description: "要转置的矩阵" } },
3924
+ returns: { type: "any[][]" },
3925
+ examples: ["matrix.transpose([[1, 2], [3, 4]]) // [[1, 3], [2, 4]]"]
3896
3926
  }
3897
3927
  );
3898
3928
 
@@ -3949,7 +3979,6 @@ for (const [name, value] of entries(mod_exports)) {
3949
3979
  var lib = Object.freeze(Object.assign(create(null), global_exports, mod_exports));
3950
3980
 
3951
3981
  export {
3952
- convert_exports,
3953
3982
  VmExtern,
3954
3983
  wrapToVmValue,
3955
3984
  unwrapFromVmValue,
@@ -3967,4 +3996,4 @@ export {
3967
3996
  emitScript,
3968
3997
  lib
3969
3998
  };
3970
- //# sourceMappingURL=chunk-ZRLBJK6A.js.map
3999
+ //# sourceMappingURL=chunk-BPFOJ4Q6.js.map