@mirascript/mirascript 0.1.76 → 0.1.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-ZRLBJK6A.js → chunk-BPFOJ4Q6.js} +499 -470
- package/dist/chunk-BPFOJ4Q6.js.map +6 -0
- package/dist/{chunk-VI74OKFU.js → chunk-LSPCAN32.js} +291 -226
- package/dist/chunk-LSPCAN32.js.map +6 -0
- package/dist/compiler/emit/constants.d.ts +1 -1
- package/dist/compiler/emit/constants.d.ts.map +1 -1
- package/dist/compiler/emit/consts.d.ts.map +1 -1
- package/dist/compiler/emit/index.d.ts.map +1 -1
- package/dist/compiler/emit-script.d.ts.map +1 -1
- package/dist/compiler/worker.js +1 -1
- package/dist/helpers/convert/{to-boolean.d.ts → boolean.d.ts} +1 -1
- package/dist/helpers/convert/boolean.d.ts.map +1 -0
- package/dist/helpers/convert/{to-format.d.ts → format.d.ts} +1 -1
- package/dist/helpers/convert/format.d.ts.map +1 -0
- package/dist/helpers/convert/index.d.ts +4 -4
- package/dist/helpers/convert/index.d.ts.map +1 -1
- package/dist/helpers/convert/{to-number.d.ts → number.d.ts} +1 -1
- package/dist/helpers/convert/number.d.ts.map +1 -0
- package/dist/helpers/convert/{to-string.d.ts → string.d.ts} +3 -1
- package/dist/helpers/convert/string.d.ts.map +1 -0
- package/dist/helpers/error.d.ts +1 -0
- package/dist/helpers/error.d.ts.map +1 -1
- package/dist/helpers/serialize.d.ts.map +1 -1
- package/dist/helpers/types/array-like.d.ts +8 -0
- package/dist/helpers/types/array-like.d.ts.map +1 -0
- package/dist/helpers/types/basic.d.ts +26 -0
- package/dist/helpers/types/basic.d.ts.map +1 -0
- package/dist/helpers/types/composed.d.ts +12 -0
- package/dist/helpers/types/composed.d.ts.map +1 -0
- package/dist/helpers/types/const.d.ts +6 -0
- package/dist/helpers/types/const.d.ts.map +1 -0
- package/dist/helpers/types/get-type.d.ts +6 -0
- package/dist/helpers/types/get-type.d.ts.map +1 -0
- package/dist/helpers/types/index.d.ts +6 -0
- package/dist/helpers/types/index.d.ts.map +1 -0
- package/dist/helpers/types/proto.d.ts +5 -0
- package/dist/helpers/types/proto.d.ts.map +1 -0
- package/dist/helpers/utils.d.ts +9 -0
- package/dist/helpers/utils.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/subtle.js +3 -3
- package/dist/vm/lib/global/debug.d.ts.map +1 -1
- package/dist/vm/lib/global/json.d.ts +3 -2
- package/dist/vm/lib/global/json.d.ts.map +1 -1
- package/dist/vm/lib/global/math/tgamma.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/entries.d.ts +1 -1
- package/dist/vm/lib/global/sequence/entries.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/fold.d.ts +3 -0
- package/dist/vm/lib/global/sequence/fold.d.ts.map +1 -0
- package/dist/vm/lib/global/sequence/group.d.ts +3 -0
- package/dist/vm/lib/global/sequence/group.d.ts.map +1 -0
- package/dist/vm/lib/global/sequence/index.d.ts +2 -0
- package/dist/vm/lib/global/sequence/index.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/new.d.ts.map +1 -1
- package/dist/vm/lib/global/sequence/zip.d.ts +2 -2
- package/dist/vm/lib/global/sequence/zip.d.ts.map +1 -1
- package/dist/vm/lib/helpers.d.ts +2 -2
- package/dist/vm/lib/helpers.d.ts.map +1 -1
- package/dist/vm/lib/mod/index.d.ts +1 -1
- package/dist/vm/lib/mod/index.d.ts.map +1 -1
- package/dist/vm/lib/mod/matrix/bin-ops.d.ts +8 -0
- package/dist/vm/lib/mod/matrix/bin-ops.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/fill.d.ts +6 -0
- package/dist/vm/lib/mod/matrix/fill.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/helpers.d.ts +6 -0
- package/dist/vm/lib/mod/matrix/helpers.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/index.d.ts +6 -0
- package/dist/vm/lib/mod/matrix/index.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/invert.d.ts +3 -0
- package/dist/vm/lib/mod/matrix/invert.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/size.d.ts +2 -0
- package/dist/vm/lib/mod/matrix/size.d.ts.map +1 -0
- package/dist/vm/lib/mod/matrix/transpose.d.ts +2 -0
- package/dist/vm/lib/mod/matrix/transpose.d.ts.map +1 -0
- package/dist/vm/operations/array-range.d.ts +3 -3
- package/dist/vm/operations/array-range.d.ts.map +1 -1
- package/dist/vm/operations/call.d.ts +1 -1
- package/dist/vm/operations/call.d.ts.map +1 -1
- package/dist/vm/operations/compound.d.ts +1 -13
- package/dist/vm/operations/compound.d.ts.map +1 -1
- package/dist/vm/operations/index.d.ts +3 -0
- package/dist/vm/operations/index.d.ts.map +1 -1
- package/dist/vm/operations/iterable.d.ts +6 -0
- package/dist/vm/operations/iterable.d.ts.map +1 -0
- package/dist/vm/operations/record.d.ts +6 -0
- package/dist/vm/operations/record.d.ts.map +1 -0
- package/dist/vm/operations/slice.d.ts.map +1 -1
- package/dist/vm/operations/spread.d.ts +6 -0
- package/dist/vm/operations/spread.d.ts.map +1 -0
- package/dist/vm/operations/utils.d.ts.map +1 -1
- package/dist/vm/types/extern/access.d.ts +5 -0
- package/dist/vm/types/extern/access.d.ts.map +1 -0
- package/dist/vm/types/{extern.d.ts → extern/index.d.ts} +3 -3
- package/dist/vm/types/extern/index.d.ts.map +1 -0
- package/dist/vm/types/extern/tag.d.ts +3 -0
- package/dist/vm/types/extern/tag.d.ts.map +1 -0
- package/dist/vm/types/extern/utils.d.ts +13 -0
- package/dist/vm/types/extern/utils.d.ts.map +1 -0
- package/dist/vm/types/index.d.ts +3 -3
- package/dist/vm/types/index.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/compiler/compile-fast.ts +1 -1
- package/src/compiler/diagnostic.ts +2 -2
- package/src/compiler/emit/constants.ts +1 -1
- package/src/compiler/emit/consts.ts +0 -1
- package/src/compiler/emit/index.ts +1 -7
- package/src/compiler/emit/sourcemap.ts +1 -1
- package/src/compiler/emit-script.ts +1 -0
- package/src/compiler/load-module.ts +5 -1
- package/src/helpers/convert/{to-boolean.ts → boolean.ts} +1 -1
- package/src/helpers/convert/{to-format.ts → format.ts} +1 -1
- package/src/helpers/convert/index.ts +4 -4
- package/src/helpers/convert/{to-number.ts → number.ts} +16 -32
- package/src/helpers/convert/{to-string.ts → string.ts} +5 -4
- package/src/helpers/error.ts +3 -1
- package/src/helpers/serialize.ts +45 -44
- package/src/helpers/types/array-like.ts +32 -0
- package/src/helpers/types/basic.ts +82 -0
- package/src/helpers/types/composed.ts +27 -0
- package/src/helpers/types/const.ts +44 -0
- package/src/helpers/types/get-type.ts +16 -0
- package/src/helpers/types/index.ts +5 -0
- package/src/helpers/types/proto.ts +21 -0
- package/src/helpers/utils.ts +33 -0
- package/src/vm/lib/global/debug.ts +4 -8
- package/src/vm/lib/global/json.ts +21 -9
- package/src/vm/lib/global/math/tgamma.ts +8 -14
- package/src/vm/lib/global/sequence/all-any.ts +1 -1
- package/src/vm/lib/global/sequence/entries.ts +6 -1
- package/src/vm/lib/global/sequence/find.ts +1 -1
- package/src/vm/lib/global/sequence/fold.ts +30 -0
- package/src/vm/lib/global/sequence/group.ts +37 -0
- package/src/vm/lib/global/sequence/index.ts +2 -0
- package/src/vm/lib/global/sequence/map-filter.ts +3 -3
- package/src/vm/lib/global/sequence/new.ts +9 -3
- package/src/vm/lib/global/sequence/sort.ts +1 -1
- package/src/vm/lib/global/sequence/unique.ts +1 -1
- package/src/vm/lib/global/sequence/with.ts +5 -5
- package/src/vm/lib/global/sequence/zip.ts +21 -10
- package/src/vm/lib/global/time.ts +1 -1
- package/src/vm/lib/helpers.ts +12 -5
- package/src/vm/lib/mod/index.ts +1 -1
- package/src/vm/lib/mod/matrix/bin-ops.ts +291 -0
- package/src/vm/lib/mod/matrix/fill.ts +109 -0
- package/src/vm/lib/mod/matrix/helpers.ts +26 -0
- package/src/vm/lib/mod/matrix/index.ts +5 -0
- package/src/vm/lib/mod/matrix/invert.ts +122 -0
- package/src/vm/lib/mod/matrix/size.ts +15 -0
- package/src/vm/lib/mod/matrix/transpose.ts +32 -0
- package/src/vm/operations/array-range.ts +15 -27
- package/src/vm/operations/call.ts +2 -2
- package/src/vm/operations/compound.ts +5 -125
- package/src/vm/operations/helpers.ts +1 -1
- package/src/vm/operations/index.ts +3 -0
- package/src/vm/operations/iterable.ts +40 -0
- package/src/vm/operations/record.ts +33 -0
- package/src/vm/operations/slice.ts +23 -22
- package/src/vm/operations/spread.ts +57 -0
- package/src/vm/operations/type-check.ts +1 -1
- package/src/vm/operations/utils.ts +45 -37
- package/src/vm/types/boundary.ts +2 -2
- package/src/vm/types/extern/access.ts +24 -0
- package/src/vm/types/extern/index.ts +124 -0
- package/src/vm/types/extern/tag.ts +58 -0
- package/src/vm/types/extern/utils.ts +55 -0
- package/src/vm/types/function.ts +1 -1
- package/src/vm/types/index.ts +3 -3
- package/dist/chunk-VI74OKFU.js.map +0 -6
- package/dist/chunk-ZRLBJK6A.js.map +0 -6
- package/dist/helpers/convert/to-boolean.d.ts.map +0 -1
- package/dist/helpers/convert/to-format.d.ts.map +0 -1
- package/dist/helpers/convert/to-number.d.ts.map +0 -1
- package/dist/helpers/convert/to-string.d.ts.map +0 -1
- package/dist/helpers/types.d.ts +0 -58
- package/dist/helpers/types.d.ts.map +0 -1
- package/dist/vm/lib/mod/matrix.d.ts +0 -15
- package/dist/vm/lib/mod/matrix.d.ts.map +0 -1
- package/dist/vm/types/extern.d.ts.map +0 -1
- package/src/helpers/types.ts +0 -283
- package/src/vm/lib/mod/matrix.ts +0 -590
- package/src/vm/types/extern.ts +0 -197
|
@@ -61,8 +61,26 @@ var hasOwnEnumerable = Function.call.bind(
|
|
|
61
61
|
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
62
62
|
Object.prototype.propertyIsEnumerable
|
|
63
63
|
);
|
|
64
|
+
var SPECIAL_KEYS = new Set(getOwnPropertyNames(Object.prototype));
|
|
65
|
+
var setRecord = (obj, key, value) => {
|
|
66
|
+
if (!SPECIAL_KEYS.has(key)) {
|
|
67
|
+
obj[key] = value ?? null;
|
|
68
|
+
} else {
|
|
69
|
+
defineProperty(obj, key, {
|
|
70
|
+
__proto__: null,
|
|
71
|
+
value: value ?? null,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
enumerable: true
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var getRecord = (obj, key) => {
|
|
79
|
+
if (!hasOwnEnumerable(obj, key)) return void 0;
|
|
80
|
+
return obj[key] ?? null;
|
|
81
|
+
};
|
|
64
82
|
|
|
65
|
-
// src/helpers/types.ts
|
|
83
|
+
// src/helpers/types/basic.ts
|
|
66
84
|
function isVmScript(value) {
|
|
67
85
|
return typeof value === "function" && kVmScript in value;
|
|
68
86
|
}
|
|
@@ -102,12 +120,68 @@ function isVmArray(value) {
|
|
|
102
120
|
return true;
|
|
103
121
|
}
|
|
104
122
|
function isVmRecord(value) {
|
|
105
|
-
if (value == null || typeof value
|
|
106
|
-
if (isVmWrapper(value)) return false;
|
|
107
|
-
if (isVmArray(value)) return false;
|
|
123
|
+
if (value == null || typeof value != "object") return false;
|
|
124
|
+
if (isVmWrapper(value) || isVmArray(value)) return false;
|
|
108
125
|
value;
|
|
109
126
|
return true;
|
|
110
127
|
}
|
|
128
|
+
|
|
129
|
+
// src/helpers/types/proto.ts
|
|
130
|
+
function isPlainArray(value) {
|
|
131
|
+
const proto = getPrototypeOf(value);
|
|
132
|
+
return isArray(proto) && hasOwn(proto, "push");
|
|
133
|
+
}
|
|
134
|
+
function isPlainObject(value) {
|
|
135
|
+
const proto1 = getPrototypeOf(value);
|
|
136
|
+
if (proto1 == null) return true;
|
|
137
|
+
const proto2 = getPrototypeOf(proto1);
|
|
138
|
+
if (proto2 != null) return false;
|
|
139
|
+
return hasOwn(proto1, "hasOwnProperty");
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/helpers/types/const.ts
|
|
143
|
+
var MAX_DEPTH = 16;
|
|
144
|
+
function isVmArrayDeep(value, depth) {
|
|
145
|
+
if (!isPlainArray(value)) return false;
|
|
146
|
+
if (depth <= 0) return true;
|
|
147
|
+
const inner_depth = depth - 1;
|
|
148
|
+
return value.every((item) => isVmConstInner(item, inner_depth));
|
|
149
|
+
}
|
|
150
|
+
function isVmRecordDeep(value, depth) {
|
|
151
|
+
if (!isPlainObject(value)) return false;
|
|
152
|
+
if (depth <= 0) return true;
|
|
153
|
+
const inner_depth = depth - 1;
|
|
154
|
+
return values(value).every((value2) => isVmConstInner(value2, inner_depth));
|
|
155
|
+
}
|
|
156
|
+
function isVmConstInner(value, depth) {
|
|
157
|
+
if (value == null) return true;
|
|
158
|
+
if (typeof value == "string" || typeof value == "number" || typeof value == "boolean") return true;
|
|
159
|
+
if (typeof value == "object") {
|
|
160
|
+
if (isVmWrapper(value)) return false;
|
|
161
|
+
if (isArray(value)) {
|
|
162
|
+
return isVmArrayDeep(value, depth);
|
|
163
|
+
} else {
|
|
164
|
+
return isVmRecordDeep(value, depth);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
function isVmConst(value, checkDeep = false) {
|
|
170
|
+
if (value === void 0) return false;
|
|
171
|
+
return isVmConstInner(value, checkDeep ? MAX_DEPTH : 0);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/helpers/types/get-type.ts
|
|
175
|
+
function getVmType(value) {
|
|
176
|
+
if (value === void 0) return "uninitialized";
|
|
177
|
+
if (value === null) return "nil";
|
|
178
|
+
if (isVmWrapper(value)) return value.type;
|
|
179
|
+
if (isVmArray(value)) return "array";
|
|
180
|
+
if (typeof value == "object") return "record";
|
|
181
|
+
return typeof value;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// src/helpers/types/array-like.ts
|
|
111
185
|
function isVmArrayLikeRecordByEntries(entries2) {
|
|
112
186
|
const { length } = entries2;
|
|
113
187
|
if (length === 0) return true;
|
|
@@ -131,116 +205,94 @@ function isVmArrayLikeRecordByKeys(keys2) {
|
|
|
131
205
|
function isVmArrayLikeRecord(value) {
|
|
132
206
|
return isVmArrayLikeRecordByKeys(keys(value));
|
|
133
207
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (!depth) return true;
|
|
139
|
-
return value.every((item) => isVmConstInner(item, depth));
|
|
208
|
+
|
|
209
|
+
// src/helpers/types/composed.ts
|
|
210
|
+
function isVmImmutable(value, checkDeep = false) {
|
|
211
|
+
return isVmModule(value) || isVmFunction(value) || isVmConst(value, checkDeep);
|
|
140
212
|
}
|
|
141
|
-
function
|
|
142
|
-
|
|
143
|
-
const proto1 = getPrototypeOf(value);
|
|
144
|
-
if (proto1 == null) {
|
|
145
|
-
isRecord = true;
|
|
146
|
-
} else {
|
|
147
|
-
const proto2 = getPrototypeOf(proto1);
|
|
148
|
-
if (proto2 != null) {
|
|
149
|
-
isRecord = false;
|
|
150
|
-
} else {
|
|
151
|
-
isRecord = "hasOwnProperty" in value;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (!isRecord) return false;
|
|
155
|
-
if (!depth) return true;
|
|
156
|
-
return values(value).every((value2) => isVmConstInner(value2, depth));
|
|
213
|
+
function isVmValue(value, checkDeep = false) {
|
|
214
|
+
return isVmWrapper(value) || isVmFunction(value) || isVmConst(value, checkDeep);
|
|
157
215
|
}
|
|
158
|
-
function
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
case "string":
|
|
162
|
-
case "number":
|
|
163
|
-
case "boolean":
|
|
164
|
-
case "undefined":
|
|
165
|
-
return true;
|
|
166
|
-
case "object":
|
|
167
|
-
if (value == null) return true;
|
|
168
|
-
if (isVmWrapper(value)) return false;
|
|
169
|
-
if (isArray(value)) {
|
|
170
|
-
return isVmArrayDeep(value, depth);
|
|
171
|
-
} else {
|
|
172
|
-
return isVmRecordDeep(value, depth);
|
|
173
|
-
}
|
|
174
|
-
case "function":
|
|
175
|
-
case "bigint":
|
|
176
|
-
case "symbol":
|
|
177
|
-
default:
|
|
178
|
-
return false;
|
|
179
|
-
}
|
|
216
|
+
function isVmAny(value, checkDeep) {
|
|
217
|
+
if (value == null) return true;
|
|
218
|
+
return isVmValue(value, checkDeep);
|
|
180
219
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
} else {
|
|
197
|
-
return isVmConstInner(value, 1);
|
|
220
|
+
|
|
221
|
+
// src/helpers/error.ts
|
|
222
|
+
var VmError = class _VmError extends Error {
|
|
223
|
+
constructor(message, recovered) {
|
|
224
|
+
super(message);
|
|
225
|
+
this.recovered = recovered;
|
|
226
|
+
this.name = "VmError";
|
|
227
|
+
}
|
|
228
|
+
/** 从其他错误构造 */
|
|
229
|
+
static from(prefix, error, recovered) {
|
|
230
|
+
if (prefix) {
|
|
231
|
+
if (prefix.endsWith(":")) {
|
|
232
|
+
prefix += " ";
|
|
233
|
+
} else if (!prefix.endsWith(": ")) {
|
|
234
|
+
prefix += ": ";
|
|
198
235
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
236
|
+
}
|
|
237
|
+
let vmError;
|
|
238
|
+
if (error instanceof Error) {
|
|
239
|
+
vmError = new _VmError(`${prefix}${error.message}`, recovered);
|
|
240
|
+
vmError.stack = error.stack;
|
|
241
|
+
} else {
|
|
242
|
+
vmError = new _VmError(`${prefix}${String(error)}`, recovered);
|
|
243
|
+
}
|
|
244
|
+
vmError.cause = error;
|
|
245
|
+
return vmError;
|
|
205
246
|
}
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
// src/helpers/serialize.ts
|
|
250
|
+
import { REG_IDENTIFIER_FULL, REG_ORDINAL_FULL } from "@mirascript/constants";
|
|
251
|
+
|
|
252
|
+
// src/helpers/convert/string.ts
|
|
253
|
+
function numberToString(value, minusZero) {
|
|
254
|
+
if (isNaN(value)) return "nan";
|
|
255
|
+
if (value === Infinity) return "inf";
|
|
256
|
+
if (value === -Infinity) return "-inf";
|
|
257
|
+
if (minusZero && value === 0 && 1 / value < 0) return "-0";
|
|
258
|
+
return String(value);
|
|
206
259
|
}
|
|
207
|
-
function
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
default:
|
|
226
|
-
return false;
|
|
260
|
+
function innerToString(value, useBraces) {
|
|
261
|
+
if (value == null) return "nil";
|
|
262
|
+
if (typeof value == "number") return numberToString(value, false);
|
|
263
|
+
if (typeof value == "string" || typeof value == "boolean") return String(value);
|
|
264
|
+
if (typeof value == "function") return displayFunction(value);
|
|
265
|
+
if (isVmWrapper(value)) return value.toString(useBraces);
|
|
266
|
+
if (isVmArray(value)) {
|
|
267
|
+
const strings = [];
|
|
268
|
+
for (const item of value) {
|
|
269
|
+
strings.push(innerToString(item, true));
|
|
270
|
+
}
|
|
271
|
+
const results = strings.join(", ");
|
|
272
|
+
if (!useBraces) return results;
|
|
273
|
+
return `[${results}]`;
|
|
274
|
+
} else {
|
|
275
|
+
const entries2 = keys(value).map((key) => `${key}: ${innerToString(value[key], true)}`).join(", ");
|
|
276
|
+
if (!useBraces) return entries2;
|
|
277
|
+
return `(${entries2})`;
|
|
227
278
|
}
|
|
228
279
|
}
|
|
229
|
-
function
|
|
230
|
-
if (value
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
280
|
+
function toString(value, fallback) {
|
|
281
|
+
if (typeof value == "string") return value;
|
|
282
|
+
if (value == null) return "";
|
|
283
|
+
try {
|
|
284
|
+
return innerToString(value, false);
|
|
285
|
+
} catch (ex) {
|
|
286
|
+
if (fallback === void 0) {
|
|
287
|
+
const e = new VmError(`Failed to convert value to string: ${display(value)}`, "");
|
|
288
|
+
e.cause = ex;
|
|
289
|
+
throw e;
|
|
290
|
+
}
|
|
291
|
+
return fallback;
|
|
292
|
+
}
|
|
240
293
|
}
|
|
241
294
|
|
|
242
295
|
// src/helpers/serialize.ts
|
|
243
|
-
import { REG_IDENTIFIER_FULL, REG_ORDINAL_FULL } from "@mirascript/constants";
|
|
244
296
|
function serializeNil() {
|
|
245
297
|
return "nil";
|
|
246
298
|
}
|
|
@@ -248,13 +300,7 @@ function serializeBoolean(value) {
|
|
|
248
300
|
return value ? "true" : "false";
|
|
249
301
|
}
|
|
250
302
|
function serializeNumber(value) {
|
|
251
|
-
|
|
252
|
-
if (!isFinite(value)) return value < 0 ? "-inf" : "inf";
|
|
253
|
-
if (value === 0) {
|
|
254
|
-
if (1 / value < 0) return "-0";
|
|
255
|
-
return "0";
|
|
256
|
-
}
|
|
257
|
-
return String(value);
|
|
303
|
+
return numberToString(value, true);
|
|
258
304
|
}
|
|
259
305
|
function serializeStringEscaped(escaped, options) {
|
|
260
306
|
return options.serializeStringEscape("\\" + escaped, options);
|
|
@@ -265,6 +311,38 @@ function serializeStringContent(value, options) {
|
|
|
265
311
|
var STRING_QUOTE = `'`;
|
|
266
312
|
var STRING_REG = new RegExp(String.raw`[${STRING_QUOTE}\\\$\p{C}\u2028\u2029]`, "gu");
|
|
267
313
|
var STRING_MARK = /^[\p{M}]$/u;
|
|
314
|
+
function serializeSpecialChar(char, options) {
|
|
315
|
+
if (char === STRING_QUOTE) {
|
|
316
|
+
return serializeStringEscaped(STRING_QUOTE, options);
|
|
317
|
+
} else if (char === "\0") {
|
|
318
|
+
return serializeStringEscaped(`0`, options);
|
|
319
|
+
} else if (char === "\n") {
|
|
320
|
+
return serializeStringEscaped(`n`, options);
|
|
321
|
+
} else if (char === "\r") {
|
|
322
|
+
return serializeStringEscaped(`r`, options);
|
|
323
|
+
} else if (char === " ") {
|
|
324
|
+
return serializeStringEscaped(`t`, options);
|
|
325
|
+
} else if (char === "\b") {
|
|
326
|
+
return serializeStringEscaped(`b`, options);
|
|
327
|
+
} else if (char === "\f") {
|
|
328
|
+
return serializeStringEscaped(`f`, options);
|
|
329
|
+
} else if (char === "\v") {
|
|
330
|
+
return serializeStringEscaped(`v`, options);
|
|
331
|
+
} else if (char === "\\") {
|
|
332
|
+
return serializeStringEscaped(`\\`, options);
|
|
333
|
+
} else if (char === "$") {
|
|
334
|
+
return serializeStringEscaped(`$`, options);
|
|
335
|
+
} else {
|
|
336
|
+
const code = char.codePointAt(0);
|
|
337
|
+
if (code <= 127) {
|
|
338
|
+
return serializeStringEscaped(`x${code.toString(16).padStart(2, "0")}`, options);
|
|
339
|
+
} else if (code >= 55296 && code <= 57343) {
|
|
340
|
+
return serializeStringContent("�", options);
|
|
341
|
+
} else {
|
|
342
|
+
return serializeStringEscaped(`u{${code.toString(16)}}`, options);
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
268
346
|
function serializeStringImpl(value, options) {
|
|
269
347
|
const oq = options.serializeStringQuote(STRING_QUOTE, true, options);
|
|
270
348
|
const cq = options.serializeStringQuote(STRING_QUOTE, false, options);
|
|
@@ -277,46 +355,15 @@ function serializeStringImpl(value, options) {
|
|
|
277
355
|
const cp = value.codePointAt(lastIndex);
|
|
278
356
|
const ch = String.fromCodePoint(cp);
|
|
279
357
|
if (!STRING_MARK.test(ch)) break;
|
|
280
|
-
|
|
281
|
-
ret += c;
|
|
358
|
+
ret += serializeStringEscaped(`u{${cp.toString(16)}}`, options);
|
|
282
359
|
lastIndex += ch.length;
|
|
283
360
|
}
|
|
284
361
|
STRING_REG.lastIndex = lastIndex;
|
|
285
362
|
let match;
|
|
286
363
|
while ((match = STRING_REG.exec(value)) !== null) {
|
|
287
|
-
const char = match[0];
|
|
288
364
|
ret += serializeStringContent(value.slice(lastIndex, match.index), options);
|
|
289
365
|
lastIndex = STRING_REG.lastIndex;
|
|
290
|
-
|
|
291
|
-
ret += serializeStringEscaped(STRING_QUOTE, options);
|
|
292
|
-
} else if (char === "\0") {
|
|
293
|
-
ret += serializeStringEscaped(`0`, options);
|
|
294
|
-
} else if (char === "\n") {
|
|
295
|
-
ret += serializeStringEscaped(`n`, options);
|
|
296
|
-
} else if (char === "\r") {
|
|
297
|
-
ret += serializeStringEscaped(`r`, options);
|
|
298
|
-
} else if (char === " ") {
|
|
299
|
-
ret += serializeStringEscaped(`t`, options);
|
|
300
|
-
} else if (char === "\b") {
|
|
301
|
-
ret += serializeStringEscaped(`b`, options);
|
|
302
|
-
} else if (char === "\f") {
|
|
303
|
-
ret += serializeStringEscaped(`f`, options);
|
|
304
|
-
} else if (char === "\v") {
|
|
305
|
-
ret += serializeStringEscaped(`v`, options);
|
|
306
|
-
} else if (char === "\\") {
|
|
307
|
-
ret += serializeStringEscaped(`\\`, options);
|
|
308
|
-
} else if (char === "$") {
|
|
309
|
-
ret += serializeStringEscaped(`$`, options);
|
|
310
|
-
} else {
|
|
311
|
-
const code = char.codePointAt(0);
|
|
312
|
-
if (code <= 127) {
|
|
313
|
-
ret += serializeStringEscaped(`x${code.toString(16).padStart(2, "0")}`, options);
|
|
314
|
-
} else if (code >= 55296 && code <= 57343) {
|
|
315
|
-
ret += serializeStringContent("�", options);
|
|
316
|
-
} else {
|
|
317
|
-
ret += serializeStringEscaped(`u{${code.toString(16)}}`, options);
|
|
318
|
-
}
|
|
319
|
-
}
|
|
366
|
+
ret += serializeSpecialChar(match[0], options);
|
|
320
367
|
}
|
|
321
368
|
ret += serializeStringContent(value.slice(lastIndex), options);
|
|
322
369
|
ret += cq;
|
|
@@ -363,7 +410,7 @@ function serializeArray(value, depth, options) {
|
|
|
363
410
|
var { valueOf } = Object.prototype;
|
|
364
411
|
function customValueOf(value) {
|
|
365
412
|
const thisValueOf = value.valueOf;
|
|
366
|
-
if (typeof thisValueOf
|
|
413
|
+
if (typeof thisValueOf !== "function" || thisValueOf === valueOf) {
|
|
367
414
|
return void 0;
|
|
368
415
|
}
|
|
369
416
|
const customValue = thisValueOf.call(value);
|
|
@@ -515,33 +562,95 @@ var DISPLAY_OPTIONS = Object.freeze({
|
|
|
515
562
|
serializeExtern: displayExtern
|
|
516
563
|
});
|
|
517
564
|
|
|
518
|
-
// src/helpers/
|
|
519
|
-
var
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
565
|
+
// src/helpers/convert/index.ts
|
|
566
|
+
var convert_exports = {};
|
|
567
|
+
__export(convert_exports, {
|
|
568
|
+
toBoolean: () => toBoolean,
|
|
569
|
+
toFormat: () => toFormat,
|
|
570
|
+
toNumber: () => toNumber,
|
|
571
|
+
toString: () => toString
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
// src/helpers/convert/number.ts
|
|
575
|
+
var parseInt = (value, radix) => Number.parseInt(value.slice(2), radix);
|
|
576
|
+
function parseNumericLiteral(value) {
|
|
577
|
+
const ch0 = value.charAt(0);
|
|
578
|
+
if (ch0 < "0" || ch0 > "9") return null;
|
|
579
|
+
if (/^0[bB][01]+$/.test(value)) return parseInt(value, 2);
|
|
580
|
+
if (/^0[oO][0-7]+$/.test(value)) return parseInt(value, 8);
|
|
581
|
+
if (/^0[xX][0-9a-fA-F]+$/.test(value)) return parseInt(value, 16);
|
|
582
|
+
if (/^[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?$/.test(value)) return Number.parseFloat(value);
|
|
583
|
+
return null;
|
|
584
|
+
}
|
|
585
|
+
function stringToNumber(value) {
|
|
586
|
+
value = value.trim();
|
|
587
|
+
if (value === "") return null;
|
|
588
|
+
if (value === "inf" || value === "+inf" || value === "Infinity" || value === "+Infinity") return PositiveInfinity;
|
|
589
|
+
if (value === "-inf" || value === "-Infinity") return NegativeInfinity;
|
|
590
|
+
if (value === "nan" || value === "NaN") return NotNumber;
|
|
591
|
+
if (value.startsWith("-")) {
|
|
592
|
+
const num = parseNumericLiteral(value.slice(1));
|
|
593
|
+
if (num != null) return -num;
|
|
594
|
+
return null;
|
|
595
|
+
} else if (value.startsWith("+")) {
|
|
596
|
+
return parseNumericLiteral(value.slice(1));
|
|
597
|
+
} else {
|
|
598
|
+
return parseNumericLiteral(value);
|
|
524
599
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
600
|
+
}
|
|
601
|
+
function toNumber(value, fallback) {
|
|
602
|
+
if (typeof value == "number") return value;
|
|
603
|
+
if (typeof value == "boolean") return value ? 1 : 0;
|
|
604
|
+
if (typeof value == "string") {
|
|
605
|
+
const num = stringToNumber(value);
|
|
606
|
+
if (num !== null) return num;
|
|
607
|
+
}
|
|
608
|
+
if (fallback === void 0) {
|
|
609
|
+
throw new VmError(`Failed to convert value to number: ${display(value)}`, NotNumber);
|
|
610
|
+
}
|
|
611
|
+
return fallback;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// src/helpers/convert/format.ts
|
|
615
|
+
function formatNumber(finite) {
|
|
616
|
+
if (finite === 0) return "0";
|
|
617
|
+
const s = finite.toString();
|
|
618
|
+
let ps;
|
|
619
|
+
const abs = Math.abs(finite);
|
|
620
|
+
if (abs >= 1e3 || abs < 1e-3) {
|
|
621
|
+
const ps1 = finite.toExponential();
|
|
622
|
+
const ps2 = finite.toExponential(5);
|
|
623
|
+
ps = ps1.length < ps2.length ? ps1 : ps2;
|
|
624
|
+
} else {
|
|
625
|
+
ps = finite.toPrecision(6);
|
|
626
|
+
}
|
|
627
|
+
return ps.length < s.length ? ps : s;
|
|
628
|
+
}
|
|
629
|
+
function toFormat(value, format) {
|
|
630
|
+
const f = format == null ? "" : format.trim();
|
|
631
|
+
if (typeof value == "number") {
|
|
632
|
+
if (!isFinite(value)) {
|
|
633
|
+
return toString(value, void 0);
|
|
533
634
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
635
|
+
if (/^\.\d+$/.test(f)) {
|
|
636
|
+
let digits = Math.trunc(Number(f.slice(1)));
|
|
637
|
+
if (!(digits <= 100)) digits = 100;
|
|
638
|
+
return value.toFixed(digits);
|
|
538
639
|
} else {
|
|
539
|
-
|
|
640
|
+
return formatNumber(value);
|
|
540
641
|
}
|
|
541
|
-
vmError.cause = error;
|
|
542
|
-
return vmError;
|
|
543
642
|
}
|
|
544
|
-
|
|
643
|
+
return toString(value, void 0);
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// src/helpers/convert/boolean.ts
|
|
647
|
+
function toBoolean(value, fallback) {
|
|
648
|
+
if (typeof value == "boolean") return value;
|
|
649
|
+
if (fallback === void 0) {
|
|
650
|
+
throw new VmError(`Failed to convert value to boolean: ${display(value)}`, false);
|
|
651
|
+
}
|
|
652
|
+
return fallback;
|
|
653
|
+
}
|
|
545
654
|
|
|
546
655
|
// src/compiler/generate-bytecode.ts
|
|
547
656
|
import { getModule, loadModule } from "@mirascript/bindings";
|
|
@@ -562,48 +671,6 @@ async function generateBytecode(script, options) {
|
|
|
562
671
|
// src/compiler/emit/index.ts
|
|
563
672
|
import { OpCode } from "@mirascript/constants";
|
|
564
673
|
|
|
565
|
-
// src/helpers/convert/to-string.ts
|
|
566
|
-
function numberToString(value) {
|
|
567
|
-
if (isNaN(value)) return "nan";
|
|
568
|
-
if (value === Infinity) return "inf";
|
|
569
|
-
if (value === -Infinity) return "-inf";
|
|
570
|
-
return String(value);
|
|
571
|
-
}
|
|
572
|
-
function innerToString(value, useBraces) {
|
|
573
|
-
if (value == null) return "nil";
|
|
574
|
-
if (typeof value == "number") return numberToString(value);
|
|
575
|
-
if (typeof value == "string" || typeof value == "boolean") return String(value);
|
|
576
|
-
if (typeof value == "function") return displayFunction(value);
|
|
577
|
-
if (isVmWrapper(value)) return value.toString(useBraces);
|
|
578
|
-
if (isVmArray(value)) {
|
|
579
|
-
const strings = [];
|
|
580
|
-
for (const item of value) {
|
|
581
|
-
strings.push(innerToString(item, true));
|
|
582
|
-
}
|
|
583
|
-
const results = strings.join(", ");
|
|
584
|
-
if (!useBraces) return results;
|
|
585
|
-
return `[${results}]`;
|
|
586
|
-
} else {
|
|
587
|
-
const entries2 = keys(value).map((key) => `${key}: ${innerToString(value[key], true)}`).join(", ");
|
|
588
|
-
if (!useBraces) return entries2;
|
|
589
|
-
return `(${entries2})`;
|
|
590
|
-
}
|
|
591
|
-
}
|
|
592
|
-
function toString(value, fallback) {
|
|
593
|
-
if (typeof value === "string") return value;
|
|
594
|
-
if (value == null) return "";
|
|
595
|
-
try {
|
|
596
|
-
return innerToString(value, false);
|
|
597
|
-
} catch (ex) {
|
|
598
|
-
if (fallback === void 0) {
|
|
599
|
-
const e = new VmError(`Failed to convert value to string: ${display(value)}`, "");
|
|
600
|
-
e.cause = ex;
|
|
601
|
-
throw e;
|
|
602
|
-
}
|
|
603
|
-
return fallback;
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
|
|
607
674
|
// src/compiler/emit/consts.ts
|
|
608
675
|
var { stringify } = JSON;
|
|
609
676
|
function toJsLiteral(value) {
|
|
@@ -739,7 +806,6 @@ function readConsts(constChunk) {
|
|
|
739
806
|
while (offset < length) {
|
|
740
807
|
const type = reader.getUint8(offset);
|
|
741
808
|
switch (type) {
|
|
742
|
-
/* c8 ignore next 2 */
|
|
743
809
|
case 0:
|
|
744
810
|
consts.push(null);
|
|
745
811
|
offset += 1;
|
|
@@ -862,7 +928,7 @@ function createSourceMap(source, scriptPrefix, sourcemaps, codeLines, functions,
|
|
|
862
928
|
}
|
|
863
929
|
|
|
864
930
|
// src/compiler/emit/constants.ts
|
|
865
|
-
var SCRIPT_PREFIX = `((global) => { global ??= $GlobalFallback(); try { $CpEnter();`;
|
|
931
|
+
var SCRIPT_PREFIX = `((/** @type {VmContext} */global) => { global ??= $GlobalFallback(); try { $CpEnter();`;
|
|
866
932
|
var SCRIPT_PREFIX_NO_GLOBAL = `(() => { try { $CpEnter();`;
|
|
867
933
|
|
|
868
934
|
// src/compiler/emit/index.ts
|
|
@@ -1004,12 +1070,6 @@ var Emitter = class {
|
|
|
1004
1070
|
this.codeLines.push(body);
|
|
1005
1071
|
break;
|
|
1006
1072
|
}
|
|
1007
|
-
if (opcode === OpCode.ElIf) {
|
|
1008
|
-
this.codeOffset++;
|
|
1009
|
-
const body = this.ident(-1) + `} else `;
|
|
1010
|
-
this.codeLines.push(body);
|
|
1011
|
-
return this.readCode();
|
|
1012
|
-
}
|
|
1013
1073
|
this.readCode();
|
|
1014
1074
|
}
|
|
1015
1075
|
return this.readBlockEnd(OpCode.IfEnd);
|
|
@@ -1737,8 +1797,8 @@ function formatDiagnostics(diagnostics, source, fileName) {
|
|
|
1737
1797
|
const messages = [];
|
|
1738
1798
|
for (const diagnostic of diagnostics) {
|
|
1739
1799
|
const range = formatRange(diagnostic.range);
|
|
1740
|
-
const codeName = DiagnosticCode[diagnostic.code] || `Unknown
|
|
1741
|
-
let message = getDiagnosticMessage(diagnostic.code)
|
|
1800
|
+
const codeName = DiagnosticCode[diagnostic.code] || `Unknown`;
|
|
1801
|
+
let message = getDiagnosticMessage(diagnostic.code) || `Unknown diagnostic code: ${diagnostic.code}`;
|
|
1742
1802
|
for (const ref of diagnostic.references) {
|
|
1743
1803
|
const refRange = formatRange(ref.range);
|
|
1744
1804
|
message += `
|
|
@@ -1758,7 +1818,6 @@ export {
|
|
|
1758
1818
|
isSafeInteger,
|
|
1759
1819
|
NotNumber,
|
|
1760
1820
|
PositiveInfinity,
|
|
1761
|
-
NegativeInfinity,
|
|
1762
1821
|
hasOwn,
|
|
1763
1822
|
keys,
|
|
1764
1823
|
values,
|
|
@@ -1772,6 +1831,8 @@ export {
|
|
|
1772
1831
|
getPrototypeOf,
|
|
1773
1832
|
keysLength,
|
|
1774
1833
|
hasOwnEnumerable,
|
|
1834
|
+
setRecord,
|
|
1835
|
+
getRecord,
|
|
1775
1836
|
VM_ARRAY_MAX_LENGTH,
|
|
1776
1837
|
kVmScript,
|
|
1777
1838
|
kVmFunction,
|
|
@@ -1794,14 +1855,17 @@ export {
|
|
|
1794
1855
|
isVmPrimitive,
|
|
1795
1856
|
isVmArray,
|
|
1796
1857
|
isVmRecord,
|
|
1858
|
+
isVmConst,
|
|
1859
|
+
getVmType,
|
|
1797
1860
|
isVmArrayLikeRecordByEntries,
|
|
1798
1861
|
isVmArrayLikeRecordByKeys,
|
|
1799
1862
|
isVmArrayLikeRecord,
|
|
1800
|
-
isVmConst,
|
|
1801
1863
|
isVmImmutable,
|
|
1802
|
-
isVmAny,
|
|
1803
1864
|
isVmValue,
|
|
1804
|
-
|
|
1865
|
+
isVmAny,
|
|
1866
|
+
VmError,
|
|
1867
|
+
innerToString,
|
|
1868
|
+
toString,
|
|
1805
1869
|
serializeNil,
|
|
1806
1870
|
serializeBoolean,
|
|
1807
1871
|
serializeNumber,
|
|
@@ -1811,9 +1875,10 @@ export {
|
|
|
1811
1875
|
serializeRecord,
|
|
1812
1876
|
serialize,
|
|
1813
1877
|
display,
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1878
|
+
toNumber,
|
|
1879
|
+
toFormat,
|
|
1880
|
+
toBoolean,
|
|
1881
|
+
convert_exports,
|
|
1817
1882
|
generateBytecodeSync,
|
|
1818
1883
|
generateBytecode,
|
|
1819
1884
|
emit,
|
|
@@ -1824,4 +1889,4 @@ export {
|
|
|
1824
1889
|
parseDiagnostics,
|
|
1825
1890
|
formatDiagnostics
|
|
1826
1891
|
};
|
|
1827
|
-
//# sourceMappingURL=chunk-
|
|
1892
|
+
//# sourceMappingURL=chunk-LSPCAN32.js.map
|