@mirascript/mirascript 0.1.21 → 0.1.23
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/bench/index.ts +45 -0
- package/dist/{chunk-RY7PYMXX.js → chunk-CHS52AEC.js} +35 -9
- package/dist/chunk-CHS52AEC.js.map +6 -0
- package/dist/{chunk-4T5YE7LC.js → chunk-K7JDJG3G.js} +26 -31
- package/dist/chunk-K7JDJG3G.js.map +6 -0
- package/dist/chunk-X6LYEGOK.js +69 -0
- package/dist/chunk-X6LYEGOK.js.map +6 -0
- package/dist/{chunk-XNGYORPT.js → chunk-XWQWKD67.js} +581 -531
- package/dist/chunk-XWQWKD67.js.map +6 -0
- package/dist/cli/index.js +4 -4
- package/dist/compiler/compile-fast.d.ts.map +1 -1
- package/dist/compiler/create-script.d.ts +6 -2
- package/dist/compiler/create-script.d.ts.map +1 -1
- package/dist/compiler/emit/constants.d.ts +1 -1
- package/dist/compiler/emit/constants.d.ts.map +1 -1
- package/dist/compiler/emit/index.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/analyze.d.ts +8 -0
- package/dist/helpers/analyze.d.ts.map +1 -0
- package/dist/index.js +3 -3
- package/dist/subtle.d.ts +3 -2
- package/dist/subtle.d.ts.map +1 -1
- package/dist/subtle.js +12 -7
- package/dist/vm/operations/call.d.ts +3 -0
- package/dist/vm/operations/call.d.ts.map +1 -0
- package/dist/vm/operations/common.d.ts +3 -0
- package/dist/vm/operations/common.d.ts.map +1 -0
- package/dist/vm/operations/compound.d.ts +12 -0
- package/dist/vm/operations/compound.d.ts.map +1 -0
- package/dist/vm/operations/convert.d.ts +6 -0
- package/dist/vm/operations/convert.d.ts.map +1 -0
- package/dist/vm/operations/cp.d.ts +2 -0
- package/dist/vm/operations/cp.d.ts.map +1 -0
- package/dist/vm/operations/helpers.d.ts +19 -0
- package/dist/vm/operations/helpers.d.ts.map +1 -0
- package/dist/vm/operations/index.d.ts +10 -0
- package/dist/vm/operations/index.d.ts.map +1 -0
- package/dist/vm/operations/operator.d.ts +24 -0
- package/dist/vm/operations/operator.d.ts.map +1 -0
- package/dist/vm/operations/slice.d.ts +4 -0
- package/dist/vm/operations/slice.d.ts.map +1 -0
- package/dist/vm/operations/type-check.d.ts +9 -0
- package/dist/vm/operations/type-check.d.ts.map +1 -0
- package/dist/vm/operations/utils.d.ts +11 -0
- package/dist/vm/operations/utils.d.ts.map +1 -0
- package/dist/vm/types/boundary.d.ts +2 -3
- package/dist/vm/types/boundary.d.ts.map +1 -1
- package/dist/vm/types/context.d.ts +2 -4
- package/dist/vm/types/context.d.ts.map +1 -1
- package/dist/vm/types/extern.d.ts +2 -2
- package/dist/vm/types/extern.d.ts.map +1 -1
- package/dist/vm/types/index.d.ts +1 -1
- package/dist/vm/types/index.d.ts.map +1 -1
- package/package.json +6 -4
- package/src/compiler/compile-fast.ts +32 -12
- package/src/compiler/create-script.ts +19 -5
- package/src/compiler/emit/constants.ts +1 -1
- package/src/compiler/emit/index.ts +18 -25
- package/src/compiler/emit/sourcemap.ts +8 -8
- package/src/helpers/analyze.ts +70 -0
- package/src/subtle.ts +3 -2
- package/src/vm/lib/global/math.ts +2 -2
- package/src/vm/lib/global/sequence/all-any.ts +2 -2
- package/src/vm/lib/global/sequence/find.ts +2 -2
- package/src/vm/lib/global/sequence/map-filter.ts +1 -1
- package/src/vm/lib/global/sequence/sort.ts +1 -1
- package/src/vm/lib/global/sequence/with.ts +2 -2
- package/src/vm/lib/global/sequence/zip.ts +1 -1
- package/src/vm/lib/helpers.ts +1 -1
- package/src/vm/lib/mod/matrix.ts +2 -2
- package/src/vm/operations/call.ts +18 -0
- package/src/vm/operations/common.ts +6 -0
- package/src/vm/operations/compound.ts +148 -0
- package/src/vm/operations/convert.ts +24 -0
- package/src/vm/operations/cp.ts +1 -0
- package/src/vm/{helpers.ts → operations/helpers.ts} +17 -18
- package/src/vm/operations/index.ts +9 -0
- package/src/vm/operations/operator.ts +131 -0
- package/src/vm/operations/slice.ts +41 -0
- package/src/vm/operations/type-check.ts +38 -0
- package/src/vm/operations/utils.ts +66 -0
- package/src/vm/types/boundary.ts +18 -13
- package/src/vm/types/context.ts +72 -38
- package/src/vm/types/extern.ts +5 -4
- package/src/vm/types/index.ts +1 -1
- package/dist/chunk-4T5YE7LC.js.map +0 -6
- package/dist/chunk-RNLB52WP.js +0 -1
- package/dist/chunk-RNLB52WP.js.map +0 -6
- package/dist/chunk-RY7PYMXX.js.map +0 -6
- package/dist/chunk-XNGYORPT.js.map +0 -6
- package/dist/vm/env.d.ts +0 -3
- package/dist/vm/env.d.ts.map +0 -1
- package/dist/vm/helpers.d.ts +0 -20
- package/dist/vm/helpers.d.ts.map +0 -1
- package/dist/vm/operations.d.ts +0 -49
- package/dist/vm/operations.d.ts.map +0 -1
- package/src/vm/env.ts +0 -16
- package/src/vm/operations.ts +0 -412
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
isInteger,
|
|
23
23
|
isNaN,
|
|
24
24
|
isSafeInteger,
|
|
25
|
-
isVmAny,
|
|
26
25
|
isVmArray,
|
|
27
26
|
isVmCallable,
|
|
28
27
|
isVmConst,
|
|
@@ -43,7 +42,7 @@ import {
|
|
|
43
42
|
parseDiagnostics,
|
|
44
43
|
toString,
|
|
45
44
|
values
|
|
46
|
-
} from "./chunk-
|
|
45
|
+
} from "./chunk-K7JDJG3G.js";
|
|
47
46
|
|
|
48
47
|
// src/compiler/load-module.ts
|
|
49
48
|
import { loadModule } from "@mirascript/bindings";
|
|
@@ -128,430 +127,6 @@ function toBoolean(value, fallback) {
|
|
|
128
127
|
return fallback;
|
|
129
128
|
}
|
|
130
129
|
|
|
131
|
-
// src/vm/operations.ts
|
|
132
|
-
var operations_exports = {};
|
|
133
|
-
__export(operations_exports, {
|
|
134
|
-
$Add: () => $Add,
|
|
135
|
-
$Aeq: () => $Aeq,
|
|
136
|
-
$And: () => $And,
|
|
137
|
-
$ArraySpread: () => $ArraySpread,
|
|
138
|
-
$AssertInit: () => $AssertInit,
|
|
139
|
-
$AssertNonNil: () => $AssertNonNil,
|
|
140
|
-
$Call: () => $Call,
|
|
141
|
-
$Concat: () => $Concat,
|
|
142
|
-
$Div: () => $Div,
|
|
143
|
-
$Eq: () => $Eq,
|
|
144
|
-
$Format: () => $Format,
|
|
145
|
-
$Get: () => $Get,
|
|
146
|
-
$Gt: () => $Gt,
|
|
147
|
-
$Gte: () => $Gte,
|
|
148
|
-
$Has: () => $Has,
|
|
149
|
-
$In: () => $In,
|
|
150
|
-
$IsArray: () => $IsArray,
|
|
151
|
-
$IsBoolean: () => $IsBoolean,
|
|
152
|
-
$IsNumber: () => $IsNumber,
|
|
153
|
-
$IsRecord: () => $IsRecord,
|
|
154
|
-
$IsString: () => $IsString,
|
|
155
|
-
$Iterable: () => $Iterable,
|
|
156
|
-
$Length: () => $Length,
|
|
157
|
-
$Lt: () => $Lt,
|
|
158
|
-
$Lte: () => $Lte,
|
|
159
|
-
$Mod: () => $Mod,
|
|
160
|
-
$Mul: () => $Mul,
|
|
161
|
-
$Naeq: () => $Naeq,
|
|
162
|
-
$Neg: () => $Neg,
|
|
163
|
-
$Neq: () => $Neq,
|
|
164
|
-
$Not: () => $Not,
|
|
165
|
-
$Nsame: () => $Nsame,
|
|
166
|
-
$Omit: () => $Omit,
|
|
167
|
-
$Or: () => $Or,
|
|
168
|
-
$Pick: () => $Pick,
|
|
169
|
-
$Pos: () => $Pos,
|
|
170
|
-
$Pow: () => $Pow,
|
|
171
|
-
$RecordSpread: () => $RecordSpread,
|
|
172
|
-
$Same: () => $Same,
|
|
173
|
-
$Set: () => $Set,
|
|
174
|
-
$Slice: () => $Slice,
|
|
175
|
-
$SliceExclusive: () => $SliceExclusive,
|
|
176
|
-
$Sub: () => $Sub,
|
|
177
|
-
$ToBoolean: () => $ToBoolean,
|
|
178
|
-
$ToNumber: () => $ToNumber,
|
|
179
|
-
$ToString: () => $ToString,
|
|
180
|
-
$Type: () => $Type
|
|
181
|
-
});
|
|
182
|
-
var { abs, min, trunc, ceil } = Math;
|
|
183
|
-
var { slice, at } = Array.prototype;
|
|
184
|
-
var isSame = (a, b) => {
|
|
185
|
-
if (typeof a == "number" && typeof b == "number") return a === b || isNaN(a) && isNaN(b);
|
|
186
|
-
if (a === b) return true;
|
|
187
|
-
if (a == null || typeof a != "object" || b == null || typeof b != "object") return false;
|
|
188
|
-
if (isVmWrapper(a)) return a.same(b);
|
|
189
|
-
if (isVmWrapper(b)) return b.same(a);
|
|
190
|
-
if (isVmArray(a) && isVmArray(b)) {
|
|
191
|
-
const len2 = a.length;
|
|
192
|
-
if (len2 !== b.length) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
for (let i = 0; i < len2; i++) {
|
|
196
|
-
if (!isSame(a[i] ?? null, b[i] ?? null)) {
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
return true;
|
|
201
|
-
}
|
|
202
|
-
if (!isVmArray(a) && !isVmArray(b)) {
|
|
203
|
-
const aKeys = keys(a);
|
|
204
|
-
const bKeys = keys(b);
|
|
205
|
-
if (aKeys.length !== bKeys.length) {
|
|
206
|
-
return false;
|
|
207
|
-
}
|
|
208
|
-
for (const key of aKeys) {
|
|
209
|
-
if (!hasOwnEnumerable(b, key)) {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
const av = a[key] ?? null;
|
|
213
|
-
const bv = b[key] ?? null;
|
|
214
|
-
if (!isSame(av, bv)) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
return false;
|
|
221
|
-
};
|
|
222
|
-
var overloadNumberString = (a, b) => {
|
|
223
|
-
if (typeof a == "number" || typeof b == "number") return true;
|
|
224
|
-
if (typeof a == "string" || typeof b == "string") return false;
|
|
225
|
-
return true;
|
|
226
|
-
};
|
|
227
|
-
var $Add = (a, b) => {
|
|
228
|
-
return $ToNumber(a) + $ToNumber(b);
|
|
229
|
-
};
|
|
230
|
-
var $Sub = (a, b) => {
|
|
231
|
-
return $ToNumber(a) - $ToNumber(b);
|
|
232
|
-
};
|
|
233
|
-
var $Mul = (a, b) => {
|
|
234
|
-
return $ToNumber(a) * $ToNumber(b);
|
|
235
|
-
};
|
|
236
|
-
var $Div = (a, b) => {
|
|
237
|
-
return $ToNumber(a) / $ToNumber(b);
|
|
238
|
-
};
|
|
239
|
-
var $Mod = (a, b) => {
|
|
240
|
-
return $ToNumber(a) % $ToNumber(b);
|
|
241
|
-
};
|
|
242
|
-
var $Pow = (a, b) => {
|
|
243
|
-
return $ToNumber(a) ** $ToNumber(b);
|
|
244
|
-
};
|
|
245
|
-
var $And = (a, b) => {
|
|
246
|
-
return $ToBoolean(a) && $ToBoolean(b);
|
|
247
|
-
};
|
|
248
|
-
var $Or = (a, b) => {
|
|
249
|
-
return $ToBoolean(a) || $ToBoolean(b);
|
|
250
|
-
};
|
|
251
|
-
var $Gt = (a, b) => {
|
|
252
|
-
if (overloadNumberString(a, b)) {
|
|
253
|
-
return $ToNumber(a) > $ToNumber(b);
|
|
254
|
-
} else {
|
|
255
|
-
return $ToString(a) > $ToString(b);
|
|
256
|
-
}
|
|
257
|
-
};
|
|
258
|
-
var $Gte = (a, b) => {
|
|
259
|
-
if (overloadNumberString(a, b)) {
|
|
260
|
-
return $ToNumber(a) >= $ToNumber(b);
|
|
261
|
-
} else {
|
|
262
|
-
return $ToString(a) >= $ToString(b);
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
var $Lt = (a, b) => {
|
|
266
|
-
if (overloadNumberString(a, b)) {
|
|
267
|
-
return $ToNumber(a) < $ToNumber(b);
|
|
268
|
-
} else {
|
|
269
|
-
return $ToString(a) < $ToString(b);
|
|
270
|
-
}
|
|
271
|
-
};
|
|
272
|
-
var $Lte = (a, b) => {
|
|
273
|
-
if (overloadNumberString(a, b)) {
|
|
274
|
-
return $ToNumber(a) <= $ToNumber(b);
|
|
275
|
-
} else {
|
|
276
|
-
return $ToString(a) <= $ToString(b);
|
|
277
|
-
}
|
|
278
|
-
};
|
|
279
|
-
var $Eq = (a, b) => {
|
|
280
|
-
$AssertInit(a);
|
|
281
|
-
$AssertInit(b);
|
|
282
|
-
if (typeof a == "number" && typeof b == "number") return a === b;
|
|
283
|
-
return isSame(a, b);
|
|
284
|
-
};
|
|
285
|
-
var $Neq = (a, b) => {
|
|
286
|
-
return !$Eq(a, b);
|
|
287
|
-
};
|
|
288
|
-
var $Aeq = (a, b) => {
|
|
289
|
-
if (overloadNumberString(a, b)) {
|
|
290
|
-
const an = $ToNumber(a);
|
|
291
|
-
const bn = $ToNumber(b);
|
|
292
|
-
const EPS = 1e-15;
|
|
293
|
-
if (isNaN(an) || isNaN(bn)) return false;
|
|
294
|
-
if (an === bn) return true;
|
|
295
|
-
const absoluteDifference = abs(an - bn);
|
|
296
|
-
if (absoluteDifference < EPS) return true;
|
|
297
|
-
const base = min(abs(an), abs(bn));
|
|
298
|
-
return absoluteDifference < base * EPS;
|
|
299
|
-
} else {
|
|
300
|
-
const as = $ToString(a);
|
|
301
|
-
const bs = $ToString(b);
|
|
302
|
-
if (as === bs) return true;
|
|
303
|
-
const ai = as.toLowerCase();
|
|
304
|
-
const bi = bs.toLowerCase();
|
|
305
|
-
if (ai === bi) return true;
|
|
306
|
-
const an = ai.normalize("NFC");
|
|
307
|
-
const bn = bi.normalize("NFC");
|
|
308
|
-
return an === bn;
|
|
309
|
-
}
|
|
310
|
-
};
|
|
311
|
-
var $Naeq = (a, b) => {
|
|
312
|
-
return !$Aeq(a, b);
|
|
313
|
-
};
|
|
314
|
-
var $Same = (a, b) => {
|
|
315
|
-
$AssertInit(a);
|
|
316
|
-
$AssertInit(b);
|
|
317
|
-
return isSame(a, b);
|
|
318
|
-
};
|
|
319
|
-
var $Nsame = (a, b) => {
|
|
320
|
-
return !$Same(a, b);
|
|
321
|
-
};
|
|
322
|
-
var $In = (value, iterable) => {
|
|
323
|
-
$AssertInit(value);
|
|
324
|
-
$AssertInit(iterable);
|
|
325
|
-
if (iterable == null) return false;
|
|
326
|
-
if (typeof iterable != "object") return false;
|
|
327
|
-
if (isVmArray(iterable)) {
|
|
328
|
-
if (value == null) {
|
|
329
|
-
for (const item of iterable) if (item == null) return true;
|
|
330
|
-
return false;
|
|
331
|
-
}
|
|
332
|
-
if (isVmPrimitive(value)) return iterable.includes(value);
|
|
333
|
-
return iterable.some((item = null) => isSame(item, value));
|
|
334
|
-
}
|
|
335
|
-
const key = toString(value, void 0);
|
|
336
|
-
if (isVmWrapper(iterable)) return iterable.has(key);
|
|
337
|
-
return hasOwnEnumerable(iterable, key);
|
|
338
|
-
};
|
|
339
|
-
var $Concat = (...args) => {
|
|
340
|
-
return args.map((a) => toFormat(a, null)).join("");
|
|
341
|
-
};
|
|
342
|
-
var $Pos = (a) => {
|
|
343
|
-
return $ToNumber(a);
|
|
344
|
-
};
|
|
345
|
-
var $Neg = (a) => {
|
|
346
|
-
return -$ToNumber(a);
|
|
347
|
-
};
|
|
348
|
-
var $Not = (a) => {
|
|
349
|
-
return !$ToBoolean(a);
|
|
350
|
-
};
|
|
351
|
-
var $Length = (value) => {
|
|
352
|
-
$AssertInit(value);
|
|
353
|
-
if (isVmArray(value)) return value.length;
|
|
354
|
-
if (isVmRecord(value)) return keys(value).length;
|
|
355
|
-
if (isVmWrapper(value)) return value.keys().length;
|
|
356
|
-
throw new VmError(`Value has no length: ${display(value)}`, 0);
|
|
357
|
-
};
|
|
358
|
-
var $Omit = (value, omitted) => {
|
|
359
|
-
$AssertInit(value);
|
|
360
|
-
if (value == null || !isVmRecord(value)) return {};
|
|
361
|
-
const result = {};
|
|
362
|
-
const valueKeys = keys(value);
|
|
363
|
-
const omittedSet = new Set(omitted.map($ToString));
|
|
364
|
-
for (const key of valueKeys) {
|
|
365
|
-
if (!omittedSet.has(key)) {
|
|
366
|
-
result[key] = value[key] ?? null;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
return result;
|
|
370
|
-
};
|
|
371
|
-
var $Pick = (value, picked) => {
|
|
372
|
-
$AssertInit(value);
|
|
373
|
-
if (value == null || !isVmRecord(value)) return {};
|
|
374
|
-
const result = {};
|
|
375
|
-
for (const key of picked) {
|
|
376
|
-
const k = $ToString(key);
|
|
377
|
-
if (hasOwnEnumerable(value, k)) {
|
|
378
|
-
result[k] = value[k] ?? null;
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
return result;
|
|
382
|
-
};
|
|
383
|
-
var sliceCore = (value, start, end, exclusive) => {
|
|
384
|
-
const { length } = value;
|
|
385
|
-
if (isNaN(start)) start = 0;
|
|
386
|
-
else if (start < 0) start = length + start;
|
|
387
|
-
if (isNaN(end)) end = exclusive ? length : length - 1;
|
|
388
|
-
else if (end < 0) end = length + end;
|
|
389
|
-
start = ceil(start);
|
|
390
|
-
if (exclusive || !isSafeInteger(end)) {
|
|
391
|
-
end = ceil(end);
|
|
392
|
-
} else {
|
|
393
|
-
end = end + 1;
|
|
394
|
-
}
|
|
395
|
-
return slice.call(value, start, end);
|
|
396
|
-
};
|
|
397
|
-
var $Slice = (value, start, end) => {
|
|
398
|
-
$AssertInit(value);
|
|
399
|
-
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
400
|
-
const s = start != null ? $ToNumber(start) : 0;
|
|
401
|
-
const e = end != null ? $ToNumber(end) : value.length - 1;
|
|
402
|
-
return sliceCore(value, s, e, false);
|
|
403
|
-
};
|
|
404
|
-
var $SliceExclusive = (value, start, end) => {
|
|
405
|
-
$AssertInit(value);
|
|
406
|
-
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
407
|
-
const s = start != null ? $ToNumber(start) : 0;
|
|
408
|
-
const e = end != null ? $ToNumber(end) : value.length;
|
|
409
|
-
return sliceCore(value, s, e, true);
|
|
410
|
-
};
|
|
411
|
-
var $AssertInit = (value) => {
|
|
412
|
-
if (value === void 0) throw new VmError(`Uninitialized value`, null);
|
|
413
|
-
};
|
|
414
|
-
var $Call = (func, args) => {
|
|
415
|
-
for (const a of args) {
|
|
416
|
-
$AssertInit(a);
|
|
417
|
-
}
|
|
418
|
-
if (isVmExtern(func)) {
|
|
419
|
-
return func.call(args) ?? null;
|
|
420
|
-
}
|
|
421
|
-
if (isVmFunction(func)) {
|
|
422
|
-
return func(...args) ?? null;
|
|
423
|
-
}
|
|
424
|
-
throw new VmError(`Value is not callable: ${display(func)}`, null);
|
|
425
|
-
};
|
|
426
|
-
var $Type = (value) => {
|
|
427
|
-
if (value == null) return "nil";
|
|
428
|
-
if (isVmWrapper(value)) return value.type;
|
|
429
|
-
if (isVmArray(value)) return "array";
|
|
430
|
-
if (typeof value == "object") return "record";
|
|
431
|
-
return typeof value;
|
|
432
|
-
};
|
|
433
|
-
var $ToBoolean = (value) => {
|
|
434
|
-
if (typeof value == "boolean") return value;
|
|
435
|
-
$AssertInit(value);
|
|
436
|
-
return toBoolean(value, void 0);
|
|
437
|
-
};
|
|
438
|
-
var $ToString = (value) => {
|
|
439
|
-
if (typeof value == "string") return value;
|
|
440
|
-
$AssertInit(value);
|
|
441
|
-
return toString(value, void 0);
|
|
442
|
-
};
|
|
443
|
-
var $ToNumber = (value) => {
|
|
444
|
-
if (typeof value == "number") return value;
|
|
445
|
-
$AssertInit(value);
|
|
446
|
-
return toNumber(value, void 0);
|
|
447
|
-
};
|
|
448
|
-
var $IsBoolean = (value) => {
|
|
449
|
-
$AssertInit(value);
|
|
450
|
-
return typeof value == "boolean";
|
|
451
|
-
};
|
|
452
|
-
var $IsNumber = (value) => {
|
|
453
|
-
$AssertInit(value);
|
|
454
|
-
return typeof value == "number";
|
|
455
|
-
};
|
|
456
|
-
var $IsString = (value) => {
|
|
457
|
-
$AssertInit(value);
|
|
458
|
-
return typeof value == "string";
|
|
459
|
-
};
|
|
460
|
-
var $IsRecord = (value) => {
|
|
461
|
-
$AssertInit(value);
|
|
462
|
-
return isVmRecord(value);
|
|
463
|
-
};
|
|
464
|
-
var $IsArray = (value) => {
|
|
465
|
-
$AssertInit(value);
|
|
466
|
-
return isVmArray(value);
|
|
467
|
-
};
|
|
468
|
-
var $AssertNonNil = (value) => {
|
|
469
|
-
$AssertInit(value);
|
|
470
|
-
if (value !== null) return;
|
|
471
|
-
throw new VmError(`Expected non-nil value`, null);
|
|
472
|
-
};
|
|
473
|
-
var $Has = (obj, key) => {
|
|
474
|
-
$AssertInit(obj);
|
|
475
|
-
const pk = $ToString(key);
|
|
476
|
-
if (obj == null || typeof obj != "object") return false;
|
|
477
|
-
if (isVmWrapper(obj)) return obj.has(pk);
|
|
478
|
-
return hasOwnEnumerable(obj, pk);
|
|
479
|
-
};
|
|
480
|
-
var $Get = (obj, key) => {
|
|
481
|
-
$AssertInit(obj);
|
|
482
|
-
if (isVmArray(obj)) {
|
|
483
|
-
const index = $ToNumber(key);
|
|
484
|
-
if (isNaN(index)) return null;
|
|
485
|
-
return at.call(obj, trunc(index)) ?? null;
|
|
486
|
-
}
|
|
487
|
-
const pk = $ToString(key);
|
|
488
|
-
if (obj == null || typeof obj != "object") return null;
|
|
489
|
-
if (isVmWrapper(obj)) return obj.get(pk) ?? null;
|
|
490
|
-
if (!hasOwnEnumerable(obj, pk)) return null;
|
|
491
|
-
return obj[pk] ?? null;
|
|
492
|
-
};
|
|
493
|
-
var $Set = (obj, key, value) => {
|
|
494
|
-
$AssertInit(obj);
|
|
495
|
-
$AssertInit(value);
|
|
496
|
-
const pk = $ToString(key);
|
|
497
|
-
if (obj == null) return;
|
|
498
|
-
if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${display(obj)}`, void 0);
|
|
499
|
-
obj.set(pk, value);
|
|
500
|
-
};
|
|
501
|
-
var $Iterable = (value) => {
|
|
502
|
-
$AssertInit(value);
|
|
503
|
-
if (isVmWrapper(value)) return value.keys();
|
|
504
|
-
if (isVmArray(value)) return value;
|
|
505
|
-
if (value != null && typeof value == "object") return keys(value);
|
|
506
|
-
throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
|
|
507
|
-
};
|
|
508
|
-
var $RecordSpread = (record) => {
|
|
509
|
-
$AssertInit(record);
|
|
510
|
-
if (record == null || isVmRecord(record)) return record;
|
|
511
|
-
if (isVmArray(record)) {
|
|
512
|
-
const result = {};
|
|
513
|
-
const len2 = record.length;
|
|
514
|
-
for (let i = 0; i < len2; i++) {
|
|
515
|
-
const item = record[i];
|
|
516
|
-
result[i] = item ?? null;
|
|
517
|
-
}
|
|
518
|
-
return result;
|
|
519
|
-
}
|
|
520
|
-
if (isVmExtern(record)) {
|
|
521
|
-
const result = create(null);
|
|
522
|
-
for (const key of record.keys()) {
|
|
523
|
-
const value = record.get(key) ?? null;
|
|
524
|
-
if (isVmPrimitive(value)) {
|
|
525
|
-
result[key] = value;
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
return result;
|
|
529
|
-
}
|
|
530
|
-
throw new VmError(`Expected record, array, extern or nil, got ${display(record)}`, null);
|
|
531
|
-
};
|
|
532
|
-
var $ArraySpread = (array) => {
|
|
533
|
-
$AssertInit(array);
|
|
534
|
-
if (array == null) return [];
|
|
535
|
-
if (isVmArray(array)) return array;
|
|
536
|
-
if (isVmExtern(array) && typeof array.value[Symbol.iterator] == "function") {
|
|
537
|
-
const result = [];
|
|
538
|
-
for (const item of array.value) {
|
|
539
|
-
if (isVmPrimitive(item)) {
|
|
540
|
-
result.push(item);
|
|
541
|
-
} else {
|
|
542
|
-
result.push(null);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
return result;
|
|
546
|
-
}
|
|
547
|
-
throw new VmError(`Expected array, iterable extern or nil, got ${display(array)}`, []);
|
|
548
|
-
};
|
|
549
|
-
var $Format = (value, format2) => {
|
|
550
|
-
$AssertInit(value);
|
|
551
|
-
const f = format2 == null ? "" : $ToString(format2);
|
|
552
|
-
return toFormat(value, f);
|
|
553
|
-
};
|
|
554
|
-
|
|
555
130
|
// src/vm/types/wrapper.ts
|
|
556
131
|
var VmWrapper = class {
|
|
557
132
|
constructor(value) {
|
|
@@ -574,6 +149,25 @@ var VmWrapper = class {
|
|
|
574
149
|
};
|
|
575
150
|
Object.defineProperty(VmWrapper.prototype, kVmWrapper, { value: true });
|
|
576
151
|
|
|
152
|
+
// src/vm/operations/common.ts
|
|
153
|
+
var $AssertInit = (value) => {
|
|
154
|
+
if (value === void 0) throw new VmError(`Uninitialized value`, null);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// src/vm/operations/call.ts
|
|
158
|
+
var $Call = (func, args) => {
|
|
159
|
+
for (const a of args) {
|
|
160
|
+
$AssertInit(a);
|
|
161
|
+
}
|
|
162
|
+
if (isVmExtern(func)) {
|
|
163
|
+
return func.call(args) ?? null;
|
|
164
|
+
}
|
|
165
|
+
if (isVmFunction(func)) {
|
|
166
|
+
return func(...args) ?? null;
|
|
167
|
+
}
|
|
168
|
+
throw new VmError(`Value is not callable: ${display(func)}`, null);
|
|
169
|
+
};
|
|
170
|
+
|
|
577
171
|
// src/vm/types/boundary.ts
|
|
578
172
|
function toVmFunctionProxy(fn) {
|
|
579
173
|
const cached = fn[kVmFunctionProxy];
|
|
@@ -582,7 +176,7 @@ function toVmFunctionProxy(fn) {
|
|
|
582
176
|
const ret = $Call(
|
|
583
177
|
fn,
|
|
584
178
|
// 作为函数参数传入的值一定丢失了它的 this
|
|
585
|
-
args.map((v) => wrapToVmValue(v, null))
|
|
179
|
+
args.map((v) => wrapToVmValue(v, null, null))
|
|
586
180
|
);
|
|
587
181
|
return unwrapFromVmValue(ret);
|
|
588
182
|
};
|
|
@@ -598,14 +192,14 @@ function fromVmFunctionProxy(fn) {
|
|
|
598
192
|
if (isVmFunction(fn)) return fn;
|
|
599
193
|
const original = fn[kVmFunctionProxy];
|
|
600
194
|
if (original && isVmFunction(original)) return original;
|
|
601
|
-
return
|
|
195
|
+
return null;
|
|
602
196
|
}
|
|
603
|
-
function wrapToVmValue(value, thisArg = null, assumeVmValue) {
|
|
197
|
+
function wrapToVmValue(value, thisArg = null, assumeVmValue = null) {
|
|
604
198
|
if (value == null) return null;
|
|
605
199
|
switch (typeof value) {
|
|
606
200
|
case "function": {
|
|
607
201
|
const unwrapped = fromVmFunctionProxy(value);
|
|
608
|
-
if (unwrapped) return unwrapped;
|
|
202
|
+
if (unwrapped != null) return unwrapped;
|
|
609
203
|
return new VmExtern(value, thisArg);
|
|
610
204
|
}
|
|
611
205
|
case "object": {
|
|
@@ -626,6 +220,14 @@ function wrapToVmValue(value, thisArg = null, assumeVmValue) {
|
|
|
626
220
|
return null;
|
|
627
221
|
}
|
|
628
222
|
}
|
|
223
|
+
function bindThis(fn, thisArg) {
|
|
224
|
+
if (thisArg == null) return fn;
|
|
225
|
+
return new Proxy(fn, {
|
|
226
|
+
apply(target, _thisArg, args) {
|
|
227
|
+
return apply(target, thisArg, args);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
}
|
|
629
231
|
function unwrapFromVmValue(value) {
|
|
630
232
|
if (isVmFunction(value)) {
|
|
631
233
|
return toVmFunctionProxy(value);
|
|
@@ -636,12 +238,7 @@ function unwrapFromVmValue(value) {
|
|
|
636
238
|
return value.value;
|
|
637
239
|
}
|
|
638
240
|
const f = value;
|
|
639
|
-
|
|
640
|
-
return new Proxy(f.value, {
|
|
641
|
-
apply(target, thisArg, args) {
|
|
642
|
-
return apply(target, caller, args);
|
|
643
|
-
}
|
|
644
|
-
});
|
|
241
|
+
return bindThis(f.value, f.thisArg);
|
|
645
242
|
}
|
|
646
243
|
|
|
647
244
|
// src/vm/types/extern.ts
|
|
@@ -682,7 +279,7 @@ var VmExtern = class extends VmWrapper {
|
|
|
682
279
|
get(key) {
|
|
683
280
|
if (!this.has(key)) return void 0;
|
|
684
281
|
const prop = this.value[key];
|
|
685
|
-
return wrapToVmValue(prop, this, (v) => this.assumeVmValue(v, key));
|
|
282
|
+
return wrapToVmValue(prop, this.value, (v) => this.assumeVmValue(v, key));
|
|
686
283
|
}
|
|
687
284
|
/** Set a property on the object */
|
|
688
285
|
set(key, value) {
|
|
@@ -697,7 +294,7 @@ var VmExtern = class extends VmWrapper {
|
|
|
697
294
|
if (typeof value != "function") {
|
|
698
295
|
throw VmError.from(`Not a callable extern`, null, null);
|
|
699
296
|
}
|
|
700
|
-
const caller = this.thisArg
|
|
297
|
+
const caller = this.thisArg;
|
|
701
298
|
const unwrappedArgs = args.map(unwrapFromVmValue);
|
|
702
299
|
let ret;
|
|
703
300
|
try {
|
|
@@ -729,7 +326,7 @@ var VmExtern = class extends VmWrapper {
|
|
|
729
326
|
if (toString2 === ArrayToString && isArray(this.value)) {
|
|
730
327
|
const mapped = ArrayMap.call(this.value, (item) => {
|
|
731
328
|
if (item === void 0) return "";
|
|
732
|
-
return innerToString(wrapToVmValue(item ?? null, null), true);
|
|
329
|
+
return innerToString(wrapToVmValue(item ?? null, null, null), true);
|
|
733
330
|
});
|
|
734
331
|
const str = mapped.join(", ");
|
|
735
332
|
if (useBraces) return `[${str}]`;
|
|
@@ -912,8 +509,8 @@ var DefaultVmContext = freeze({
|
|
|
912
509
|
/** @inheritdoc */
|
|
913
510
|
get(key) {
|
|
914
511
|
const val = VM_SHARED_CONTEXT[key];
|
|
915
|
-
if (val
|
|
916
|
-
return
|
|
512
|
+
if (val !== void 0) return val;
|
|
513
|
+
return globalVarNotFound(key);
|
|
917
514
|
},
|
|
918
515
|
/** @inheritdoc */
|
|
919
516
|
has(key) {
|
|
@@ -928,26 +525,23 @@ var ValueVmContext = class {
|
|
|
928
525
|
constructor(env, describer) {
|
|
929
526
|
this.env = env;
|
|
930
527
|
this.describer = describer;
|
|
931
|
-
this.cachedKeys = null;
|
|
932
528
|
}
|
|
933
529
|
/** @inheritdoc */
|
|
934
530
|
keys() {
|
|
935
|
-
|
|
936
|
-
if (this.cachedKeys?.[0] !== defaultKeys) {
|
|
937
|
-
const allKeys = freeze([...keys(this.env), ...defaultKeys]);
|
|
938
|
-
this.cachedKeys = freeze([defaultKeys, allKeys]);
|
|
939
|
-
}
|
|
940
|
-
return this.cachedKeys[1];
|
|
531
|
+
return [...keys(this.env), ...DefaultVmContext.keys()];
|
|
941
532
|
}
|
|
942
533
|
/** @inheritdoc */
|
|
943
534
|
get(key) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
535
|
+
if (hasOwn(this.env, key)) return this.env[key] ?? null;
|
|
536
|
+
{
|
|
537
|
+
const val = VM_SHARED_CONTEXT[key];
|
|
538
|
+
if (val !== void 0) return val;
|
|
539
|
+
return globalVarNotFound(key);
|
|
540
|
+
}
|
|
947
541
|
}
|
|
948
542
|
/** @inheritdoc */
|
|
949
543
|
has(key) {
|
|
950
|
-
return key in
|
|
544
|
+
return hasOwn(this.env, key) || key in VM_SHARED_CONTEXT;
|
|
951
545
|
}
|
|
952
546
|
/** @inheritdoc */
|
|
953
547
|
describe(key) {
|
|
@@ -957,6 +551,49 @@ var ValueVmContext = class {
|
|
|
957
551
|
};
|
|
958
552
|
defineProperty(ValueVmContext.prototype, kVmContext, { value: true });
|
|
959
553
|
freeze(ValueVmContext.prototype);
|
|
554
|
+
var Value2VmContext = class {
|
|
555
|
+
constructor(env, extern, describer) {
|
|
556
|
+
this.env = env;
|
|
557
|
+
this.extern = extern;
|
|
558
|
+
this.describer = describer;
|
|
559
|
+
this.externCache = /* @__PURE__ */ new WeakMap();
|
|
560
|
+
}
|
|
561
|
+
/** @inheritdoc */
|
|
562
|
+
keys() {
|
|
563
|
+
return [...this.env == null ? [] : keys(this.env), ...keys(this.extern), ...DefaultVmContext.keys()];
|
|
564
|
+
}
|
|
565
|
+
/** @inheritdoc */
|
|
566
|
+
get(key) {
|
|
567
|
+
if (this.env != null && hasOwn(this.env, key)) return this.env[key] ?? null;
|
|
568
|
+
if (hasOwn(this.extern, key)) {
|
|
569
|
+
const val2 = this.extern[key];
|
|
570
|
+
if (val2 == null) return null;
|
|
571
|
+
if (typeof val2 != "object" && typeof val2 != "function") {
|
|
572
|
+
return wrapToVmValue(val2, null, null);
|
|
573
|
+
}
|
|
574
|
+
let cached = this.externCache.get(val2);
|
|
575
|
+
if (cached == null) {
|
|
576
|
+
cached = wrapToVmValue(val2, null, null);
|
|
577
|
+
this.externCache.set(val2, cached);
|
|
578
|
+
}
|
|
579
|
+
return cached;
|
|
580
|
+
}
|
|
581
|
+
const val = VM_SHARED_CONTEXT[key];
|
|
582
|
+
if (val !== void 0) return val;
|
|
583
|
+
return globalVarNotFound(key);
|
|
584
|
+
}
|
|
585
|
+
/** @inheritdoc */
|
|
586
|
+
has(key) {
|
|
587
|
+
return this.env != null && hasOwn(this.env, key) || hasOwn(this.extern, key) || key in VM_SHARED_CONTEXT;
|
|
588
|
+
}
|
|
589
|
+
/** @inheritdoc */
|
|
590
|
+
describe(key) {
|
|
591
|
+
if (this.env != null && hasOwn(this.env, key) || hasOwn(this.extern, key)) return this.describer?.(key);
|
|
592
|
+
return VM_SHARED_CONTEXT_DESCRIPTIONS[key];
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
defineProperty(Value2VmContext.prototype, kVmContext, { value: true });
|
|
596
|
+
freeze(Value2VmContext.prototype);
|
|
960
597
|
var FactoryVmContext = class {
|
|
961
598
|
constructor(getter, enumerator, describer) {
|
|
962
599
|
this.getter = getter;
|
|
@@ -966,68 +603,355 @@ var FactoryVmContext = class {
|
|
|
966
603
|
/** @inheritdoc */
|
|
967
604
|
keys() {
|
|
968
605
|
if (!this.enumerator) return DefaultVmContext.keys();
|
|
969
|
-
return
|
|
606
|
+
return [...this.enumerator(), ...DefaultVmContext.keys()];
|
|
970
607
|
}
|
|
971
608
|
/** @inheritdoc */
|
|
972
609
|
get(key) {
|
|
973
610
|
const value = this.getter(key);
|
|
974
611
|
if (value !== void 0) return value;
|
|
975
|
-
|
|
612
|
+
const val = VM_SHARED_CONTEXT[key];
|
|
613
|
+
if (val !== void 0) return val;
|
|
614
|
+
return globalVarNotFound(key);
|
|
976
615
|
}
|
|
977
616
|
/** @inheritdoc */
|
|
978
617
|
has(key) {
|
|
979
|
-
return this.getter(key) !== void 0 ||
|
|
618
|
+
return this.getter(key) !== void 0 || key in VM_SHARED_CONTEXT;
|
|
619
|
+
}
|
|
620
|
+
/** @inheritdoc */
|
|
621
|
+
describe(key) {
|
|
622
|
+
if (this.getter(key) !== void 0) return this.describer?.(key);
|
|
623
|
+
return VM_SHARED_CONTEXT_DESCRIPTIONS[key];
|
|
624
|
+
}
|
|
625
|
+
};
|
|
626
|
+
defineProperty(FactoryVmContext.prototype, kVmContext, { value: true });
|
|
627
|
+
freeze(FactoryVmContext.prototype);
|
|
628
|
+
function createVmContext(arg0 = null, arg1 = null, describer = null) {
|
|
629
|
+
if (typeof arg0 == "function") {
|
|
630
|
+
const getter = arg0;
|
|
631
|
+
const enumerator = arg1;
|
|
632
|
+
return new FactoryVmContext(getter, enumerator, describer);
|
|
633
|
+
}
|
|
634
|
+
const vmValues = arg0;
|
|
635
|
+
const externValues = arg1;
|
|
636
|
+
if (externValues == null) {
|
|
637
|
+
if (vmValues == null) {
|
|
638
|
+
return DefaultVmContext;
|
|
639
|
+
}
|
|
640
|
+
return new ValueVmContext(vmValues, describer);
|
|
641
|
+
}
|
|
642
|
+
return new Value2VmContext(vmValues, externValues, describer);
|
|
643
|
+
}
|
|
644
|
+
|
|
645
|
+
// src/vm/operations/index.ts
|
|
646
|
+
var operations_exports = {};
|
|
647
|
+
__export(operations_exports, {
|
|
648
|
+
$Add: () => $Add,
|
|
649
|
+
$Aeq: () => $Aeq,
|
|
650
|
+
$And: () => $And,
|
|
651
|
+
$ArrayRange: () => $ArrayRange,
|
|
652
|
+
$ArrayRangeExclusive: () => $ArrayRangeExclusive,
|
|
653
|
+
$ArraySpread: () => $ArraySpread,
|
|
654
|
+
$AssertInit: () => $AssertInit,
|
|
655
|
+
$AssertNonNil: () => $AssertNonNil,
|
|
656
|
+
$Call: () => $Call,
|
|
657
|
+
$Concat: () => $Concat,
|
|
658
|
+
$Cp: () => Cp,
|
|
659
|
+
$CpEnter: () => CpEnter,
|
|
660
|
+
$CpExit: () => CpExit,
|
|
661
|
+
$Div: () => $Div,
|
|
662
|
+
$El: () => $El,
|
|
663
|
+
$ElOpt: () => $ElOpt,
|
|
664
|
+
$Eq: () => $Eq,
|
|
665
|
+
$Fn: () => $Fn,
|
|
666
|
+
$Format: () => $Format,
|
|
667
|
+
$Get: () => $Get,
|
|
668
|
+
$GlobalFallback: () => $GlobalFallback,
|
|
669
|
+
$Gt: () => $Gt,
|
|
670
|
+
$Gte: () => $Gte,
|
|
671
|
+
$Has: () => $Has,
|
|
672
|
+
$In: () => $In,
|
|
673
|
+
$IsArray: () => $IsArray,
|
|
674
|
+
$IsBoolean: () => $IsBoolean,
|
|
675
|
+
$IsNumber: () => $IsNumber,
|
|
676
|
+
$IsRecord: () => $IsRecord,
|
|
677
|
+
$IsString: () => $IsString,
|
|
678
|
+
$Iterable: () => $Iterable,
|
|
679
|
+
$Length: () => $Length,
|
|
680
|
+
$Lt: () => $Lt,
|
|
681
|
+
$Lte: () => $Lte,
|
|
682
|
+
$Mod: () => $Mod,
|
|
683
|
+
$Mul: () => $Mul,
|
|
684
|
+
$Naeq: () => $Naeq,
|
|
685
|
+
$Neg: () => $Neg,
|
|
686
|
+
$Neq: () => $Neq,
|
|
687
|
+
$Not: () => $Not,
|
|
688
|
+
$Nsame: () => $Nsame,
|
|
689
|
+
$Omit: () => $Omit,
|
|
690
|
+
$Or: () => $Or,
|
|
691
|
+
$Pick: () => $Pick,
|
|
692
|
+
$Pos: () => $Pos,
|
|
693
|
+
$Pow: () => $Pow,
|
|
694
|
+
$RecordSpread: () => $RecordSpread,
|
|
695
|
+
$Same: () => $Same,
|
|
696
|
+
$Set: () => $Set,
|
|
697
|
+
$Slice: () => $Slice,
|
|
698
|
+
$SliceExclusive: () => $SliceExclusive,
|
|
699
|
+
$Sub: () => $Sub,
|
|
700
|
+
$ToBoolean: () => $ToBoolean,
|
|
701
|
+
$ToNumber: () => $ToNumber,
|
|
702
|
+
$ToString: () => $ToString,
|
|
703
|
+
$Type: () => $Type,
|
|
704
|
+
$Upvalue: () => $Upvalue,
|
|
705
|
+
$VArgs: () => $VArgs
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
// src/vm/operations/convert.ts
|
|
709
|
+
var $ToBoolean = (value) => {
|
|
710
|
+
if (typeof value == "boolean") return value;
|
|
711
|
+
$AssertInit(value);
|
|
712
|
+
return toBoolean(value, void 0);
|
|
713
|
+
};
|
|
714
|
+
var $ToString = (value) => {
|
|
715
|
+
if (typeof value == "string") return value;
|
|
716
|
+
$AssertInit(value);
|
|
717
|
+
return toString(value, void 0);
|
|
718
|
+
};
|
|
719
|
+
var $ToNumber = (value) => {
|
|
720
|
+
if (typeof value == "number") return value;
|
|
721
|
+
$AssertInit(value);
|
|
722
|
+
return toNumber(value, void 0);
|
|
723
|
+
};
|
|
724
|
+
var $Format = (value, format2) => {
|
|
725
|
+
$AssertInit(value);
|
|
726
|
+
const f = format2 == null ? "" : $ToString(format2);
|
|
727
|
+
return toFormat(value, f);
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// src/vm/operations/type-check.ts
|
|
731
|
+
var $Type = (value) => {
|
|
732
|
+
if (value == null) return "nil";
|
|
733
|
+
if (isVmWrapper(value)) return value.type;
|
|
734
|
+
if (isVmArray(value)) return "array";
|
|
735
|
+
if (typeof value == "object") return "record";
|
|
736
|
+
return typeof value;
|
|
737
|
+
};
|
|
738
|
+
var $IsBoolean = (value) => {
|
|
739
|
+
$AssertInit(value);
|
|
740
|
+
return typeof value == "boolean";
|
|
741
|
+
};
|
|
742
|
+
var $IsNumber = (value) => {
|
|
743
|
+
$AssertInit(value);
|
|
744
|
+
return typeof value == "number";
|
|
745
|
+
};
|
|
746
|
+
var $IsString = (value) => {
|
|
747
|
+
$AssertInit(value);
|
|
748
|
+
return typeof value == "string";
|
|
749
|
+
};
|
|
750
|
+
var $IsRecord = (value) => {
|
|
751
|
+
$AssertInit(value);
|
|
752
|
+
return isVmRecord(value);
|
|
753
|
+
};
|
|
754
|
+
var $IsArray = (value) => {
|
|
755
|
+
$AssertInit(value);
|
|
756
|
+
return isVmArray(value);
|
|
757
|
+
};
|
|
758
|
+
var $AssertNonNil = (value) => {
|
|
759
|
+
$AssertInit(value);
|
|
760
|
+
if (value !== null) return;
|
|
761
|
+
throw new VmError(`Expected non-nil value`, null);
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
// src/vm/operations/utils.ts
|
|
765
|
+
function overloadNumberString(a, b) {
|
|
766
|
+
if (typeof a == "number" || typeof b == "number") return true;
|
|
767
|
+
if (typeof a == "string" || typeof b == "string") return false;
|
|
768
|
+
return true;
|
|
769
|
+
}
|
|
770
|
+
function isSame(a, b) {
|
|
771
|
+
if (typeof a == "number" && typeof b == "number") {
|
|
772
|
+
return a === b || isNaN(a) && isNaN(b);
|
|
773
|
+
}
|
|
774
|
+
if (a === b) return true;
|
|
775
|
+
if (a == null || typeof a != "object" || b == null || typeof b != "object") return false;
|
|
776
|
+
if (isVmWrapper(a)) return a.same(b);
|
|
777
|
+
if (isVmWrapper(b)) return b.same(a);
|
|
778
|
+
if (isVmArray(a) && isVmArray(b)) {
|
|
779
|
+
const len2 = a.length;
|
|
780
|
+
if (len2 !== b.length) {
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
for (let i = 0; i < len2; i++) {
|
|
784
|
+
if (!isSame(a[i] ?? null, b[i] ?? null)) {
|
|
785
|
+
return false;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
return true;
|
|
789
|
+
}
|
|
790
|
+
if (!isVmArray(a) && !isVmArray(b)) {
|
|
791
|
+
const aKeys = keys(a);
|
|
792
|
+
const bKeys = keys(b);
|
|
793
|
+
if (aKeys.length !== bKeys.length) {
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
for (const key of aKeys) {
|
|
797
|
+
if (!hasOwnEnumerable(b, key)) {
|
|
798
|
+
return false;
|
|
799
|
+
}
|
|
800
|
+
const av = a[key] ?? null;
|
|
801
|
+
const bv = b[key] ?? null;
|
|
802
|
+
if (!isSame(av, bv)) {
|
|
803
|
+
return false;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
return true;
|
|
807
|
+
}
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// src/vm/operations/operator.ts
|
|
812
|
+
var $Concat = (...args) => {
|
|
813
|
+
return args.map((a) => toFormat(a, null)).join("");
|
|
814
|
+
};
|
|
815
|
+
var $Pos = (a) => {
|
|
816
|
+
return $ToNumber(a);
|
|
817
|
+
};
|
|
818
|
+
var $Neg = (a) => {
|
|
819
|
+
return -$ToNumber(a);
|
|
820
|
+
};
|
|
821
|
+
var $Not = (a) => {
|
|
822
|
+
return !$ToBoolean(a);
|
|
823
|
+
};
|
|
824
|
+
var $Add = (a, b) => {
|
|
825
|
+
return $ToNumber(a) + $ToNumber(b);
|
|
826
|
+
};
|
|
827
|
+
var $Sub = (a, b) => {
|
|
828
|
+
return $ToNumber(a) - $ToNumber(b);
|
|
829
|
+
};
|
|
830
|
+
var $Mul = (a, b) => {
|
|
831
|
+
return $ToNumber(a) * $ToNumber(b);
|
|
832
|
+
};
|
|
833
|
+
var $Div = (a, b) => {
|
|
834
|
+
return $ToNumber(a) / $ToNumber(b);
|
|
835
|
+
};
|
|
836
|
+
var $Mod = (a, b) => {
|
|
837
|
+
return $ToNumber(a) % $ToNumber(b);
|
|
838
|
+
};
|
|
839
|
+
var $Pow = (a, b) => {
|
|
840
|
+
return $ToNumber(a) ** $ToNumber(b);
|
|
841
|
+
};
|
|
842
|
+
var $And = (a, b) => {
|
|
843
|
+
return $ToBoolean(a) && $ToBoolean(b);
|
|
844
|
+
};
|
|
845
|
+
var $Or = (a, b) => {
|
|
846
|
+
return $ToBoolean(a) || $ToBoolean(b);
|
|
847
|
+
};
|
|
848
|
+
var $Gt = (a, b) => {
|
|
849
|
+
if (overloadNumberString(a, b)) {
|
|
850
|
+
return $ToNumber(a) > $ToNumber(b);
|
|
851
|
+
} else {
|
|
852
|
+
return $ToString(a) > $ToString(b);
|
|
980
853
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
return
|
|
854
|
+
};
|
|
855
|
+
var $Gte = (a, b) => {
|
|
856
|
+
if (overloadNumberString(a, b)) {
|
|
857
|
+
return $ToNumber(a) >= $ToNumber(b);
|
|
858
|
+
} else {
|
|
859
|
+
return $ToString(a) >= $ToString(b);
|
|
985
860
|
}
|
|
986
861
|
};
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
return
|
|
862
|
+
var $Lt = (a, b) => {
|
|
863
|
+
if (overloadNumberString(a, b)) {
|
|
864
|
+
return $ToNumber(a) < $ToNumber(b);
|
|
865
|
+
} else {
|
|
866
|
+
return $ToString(a) < $ToString(b);
|
|
992
867
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
return
|
|
868
|
+
};
|
|
869
|
+
var $Lte = (a, b) => {
|
|
870
|
+
if (overloadNumberString(a, b)) {
|
|
871
|
+
return $ToNumber(a) <= $ToNumber(b);
|
|
872
|
+
} else {
|
|
873
|
+
return $ToString(a) <= $ToString(b);
|
|
997
874
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
875
|
+
};
|
|
876
|
+
var $Eq = (a, b) => {
|
|
877
|
+
$AssertInit(a);
|
|
878
|
+
$AssertInit(b);
|
|
879
|
+
if (typeof a == "number" && typeof b == "number") return a === b;
|
|
880
|
+
return isSame(a, b);
|
|
881
|
+
};
|
|
882
|
+
var $Neq = (a, b) => {
|
|
883
|
+
return !$Eq(a, b);
|
|
884
|
+
};
|
|
885
|
+
var { abs, min } = Math;
|
|
886
|
+
var $Aeq = (a, b) => {
|
|
887
|
+
if (overloadNumberString(a, b)) {
|
|
888
|
+
const an = $ToNumber(a);
|
|
889
|
+
const bn = $ToNumber(b);
|
|
890
|
+
const EPS = 1e-15;
|
|
891
|
+
if (isNaN(an) || isNaN(bn)) return false;
|
|
892
|
+
if (an === bn) return true;
|
|
893
|
+
const absoluteDifference = abs(an - bn);
|
|
894
|
+
if (absoluteDifference < EPS) return true;
|
|
895
|
+
const base = min(abs(an), abs(bn));
|
|
896
|
+
return absoluteDifference < base * EPS;
|
|
897
|
+
} else {
|
|
898
|
+
const as = $ToString(a);
|
|
899
|
+
const bs = $ToString(b);
|
|
900
|
+
if (as === bs) return true;
|
|
901
|
+
const ai = as.toLowerCase();
|
|
902
|
+
const bi = bs.toLowerCase();
|
|
903
|
+
if (ai === bi) return true;
|
|
904
|
+
const an = ai.normalize("NFC");
|
|
905
|
+
const bn = bi.normalize("NFC");
|
|
906
|
+
return an === bn;
|
|
1006
907
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
908
|
+
};
|
|
909
|
+
var $Naeq = (a, b) => {
|
|
910
|
+
return !$Aeq(a, b);
|
|
911
|
+
};
|
|
912
|
+
var $Same = (a, b) => {
|
|
913
|
+
$AssertInit(a);
|
|
914
|
+
$AssertInit(b);
|
|
915
|
+
return isSame(a, b);
|
|
916
|
+
};
|
|
917
|
+
var $Nsame = (a, b) => {
|
|
918
|
+
return !$Same(a, b);
|
|
919
|
+
};
|
|
920
|
+
|
|
921
|
+
// src/vm/operations/slice.ts
|
|
922
|
+
var { ceil } = Math;
|
|
923
|
+
var { slice } = Array.prototype;
|
|
924
|
+
var sliceCore = (value, start, end, exclusive) => {
|
|
925
|
+
const { length } = value;
|
|
926
|
+
if (isNaN(start)) start = 0;
|
|
927
|
+
else if (start < 0) start = length + start;
|
|
928
|
+
if (isNaN(end)) end = exclusive ? length : length - 1;
|
|
929
|
+
else if (end < 0) end = length + end;
|
|
930
|
+
start = ceil(start);
|
|
931
|
+
if (exclusive || !isSafeInteger(end)) {
|
|
932
|
+
end = ceil(end);
|
|
933
|
+
} else {
|
|
934
|
+
end = end + 1;
|
|
1011
935
|
}
|
|
1012
|
-
return
|
|
1013
|
-
}
|
|
936
|
+
return slice.call(value, start, end);
|
|
937
|
+
};
|
|
938
|
+
var $Slice = (value, start, end) => {
|
|
939
|
+
$AssertInit(value);
|
|
940
|
+
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
941
|
+
const s = start != null ? $ToNumber(start) : 0;
|
|
942
|
+
const e = end != null ? $ToNumber(end) : value.length - 1;
|
|
943
|
+
return sliceCore(value, s, e, false);
|
|
944
|
+
};
|
|
945
|
+
var $SliceExclusive = (value, start, end) => {
|
|
946
|
+
$AssertInit(value);
|
|
947
|
+
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
948
|
+
const s = start != null ? $ToNumber(start) : 0;
|
|
949
|
+
const e = end != null ? $ToNumber(end) : value.length;
|
|
950
|
+
return sliceCore(value, s, e, true);
|
|
951
|
+
};
|
|
1014
952
|
|
|
1015
|
-
// src/vm/helpers.ts
|
|
1016
|
-
var
|
|
1017
|
-
__export(helpers_exports, {
|
|
1018
|
-
ArrayRange: () => ArrayRange,
|
|
1019
|
-
ArrayRangeExclusive: () => ArrayRangeExclusive,
|
|
1020
|
-
Cp: () => Cp,
|
|
1021
|
-
CpEnter: () => CpEnter,
|
|
1022
|
-
CpExit: () => CpExit,
|
|
1023
|
-
Element: () => Element,
|
|
1024
|
-
ElementOpt: () => ElementOpt,
|
|
1025
|
-
Function: () => Function2,
|
|
1026
|
-
GlobalFallback: () => GlobalFallback,
|
|
1027
|
-
Upvalue: () => Upvalue,
|
|
1028
|
-
Vargs: () => Vargs
|
|
1029
|
-
});
|
|
1030
|
-
var Vargs = (varags) => {
|
|
953
|
+
// src/vm/operations/helpers.ts
|
|
954
|
+
var $VArgs = (varags) => {
|
|
1031
955
|
for (let i = 0, l = varags.length; i < l; i++) {
|
|
1032
956
|
const el = varags[i];
|
|
1033
957
|
if (!isVmConst(el)) {
|
|
@@ -1036,22 +960,22 @@ var Vargs = (varags) => {
|
|
|
1036
960
|
}
|
|
1037
961
|
return varags;
|
|
1038
962
|
};
|
|
1039
|
-
var
|
|
963
|
+
var $El = (value) => {
|
|
1040
964
|
$AssertInit(value);
|
|
1041
965
|
if (!isVmConst(value)) return null;
|
|
1042
966
|
return value;
|
|
1043
967
|
};
|
|
1044
968
|
var EMPTY = create(null);
|
|
1045
|
-
var
|
|
969
|
+
var $ElOpt = (key, value) => {
|
|
1046
970
|
$AssertInit(value);
|
|
1047
971
|
if (value == null || !isVmConst(value)) return EMPTY;
|
|
1048
972
|
return { __proto__: null, [key]: value };
|
|
1049
973
|
};
|
|
1050
|
-
var
|
|
974
|
+
var $Fn = (name, fn) => {
|
|
1051
975
|
defineProperty(fn, "name", { value: name || VM_FUNCTION_ANONYMOUS_NAME });
|
|
1052
976
|
return VmFunction(fn, { isLib: false, injectCp: false });
|
|
1053
977
|
};
|
|
1054
|
-
var Upvalue = (value) => {
|
|
978
|
+
var $Upvalue = (value) => {
|
|
1055
979
|
$AssertInit(value);
|
|
1056
980
|
return value;
|
|
1057
981
|
};
|
|
@@ -1063,7 +987,7 @@ var assertArrayLength = (start, end) => {
|
|
|
1063
987
|
var isEmptyRange = (start, end) => {
|
|
1064
988
|
return !isFinite(start) || !isFinite(end) || start > end;
|
|
1065
989
|
};
|
|
1066
|
-
var ArrayRange = (start, end) => {
|
|
990
|
+
var $ArrayRange = (start, end) => {
|
|
1067
991
|
const s = $ToNumber(start);
|
|
1068
992
|
const e = $ToNumber(end);
|
|
1069
993
|
if (isEmptyRange(s, e)) return [];
|
|
@@ -1074,7 +998,7 @@ var ArrayRange = (start, end) => {
|
|
|
1074
998
|
}
|
|
1075
999
|
return arr;
|
|
1076
1000
|
};
|
|
1077
|
-
var ArrayRangeExclusive = (start, end) => {
|
|
1001
|
+
var $ArrayRangeExclusive = (start, end) => {
|
|
1078
1002
|
const s = $ToNumber(start);
|
|
1079
1003
|
const e = $ToNumber(end);
|
|
1080
1004
|
if (isEmptyRange(s, e)) return [];
|
|
@@ -1085,29 +1009,138 @@ var ArrayRangeExclusive = (start, end) => {
|
|
|
1085
1009
|
}
|
|
1086
1010
|
return arr;
|
|
1087
1011
|
};
|
|
1088
|
-
function GlobalFallback() {
|
|
1012
|
+
function $GlobalFallback() {
|
|
1089
1013
|
return DefaultVmContext;
|
|
1090
1014
|
}
|
|
1091
1015
|
|
|
1092
|
-
// src/
|
|
1093
|
-
|
|
1094
|
-
var
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1016
|
+
// src/vm/operations/compound.ts
|
|
1017
|
+
var { trunc } = Math;
|
|
1018
|
+
var { at } = Array.prototype;
|
|
1019
|
+
var $In = (value, iterable) => {
|
|
1020
|
+
$AssertInit(value);
|
|
1021
|
+
$AssertInit(iterable);
|
|
1022
|
+
if (iterable == null) return false;
|
|
1023
|
+
if (typeof iterable != "object") return false;
|
|
1024
|
+
if (isVmArray(iterable)) {
|
|
1025
|
+
if (value == null) {
|
|
1026
|
+
for (const item of iterable) if (item == null) return true;
|
|
1027
|
+
return false;
|
|
1028
|
+
}
|
|
1029
|
+
if (isVmPrimitive(value)) return iterable.includes(value);
|
|
1030
|
+
return iterable.some((item = null) => isSame(item, value));
|
|
1031
|
+
}
|
|
1032
|
+
const key = toString(value, void 0);
|
|
1033
|
+
if (isVmWrapper(iterable)) return iterable.has(key);
|
|
1034
|
+
return hasOwnEnumerable(iterable, key);
|
|
1035
|
+
};
|
|
1036
|
+
var $Length = (value) => {
|
|
1037
|
+
$AssertInit(value);
|
|
1038
|
+
if (isVmArray(value)) return value.length;
|
|
1039
|
+
if (isVmRecord(value)) return keys(value).length;
|
|
1040
|
+
if (isVmWrapper(value)) return value.keys().length;
|
|
1041
|
+
throw new VmError(`Value has no length: ${display(value)}`, 0);
|
|
1042
|
+
};
|
|
1043
|
+
var $Omit = (value, omitted) => {
|
|
1044
|
+
$AssertInit(value);
|
|
1045
|
+
if (value == null || !isVmRecord(value)) return {};
|
|
1046
|
+
const result = {};
|
|
1047
|
+
const valueKeys = keys(value);
|
|
1048
|
+
const omittedSet = new Set(omitted.map($ToString));
|
|
1049
|
+
for (const key of valueKeys) {
|
|
1050
|
+
if (!omittedSet.has(key)) {
|
|
1051
|
+
result[key] = value[key] ?? null;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
return result;
|
|
1055
|
+
};
|
|
1056
|
+
var $Pick = (value, picked) => {
|
|
1057
|
+
$AssertInit(value);
|
|
1058
|
+
if (value == null || !isVmRecord(value)) return {};
|
|
1059
|
+
const result = {};
|
|
1060
|
+
for (const key of picked) {
|
|
1061
|
+
const k = $ToString(key);
|
|
1062
|
+
if (hasOwnEnumerable(value, k)) {
|
|
1063
|
+
result[k] = value[k] ?? null;
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
return result;
|
|
1067
|
+
};
|
|
1068
|
+
var $Has = (obj, key) => {
|
|
1069
|
+
$AssertInit(obj);
|
|
1070
|
+
const pk = $ToString(key);
|
|
1071
|
+
if (obj == null || typeof obj != "object") return false;
|
|
1072
|
+
if (isVmWrapper(obj)) return obj.has(pk);
|
|
1073
|
+
return hasOwnEnumerable(obj, pk);
|
|
1074
|
+
};
|
|
1075
|
+
var $Get = (obj, key) => {
|
|
1076
|
+
$AssertInit(obj);
|
|
1077
|
+
if (isVmArray(obj)) {
|
|
1078
|
+
const index = $ToNumber(key);
|
|
1079
|
+
if (isNaN(index)) return null;
|
|
1080
|
+
return at.call(obj, trunc(index)) ?? null;
|
|
1081
|
+
}
|
|
1082
|
+
const pk = $ToString(key);
|
|
1083
|
+
if (obj == null || typeof obj != "object") return null;
|
|
1084
|
+
if (isVmWrapper(obj)) return obj.get(pk) ?? null;
|
|
1085
|
+
if (!hasOwnEnumerable(obj, pk)) return null;
|
|
1086
|
+
return obj[pk] ?? null;
|
|
1087
|
+
};
|
|
1088
|
+
var $Set = (obj, key, value) => {
|
|
1089
|
+
$AssertInit(obj);
|
|
1090
|
+
$AssertInit(value);
|
|
1091
|
+
const pk = $ToString(key);
|
|
1092
|
+
if (obj == null) return;
|
|
1093
|
+
if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${display(obj)}`, void 0);
|
|
1094
|
+
obj.set(pk, value);
|
|
1095
|
+
};
|
|
1096
|
+
var $Iterable = (value) => {
|
|
1097
|
+
$AssertInit(value);
|
|
1098
|
+
if (isVmWrapper(value)) return value.keys();
|
|
1099
|
+
if (isVmArray(value)) return value;
|
|
1100
|
+
if (value != null && typeof value == "object") return keys(value);
|
|
1101
|
+
throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
|
|
1102
|
+
};
|
|
1103
|
+
var $RecordSpread = (record) => {
|
|
1104
|
+
$AssertInit(record);
|
|
1105
|
+
if (record == null || isVmRecord(record)) return record;
|
|
1106
|
+
if (isVmArray(record)) {
|
|
1107
|
+
const result = {};
|
|
1108
|
+
const len2 = record.length;
|
|
1109
|
+
for (let i = 0; i < len2; i++) {
|
|
1110
|
+
const item = record[i];
|
|
1111
|
+
result[i] = item ?? null;
|
|
1112
|
+
}
|
|
1113
|
+
return result;
|
|
1114
|
+
}
|
|
1115
|
+
if (isVmExtern(record)) {
|
|
1116
|
+
const result = create(null);
|
|
1117
|
+
for (const key of record.keys()) {
|
|
1118
|
+
const value = record.get(key) ?? null;
|
|
1119
|
+
if (isVmPrimitive(value)) {
|
|
1120
|
+
result[key] = value;
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
return result;
|
|
1124
|
+
}
|
|
1125
|
+
throw new VmError(`Expected record, array, extern or nil, got ${display(record)}`, null);
|
|
1126
|
+
};
|
|
1127
|
+
var $ArraySpread = (array) => {
|
|
1128
|
+
$AssertInit(array);
|
|
1129
|
+
if (array == null) return [];
|
|
1130
|
+
if (isVmArray(array)) return array;
|
|
1131
|
+
if (isVmExtern(array) && typeof array.value[Symbol.iterator] == "function") {
|
|
1132
|
+
const result = [];
|
|
1133
|
+
for (const item of array.value) {
|
|
1134
|
+
if (isVmPrimitive(item)) {
|
|
1135
|
+
result.push(item);
|
|
1136
|
+
} else {
|
|
1137
|
+
result.push(null);
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
return result;
|
|
1141
|
+
}
|
|
1142
|
+
throw new VmError(`Expected array, iterable extern or nil, got ${display(array)}`, []);
|
|
1098
1143
|
};
|
|
1099
|
-
|
|
1100
|
-
// src/vm/env.ts
|
|
1101
|
-
var keys2 = [];
|
|
1102
|
-
var values2 = [];
|
|
1103
|
-
for (const [key, value] of entries(operations_exports)) {
|
|
1104
|
-
keys2.push(key);
|
|
1105
|
-
values2.push(value);
|
|
1106
|
-
}
|
|
1107
|
-
for (const [key, value] of entries(helpers_exports)) {
|
|
1108
|
-
keys2.push(key);
|
|
1109
|
-
values2.push(value);
|
|
1110
|
-
}
|
|
1111
1144
|
|
|
1112
1145
|
// src/compiler/create-script.ts
|
|
1113
1146
|
function wrapScript(source, mode, script) {
|
|
@@ -1123,16 +1156,34 @@ function wrapScript(source, mode, script) {
|
|
|
1123
1156
|
}
|
|
1124
1157
|
return script;
|
|
1125
1158
|
}
|
|
1159
|
+
var [keys2, values2] = (() => {
|
|
1160
|
+
const keys4 = [];
|
|
1161
|
+
const values4 = [];
|
|
1162
|
+
for (const [key, value] of entries(operations_exports)) {
|
|
1163
|
+
keys4.push(key);
|
|
1164
|
+
values4.push(value);
|
|
1165
|
+
}
|
|
1166
|
+
return [keys4.join(","), values4];
|
|
1167
|
+
})();
|
|
1126
1168
|
function createScript(source, mode, code) {
|
|
1127
1169
|
let script;
|
|
1128
1170
|
try {
|
|
1129
|
-
script = new Function(
|
|
1171
|
+
script = new Function(keys2, `'use strict';
|
|
1172
|
+
return ${code}`)(...values2);
|
|
1130
1173
|
} catch (error) {
|
|
1131
1174
|
throw new Error(`Failed to create script`, { cause: error });
|
|
1132
1175
|
}
|
|
1133
1176
|
return wrapScript(source, mode, script);
|
|
1134
1177
|
}
|
|
1135
1178
|
|
|
1179
|
+
// src/compiler/keywords.ts
|
|
1180
|
+
import { getModule } from "@mirascript/bindings";
|
|
1181
|
+
var keywords = () => {
|
|
1182
|
+
const kw = Object.freeze(getModule().keywords());
|
|
1183
|
+
keywords = () => kw;
|
|
1184
|
+
return kw;
|
|
1185
|
+
};
|
|
1186
|
+
|
|
1136
1187
|
// src/compiler/emit-script.ts
|
|
1137
1188
|
function reportDiagnostic(source, diagnostics, fileName) {
|
|
1138
1189
|
const parsed = parseDiagnostics(source, diagnostics);
|
|
@@ -1760,7 +1811,7 @@ var factorial = VmLib(
|
|
|
1760
1811
|
);
|
|
1761
1812
|
|
|
1762
1813
|
// src/vm/lib/global/math.ts
|
|
1763
|
-
var { atan2: _atan2, pow: _pow } = Math;
|
|
1814
|
+
var { atan2: _atan2, pow: _pow, random: _random } = Math;
|
|
1764
1815
|
var atan2 = VmLib((x, y) => _atan2(expectNumber(0, x), expectNumber(1, y)), {
|
|
1765
1816
|
summary: "返回从原点到点 (x, y) 的角度(弧度)",
|
|
1766
1817
|
params: { x: "x 坐标", y: "y 坐标" },
|
|
@@ -1773,7 +1824,7 @@ var pow2 = VmLib((x, y) => _pow(expectNumber(0, x), expectNumber(1, y)), {
|
|
|
1773
1824
|
paramsType: { x: "number", y: "number" },
|
|
1774
1825
|
returnsType: "number"
|
|
1775
1826
|
});
|
|
1776
|
-
var random = VmLib(
|
|
1827
|
+
var random = VmLib(() => _random(), {
|
|
1777
1828
|
summary: "返回 [0, 1) 之间的伪随机数",
|
|
1778
1829
|
params: {},
|
|
1779
1830
|
paramsType: {},
|
|
@@ -1927,7 +1978,7 @@ var normalizeEntries = (data, entries3) => {
|
|
|
1927
1978
|
}
|
|
1928
1979
|
}
|
|
1929
1980
|
const value = entries3[i + 1];
|
|
1930
|
-
entryData.set(key,
|
|
1981
|
+
entryData.set(key, $El(value));
|
|
1931
1982
|
}
|
|
1932
1983
|
return entryData;
|
|
1933
1984
|
};
|
|
@@ -3437,7 +3488,6 @@ var lib = Object.freeze(Object.assign(create(null), global_exports, mod_exports)
|
|
|
3437
3488
|
|
|
3438
3489
|
export {
|
|
3439
3490
|
convert_exports,
|
|
3440
|
-
operations_exports,
|
|
3441
3491
|
VmExtern,
|
|
3442
3492
|
wrapToVmValue,
|
|
3443
3493
|
unwrapFromVmValue,
|
|
@@ -3446,8 +3496,8 @@ export {
|
|
|
3446
3496
|
defineVmContextValue,
|
|
3447
3497
|
DefaultVmContext,
|
|
3448
3498
|
createVmContext,
|
|
3449
|
-
GlobalFallback,
|
|
3450
|
-
|
|
3499
|
+
$GlobalFallback,
|
|
3500
|
+
operations_exports,
|
|
3451
3501
|
wrapScript,
|
|
3452
3502
|
createScript,
|
|
3453
3503
|
keywords,
|
|
@@ -3458,4 +3508,4 @@ export {
|
|
|
3458
3508
|
panic,
|
|
3459
3509
|
lib
|
|
3460
3510
|
};
|
|
3461
|
-
//# sourceMappingURL=chunk-
|
|
3511
|
+
//# sourceMappingURL=chunk-XWQWKD67.js.map
|