@mirascript/mirascript 0.1.13 → 0.1.14
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/dist/chunk-55FKP56O.js +2317 -0
- package/dist/chunk-55FKP56O.js.map +6 -0
- package/dist/{chunk-IKSSUVRE.js → chunk-Q74RKZ7O.js} +73 -1250
- package/dist/chunk-Q74RKZ7O.js.map +6 -0
- package/dist/cli/index.js +8 -7
- package/dist/cli/index.js.map +1 -1
- package/dist/compiler/emit.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/serialize.d.ts +1 -1
- package/dist/helpers/serialize.d.ts.map +1 -1
- package/dist/index.js +15 -9
- package/dist/subtle.d.ts +1 -1
- package/dist/subtle.d.ts.map +1 -1
- package/dist/subtle.js +7 -7
- package/dist/vm/lib/global/debug.d.ts +1 -1
- package/dist/vm/lib/global/json.d.ts +2 -2
- package/dist/vm/lib/global/json.d.ts.map +1 -1
- package/dist/vm/lib/global/mod/matrix.d.ts +1 -1
- package/dist/vm/lib/global/mod/matrix.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/all-any.d.ts +2 -2
- package/dist/vm/lib/global/sequence/entries.d.ts +4 -4
- package/dist/vm/lib/global/sequence/find.d.ts +2 -2
- package/dist/vm/lib/global/sequence/repeat.d.ts +1 -1
- package/dist/vm/lib/global/sequence/with.d.ts +1 -1
- package/dist/vm/lib/global/sequence/with.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/zip.d.ts +1 -1
- package/dist/vm/operations.d.ts +2 -0
- package/dist/vm/operations.d.ts.map +1 -1
- package/dist/vm/types/any.d.ts +10 -0
- package/dist/vm/types/any.d.ts.map +1 -0
- package/dist/vm/types/array.d.ts +12 -0
- package/dist/vm/types/array.d.ts.map +1 -0
- package/dist/vm/types/callable.d.ts +5 -0
- package/dist/vm/types/callable.d.ts.map +1 -0
- package/dist/vm/types/const.d.ts +15 -0
- package/dist/vm/types/const.d.ts.map +1 -0
- package/dist/vm/types/context.d.ts.map +1 -1
- package/dist/vm/types/extern.d.ts +1 -1
- package/dist/vm/types/extern.d.ts.map +1 -1
- package/dist/vm/types/immutable.d.ts +15 -0
- package/dist/vm/types/immutable.d.ts.map +1 -0
- package/dist/vm/types/index.d.ts +17 -47
- package/dist/vm/types/index.d.ts.map +1 -1
- package/dist/vm/types/primitive.d.ts +7 -0
- package/dist/vm/types/primitive.d.ts.map +1 -0
- package/dist/vm/types/record.d.ts +20 -0
- package/dist/vm/types/record.d.ts.map +1 -0
- package/dist/vm/types/value.d.ts +14 -0
- package/dist/vm/types/value.d.ts.map +1 -0
- package/dist/vm/types/wrapper.d.ts +1 -1
- package/dist/vm/types/wrapper.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/compiler/compile-fast.ts +1 -1
- package/src/compiler/emit.ts +131 -17
- package/src/helpers/serialize.ts +34 -14
- package/src/subtle.ts +1 -1
- package/src/vm/operations.ts +5 -5
- package/src/vm/types/any.ts +33 -0
- package/src/vm/types/array.ts +19 -0
- package/src/vm/types/callable.ts +10 -0
- package/src/vm/types/{checker.ts → const.ts} +7 -55
- package/src/vm/types/context.ts +5 -1
- package/src/vm/types/extern.ts +19 -5
- package/src/vm/types/immutable.ts +22 -0
- package/src/vm/types/index.ts +31 -83
- package/src/vm/types/primitive.ts +14 -0
- package/src/vm/types/record.ts +53 -0
- package/src/vm/types/value.ts +22 -0
- package/src/vm/types/wrapper.ts +1 -1
- package/dist/chunk-AGIXQM52.js +0 -916
- package/dist/chunk-AGIXQM52.js.map +0 -6
- package/dist/chunk-IKSSUVRE.js.map +0 -6
- package/dist/vm/types/checker.d.ts +0 -30
- package/dist/vm/types/checker.d.ts.map +0 -1
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
+
$Add,
|
|
3
|
+
$Call,
|
|
4
|
+
$Div,
|
|
5
|
+
$Format,
|
|
6
|
+
$Mul,
|
|
7
|
+
$Same,
|
|
8
|
+
$Sub,
|
|
9
|
+
$ToBoolean,
|
|
10
|
+
$ToNumber,
|
|
11
|
+
$ToString,
|
|
12
|
+
$Type,
|
|
13
|
+
Cp,
|
|
2
14
|
DiagnosticCode,
|
|
15
|
+
Element,
|
|
16
|
+
GlobalFallback,
|
|
17
|
+
VM_ARRAY_MAX_LENGTH,
|
|
18
|
+
VmError,
|
|
19
|
+
VmFunction,
|
|
20
|
+
VmModule,
|
|
21
|
+
VmSharedContext,
|
|
3
22
|
__export,
|
|
4
|
-
apply,
|
|
5
23
|
create,
|
|
6
24
|
defineProperty,
|
|
7
25
|
emit,
|
|
@@ -10,18 +28,27 @@ import {
|
|
|
10
28
|
fromEntries,
|
|
11
29
|
generateBytecode,
|
|
12
30
|
generateBytecodeSync,
|
|
13
|
-
getPrototypeOf,
|
|
14
31
|
hasOwn,
|
|
15
|
-
|
|
32
|
+
helpers_exports,
|
|
16
33
|
isArray,
|
|
17
34
|
isFinite,
|
|
18
35
|
isInteger,
|
|
19
36
|
isNaN,
|
|
20
37
|
isSafeInteger,
|
|
38
|
+
isVmArray,
|
|
39
|
+
isVmArrayLikeRecordByEntires,
|
|
40
|
+
isVmCallable,
|
|
41
|
+
isVmConst,
|
|
42
|
+
isVmExtern,
|
|
43
|
+
isVmFunction,
|
|
44
|
+
isVmModule,
|
|
45
|
+
isVmPrimitive,
|
|
46
|
+
isVmRecord,
|
|
21
47
|
keys,
|
|
48
|
+
operations_exports,
|
|
22
49
|
parseDiagnostics,
|
|
23
50
|
values
|
|
24
|
-
} from "./chunk-
|
|
51
|
+
} from "./chunk-55FKP56O.js";
|
|
25
52
|
|
|
26
53
|
// src/subtle.ts
|
|
27
54
|
import { getModule } from "@mirascript/bindings";
|
|
@@ -35,1202 +62,12 @@ __export(constants_exports, {
|
|
|
35
62
|
var REG_IDENTIFIER = /(?:_+|@+|\$+|\p{XID_Start})\p{XID_Continue}*/u;
|
|
36
63
|
var REG_ORDINAL = /(?:0|[1-9]\d{0,8}|1\d{9}|20\d{8}|21[0-3]\d{7}|214[0-6]\d{6}|2147[0-3]\d{5}|21474[0-7]\d{4}|214748[0-2]\d{3}|2147483[0-5]\d{2}|21474836[0-3]\d|214748364[0-7])/;
|
|
37
64
|
|
|
38
|
-
// src/vm/error.ts
|
|
39
|
-
var VmError = class _VmError extends Error {
|
|
40
|
-
constructor(message, recovered) {
|
|
41
|
-
super(message);
|
|
42
|
-
this.recovered = recovered;
|
|
43
|
-
this.name = "VmError";
|
|
44
|
-
}
|
|
45
|
-
/** 从其他错误构造 */
|
|
46
|
-
static from(prefix, error, recovered) {
|
|
47
|
-
if (prefix) {
|
|
48
|
-
if (prefix.endsWith(":")) {
|
|
49
|
-
prefix += " ";
|
|
50
|
-
} else if (!prefix.endsWith(": ")) {
|
|
51
|
-
prefix += ": ";
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
let vmError;
|
|
55
|
-
if (error instanceof Error) {
|
|
56
|
-
vmError = new _VmError(`${prefix}${error.message}`, recovered);
|
|
57
|
-
vmError.stack = error.stack;
|
|
58
|
-
} else {
|
|
59
|
-
vmError = new _VmError(`${prefix}${String(error)}`, recovered);
|
|
60
|
-
}
|
|
61
|
-
vmError.cause = error;
|
|
62
|
-
return vmError;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// src/vm/types/wrapper.ts
|
|
67
|
-
var VmWrapper = class {
|
|
68
|
-
constructor(value) {
|
|
69
|
-
this.value = value;
|
|
70
|
-
}
|
|
71
|
-
/** Convert the object to JSON */
|
|
72
|
-
toJSON() {
|
|
73
|
-
return void 0;
|
|
74
|
-
}
|
|
75
|
-
/** 转为字符串 */
|
|
76
|
-
toString() {
|
|
77
|
-
const { type, describe } = this;
|
|
78
|
-
if (!describe) return `<${type}>`;
|
|
79
|
-
return `<${type} ${describe}>`;
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
var kVmWrapper = Symbol.for("mirascript.vm.wrapper");
|
|
83
|
-
Object.defineProperty(VmWrapper.prototype, kVmWrapper, { value: true });
|
|
84
|
-
function isVmWrapper(value) {
|
|
85
|
-
return value != null && typeof value == "object" && kVmWrapper in value;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
// src/vm/helpers.ts
|
|
89
|
-
var helpers_exports = {};
|
|
90
|
-
__export(helpers_exports, {
|
|
91
|
-
ArrayRange: () => ArrayRange,
|
|
92
|
-
ArrayRangeExclusive: () => ArrayRangeExclusive,
|
|
93
|
-
Cp: () => Cp,
|
|
94
|
-
CpEnter: () => CpEnter,
|
|
95
|
-
CpExit: () => CpExit,
|
|
96
|
-
Element: () => Element,
|
|
97
|
-
ElementOpt: () => ElementOpt,
|
|
98
|
-
Function: () => Function2,
|
|
99
|
-
GlobalFallback: () => GlobalFallback,
|
|
100
|
-
Upvalue: () => Upvalue,
|
|
101
|
-
Vargs: () => Vargs,
|
|
102
|
-
configCheckpoint: () => configCheckpoint
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
// src/vm/operations.ts
|
|
106
|
-
var operations_exports = {};
|
|
107
|
-
__export(operations_exports, {
|
|
108
|
-
$Add: () => $Add,
|
|
109
|
-
$Aeq: () => $Aeq,
|
|
110
|
-
$And: () => $And,
|
|
111
|
-
$ArraySpread: () => $ArraySpread,
|
|
112
|
-
$AssertInit: () => $AssertInit,
|
|
113
|
-
$AssertNonNil: () => $AssertNonNil,
|
|
114
|
-
$Call: () => $Call,
|
|
115
|
-
$Concat: () => $Concat,
|
|
116
|
-
$Div: () => $Div,
|
|
117
|
-
$Eq: () => $Eq,
|
|
118
|
-
$Format: () => $Format,
|
|
119
|
-
$Get: () => $Get,
|
|
120
|
-
$Gt: () => $Gt,
|
|
121
|
-
$Gte: () => $Gte,
|
|
122
|
-
$Has: () => $Has,
|
|
123
|
-
$In: () => $In,
|
|
124
|
-
$IsArray: () => $IsArray,
|
|
125
|
-
$IsBoolean: () => $IsBoolean,
|
|
126
|
-
$IsNumber: () => $IsNumber,
|
|
127
|
-
$IsRecord: () => $IsRecord,
|
|
128
|
-
$IsString: () => $IsString,
|
|
129
|
-
$Iterable: () => $Iterable,
|
|
130
|
-
$Length: () => $Length,
|
|
131
|
-
$Lt: () => $Lt,
|
|
132
|
-
$Lte: () => $Lte,
|
|
133
|
-
$Mod: () => $Mod,
|
|
134
|
-
$Mul: () => $Mul,
|
|
135
|
-
$Naeq: () => $Naeq,
|
|
136
|
-
$Neg: () => $Neg,
|
|
137
|
-
$Neq: () => $Neq,
|
|
138
|
-
$Not: () => $Not,
|
|
139
|
-
$Nsame: () => $Nsame,
|
|
140
|
-
$Omit: () => $Omit,
|
|
141
|
-
$Or: () => $Or,
|
|
142
|
-
$Pick: () => $Pick,
|
|
143
|
-
$Pos: () => $Pos,
|
|
144
|
-
$Pow: () => $Pow,
|
|
145
|
-
$RecordSpread: () => $RecordSpread,
|
|
146
|
-
$Same: () => $Same,
|
|
147
|
-
$Set: () => $Set,
|
|
148
|
-
$Slice: () => $Slice,
|
|
149
|
-
$SliceExclusive: () => $SliceExclusive,
|
|
150
|
-
$Sub: () => $Sub,
|
|
151
|
-
$ToBoolean: () => $ToBoolean,
|
|
152
|
-
$ToNumber: () => $ToNumber,
|
|
153
|
-
$ToString: () => $ToString,
|
|
154
|
-
$Type: () => $Type
|
|
155
|
-
});
|
|
156
|
-
var { abs, min, trunc, ceil } = Math;
|
|
157
|
-
var { slice, at } = Array.prototype;
|
|
158
|
-
var { POSITIVE_INFINITY, NEGATIVE_INFINITY } = Number;
|
|
159
|
-
var isSame = (a, b) => {
|
|
160
|
-
if (typeof a == "number" && typeof b == "number") return a === b || isNaN(a) && isNaN(b);
|
|
161
|
-
if (a === b) return true;
|
|
162
|
-
if (a == null || typeof a != "object" || b == null || typeof b != "object") return false;
|
|
163
|
-
if (isVmWrapper(a)) return a.same(b);
|
|
164
|
-
if (isVmWrapper(b)) return b.same(a);
|
|
165
|
-
if (isVmArray(a) && isVmArray(b)) {
|
|
166
|
-
const len2 = a.length;
|
|
167
|
-
if (len2 !== b.length) {
|
|
168
|
-
return false;
|
|
169
|
-
}
|
|
170
|
-
for (let i = 0; i < len2; i++) {
|
|
171
|
-
if (!isSame(a[i] ?? null, b[i] ?? null)) {
|
|
172
|
-
return false;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
if (!isVmArray(a) && !isVmArray(b)) {
|
|
178
|
-
const aKeys = keys(a);
|
|
179
|
-
const bKeys = keys(b);
|
|
180
|
-
if (aKeys.length !== bKeys.length) {
|
|
181
|
-
return false;
|
|
182
|
-
}
|
|
183
|
-
for (const key of aKeys) {
|
|
184
|
-
if (!hasOwnEnumerable(b, key)) {
|
|
185
|
-
return false;
|
|
186
|
-
}
|
|
187
|
-
if (!isSame(a[key] ?? null, b[key] ?? null)) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
return true;
|
|
192
|
-
}
|
|
193
|
-
return false;
|
|
194
|
-
};
|
|
195
|
-
var overloadNumberString = (a, b) => {
|
|
196
|
-
if (typeof a == "number" || typeof b == "number") return true;
|
|
197
|
-
if (typeof a == "string" || typeof b == "string") return false;
|
|
198
|
-
return true;
|
|
199
|
-
};
|
|
200
|
-
var $Add = (a, b) => {
|
|
201
|
-
return $ToNumber(a) + $ToNumber(b);
|
|
202
|
-
};
|
|
203
|
-
var $Sub = (a, b) => {
|
|
204
|
-
return $ToNumber(a) - $ToNumber(b);
|
|
205
|
-
};
|
|
206
|
-
var $Mul = (a, b) => {
|
|
207
|
-
return $ToNumber(a) * $ToNumber(b);
|
|
208
|
-
};
|
|
209
|
-
var $Div = (a, b) => {
|
|
210
|
-
return $ToNumber(a) / $ToNumber(b);
|
|
211
|
-
};
|
|
212
|
-
var $Mod = (a, b) => {
|
|
213
|
-
return $ToNumber(a) % $ToNumber(b);
|
|
214
|
-
};
|
|
215
|
-
var $Pow = (a, b) => {
|
|
216
|
-
return $ToNumber(a) ** $ToNumber(b);
|
|
217
|
-
};
|
|
218
|
-
var $And = (a, b) => {
|
|
219
|
-
return $ToBoolean(a) && $ToBoolean(b);
|
|
220
|
-
};
|
|
221
|
-
var $Or = (a, b) => {
|
|
222
|
-
return $ToBoolean(a) || $ToBoolean(b);
|
|
223
|
-
};
|
|
224
|
-
var $Gt = (a, b) => {
|
|
225
|
-
if (overloadNumberString(a, b)) {
|
|
226
|
-
return $ToNumber(a) > $ToNumber(b);
|
|
227
|
-
} else {
|
|
228
|
-
return $ToString(a) > $ToString(b);
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
var $Gte = (a, b) => {
|
|
232
|
-
if (overloadNumberString(a, b)) {
|
|
233
|
-
return $ToNumber(a) >= $ToNumber(b);
|
|
234
|
-
} else {
|
|
235
|
-
return $ToString(a) >= $ToString(b);
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
var $Lt = (a, b) => {
|
|
239
|
-
if (overloadNumberString(a, b)) {
|
|
240
|
-
return $ToNumber(a) < $ToNumber(b);
|
|
241
|
-
} else {
|
|
242
|
-
return $ToString(a) < $ToString(b);
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
var $Lte = (a, b) => {
|
|
246
|
-
if (overloadNumberString(a, b)) {
|
|
247
|
-
return $ToNumber(a) <= $ToNumber(b);
|
|
248
|
-
} else {
|
|
249
|
-
return $ToString(a) <= $ToString(b);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
var $Eq = (a, b) => {
|
|
253
|
-
$AssertInit(a);
|
|
254
|
-
$AssertInit(b);
|
|
255
|
-
if (typeof a == "number" && typeof b == "number") return a === b;
|
|
256
|
-
return isSame(a, b);
|
|
257
|
-
};
|
|
258
|
-
var $Neq = (a, b) => {
|
|
259
|
-
return !$Eq(a, b);
|
|
260
|
-
};
|
|
261
|
-
var $Aeq = (a, b) => {
|
|
262
|
-
if (overloadNumberString(a, b)) {
|
|
263
|
-
const an = $ToNumber(a);
|
|
264
|
-
const bn = $ToNumber(b);
|
|
265
|
-
const EPS = 1e-15;
|
|
266
|
-
if (isNaN(an) || isNaN(bn)) return false;
|
|
267
|
-
if (an === bn) return true;
|
|
268
|
-
const absoluteDifference = abs(an - bn);
|
|
269
|
-
if (absoluteDifference < EPS) return true;
|
|
270
|
-
const base = min(abs(an), abs(bn));
|
|
271
|
-
return absoluteDifference < base * EPS;
|
|
272
|
-
} else {
|
|
273
|
-
const as = $ToString(a);
|
|
274
|
-
const bs = $ToString(b);
|
|
275
|
-
if (as === bs) return true;
|
|
276
|
-
const ai = as.toLowerCase();
|
|
277
|
-
const bi = bs.toLowerCase();
|
|
278
|
-
if (ai === bi) return true;
|
|
279
|
-
const an = ai.normalize("NFC");
|
|
280
|
-
const bn = bi.normalize("NFC");
|
|
281
|
-
return an === bn;
|
|
282
|
-
}
|
|
283
|
-
};
|
|
284
|
-
var $Naeq = (a, b) => {
|
|
285
|
-
return !$Aeq(a, b);
|
|
286
|
-
};
|
|
287
|
-
var $Same = (a, b) => {
|
|
288
|
-
$AssertInit(a);
|
|
289
|
-
$AssertInit(b);
|
|
290
|
-
return isSame(a, b);
|
|
291
|
-
};
|
|
292
|
-
var $Nsame = (a, b) => {
|
|
293
|
-
return !$Same(a, b);
|
|
294
|
-
};
|
|
295
|
-
var $In = (value, iterable) => {
|
|
296
|
-
$AssertInit(value);
|
|
297
|
-
$AssertInit(iterable);
|
|
298
|
-
if (iterable == null) return false;
|
|
299
|
-
if (isVmArray(iterable)) {
|
|
300
|
-
if (value == null) {
|
|
301
|
-
for (const item of iterable) {
|
|
302
|
-
if (item == null) return true;
|
|
303
|
-
}
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
if (isVmPrimitive(value)) return iterable.includes(value);
|
|
307
|
-
value;
|
|
308
|
-
return iterable.some((item = null) => isSame(item, value));
|
|
309
|
-
}
|
|
310
|
-
if (isVmWrapper(iterable)) return iterable.has($ToString(value));
|
|
311
|
-
if (typeof iterable == "object") return hasOwnEnumerable(iterable, $ToString(value));
|
|
312
|
-
iterable;
|
|
313
|
-
return false;
|
|
314
|
-
};
|
|
315
|
-
var $Concat = (...args) => {
|
|
316
|
-
return args.map($Format).join("");
|
|
317
|
-
};
|
|
318
|
-
var $Pos = (a) => {
|
|
319
|
-
return $ToNumber(a);
|
|
320
|
-
};
|
|
321
|
-
var $Neg = (a) => {
|
|
322
|
-
return -$ToNumber(a);
|
|
323
|
-
};
|
|
324
|
-
var $Not = (a) => {
|
|
325
|
-
return !$ToBoolean(a);
|
|
326
|
-
};
|
|
327
|
-
var $Length = (value) => {
|
|
328
|
-
$AssertInit(value);
|
|
329
|
-
if (isVmArray(value)) return value.length;
|
|
330
|
-
if (isVmRecord(value)) return keys(value).length;
|
|
331
|
-
if (isVmWrapper(value)) {
|
|
332
|
-
return value.keys().length;
|
|
333
|
-
}
|
|
334
|
-
return Number.NaN;
|
|
335
|
-
};
|
|
336
|
-
var $Omit = (value, omitted) => {
|
|
337
|
-
$AssertInit(value);
|
|
338
|
-
if (value == null || !isVmRecord(value)) return {};
|
|
339
|
-
const result = {};
|
|
340
|
-
const valueKeys = keys(value);
|
|
341
|
-
const omittedSet = new Set(omitted.map($ToString));
|
|
342
|
-
for (const key of valueKeys) {
|
|
343
|
-
if (!omittedSet.has(key)) {
|
|
344
|
-
result[key] = value[key] ?? null;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return result;
|
|
348
|
-
};
|
|
349
|
-
var $Pick = (value, picked) => {
|
|
350
|
-
$AssertInit(value);
|
|
351
|
-
if (value == null || !isVmRecord(value)) return {};
|
|
352
|
-
const result = {};
|
|
353
|
-
for (const key of picked) {
|
|
354
|
-
const k = $ToString(key);
|
|
355
|
-
if (hasOwnEnumerable(value, k)) {
|
|
356
|
-
result[k] = value[k] ?? null;
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
return result;
|
|
360
|
-
};
|
|
361
|
-
var sliceCore = (value, start, end, exclusive) => {
|
|
362
|
-
const { length } = value;
|
|
363
|
-
if (isNaN(start)) start = 0;
|
|
364
|
-
else if (start < 0) start = length + start;
|
|
365
|
-
if (isNaN(end)) end = exclusive ? length : length - 1;
|
|
366
|
-
else if (end < 0) end = length + end;
|
|
367
|
-
start = ceil(start);
|
|
368
|
-
if (exclusive || !isSafeInteger(end)) {
|
|
369
|
-
end = ceil(end);
|
|
370
|
-
} else {
|
|
371
|
-
end = end + 1;
|
|
372
|
-
}
|
|
373
|
-
return slice.call(value, start, end);
|
|
374
|
-
};
|
|
375
|
-
var $Slice = (value, start, end) => {
|
|
376
|
-
$AssertInit(value);
|
|
377
|
-
if (!isVmArray(value)) throw new VmError(`Expected array, got ${$Type(value)}`, []);
|
|
378
|
-
const s = start != null ? $ToNumber(start) : 0;
|
|
379
|
-
const e = end != null ? $ToNumber(end) : value.length - 1;
|
|
380
|
-
return sliceCore(value, s, e, false);
|
|
381
|
-
};
|
|
382
|
-
var $SliceExclusive = (value, start, end) => {
|
|
383
|
-
$AssertInit(value);
|
|
384
|
-
if (!isVmArray(value)) throw new VmError(`Expected array, got ${$Type(value)}`, []);
|
|
385
|
-
const s = start != null ? $ToNumber(start) : 0;
|
|
386
|
-
const e = end != null ? $ToNumber(end) : value.length;
|
|
387
|
-
return sliceCore(value, s, e, true);
|
|
388
|
-
};
|
|
389
|
-
var $AssertInit = (value) => {
|
|
390
|
-
if (value === void 0) throw new VmError(`Uninitialized value`, null);
|
|
391
|
-
};
|
|
392
|
-
var $Call = (func, args) => {
|
|
393
|
-
for (const a of args) {
|
|
394
|
-
$AssertInit(a);
|
|
395
|
-
}
|
|
396
|
-
if (isVmExtern(func)) {
|
|
397
|
-
return func.call(args) ?? null;
|
|
398
|
-
}
|
|
399
|
-
if (isVmFunction(func)) {
|
|
400
|
-
return func(...args) ?? null;
|
|
401
|
-
}
|
|
402
|
-
throw new VmError(`Expected callable, got ${$Type(func)}`, null);
|
|
403
|
-
};
|
|
404
|
-
var $Type = (value) => {
|
|
405
|
-
if (value === void 0 || value === null) return "nil";
|
|
406
|
-
if (isVmExtern(value)) return "extern";
|
|
407
|
-
if (isVmModule(value)) return "module";
|
|
408
|
-
if (isVmArray(value)) return "array";
|
|
409
|
-
if (typeof value == "object") return "record";
|
|
410
|
-
return typeof value;
|
|
411
|
-
};
|
|
412
|
-
var $ToBoolean = (value) => {
|
|
413
|
-
$AssertInit(value);
|
|
414
|
-
return value != null && value !== false;
|
|
415
|
-
};
|
|
416
|
-
function numberToString(value) {
|
|
417
|
-
if (isNaN(value)) return "nan";
|
|
418
|
-
if (value === Infinity) return "inf";
|
|
419
|
-
if (value === -Infinity) return "-inf";
|
|
420
|
-
return String(value);
|
|
421
|
-
}
|
|
422
|
-
function innerToString(value, useBraces) {
|
|
423
|
-
if (value == null) return "nil";
|
|
424
|
-
if (isVmWrapper(value)) return value.toString();
|
|
425
|
-
if (typeof value == "function") {
|
|
426
|
-
const name = getVmFunctionInfo(value)?.fullName;
|
|
427
|
-
return name ? `<function ${name}>` : `<function>`;
|
|
428
|
-
}
|
|
429
|
-
if (isVmArray(value)) {
|
|
430
|
-
const strings = [];
|
|
431
|
-
for (const item of value) {
|
|
432
|
-
strings.push(innerToString(item, true));
|
|
433
|
-
}
|
|
434
|
-
const results = strings.join(", ");
|
|
435
|
-
if (!useBraces) return results;
|
|
436
|
-
return `[${results}]`;
|
|
437
|
-
}
|
|
438
|
-
if (typeof value == "object") {
|
|
439
|
-
const entries3 = keys(value).map((key) => `${key}: ${innerToString(value[key], true)}`).join(", ");
|
|
440
|
-
if (!useBraces) return entries3;
|
|
441
|
-
return `(${entries3})`;
|
|
442
|
-
}
|
|
443
|
-
if (typeof value == "number") {
|
|
444
|
-
return numberToString(value);
|
|
445
|
-
}
|
|
446
|
-
return String(value);
|
|
447
|
-
}
|
|
448
|
-
var $ToString = (value) => {
|
|
449
|
-
$AssertInit(value);
|
|
450
|
-
if (typeof value == "string") return value;
|
|
451
|
-
if (value === null) return "";
|
|
452
|
-
return innerToString(value, false);
|
|
453
|
-
};
|
|
454
|
-
var $ToNumber = (value) => {
|
|
455
|
-
$AssertInit(value);
|
|
456
|
-
if (typeof value == "number") return value;
|
|
457
|
-
if (value == null) return 0;
|
|
458
|
-
if (typeof value == "string") {
|
|
459
|
-
value = value.trim();
|
|
460
|
-
if (value === "") return 0;
|
|
461
|
-
if (value === "inf" || value === "+inf" || value === "Infinity" || value === "+Infinity") {
|
|
462
|
-
return POSITIVE_INFINITY;
|
|
463
|
-
}
|
|
464
|
-
if (value === "-inf" || value === "-Infinity") {
|
|
465
|
-
return NEGATIVE_INFINITY;
|
|
466
|
-
}
|
|
467
|
-
return Number(value);
|
|
468
|
-
}
|
|
469
|
-
if (typeof value == "boolean") return value ? 1 : 0;
|
|
470
|
-
return Number.NaN;
|
|
471
|
-
};
|
|
472
|
-
var $IsBoolean = (value) => {
|
|
473
|
-
$AssertInit(value);
|
|
474
|
-
return typeof value == "boolean";
|
|
475
|
-
};
|
|
476
|
-
var $IsNumber = (value) => {
|
|
477
|
-
$AssertInit(value);
|
|
478
|
-
return typeof value == "number";
|
|
479
|
-
};
|
|
480
|
-
var $IsString = (value) => {
|
|
481
|
-
$AssertInit(value);
|
|
482
|
-
return typeof value == "string";
|
|
483
|
-
};
|
|
484
|
-
var $IsRecord = (value) => {
|
|
485
|
-
$AssertInit(value);
|
|
486
|
-
return isVmRecord(value);
|
|
487
|
-
};
|
|
488
|
-
var $IsArray = (value) => {
|
|
489
|
-
$AssertInit(value);
|
|
490
|
-
return isVmArray(value);
|
|
491
|
-
};
|
|
492
|
-
var $AssertNonNil = (value) => {
|
|
493
|
-
$AssertInit(value);
|
|
494
|
-
if (value !== null) return;
|
|
495
|
-
throw new VmError("Expected non-nil value", null);
|
|
496
|
-
};
|
|
497
|
-
var $Has = (obj, key) => {
|
|
498
|
-
$AssertInit(obj);
|
|
499
|
-
const pk = $ToString(key);
|
|
500
|
-
if (obj == null || typeof obj != "object") return false;
|
|
501
|
-
if (isVmWrapper(obj)) return obj.has(pk);
|
|
502
|
-
return hasOwnEnumerable(obj, pk);
|
|
503
|
-
};
|
|
504
|
-
var $Get = (obj, key) => {
|
|
505
|
-
$AssertInit(obj);
|
|
506
|
-
if (isVmArray(obj)) {
|
|
507
|
-
const index = $ToNumber(key);
|
|
508
|
-
if (isNaN(index)) return null;
|
|
509
|
-
return at.call(obj, trunc(index)) ?? null;
|
|
510
|
-
}
|
|
511
|
-
const pk = $ToString(key);
|
|
512
|
-
if (obj == null || typeof obj != "object") return null;
|
|
513
|
-
if (isVmWrapper(obj)) return obj.get(pk) ?? null;
|
|
514
|
-
if (!hasOwnEnumerable(obj, pk)) return null;
|
|
515
|
-
return obj[pk] ?? null;
|
|
516
|
-
};
|
|
517
|
-
var $Set = (obj, key, value) => {
|
|
518
|
-
$AssertInit(obj);
|
|
519
|
-
$AssertInit(value);
|
|
520
|
-
const pk = $ToString(key);
|
|
521
|
-
if (obj == null) return;
|
|
522
|
-
if (!isVmExtern(obj)) throw new VmError(`Expected extern, got ${$Type(obj)}`, void 0);
|
|
523
|
-
obj.set(pk, value);
|
|
524
|
-
};
|
|
525
|
-
var $Iterable = (value) => {
|
|
526
|
-
$AssertInit(value);
|
|
527
|
-
if (isVmWrapper(value)) return value.keys();
|
|
528
|
-
if (isVmArray(value)) return value;
|
|
529
|
-
if (value != null && typeof value == "object") return keys(value);
|
|
530
|
-
throw new VmError(`Value is not iterable`, isVmFunction(value) ? [] : [value]);
|
|
531
|
-
};
|
|
532
|
-
var $RecordSpread = (record) => {
|
|
533
|
-
$AssertInit(record);
|
|
534
|
-
if (record == null || isVmRecord(record)) return record;
|
|
535
|
-
if (isVmArray(record)) {
|
|
536
|
-
const result = {};
|
|
537
|
-
const len2 = record.length;
|
|
538
|
-
for (let i = 0; i < len2; i++) {
|
|
539
|
-
const item = record[i];
|
|
540
|
-
result[i] = item ?? null;
|
|
541
|
-
}
|
|
542
|
-
return result;
|
|
543
|
-
}
|
|
544
|
-
if (isVmExtern(record)) {
|
|
545
|
-
const result = create(null);
|
|
546
|
-
for (const key of record.keys()) {
|
|
547
|
-
const value = record.get(key) ?? null;
|
|
548
|
-
if (isVmPrimitive(value)) {
|
|
549
|
-
result[key] = value;
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
return result;
|
|
553
|
-
}
|
|
554
|
-
throw new VmError(`Expected record, array, extern or nil, got ${$Type(record)}`, null);
|
|
555
|
-
};
|
|
556
|
-
var $ArraySpread = (array) => {
|
|
557
|
-
$AssertInit(array);
|
|
558
|
-
if (array == null) return [];
|
|
559
|
-
if (isVmArray(array)) return array;
|
|
560
|
-
if (isVmExtern(array) && typeof array.value[Symbol.iterator] == "function") {
|
|
561
|
-
const result = [];
|
|
562
|
-
for (const item of array.value) {
|
|
563
|
-
if (isVmPrimitive(item)) {
|
|
564
|
-
result.push(item);
|
|
565
|
-
} else {
|
|
566
|
-
result.push(null);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
return result;
|
|
570
|
-
}
|
|
571
|
-
throw new VmError(`Expected array, iterable extern or nil, got ${$Type(array)}`, []);
|
|
572
|
-
};
|
|
573
|
-
function formatNumber(value) {
|
|
574
|
-
if (!Number.isFinite(value)) return numberToString(value);
|
|
575
|
-
if (value === 0) return "0";
|
|
576
|
-
const s = value.toString();
|
|
577
|
-
let ps;
|
|
578
|
-
const abs3 = Math.abs(value);
|
|
579
|
-
if (abs3 >= 1e3 || abs3 < 1e-3) {
|
|
580
|
-
const ps1 = value.toExponential();
|
|
581
|
-
const ps2 = value.toExponential(5);
|
|
582
|
-
ps = ps1.length < ps2.length ? ps1 : ps2;
|
|
583
|
-
} else {
|
|
584
|
-
ps = value.toPrecision(6);
|
|
585
|
-
}
|
|
586
|
-
return ps.length < s.length ? ps : s;
|
|
587
|
-
}
|
|
588
|
-
var $Format = (value, format2) => {
|
|
589
|
-
$AssertInit(value);
|
|
590
|
-
const f = format2 == null ? "" : typeof format2 == "string" ? format2.trim() : $ToString(format2);
|
|
591
|
-
if (typeof value == "number") {
|
|
592
|
-
if (/^\.\d+$/.test(f)) {
|
|
593
|
-
let digits = Math.trunc(Number(f.slice(1)));
|
|
594
|
-
if (!(digits <= 100)) digits = 100;
|
|
595
|
-
return value.toFixed(digits);
|
|
596
|
-
} else {
|
|
597
|
-
return formatNumber(value);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
return $ToString(value);
|
|
601
|
-
};
|
|
602
|
-
|
|
603
|
-
// src/vm/helpers.ts
|
|
604
|
-
var Vargs = (varags) => {
|
|
605
|
-
for (let i = 0, l = varags.length; i < l; i++) {
|
|
606
|
-
const el = varags[i];
|
|
607
|
-
if (!isVmConst(el)) {
|
|
608
|
-
varags[i] = null;
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
return varags;
|
|
612
|
-
};
|
|
613
|
-
var Element = (value) => {
|
|
614
|
-
$AssertInit(value);
|
|
615
|
-
if (!isVmConst(value)) return null;
|
|
616
|
-
return value;
|
|
617
|
-
};
|
|
618
|
-
var ElementOpt = (key, value) => {
|
|
619
|
-
$AssertInit(value);
|
|
620
|
-
if (value == null || !isVmConst(value)) return {};
|
|
621
|
-
return { [key]: value };
|
|
622
|
-
};
|
|
623
|
-
var Function2 = (fn) => {
|
|
624
|
-
return VmFunction(fn, { isLib: false, injectCp: false });
|
|
625
|
-
};
|
|
626
|
-
var Upvalue = (value) => {
|
|
627
|
-
$AssertInit(value);
|
|
628
|
-
return value;
|
|
629
|
-
};
|
|
630
|
-
var assertArrayLength = (start, end) => {
|
|
631
|
-
if (end - start > VM_ARRAY_MAX_LENGTH) {
|
|
632
|
-
throw new RangeError(`Array length exceeds maximum limit of ${VM_ARRAY_MAX_LENGTH}`);
|
|
633
|
-
}
|
|
634
|
-
};
|
|
635
|
-
var isEmptyRange = (start, end) => {
|
|
636
|
-
return !isFinite(start) || !isFinite(end) || start > end;
|
|
637
|
-
};
|
|
638
|
-
var ArrayRange = (start, end) => {
|
|
639
|
-
const s = $ToNumber(start);
|
|
640
|
-
const e = $ToNumber(end);
|
|
641
|
-
if (isEmptyRange(s, e)) return [];
|
|
642
|
-
assertArrayLength(s, e);
|
|
643
|
-
const arr = [];
|
|
644
|
-
for (let i = s; i <= e; i++) {
|
|
645
|
-
arr.push(i);
|
|
646
|
-
}
|
|
647
|
-
return arr;
|
|
648
|
-
};
|
|
649
|
-
var ArrayRangeExclusive = (start, end) => {
|
|
650
|
-
const s = $ToNumber(start);
|
|
651
|
-
const e = $ToNumber(end);
|
|
652
|
-
if (isEmptyRange(s, e)) return [];
|
|
653
|
-
assertArrayLength(s, e);
|
|
654
|
-
const arr = [];
|
|
655
|
-
for (let i = s; i < e; i++) {
|
|
656
|
-
arr.push(i);
|
|
657
|
-
}
|
|
658
|
-
return arr;
|
|
659
|
-
};
|
|
660
|
-
var MAX_DEPTH = 128;
|
|
661
|
-
var cpDepth = 0;
|
|
662
|
-
var cp = Number.NaN;
|
|
663
|
-
var cpTimeout = 100;
|
|
664
|
-
function Cp() {
|
|
665
|
-
if (!cp) {
|
|
666
|
-
cp = Date.now();
|
|
667
|
-
} else if (Date.now() - cp > cpTimeout) {
|
|
668
|
-
throw new RangeError("Execution timeout");
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
function CpEnter() {
|
|
672
|
-
cpDepth++;
|
|
673
|
-
if (cpDepth <= 1) {
|
|
674
|
-
cp = Date.now();
|
|
675
|
-
cpDepth = 1;
|
|
676
|
-
} else if (cpDepth > MAX_DEPTH) {
|
|
677
|
-
throw new RangeError("Maximum call depth exceeded");
|
|
678
|
-
} else {
|
|
679
|
-
Cp();
|
|
680
|
-
}
|
|
681
|
-
}
|
|
682
|
-
function CpExit() {
|
|
683
|
-
cpDepth--;
|
|
684
|
-
if (cpDepth < 1) {
|
|
685
|
-
cp = Number.NaN;
|
|
686
|
-
cpDepth = 0;
|
|
687
|
-
} else {
|
|
688
|
-
Cp();
|
|
689
|
-
}
|
|
690
|
-
}
|
|
691
|
-
function configCheckpoint(timeout = 100) {
|
|
692
|
-
if (typeof timeout !== "number" || timeout <= 0 || Number.isNaN(timeout)) {
|
|
693
|
-
throw new RangeError("Invalid timeout value");
|
|
694
|
-
}
|
|
695
|
-
cpTimeout = timeout;
|
|
696
|
-
}
|
|
697
|
-
function GlobalFallback() {
|
|
698
|
-
return DefaultVmContext;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
// src/vm/types/function.ts
|
|
702
|
-
var kVmFunction = Symbol.for("mirascript.vm.function");
|
|
703
|
-
function isVmFunction(value) {
|
|
704
|
-
return getVmFunctionInfo(value) != null;
|
|
705
|
-
}
|
|
706
|
-
function getVmFunctionInfo(value) {
|
|
707
|
-
if (typeof value != "function") return void 0;
|
|
708
|
-
return value[kVmFunction];
|
|
709
|
-
}
|
|
710
|
-
function VmFunction(fn, option = {}) {
|
|
711
|
-
if (typeof fn != "function") {
|
|
712
|
-
throw new TypeError("Invalid function");
|
|
713
|
-
}
|
|
714
|
-
const exists = fromVmFunctionProxy(fn);
|
|
715
|
-
if (exists) return exists;
|
|
716
|
-
const info = {
|
|
717
|
-
fullName: option.fullName ?? fn.name,
|
|
718
|
-
isLib: option.isLib ?? false,
|
|
719
|
-
summary: option.summary || void 0,
|
|
720
|
-
params: option.params,
|
|
721
|
-
paramsType: option.paramsType,
|
|
722
|
-
returns: option.returns || void 0,
|
|
723
|
-
returnsType: option.returnsType || void 0,
|
|
724
|
-
examples: option.examples?.length ? option.examples : void 0
|
|
725
|
-
};
|
|
726
|
-
if (option.injectCp) {
|
|
727
|
-
const original = fn;
|
|
728
|
-
info.original = original;
|
|
729
|
-
fn = ((...args) => {
|
|
730
|
-
try {
|
|
731
|
-
CpEnter();
|
|
732
|
-
const ret = original(...args);
|
|
733
|
-
return ret;
|
|
734
|
-
} finally {
|
|
735
|
-
CpExit();
|
|
736
|
-
}
|
|
737
|
-
});
|
|
738
|
-
defineProperty(fn, "name", {
|
|
739
|
-
value: original.name,
|
|
740
|
-
configurable: true
|
|
741
|
-
});
|
|
742
|
-
}
|
|
743
|
-
defineProperty(fn, kVmFunction, {
|
|
744
|
-
value: Object.freeze(info)
|
|
745
|
-
});
|
|
746
|
-
return fn;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
// src/vm/types/boundary.ts
|
|
750
|
-
var kProxy = Symbol.for("mirascript.vm.function.proxy");
|
|
751
|
-
function toVmFunctionProxy(fn) {
|
|
752
|
-
if (!isVmFunction(fn)) return fn;
|
|
753
|
-
const cached = fn[kProxy];
|
|
754
|
-
if (cached != null) return cached;
|
|
755
|
-
const proxy = (...args) => {
|
|
756
|
-
const ret = $Call(
|
|
757
|
-
fn,
|
|
758
|
-
// 作为函数参数传入的值一定丢失了它的 this
|
|
759
|
-
args.map((v) => wrapToVmValue(v, null))
|
|
760
|
-
);
|
|
761
|
-
return unwrapFromVmValue(ret);
|
|
762
|
-
};
|
|
763
|
-
defineProperty(fn, kProxy, { value: proxy });
|
|
764
|
-
defineProperty(proxy, kProxy, { value: fn });
|
|
765
|
-
defineProperty(proxy, "name", {
|
|
766
|
-
value: fn.name,
|
|
767
|
-
configurable: true
|
|
768
|
-
});
|
|
769
|
-
return proxy;
|
|
770
|
-
}
|
|
771
|
-
function fromVmFunctionProxy(fn) {
|
|
772
|
-
if (isVmFunction(fn)) return fn;
|
|
773
|
-
const original = fn[kProxy];
|
|
774
|
-
if (original && isVmFunction(original)) return original;
|
|
775
|
-
return void 0;
|
|
776
|
-
}
|
|
777
|
-
function wrapToVmValue(value, thisArg = null, assumeVmValue) {
|
|
778
|
-
if (value == null) return null;
|
|
779
|
-
switch (typeof value) {
|
|
780
|
-
case "function": {
|
|
781
|
-
const unwrapped = fromVmFunctionProxy(value);
|
|
782
|
-
if (unwrapped) return unwrapped;
|
|
783
|
-
return new VmExtern(value, thisArg);
|
|
784
|
-
}
|
|
785
|
-
case "object": {
|
|
786
|
-
if (isVmWrapper(value)) return value;
|
|
787
|
-
if (value instanceof Date) return value.valueOf();
|
|
788
|
-
if (assumeVmValue?.(value)) return value;
|
|
789
|
-
return new VmExtern(value);
|
|
790
|
-
}
|
|
791
|
-
case "string":
|
|
792
|
-
case "number":
|
|
793
|
-
case "boolean":
|
|
794
|
-
return value;
|
|
795
|
-
case "bigint":
|
|
796
|
-
return Number(value);
|
|
797
|
-
case "symbol":
|
|
798
|
-
case "undefined":
|
|
799
|
-
default:
|
|
800
|
-
return null;
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
|
-
function unwrapFromVmValue(value) {
|
|
804
|
-
if (typeof value == "function") {
|
|
805
|
-
return toVmFunctionProxy(value);
|
|
806
|
-
}
|
|
807
|
-
if (value == null || typeof value != "object") return value;
|
|
808
|
-
if (!isVmExtern(value)) return value;
|
|
809
|
-
if (value.thisArg == null || typeof value.value != "function") {
|
|
810
|
-
return value.value;
|
|
811
|
-
}
|
|
812
|
-
const f = value;
|
|
813
|
-
const caller = f.thisArg.value;
|
|
814
|
-
return new Proxy(f.value, {
|
|
815
|
-
apply(target, thisArg, args) {
|
|
816
|
-
return apply(target, caller, args);
|
|
817
|
-
}
|
|
818
|
-
});
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
// src/vm/types/extern.ts
|
|
822
|
-
var ObjectPrototype = Object.prototype;
|
|
823
|
-
var ObjectToString = ObjectPrototype.toString;
|
|
824
|
-
var FunctionToString = Function.prototype.toString;
|
|
825
|
-
var VmExtern = class extends VmWrapper {
|
|
826
|
-
constructor(value, thisArg = null) {
|
|
827
|
-
super(value);
|
|
828
|
-
this.thisArg = thisArg;
|
|
829
|
-
}
|
|
830
|
-
/** Check if the object has a property */
|
|
831
|
-
access(key, read) {
|
|
832
|
-
if (key.startsWith("_")) return false;
|
|
833
|
-
if (typeof this.value == "function" && (key === "prototype" || key === "arguments" || key === "caller"))
|
|
834
|
-
return false;
|
|
835
|
-
if (hasOwn(this.value, key)) return true;
|
|
836
|
-
if (!read) return true;
|
|
837
|
-
if (!(key in this.value)) return false;
|
|
838
|
-
if (key === "constructor") return false;
|
|
839
|
-
const prop = this.value[key];
|
|
840
|
-
if (key in Function.prototype && prop === Function.prototype[key]) return false;
|
|
841
|
-
if (key in Array.prototype && prop === Array.prototype[key]) return false;
|
|
842
|
-
if (key in Object.prototype && prop === Object.prototype[key]) return false;
|
|
843
|
-
return true;
|
|
844
|
-
}
|
|
845
|
-
/** 决定是否对属性进行包装 */
|
|
846
|
-
assumeVmValue(value, key) {
|
|
847
|
-
return false;
|
|
848
|
-
}
|
|
849
|
-
/** @inheritdoc */
|
|
850
|
-
has(key) {
|
|
851
|
-
return this.access(key, true);
|
|
852
|
-
}
|
|
853
|
-
/** @inheritdoc */
|
|
854
|
-
get(key) {
|
|
855
|
-
if (!this.has(key)) return void 0;
|
|
856
|
-
const prop = this.value[key];
|
|
857
|
-
return wrapToVmValue(prop, this, (v) => this.assumeVmValue(v, key));
|
|
858
|
-
}
|
|
859
|
-
/** Set a property on the object */
|
|
860
|
-
set(key, value) {
|
|
861
|
-
if (!this.access(key, false)) return false;
|
|
862
|
-
const prop = unwrapFromVmValue(value);
|
|
863
|
-
this.value[key] = prop;
|
|
864
|
-
return true;
|
|
865
|
-
}
|
|
866
|
-
/** Call extern value */
|
|
867
|
-
call(args) {
|
|
868
|
-
const { value } = this;
|
|
869
|
-
if (typeof value != "function") {
|
|
870
|
-
throw VmError.from(`Not a callable extern`, null, null);
|
|
871
|
-
}
|
|
872
|
-
const caller = this.thisArg?.value ?? null;
|
|
873
|
-
const unwrappedArgs = args.map(unwrapFromVmValue);
|
|
874
|
-
let ret;
|
|
875
|
-
try {
|
|
876
|
-
ret = apply(value, caller, unwrappedArgs);
|
|
877
|
-
} catch (ex) {
|
|
878
|
-
throw VmError.from(`Callable extern`, ex, null);
|
|
879
|
-
}
|
|
880
|
-
return wrapToVmValue(ret, null, (obj) => this.assumeVmValue(obj, void 0));
|
|
881
|
-
}
|
|
882
|
-
/** @inheritdoc */
|
|
883
|
-
keys() {
|
|
884
|
-
const keys4 = [];
|
|
885
|
-
for (const key in this.value) {
|
|
886
|
-
if (this.has(key)) keys4.push(key);
|
|
887
|
-
}
|
|
888
|
-
return keys4;
|
|
889
|
-
}
|
|
890
|
-
/** @inheritdoc */
|
|
891
|
-
same(other) {
|
|
892
|
-
if (!isVmExtern(other)) return false;
|
|
893
|
-
return this.value === other.value && this.thisArg === other.thisArg;
|
|
894
|
-
}
|
|
895
|
-
/** @inheritdoc */
|
|
896
|
-
toString() {
|
|
897
|
-
const { toString } = this.value;
|
|
898
|
-
if (typeof toString != "function" || toString === ObjectToString || toString === FunctionToString) {
|
|
899
|
-
return super.toString();
|
|
900
|
-
}
|
|
901
|
-
try {
|
|
902
|
-
return String(this.value);
|
|
903
|
-
} catch {
|
|
904
|
-
return super.toString();
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
/** @inheritdoc */
|
|
908
|
-
get type() {
|
|
909
|
-
return "extern";
|
|
910
|
-
}
|
|
911
|
-
/** @inheritdoc */
|
|
912
|
-
get describe() {
|
|
913
|
-
const tag = ObjectToString.call(this.value).slice(8, -1);
|
|
914
|
-
if (tag === "Object") {
|
|
915
|
-
const proto = getPrototypeOf(this.value);
|
|
916
|
-
if (proto === ObjectPrototype) {
|
|
917
|
-
return "Object";
|
|
918
|
-
}
|
|
919
|
-
if (proto == null) {
|
|
920
|
-
return "Object: null prototype";
|
|
921
|
-
}
|
|
922
|
-
if (typeof proto.constructor === "function" && proto.constructor.name) {
|
|
923
|
-
return proto.constructor.name;
|
|
924
|
-
}
|
|
925
|
-
} else if (tag === "Function" && "prototype" in this.value && typeof this.value.prototype == "object") {
|
|
926
|
-
const { name } = this.value;
|
|
927
|
-
return `class ${name || "<anonymous>"}`;
|
|
928
|
-
} else if (tag === "Function") {
|
|
929
|
-
const { name } = this.value;
|
|
930
|
-
return `function ${name || "<anonymous>"}()`;
|
|
931
|
-
} else if (tag === "AsyncFunction") {
|
|
932
|
-
const { name } = this.value;
|
|
933
|
-
return `async function ${name || "<anonymous>"}()`;
|
|
934
|
-
} else if (tag === "GeneratorFunction") {
|
|
935
|
-
const { name } = this.value;
|
|
936
|
-
return `function* ${name || "<anonymous>"}()`;
|
|
937
|
-
} else if (tag === "AsyncGeneratorFunction") {
|
|
938
|
-
const { name } = this.value;
|
|
939
|
-
return `async function* ${name || "<anonymous>"}()`;
|
|
940
|
-
}
|
|
941
|
-
return tag;
|
|
942
|
-
}
|
|
943
|
-
};
|
|
944
|
-
var kVmExtern = Symbol.for("mirascript.vm.extern");
|
|
945
|
-
Object.defineProperty(VmExtern.prototype, kVmExtern, { value: true });
|
|
946
|
-
function isVmExtern(value) {
|
|
947
|
-
return value != null && typeof value == "object" && kVmExtern in value;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
// src/vm/types/module.ts
|
|
951
|
-
var VmModule = class extends VmWrapper {
|
|
952
|
-
constructor(name, value) {
|
|
953
|
-
super(value);
|
|
954
|
-
this.name = name;
|
|
955
|
-
}
|
|
956
|
-
/** @inheritdoc */
|
|
957
|
-
has(key) {
|
|
958
|
-
return hasOwnEnumerable(this.value, key);
|
|
959
|
-
}
|
|
960
|
-
/** @inheritdoc */
|
|
961
|
-
get(key) {
|
|
962
|
-
if (!this.has(key)) return void 0;
|
|
963
|
-
return this.value[key] ?? null;
|
|
964
|
-
}
|
|
965
|
-
/** @inheritdoc */
|
|
966
|
-
keys() {
|
|
967
|
-
return keys(this.value);
|
|
968
|
-
}
|
|
969
|
-
/** @inheritdoc */
|
|
970
|
-
same(other) {
|
|
971
|
-
return this === other;
|
|
972
|
-
}
|
|
973
|
-
/** @inheritdoc */
|
|
974
|
-
get type() {
|
|
975
|
-
return "module";
|
|
976
|
-
}
|
|
977
|
-
/** @inheritdoc */
|
|
978
|
-
get describe() {
|
|
979
|
-
return this.name;
|
|
980
|
-
}
|
|
981
|
-
};
|
|
982
|
-
var kVmModule = Symbol.for("mirascript.vm.module");
|
|
983
|
-
Object.defineProperty(VmModule.prototype, kVmModule, { value: true });
|
|
984
|
-
function isVmModule(value) {
|
|
985
|
-
return value != null && typeof value == "object" && kVmModule in value;
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
// src/vm/types/script.ts
|
|
989
|
-
var kVmScript = Symbol.for("mirascript.vm.script");
|
|
990
|
-
function isVmScript(value) {
|
|
991
|
-
return typeof value === "function" && value[kVmScript] === true;
|
|
992
|
-
}
|
|
993
|
-
|
|
994
|
-
// src/vm/types/checker.ts
|
|
995
|
-
var MAX_DEPTH2 = 32;
|
|
996
|
-
function isVmArrayDeep(value, depth) {
|
|
997
|
-
const proto1 = getPrototypeOf(value);
|
|
998
|
-
if (!isArray(proto1)) return false;
|
|
999
|
-
if (!depth) return true;
|
|
1000
|
-
return value.every((item) => isVmConstInner(item, depth));
|
|
1001
|
-
}
|
|
1002
|
-
function isVmRecordDeep(value, depth) {
|
|
1003
|
-
let isRecord;
|
|
1004
|
-
const proto1 = getPrototypeOf(value);
|
|
1005
|
-
if (proto1 == null) {
|
|
1006
|
-
isRecord = true;
|
|
1007
|
-
} else {
|
|
1008
|
-
const proto2 = getPrototypeOf(proto1);
|
|
1009
|
-
if (proto2 != null) {
|
|
1010
|
-
isRecord = false;
|
|
1011
|
-
} else {
|
|
1012
|
-
isRecord = "hasOwnProperty" in value;
|
|
1013
|
-
}
|
|
1014
|
-
}
|
|
1015
|
-
if (!isRecord) return false;
|
|
1016
|
-
if (!depth) return true;
|
|
1017
|
-
return values(value).every((value2) => isVmConstInner(value2, depth));
|
|
1018
|
-
}
|
|
1019
|
-
function isVmConstInner(value, depth) {
|
|
1020
|
-
if (depth++ >= MAX_DEPTH2) return false;
|
|
1021
|
-
switch (typeof value) {
|
|
1022
|
-
case "string":
|
|
1023
|
-
case "number":
|
|
1024
|
-
case "boolean":
|
|
1025
|
-
case "undefined":
|
|
1026
|
-
return true;
|
|
1027
|
-
case "object":
|
|
1028
|
-
if (value == null) return true;
|
|
1029
|
-
if (isVmWrapper(value)) return false;
|
|
1030
|
-
if (isArray(value)) {
|
|
1031
|
-
return isVmArrayDeep(value, depth);
|
|
1032
|
-
} else {
|
|
1033
|
-
return isVmRecordDeep(value, depth);
|
|
1034
|
-
}
|
|
1035
|
-
case "function":
|
|
1036
|
-
case "bigint":
|
|
1037
|
-
case "symbol":
|
|
1038
|
-
default:
|
|
1039
|
-
return false;
|
|
1040
|
-
}
|
|
1041
|
-
}
|
|
1042
|
-
function isVmConst(value, checkDeep = false) {
|
|
1043
|
-
switch (typeof value) {
|
|
1044
|
-
case "string":
|
|
1045
|
-
case "number":
|
|
1046
|
-
case "boolean":
|
|
1047
|
-
return true;
|
|
1048
|
-
case "object":
|
|
1049
|
-
if (value == null) return true;
|
|
1050
|
-
if (isVmWrapper(value)) return false;
|
|
1051
|
-
if (!checkDeep) {
|
|
1052
|
-
if (isArray(value)) {
|
|
1053
|
-
return isVmArrayDeep(value, 0);
|
|
1054
|
-
} else {
|
|
1055
|
-
return isVmRecordDeep(value, 0);
|
|
1056
|
-
}
|
|
1057
|
-
} else {
|
|
1058
|
-
return isVmConstInner(value, 1);
|
|
1059
|
-
}
|
|
1060
|
-
case "undefined":
|
|
1061
|
-
case "function":
|
|
1062
|
-
case "bigint":
|
|
1063
|
-
case "symbol":
|
|
1064
|
-
default:
|
|
1065
|
-
return false;
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
function isVmImmutable(value, checkDeep = false) {
|
|
1069
|
-
return isVmModule(value) || isVmFunction(value) || isVmConst(value, checkDeep);
|
|
1070
|
-
}
|
|
1071
|
-
function isVmValue(value, checkDeep = false) {
|
|
1072
|
-
if (value === void 0) return false;
|
|
1073
|
-
return isVmAny(value, checkDeep);
|
|
1074
|
-
}
|
|
1075
|
-
function isVmAny(value, checkDeep) {
|
|
1076
|
-
switch (typeof value) {
|
|
1077
|
-
case "string":
|
|
1078
|
-
case "number":
|
|
1079
|
-
case "boolean":
|
|
1080
|
-
case "undefined":
|
|
1081
|
-
return true;
|
|
1082
|
-
case "object":
|
|
1083
|
-
if (value == null) return true;
|
|
1084
|
-
if (isVmWrapper(value)) return true;
|
|
1085
|
-
return isVmConst(value, checkDeep);
|
|
1086
|
-
case "function":
|
|
1087
|
-
return isVmFunction(value);
|
|
1088
|
-
case "bigint":
|
|
1089
|
-
case "symbol":
|
|
1090
|
-
default:
|
|
1091
|
-
return false;
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
|
|
1095
|
-
// src/vm/types/index.ts
|
|
1096
|
-
function isVmArray(value) {
|
|
1097
|
-
if (!isArray(value)) return false;
|
|
1098
|
-
value;
|
|
1099
|
-
return true;
|
|
1100
|
-
}
|
|
1101
|
-
function isVmRecord(value) {
|
|
1102
|
-
if (value == null || typeof value !== "object") return false;
|
|
1103
|
-
if (isVmWrapper(value)) return false;
|
|
1104
|
-
if (isVmArray(value)) return false;
|
|
1105
|
-
value;
|
|
1106
|
-
return true;
|
|
1107
|
-
}
|
|
1108
|
-
function isVmPrimitive(value) {
|
|
1109
|
-
if (value === null || typeof value == "number" || typeof value == "string" || typeof value == "boolean") {
|
|
1110
|
-
value;
|
|
1111
|
-
value;
|
|
1112
|
-
return true;
|
|
1113
|
-
}
|
|
1114
|
-
return false;
|
|
1115
|
-
}
|
|
1116
|
-
function isVmCallable(value) {
|
|
1117
|
-
return isVmFunction(value) || isVmExtern(value) && typeof value.value == "function";
|
|
1118
|
-
}
|
|
1119
|
-
var VM_ARRAY_MAX_LENGTH = 2 ** 31 - 1;
|
|
1120
|
-
|
|
1121
|
-
// src/vm/types/context.ts
|
|
1122
|
-
var kVmContext = Symbol.for("mirascript.vm.context");
|
|
1123
|
-
var VmSharedContext = create(null);
|
|
1124
|
-
function defineVmContextValue(name, value, override = false) {
|
|
1125
|
-
if (!override && name in VmSharedContext) throw new Error(`Global variable '${name}' is already defined.`);
|
|
1126
|
-
let v;
|
|
1127
|
-
if (typeof value == "function") {
|
|
1128
|
-
v = VmFunction(value, {
|
|
1129
|
-
isLib: true,
|
|
1130
|
-
fullName: `global.${name}`
|
|
1131
|
-
});
|
|
1132
|
-
} else {
|
|
1133
|
-
v = value;
|
|
1134
|
-
}
|
|
1135
|
-
VmSharedContext[name] = v ?? null;
|
|
1136
|
-
}
|
|
1137
|
-
var DefaultVmContext = Object.freeze({
|
|
1138
|
-
[kVmContext]: true,
|
|
1139
|
-
/** @inheritdoc */
|
|
1140
|
-
keys() {
|
|
1141
|
-
return keys(VmSharedContext);
|
|
1142
|
-
},
|
|
1143
|
-
/** @inheritdoc */
|
|
1144
|
-
get(key) {
|
|
1145
|
-
return VmSharedContext[key] ?? null;
|
|
1146
|
-
},
|
|
1147
|
-
/** @inheritdoc */
|
|
1148
|
-
has(key) {
|
|
1149
|
-
return key in VmSharedContext;
|
|
1150
|
-
}
|
|
1151
|
-
});
|
|
1152
|
-
var _a;
|
|
1153
|
-
_a = kVmContext;
|
|
1154
|
-
var ValueVmContext = class {
|
|
1155
|
-
constructor(env, describe) {
|
|
1156
|
-
this.env = env;
|
|
1157
|
-
this.describe = describe;
|
|
1158
|
-
this[_a] = true;
|
|
1159
|
-
this.cachedKeys = null;
|
|
1160
|
-
}
|
|
1161
|
-
/** @inheritdoc */
|
|
1162
|
-
keys() {
|
|
1163
|
-
this.cachedKeys ??= keys(this.env);
|
|
1164
|
-
return [...this.cachedKeys, ...DefaultVmContext.keys()];
|
|
1165
|
-
}
|
|
1166
|
-
/** @inheritdoc */
|
|
1167
|
-
get(key) {
|
|
1168
|
-
return this.env[key] ?? null;
|
|
1169
|
-
}
|
|
1170
|
-
/** @inheritdoc */
|
|
1171
|
-
has(key) {
|
|
1172
|
-
return key in this.env;
|
|
1173
|
-
}
|
|
1174
|
-
};
|
|
1175
|
-
var _a2;
|
|
1176
|
-
_a2 = kVmContext;
|
|
1177
|
-
var FactoryVmContext = class {
|
|
1178
|
-
constructor(getter, enumerator, describe) {
|
|
1179
|
-
this.getter = getter;
|
|
1180
|
-
this.enumerator = enumerator;
|
|
1181
|
-
this.describe = describe;
|
|
1182
|
-
this[_a2] = true;
|
|
1183
|
-
}
|
|
1184
|
-
/** @inheritdoc */
|
|
1185
|
-
keys() {
|
|
1186
|
-
if (!this.enumerator) return DefaultVmContext.keys();
|
|
1187
|
-
return [...this.enumerator(), ...DefaultVmContext.keys()];
|
|
1188
|
-
}
|
|
1189
|
-
/** @inheritdoc */
|
|
1190
|
-
get(key) {
|
|
1191
|
-
const value = this.getter(key);
|
|
1192
|
-
if (value !== void 0) return value;
|
|
1193
|
-
return DefaultVmContext.get(key);
|
|
1194
|
-
}
|
|
1195
|
-
/** @inheritdoc */
|
|
1196
|
-
has(key) {
|
|
1197
|
-
return this.getter(key) !== void 0 || DefaultVmContext.has(key);
|
|
1198
|
-
}
|
|
1199
|
-
};
|
|
1200
|
-
function createVmContext(...args) {
|
|
1201
|
-
if (args[0] == null && args[1] == null) {
|
|
1202
|
-
return { ...DefaultVmContext };
|
|
1203
|
-
}
|
|
1204
|
-
if (typeof args[0] == "function") {
|
|
1205
|
-
const [getter, enumerator, describer2] = args;
|
|
1206
|
-
return new FactoryVmContext(getter, enumerator ?? void 0, describer2 ?? void 0);
|
|
1207
|
-
}
|
|
1208
|
-
const [vmValues, externValues, describer] = args;
|
|
1209
|
-
const env = create(VmSharedContext);
|
|
1210
|
-
if (vmValues) {
|
|
1211
|
-
for (const [key, value] of entries(vmValues)) {
|
|
1212
|
-
if (!isVmAny(value, false)) continue;
|
|
1213
|
-
env[key] = value ?? null;
|
|
1214
|
-
}
|
|
1215
|
-
}
|
|
1216
|
-
if (externValues) {
|
|
1217
|
-
for (const [key, value] of entries(externValues)) {
|
|
1218
|
-
env[key] = value == null ? null : wrapToVmValue(value, null);
|
|
1219
|
-
}
|
|
1220
|
-
}
|
|
1221
|
-
return new ValueVmContext(env, describer ?? void 0);
|
|
1222
|
-
}
|
|
1223
|
-
function isVmContext(context) {
|
|
1224
|
-
if (context == null || typeof context != "object") return false;
|
|
1225
|
-
return context[kVmContext] === true;
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
65
|
// src/vm/lib/global/index.ts
|
|
1229
66
|
var global_exports = {};
|
|
1230
67
|
__export(global_exports, {
|
|
1231
68
|
"@e": () => E,
|
|
1232
69
|
"@pi": () => PI,
|
|
1233
|
-
abs: () =>
|
|
70
|
+
abs: () => abs,
|
|
1234
71
|
acos: () => acos,
|
|
1235
72
|
acosh: () => acosh,
|
|
1236
73
|
all: () => all,
|
|
@@ -1245,7 +82,7 @@ __export(global_exports, {
|
|
|
1245
82
|
b_or: () => b_or,
|
|
1246
83
|
b_xor: () => b_xor,
|
|
1247
84
|
cbrt: () => cbrt,
|
|
1248
|
-
ceil: () =>
|
|
85
|
+
ceil: () => ceil,
|
|
1249
86
|
chars: () => chars,
|
|
1250
87
|
contains: () => contains,
|
|
1251
88
|
cos: () => cos,
|
|
@@ -1274,7 +111,7 @@ __export(global_exports, {
|
|
|
1274
111
|
map: () => map2,
|
|
1275
112
|
matrix: () => matrix,
|
|
1276
113
|
max: () => max,
|
|
1277
|
-
min: () =>
|
|
114
|
+
min: () => min,
|
|
1278
115
|
panic: () => panic,
|
|
1279
116
|
pow: () => pow2,
|
|
1280
117
|
product: () => product,
|
|
@@ -1307,7 +144,7 @@ __export(global_exports, {
|
|
|
1307
144
|
trim: () => trim,
|
|
1308
145
|
trim_end: () => trim_end,
|
|
1309
146
|
trim_start: () => trim_start,
|
|
1310
|
-
trunc: () =>
|
|
147
|
+
trunc: () => trunc,
|
|
1311
148
|
values: () => values2,
|
|
1312
149
|
with: () => _with,
|
|
1313
150
|
zip: () => zip
|
|
@@ -1434,7 +271,7 @@ var max = VmLib(build(Math.max), {
|
|
|
1434
271
|
returnsType: "number",
|
|
1435
272
|
examples: ["max(3, 7, 2) // 7"]
|
|
1436
273
|
});
|
|
1437
|
-
var
|
|
274
|
+
var min = VmLib(build(Math.min), {
|
|
1438
275
|
summary: "返回一组数中的最小值",
|
|
1439
276
|
params: { "..values": "要比较的数值" },
|
|
1440
277
|
paramsType: { "..values": "number[]" },
|
|
@@ -1485,7 +322,7 @@ function build2(f) {
|
|
|
1485
322
|
return f($ToNumber(x));
|
|
1486
323
|
};
|
|
1487
324
|
}
|
|
1488
|
-
var
|
|
325
|
+
var trunc = VmLib(build2(Math.trunc), {
|
|
1489
326
|
summary: "返回数值的整数部分(去除小数)",
|
|
1490
327
|
params: { x: "要取整数部分的数" },
|
|
1491
328
|
paramsType: { x: "number" },
|
|
@@ -1497,7 +334,7 @@ var floor = VmLib(build2(Math.floor), {
|
|
|
1497
334
|
paramsType: { x: "number" },
|
|
1498
335
|
returnsType: "number"
|
|
1499
336
|
});
|
|
1500
|
-
var
|
|
337
|
+
var ceil = VmLib(build2(Math.ceil), {
|
|
1501
338
|
summary: "返回大于等于给定数的最小整数",
|
|
1502
339
|
params: { x: "要向上取整的数" },
|
|
1503
340
|
paramsType: { x: "number" },
|
|
@@ -1526,7 +363,7 @@ var sign = VmLib(build2(Math.sign), {
|
|
|
1526
363
|
paramsType: { x: "number" },
|
|
1527
364
|
returnsType: "number"
|
|
1528
365
|
});
|
|
1529
|
-
var
|
|
366
|
+
var abs = VmLib(build2(Math.abs), {
|
|
1530
367
|
summary: "返回数值的绝对值",
|
|
1531
368
|
params: { x: "要取绝对值的数" },
|
|
1532
369
|
paramsType: { x: "number" },
|
|
@@ -3286,16 +2123,20 @@ var DEFAULT_OPTIONS = Object.freeze({
|
|
|
3286
2123
|
serializeModule: serializeNil,
|
|
3287
2124
|
serializeExtern: serializeNil
|
|
3288
2125
|
});
|
|
2126
|
+
function isDefaultOptions(options) {
|
|
2127
|
+
return options == null || options === DEFAULT_OPTIONS;
|
|
2128
|
+
}
|
|
3289
2129
|
function getSerializeOptions(options) {
|
|
3290
|
-
if (options
|
|
3291
|
-
|
|
2130
|
+
if (isDefaultOptions(options)) return DEFAULT_OPTIONS;
|
|
2131
|
+
let opt = null;
|
|
3292
2132
|
for (const key in options) {
|
|
2133
|
+
if (!hasOwn(options, key) || !hasOwn(DEFAULT_OPTIONS, key)) continue;
|
|
3293
2134
|
const el = options[key];
|
|
3294
|
-
if (el
|
|
3295
|
-
|
|
3296
|
-
|
|
2135
|
+
if (el == null) continue;
|
|
2136
|
+
opt ??= { ...DEFAULT_OPTIONS };
|
|
2137
|
+
opt[key] = el;
|
|
3297
2138
|
}
|
|
3298
|
-
return Object.freeze(opt);
|
|
2139
|
+
return opt ? Object.freeze(opt) : DEFAULT_OPTIONS;
|
|
3299
2140
|
}
|
|
3300
2141
|
function serializeStringImpl(value, options) {
|
|
3301
2142
|
if (!/[\p{C}'"`$\\]/u.test(value)) {
|
|
@@ -3345,7 +2186,16 @@ function serializeStringImpl(value, options) {
|
|
|
3345
2186
|
function serializeString(value, options) {
|
|
3346
2187
|
return serializeStringImpl(value, getSerializeOptions(options));
|
|
3347
2188
|
}
|
|
3348
|
-
function
|
|
2189
|
+
function serializeRecordKeyDefault(key) {
|
|
2190
|
+
if (REG_ORDINAL_FULL.test(key) || REG_IDENTIFIER_FULL.test(key)) {
|
|
2191
|
+
return key;
|
|
2192
|
+
}
|
|
2193
|
+
return serializeStringImpl(key, DEFAULT_OPTIONS);
|
|
2194
|
+
}
|
|
2195
|
+
function serializeRecordKeyOpt(value, options) {
|
|
2196
|
+
if (isDefaultOptions(options)) {
|
|
2197
|
+
return serializeRecordKeyDefault(value);
|
|
2198
|
+
}
|
|
3349
2199
|
if (REG_ORDINAL_FULL.test(value)) {
|
|
3350
2200
|
return options.serializePropName(Number(value), options);
|
|
3351
2201
|
}
|
|
@@ -3354,8 +2204,11 @@ function serializePropNameImpl(value, options) {
|
|
|
3354
2204
|
}
|
|
3355
2205
|
return options.serializeString(value, options);
|
|
3356
2206
|
}
|
|
3357
|
-
function
|
|
3358
|
-
|
|
2207
|
+
function serializeRecordKey(key, options) {
|
|
2208
|
+
if (isDefaultOptions(options)) {
|
|
2209
|
+
return serializeRecordKeyDefault(key);
|
|
2210
|
+
}
|
|
2211
|
+
return serializeRecordKeyOpt(key, getSerializeOptions(options));
|
|
3359
2212
|
}
|
|
3360
2213
|
function serializeNil() {
|
|
3361
2214
|
return "nil";
|
|
@@ -3406,16 +2259,16 @@ function serializeRecord(value, depth, options) {
|
|
|
3406
2259
|
if (k === "0") {
|
|
3407
2260
|
return `(${serializeImpl(v, depth, options)},)`;
|
|
3408
2261
|
}
|
|
3409
|
-
return `(${
|
|
2262
|
+
return `(${serializeRecordKeyOpt(k, options)}: ${serializeImpl(v, depth, options)})`;
|
|
3410
2263
|
}
|
|
3411
|
-
const omitKey = e
|
|
2264
|
+
const omitKey = isVmArrayLikeRecordByEntires(e);
|
|
3412
2265
|
let str = "(";
|
|
3413
2266
|
for (const [key, val] of e) {
|
|
3414
2267
|
if (str.length > 1) str += ", ";
|
|
3415
2268
|
if (omitKey) {
|
|
3416
2269
|
str += serializeImpl(val, depth, options);
|
|
3417
2270
|
} else {
|
|
3418
|
-
str += `${
|
|
2271
|
+
str += `${serializeRecordKeyOpt(key, options)}: ${serializeImpl(val, depth, options)}`;
|
|
3419
2272
|
}
|
|
3420
2273
|
}
|
|
3421
2274
|
str += ")";
|
|
@@ -3472,12 +2325,12 @@ for (const [key, value] of entries(helpers_exports)) {
|
|
|
3472
2325
|
}
|
|
3473
2326
|
|
|
3474
2327
|
// src/compiler/create-script.ts
|
|
3475
|
-
var
|
|
2328
|
+
var kVmScript = Symbol.for("mirascript.vm.script");
|
|
3476
2329
|
function wrapScript(source, script) {
|
|
3477
|
-
if (
|
|
2330
|
+
if (kVmScript in script) {
|
|
3478
2331
|
return script;
|
|
3479
2332
|
}
|
|
3480
|
-
defineProperty(script,
|
|
2333
|
+
defineProperty(script, kVmScript, { value: true });
|
|
3481
2334
|
if (typeof source === "string") {
|
|
3482
2335
|
defineProperty(script, "source", { value: source, configurable: true });
|
|
3483
2336
|
} else if (source instanceof Uint8Array) {
|
|
@@ -3522,7 +2375,7 @@ function compileScriptFast(code, options) {
|
|
|
3522
2375
|
}
|
|
3523
2376
|
if (REG_IDENTIFIER_FAST.test(trimmedCode)) {
|
|
3524
2377
|
const id = trimmedCode;
|
|
3525
|
-
return wrapScript(code, (global = GlobalFallback()) => global.get(id)
|
|
2378
|
+
return wrapScript(code, (global = GlobalFallback()) => global.get(id));
|
|
3526
2379
|
}
|
|
3527
2380
|
if (REG_NUMBER_FULL.test(trimmedCode)) {
|
|
3528
2381
|
const num2 = Number(trimmedCode);
|
|
@@ -3652,36 +2505,6 @@ var keywords = () => {
|
|
|
3652
2505
|
};
|
|
3653
2506
|
|
|
3654
2507
|
export {
|
|
3655
|
-
VmError,
|
|
3656
|
-
isVmWrapper,
|
|
3657
|
-
operations_exports,
|
|
3658
|
-
VmSharedContext,
|
|
3659
|
-
defineVmContextValue,
|
|
3660
|
-
DefaultVmContext,
|
|
3661
|
-
createVmContext,
|
|
3662
|
-
isVmContext,
|
|
3663
|
-
configCheckpoint,
|
|
3664
|
-
isVmFunction,
|
|
3665
|
-
getVmFunctionInfo,
|
|
3666
|
-
VmFunction,
|
|
3667
|
-
toVmFunctionProxy,
|
|
3668
|
-
fromVmFunctionProxy,
|
|
3669
|
-
wrapToVmValue,
|
|
3670
|
-
unwrapFromVmValue,
|
|
3671
|
-
VmExtern,
|
|
3672
|
-
isVmExtern,
|
|
3673
|
-
VmModule,
|
|
3674
|
-
isVmModule,
|
|
3675
|
-
isVmScript,
|
|
3676
|
-
isVmConst,
|
|
3677
|
-
isVmImmutable,
|
|
3678
|
-
isVmValue,
|
|
3679
|
-
isVmAny,
|
|
3680
|
-
isVmArray,
|
|
3681
|
-
isVmRecord,
|
|
3682
|
-
isVmPrimitive,
|
|
3683
|
-
isVmCallable,
|
|
3684
|
-
VM_ARRAY_MAX_LENGTH,
|
|
3685
2508
|
constants_exports,
|
|
3686
2509
|
emitScript,
|
|
3687
2510
|
compile,
|
|
@@ -3690,7 +2513,7 @@ export {
|
|
|
3690
2513
|
debug_print,
|
|
3691
2514
|
lib,
|
|
3692
2515
|
serializeString,
|
|
3693
|
-
|
|
2516
|
+
serializeRecordKey,
|
|
3694
2517
|
serializeNil,
|
|
3695
2518
|
serializeBoolean,
|
|
3696
2519
|
serializeNumber,
|
|
@@ -3698,4 +2521,4 @@ export {
|
|
|
3698
2521
|
serializeRecord,
|
|
3699
2522
|
serialize
|
|
3700
2523
|
};
|
|
3701
|
-
//# sourceMappingURL=chunk-
|
|
2524
|
+
//# sourceMappingURL=chunk-Q74RKZ7O.js.map
|