@mirascript/mirascript 0.1.22 → 0.1.24
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-PECLT2P6.js → chunk-AZICQWZD.js} +35 -9
- package/dist/chunk-AZICQWZD.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-7HH5Y4QO.js → chunk-UCIDBTZL.js} +599 -535
- package/dist/chunk-UCIDBTZL.js.map +6 -0
- package/dist/chunk-X6LYEGOK.js +69 -0
- package/dist/chunk-X6LYEGOK.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 +3 -3
- 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/debug.ts +1 -1
- 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 +24 -9
- package/src/vm/types/index.ts +1 -1
- package/dist/chunk-4T5YE7LC.js.map +0 -6
- package/dist/chunk-7HH5Y4QO.js.map +0 -6
- package/dist/chunk-PECLT2P6.js.map +0 -6
- package/dist/chunk-RNLB52WP.js +0 -1
- package/dist/chunk-RNLB52WP.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 {
|
|
@@ -708,12 +305,26 @@ var VmExtern = class extends VmWrapper {
|
|
|
708
305
|
return wrapToVmValue(ret, null, (obj) => this.assumeVmValue(obj, void 0));
|
|
709
306
|
}
|
|
710
307
|
/** @inheritdoc */
|
|
711
|
-
keys() {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
308
|
+
keys(includeNonEnumerable = false) {
|
|
309
|
+
if (!includeNonEnumerable) {
|
|
310
|
+
const keys4 = [];
|
|
311
|
+
for (const key in this.value) {
|
|
312
|
+
if (this.has(key)) keys4.push(key);
|
|
313
|
+
}
|
|
314
|
+
return keys4;
|
|
315
|
+
} else {
|
|
316
|
+
const keys4 = /* @__PURE__ */ new Set();
|
|
317
|
+
let e = this.value;
|
|
318
|
+
while (e && (typeof e == "object" || typeof e == "function")) {
|
|
319
|
+
for (const key of Object.getOwnPropertyNames(e)) {
|
|
320
|
+
if (this.has(key)) {
|
|
321
|
+
keys4.add(key);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
e = Object.getPrototypeOf(e);
|
|
325
|
+
}
|
|
326
|
+
return Array.from(keys4);
|
|
715
327
|
}
|
|
716
|
-
return keys4;
|
|
717
328
|
}
|
|
718
329
|
/** @inheritdoc */
|
|
719
330
|
same(other) {
|
|
@@ -729,7 +340,7 @@ var VmExtern = class extends VmWrapper {
|
|
|
729
340
|
if (toString2 === ArrayToString && isArray(this.value)) {
|
|
730
341
|
const mapped = ArrayMap.call(this.value, (item) => {
|
|
731
342
|
if (item === void 0) return "";
|
|
732
|
-
return innerToString(wrapToVmValue(item ?? null, null), true);
|
|
343
|
+
return innerToString(wrapToVmValue(item ?? null, null, null), true);
|
|
733
344
|
});
|
|
734
345
|
const str = mapped.join(", ");
|
|
735
346
|
if (useBraces) return `[${str}]`;
|
|
@@ -912,8 +523,8 @@ var DefaultVmContext = freeze({
|
|
|
912
523
|
/** @inheritdoc */
|
|
913
524
|
get(key) {
|
|
914
525
|
const val = VM_SHARED_CONTEXT[key];
|
|
915
|
-
if (val
|
|
916
|
-
return
|
|
526
|
+
if (val !== void 0) return val;
|
|
527
|
+
return globalVarNotFound(key);
|
|
917
528
|
},
|
|
918
529
|
/** @inheritdoc */
|
|
919
530
|
has(key) {
|
|
@@ -928,26 +539,23 @@ var ValueVmContext = class {
|
|
|
928
539
|
constructor(env, describer) {
|
|
929
540
|
this.env = env;
|
|
930
541
|
this.describer = describer;
|
|
931
|
-
this.cachedKeys = null;
|
|
932
542
|
}
|
|
933
543
|
/** @inheritdoc */
|
|
934
544
|
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];
|
|
545
|
+
return [...keys(this.env), ...DefaultVmContext.keys()];
|
|
941
546
|
}
|
|
942
547
|
/** @inheritdoc */
|
|
943
548
|
get(key) {
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
549
|
+
if (hasOwn(this.env, key)) return this.env[key] ?? null;
|
|
550
|
+
{
|
|
551
|
+
const val = VM_SHARED_CONTEXT[key];
|
|
552
|
+
if (val !== void 0) return val;
|
|
553
|
+
return globalVarNotFound(key);
|
|
554
|
+
}
|
|
947
555
|
}
|
|
948
556
|
/** @inheritdoc */
|
|
949
557
|
has(key) {
|
|
950
|
-
return key in
|
|
558
|
+
return hasOwn(this.env, key) || key in VM_SHARED_CONTEXT;
|
|
951
559
|
}
|
|
952
560
|
/** @inheritdoc */
|
|
953
561
|
describe(key) {
|
|
@@ -957,6 +565,49 @@ var ValueVmContext = class {
|
|
|
957
565
|
};
|
|
958
566
|
defineProperty(ValueVmContext.prototype, kVmContext, { value: true });
|
|
959
567
|
freeze(ValueVmContext.prototype);
|
|
568
|
+
var Value2VmContext = class {
|
|
569
|
+
constructor(env, extern, describer) {
|
|
570
|
+
this.env = env;
|
|
571
|
+
this.extern = extern;
|
|
572
|
+
this.describer = describer;
|
|
573
|
+
this.externCache = /* @__PURE__ */ new WeakMap();
|
|
574
|
+
}
|
|
575
|
+
/** @inheritdoc */
|
|
576
|
+
keys() {
|
|
577
|
+
return [...this.env == null ? [] : keys(this.env), ...keys(this.extern), ...DefaultVmContext.keys()];
|
|
578
|
+
}
|
|
579
|
+
/** @inheritdoc */
|
|
580
|
+
get(key) {
|
|
581
|
+
if (this.env != null && hasOwn(this.env, key)) return this.env[key] ?? null;
|
|
582
|
+
if (hasOwn(this.extern, key)) {
|
|
583
|
+
const val2 = this.extern[key];
|
|
584
|
+
if (val2 == null) return null;
|
|
585
|
+
if (typeof val2 != "object" && typeof val2 != "function") {
|
|
586
|
+
return wrapToVmValue(val2, null, null);
|
|
587
|
+
}
|
|
588
|
+
let cached = this.externCache.get(val2);
|
|
589
|
+
if (cached == null) {
|
|
590
|
+
cached = wrapToVmValue(val2, null, null);
|
|
591
|
+
this.externCache.set(val2, cached);
|
|
592
|
+
}
|
|
593
|
+
return cached;
|
|
594
|
+
}
|
|
595
|
+
const val = VM_SHARED_CONTEXT[key];
|
|
596
|
+
if (val !== void 0) return val;
|
|
597
|
+
return globalVarNotFound(key);
|
|
598
|
+
}
|
|
599
|
+
/** @inheritdoc */
|
|
600
|
+
has(key) {
|
|
601
|
+
return this.env != null && hasOwn(this.env, key) || hasOwn(this.extern, key) || key in VM_SHARED_CONTEXT;
|
|
602
|
+
}
|
|
603
|
+
/** @inheritdoc */
|
|
604
|
+
describe(key) {
|
|
605
|
+
if (this.env != null && hasOwn(this.env, key) || hasOwn(this.extern, key)) return this.describer?.(key);
|
|
606
|
+
return VM_SHARED_CONTEXT_DESCRIPTIONS[key];
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
defineProperty(Value2VmContext.prototype, kVmContext, { value: true });
|
|
610
|
+
freeze(Value2VmContext.prototype);
|
|
960
611
|
var FactoryVmContext = class {
|
|
961
612
|
constructor(getter, enumerator, describer) {
|
|
962
613
|
this.getter = getter;
|
|
@@ -966,68 +617,355 @@ var FactoryVmContext = class {
|
|
|
966
617
|
/** @inheritdoc */
|
|
967
618
|
keys() {
|
|
968
619
|
if (!this.enumerator) return DefaultVmContext.keys();
|
|
969
|
-
return
|
|
620
|
+
return [...this.enumerator(), ...DefaultVmContext.keys()];
|
|
970
621
|
}
|
|
971
622
|
/** @inheritdoc */
|
|
972
623
|
get(key) {
|
|
973
624
|
const value = this.getter(key);
|
|
974
625
|
if (value !== void 0) return value;
|
|
975
|
-
|
|
626
|
+
const val = VM_SHARED_CONTEXT[key];
|
|
627
|
+
if (val !== void 0) return val;
|
|
628
|
+
return globalVarNotFound(key);
|
|
976
629
|
}
|
|
977
630
|
/** @inheritdoc */
|
|
978
631
|
has(key) {
|
|
979
|
-
return this.getter(key) !== void 0 ||
|
|
632
|
+
return this.getter(key) !== void 0 || key in VM_SHARED_CONTEXT;
|
|
633
|
+
}
|
|
634
|
+
/** @inheritdoc */
|
|
635
|
+
describe(key) {
|
|
636
|
+
if (this.getter(key) !== void 0) return this.describer?.(key);
|
|
637
|
+
return VM_SHARED_CONTEXT_DESCRIPTIONS[key];
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
defineProperty(FactoryVmContext.prototype, kVmContext, { value: true });
|
|
641
|
+
freeze(FactoryVmContext.prototype);
|
|
642
|
+
function createVmContext(arg0 = null, arg1 = null, describer = null) {
|
|
643
|
+
if (typeof arg0 == "function") {
|
|
644
|
+
const getter = arg0;
|
|
645
|
+
const enumerator = arg1;
|
|
646
|
+
return new FactoryVmContext(getter, enumerator, describer);
|
|
647
|
+
}
|
|
648
|
+
const vmValues = arg0;
|
|
649
|
+
const externValues = arg1;
|
|
650
|
+
if (externValues == null) {
|
|
651
|
+
if (vmValues == null) {
|
|
652
|
+
return DefaultVmContext;
|
|
653
|
+
}
|
|
654
|
+
return new ValueVmContext(vmValues, describer);
|
|
655
|
+
}
|
|
656
|
+
return new Value2VmContext(vmValues, externValues, describer);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
// src/vm/operations/index.ts
|
|
660
|
+
var operations_exports = {};
|
|
661
|
+
__export(operations_exports, {
|
|
662
|
+
$Add: () => $Add,
|
|
663
|
+
$Aeq: () => $Aeq,
|
|
664
|
+
$And: () => $And,
|
|
665
|
+
$ArrayRange: () => $ArrayRange,
|
|
666
|
+
$ArrayRangeExclusive: () => $ArrayRangeExclusive,
|
|
667
|
+
$ArraySpread: () => $ArraySpread,
|
|
668
|
+
$AssertInit: () => $AssertInit,
|
|
669
|
+
$AssertNonNil: () => $AssertNonNil,
|
|
670
|
+
$Call: () => $Call,
|
|
671
|
+
$Concat: () => $Concat,
|
|
672
|
+
$Cp: () => Cp,
|
|
673
|
+
$CpEnter: () => CpEnter,
|
|
674
|
+
$CpExit: () => CpExit,
|
|
675
|
+
$Div: () => $Div,
|
|
676
|
+
$El: () => $El,
|
|
677
|
+
$ElOpt: () => $ElOpt,
|
|
678
|
+
$Eq: () => $Eq,
|
|
679
|
+
$Fn: () => $Fn,
|
|
680
|
+
$Format: () => $Format,
|
|
681
|
+
$Get: () => $Get,
|
|
682
|
+
$GlobalFallback: () => $GlobalFallback,
|
|
683
|
+
$Gt: () => $Gt,
|
|
684
|
+
$Gte: () => $Gte,
|
|
685
|
+
$Has: () => $Has,
|
|
686
|
+
$In: () => $In,
|
|
687
|
+
$IsArray: () => $IsArray,
|
|
688
|
+
$IsBoolean: () => $IsBoolean,
|
|
689
|
+
$IsNumber: () => $IsNumber,
|
|
690
|
+
$IsRecord: () => $IsRecord,
|
|
691
|
+
$IsString: () => $IsString,
|
|
692
|
+
$Iterable: () => $Iterable,
|
|
693
|
+
$Length: () => $Length,
|
|
694
|
+
$Lt: () => $Lt,
|
|
695
|
+
$Lte: () => $Lte,
|
|
696
|
+
$Mod: () => $Mod,
|
|
697
|
+
$Mul: () => $Mul,
|
|
698
|
+
$Naeq: () => $Naeq,
|
|
699
|
+
$Neg: () => $Neg,
|
|
700
|
+
$Neq: () => $Neq,
|
|
701
|
+
$Not: () => $Not,
|
|
702
|
+
$Nsame: () => $Nsame,
|
|
703
|
+
$Omit: () => $Omit,
|
|
704
|
+
$Or: () => $Or,
|
|
705
|
+
$Pick: () => $Pick,
|
|
706
|
+
$Pos: () => $Pos,
|
|
707
|
+
$Pow: () => $Pow,
|
|
708
|
+
$RecordSpread: () => $RecordSpread,
|
|
709
|
+
$Same: () => $Same,
|
|
710
|
+
$Set: () => $Set,
|
|
711
|
+
$Slice: () => $Slice,
|
|
712
|
+
$SliceExclusive: () => $SliceExclusive,
|
|
713
|
+
$Sub: () => $Sub,
|
|
714
|
+
$ToBoolean: () => $ToBoolean,
|
|
715
|
+
$ToNumber: () => $ToNumber,
|
|
716
|
+
$ToString: () => $ToString,
|
|
717
|
+
$Type: () => $Type,
|
|
718
|
+
$Upvalue: () => $Upvalue,
|
|
719
|
+
$VArgs: () => $VArgs
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// src/vm/operations/convert.ts
|
|
723
|
+
var $ToBoolean = (value) => {
|
|
724
|
+
if (typeof value == "boolean") return value;
|
|
725
|
+
$AssertInit(value);
|
|
726
|
+
return toBoolean(value, void 0);
|
|
727
|
+
};
|
|
728
|
+
var $ToString = (value) => {
|
|
729
|
+
if (typeof value == "string") return value;
|
|
730
|
+
$AssertInit(value);
|
|
731
|
+
return toString(value, void 0);
|
|
732
|
+
};
|
|
733
|
+
var $ToNumber = (value) => {
|
|
734
|
+
if (typeof value == "number") return value;
|
|
735
|
+
$AssertInit(value);
|
|
736
|
+
return toNumber(value, void 0);
|
|
737
|
+
};
|
|
738
|
+
var $Format = (value, format2) => {
|
|
739
|
+
$AssertInit(value);
|
|
740
|
+
const f = format2 == null ? "" : $ToString(format2);
|
|
741
|
+
return toFormat(value, f);
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
// src/vm/operations/type-check.ts
|
|
745
|
+
var $Type = (value) => {
|
|
746
|
+
if (value == null) return "nil";
|
|
747
|
+
if (isVmWrapper(value)) return value.type;
|
|
748
|
+
if (isVmArray(value)) return "array";
|
|
749
|
+
if (typeof value == "object") return "record";
|
|
750
|
+
return typeof value;
|
|
751
|
+
};
|
|
752
|
+
var $IsBoolean = (value) => {
|
|
753
|
+
$AssertInit(value);
|
|
754
|
+
return typeof value == "boolean";
|
|
755
|
+
};
|
|
756
|
+
var $IsNumber = (value) => {
|
|
757
|
+
$AssertInit(value);
|
|
758
|
+
return typeof value == "number";
|
|
759
|
+
};
|
|
760
|
+
var $IsString = (value) => {
|
|
761
|
+
$AssertInit(value);
|
|
762
|
+
return typeof value == "string";
|
|
763
|
+
};
|
|
764
|
+
var $IsRecord = (value) => {
|
|
765
|
+
$AssertInit(value);
|
|
766
|
+
return isVmRecord(value);
|
|
767
|
+
};
|
|
768
|
+
var $IsArray = (value) => {
|
|
769
|
+
$AssertInit(value);
|
|
770
|
+
return isVmArray(value);
|
|
771
|
+
};
|
|
772
|
+
var $AssertNonNil = (value) => {
|
|
773
|
+
$AssertInit(value);
|
|
774
|
+
if (value !== null) return;
|
|
775
|
+
throw new VmError(`Expected non-nil value`, null);
|
|
776
|
+
};
|
|
777
|
+
|
|
778
|
+
// src/vm/operations/utils.ts
|
|
779
|
+
function overloadNumberString(a, b) {
|
|
780
|
+
if (typeof a == "number" || typeof b == "number") return true;
|
|
781
|
+
if (typeof a == "string" || typeof b == "string") return false;
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
function isSame(a, b) {
|
|
785
|
+
if (typeof a == "number" && typeof b == "number") {
|
|
786
|
+
return a === b || isNaN(a) && isNaN(b);
|
|
787
|
+
}
|
|
788
|
+
if (a === b) return true;
|
|
789
|
+
if (a == null || typeof a != "object" || b == null || typeof b != "object") return false;
|
|
790
|
+
if (isVmWrapper(a)) return a.same(b);
|
|
791
|
+
if (isVmWrapper(b)) return b.same(a);
|
|
792
|
+
if (isVmArray(a) && isVmArray(b)) {
|
|
793
|
+
const len2 = a.length;
|
|
794
|
+
if (len2 !== b.length) {
|
|
795
|
+
return false;
|
|
796
|
+
}
|
|
797
|
+
for (let i = 0; i < len2; i++) {
|
|
798
|
+
if (!isSame(a[i] ?? null, b[i] ?? null)) {
|
|
799
|
+
return false;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
return true;
|
|
803
|
+
}
|
|
804
|
+
if (!isVmArray(a) && !isVmArray(b)) {
|
|
805
|
+
const aKeys = keys(a);
|
|
806
|
+
const bKeys = keys(b);
|
|
807
|
+
if (aKeys.length !== bKeys.length) {
|
|
808
|
+
return false;
|
|
809
|
+
}
|
|
810
|
+
for (const key of aKeys) {
|
|
811
|
+
if (!hasOwnEnumerable(b, key)) {
|
|
812
|
+
return false;
|
|
813
|
+
}
|
|
814
|
+
const av = a[key] ?? null;
|
|
815
|
+
const bv = b[key] ?? null;
|
|
816
|
+
if (!isSame(av, bv)) {
|
|
817
|
+
return false;
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
return true;
|
|
821
|
+
}
|
|
822
|
+
return false;
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// src/vm/operations/operator.ts
|
|
826
|
+
var $Concat = (...args) => {
|
|
827
|
+
return args.map((a) => toFormat(a, null)).join("");
|
|
828
|
+
};
|
|
829
|
+
var $Pos = (a) => {
|
|
830
|
+
return $ToNumber(a);
|
|
831
|
+
};
|
|
832
|
+
var $Neg = (a) => {
|
|
833
|
+
return -$ToNumber(a);
|
|
834
|
+
};
|
|
835
|
+
var $Not = (a) => {
|
|
836
|
+
return !$ToBoolean(a);
|
|
837
|
+
};
|
|
838
|
+
var $Add = (a, b) => {
|
|
839
|
+
return $ToNumber(a) + $ToNumber(b);
|
|
840
|
+
};
|
|
841
|
+
var $Sub = (a, b) => {
|
|
842
|
+
return $ToNumber(a) - $ToNumber(b);
|
|
843
|
+
};
|
|
844
|
+
var $Mul = (a, b) => {
|
|
845
|
+
return $ToNumber(a) * $ToNumber(b);
|
|
846
|
+
};
|
|
847
|
+
var $Div = (a, b) => {
|
|
848
|
+
return $ToNumber(a) / $ToNumber(b);
|
|
849
|
+
};
|
|
850
|
+
var $Mod = (a, b) => {
|
|
851
|
+
return $ToNumber(a) % $ToNumber(b);
|
|
852
|
+
};
|
|
853
|
+
var $Pow = (a, b) => {
|
|
854
|
+
return $ToNumber(a) ** $ToNumber(b);
|
|
855
|
+
};
|
|
856
|
+
var $And = (a, b) => {
|
|
857
|
+
return $ToBoolean(a) && $ToBoolean(b);
|
|
858
|
+
};
|
|
859
|
+
var $Or = (a, b) => {
|
|
860
|
+
return $ToBoolean(a) || $ToBoolean(b);
|
|
861
|
+
};
|
|
862
|
+
var $Gt = (a, b) => {
|
|
863
|
+
if (overloadNumberString(a, b)) {
|
|
864
|
+
return $ToNumber(a) > $ToNumber(b);
|
|
865
|
+
} else {
|
|
866
|
+
return $ToString(a) > $ToString(b);
|
|
980
867
|
}
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
return
|
|
868
|
+
};
|
|
869
|
+
var $Gte = (a, b) => {
|
|
870
|
+
if (overloadNumberString(a, b)) {
|
|
871
|
+
return $ToNumber(a) >= $ToNumber(b);
|
|
872
|
+
} else {
|
|
873
|
+
return $ToString(a) >= $ToString(b);
|
|
985
874
|
}
|
|
986
875
|
};
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
return
|
|
876
|
+
var $Lt = (a, b) => {
|
|
877
|
+
if (overloadNumberString(a, b)) {
|
|
878
|
+
return $ToNumber(a) < $ToNumber(b);
|
|
879
|
+
} else {
|
|
880
|
+
return $ToString(a) < $ToString(b);
|
|
992
881
|
}
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
return
|
|
882
|
+
};
|
|
883
|
+
var $Lte = (a, b) => {
|
|
884
|
+
if (overloadNumberString(a, b)) {
|
|
885
|
+
return $ToNumber(a) <= $ToNumber(b);
|
|
886
|
+
} else {
|
|
887
|
+
return $ToString(a) <= $ToString(b);
|
|
997
888
|
}
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
889
|
+
};
|
|
890
|
+
var $Eq = (a, b) => {
|
|
891
|
+
$AssertInit(a);
|
|
892
|
+
$AssertInit(b);
|
|
893
|
+
if (typeof a == "number" && typeof b == "number") return a === b;
|
|
894
|
+
return isSame(a, b);
|
|
895
|
+
};
|
|
896
|
+
var $Neq = (a, b) => {
|
|
897
|
+
return !$Eq(a, b);
|
|
898
|
+
};
|
|
899
|
+
var { abs, min } = Math;
|
|
900
|
+
var $Aeq = (a, b) => {
|
|
901
|
+
if (overloadNumberString(a, b)) {
|
|
902
|
+
const an = $ToNumber(a);
|
|
903
|
+
const bn = $ToNumber(b);
|
|
904
|
+
const EPS = 1e-15;
|
|
905
|
+
if (isNaN(an) || isNaN(bn)) return false;
|
|
906
|
+
if (an === bn) return true;
|
|
907
|
+
const absoluteDifference = abs(an - bn);
|
|
908
|
+
if (absoluteDifference < EPS) return true;
|
|
909
|
+
const base = min(abs(an), abs(bn));
|
|
910
|
+
return absoluteDifference < base * EPS;
|
|
911
|
+
} else {
|
|
912
|
+
const as = $ToString(a);
|
|
913
|
+
const bs = $ToString(b);
|
|
914
|
+
if (as === bs) return true;
|
|
915
|
+
const ai = as.toLowerCase();
|
|
916
|
+
const bi = bs.toLowerCase();
|
|
917
|
+
if (ai === bi) return true;
|
|
918
|
+
const an = ai.normalize("NFC");
|
|
919
|
+
const bn = bi.normalize("NFC");
|
|
920
|
+
return an === bn;
|
|
1006
921
|
}
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
922
|
+
};
|
|
923
|
+
var $Naeq = (a, b) => {
|
|
924
|
+
return !$Aeq(a, b);
|
|
925
|
+
};
|
|
926
|
+
var $Same = (a, b) => {
|
|
927
|
+
$AssertInit(a);
|
|
928
|
+
$AssertInit(b);
|
|
929
|
+
return isSame(a, b);
|
|
930
|
+
};
|
|
931
|
+
var $Nsame = (a, b) => {
|
|
932
|
+
return !$Same(a, b);
|
|
933
|
+
};
|
|
934
|
+
|
|
935
|
+
// src/vm/operations/slice.ts
|
|
936
|
+
var { ceil } = Math;
|
|
937
|
+
var { slice } = Array.prototype;
|
|
938
|
+
var sliceCore = (value, start, end, exclusive) => {
|
|
939
|
+
const { length } = value;
|
|
940
|
+
if (isNaN(start)) start = 0;
|
|
941
|
+
else if (start < 0) start = length + start;
|
|
942
|
+
if (isNaN(end)) end = exclusive ? length : length - 1;
|
|
943
|
+
else if (end < 0) end = length + end;
|
|
944
|
+
start = ceil(start);
|
|
945
|
+
if (exclusive || !isSafeInteger(end)) {
|
|
946
|
+
end = ceil(end);
|
|
947
|
+
} else {
|
|
948
|
+
end = end + 1;
|
|
1011
949
|
}
|
|
1012
|
-
return
|
|
1013
|
-
}
|
|
950
|
+
return slice.call(value, start, end);
|
|
951
|
+
};
|
|
952
|
+
var $Slice = (value, start, end) => {
|
|
953
|
+
$AssertInit(value);
|
|
954
|
+
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
955
|
+
const s = start != null ? $ToNumber(start) : 0;
|
|
956
|
+
const e = end != null ? $ToNumber(end) : value.length - 1;
|
|
957
|
+
return sliceCore(value, s, e, false);
|
|
958
|
+
};
|
|
959
|
+
var $SliceExclusive = (value, start, end) => {
|
|
960
|
+
$AssertInit(value);
|
|
961
|
+
if (!isVmArray(value)) throw new VmError(`Expected array, got ${display(value)}`, []);
|
|
962
|
+
const s = start != null ? $ToNumber(start) : 0;
|
|
963
|
+
const e = end != null ? $ToNumber(end) : value.length;
|
|
964
|
+
return sliceCore(value, s, e, true);
|
|
965
|
+
};
|
|
1014
966
|
|
|
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) => {
|
|
967
|
+
// src/vm/operations/helpers.ts
|
|
968
|
+
var $VArgs = (varags) => {
|
|
1031
969
|
for (let i = 0, l = varags.length; i < l; i++) {
|
|
1032
970
|
const el = varags[i];
|
|
1033
971
|
if (!isVmConst(el)) {
|
|
@@ -1036,22 +974,22 @@ var Vargs = (varags) => {
|
|
|
1036
974
|
}
|
|
1037
975
|
return varags;
|
|
1038
976
|
};
|
|
1039
|
-
var
|
|
977
|
+
var $El = (value) => {
|
|
1040
978
|
$AssertInit(value);
|
|
1041
979
|
if (!isVmConst(value)) return null;
|
|
1042
980
|
return value;
|
|
1043
981
|
};
|
|
1044
982
|
var EMPTY = create(null);
|
|
1045
|
-
var
|
|
983
|
+
var $ElOpt = (key, value) => {
|
|
1046
984
|
$AssertInit(value);
|
|
1047
985
|
if (value == null || !isVmConst(value)) return EMPTY;
|
|
1048
986
|
return { __proto__: null, [key]: value };
|
|
1049
987
|
};
|
|
1050
|
-
var
|
|
988
|
+
var $Fn = (name, fn) => {
|
|
1051
989
|
defineProperty(fn, "name", { value: name || VM_FUNCTION_ANONYMOUS_NAME });
|
|
1052
990
|
return VmFunction(fn, { isLib: false, injectCp: false });
|
|
1053
991
|
};
|
|
1054
|
-
var Upvalue = (value) => {
|
|
992
|
+
var $Upvalue = (value) => {
|
|
1055
993
|
$AssertInit(value);
|
|
1056
994
|
return value;
|
|
1057
995
|
};
|
|
@@ -1063,7 +1001,7 @@ var assertArrayLength = (start, end) => {
|
|
|
1063
1001
|
var isEmptyRange = (start, end) => {
|
|
1064
1002
|
return !isFinite(start) || !isFinite(end) || start > end;
|
|
1065
1003
|
};
|
|
1066
|
-
var ArrayRange = (start, end) => {
|
|
1004
|
+
var $ArrayRange = (start, end) => {
|
|
1067
1005
|
const s = $ToNumber(start);
|
|
1068
1006
|
const e = $ToNumber(end);
|
|
1069
1007
|
if (isEmptyRange(s, e)) return [];
|
|
@@ -1074,7 +1012,7 @@ var ArrayRange = (start, end) => {
|
|
|
1074
1012
|
}
|
|
1075
1013
|
return arr;
|
|
1076
1014
|
};
|
|
1077
|
-
var ArrayRangeExclusive = (start, end) => {
|
|
1015
|
+
var $ArrayRangeExclusive = (start, end) => {
|
|
1078
1016
|
const s = $ToNumber(start);
|
|
1079
1017
|
const e = $ToNumber(end);
|
|
1080
1018
|
if (isEmptyRange(s, e)) return [];
|
|
@@ -1085,29 +1023,138 @@ var ArrayRangeExclusive = (start, end) => {
|
|
|
1085
1023
|
}
|
|
1086
1024
|
return arr;
|
|
1087
1025
|
};
|
|
1088
|
-
function GlobalFallback() {
|
|
1026
|
+
function $GlobalFallback() {
|
|
1089
1027
|
return DefaultVmContext;
|
|
1090
1028
|
}
|
|
1091
1029
|
|
|
1092
|
-
// src/
|
|
1093
|
-
|
|
1094
|
-
var
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1030
|
+
// src/vm/operations/compound.ts
|
|
1031
|
+
var { trunc } = Math;
|
|
1032
|
+
var { at } = Array.prototype;
|
|
1033
|
+
var $In = (value, iterable) => {
|
|
1034
|
+
$AssertInit(value);
|
|
1035
|
+
$AssertInit(iterable);
|
|
1036
|
+
if (iterable == null) return false;
|
|
1037
|
+
if (typeof iterable != "object") return false;
|
|
1038
|
+
if (isVmArray(iterable)) {
|
|
1039
|
+
if (value == null) {
|
|
1040
|
+
for (const item of iterable) if (item == null) return true;
|
|
1041
|
+
return false;
|
|
1042
|
+
}
|
|
1043
|
+
if (isVmPrimitive(value)) return iterable.includes(value);
|
|
1044
|
+
return iterable.some((item = null) => isSame(item, value));
|
|
1045
|
+
}
|
|
1046
|
+
const key = toString(value, void 0);
|
|
1047
|
+
if (isVmWrapper(iterable)) return iterable.has(key);
|
|
1048
|
+
return hasOwnEnumerable(iterable, key);
|
|
1049
|
+
};
|
|
1050
|
+
var $Length = (value) => {
|
|
1051
|
+
$AssertInit(value);
|
|
1052
|
+
if (isVmArray(value)) return value.length;
|
|
1053
|
+
if (isVmRecord(value)) return keys(value).length;
|
|
1054
|
+
if (isVmWrapper(value)) return value.keys().length;
|
|
1055
|
+
throw new VmError(`Value has no length: ${display(value)}`, 0);
|
|
1056
|
+
};
|
|
1057
|
+
var $Omit = (value, omitted) => {
|
|
1058
|
+
$AssertInit(value);
|
|
1059
|
+
if (value == null || !isVmRecord(value)) return {};
|
|
1060
|
+
const result = {};
|
|
1061
|
+
const valueKeys = keys(value);
|
|
1062
|
+
const omittedSet = new Set(omitted.map($ToString));
|
|
1063
|
+
for (const key of valueKeys) {
|
|
1064
|
+
if (!omittedSet.has(key)) {
|
|
1065
|
+
result[key] = value[key] ?? null;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
return result;
|
|
1069
|
+
};
|
|
1070
|
+
var $Pick = (value, picked) => {
|
|
1071
|
+
$AssertInit(value);
|
|
1072
|
+
if (value == null || !isVmRecord(value)) return {};
|
|
1073
|
+
const result = {};
|
|
1074
|
+
for (const key of picked) {
|
|
1075
|
+
const k = $ToString(key);
|
|
1076
|
+
if (hasOwnEnumerable(value, k)) {
|
|
1077
|
+
result[k] = value[k] ?? null;
|
|
1078
|
+
}
|
|
1079
|
+
}
|
|
1080
|
+
return result;
|
|
1081
|
+
};
|
|
1082
|
+
var $Has = (obj, key) => {
|
|
1083
|
+
$AssertInit(obj);
|
|
1084
|
+
const pk = $ToString(key);
|
|
1085
|
+
if (obj == null || typeof obj != "object") return false;
|
|
1086
|
+
if (isVmWrapper(obj)) return obj.has(pk);
|
|
1087
|
+
return hasOwnEnumerable(obj, pk);
|
|
1088
|
+
};
|
|
1089
|
+
var $Get = (obj, key) => {
|
|
1090
|
+
$AssertInit(obj);
|
|
1091
|
+
if (isVmArray(obj)) {
|
|
1092
|
+
const index = $ToNumber(key);
|
|
1093
|
+
if (isNaN(index)) return null;
|
|
1094
|
+
return at.call(obj, trunc(index)) ?? null;
|
|
1095
|
+
}
|
|
1096
|
+
const pk = $ToString(key);
|
|
1097
|
+
if (obj == null || typeof obj != "object") return null;
|
|
1098
|
+
if (isVmWrapper(obj)) return obj.get(pk) ?? null;
|
|
1099
|
+
if (!hasOwnEnumerable(obj, pk)) return null;
|
|
1100
|
+
return obj[pk] ?? null;
|
|
1101
|
+
};
|
|
1102
|
+
var $Set = (obj, key, value) => {
|
|
1103
|
+
$AssertInit(obj);
|
|
1104
|
+
$AssertInit(value);
|
|
1105
|
+
const pk = $ToString(key);
|
|
1106
|
+
if (obj == null) return;
|
|
1107
|
+
if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${display(obj)}`, void 0);
|
|
1108
|
+
obj.set(pk, value);
|
|
1109
|
+
};
|
|
1110
|
+
var $Iterable = (value) => {
|
|
1111
|
+
$AssertInit(value);
|
|
1112
|
+
if (isVmWrapper(value)) return value.keys();
|
|
1113
|
+
if (isVmArray(value)) return value;
|
|
1114
|
+
if (value != null && typeof value == "object") return keys(value);
|
|
1115
|
+
throw new VmError(`Value is not iterable: ${display(value)}`, isVmFunction(value) ? [] : [value]);
|
|
1116
|
+
};
|
|
1117
|
+
var $RecordSpread = (record) => {
|
|
1118
|
+
$AssertInit(record);
|
|
1119
|
+
if (record == null || isVmRecord(record)) return record;
|
|
1120
|
+
if (isVmArray(record)) {
|
|
1121
|
+
const result = {};
|
|
1122
|
+
const len2 = record.length;
|
|
1123
|
+
for (let i = 0; i < len2; i++) {
|
|
1124
|
+
const item = record[i];
|
|
1125
|
+
result[i] = item ?? null;
|
|
1126
|
+
}
|
|
1127
|
+
return result;
|
|
1128
|
+
}
|
|
1129
|
+
if (isVmExtern(record)) {
|
|
1130
|
+
const result = create(null);
|
|
1131
|
+
for (const key of record.keys()) {
|
|
1132
|
+
const value = record.get(key) ?? null;
|
|
1133
|
+
if (isVmPrimitive(value)) {
|
|
1134
|
+
result[key] = value;
|
|
1135
|
+
}
|
|
1136
|
+
}
|
|
1137
|
+
return result;
|
|
1138
|
+
}
|
|
1139
|
+
throw new VmError(`Expected record, array, extern or nil, got ${display(record)}`, null);
|
|
1140
|
+
};
|
|
1141
|
+
var $ArraySpread = (array) => {
|
|
1142
|
+
$AssertInit(array);
|
|
1143
|
+
if (array == null) return [];
|
|
1144
|
+
if (isVmArray(array)) return array;
|
|
1145
|
+
if (isVmExtern(array) && typeof array.value[Symbol.iterator] == "function") {
|
|
1146
|
+
const result = [];
|
|
1147
|
+
for (const item of array.value) {
|
|
1148
|
+
if (isVmPrimitive(item)) {
|
|
1149
|
+
result.push(item);
|
|
1150
|
+
} else {
|
|
1151
|
+
result.push(null);
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
return result;
|
|
1155
|
+
}
|
|
1156
|
+
throw new VmError(`Expected array, iterable extern or nil, got ${display(array)}`, []);
|
|
1098
1157
|
};
|
|
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
1158
|
|
|
1112
1159
|
// src/compiler/create-script.ts
|
|
1113
1160
|
function wrapScript(source, mode, script) {
|
|
@@ -1123,16 +1170,34 @@ function wrapScript(source, mode, script) {
|
|
|
1123
1170
|
}
|
|
1124
1171
|
return script;
|
|
1125
1172
|
}
|
|
1173
|
+
var [keys2, values2] = (() => {
|
|
1174
|
+
const keys4 = [];
|
|
1175
|
+
const values4 = [];
|
|
1176
|
+
for (const [key, value] of entries(operations_exports)) {
|
|
1177
|
+
keys4.push(key);
|
|
1178
|
+
values4.push(value);
|
|
1179
|
+
}
|
|
1180
|
+
return [keys4.join(","), values4];
|
|
1181
|
+
})();
|
|
1126
1182
|
function createScript(source, mode, code) {
|
|
1127
1183
|
let script;
|
|
1128
1184
|
try {
|
|
1129
|
-
script = new Function(
|
|
1185
|
+
script = new Function(keys2, `'use strict';
|
|
1186
|
+
return ${code}`)(...values2);
|
|
1130
1187
|
} catch (error) {
|
|
1131
1188
|
throw new Error(`Failed to create script`, { cause: error });
|
|
1132
1189
|
}
|
|
1133
1190
|
return wrapScript(source, mode, script);
|
|
1134
1191
|
}
|
|
1135
1192
|
|
|
1193
|
+
// src/compiler/keywords.ts
|
|
1194
|
+
import { getModule } from "@mirascript/bindings";
|
|
1195
|
+
var keywords = () => {
|
|
1196
|
+
const kw = Object.freeze(getModule().keywords());
|
|
1197
|
+
keywords = () => kw;
|
|
1198
|
+
return kw;
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1136
1201
|
// src/compiler/emit-script.ts
|
|
1137
1202
|
function reportDiagnostic(source, diagnostics, fileName) {
|
|
1138
1203
|
const parsed = parseDiagnostics(source, diagnostics);
|
|
@@ -1927,7 +1992,7 @@ var normalizeEntries = (data, entries3) => {
|
|
|
1927
1992
|
}
|
|
1928
1993
|
}
|
|
1929
1994
|
const value = entries3[i + 1];
|
|
1930
|
-
entryData.set(key,
|
|
1995
|
+
entryData.set(key, $El(value));
|
|
1931
1996
|
}
|
|
1932
1997
|
return entryData;
|
|
1933
1998
|
};
|
|
@@ -2499,7 +2564,7 @@ var debug_print = VmLib(
|
|
|
2499
2564
|
var panic = VmLib(
|
|
2500
2565
|
(message) => {
|
|
2501
2566
|
if (message === void 0) console.error(...panic.prefix);
|
|
2502
|
-
else console.error(...panic.prefix, serializeValue(message, "", panic.serializer));
|
|
2567
|
+
else console.error(...panic.prefix, serializeValue(message, "", panic.serializer) ?? message);
|
|
2503
2568
|
const mgsStr = toString(message, null);
|
|
2504
2569
|
const error = !mgsStr ? "panic" : "panic: " + mgsStr;
|
|
2505
2570
|
throw new VmError(error, void 0);
|
|
@@ -3437,7 +3502,6 @@ var lib = Object.freeze(Object.assign(create(null), global_exports, mod_exports)
|
|
|
3437
3502
|
|
|
3438
3503
|
export {
|
|
3439
3504
|
convert_exports,
|
|
3440
|
-
operations_exports,
|
|
3441
3505
|
VmExtern,
|
|
3442
3506
|
wrapToVmValue,
|
|
3443
3507
|
unwrapFromVmValue,
|
|
@@ -3446,8 +3510,8 @@ export {
|
|
|
3446
3510
|
defineVmContextValue,
|
|
3447
3511
|
DefaultVmContext,
|
|
3448
3512
|
createVmContext,
|
|
3449
|
-
GlobalFallback,
|
|
3450
|
-
|
|
3513
|
+
$GlobalFallback,
|
|
3514
|
+
operations_exports,
|
|
3451
3515
|
wrapScript,
|
|
3452
3516
|
createScript,
|
|
3453
3517
|
keywords,
|
|
@@ -3458,4 +3522,4 @@ export {
|
|
|
3458
3522
|
panic,
|
|
3459
3523
|
lib
|
|
3460
3524
|
};
|
|
3461
|
-
//# sourceMappingURL=chunk-
|
|
3525
|
+
//# sourceMappingURL=chunk-UCIDBTZL.js.map
|