cvm-server 0.13.0 → 0.14.0
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/main.cjs +1132 -908
- package/package.json +1 -1
package/main.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
3
3
|
const stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
4
4
|
const zod = require("zod");
|
|
5
5
|
const s$1 = require("typescript");
|
|
6
|
-
const
|
|
6
|
+
const N$1 = require("fs");
|
|
7
7
|
const r = require("path");
|
|
8
8
|
const mongodb = require("mongodb");
|
|
9
9
|
const promises = require("fs/promises");
|
|
@@ -11,31 +11,31 @@ const dotenv = require("dotenv");
|
|
|
11
11
|
const url = require("url");
|
|
12
12
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
13
13
|
function _interopNamespaceDefault(e2) {
|
|
14
|
-
const
|
|
14
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
15
15
|
if (e2) {
|
|
16
16
|
for (const k2 in e2) {
|
|
17
17
|
if (k2 !== "default") {
|
|
18
18
|
const d2 = Object.getOwnPropertyDescriptor(e2, k2);
|
|
19
|
-
Object.defineProperty(
|
|
19
|
+
Object.defineProperty(n, k2, d2.get ? d2 : {
|
|
20
20
|
enumerable: true,
|
|
21
21
|
get: () => e2[k2]
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
return Object.freeze(
|
|
26
|
+
n.default = e2;
|
|
27
|
+
return Object.freeze(n);
|
|
28
28
|
}
|
|
29
29
|
const s__namespace = /* @__PURE__ */ _interopNamespaceDefault(s$1);
|
|
30
|
-
const
|
|
30
|
+
const N__namespace = /* @__PURE__ */ _interopNamespaceDefault(N$1);
|
|
31
31
|
const r__namespace = /* @__PURE__ */ _interopNamespaceDefault(r);
|
|
32
32
|
const dotenv__namespace = /* @__PURE__ */ _interopNamespaceDefault(dotenv);
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
function
|
|
38
|
-
const t2 = [],
|
|
33
|
+
var _$1 = Object.defineProperty;
|
|
34
|
+
var I = (e2, t2, n) => t2 in e2 ? _$1(e2, t2, { enumerable: true, configurable: true, writable: true, value: n }) : e2[t2] = n;
|
|
35
|
+
var o$1 = (e2, t2, n) => I(e2, typeof t2 != "symbol" ? t2 + "" : t2, n);
|
|
36
|
+
var i$2 = /* @__PURE__ */ ((e2) => (e2.PUSH = "PUSH", e2.PUSH_UNDEFINED = "PUSH_UNDEFINED", e2.POP = "POP", e2.DUP = "DUP", e2.DUP2 = "DUP2", e2.SWAP = "SWAP", e2.LOAD = "LOAD", e2.STORE = "STORE", e2.CONCAT = "CONCAT", e2.ARRAY_NEW = "ARRAY_NEW", e2.ARRAY_PUSH = "ARRAY_PUSH", e2.ARRAY_GET = "ARRAY_GET", e2.ARRAY_SET = "ARRAY_SET", e2.ARRAY_LEN = "ARRAY_LEN", e2.ARRAY_MAP_PROP = "ARRAY_MAP_PROP", e2.ARRAY_FILTER_PROP = "ARRAY_FILTER_PROP", e2.ARRAY_SLICE = "ARRAY_SLICE", e2.ARRAY_JOIN = "ARRAY_JOIN", e2.ARRAY_INDEX_OF = "ARRAY_INDEX_OF", e2.STRING_LEN = "STRING_LEN", e2.STRING_SUBSTRING = "STRING_SUBSTRING", e2.STRING_INDEXOF = "STRING_INDEXOF", e2.STRING_SPLIT = "STRING_SPLIT", e2.STRING_SLICE = "STRING_SLICE", e2.STRING_CHARAT = "STRING_CHARAT", e2.STRING_TOUPPERCASE = "STRING_TOUPPERCASE", e2.STRING_TOLOWERCASE = "STRING_TOLOWERCASE", e2.STRING_INCLUDES = "STRING_INCLUDES", e2.STRING_ENDS_WITH = "STRING_ENDS_WITH", e2.STRING_STARTS_WITH = "STRING_STARTS_WITH", e2.STRING_TRIM = "STRING_TRIM", e2.STRING_TRIM_START = "STRING_TRIM_START", e2.STRING_TRIM_END = "STRING_TRIM_END", e2.STRING_REPLACE = "STRING_REPLACE", e2.STRING_REPLACE_ALL = "STRING_REPLACE_ALL", e2.STRING_LAST_INDEX_OF = "STRING_LAST_INDEX_OF", e2.STRING_REPEAT = "STRING_REPEAT", e2.STRING_PAD_START = "STRING_PAD_START", e2.STRING_PAD_END = "STRING_PAD_END", e2.LOAD_REGEX = "LOAD_REGEX", e2.LENGTH = "LENGTH", e2.TO_STRING = "TO_STRING", e2.JSON_PARSE = "JSON_PARSE", e2.TYPEOF = "TYPEOF", e2.ADD = "ADD", e2.SUB = "SUB", e2.MUL = "MUL", e2.DIV = "DIV", e2.MOD = "MOD", e2.UNARY_MINUS = "UNARY_MINUS", e2.UNARY_PLUS = "UNARY_PLUS", e2.INC = "INC", e2.DEC = "DEC", e2.EQ = "EQ", e2.NEQ = "NEQ", e2.LT = "LT", e2.GT = "GT", e2.LTE = "LTE", e2.GTE = "GTE", e2.EQ_STRICT = "EQ_STRICT", e2.NEQ_STRICT = "NEQ_STRICT", e2.JUMP = "JUMP", e2.JUMP_IF = "JUMP_IF", e2.JUMP_IF_FALSE = "JUMP_IF_FALSE", e2.JUMP_IF_TRUE = "JUMP_IF_TRUE", e2.CALL = "CALL", e2.RETURN = "RETURN", e2.AND = "AND", e2.OR = "OR", e2.NOT = "NOT", e2.BREAK = "BREAK", e2.CONTINUE = "CONTINUE", e2.ITER_START = "ITER_START", e2.ITER_NEXT = "ITER_NEXT", e2.ITER_END = "ITER_END", e2.OBJECT_ITER_START = "OBJECT_ITER_START", e2.OBJECT_ITER_NEXT = "OBJECT_ITER_NEXT", e2.FS_LIST_FILES = "FS_LIST_FILES", e2.FS_READ_FILE = "FS_READ_FILE", e2.FS_WRITE_FILE = "FS_WRITE_FILE", e2.OBJECT_CREATE = "OBJECT_CREATE", e2.PROPERTY_GET = "PROPERTY_GET", e2.PROPERTY_SET = "PROPERTY_SET", e2.OBJECT_KEYS = "OBJECT_KEYS", e2.JSON_STRINGIFY = "JSON_STRINGIFY", e2.GET = "GET", e2.SET = "SET", e2.CC = "CC", e2.PRINT = "PRINT", e2.HALT = "HALT", e2))(i$2 || {});
|
|
37
|
+
function A(e2) {
|
|
38
|
+
const t2 = [], n = [];
|
|
39
39
|
let r2 = false;
|
|
40
40
|
const a2 = s__namespace.createSourceFile(
|
|
41
41
|
"program.ts",
|
|
@@ -43,30 +43,31 @@ function f$3(e2) {
|
|
|
43
43
|
s__namespace.ScriptTarget.Latest,
|
|
44
44
|
true
|
|
45
45
|
);
|
|
46
|
-
function m2(
|
|
47
|
-
if (s__namespace.isFunctionDeclaration(
|
|
48
|
-
const
|
|
49
|
-
["setTimeout", "fetch", "require", "import"].includes(
|
|
46
|
+
function m2(T) {
|
|
47
|
+
if (s__namespace.isFunctionDeclaration(T) && T.name && T.name.text === "main" && (r2 = true, T.parameters.length > 0 && t2.push("main() must not have parameters")), s__namespace.isCallExpression(T) && s__namespace.isIdentifier(T.expression)) {
|
|
48
|
+
const c2 = T.expression.text;
|
|
49
|
+
["setTimeout", "fetch", "require", "import"].includes(c2) && t2.push(`Unsupported function: ${c2}`);
|
|
50
50
|
}
|
|
51
|
-
s__namespace.forEachChild(
|
|
51
|
+
s__namespace.forEachChild(T, m2);
|
|
52
52
|
}
|
|
53
|
-
return m2(a2), r2 || t2.push("Program must have a main() function"), t2.length === 0 &&
|
|
54
|
-
bytecode:
|
|
53
|
+
return m2(a2), r2 || t2.push("Program must have a main() function"), t2.length === 0 && n.push({ op: i$2.HALT }), {
|
|
54
|
+
bytecode: n,
|
|
55
55
|
errors: t2,
|
|
56
56
|
hasMain: r2
|
|
57
57
|
};
|
|
58
58
|
}
|
|
59
|
-
class
|
|
59
|
+
class P {
|
|
60
60
|
constructor() {
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
o$1(this, "bytecode", []);
|
|
62
|
+
o$1(this, "contextStack", []);
|
|
63
|
+
o$1(this, "tempVarCounter", 0);
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
66
|
* Emit an instruction and return its index
|
|
66
67
|
*/
|
|
67
|
-
emit(t2,
|
|
68
|
+
emit(t2, n) {
|
|
68
69
|
const r2 = this.bytecode.length;
|
|
69
|
-
return this.bytecode.push({ op: t2, arg:
|
|
70
|
+
return this.bytecode.push({ op: t2, arg: n }), r2;
|
|
70
71
|
}
|
|
71
72
|
/**
|
|
72
73
|
* Get the current address (next instruction index)
|
|
@@ -77,14 +78,14 @@ class I {
|
|
|
77
78
|
/**
|
|
78
79
|
* Patch a jump instruction with the target address
|
|
79
80
|
*/
|
|
80
|
-
patchJump(t2,
|
|
81
|
-
t2 >= 0 && t2 < this.bytecode.length && (this.bytecode[t2].arg =
|
|
81
|
+
patchJump(t2, n) {
|
|
82
|
+
t2 >= 0 && t2 < this.bytecode.length && (this.bytecode[t2].arg = n);
|
|
82
83
|
}
|
|
83
84
|
/**
|
|
84
85
|
* Patch multiple jump instructions with the same target
|
|
85
86
|
*/
|
|
86
|
-
patchJumps(t2,
|
|
87
|
-
t2.forEach((r2) => this.patchJump(r2,
|
|
87
|
+
patchJumps(t2, n) {
|
|
88
|
+
t2.forEach((r2) => this.patchJump(r2, n));
|
|
88
89
|
}
|
|
89
90
|
/**
|
|
90
91
|
* Push a new jump context onto the stack
|
|
@@ -109,9 +110,9 @@ class I {
|
|
|
109
110
|
*/
|
|
110
111
|
findLoopContext() {
|
|
111
112
|
for (let t2 = this.contextStack.length - 1; t2 >= 0; t2--) {
|
|
112
|
-
const
|
|
113
|
-
if (
|
|
114
|
-
return
|
|
113
|
+
const n = this.contextStack[t2];
|
|
114
|
+
if (n.type === "loop" || n.type === "foreach")
|
|
115
|
+
return n;
|
|
115
116
|
}
|
|
116
117
|
return null;
|
|
117
118
|
}
|
|
@@ -133,326 +134,434 @@ class I {
|
|
|
133
134
|
getUnclosedContexts() {
|
|
134
135
|
return [...this.contextStack];
|
|
135
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Generate a unique temporary variable name
|
|
139
|
+
*/
|
|
140
|
+
generateTempVar() {
|
|
141
|
+
return `__temp${this.tempVarCounter++}`;
|
|
142
|
+
}
|
|
136
143
|
}
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const a2 = t2.emit(
|
|
144
|
+
const g = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
145
|
+
n(e2.expression);
|
|
146
|
+
const a2 = t2.emit(i$2.JUMP_IF_FALSE, -1), m2 = {
|
|
140
147
|
type: "if",
|
|
141
148
|
endTargets: []
|
|
142
149
|
};
|
|
143
150
|
if (e2.elseStatement ? m2.elseTarget = a2 : m2.endTargets.push(a2), t2.pushContext(m2), r2(e2.thenStatement), e2.elseStatement) {
|
|
144
|
-
const
|
|
145
|
-
m2.endTargets.push(
|
|
151
|
+
const c2 = t2.emit(i$2.JUMP, -1);
|
|
152
|
+
m2.endTargets.push(c2);
|
|
146
153
|
const S = t2.currentAddress();
|
|
147
154
|
t2.patchJump(a2, S), r2(e2.elseStatement);
|
|
148
155
|
}
|
|
149
|
-
const
|
|
150
|
-
if (
|
|
151
|
-
const
|
|
152
|
-
t2.patchJumps(
|
|
156
|
+
const T = t2.popContext();
|
|
157
|
+
if (T) {
|
|
158
|
+
const c2 = t2.currentAddress();
|
|
159
|
+
t2.patchJumps(T.endTargets, c2);
|
|
153
160
|
}
|
|
154
|
-
},
|
|
161
|
+
}, N = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
155
162
|
const a2 = t2.currentAddress();
|
|
156
|
-
|
|
157
|
-
const
|
|
163
|
+
n(e2.expression);
|
|
164
|
+
const T = {
|
|
158
165
|
type: "loop",
|
|
159
|
-
breakTargets: [t2.emit(
|
|
166
|
+
breakTargets: [t2.emit(i$2.JUMP_IF_FALSE, -1)],
|
|
160
167
|
continueTargets: [],
|
|
161
168
|
endTargets: [],
|
|
162
169
|
startAddress: a2
|
|
163
170
|
};
|
|
164
|
-
t2.pushContext(
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
171
|
+
t2.pushContext(T), r2(e2.statement), t2.emit(i$2.JUMP, a2);
|
|
172
|
+
const c2 = t2.popContext();
|
|
173
|
+
if (c2) {
|
|
167
174
|
const S = t2.currentAddress();
|
|
168
|
-
t2.patchJumps(
|
|
175
|
+
t2.patchJumps(c2.breakTargets || [], S);
|
|
169
176
|
}
|
|
170
|
-
},
|
|
177
|
+
}, h$1 = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
171
178
|
const a2 = e2.initializer, m2 = e2.expression;
|
|
172
|
-
let
|
|
179
|
+
let T;
|
|
173
180
|
if (s__namespace.isVariableDeclarationList(a2))
|
|
174
|
-
|
|
181
|
+
T = a2.declarations[0].name.getText();
|
|
175
182
|
else if (s__namespace.isIdentifier(a2))
|
|
176
|
-
|
|
183
|
+
T = a2.text;
|
|
177
184
|
else
|
|
178
185
|
throw new Error("Unsupported for-of variable declaration");
|
|
179
|
-
|
|
180
|
-
const
|
|
181
|
-
t2.emit(
|
|
182
|
-
const S = t2.emit(
|
|
183
|
-
t2.emit(
|
|
184
|
-
const
|
|
186
|
+
n(m2), t2.emit(i$2.ITER_START);
|
|
187
|
+
const c2 = t2.currentAddress();
|
|
188
|
+
t2.emit(i$2.ITER_NEXT);
|
|
189
|
+
const S = t2.emit(i$2.JUMP_IF_FALSE, -1);
|
|
190
|
+
t2.emit(i$2.STORE, T);
|
|
191
|
+
const u2 = {
|
|
185
192
|
type: "foreach",
|
|
186
193
|
breakTargets: [S],
|
|
187
194
|
continueTargets: [],
|
|
188
195
|
endTargets: [],
|
|
189
|
-
startAddress:
|
|
190
|
-
iterVariable:
|
|
196
|
+
startAddress: c2,
|
|
197
|
+
iterVariable: T
|
|
191
198
|
};
|
|
192
|
-
t2.pushContext(
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
const
|
|
196
|
-
t2.patchJumps(
|
|
199
|
+
t2.pushContext(u2), r2(e2.statement), t2.emit(i$2.JUMP, c2);
|
|
200
|
+
const l = t2.popContext();
|
|
201
|
+
if (l) {
|
|
202
|
+
const x2 = t2.currentAddress();
|
|
203
|
+
t2.patchJumps(l.breakTargets || [], x2), t2.emit(i$2.ITER_END);
|
|
197
204
|
}
|
|
198
|
-
},
|
|
205
|
+
}, p$2 = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
206
|
+
const a2 = e2.initializer, m2 = e2.expression;
|
|
207
|
+
let T;
|
|
208
|
+
if (s__namespace.isVariableDeclarationList(a2))
|
|
209
|
+
T = a2.declarations[0].name.getText();
|
|
210
|
+
else if (s__namespace.isIdentifier(a2))
|
|
211
|
+
T = a2.text;
|
|
212
|
+
else
|
|
213
|
+
throw new Error("Unsupported for-in variable declaration");
|
|
214
|
+
n(m2), t2.emit(i$2.OBJECT_ITER_START);
|
|
215
|
+
const c2 = t2.currentAddress();
|
|
216
|
+
t2.emit(i$2.OBJECT_ITER_NEXT);
|
|
217
|
+
const S = t2.emit(i$2.JUMP_IF_FALSE, -1);
|
|
218
|
+
t2.emit(i$2.STORE, T);
|
|
219
|
+
const u2 = {
|
|
220
|
+
type: "foreach",
|
|
221
|
+
breakTargets: [S],
|
|
222
|
+
continueTargets: [],
|
|
223
|
+
endTargets: [],
|
|
224
|
+
startAddress: c2,
|
|
225
|
+
iterVariable: T
|
|
226
|
+
};
|
|
227
|
+
t2.pushContext(u2), r2(e2.statement), t2.emit(i$2.JUMP, c2);
|
|
228
|
+
const l = t2.popContext();
|
|
229
|
+
if (l) {
|
|
230
|
+
const x2 = t2.currentAddress();
|
|
231
|
+
t2.patchJumps(l.breakTargets || [], x2), t2.emit(i$2.ITER_END);
|
|
232
|
+
}
|
|
233
|
+
}, U = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
234
|
+
if (e2.initializer)
|
|
235
|
+
if (s__namespace.isVariableDeclarationList(e2.initializer))
|
|
236
|
+
for (const S of e2.initializer.declarations)
|
|
237
|
+
S.initializer && (n(S.initializer), t2.emit(i$2.STORE, S.name.getText()));
|
|
238
|
+
else
|
|
239
|
+
n(e2.initializer), t2.emit(i$2.POP);
|
|
240
|
+
const a2 = t2.currentAddress();
|
|
241
|
+
let m2;
|
|
242
|
+
e2.condition && (n(e2.condition), m2 = t2.emit(i$2.JUMP_IF_FALSE, -1));
|
|
243
|
+
const T = {
|
|
244
|
+
type: "loop",
|
|
245
|
+
breakTargets: m2 ? [m2] : [],
|
|
246
|
+
continueTargets: [],
|
|
247
|
+
endTargets: [],
|
|
248
|
+
startAddress: a2
|
|
249
|
+
};
|
|
250
|
+
t2.pushContext(T), r2(e2.statement), e2.incrementor && (n(e2.incrementor), t2.emit(i$2.POP)), t2.emit(i$2.JUMP, a2);
|
|
251
|
+
const c2 = t2.popContext();
|
|
252
|
+
if (c2) {
|
|
253
|
+
const S = t2.currentAddress();
|
|
254
|
+
t2.patchJumps(c2.breakTargets || [], S);
|
|
255
|
+
}
|
|
256
|
+
}, y$1 = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
257
|
+
const a2 = t2.generateTempVar();
|
|
258
|
+
n(e2.expression), t2.emit(i$2.STORE, a2);
|
|
259
|
+
const m2 = [], T = [];
|
|
260
|
+
let c2 = null;
|
|
261
|
+
if (e2.caseBlock.clauses.forEach((l, x2) => {
|
|
262
|
+
if (s__namespace.isCaseClause(l)) {
|
|
263
|
+
t2.emit(i$2.LOAD, a2), n(l.expression), t2.emit(i$2.EQ_STRICT);
|
|
264
|
+
const R = t2.emit(i$2.JUMP_IF_TRUE, -1);
|
|
265
|
+
T.push(R);
|
|
266
|
+
} else s__namespace.isDefaultClause(l) && (c2 = t2.emit(i$2.JUMP, -1));
|
|
267
|
+
}), c2 === null) {
|
|
268
|
+
const l = t2.emit(i$2.JUMP, -1);
|
|
269
|
+
m2.push(l);
|
|
270
|
+
}
|
|
271
|
+
let S = 0;
|
|
272
|
+
e2.caseBlock.clauses.forEach((l, x2) => {
|
|
273
|
+
if (s__namespace.isCaseClause(l)) {
|
|
274
|
+
const R = t2.currentAddress();
|
|
275
|
+
t2.patchJumps([T[S]], R), S++, l.statements.forEach((E2) => {
|
|
276
|
+
if (s__namespace.isBreakStatement(E2)) {
|
|
277
|
+
const f3 = t2.emit(i$2.JUMP, -1);
|
|
278
|
+
m2.push(f3);
|
|
279
|
+
} else
|
|
280
|
+
r2(E2);
|
|
281
|
+
});
|
|
282
|
+
} else if (s__namespace.isDefaultClause(l)) {
|
|
283
|
+
const R = t2.currentAddress();
|
|
284
|
+
c2 !== null && t2.patchJumps([c2], R), l.statements.forEach((E2) => {
|
|
285
|
+
if (s__namespace.isBreakStatement(E2)) {
|
|
286
|
+
const f3 = t2.emit(i$2.JUMP, -1);
|
|
287
|
+
m2.push(f3);
|
|
288
|
+
} else
|
|
289
|
+
r2(E2);
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
const u2 = t2.currentAddress();
|
|
294
|
+
t2.patchJumps(m2, u2);
|
|
295
|
+
}, L$1 = (e2, t2, { compileStatement: n }) => {
|
|
199
296
|
e2.statements.forEach((r2) => {
|
|
200
|
-
|
|
297
|
+
n(r2);
|
|
201
298
|
});
|
|
202
|
-
},
|
|
299
|
+
}, k = (e2, t2, { compileExpression: n }) => {
|
|
203
300
|
const r2 = e2.declarationList.declarations[0];
|
|
204
|
-
r2.initializer && (
|
|
205
|
-
},
|
|
301
|
+
r2.initializer && (n(r2.initializer), t2.emit(i$2.STORE, r2.name.getText()));
|
|
302
|
+
}, D = (e2, t2, { compileExpression: n }) => {
|
|
206
303
|
const r2 = e2.expression;
|
|
207
304
|
if (s__namespace.isBinaryExpression(r2)) {
|
|
208
305
|
const a2 = r2.operatorToken.kind;
|
|
209
306
|
if (a2 === s__namespace.SyntaxKind.PlusEqualsToken || a2 === s__namespace.SyntaxKind.MinusEqualsToken || a2 === s__namespace.SyntaxKind.AsteriskEqualsToken || a2 === s__namespace.SyntaxKind.SlashEqualsToken || a2 === s__namespace.SyntaxKind.PercentEqualsToken) {
|
|
210
307
|
if (s__namespace.isIdentifier(r2.left)) {
|
|
211
|
-
switch (t2.emit(
|
|
308
|
+
switch (t2.emit(i$2.LOAD, r2.left.text), n(r2.right), a2) {
|
|
212
309
|
case s__namespace.SyntaxKind.PlusEqualsToken:
|
|
213
|
-
t2.emit(
|
|
310
|
+
t2.emit(i$2.ADD);
|
|
214
311
|
break;
|
|
215
312
|
case s__namespace.SyntaxKind.MinusEqualsToken:
|
|
216
|
-
t2.emit(
|
|
313
|
+
t2.emit(i$2.SUB);
|
|
217
314
|
break;
|
|
218
315
|
case s__namespace.SyntaxKind.AsteriskEqualsToken:
|
|
219
|
-
t2.emit(
|
|
316
|
+
t2.emit(i$2.MUL);
|
|
220
317
|
break;
|
|
221
318
|
case s__namespace.SyntaxKind.SlashEqualsToken:
|
|
222
|
-
t2.emit(
|
|
319
|
+
t2.emit(i$2.DIV);
|
|
223
320
|
break;
|
|
224
321
|
case s__namespace.SyntaxKind.PercentEqualsToken:
|
|
225
|
-
t2.emit(
|
|
322
|
+
t2.emit(i$2.MOD);
|
|
226
323
|
break;
|
|
227
324
|
}
|
|
228
|
-
t2.emit(
|
|
325
|
+
t2.emit(i$2.STORE, r2.left.text);
|
|
229
326
|
} else if (s__namespace.isElementAccessExpression(r2.left))
|
|
230
327
|
throw new Error("Compound assignment to array elements not yet supported");
|
|
231
328
|
return;
|
|
232
329
|
} else if (a2 === s__namespace.SyntaxKind.EqualsToken) {
|
|
233
|
-
if (
|
|
234
|
-
t2.emit(
|
|
330
|
+
if (n(r2.right), s__namespace.isIdentifier(r2.left))
|
|
331
|
+
t2.emit(i$2.STORE, r2.left.text);
|
|
235
332
|
else if (s__namespace.isElementAccessExpression(r2.left)) {
|
|
236
333
|
const m2 = `__temp_${t2.getBytecode().length}`;
|
|
237
|
-
t2.emit(
|
|
334
|
+
t2.emit(i$2.STORE, m2), n(r2.left.expression), n(r2.left.argumentExpression), t2.emit(i$2.LOAD, m2), t2.emit(i$2.ARRAY_SET), t2.emit(i$2.POP);
|
|
238
335
|
} else if (s__namespace.isPropertyAccessExpression(r2.left)) {
|
|
239
336
|
const m2 = `__temp_${t2.getBytecode().length}`;
|
|
240
|
-
t2.emit(
|
|
337
|
+
t2.emit(i$2.STORE, m2), n(r2.left.expression), t2.emit(i$2.PUSH, r2.left.name.text), t2.emit(i$2.LOAD, m2), t2.emit(i$2.PROPERTY_SET), t2.emit(i$2.POP);
|
|
241
338
|
}
|
|
242
339
|
return;
|
|
243
340
|
}
|
|
244
341
|
}
|
|
245
342
|
s__namespace.isCallExpression(r2) && s__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.expression.getText() === "console" && r2.expression.name.getText() === "log" ? (r2.arguments.forEach((a2) => {
|
|
246
|
-
|
|
247
|
-
}), t2.emit(
|
|
248
|
-
},
|
|
249
|
-
e2.expression ?
|
|
250
|
-
},
|
|
343
|
+
n(a2);
|
|
344
|
+
}), t2.emit(i$2.PRINT)) : s__namespace.isCallExpression(r2) && s__namespace.isIdentifier(r2.expression) && r2.expression.text === "CC" ? (r2.arguments.length > 0 && n(r2.arguments[0]), t2.emit(i$2.CC), t2.emit(i$2.POP)) : s__namespace.isCallExpression(r2) && s__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.name.getText() === "push" ? (n(r2.expression.expression), r2.arguments.length > 0 && n(r2.arguments[0]), t2.emit(i$2.ARRAY_PUSH)) : (s__namespace.isPostfixUnaryExpression(r2) || s__namespace.isPrefixUnaryExpression(r2), n(r2), t2.emit(i$2.POP));
|
|
345
|
+
}, G = (e2, t2, { compileExpression: n }) => {
|
|
346
|
+
e2.expression ? n(e2.expression) : t2.emit(i$2.PUSH, null), t2.emit(i$2.RETURN);
|
|
347
|
+
}, F$1 = (e2, t2, n) => {
|
|
251
348
|
const r2 = t2.findLoopContext();
|
|
252
349
|
if (r2) {
|
|
253
|
-
r2.type === "foreach" && t2.emit(
|
|
254
|
-
const a2 = t2.emit(
|
|
350
|
+
r2.type === "foreach" && t2.emit(i$2.ITER_END);
|
|
351
|
+
const a2 = t2.emit(i$2.BREAK, -1);
|
|
255
352
|
r2.breakTargets = r2.breakTargets || [], r2.breakTargets.push(a2);
|
|
256
353
|
} else
|
|
257
|
-
|
|
258
|
-
},
|
|
354
|
+
n.reportError(e2, "break statement not in loop");
|
|
355
|
+
}, b$1 = (e2, t2, n) => {
|
|
259
356
|
const r2 = t2.findLoopContext();
|
|
260
357
|
if (r2 && r2.startAddress !== void 0) {
|
|
261
|
-
const a2 = t2.emit(
|
|
358
|
+
const a2 = t2.emit(i$2.CONTINUE, r2.startAddress);
|
|
262
359
|
r2.continueTargets = r2.continueTargets || [], r2.continueTargets.push(a2);
|
|
263
360
|
} else
|
|
264
|
-
|
|
265
|
-
},
|
|
266
|
-
[s__namespace.SyntaxKind.IfStatement]:
|
|
267
|
-
[s__namespace.SyntaxKind.WhileStatement]:
|
|
268
|
-
[s__namespace.SyntaxKind.ForOfStatement]:
|
|
269
|
-
[s__namespace.SyntaxKind.
|
|
270
|
-
[s__namespace.SyntaxKind.
|
|
271
|
-
[s__namespace.SyntaxKind.
|
|
272
|
-
[s__namespace.SyntaxKind.
|
|
273
|
-
[s__namespace.SyntaxKind.
|
|
274
|
-
[s__namespace.SyntaxKind.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
361
|
+
n.reportError(e2, "continue statement not in loop");
|
|
362
|
+
}, K = {
|
|
363
|
+
[s__namespace.SyntaxKind.IfStatement]: g,
|
|
364
|
+
[s__namespace.SyntaxKind.WhileStatement]: N,
|
|
365
|
+
[s__namespace.SyntaxKind.ForOfStatement]: h$1,
|
|
366
|
+
[s__namespace.SyntaxKind.ForInStatement]: p$2,
|
|
367
|
+
[s__namespace.SyntaxKind.ForStatement]: U,
|
|
368
|
+
[s__namespace.SyntaxKind.SwitchStatement]: y$1,
|
|
369
|
+
[s__namespace.SyntaxKind.Block]: L$1,
|
|
370
|
+
[s__namespace.SyntaxKind.VariableStatement]: k,
|
|
371
|
+
[s__namespace.SyntaxKind.ExpressionStatement]: D,
|
|
372
|
+
[s__namespace.SyntaxKind.ReturnStatement]: G,
|
|
373
|
+
[s__namespace.SyntaxKind.BreakStatement]: F$1,
|
|
374
|
+
[s__namespace.SyntaxKind.ContinueStatement]: b$1
|
|
375
|
+
}, J = (e2, t2, n) => {
|
|
376
|
+
t2.emit(i$2.PUSH, e2.text);
|
|
377
|
+
}, H = (e2, t2, n) => {
|
|
378
|
+
t2.emit(i$2.PUSH, Number(e2.text));
|
|
379
|
+
}, M$1 = (e2, t2, n) => {
|
|
380
|
+
t2.emit(i$2.PUSH, true);
|
|
381
|
+
}, Y = (e2, t2, n) => {
|
|
382
|
+
t2.emit(i$2.PUSH, false);
|
|
383
|
+
}, B$1 = (e2, t2, n) => {
|
|
384
|
+
t2.emit(i$2.PUSH, null);
|
|
385
|
+
}, C$2 = (e2, t2, n) => {
|
|
386
|
+
const r2 = e2.text, a2 = r2.lastIndexOf("/"), m2 = r2.substring(1, a2), T = r2.substring(a2 + 1);
|
|
387
|
+
t2.emit(i$2.LOAD_REGEX, { pattern: m2, flags: T });
|
|
388
|
+
}, d$3 = (e2, t2, n) => {
|
|
389
|
+
e2.text === "undefined" ? t2.emit(i$2.PUSH_UNDEFINED) : t2.emit(i$2.LOAD, e2.text);
|
|
390
|
+
}, w$1 = (e2, t2, { compileExpression: n }) => {
|
|
391
|
+
t2.emit(i$2.ARRAY_NEW), e2.elements.forEach((r2) => {
|
|
392
|
+
n(r2), t2.emit(i$2.ARRAY_PUSH);
|
|
290
393
|
});
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
},
|
|
294
|
-
e2.name.text === "length" ? (
|
|
295
|
-
},
|
|
296
|
-
|
|
297
|
-
},
|
|
394
|
+
}, O = (e2, t2, { compileExpression: n }) => {
|
|
395
|
+
n(e2.expression);
|
|
396
|
+
}, q = (e2, t2, { compileExpression: n }) => {
|
|
397
|
+
e2.name.text === "length" ? (n(e2.expression), t2.emit(i$2.LENGTH)) : (n(e2.expression), t2.emit(i$2.PUSH, e2.name.text), t2.emit(i$2.PROPERTY_GET));
|
|
398
|
+
}, V$1 = (e2, t2, { compileExpression: n, reportError: r2 }) => {
|
|
399
|
+
n(e2.expression), e2.argumentExpression ? n(e2.argumentExpression) : r2(e2, "Element access requires an index expression"), t2.emit(i$2.ARRAY_GET);
|
|
400
|
+
}, W$1 = (e2, t2, { compileExpression: n }) => {
|
|
298
401
|
switch (e2.operator) {
|
|
299
402
|
case s__namespace.SyntaxKind.ExclamationToken:
|
|
300
|
-
|
|
403
|
+
n(e2.operand), t2.emit(i$2.NOT);
|
|
301
404
|
break;
|
|
302
405
|
case s__namespace.SyntaxKind.MinusToken:
|
|
303
|
-
|
|
406
|
+
n(e2.operand), t2.emit(i$2.UNARY_MINUS);
|
|
304
407
|
break;
|
|
305
408
|
case s__namespace.SyntaxKind.PlusToken:
|
|
306
|
-
|
|
409
|
+
n(e2.operand), t2.emit(i$2.UNARY_PLUS);
|
|
307
410
|
break;
|
|
308
411
|
case s__namespace.SyntaxKind.PlusPlusToken:
|
|
309
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
412
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(i$2.PUSH, e2.operand.text), t2.emit(i$2.INC, false));
|
|
310
413
|
break;
|
|
311
414
|
case s__namespace.SyntaxKind.MinusMinusToken:
|
|
312
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
415
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(i$2.PUSH, e2.operand.text), t2.emit(i$2.DEC, false));
|
|
313
416
|
break;
|
|
314
417
|
}
|
|
315
|
-
},
|
|
418
|
+
}, j$2 = (e2, t2, { compileExpression: n }) => {
|
|
316
419
|
switch (e2.operator) {
|
|
317
420
|
case s__namespace.SyntaxKind.PlusPlusToken:
|
|
318
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
421
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(i$2.PUSH, e2.operand.text), t2.emit(i$2.INC, true));
|
|
319
422
|
break;
|
|
320
423
|
case s__namespace.SyntaxKind.MinusMinusToken:
|
|
321
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
424
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(i$2.PUSH, e2.operand.text), t2.emit(i$2.DEC, true));
|
|
322
425
|
break;
|
|
323
426
|
}
|
|
324
|
-
},
|
|
427
|
+
}, X = (e2, t2, { compileExpression: n }) => {
|
|
325
428
|
const r2 = e2.operatorToken.kind;
|
|
326
|
-
switch (
|
|
429
|
+
switch (n(e2.left), n(e2.right), r2) {
|
|
327
430
|
case s__namespace.SyntaxKind.PlusToken:
|
|
328
|
-
t2.emit(
|
|
431
|
+
t2.emit(i$2.ADD);
|
|
329
432
|
break;
|
|
330
433
|
case s__namespace.SyntaxKind.MinusToken:
|
|
331
|
-
t2.emit(
|
|
434
|
+
t2.emit(i$2.SUB);
|
|
332
435
|
break;
|
|
333
436
|
case s__namespace.SyntaxKind.AsteriskToken:
|
|
334
|
-
t2.emit(
|
|
437
|
+
t2.emit(i$2.MUL);
|
|
335
438
|
break;
|
|
336
439
|
case s__namespace.SyntaxKind.SlashToken:
|
|
337
|
-
t2.emit(
|
|
440
|
+
t2.emit(i$2.DIV);
|
|
338
441
|
break;
|
|
339
442
|
case s__namespace.SyntaxKind.PercentToken:
|
|
340
|
-
t2.emit(
|
|
443
|
+
t2.emit(i$2.MOD);
|
|
341
444
|
break;
|
|
342
445
|
case s__namespace.SyntaxKind.EqualsEqualsToken:
|
|
343
|
-
t2.emit(
|
|
446
|
+
t2.emit(i$2.EQ);
|
|
344
447
|
break;
|
|
345
448
|
case s__namespace.SyntaxKind.ExclamationEqualsToken:
|
|
346
|
-
t2.emit(
|
|
449
|
+
t2.emit(i$2.NEQ);
|
|
347
450
|
break;
|
|
348
451
|
case s__namespace.SyntaxKind.LessThanToken:
|
|
349
|
-
t2.emit(
|
|
452
|
+
t2.emit(i$2.LT);
|
|
350
453
|
break;
|
|
351
454
|
case s__namespace.SyntaxKind.GreaterThanToken:
|
|
352
|
-
t2.emit(
|
|
455
|
+
t2.emit(i$2.GT);
|
|
353
456
|
break;
|
|
354
457
|
case s__namespace.SyntaxKind.LessThanEqualsToken:
|
|
355
|
-
t2.emit(
|
|
458
|
+
t2.emit(i$2.LTE);
|
|
356
459
|
break;
|
|
357
460
|
case s__namespace.SyntaxKind.GreaterThanEqualsToken:
|
|
358
|
-
t2.emit(
|
|
461
|
+
t2.emit(i$2.GTE);
|
|
359
462
|
break;
|
|
360
463
|
case s__namespace.SyntaxKind.EqualsEqualsEqualsToken:
|
|
361
|
-
t2.emit(
|
|
464
|
+
t2.emit(i$2.EQ_STRICT);
|
|
362
465
|
break;
|
|
363
466
|
case s__namespace.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
364
|
-
t2.emit(
|
|
467
|
+
t2.emit(i$2.NEQ_STRICT);
|
|
365
468
|
break;
|
|
366
469
|
case s__namespace.SyntaxKind.AmpersandAmpersandToken:
|
|
367
|
-
t2.emit(
|
|
470
|
+
t2.emit(i$2.AND);
|
|
368
471
|
break;
|
|
369
472
|
case s__namespace.SyntaxKind.BarBarToken:
|
|
370
|
-
t2.emit(
|
|
473
|
+
t2.emit(i$2.OR);
|
|
371
474
|
break;
|
|
372
475
|
}
|
|
373
|
-
},
|
|
374
|
-
|
|
375
|
-
const r2 = t2.emit(
|
|
376
|
-
|
|
377
|
-
const a2 = t2.emit(
|
|
378
|
-
t2.patchJump(r2, m2),
|
|
379
|
-
const
|
|
380
|
-
t2.patchJump(a2,
|
|
381
|
-
},
|
|
382
|
-
|
|
383
|
-
},
|
|
476
|
+
}, v = (e2, t2, { compileExpression: n }) => {
|
|
477
|
+
n(e2.condition);
|
|
478
|
+
const r2 = t2.emit(i$2.JUMP_IF_FALSE, -1);
|
|
479
|
+
n(e2.whenTrue);
|
|
480
|
+
const a2 = t2.emit(i$2.JUMP, -1), m2 = t2.currentAddress();
|
|
481
|
+
t2.patchJump(r2, m2), n(e2.whenFalse);
|
|
482
|
+
const T = t2.currentAddress();
|
|
483
|
+
t2.patchJump(a2, T);
|
|
484
|
+
}, z = (e2, t2, { compileExpression: n }) => {
|
|
485
|
+
n(e2.expression), t2.emit(i$2.TYPEOF);
|
|
486
|
+
}, Q$1 = (e2, t2, { compileExpression: n, reportError: r2 }) => {
|
|
384
487
|
if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "fs") {
|
|
385
488
|
const a2 = e2.expression.name.text;
|
|
386
489
|
if (a2 === "listFiles")
|
|
387
|
-
e2.arguments.length > 0 ?
|
|
490
|
+
e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, "."), e2.arguments.length > 1 && n(e2.arguments[1]), t2.emit(i$2.FS_LIST_FILES);
|
|
388
491
|
else if (a2 === "readFile")
|
|
389
|
-
e2.arguments.length > 0 ? (
|
|
492
|
+
e2.arguments.length > 0 ? (n(e2.arguments[0]), t2.emit(i$2.FS_READ_FILE)) : r2(e2, "fs.readFile() requires a path argument");
|
|
390
493
|
else if (a2 === "writeFile") {
|
|
391
494
|
if (e2.arguments.length < 2) {
|
|
392
495
|
r2(e2, "fs.writeFile() requires path and content arguments");
|
|
393
496
|
return;
|
|
394
497
|
}
|
|
395
|
-
|
|
498
|
+
n(e2.arguments[0]), n(e2.arguments[1]), t2.emit(i$2.FS_WRITE_FILE);
|
|
396
499
|
} else
|
|
397
500
|
r2(e2, `Unsupported fs method: ${a2}`);
|
|
398
501
|
} else if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "parse")
|
|
399
|
-
e2.arguments.length > 0 &&
|
|
502
|
+
e2.arguments.length > 0 && n(e2.arguments[0]), t2.emit(i$2.JSON_PARSE);
|
|
400
503
|
else if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "stringify")
|
|
401
|
-
e2.arguments.length > 0 ?
|
|
402
|
-
else if (s__namespace.isIdentifier(e2.expression) && e2.expression.text === "
|
|
403
|
-
e2.arguments.length
|
|
504
|
+
e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH_UNDEFINED), t2.emit(i$2.JSON_STRINGIFY);
|
|
505
|
+
else if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "Object" && e2.expression.name.text === "keys") {
|
|
506
|
+
if (e2.arguments.length !== 1) {
|
|
507
|
+
r2(e2, "Object.keys() requires exactly one argument");
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
n(e2.arguments[0]), t2.emit(i$2.OBJECT_KEYS);
|
|
511
|
+
} else if (s__namespace.isIdentifier(e2.expression) && e2.expression.text === "CC")
|
|
512
|
+
e2.arguments.length > 0 && n(e2.arguments[0]), t2.emit(i$2.CC);
|
|
404
513
|
else if (s__namespace.isPropertyAccessExpression(e2.expression)) {
|
|
405
514
|
const a2 = e2.expression.name.text;
|
|
406
515
|
if (a2 === "substring")
|
|
407
|
-
|
|
516
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, 0), e2.arguments.length > 1 && n(e2.arguments[1]), t2.emit(i$2.STRING_SUBSTRING);
|
|
408
517
|
else if (a2 === "indexOf")
|
|
409
|
-
|
|
518
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_INDEXOF);
|
|
410
519
|
else if (a2 === "split")
|
|
411
|
-
|
|
520
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_SPLIT);
|
|
412
521
|
else if (a2 === "slice")
|
|
413
|
-
|
|
522
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, 0), e2.arguments.length > 1 ? n(e2.arguments[1]) : t2.emit(i$2.PUSH_UNDEFINED), t2.emit(i$2.STRING_SLICE);
|
|
414
523
|
else if (a2 === "join")
|
|
415
|
-
|
|
524
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ","), t2.emit(i$2.ARRAY_JOIN);
|
|
416
525
|
else if (a2 === "charAt")
|
|
417
|
-
|
|
526
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, 0), t2.emit(i$2.STRING_CHARAT);
|
|
418
527
|
else if (a2 === "toUpperCase")
|
|
419
|
-
|
|
528
|
+
n(e2.expression.expression), t2.emit(i$2.STRING_TOUPPERCASE);
|
|
420
529
|
else if (a2 === "toLowerCase")
|
|
421
|
-
|
|
530
|
+
n(e2.expression.expression), t2.emit(i$2.STRING_TOLOWERCASE);
|
|
422
531
|
else if (a2 === "toString")
|
|
423
|
-
|
|
532
|
+
n(e2.expression.expression), t2.emit(i$2.TO_STRING);
|
|
424
533
|
else if (a2 === "includes")
|
|
425
|
-
|
|
534
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_INCLUDES);
|
|
426
535
|
else if (a2 === "endsWith")
|
|
427
|
-
|
|
536
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_ENDS_WITH);
|
|
428
537
|
else if (a2 === "startsWith")
|
|
429
|
-
|
|
538
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_STARTS_WITH);
|
|
430
539
|
else if (a2 === "trim")
|
|
431
|
-
|
|
540
|
+
n(e2.expression.expression), t2.emit(i$2.STRING_TRIM);
|
|
432
541
|
else if (a2 === "trimStart")
|
|
433
|
-
|
|
542
|
+
n(e2.expression.expression), t2.emit(i$2.STRING_TRIM_START);
|
|
434
543
|
else if (a2 === "trimEnd")
|
|
435
|
-
|
|
544
|
+
n(e2.expression.expression), t2.emit(i$2.STRING_TRIM_END);
|
|
436
545
|
else if (a2 === "replace")
|
|
437
|
-
|
|
546
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), e2.arguments.length > 1 ? n(e2.arguments[1]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_REPLACE);
|
|
438
547
|
else if (a2 === "replaceAll")
|
|
439
|
-
|
|
548
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), e2.arguments.length > 1 ? n(e2.arguments[1]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_REPLACE_ALL);
|
|
440
549
|
else if (a2 === "lastIndexOf")
|
|
441
|
-
|
|
550
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, ""), t2.emit(i$2.STRING_LAST_INDEX_OF);
|
|
442
551
|
else if (a2 === "repeat")
|
|
443
|
-
|
|
552
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, 0), t2.emit(i$2.STRING_REPEAT);
|
|
444
553
|
else if (a2 === "padStart")
|
|
445
|
-
|
|
554
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, 0), e2.arguments.length > 1 ? n(e2.arguments[1]) : t2.emit(i$2.PUSH, " "), t2.emit(i$2.STRING_PAD_START);
|
|
446
555
|
else if (a2 === "padEnd")
|
|
447
|
-
|
|
556
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH, 0), e2.arguments.length > 1 ? n(e2.arguments[1]) : t2.emit(i$2.PUSH, " "), t2.emit(i$2.STRING_PAD_END);
|
|
448
557
|
else if (a2 === "push")
|
|
449
|
-
|
|
558
|
+
n(e2.expression.expression), e2.arguments.length > 0 ? n(e2.arguments[0]) : t2.emit(i$2.PUSH_UNDEFINED), t2.emit(i$2.ARRAY_PUSH);
|
|
450
559
|
else
|
|
451
560
|
throw new Error(`Method call '${a2}' is not supported`);
|
|
452
561
|
} else
|
|
453
562
|
throw new Error("Unsupported call expression");
|
|
454
|
-
},
|
|
455
|
-
t2.emit(
|
|
563
|
+
}, $$1 = (e2, t2, { compileExpression: n }) => {
|
|
564
|
+
t2.emit(i$2.OBJECT_CREATE);
|
|
456
565
|
for (const r2 of e2.properties)
|
|
457
566
|
if (s__namespace.isPropertyAssignment(r2)) {
|
|
458
567
|
let a2;
|
|
@@ -462,92 +571,93 @@ const A = (e2, t2, { compileExpression: i2, compileStatement: r2 }) => {
|
|
|
462
571
|
a2 = r2.name.text;
|
|
463
572
|
else
|
|
464
573
|
throw new Error("Computed property names are not supported");
|
|
465
|
-
t2.emit(
|
|
574
|
+
t2.emit(i$2.PUSH, a2), n(r2.initializer), t2.emit(i$2.PROPERTY_SET);
|
|
466
575
|
} else if (s__namespace.isShorthandPropertyAssignment(r2)) {
|
|
467
576
|
const a2 = r2.name.text;
|
|
468
|
-
t2.emit(
|
|
577
|
+
t2.emit(i$2.PUSH, a2), t2.emit(i$2.LOAD, a2), t2.emit(i$2.PROPERTY_SET);
|
|
469
578
|
} else
|
|
470
579
|
throw new Error("Unsupported property type in object literal");
|
|
471
|
-
},
|
|
472
|
-
[s__namespace.SyntaxKind.StringLiteral]:
|
|
473
|
-
[s__namespace.SyntaxKind.NumericLiteral]:
|
|
474
|
-
[s__namespace.SyntaxKind.TrueKeyword]:
|
|
475
|
-
[s__namespace.SyntaxKind.FalseKeyword]:
|
|
476
|
-
[s__namespace.SyntaxKind.NullKeyword]:
|
|
477
|
-
[s__namespace.SyntaxKind.
|
|
478
|
-
[s__namespace.SyntaxKind.
|
|
479
|
-
[s__namespace.SyntaxKind.
|
|
480
|
-
[s__namespace.SyntaxKind.
|
|
481
|
-
[s__namespace.SyntaxKind.
|
|
482
|
-
[s__namespace.SyntaxKind.
|
|
483
|
-
[s__namespace.SyntaxKind.
|
|
484
|
-
[s__namespace.SyntaxKind.
|
|
485
|
-
[s__namespace.SyntaxKind.
|
|
486
|
-
[s__namespace.SyntaxKind.
|
|
487
|
-
[s__namespace.SyntaxKind.
|
|
488
|
-
[s__namespace.SyntaxKind.
|
|
580
|
+
}, Z$1 = {
|
|
581
|
+
[s__namespace.SyntaxKind.StringLiteral]: J,
|
|
582
|
+
[s__namespace.SyntaxKind.NumericLiteral]: H,
|
|
583
|
+
[s__namespace.SyntaxKind.TrueKeyword]: M$1,
|
|
584
|
+
[s__namespace.SyntaxKind.FalseKeyword]: Y,
|
|
585
|
+
[s__namespace.SyntaxKind.NullKeyword]: B$1,
|
|
586
|
+
[s__namespace.SyntaxKind.RegularExpressionLiteral]: C$2,
|
|
587
|
+
[s__namespace.SyntaxKind.Identifier]: d$3,
|
|
588
|
+
[s__namespace.SyntaxKind.ArrayLiteralExpression]: w$1,
|
|
589
|
+
[s__namespace.SyntaxKind.BinaryExpression]: X,
|
|
590
|
+
[s__namespace.SyntaxKind.PrefixUnaryExpression]: W$1,
|
|
591
|
+
[s__namespace.SyntaxKind.PostfixUnaryExpression]: j$2,
|
|
592
|
+
[s__namespace.SyntaxKind.CallExpression]: Q$1,
|
|
593
|
+
[s__namespace.SyntaxKind.PropertyAccessExpression]: q,
|
|
594
|
+
[s__namespace.SyntaxKind.ElementAccessExpression]: V$1,
|
|
595
|
+
[s__namespace.SyntaxKind.ConditionalExpression]: v,
|
|
596
|
+
[s__namespace.SyntaxKind.TypeOfExpression]: z,
|
|
597
|
+
[s__namespace.SyntaxKind.ParenthesizedExpression]: O,
|
|
598
|
+
[s__namespace.SyntaxKind.ObjectLiteralExpression]: $$1
|
|
489
599
|
};
|
|
490
|
-
function
|
|
491
|
-
const t2 = [],
|
|
492
|
-
if (
|
|
600
|
+
function te$1(e2) {
|
|
601
|
+
const t2 = [], n = A(e2);
|
|
602
|
+
if (n.errors.length > 0)
|
|
493
603
|
return {
|
|
494
604
|
success: false,
|
|
495
605
|
bytecode: [],
|
|
496
|
-
errors:
|
|
606
|
+
errors: n.errors.map((S) => ({
|
|
497
607
|
message: S,
|
|
498
608
|
line: 0,
|
|
499
609
|
character: 0
|
|
500
610
|
}))
|
|
501
611
|
};
|
|
502
|
-
const r2 = new
|
|
503
|
-
compileStatement:
|
|
504
|
-
compileExpression:
|
|
505
|
-
reportError: (S,
|
|
506
|
-
const { line:
|
|
612
|
+
const r2 = new P(), a2 = s__namespace.createSourceFile("program.ts", e2, s__namespace.ScriptTarget.Latest, true), m2 = {
|
|
613
|
+
compileStatement: T,
|
|
614
|
+
compileExpression: c2,
|
|
615
|
+
reportError: (S, u2) => {
|
|
616
|
+
const { line: l, character: x2 } = a2.getLineAndCharacterOfPosition(S.getStart());
|
|
507
617
|
throw t2.push({
|
|
508
|
-
message:
|
|
509
|
-
line:
|
|
618
|
+
message: u2,
|
|
619
|
+
line: l + 1,
|
|
510
620
|
// TypeScript uses 0-based lines
|
|
511
|
-
character:
|
|
621
|
+
character: x2 + 1
|
|
512
622
|
// TypeScript uses 0-based columns
|
|
513
|
-
}), new Error(
|
|
623
|
+
}), new Error(u2);
|
|
514
624
|
}
|
|
515
625
|
};
|
|
516
|
-
function
|
|
517
|
-
const
|
|
518
|
-
if (
|
|
519
|
-
|
|
626
|
+
function T(S) {
|
|
627
|
+
const u2 = K[S.kind];
|
|
628
|
+
if (u2)
|
|
629
|
+
u2(S, r2, m2);
|
|
520
630
|
else {
|
|
521
|
-
const { line:
|
|
631
|
+
const { line: l, character: x2 } = a2.getLineAndCharacterOfPosition(S.getStart());
|
|
522
632
|
t2.push({
|
|
523
633
|
message: `Unsupported statement: ${s__namespace.SyntaxKind[S.kind]}`,
|
|
524
|
-
line:
|
|
525
|
-
character:
|
|
634
|
+
line: l + 1,
|
|
635
|
+
character: x2 + 1
|
|
526
636
|
});
|
|
527
637
|
}
|
|
528
638
|
}
|
|
529
|
-
function
|
|
530
|
-
const
|
|
531
|
-
if (
|
|
532
|
-
|
|
639
|
+
function c2(S) {
|
|
640
|
+
const u2 = Z$1[S.kind];
|
|
641
|
+
if (u2)
|
|
642
|
+
u2(S, r2, m2);
|
|
533
643
|
else {
|
|
534
|
-
const { line:
|
|
644
|
+
const { line: l, character: x2 } = a2.getLineAndCharacterOfPosition(S.getStart());
|
|
535
645
|
t2.push({
|
|
536
646
|
message: `Unsupported expression: ${s__namespace.SyntaxKind[S.kind]}`,
|
|
537
|
-
line:
|
|
538
|
-
character:
|
|
647
|
+
line: l + 1,
|
|
648
|
+
character: x2 + 1
|
|
539
649
|
});
|
|
540
650
|
}
|
|
541
651
|
}
|
|
542
652
|
return a2.forEachChild((S) => {
|
|
543
|
-
var
|
|
544
|
-
s__namespace.isFunctionDeclaration(S) && ((
|
|
653
|
+
var u2;
|
|
654
|
+
s__namespace.isFunctionDeclaration(S) && ((u2 = S.name) == null ? void 0 : u2.text) === "main" && S.body && S.body.statements.forEach((l) => {
|
|
545
655
|
try {
|
|
546
|
-
|
|
656
|
+
T(l);
|
|
547
657
|
} catch {
|
|
548
658
|
}
|
|
549
659
|
});
|
|
550
|
-
}), r2.emit(
|
|
660
|
+
}), r2.emit(i$2.HALT), {
|
|
551
661
|
success: t2.length === 0,
|
|
552
662
|
bytecode: r2.getBytecode(),
|
|
553
663
|
errors: t2
|
|
@@ -577,7 +687,7 @@ function y(r2) {
|
|
|
577
687
|
function u$1(r2) {
|
|
578
688
|
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "array-ref";
|
|
579
689
|
}
|
|
580
|
-
function b
|
|
690
|
+
function b(r2) {
|
|
581
691
|
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "object-ref";
|
|
582
692
|
}
|
|
583
693
|
function p$1(r2) {
|
|
@@ -586,8 +696,8 @@ function p$1(r2) {
|
|
|
586
696
|
function j$1(r2) {
|
|
587
697
|
return e(r2) ? r2 : f$2(r2) || c(r2) ? false : i$1(r2) ? r2 !== 0 : t(r2) ? r2 !== "" : o(r2) || y(r2) ? true : !!r2;
|
|
588
698
|
}
|
|
589
|
-
function d$
|
|
590
|
-
return t(r2) ? "string" : i$1(r2) ? "number" : e(r2) ? "boolean" : f$2(r2) ? "null" : c(r2) ? "undefined" : o(r2) || u$1(r2) ? "array" : y(r2) || b
|
|
699
|
+
function d$2(r2) {
|
|
700
|
+
return t(r2) ? "string" : i$1(r2) ? "number" : e(r2) ? "boolean" : f$2(r2) ? "null" : c(r2) ? "undefined" : o(r2) || u$1(r2) ? "array" : y(r2) || b(r2) ? "object" : "unknown";
|
|
591
701
|
}
|
|
592
702
|
function m(r2) {
|
|
593
703
|
if (i$1(r2)) return r2;
|
|
@@ -595,23 +705,23 @@ function m(r2) {
|
|
|
595
705
|
if (f$2(r2)) return 0;
|
|
596
706
|
if (c(r2)) return NaN;
|
|
597
707
|
if (t(r2)) {
|
|
598
|
-
const
|
|
599
|
-
return
|
|
708
|
+
const n = r2.trim();
|
|
709
|
+
return n === "" ? 0 : Number(n);
|
|
600
710
|
}
|
|
601
711
|
return o(r2) ? NaN : Number(r2);
|
|
602
712
|
}
|
|
603
|
-
function s(r2 = [],
|
|
604
|
-
return
|
|
713
|
+
function s(r2 = [], n) {
|
|
714
|
+
return n ? { type: "array", elements: r2, properties: n } : { type: "array", elements: r2 };
|
|
605
715
|
}
|
|
606
|
-
function C() {
|
|
716
|
+
function C$1() {
|
|
607
717
|
return { type: "undefined" };
|
|
608
718
|
}
|
|
609
|
-
function M
|
|
719
|
+
function M(r2 = {}) {
|
|
610
720
|
return { type: "object", properties: r2 };
|
|
611
721
|
}
|
|
612
|
-
var d = Object.defineProperty;
|
|
613
|
-
var h = (s2, t2,
|
|
614
|
-
var a = (s2, t2,
|
|
722
|
+
var d$1 = Object.defineProperty;
|
|
723
|
+
var h = (s2, t2, n) => t2 in s2 ? d$1(s2, t2, { enumerable: true, configurable: true, writable: true, value: n }) : s2[t2] = n;
|
|
724
|
+
var a = (s2, t2, n) => h(s2, typeof t2 != "symbol" ? t2 + "" : t2, n);
|
|
615
725
|
class p {
|
|
616
726
|
constructor(t2) {
|
|
617
727
|
a(this, "connected", false);
|
|
@@ -624,7 +734,7 @@ class p {
|
|
|
624
734
|
return r__namespace.join(this.dataDir, "metadata.json");
|
|
625
735
|
}
|
|
626
736
|
async connect() {
|
|
627
|
-
await
|
|
737
|
+
await N$1.promises.mkdir(this.dataDir, { recursive: true }), await N$1.promises.mkdir(this.programsDir, { recursive: true }), await N$1.promises.mkdir(this.executionsDir, { recursive: true }), await N$1.promises.mkdir(this.outputsDir, { recursive: true }), this.connected = true;
|
|
628
738
|
}
|
|
629
739
|
async disconnect() {
|
|
630
740
|
this.connected = false;
|
|
@@ -634,14 +744,14 @@ class p {
|
|
|
634
744
|
}
|
|
635
745
|
async saveProgram(t2) {
|
|
636
746
|
if (!this.connected) throw new Error("Not connected");
|
|
637
|
-
const
|
|
638
|
-
await
|
|
747
|
+
const n = r__namespace.join(this.programsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
|
|
748
|
+
await N$1.promises.writeFile(n, e2, "utf-8");
|
|
639
749
|
}
|
|
640
750
|
async getProgram(t2) {
|
|
641
751
|
if (!this.connected) throw new Error("Not connected");
|
|
642
|
-
const
|
|
752
|
+
const n = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
643
753
|
try {
|
|
644
|
-
const e2 = await
|
|
754
|
+
const e2 = await N$1.promises.readFile(n, "utf-8"), o2 = JSON.parse(e2);
|
|
645
755
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
646
756
|
} catch (e2) {
|
|
647
757
|
if (e2.code === "ENOENT")
|
|
@@ -651,14 +761,14 @@ class p {
|
|
|
651
761
|
}
|
|
652
762
|
async saveExecution(t2) {
|
|
653
763
|
if (!this.connected) throw new Error("Not connected");
|
|
654
|
-
const
|
|
655
|
-
await
|
|
764
|
+
const n = r__namespace.join(this.executionsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
|
|
765
|
+
await N$1.promises.writeFile(n, e2, "utf-8");
|
|
656
766
|
}
|
|
657
767
|
async getExecution(t2) {
|
|
658
768
|
if (!this.connected) throw new Error("Not connected");
|
|
659
|
-
const
|
|
769
|
+
const n = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
660
770
|
try {
|
|
661
|
-
const e2 = await
|
|
771
|
+
const e2 = await N$1.promises.readFile(n, "utf-8"), o2 = JSON.parse(e2);
|
|
662
772
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
663
773
|
} catch (e2) {
|
|
664
774
|
if (e2.code === "ENOENT")
|
|
@@ -666,18 +776,18 @@ class p {
|
|
|
666
776
|
throw e2;
|
|
667
777
|
}
|
|
668
778
|
}
|
|
669
|
-
async appendOutput(t2,
|
|
779
|
+
async appendOutput(t2, n) {
|
|
670
780
|
if (!this.connected) throw new Error("Not connected");
|
|
671
|
-
const e2 = r__namespace.join(this.outputsDir, `${t2}.output`), o2 =
|
|
781
|
+
const e2 = r__namespace.join(this.outputsDir, `${t2}.output`), o2 = n.join(`
|
|
672
782
|
`) + `
|
|
673
783
|
`;
|
|
674
|
-
await
|
|
784
|
+
await N$1.promises.appendFile(e2, o2, "utf-8");
|
|
675
785
|
}
|
|
676
786
|
async getOutput(t2) {
|
|
677
787
|
if (!this.connected) throw new Error("Not connected");
|
|
678
|
-
const
|
|
788
|
+
const n = r__namespace.join(this.outputsDir, `${t2}.output`);
|
|
679
789
|
try {
|
|
680
|
-
return (await
|
|
790
|
+
return (await N$1.promises.readFile(n, "utf-8")).split(`
|
|
681
791
|
`).filter((o2) => o2.length > 0);
|
|
682
792
|
} catch (e2) {
|
|
683
793
|
if (e2.code === "ENOENT")
|
|
@@ -687,18 +797,18 @@ class p {
|
|
|
687
797
|
}
|
|
688
798
|
async listExecutions() {
|
|
689
799
|
if (!this.connected) throw new Error("Not connected");
|
|
690
|
-
const t2 = await
|
|
800
|
+
const t2 = await N$1.promises.readdir(this.executionsDir), n = [];
|
|
691
801
|
for (const e2 of t2)
|
|
692
802
|
if (e2.endsWith(".json")) {
|
|
693
803
|
const o2 = e2.slice(0, -5), i2 = await this.getExecution(o2);
|
|
694
|
-
i2 &&
|
|
804
|
+
i2 && n.push(i2);
|
|
695
805
|
}
|
|
696
|
-
return
|
|
806
|
+
return n;
|
|
697
807
|
}
|
|
698
808
|
async getCurrentExecutionId() {
|
|
699
809
|
if (!this.connected) throw new Error("Not connected");
|
|
700
810
|
try {
|
|
701
|
-
const t2 = await
|
|
811
|
+
const t2 = await N$1.promises.readFile(this.metadataFile, "utf-8");
|
|
702
812
|
return JSON.parse(t2).currentExecutionId || null;
|
|
703
813
|
} catch (t2) {
|
|
704
814
|
if (t2.code === "ENOENT")
|
|
@@ -708,20 +818,20 @@ class p {
|
|
|
708
818
|
}
|
|
709
819
|
async setCurrentExecutionId(t2) {
|
|
710
820
|
if (!this.connected) throw new Error("Not connected");
|
|
711
|
-
const
|
|
712
|
-
await
|
|
821
|
+
const n = { currentExecutionId: t2 };
|
|
822
|
+
await N$1.promises.writeFile(this.metadataFile, JSON.stringify(n, null, 2), "utf-8");
|
|
713
823
|
}
|
|
714
824
|
async deleteExecution(t2) {
|
|
715
825
|
if (!this.connected) throw new Error("Not connected");
|
|
716
|
-
const
|
|
826
|
+
const n = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
717
827
|
try {
|
|
718
|
-
await
|
|
828
|
+
await N$1.promises.unlink(n);
|
|
719
829
|
} catch (i2) {
|
|
720
830
|
if (i2.code !== "ENOENT") throw i2;
|
|
721
831
|
}
|
|
722
832
|
const e2 = r__namespace.join(this.outputsDir, `${t2}.output`);
|
|
723
833
|
try {
|
|
724
|
-
await
|
|
834
|
+
await N$1.promises.unlink(e2);
|
|
725
835
|
} catch (i2) {
|
|
726
836
|
if (i2.code !== "ENOENT") throw i2;
|
|
727
837
|
}
|
|
@@ -729,19 +839,19 @@ class p {
|
|
|
729
839
|
}
|
|
730
840
|
async listPrograms() {
|
|
731
841
|
if (!this.connected) throw new Error("Not connected");
|
|
732
|
-
const t2 = await
|
|
842
|
+
const t2 = await N$1.promises.readdir(this.programsDir), n = [];
|
|
733
843
|
for (const e2 of t2)
|
|
734
844
|
if (e2.endsWith(".json")) {
|
|
735
845
|
const o2 = e2.slice(0, -5), i2 = await this.getProgram(o2);
|
|
736
|
-
i2 &&
|
|
846
|
+
i2 && n.push(i2);
|
|
737
847
|
}
|
|
738
|
-
return
|
|
848
|
+
return n;
|
|
739
849
|
}
|
|
740
850
|
async deleteProgram(t2) {
|
|
741
851
|
if (!this.connected) throw new Error("Not connected");
|
|
742
|
-
const
|
|
852
|
+
const n = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
743
853
|
try {
|
|
744
|
-
await
|
|
854
|
+
await N$1.promises.unlink(n);
|
|
745
855
|
} catch (e2) {
|
|
746
856
|
if (e2.code !== "ENOENT") throw e2;
|
|
747
857
|
}
|
|
@@ -770,7 +880,7 @@ let f$1 = class f {
|
|
|
770
880
|
}
|
|
771
881
|
async getCollections() {
|
|
772
882
|
if (!this.db) throw new Error("Not connected to database");
|
|
773
|
-
return (await this.db.listCollections().toArray()).map((
|
|
883
|
+
return (await this.db.listCollections().toArray()).map((n) => n.name);
|
|
774
884
|
}
|
|
775
885
|
getCollection(t2) {
|
|
776
886
|
if (!this.db) throw new Error("Not connected to database");
|
|
@@ -796,12 +906,12 @@ let f$1 = class f {
|
|
|
796
906
|
async getExecution(t2) {
|
|
797
907
|
return await this.getCollection("executions").findOne({ id: t2 });
|
|
798
908
|
}
|
|
799
|
-
async appendOutput(t2,
|
|
909
|
+
async appendOutput(t2, n) {
|
|
800
910
|
const e2 = this.getCollection("outputs");
|
|
801
911
|
await e2.findOne({ executionId: t2 }) ? await e2.updateOne(
|
|
802
912
|
{ executionId: t2 },
|
|
803
|
-
{ $push: { lines: { $each:
|
|
804
|
-
) : await e2.insertOne({ executionId: t2, lines:
|
|
913
|
+
{ $push: { lines: { $each: n } } }
|
|
914
|
+
) : await e2.insertOne({ executionId: t2, lines: n });
|
|
805
915
|
}
|
|
806
916
|
async getOutput(t2) {
|
|
807
917
|
const e2 = await this.getCollection("outputs").findOne({ executionId: t2 });
|
|
@@ -811,8 +921,8 @@ let f$1 = class f {
|
|
|
811
921
|
return await this.getCollection("executions").find({}).toArray();
|
|
812
922
|
}
|
|
813
923
|
async getCurrentExecutionId() {
|
|
814
|
-
const
|
|
815
|
-
return (
|
|
924
|
+
const n = await this.getCollection("metadata").findOne({ _id: "current" });
|
|
925
|
+
return (n == null ? void 0 : n.currentExecutionId) || null;
|
|
816
926
|
}
|
|
817
927
|
async setCurrentExecutionId(t2) {
|
|
818
928
|
await this.getCollection("metadata").replaceOne(
|
|
@@ -823,7 +933,7 @@ let f$1 = class f {
|
|
|
823
933
|
}
|
|
824
934
|
async deleteExecution(t2) {
|
|
825
935
|
var o2;
|
|
826
|
-
let
|
|
936
|
+
let n = true;
|
|
827
937
|
const e2 = this.client.startSession();
|
|
828
938
|
try {
|
|
829
939
|
await e2.withTransaction(async () => {
|
|
@@ -835,13 +945,13 @@ let f$1 = class f {
|
|
|
835
945
|
});
|
|
836
946
|
} catch (i2) {
|
|
837
947
|
if ((o2 = i2 == null ? void 0 : i2.message) != null && o2.includes("Transaction numbers are only allowed"))
|
|
838
|
-
|
|
948
|
+
n = false;
|
|
839
949
|
else
|
|
840
950
|
throw i2;
|
|
841
951
|
} finally {
|
|
842
952
|
await e2.endSession();
|
|
843
953
|
}
|
|
844
|
-
|
|
954
|
+
n || (await this.getCollection("executions").deleteOne({ id: t2 }), await this.getCollection("outputs").deleteMany({ executionId: t2 }), await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null));
|
|
845
955
|
}
|
|
846
956
|
async listPrograms() {
|
|
847
957
|
return await this.getCollection("programs").find({}).toArray();
|
|
@@ -852,8 +962,8 @@ let f$1 = class f {
|
|
|
852
962
|
};
|
|
853
963
|
class E {
|
|
854
964
|
static create(t2) {
|
|
855
|
-
const
|
|
856
|
-
switch (
|
|
965
|
+
const n = (t2 == null ? void 0 : t2.type) || process.env.CVM_STORAGE_TYPE || "file";
|
|
966
|
+
switch (n) {
|
|
857
967
|
case "file": {
|
|
858
968
|
const e2 = (t2 == null ? void 0 : t2.dataDir) || process.env.CVM_DATA_DIR || ".cvm";
|
|
859
969
|
return new p(e2);
|
|
@@ -863,74 +973,74 @@ class E {
|
|
|
863
973
|
return new f$1(e2);
|
|
864
974
|
}
|
|
865
975
|
default:
|
|
866
|
-
throw new Error(`Unsupported storage type: ${
|
|
976
|
+
throw new Error(`Unsupported storage type: ${n}`);
|
|
867
977
|
}
|
|
868
978
|
}
|
|
869
979
|
}
|
|
870
|
-
var
|
|
871
|
-
var
|
|
872
|
-
var
|
|
980
|
+
var B = Object.defineProperty;
|
|
981
|
+
var W = (e2, t2, r2) => t2 in e2 ? B(e2, t2, { enumerable: true, configurable: true, writable: true, value: r2 }) : e2[t2] = r2;
|
|
982
|
+
var _ = (e2, t2, r2) => W(e2, typeof t2 != "symbol" ? t2 + "" : t2, r2);
|
|
873
983
|
function Q(e2) {
|
|
874
984
|
return !!(e2 && typeof e2 == "object" && "type" in e2 && "message" in e2);
|
|
875
985
|
}
|
|
876
|
-
function
|
|
986
|
+
function d(e2, t2) {
|
|
877
987
|
return e2.stack.length < 1 ? {
|
|
878
988
|
type: "RuntimeError",
|
|
879
989
|
message: "Stack underflow",
|
|
880
990
|
pc: e2.pc,
|
|
881
|
-
opcode: t2 ||
|
|
991
|
+
opcode: t2 || i$2.POP
|
|
882
992
|
} : e2.stack.pop();
|
|
883
993
|
}
|
|
884
994
|
const f2 = Q, Z = {
|
|
885
|
-
[
|
|
995
|
+
[i$2.ADD]: {
|
|
886
996
|
stackIn: 2,
|
|
887
997
|
stackOut: 1,
|
|
888
998
|
execute: (e2, t$1) => {
|
|
889
|
-
const r2 =
|
|
999
|
+
const r2 = d(e2, t$1.op);
|
|
890
1000
|
if (f2(r2)) return r2;
|
|
891
|
-
const
|
|
892
|
-
if (f2(
|
|
893
|
-
if (t(
|
|
894
|
-
e2.stack.push(p$1(
|
|
1001
|
+
const s2 = d(e2, t$1.op);
|
|
1002
|
+
if (f2(s2)) return s2;
|
|
1003
|
+
if (t(s2) || t(r2))
|
|
1004
|
+
e2.stack.push(p$1(s2) + p$1(r2));
|
|
895
1005
|
else {
|
|
896
|
-
const
|
|
897
|
-
e2.stack.push(
|
|
1006
|
+
const o2 = m(s2), c2 = m(r2);
|
|
1007
|
+
e2.stack.push(o2 + c2);
|
|
898
1008
|
}
|
|
899
1009
|
}
|
|
900
1010
|
},
|
|
901
|
-
[
|
|
1011
|
+
[i$2.SUB]: {
|
|
902
1012
|
stackIn: 2,
|
|
903
1013
|
stackOut: 1,
|
|
904
1014
|
execute: (e2, t2) => {
|
|
905
|
-
const r2 =
|
|
1015
|
+
const r2 = d(e2, t2.op);
|
|
906
1016
|
if (f2(r2)) return r2;
|
|
907
|
-
const
|
|
908
|
-
if (f2(
|
|
909
|
-
const
|
|
910
|
-
e2.stack.push(
|
|
1017
|
+
const s2 = d(e2, t2.op);
|
|
1018
|
+
if (f2(s2)) return s2;
|
|
1019
|
+
const o2 = m(s2), c2 = m(r2);
|
|
1020
|
+
e2.stack.push(o2 - c2);
|
|
911
1021
|
}
|
|
912
1022
|
},
|
|
913
|
-
[
|
|
1023
|
+
[i$2.MUL]: {
|
|
914
1024
|
stackIn: 2,
|
|
915
1025
|
stackOut: 1,
|
|
916
1026
|
execute: (e2, t2) => {
|
|
917
|
-
const r2 =
|
|
1027
|
+
const r2 = d(e2, t2.op);
|
|
918
1028
|
if (f2(r2)) return r2;
|
|
919
|
-
const
|
|
920
|
-
if (f2(
|
|
921
|
-
const
|
|
922
|
-
e2.stack.push(
|
|
1029
|
+
const s2 = d(e2, t2.op);
|
|
1030
|
+
if (f2(s2)) return s2;
|
|
1031
|
+
const o2 = m(s2), c2 = m(r2);
|
|
1032
|
+
e2.stack.push(o2 * c2);
|
|
923
1033
|
}
|
|
924
1034
|
},
|
|
925
|
-
[
|
|
1035
|
+
[i$2.DIV]: {
|
|
926
1036
|
stackIn: 2,
|
|
927
1037
|
stackOut: 1,
|
|
928
1038
|
execute: (e2, t2) => {
|
|
929
|
-
const r2 =
|
|
1039
|
+
const r2 = d(e2, t2.op);
|
|
930
1040
|
if (f2(r2)) return r2;
|
|
931
|
-
const
|
|
932
|
-
if (f2(
|
|
933
|
-
const
|
|
1041
|
+
const s2 = d(e2, t2.op);
|
|
1042
|
+
if (f2(s2)) return s2;
|
|
1043
|
+
const o2 = m(s2), c2 = m(r2);
|
|
934
1044
|
if (c2 === 0)
|
|
935
1045
|
return {
|
|
936
1046
|
type: "DivisionByZero",
|
|
@@ -938,64 +1048,64 @@ const f2 = Q, Z = {
|
|
|
938
1048
|
pc: e2.pc,
|
|
939
1049
|
opcode: t2.op
|
|
940
1050
|
};
|
|
941
|
-
e2.stack.push(
|
|
1051
|
+
e2.stack.push(o2 / c2);
|
|
942
1052
|
}
|
|
943
1053
|
},
|
|
944
|
-
[
|
|
1054
|
+
[i$2.MOD]: {
|
|
945
1055
|
stackIn: 2,
|
|
946
1056
|
stackOut: 1,
|
|
947
1057
|
execute: (e2, t2) => {
|
|
948
|
-
const r2 =
|
|
1058
|
+
const r2 = d(e2, t2.op);
|
|
949
1059
|
if (f2(r2)) return r2;
|
|
950
|
-
const
|
|
951
|
-
if (f2(
|
|
952
|
-
const
|
|
953
|
-
e2.stack.push(
|
|
1060
|
+
const s2 = d(e2, t2.op);
|
|
1061
|
+
if (f2(s2)) return s2;
|
|
1062
|
+
const o2 = m(s2), c2 = m(r2);
|
|
1063
|
+
e2.stack.push(o2 % c2);
|
|
954
1064
|
}
|
|
955
1065
|
},
|
|
956
|
-
[
|
|
1066
|
+
[i$2.UNARY_MINUS]: {
|
|
957
1067
|
stackIn: 1,
|
|
958
1068
|
stackOut: 1,
|
|
959
1069
|
execute: (e2, t2) => {
|
|
960
|
-
const r2 =
|
|
1070
|
+
const r2 = d(e2, t2.op);
|
|
961
1071
|
if (f2(r2)) return r2;
|
|
962
|
-
const
|
|
963
|
-
e2.stack.push(-
|
|
1072
|
+
const s2 = m(r2);
|
|
1073
|
+
e2.stack.push(-s2);
|
|
964
1074
|
}
|
|
965
1075
|
},
|
|
966
|
-
[
|
|
1076
|
+
[i$2.UNARY_PLUS]: {
|
|
967
1077
|
stackIn: 1,
|
|
968
1078
|
stackOut: 1,
|
|
969
1079
|
execute: (e2, t2) => {
|
|
970
|
-
const r2 =
|
|
1080
|
+
const r2 = d(e2, t2.op);
|
|
971
1081
|
if (f2(r2)) return r2;
|
|
972
|
-
const
|
|
973
|
-
e2.stack.push(
|
|
1082
|
+
const s2 = m(r2);
|
|
1083
|
+
e2.stack.push(s2);
|
|
974
1084
|
}
|
|
975
1085
|
}
|
|
976
1086
|
}, ee = {
|
|
977
|
-
[
|
|
1087
|
+
[i$2.PUSH]: {
|
|
978
1088
|
stackIn: 0,
|
|
979
1089
|
stackOut: 1,
|
|
980
1090
|
execute: (e2, t2) => {
|
|
981
1091
|
e2.stack.push(t2.arg);
|
|
982
1092
|
}
|
|
983
1093
|
},
|
|
984
|
-
[
|
|
1094
|
+
[i$2.PUSH_UNDEFINED]: {
|
|
985
1095
|
stackIn: 0,
|
|
986
1096
|
stackOut: 1,
|
|
987
1097
|
execute: (e2) => {
|
|
988
|
-
e2.stack.push(C());
|
|
1098
|
+
e2.stack.push(C$1());
|
|
989
1099
|
}
|
|
990
1100
|
},
|
|
991
|
-
[
|
|
1101
|
+
[i$2.POP]: {
|
|
992
1102
|
stackIn: 1,
|
|
993
1103
|
stackOut: 0,
|
|
994
1104
|
execute: (e2) => {
|
|
995
1105
|
e2.stack.pop();
|
|
996
1106
|
}
|
|
997
1107
|
},
|
|
998
|
-
[
|
|
1108
|
+
[i$2.DUP]: {
|
|
999
1109
|
stackIn: 1,
|
|
1000
1110
|
stackOut: 2,
|
|
1001
1111
|
execute: (e2, t2) => {
|
|
@@ -1003,24 +1113,24 @@ const f2 = Q, Z = {
|
|
|
1003
1113
|
e2.stack.push(r2), e2.stack.push(r2);
|
|
1004
1114
|
}
|
|
1005
1115
|
},
|
|
1006
|
-
[
|
|
1116
|
+
[i$2.SWAP]: {
|
|
1007
1117
|
stackIn: 2,
|
|
1008
1118
|
stackOut: 2,
|
|
1009
1119
|
execute: (e2, t2) => {
|
|
1010
|
-
const r2 = e2.stack.pop(),
|
|
1011
|
-
e2.stack.push(r2), e2.stack.push(
|
|
1120
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1121
|
+
e2.stack.push(r2), e2.stack.push(s2);
|
|
1012
1122
|
}
|
|
1013
1123
|
},
|
|
1014
|
-
[
|
|
1124
|
+
[i$2.DUP2]: {
|
|
1015
1125
|
stackIn: 2,
|
|
1016
1126
|
stackOut: 4,
|
|
1017
1127
|
execute: (e2, t2) => {
|
|
1018
|
-
const r2 = e2.stack.pop(),
|
|
1019
|
-
e2.stack.push(
|
|
1128
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1129
|
+
e2.stack.push(s2), e2.stack.push(r2), e2.stack.push(s2), e2.stack.push(r2);
|
|
1020
1130
|
}
|
|
1021
1131
|
}
|
|
1022
1132
|
}, re = {
|
|
1023
|
-
[
|
|
1133
|
+
[i$2.PRINT]: {
|
|
1024
1134
|
stackIn: 1,
|
|
1025
1135
|
stackOut: 0,
|
|
1026
1136
|
execute: (e2) => {
|
|
@@ -1028,7 +1138,7 @@ const f2 = Q, Z = {
|
|
|
1028
1138
|
t2 !== void 0 && e2.output.push(p$1(t2));
|
|
1029
1139
|
}
|
|
1030
1140
|
},
|
|
1031
|
-
[
|
|
1141
|
+
[i$2.CC]: {
|
|
1032
1142
|
stackIn: 1,
|
|
1033
1143
|
stackOut: 0,
|
|
1034
1144
|
controlsPC: true,
|
|
@@ -1039,7 +1149,7 @@ const f2 = Q, Z = {
|
|
|
1039
1149
|
}
|
|
1040
1150
|
}
|
|
1041
1151
|
}, te = {
|
|
1042
|
-
[
|
|
1152
|
+
[i$2.HALT]: {
|
|
1043
1153
|
stackIn: 0,
|
|
1044
1154
|
stackOut: 0,
|
|
1045
1155
|
controlsPC: true,
|
|
@@ -1047,7 +1157,7 @@ const f2 = Q, Z = {
|
|
|
1047
1157
|
e2.status = "complete";
|
|
1048
1158
|
}
|
|
1049
1159
|
},
|
|
1050
|
-
[
|
|
1160
|
+
[i$2.JUMP]: {
|
|
1051
1161
|
stackIn: 0,
|
|
1052
1162
|
stackOut: 0,
|
|
1053
1163
|
controlsPC: true,
|
|
@@ -1070,7 +1180,7 @@ const f2 = Q, Z = {
|
|
|
1070
1180
|
e2.pc = r2;
|
|
1071
1181
|
}
|
|
1072
1182
|
},
|
|
1073
|
-
[
|
|
1183
|
+
[i$2.JUMP_IF_FALSE]: {
|
|
1074
1184
|
stackIn: 1,
|
|
1075
1185
|
stackOut: 0,
|
|
1076
1186
|
controlsPC: true,
|
|
@@ -1083,18 +1193,18 @@ const f2 = Q, Z = {
|
|
|
1083
1193
|
pc: e2.pc,
|
|
1084
1194
|
opcode: t2.op
|
|
1085
1195
|
};
|
|
1086
|
-
const
|
|
1087
|
-
if (
|
|
1196
|
+
const s2 = t2.arg;
|
|
1197
|
+
if (s2 < 0)
|
|
1088
1198
|
return {
|
|
1089
1199
|
type: "RuntimeError",
|
|
1090
|
-
message: `Invalid jump target: ${
|
|
1200
|
+
message: `Invalid jump target: ${s2}`,
|
|
1091
1201
|
pc: e2.pc,
|
|
1092
1202
|
opcode: t2.op
|
|
1093
1203
|
};
|
|
1094
|
-
j$1(r2) ? e2.pc++ : e2.pc =
|
|
1204
|
+
j$1(r2) ? e2.pc++ : e2.pc = s2;
|
|
1095
1205
|
}
|
|
1096
1206
|
},
|
|
1097
|
-
[
|
|
1207
|
+
[i$2.JUMP_IF]: {
|
|
1098
1208
|
stackIn: 1,
|
|
1099
1209
|
stackOut: 0,
|
|
1100
1210
|
controlsPC: true,
|
|
@@ -1107,18 +1217,18 @@ const f2 = Q, Z = {
|
|
|
1107
1217
|
pc: e2.pc,
|
|
1108
1218
|
opcode: t2.op
|
|
1109
1219
|
};
|
|
1110
|
-
const
|
|
1111
|
-
if (
|
|
1220
|
+
const s2 = t2.arg;
|
|
1221
|
+
if (s2 < 0)
|
|
1112
1222
|
return {
|
|
1113
1223
|
type: "RuntimeError",
|
|
1114
|
-
message: `Invalid jump target: ${
|
|
1224
|
+
message: `Invalid jump target: ${s2}`,
|
|
1115
1225
|
pc: e2.pc,
|
|
1116
1226
|
opcode: t2.op
|
|
1117
1227
|
};
|
|
1118
|
-
j$1(r2) ? e2.pc =
|
|
1228
|
+
j$1(r2) ? e2.pc = s2 : e2.pc++;
|
|
1119
1229
|
}
|
|
1120
1230
|
},
|
|
1121
|
-
[
|
|
1231
|
+
[i$2.JUMP_IF_TRUE]: {
|
|
1122
1232
|
stackIn: 1,
|
|
1123
1233
|
stackOut: 0,
|
|
1124
1234
|
controlsPC: true,
|
|
@@ -1131,18 +1241,18 @@ const f2 = Q, Z = {
|
|
|
1131
1241
|
pc: e2.pc,
|
|
1132
1242
|
opcode: t2.op
|
|
1133
1243
|
};
|
|
1134
|
-
const
|
|
1135
|
-
if (
|
|
1244
|
+
const s2 = t2.arg;
|
|
1245
|
+
if (s2 < 0)
|
|
1136
1246
|
return {
|
|
1137
1247
|
type: "RuntimeError",
|
|
1138
|
-
message: `Invalid jump target: ${
|
|
1248
|
+
message: `Invalid jump target: ${s2}`,
|
|
1139
1249
|
pc: e2.pc,
|
|
1140
1250
|
opcode: t2.op
|
|
1141
1251
|
};
|
|
1142
|
-
j$1(r2) ? e2.pc =
|
|
1252
|
+
j$1(r2) ? e2.pc = s2 : e2.pc++;
|
|
1143
1253
|
}
|
|
1144
1254
|
},
|
|
1145
|
-
[
|
|
1255
|
+
[i$2.CALL]: {
|
|
1146
1256
|
stackIn: 1,
|
|
1147
1257
|
stackOut: 0,
|
|
1148
1258
|
controlsPC: false,
|
|
@@ -1150,19 +1260,19 @@ const f2 = Q, Z = {
|
|
|
1150
1260
|
type: "RuntimeError",
|
|
1151
1261
|
message: "Functions not implemented",
|
|
1152
1262
|
pc: e2.pc,
|
|
1153
|
-
opcode:
|
|
1263
|
+
opcode: i$2.CALL
|
|
1154
1264
|
})
|
|
1155
1265
|
}
|
|
1156
|
-
},
|
|
1157
|
-
[
|
|
1266
|
+
}, se = {
|
|
1267
|
+
[i$2.LOAD]: {
|
|
1158
1268
|
stackIn: 0,
|
|
1159
1269
|
stackOut: 1,
|
|
1160
1270
|
execute: (e2, t2) => {
|
|
1161
1271
|
const r2 = t2.arg;
|
|
1162
|
-
e2.variables.has(r2) ? e2.stack.push(e2.variables.get(r2)) : e2.stack.push(C());
|
|
1272
|
+
e2.variables.has(r2) ? e2.stack.push(e2.variables.get(r2)) : e2.stack.push(C$1());
|
|
1163
1273
|
}
|
|
1164
1274
|
},
|
|
1165
|
-
[
|
|
1275
|
+
[i$2.STORE]: {
|
|
1166
1276
|
stackIn: 1,
|
|
1167
1277
|
stackOut: 0,
|
|
1168
1278
|
execute: (e2, t2) => {
|
|
@@ -1170,8 +1280,8 @@ const f2 = Q, Z = {
|
|
|
1170
1280
|
e2.variables.set(t2.arg, r2);
|
|
1171
1281
|
}
|
|
1172
1282
|
}
|
|
1173
|
-
},
|
|
1174
|
-
[
|
|
1283
|
+
}, oe = {
|
|
1284
|
+
[i$2.ITER_START]: {
|
|
1175
1285
|
stackIn: 1,
|
|
1176
1286
|
stackOut: 0,
|
|
1177
1287
|
execute: (e2, t2) => {
|
|
@@ -1183,19 +1293,19 @@ const f2 = Q, Z = {
|
|
|
1183
1293
|
pc: e2.pc,
|
|
1184
1294
|
opcode: t2.op
|
|
1185
1295
|
};
|
|
1186
|
-
let
|
|
1296
|
+
let s2;
|
|
1187
1297
|
if (u$1(r2)) {
|
|
1188
|
-
const
|
|
1189
|
-
if (!
|
|
1298
|
+
const o2 = e2.heap.get(r2.id);
|
|
1299
|
+
if (!o2 || o2.type !== "array")
|
|
1190
1300
|
return {
|
|
1191
1301
|
type: "RuntimeError",
|
|
1192
1302
|
message: "Invalid array reference",
|
|
1193
1303
|
pc: e2.pc,
|
|
1194
1304
|
opcode: t2.op
|
|
1195
1305
|
};
|
|
1196
|
-
|
|
1306
|
+
s2 = o2.data;
|
|
1197
1307
|
} else if (o(r2))
|
|
1198
|
-
|
|
1308
|
+
s2 = r2;
|
|
1199
1309
|
else
|
|
1200
1310
|
return {
|
|
1201
1311
|
type: "TypeError",
|
|
@@ -1211,13 +1321,13 @@ const f2 = Q, Z = {
|
|
|
1211
1321
|
opcode: t2.op
|
|
1212
1322
|
};
|
|
1213
1323
|
e2.iterators.push({
|
|
1214
|
-
array:
|
|
1324
|
+
array: s2,
|
|
1215
1325
|
index: 0,
|
|
1216
|
-
length:
|
|
1326
|
+
length: s2.elements.length
|
|
1217
1327
|
});
|
|
1218
1328
|
}
|
|
1219
1329
|
},
|
|
1220
|
-
[
|
|
1330
|
+
[i$2.ITER_NEXT]: {
|
|
1221
1331
|
stackIn: 0,
|
|
1222
1332
|
stackOut: 2,
|
|
1223
1333
|
// Pushes element and hasMore flag
|
|
@@ -1230,10 +1340,10 @@ const f2 = Q, Z = {
|
|
|
1230
1340
|
opcode: t2.op
|
|
1231
1341
|
};
|
|
1232
1342
|
const r2 = e2.iterators[e2.iterators.length - 1];
|
|
1233
|
-
r2.index < r2.length ? (r2.index < r2.array.elements.length ? e2.stack.push(r2.array.elements[r2.index]) : e2.stack.push(C()), e2.stack.push(true), r2.index++) : (e2.stack.push(null), e2.stack.push(false));
|
|
1343
|
+
r2.index < r2.length ? (r2.array && r2.index < r2.array.elements.length ? e2.stack.push(r2.array.elements[r2.index]) : e2.stack.push(C$1()), e2.stack.push(true), r2.index++) : (e2.stack.push(null), e2.stack.push(false));
|
|
1234
1344
|
}
|
|
1235
1345
|
},
|
|
1236
|
-
[
|
|
1346
|
+
[i$2.ITER_END]: {
|
|
1237
1347
|
stackIn: 0,
|
|
1238
1348
|
stackOut: 0,
|
|
1239
1349
|
execute: (e2, t2) => {
|
|
@@ -1248,122 +1358,122 @@ const f2 = Q, Z = {
|
|
|
1248
1358
|
}
|
|
1249
1359
|
}
|
|
1250
1360
|
};
|
|
1251
|
-
function
|
|
1252
|
-
const
|
|
1253
|
-
if (f2(o2)) return o2;
|
|
1254
|
-
const s2 = l(e2, t2.op);
|
|
1361
|
+
function x$1(e2, t2, r2) {
|
|
1362
|
+
const s2 = d(e2, t2.op);
|
|
1255
1363
|
if (f2(s2)) return s2;
|
|
1256
|
-
const
|
|
1364
|
+
const o2 = d(e2, t2.op);
|
|
1365
|
+
if (f2(o2)) return o2;
|
|
1366
|
+
const c2 = r2(o2, s2);
|
|
1257
1367
|
e2.stack.push(c2);
|
|
1258
1368
|
}
|
|
1259
1369
|
const ce = {
|
|
1260
|
-
[
|
|
1370
|
+
[i$2.EQ]: {
|
|
1261
1371
|
stackIn: 2,
|
|
1262
1372
|
stackOut: 1,
|
|
1263
|
-
execute: (e2, t2) =>
|
|
1264
|
-
if (f$2(r2) && c(
|
|
1373
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => {
|
|
1374
|
+
if (f$2(r2) && c(s2) || c(r2) && f$2(s2))
|
|
1265
1375
|
return true;
|
|
1266
|
-
if (c(r2) && c(
|
|
1376
|
+
if (c(r2) && c(s2))
|
|
1267
1377
|
return true;
|
|
1268
|
-
if (u$1(r2) || b
|
|
1269
|
-
return u$1(r2) && u$1(
|
|
1378
|
+
if (u$1(r2) || b(r2))
|
|
1379
|
+
return u$1(r2) && u$1(s2) || b(r2) && b(s2) ? r2.id === s2.id : false;
|
|
1270
1380
|
{
|
|
1271
|
-
const
|
|
1272
|
-
return !isNaN(
|
|
1381
|
+
const o2 = m(r2), c2 = m(s2);
|
|
1382
|
+
return !isNaN(o2) && !isNaN(c2) ? o2 === c2 : p$1(r2) === p$1(s2);
|
|
1273
1383
|
}
|
|
1274
1384
|
})
|
|
1275
1385
|
},
|
|
1276
|
-
[
|
|
1386
|
+
[i$2.NEQ]: {
|
|
1277
1387
|
stackIn: 2,
|
|
1278
1388
|
stackOut: 1,
|
|
1279
|
-
execute: (e2, t2) =>
|
|
1280
|
-
if (f$2(r2) && c(
|
|
1389
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => {
|
|
1390
|
+
if (f$2(r2) && c(s2) || c(r2) && f$2(s2))
|
|
1281
1391
|
return false;
|
|
1282
|
-
if (c(r2) && c(
|
|
1392
|
+
if (c(r2) && c(s2))
|
|
1283
1393
|
return false;
|
|
1284
|
-
if (u$1(r2) || b
|
|
1285
|
-
return u$1(r2) && u$1(
|
|
1394
|
+
if (u$1(r2) || b(r2))
|
|
1395
|
+
return u$1(r2) && u$1(s2) || b(r2) && b(s2) ? r2.id !== s2.id : true;
|
|
1286
1396
|
{
|
|
1287
|
-
const
|
|
1288
|
-
return !isNaN(
|
|
1397
|
+
const o2 = m(r2), c2 = m(s2);
|
|
1398
|
+
return !isNaN(o2) && !isNaN(c2) ? o2 !== c2 : p$1(r2) !== p$1(s2);
|
|
1289
1399
|
}
|
|
1290
1400
|
})
|
|
1291
1401
|
},
|
|
1292
|
-
[
|
|
1402
|
+
[i$2.LT]: {
|
|
1293
1403
|
stackIn: 2,
|
|
1294
1404
|
stackOut: 1,
|
|
1295
|
-
execute: (e2, t2) =>
|
|
1296
|
-
const
|
|
1297
|
-
return
|
|
1405
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => {
|
|
1406
|
+
const o2 = m(r2), c2 = m(s2);
|
|
1407
|
+
return o2 < c2;
|
|
1298
1408
|
})
|
|
1299
1409
|
},
|
|
1300
|
-
[
|
|
1410
|
+
[i$2.GT]: {
|
|
1301
1411
|
stackIn: 2,
|
|
1302
1412
|
stackOut: 1,
|
|
1303
|
-
execute: (e2, t2) =>
|
|
1304
|
-
const
|
|
1305
|
-
return
|
|
1413
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => {
|
|
1414
|
+
const o2 = m(r2), c2 = m(s2);
|
|
1415
|
+
return o2 > c2;
|
|
1306
1416
|
})
|
|
1307
1417
|
},
|
|
1308
|
-
[
|
|
1418
|
+
[i$2.LTE]: {
|
|
1309
1419
|
stackIn: 2,
|
|
1310
1420
|
stackOut: 1,
|
|
1311
|
-
execute: (e2, t2) =>
|
|
1312
|
-
const
|
|
1313
|
-
return
|
|
1421
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => {
|
|
1422
|
+
const o2 = m(r2), c2 = m(s2);
|
|
1423
|
+
return o2 <= c2;
|
|
1314
1424
|
})
|
|
1315
1425
|
},
|
|
1316
|
-
[
|
|
1426
|
+
[i$2.GTE]: {
|
|
1317
1427
|
stackIn: 2,
|
|
1318
1428
|
stackOut: 1,
|
|
1319
|
-
execute: (e2, t2) =>
|
|
1320
|
-
const
|
|
1321
|
-
return
|
|
1429
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => {
|
|
1430
|
+
const o2 = m(r2), c2 = m(s2);
|
|
1431
|
+
return o2 >= c2;
|
|
1322
1432
|
})
|
|
1323
1433
|
},
|
|
1324
|
-
[
|
|
1434
|
+
[i$2.EQ_STRICT]: {
|
|
1325
1435
|
stackIn: 2,
|
|
1326
1436
|
stackOut: 1,
|
|
1327
|
-
execute: (e2, t2) =>
|
|
1437
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => u$1(r2) && u$1(s2) || b(r2) && b(s2) ? r2.id === s2.id : r2 === s2)
|
|
1328
1438
|
},
|
|
1329
|
-
[
|
|
1439
|
+
[i$2.NEQ_STRICT]: {
|
|
1330
1440
|
stackIn: 2,
|
|
1331
1441
|
stackOut: 1,
|
|
1332
|
-
execute: (e2, t2) =>
|
|
1442
|
+
execute: (e2, t2) => x$1(e2, t2, (r2, s2) => u$1(r2) && u$1(s2) || b(r2) && b(s2) ? r2.id !== s2.id : r2 !== s2)
|
|
1333
1443
|
}
|
|
1334
1444
|
}, ne = {
|
|
1335
|
-
[
|
|
1445
|
+
[i$2.AND]: {
|
|
1336
1446
|
stackIn: 2,
|
|
1337
1447
|
stackOut: 1,
|
|
1338
1448
|
execute: (e2, t2) => {
|
|
1339
|
-
const r2 =
|
|
1449
|
+
const r2 = d(e2, t2.op);
|
|
1340
1450
|
if (f2(r2)) return r2;
|
|
1341
|
-
const
|
|
1342
|
-
if (f2(
|
|
1343
|
-
const
|
|
1344
|
-
e2.stack.push(
|
|
1451
|
+
const s2 = d(e2, t2.op);
|
|
1452
|
+
if (f2(s2)) return s2;
|
|
1453
|
+
const o2 = j$1(s2) ? r2 : s2;
|
|
1454
|
+
e2.stack.push(o2);
|
|
1345
1455
|
}
|
|
1346
1456
|
},
|
|
1347
|
-
[
|
|
1457
|
+
[i$2.OR]: {
|
|
1348
1458
|
stackIn: 2,
|
|
1349
1459
|
stackOut: 1,
|
|
1350
1460
|
execute: (e2, t2) => {
|
|
1351
|
-
const r2 =
|
|
1461
|
+
const r2 = d(e2, t2.op);
|
|
1352
1462
|
if (f2(r2)) return r2;
|
|
1353
|
-
const
|
|
1354
|
-
if (f2(
|
|
1355
|
-
const
|
|
1356
|
-
e2.stack.push(
|
|
1463
|
+
const s2 = d(e2, t2.op);
|
|
1464
|
+
if (f2(s2)) return s2;
|
|
1465
|
+
const o2 = j$1(s2) ? s2 : r2;
|
|
1466
|
+
e2.stack.push(o2);
|
|
1357
1467
|
}
|
|
1358
1468
|
},
|
|
1359
|
-
[
|
|
1469
|
+
[i$2.NOT]: {
|
|
1360
1470
|
stackIn: 1,
|
|
1361
1471
|
stackOut: 1,
|
|
1362
1472
|
execute: (e2, t2) => {
|
|
1363
|
-
const r2 =
|
|
1473
|
+
const r2 = d(e2, t2.op);
|
|
1364
1474
|
if (f2(r2)) return r2;
|
|
1365
|
-
const
|
|
1366
|
-
e2.stack.push(
|
|
1475
|
+
const s2 = !j$1(r2);
|
|
1476
|
+
e2.stack.push(s2);
|
|
1367
1477
|
}
|
|
1368
1478
|
}
|
|
1369
1479
|
}, pe = {
|
|
@@ -1371,26 +1481,26 @@ const ce = {
|
|
|
1371
1481
|
* ARRAY_NEW: Creates a new empty array on the heap
|
|
1372
1482
|
* Stack: [] -> [array-ref]
|
|
1373
1483
|
*/
|
|
1374
|
-
[
|
|
1484
|
+
[i$2.ARRAY_NEW]: {
|
|
1375
1485
|
stackIn: 0,
|
|
1376
1486
|
stackOut: 1,
|
|
1377
1487
|
execute: (e2, t2) => {
|
|
1378
|
-
const r2 = s(),
|
|
1379
|
-
e2.stack.push(
|
|
1488
|
+
const r2 = s(), s$12 = e2.heap.allocate("array", r2);
|
|
1489
|
+
e2.stack.push(s$12);
|
|
1380
1490
|
}
|
|
1381
1491
|
},
|
|
1382
1492
|
/**
|
|
1383
1493
|
* ARRAY_PUSH: Pushes a value to the end of an array
|
|
1384
1494
|
* Stack: [array-ref, value] -> [array-ref]
|
|
1385
1495
|
*/
|
|
1386
|
-
[
|
|
1496
|
+
[i$2.ARRAY_PUSH]: {
|
|
1387
1497
|
stackIn: 2,
|
|
1388
1498
|
stackOut: 1,
|
|
1389
1499
|
execute: (e2, t2) => {
|
|
1390
|
-
const r2 = e2.stack.pop(),
|
|
1391
|
-
let
|
|
1392
|
-
if (u$1(
|
|
1393
|
-
const c2 = e2.heap.get(
|
|
1500
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1501
|
+
let o$12;
|
|
1502
|
+
if (u$1(s2)) {
|
|
1503
|
+
const c2 = e2.heap.get(s2.id);
|
|
1394
1504
|
if (!c2 || c2.type !== "array")
|
|
1395
1505
|
return {
|
|
1396
1506
|
type: "RuntimeError",
|
|
@@ -1398,9 +1508,9 @@ const ce = {
|
|
|
1398
1508
|
pc: e2.pc,
|
|
1399
1509
|
opcode: t2.op
|
|
1400
1510
|
};
|
|
1401
|
-
|
|
1402
|
-
} else if (o(
|
|
1403
|
-
|
|
1511
|
+
o$12 = c2.data;
|
|
1512
|
+
} else if (o(s2))
|
|
1513
|
+
o$12 = s2;
|
|
1404
1514
|
else
|
|
1405
1515
|
return {
|
|
1406
1516
|
type: "RuntimeError",
|
|
@@ -1408,49 +1518,49 @@ const ce = {
|
|
|
1408
1518
|
pc: e2.pc,
|
|
1409
1519
|
opcode: t2.op
|
|
1410
1520
|
};
|
|
1411
|
-
|
|
1521
|
+
o$12.elements.push(r2), e2.stack.push(s2);
|
|
1412
1522
|
}
|
|
1413
1523
|
},
|
|
1414
|
-
[
|
|
1524
|
+
[i$2.ARRAY_GET]: {
|
|
1415
1525
|
stackIn: 2,
|
|
1416
1526
|
stackOut: 1,
|
|
1417
1527
|
execute: (e2, t$1) => {
|
|
1418
1528
|
var a2;
|
|
1419
|
-
const r2 = e2.stack.pop(),
|
|
1420
|
-
let
|
|
1421
|
-
if (u$1(
|
|
1422
|
-
const
|
|
1423
|
-
if (!
|
|
1529
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1530
|
+
let o$12;
|
|
1531
|
+
if (u$1(s2)) {
|
|
1532
|
+
const i2 = e2.heap.get(s2.id);
|
|
1533
|
+
if (!i2 || i2.type !== "array")
|
|
1424
1534
|
return {
|
|
1425
1535
|
type: "RuntimeError",
|
|
1426
1536
|
message: "Invalid array reference",
|
|
1427
1537
|
pc: e2.pc,
|
|
1428
1538
|
opcode: t$1.op
|
|
1429
1539
|
};
|
|
1430
|
-
|
|
1431
|
-
} else if (b
|
|
1432
|
-
const
|
|
1433
|
-
if (!
|
|
1540
|
+
o$12 = i2.data;
|
|
1541
|
+
} else if (b(s2)) {
|
|
1542
|
+
const i2 = e2.heap.get(s2.id);
|
|
1543
|
+
if (!i2 || i2.type !== "object")
|
|
1434
1544
|
return {
|
|
1435
1545
|
type: "RuntimeError",
|
|
1436
1546
|
message: "Invalid object reference",
|
|
1437
1547
|
pc: e2.pc,
|
|
1438
1548
|
opcode: t$1.op
|
|
1439
1549
|
};
|
|
1440
|
-
const
|
|
1550
|
+
const u2 = i2.data, y2 = p$1(r2), E2 = u2.properties[y2] ?? C$1();
|
|
1441
1551
|
e2.stack.push(E2);
|
|
1442
1552
|
return;
|
|
1443
|
-
} else if (o(
|
|
1444
|
-
|
|
1445
|
-
else if (t(
|
|
1446
|
-
let
|
|
1553
|
+
} else if (o(s2))
|
|
1554
|
+
o$12 = s2;
|
|
1555
|
+
else if (t(s2)) {
|
|
1556
|
+
let i2;
|
|
1447
1557
|
if (i$1(r2))
|
|
1448
|
-
|
|
1558
|
+
i2 = r2;
|
|
1449
1559
|
else if (t(r2)) {
|
|
1450
|
-
const
|
|
1451
|
-
!isNaN(
|
|
1560
|
+
const u2 = parseInt(r2, 10);
|
|
1561
|
+
!isNaN(u2) && u2.toString() === r2 && (i2 = u2);
|
|
1452
1562
|
}
|
|
1453
|
-
|
|
1563
|
+
i2 !== void 0 && i2 >= 0 && i2 < s2.length ? e2.stack.push(s2[i2]) : e2.stack.push(C$1());
|
|
1454
1564
|
return;
|
|
1455
1565
|
} else
|
|
1456
1566
|
return {
|
|
@@ -1463,12 +1573,12 @@ const ce = {
|
|
|
1463
1573
|
if (i$1(r2))
|
|
1464
1574
|
c2 = r2;
|
|
1465
1575
|
else if (t(r2)) {
|
|
1466
|
-
const
|
|
1467
|
-
if (!isNaN(
|
|
1468
|
-
c2 =
|
|
1576
|
+
const i2 = parseInt(r2, 10);
|
|
1577
|
+
if (!isNaN(i2) && i2.toString() === r2 && i2 >= 0)
|
|
1578
|
+
c2 = i2;
|
|
1469
1579
|
else {
|
|
1470
|
-
const
|
|
1471
|
-
e2.stack.push(
|
|
1580
|
+
const u2 = ((a2 = o$12.properties) == null ? void 0 : a2[r2]) ?? C$1();
|
|
1581
|
+
e2.stack.push(u2);
|
|
1472
1582
|
return;
|
|
1473
1583
|
}
|
|
1474
1584
|
} else
|
|
@@ -1478,40 +1588,40 @@ const ce = {
|
|
|
1478
1588
|
pc: e2.pc,
|
|
1479
1589
|
opcode: t$1.op
|
|
1480
1590
|
};
|
|
1481
|
-
const p2 =
|
|
1591
|
+
const p2 = o$12.elements[c2] ?? C$1();
|
|
1482
1592
|
e2.stack.push(p2);
|
|
1483
1593
|
}
|
|
1484
1594
|
},
|
|
1485
|
-
[
|
|
1595
|
+
[i$2.ARRAY_SET]: {
|
|
1486
1596
|
stackIn: 3,
|
|
1487
1597
|
stackOut: 1,
|
|
1488
1598
|
execute: (e2, t$1) => {
|
|
1489
|
-
const r2 = e2.stack.pop(),
|
|
1599
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop(), o$12 = e2.stack.pop();
|
|
1490
1600
|
let c2;
|
|
1491
|
-
if (u$1(
|
|
1492
|
-
const
|
|
1493
|
-
if (!
|
|
1601
|
+
if (u$1(o$12)) {
|
|
1602
|
+
const i2 = e2.heap.get(o$12.id);
|
|
1603
|
+
if (!i2 || i2.type !== "array")
|
|
1494
1604
|
return {
|
|
1495
1605
|
type: "RuntimeError",
|
|
1496
1606
|
message: "Invalid array reference",
|
|
1497
1607
|
pc: e2.pc,
|
|
1498
1608
|
opcode: t$1.op
|
|
1499
1609
|
};
|
|
1500
|
-
c2 =
|
|
1501
|
-
} else if (b$
|
|
1502
|
-
const
|
|
1503
|
-
if (!
|
|
1610
|
+
c2 = i2.data;
|
|
1611
|
+
} else if (b(o$12)) {
|
|
1612
|
+
const i2 = e2.heap.get(o$12.id);
|
|
1613
|
+
if (!i2 || i2.type !== "object")
|
|
1504
1614
|
return {
|
|
1505
1615
|
type: "RuntimeError",
|
|
1506
1616
|
message: "Invalid object reference",
|
|
1507
1617
|
pc: e2.pc,
|
|
1508
1618
|
opcode: t$1.op
|
|
1509
1619
|
};
|
|
1510
|
-
const
|
|
1511
|
-
|
|
1620
|
+
const u2 = i2.data, y2 = p$1(s2);
|
|
1621
|
+
u2.properties[y2] = r2, e2.stack.push(o$12);
|
|
1512
1622
|
return;
|
|
1513
|
-
} else if (o(
|
|
1514
|
-
c2 =
|
|
1623
|
+
} else if (o(o$12))
|
|
1624
|
+
c2 = o$12;
|
|
1515
1625
|
else
|
|
1516
1626
|
return {
|
|
1517
1627
|
type: "RuntimeError",
|
|
@@ -1520,14 +1630,14 @@ const ce = {
|
|
|
1520
1630
|
opcode: t$1.op
|
|
1521
1631
|
};
|
|
1522
1632
|
let p2;
|
|
1523
|
-
if (i$1(
|
|
1524
|
-
p2 =
|
|
1525
|
-
else if (t(
|
|
1526
|
-
const
|
|
1527
|
-
if (!isNaN(
|
|
1528
|
-
p2 =
|
|
1633
|
+
if (i$1(s2))
|
|
1634
|
+
p2 = s2;
|
|
1635
|
+
else if (t(s2)) {
|
|
1636
|
+
const i2 = parseInt(s2, 10);
|
|
1637
|
+
if (!isNaN(i2) && i2.toString() === s2 && i2 >= 0)
|
|
1638
|
+
p2 = i2;
|
|
1529
1639
|
else {
|
|
1530
|
-
c2.properties || (c2.properties = {}), c2.properties[
|
|
1640
|
+
c2.properties || (c2.properties = {}), c2.properties[s2] = r2, e2.stack.push(o$12);
|
|
1531
1641
|
return;
|
|
1532
1642
|
}
|
|
1533
1643
|
} else
|
|
@@ -1545,27 +1655,27 @@ const ce = {
|
|
|
1545
1655
|
pc: e2.pc,
|
|
1546
1656
|
opcode: t$1.op
|
|
1547
1657
|
};
|
|
1548
|
-
c2.elements[a2] = r2, e2.stack.push(
|
|
1658
|
+
c2.elements[a2] = r2, e2.stack.push(o$12);
|
|
1549
1659
|
}
|
|
1550
1660
|
},
|
|
1551
|
-
[
|
|
1661
|
+
[i$2.ARRAY_LEN]: {
|
|
1552
1662
|
stackIn: 1,
|
|
1553
1663
|
stackOut: 1,
|
|
1554
1664
|
execute: (e2, t2) => {
|
|
1555
1665
|
const r2 = e2.stack.pop();
|
|
1556
|
-
let
|
|
1666
|
+
let s2;
|
|
1557
1667
|
if (u$1(r2)) {
|
|
1558
|
-
const
|
|
1559
|
-
if (!
|
|
1668
|
+
const o2 = e2.heap.get(r2.id);
|
|
1669
|
+
if (!o2 || o2.type !== "array")
|
|
1560
1670
|
return {
|
|
1561
1671
|
type: "RuntimeError",
|
|
1562
1672
|
message: "Invalid array reference",
|
|
1563
1673
|
pc: e2.pc,
|
|
1564
1674
|
opcode: t2.op
|
|
1565
1675
|
};
|
|
1566
|
-
|
|
1676
|
+
s2 = o2.data;
|
|
1567
1677
|
} else if (o(r2))
|
|
1568
|
-
|
|
1678
|
+
s2 = r2;
|
|
1569
1679
|
else
|
|
1570
1680
|
return {
|
|
1571
1681
|
type: "RuntimeError",
|
|
@@ -1573,35 +1683,35 @@ const ce = {
|
|
|
1573
1683
|
pc: e2.pc,
|
|
1574
1684
|
opcode: t2.op
|
|
1575
1685
|
};
|
|
1576
|
-
e2.stack.push(
|
|
1686
|
+
e2.stack.push(s2.elements.length);
|
|
1577
1687
|
}
|
|
1578
1688
|
},
|
|
1579
|
-
[
|
|
1689
|
+
[i$2.ARRAY_MAP_PROP]: {
|
|
1580
1690
|
stackIn: 2,
|
|
1581
1691
|
stackOut: 1,
|
|
1582
1692
|
execute: (e2, t2) => {
|
|
1583
|
-
const r2 = e2.stack.pop(),
|
|
1584
|
-
if (!u$1(
|
|
1693
|
+
const r2 = e2.stack.pop(), s$12 = e2.stack.pop();
|
|
1694
|
+
if (!u$1(s$12))
|
|
1585
1695
|
return {
|
|
1586
1696
|
type: "RuntimeError",
|
|
1587
1697
|
message: "map() requires an array",
|
|
1588
1698
|
pc: e2.pc,
|
|
1589
1699
|
opcode: t2.op
|
|
1590
1700
|
};
|
|
1591
|
-
const
|
|
1592
|
-
if (!
|
|
1701
|
+
const o2 = e2.heap.get(s$12.id);
|
|
1702
|
+
if (!o2 || o2.type !== "array")
|
|
1593
1703
|
return {
|
|
1594
1704
|
type: "RuntimeError",
|
|
1595
1705
|
message: "Invalid array reference",
|
|
1596
1706
|
pc: e2.pc,
|
|
1597
1707
|
opcode: t2.op
|
|
1598
1708
|
};
|
|
1599
|
-
const c2 =
|
|
1600
|
-
for (const
|
|
1601
|
-
if (b
|
|
1602
|
-
const
|
|
1603
|
-
if (
|
|
1604
|
-
const y2 =
|
|
1709
|
+
const c2 = o2.data, p2 = s();
|
|
1710
|
+
for (const i2 of c2.elements)
|
|
1711
|
+
if (b(i2)) {
|
|
1712
|
+
const u2 = e2.heap.get(i2.id);
|
|
1713
|
+
if (u2 && u2.type === "object") {
|
|
1714
|
+
const y2 = u2.data, E2 = p$1(r2);
|
|
1605
1715
|
p2.elements.push(y2.properties[E2] || null);
|
|
1606
1716
|
} else
|
|
1607
1717
|
p2.elements.push(null);
|
|
@@ -1611,104 +1721,104 @@ const ce = {
|
|
|
1611
1721
|
e2.stack.push(a2);
|
|
1612
1722
|
}
|
|
1613
1723
|
},
|
|
1614
|
-
[
|
|
1724
|
+
[i$2.ARRAY_FILTER_PROP]: {
|
|
1615
1725
|
stackIn: 2,
|
|
1616
1726
|
stackOut: 1,
|
|
1617
1727
|
execute: (e2, t2) => {
|
|
1618
|
-
const r2 = e2.stack.pop(),
|
|
1619
|
-
if (!u$1(
|
|
1728
|
+
const r2 = e2.stack.pop(), s$12 = e2.stack.pop();
|
|
1729
|
+
if (!u$1(s$12))
|
|
1620
1730
|
return {
|
|
1621
1731
|
type: "RuntimeError",
|
|
1622
1732
|
message: "filter() requires an array",
|
|
1623
1733
|
pc: e2.pc,
|
|
1624
1734
|
opcode: t2.op
|
|
1625
1735
|
};
|
|
1626
|
-
const
|
|
1627
|
-
if (!
|
|
1736
|
+
const o2 = e2.heap.get(s$12.id);
|
|
1737
|
+
if (!o2 || o2.type !== "array")
|
|
1628
1738
|
return {
|
|
1629
1739
|
type: "RuntimeError",
|
|
1630
1740
|
message: "Invalid array reference",
|
|
1631
1741
|
pc: e2.pc,
|
|
1632
1742
|
opcode: t2.op
|
|
1633
1743
|
};
|
|
1634
|
-
const c2 =
|
|
1635
|
-
for (const
|
|
1636
|
-
if (b
|
|
1637
|
-
const
|
|
1638
|
-
if (
|
|
1639
|
-
const y2 =
|
|
1640
|
-
E2 in y2.properties && y2.properties[E2] && p2.elements.push(
|
|
1744
|
+
const c2 = o2.data, p2 = s();
|
|
1745
|
+
for (const i2 of c2.elements)
|
|
1746
|
+
if (b(i2)) {
|
|
1747
|
+
const u2 = e2.heap.get(i2.id);
|
|
1748
|
+
if (u2 && u2.type === "object") {
|
|
1749
|
+
const y2 = u2.data, E2 = p$1(r2);
|
|
1750
|
+
E2 in y2.properties && y2.properties[E2] && p2.elements.push(i2);
|
|
1641
1751
|
}
|
|
1642
1752
|
}
|
|
1643
1753
|
const a2 = e2.heap.allocate("array", p2);
|
|
1644
1754
|
e2.stack.push(a2);
|
|
1645
1755
|
}
|
|
1646
1756
|
},
|
|
1647
|
-
[
|
|
1757
|
+
[i$2.ARRAY_SLICE]: {
|
|
1648
1758
|
stackIn: 3,
|
|
1649
1759
|
// array, start, end
|
|
1650
1760
|
stackOut: 1,
|
|
1651
1761
|
execute: (e2, t2) => {
|
|
1652
|
-
const r2 = e2.stack.pop(),
|
|
1653
|
-
if (!((
|
|
1654
|
-
if (!u$1(
|
|
1762
|
+
const r2 = e2.stack.pop(), s$12 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1763
|
+
if (!((M2) => {
|
|
1764
|
+
if (!u$1(M2))
|
|
1655
1765
|
return false;
|
|
1656
|
-
const U2 = e2.heap.get(
|
|
1766
|
+
const U2 = e2.heap.get(M2.id);
|
|
1657
1767
|
return U2 !== void 0 && U2.type === "array";
|
|
1658
|
-
})(
|
|
1768
|
+
})(o2))
|
|
1659
1769
|
return {
|
|
1660
1770
|
type: "RuntimeError",
|
|
1661
1771
|
message: "ARRAY_SLICE requires an array",
|
|
1662
1772
|
pc: e2.pc,
|
|
1663
1773
|
opcode: t2.op
|
|
1664
1774
|
};
|
|
1665
|
-
const a2 = e2.heap.get(
|
|
1666
|
-
e2.stack.push(
|
|
1775
|
+
const a2 = e2.heap.get(o2.id).data, i2 = i$1(s$12) ? s$12 : 0, u2 = r2 === void 0 ? a2.elements.length : i$1(r2) ? r2 : a2.elements.length, y2 = i2 < 0 ? Math.max(0, a2.elements.length + i2) : i2, E2 = u2 < 0 ? Math.max(0, a2.elements.length + u2) : u2, J2 = a2.elements.slice(y2, E2), Y2 = s(J2), z2 = e2.heap.allocate("array", Y2);
|
|
1776
|
+
e2.stack.push(z2);
|
|
1667
1777
|
}
|
|
1668
1778
|
},
|
|
1669
|
-
[
|
|
1779
|
+
[i$2.ARRAY_JOIN]: {
|
|
1670
1780
|
stackIn: 2,
|
|
1671
1781
|
// array, separator
|
|
1672
1782
|
stackOut: 1,
|
|
1673
1783
|
// string
|
|
1674
1784
|
execute: (e2, t$1) => {
|
|
1675
|
-
const r2 = e2.stack.pop(),
|
|
1785
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1676
1786
|
if (!((y2) => {
|
|
1677
1787
|
if (!u$1(y2))
|
|
1678
1788
|
return false;
|
|
1679
1789
|
const E2 = e2.heap.get(y2.id);
|
|
1680
1790
|
return E2 !== void 0 && E2.type === "array";
|
|
1681
|
-
})(
|
|
1791
|
+
})(s2))
|
|
1682
1792
|
return {
|
|
1683
1793
|
type: "RuntimeError",
|
|
1684
1794
|
message: "ARRAY_JOIN requires an array",
|
|
1685
1795
|
pc: e2.pc,
|
|
1686
1796
|
opcode: t$1.op
|
|
1687
1797
|
};
|
|
1688
|
-
const p2 = e2.heap.get(
|
|
1689
|
-
e2.stack.push(
|
|
1798
|
+
const p2 = e2.heap.get(s2.id).data, a2 = t(r2) ? r2 : String(r2), u2 = p2.elements.map((y2) => y2 === null ? "null" : y2 === void 0 || c(y2) ? "undefined" : String(y2)).join(a2);
|
|
1799
|
+
e2.stack.push(u2);
|
|
1690
1800
|
}
|
|
1691
1801
|
},
|
|
1692
|
-
[
|
|
1802
|
+
[i$2.ARRAY_INDEX_OF]: {
|
|
1693
1803
|
stackIn: 2,
|
|
1694
1804
|
// array, searchElement
|
|
1695
1805
|
stackOut: 1,
|
|
1696
1806
|
// number (index or -1)
|
|
1697
1807
|
execute: (e2, t2) => {
|
|
1698
|
-
const r2 = e2.stack.pop(),
|
|
1808
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1699
1809
|
if (!((a2) => {
|
|
1700
1810
|
if (!u$1(a2))
|
|
1701
1811
|
return false;
|
|
1702
|
-
const
|
|
1703
|
-
return
|
|
1704
|
-
})(
|
|
1812
|
+
const i2 = e2.heap.get(a2.id);
|
|
1813
|
+
return i2 !== void 0 && i2.type === "array";
|
|
1814
|
+
})(s2))
|
|
1705
1815
|
return {
|
|
1706
1816
|
type: "RuntimeError",
|
|
1707
1817
|
message: "ARRAY_INDEX_OF requires an array",
|
|
1708
1818
|
pc: e2.pc,
|
|
1709
1819
|
opcode: t2.op
|
|
1710
1820
|
};
|
|
1711
|
-
const p2 = e2.heap.get(
|
|
1821
|
+
const p2 = e2.heap.get(s2.id).data;
|
|
1712
1822
|
for (let a2 = 0; a2 < p2.elements.length; a2++)
|
|
1713
1823
|
if (p2.elements[a2] === r2) {
|
|
1714
1824
|
e2.stack.push(a2);
|
|
@@ -1718,43 +1828,43 @@ const ce = {
|
|
|
1718
1828
|
}
|
|
1719
1829
|
}
|
|
1720
1830
|
};
|
|
1721
|
-
function
|
|
1831
|
+
function L(e2, t2) {
|
|
1722
1832
|
if (e2 === null) return null;
|
|
1723
1833
|
if (e2 !== void 0) {
|
|
1724
1834
|
if (typeof e2 == "string" || typeof e2 == "number" || typeof e2 == "boolean" || e2 && typeof e2 == "object" && e2.type === "array" && Array.isArray(e2.elements))
|
|
1725
1835
|
return e2;
|
|
1726
1836
|
if (Array.isArray(e2)) {
|
|
1727
1837
|
const r2 = s();
|
|
1728
|
-
return r2.elements = e2.map((
|
|
1838
|
+
return r2.elements = e2.map((s2) => L(s2, t2)), t2.allocate("array", r2);
|
|
1729
1839
|
}
|
|
1730
1840
|
if (e2 && typeof e2 == "object" && e2.type === "object" && e2.properties)
|
|
1731
1841
|
return e2;
|
|
1732
1842
|
if (typeof e2 == "object") {
|
|
1733
|
-
const r2 = M
|
|
1734
|
-
for (const [
|
|
1735
|
-
r2.properties[
|
|
1843
|
+
const r2 = M();
|
|
1844
|
+
for (const [s2, o2] of Object.entries(e2))
|
|
1845
|
+
r2.properties[s2] = L(o2, t2);
|
|
1736
1846
|
return t2.allocate("object", r2);
|
|
1737
1847
|
}
|
|
1738
1848
|
return null;
|
|
1739
1849
|
}
|
|
1740
1850
|
}
|
|
1741
1851
|
const ae = {
|
|
1742
|
-
[
|
|
1852
|
+
[i$2.CONCAT]: {
|
|
1743
1853
|
stackIn: 2,
|
|
1744
1854
|
stackOut: 1,
|
|
1745
1855
|
execute: (e2, t2) => {
|
|
1746
|
-
const r2 =
|
|
1856
|
+
const r2 = d(e2, t2.op);
|
|
1747
1857
|
if (f2(r2)) return r2;
|
|
1748
|
-
const
|
|
1749
|
-
if (f2(
|
|
1750
|
-
e2.stack.push(p$1(
|
|
1858
|
+
const s2 = d(e2, t2.op);
|
|
1859
|
+
if (f2(s2)) return s2;
|
|
1860
|
+
e2.stack.push(p$1(s2) + p$1(r2));
|
|
1751
1861
|
}
|
|
1752
1862
|
},
|
|
1753
|
-
[
|
|
1863
|
+
[i$2.STRING_LEN]: {
|
|
1754
1864
|
stackIn: 1,
|
|
1755
1865
|
stackOut: 1,
|
|
1756
1866
|
execute: (e2, t$1) => {
|
|
1757
|
-
const r2 =
|
|
1867
|
+
const r2 = d(e2, t$1.op);
|
|
1758
1868
|
if (f2(r2)) return r2;
|
|
1759
1869
|
if (!t(r2))
|
|
1760
1870
|
return {
|
|
@@ -1766,27 +1876,27 @@ const ae = {
|
|
|
1766
1876
|
e2.stack.push(r2.length);
|
|
1767
1877
|
}
|
|
1768
1878
|
},
|
|
1769
|
-
[
|
|
1879
|
+
[i$2.LENGTH]: {
|
|
1770
1880
|
stackIn: 1,
|
|
1771
1881
|
stackOut: 1,
|
|
1772
1882
|
execute: (e2, t$1) => {
|
|
1773
|
-
const r2 =
|
|
1883
|
+
const r2 = d(e2, t$1.op);
|
|
1774
1884
|
if (f2(r2)) return r2;
|
|
1775
1885
|
if (t(r2))
|
|
1776
1886
|
e2.stack.push(r2.length);
|
|
1777
1887
|
else if (o(r2))
|
|
1778
1888
|
e2.stack.push(r2.elements.length);
|
|
1779
1889
|
else if (u$1(r2)) {
|
|
1780
|
-
const
|
|
1781
|
-
if (!
|
|
1890
|
+
const s2 = e2.heap.get(r2.id);
|
|
1891
|
+
if (!s2 || s2.type !== "array")
|
|
1782
1892
|
return {
|
|
1783
1893
|
type: "RuntimeError",
|
|
1784
1894
|
message: "Invalid array reference",
|
|
1785
1895
|
pc: e2.pc,
|
|
1786
1896
|
opcode: t$1.op
|
|
1787
1897
|
};
|
|
1788
|
-
const
|
|
1789
|
-
e2.stack.push(
|
|
1898
|
+
const o2 = s2.data;
|
|
1899
|
+
e2.stack.push(o2.elements.length);
|
|
1790
1900
|
} else
|
|
1791
1901
|
return {
|
|
1792
1902
|
type: "RuntimeError",
|
|
@@ -1796,11 +1906,11 @@ const ae = {
|
|
|
1796
1906
|
};
|
|
1797
1907
|
}
|
|
1798
1908
|
},
|
|
1799
|
-
[
|
|
1909
|
+
[i$2.JSON_PARSE]: {
|
|
1800
1910
|
stackIn: 1,
|
|
1801
1911
|
stackOut: 1,
|
|
1802
1912
|
execute: (e2, t$1) => {
|
|
1803
|
-
const r2 =
|
|
1913
|
+
const r2 = d(e2, t$1.op);
|
|
1804
1914
|
if (f2(r2)) return r2;
|
|
1805
1915
|
if (!t(r2))
|
|
1806
1916
|
return {
|
|
@@ -1810,24 +1920,24 @@ const ae = {
|
|
|
1810
1920
|
opcode: t$1.op
|
|
1811
1921
|
};
|
|
1812
1922
|
try {
|
|
1813
|
-
const
|
|
1814
|
-
e2.stack.push(
|
|
1923
|
+
const s2 = JSON.parse(r2);
|
|
1924
|
+
e2.stack.push(L(s2, e2.heap));
|
|
1815
1925
|
} catch {
|
|
1816
1926
|
e2.stack.push(null);
|
|
1817
1927
|
}
|
|
1818
1928
|
}
|
|
1819
1929
|
},
|
|
1820
|
-
[
|
|
1930
|
+
[i$2.TYPEOF]: {
|
|
1821
1931
|
stackIn: 1,
|
|
1822
1932
|
stackOut: 1,
|
|
1823
1933
|
execute: (e2, t2) => {
|
|
1824
|
-
const r2 =
|
|
1934
|
+
const r2 = d(e2, t2.op);
|
|
1825
1935
|
if (f2(r2)) return r2;
|
|
1826
|
-
e2.stack.push(d$
|
|
1936
|
+
e2.stack.push(d$2(r2));
|
|
1827
1937
|
}
|
|
1828
1938
|
}
|
|
1829
|
-
},
|
|
1830
|
-
[
|
|
1939
|
+
}, ie = {
|
|
1940
|
+
[i$2.INC]: {
|
|
1831
1941
|
stackIn: 1,
|
|
1832
1942
|
stackOut: 1,
|
|
1833
1943
|
execute: (e2, t2) => {
|
|
@@ -1839,13 +1949,13 @@ const ae = {
|
|
|
1839
1949
|
pc: e2.pc,
|
|
1840
1950
|
opcode: t2.op
|
|
1841
1951
|
};
|
|
1842
|
-
const
|
|
1843
|
-
e2.variables.set(r2,
|
|
1952
|
+
const s2 = e2.variables.get(r2) ?? 0, o2 = m(s2) + 1;
|
|
1953
|
+
e2.variables.set(r2, o2);
|
|
1844
1954
|
const c2 = t2.arg === true;
|
|
1845
|
-
e2.stack.push(c2 ? m(
|
|
1955
|
+
e2.stack.push(c2 ? m(s2) : o2);
|
|
1846
1956
|
}
|
|
1847
1957
|
},
|
|
1848
|
-
[
|
|
1958
|
+
[i$2.DEC]: {
|
|
1849
1959
|
stackIn: 1,
|
|
1850
1960
|
stackOut: 1,
|
|
1851
1961
|
execute: (e2, t2) => {
|
|
@@ -1857,14 +1967,14 @@ const ae = {
|
|
|
1857
1967
|
pc: e2.pc,
|
|
1858
1968
|
opcode: t2.op
|
|
1859
1969
|
};
|
|
1860
|
-
const
|
|
1861
|
-
e2.variables.set(r2,
|
|
1970
|
+
const s2 = e2.variables.get(r2) ?? 0, o2 = m(s2) - 1;
|
|
1971
|
+
e2.variables.set(r2, o2);
|
|
1862
1972
|
const c2 = t2.arg === true;
|
|
1863
|
-
e2.stack.push(c2 ? m(
|
|
1973
|
+
e2.stack.push(c2 ? m(s2) : o2);
|
|
1864
1974
|
}
|
|
1865
1975
|
}
|
|
1866
|
-
},
|
|
1867
|
-
[
|
|
1976
|
+
}, ue = {
|
|
1977
|
+
[i$2.RETURN]: {
|
|
1868
1978
|
stackIn: 0,
|
|
1869
1979
|
stackOut: 0,
|
|
1870
1980
|
controlsPC: true,
|
|
@@ -1873,7 +1983,7 @@ const ae = {
|
|
|
1873
1983
|
e2.returnValue = r2, e2.status = "complete";
|
|
1874
1984
|
}
|
|
1875
1985
|
},
|
|
1876
|
-
[
|
|
1986
|
+
[i$2.BREAK]: {
|
|
1877
1987
|
stackIn: 0,
|
|
1878
1988
|
stackOut: 0,
|
|
1879
1989
|
controlsPC: true,
|
|
@@ -1896,7 +2006,7 @@ const ae = {
|
|
|
1896
2006
|
e2.pc = r2;
|
|
1897
2007
|
}
|
|
1898
2008
|
},
|
|
1899
|
-
[
|
|
2009
|
+
[i$2.CONTINUE]: {
|
|
1900
2010
|
stackIn: 0,
|
|
1901
2011
|
stackOut: 0,
|
|
1902
2012
|
controlsPC: true,
|
|
@@ -1919,7 +2029,7 @@ const ae = {
|
|
|
1919
2029
|
e2.pc = r2;
|
|
1920
2030
|
}
|
|
1921
2031
|
},
|
|
1922
|
-
[
|
|
2032
|
+
[i$2.FS_LIST_FILES]: {
|
|
1923
2033
|
stackIn: 1,
|
|
1924
2034
|
// Minimum 1 argument (path), optionally 2 (path + options)
|
|
1925
2035
|
stackOut: 1,
|
|
@@ -1931,9 +2041,9 @@ const ae = {
|
|
|
1931
2041
|
pc: e2.pc,
|
|
1932
2042
|
opcode: t$1.op
|
|
1933
2043
|
};
|
|
1934
|
-
let r2,
|
|
1935
|
-
const
|
|
1936
|
-
if (e2.stack.length >= 2 && typeof
|
|
2044
|
+
let r2, s2 = {};
|
|
2045
|
+
const o$12 = e2.stack[e2.stack.length - 1];
|
|
2046
|
+
if (e2.stack.length >= 2 && typeof o$12 == "object" && o$12 !== null && !o(o$12) && (s2 = e2.stack.pop()), r2 = e2.stack.pop(), !t(r2))
|
|
1937
2047
|
return {
|
|
1938
2048
|
type: "RuntimeError",
|
|
1939
2049
|
message: "FS_LIST_FILES requires a string path",
|
|
@@ -1947,7 +2057,7 @@ const ae = {
|
|
|
1947
2057
|
pc: e2.pc,
|
|
1948
2058
|
opcode: t$1.op
|
|
1949
2059
|
};
|
|
1950
|
-
const c2 = e2.fileSystem.listFiles(r2,
|
|
2060
|
+
const c2 = e2.fileSystem.listFiles(r2, s2);
|
|
1951
2061
|
if (o(c2)) {
|
|
1952
2062
|
const p2 = e2.heap.allocate("array", c2);
|
|
1953
2063
|
e2.stack.push(p2);
|
|
@@ -1955,7 +2065,7 @@ const ae = {
|
|
|
1955
2065
|
e2.stack.push(c2);
|
|
1956
2066
|
}
|
|
1957
2067
|
},
|
|
1958
|
-
[
|
|
2068
|
+
[i$2.FS_READ_FILE]: {
|
|
1959
2069
|
stackIn: 1,
|
|
1960
2070
|
// path
|
|
1961
2071
|
stackOut: 1,
|
|
@@ -1976,18 +2086,18 @@ const ae = {
|
|
|
1976
2086
|
pc: e2.pc,
|
|
1977
2087
|
opcode: t$1.op
|
|
1978
2088
|
};
|
|
1979
|
-
const
|
|
1980
|
-
e2.stack.push(
|
|
2089
|
+
const s2 = e2.fileSystem.readFile(r2);
|
|
2090
|
+
e2.stack.push(s2);
|
|
1981
2091
|
}
|
|
1982
2092
|
},
|
|
1983
|
-
[
|
|
2093
|
+
[i$2.FS_WRITE_FILE]: {
|
|
1984
2094
|
stackIn: 2,
|
|
1985
2095
|
// path, content
|
|
1986
2096
|
stackOut: 1,
|
|
1987
2097
|
// Returns boolean
|
|
1988
2098
|
execute: (e2, t$1) => {
|
|
1989
|
-
const r2 = e2.stack.pop(),
|
|
1990
|
-
if (!
|
|
2099
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2100
|
+
if (!s2 || !t(s2))
|
|
1991
2101
|
return {
|
|
1992
2102
|
type: "RuntimeError",
|
|
1993
2103
|
message: "FS_WRITE_FILE requires a string path",
|
|
@@ -2008,12 +2118,12 @@ const ae = {
|
|
|
2008
2118
|
pc: e2.pc,
|
|
2009
2119
|
opcode: t$1.op
|
|
2010
2120
|
};
|
|
2011
|
-
const
|
|
2121
|
+
const o2 = p$1(r2), c2 = e2.fileSystem.writeFile(s2, o2);
|
|
2012
2122
|
e2.stack.push(c2);
|
|
2013
2123
|
}
|
|
2014
2124
|
},
|
|
2015
2125
|
// String method handlers
|
|
2016
|
-
[
|
|
2126
|
+
[i$2.STRING_SUBSTRING]: {
|
|
2017
2127
|
stackIn: 2,
|
|
2018
2128
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
2019
2129
|
stackOut: 1,
|
|
@@ -2026,62 +2136,62 @@ const ae = {
|
|
|
2026
2136
|
opcode: t$1.op
|
|
2027
2137
|
};
|
|
2028
2138
|
const r2 = e2.stack.length;
|
|
2029
|
-
let
|
|
2139
|
+
let s2, o2, c2;
|
|
2030
2140
|
const p2 = e2.stack[r2 - 1], a2 = e2.stack[r2 - 2];
|
|
2031
|
-
if (r2 >= 3 && typeof p2 == "number" && typeof a2 == "number" ? (c2 = e2.stack.pop(),
|
|
2141
|
+
if (r2 >= 3 && typeof p2 == "number" && typeof a2 == "number" ? (c2 = e2.stack.pop(), o2 = e2.stack.pop(), s2 = e2.stack.pop()) : (o2 = e2.stack.pop(), s2 = e2.stack.pop(), c2 = void 0), !t(s2))
|
|
2032
2142
|
return {
|
|
2033
2143
|
type: "RuntimeError",
|
|
2034
2144
|
message: "STRING_SUBSTRING requires a string",
|
|
2035
2145
|
pc: e2.pc,
|
|
2036
2146
|
opcode: t$1.op
|
|
2037
2147
|
};
|
|
2038
|
-
if (typeof
|
|
2148
|
+
if (typeof o2 != "number")
|
|
2039
2149
|
return {
|
|
2040
2150
|
type: "RuntimeError",
|
|
2041
2151
|
message: "STRING_SUBSTRING requires numeric start index",
|
|
2042
2152
|
pc: e2.pc,
|
|
2043
2153
|
opcode: t$1.op
|
|
2044
2154
|
};
|
|
2045
|
-
const
|
|
2046
|
-
|
|
2047
|
-
const
|
|
2048
|
-
e2.stack.push(
|
|
2155
|
+
const i2 = s2.length;
|
|
2156
|
+
o2 < 0 && (o2 = Math.max(0, i2 + o2)), c2 !== void 0 && c2 < 0 && (c2 = Math.max(0, i2 + c2));
|
|
2157
|
+
const u2 = c2 !== void 0 ? s2.substring(o2, c2) : s2.substring(o2);
|
|
2158
|
+
e2.stack.push(u2);
|
|
2049
2159
|
}
|
|
2050
2160
|
},
|
|
2051
|
-
[
|
|
2161
|
+
[i$2.STRING_INDEXOF]: {
|
|
2052
2162
|
stackIn: 2,
|
|
2053
2163
|
stackOut: 1,
|
|
2054
2164
|
execute: (e2, t$1) => {
|
|
2055
|
-
const r2 = e2.stack.pop(),
|
|
2056
|
-
if (!t(
|
|
2165
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2166
|
+
if (!t(s2) || !t(r2))
|
|
2057
2167
|
return {
|
|
2058
2168
|
type: "RuntimeError",
|
|
2059
2169
|
message: "STRING_INDEXOF requires string arguments",
|
|
2060
2170
|
pc: e2.pc,
|
|
2061
2171
|
opcode: t$1.op
|
|
2062
2172
|
};
|
|
2063
|
-
e2.stack.push(
|
|
2173
|
+
e2.stack.push(s2.indexOf(r2));
|
|
2064
2174
|
}
|
|
2065
2175
|
},
|
|
2066
|
-
[
|
|
2176
|
+
[i$2.STRING_SPLIT]: {
|
|
2067
2177
|
stackIn: 2,
|
|
2068
2178
|
stackOut: 1,
|
|
2069
2179
|
execute: (e2, t$1) => {
|
|
2070
|
-
const r2 = e2.stack.pop(),
|
|
2071
|
-
if (!t(
|
|
2180
|
+
const r2 = e2.stack.pop(), s$12 = e2.stack.pop();
|
|
2181
|
+
if (!t(s$12) || !t(r2))
|
|
2072
2182
|
return {
|
|
2073
2183
|
type: "RuntimeError",
|
|
2074
2184
|
message: "STRING_SPLIT requires string arguments",
|
|
2075
2185
|
pc: e2.pc,
|
|
2076
2186
|
opcode: t$1.op
|
|
2077
2187
|
};
|
|
2078
|
-
let
|
|
2079
|
-
r2 === "" ? s$12
|
|
2080
|
-
const c2 = s(
|
|
2188
|
+
let o2;
|
|
2189
|
+
r2 === "" ? o2 = s$12.split("") : o2 = s$12.split(r2);
|
|
2190
|
+
const c2 = s(o2), p2 = e2.heap.allocate("array", c2);
|
|
2081
2191
|
e2.stack.push(p2);
|
|
2082
2192
|
}
|
|
2083
2193
|
},
|
|
2084
|
-
[
|
|
2194
|
+
[i$2.STRING_SLICE]: {
|
|
2085
2195
|
stackIn: 2,
|
|
2086
2196
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
2087
2197
|
stackOut: 1,
|
|
@@ -2094,32 +2204,32 @@ const ae = {
|
|
|
2094
2204
|
opcode: t$1.op
|
|
2095
2205
|
};
|
|
2096
2206
|
const r2 = e2.stack.length;
|
|
2097
|
-
let
|
|
2207
|
+
let s2, o2, c2;
|
|
2098
2208
|
const p2 = e2.stack.length >= 1 ? e2.stack[r2 - 1] : void 0, a2 = e2.stack.length >= 2 ? e2.stack[r2 - 2] : void 0;
|
|
2099
|
-
if (r2 >= 3 && typeof p2 == "number" && typeof a2 == "number" ? (c2 = e2.stack.pop(),
|
|
2209
|
+
if (r2 >= 3 && typeof p2 == "number" && typeof a2 == "number" ? (c2 = e2.stack.pop(), o2 = e2.stack.pop(), s2 = e2.stack.pop()) : (o2 = e2.stack.pop(), s2 = e2.stack.pop(), c2 = void 0), !t(s2))
|
|
2100
2210
|
return {
|
|
2101
2211
|
type: "RuntimeError",
|
|
2102
2212
|
message: "STRING_SLICE requires a string",
|
|
2103
2213
|
pc: e2.pc,
|
|
2104
2214
|
opcode: t$1.op
|
|
2105
2215
|
};
|
|
2106
|
-
if (typeof
|
|
2216
|
+
if (typeof o2 != "number")
|
|
2107
2217
|
return {
|
|
2108
2218
|
type: "RuntimeError",
|
|
2109
2219
|
message: "STRING_SLICE requires numeric start index",
|
|
2110
2220
|
pc: e2.pc,
|
|
2111
2221
|
opcode: t$1.op
|
|
2112
2222
|
};
|
|
2113
|
-
const
|
|
2114
|
-
e2.stack.push(
|
|
2223
|
+
const i2 = c2 !== void 0 ? s2.slice(o2, c2) : s2.slice(o2);
|
|
2224
|
+
e2.stack.push(i2);
|
|
2115
2225
|
}
|
|
2116
2226
|
},
|
|
2117
|
-
[
|
|
2227
|
+
[i$2.STRING_CHARAT]: {
|
|
2118
2228
|
stackIn: 2,
|
|
2119
2229
|
stackOut: 1,
|
|
2120
2230
|
execute: (e2, t$1) => {
|
|
2121
|
-
const r2 = e2.stack.pop(),
|
|
2122
|
-
if (!t(
|
|
2231
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2232
|
+
if (!t(s2))
|
|
2123
2233
|
return {
|
|
2124
2234
|
type: "RuntimeError",
|
|
2125
2235
|
message: "STRING_CHARAT requires a string",
|
|
@@ -2133,11 +2243,11 @@ const ae = {
|
|
|
2133
2243
|
pc: e2.pc,
|
|
2134
2244
|
opcode: t$1.op
|
|
2135
2245
|
};
|
|
2136
|
-
const
|
|
2137
|
-
e2.stack.push(
|
|
2246
|
+
const o2 = s2.charAt(r2);
|
|
2247
|
+
e2.stack.push(o2);
|
|
2138
2248
|
}
|
|
2139
2249
|
},
|
|
2140
|
-
[
|
|
2250
|
+
[i$2.STRING_TOUPPERCASE]: {
|
|
2141
2251
|
stackIn: 1,
|
|
2142
2252
|
stackOut: 1,
|
|
2143
2253
|
execute: (e2, t$1) => {
|
|
@@ -2152,7 +2262,7 @@ const ae = {
|
|
|
2152
2262
|
e2.stack.push(r2.toUpperCase());
|
|
2153
2263
|
}
|
|
2154
2264
|
},
|
|
2155
|
-
[
|
|
2265
|
+
[i$2.STRING_TOLOWERCASE]: {
|
|
2156
2266
|
stackIn: 1,
|
|
2157
2267
|
stackOut: 1,
|
|
2158
2268
|
execute: (e2, t$1) => {
|
|
@@ -2167,7 +2277,7 @@ const ae = {
|
|
|
2167
2277
|
e2.stack.push(r2.toLowerCase());
|
|
2168
2278
|
}
|
|
2169
2279
|
},
|
|
2170
|
-
[
|
|
2280
|
+
[i$2.TO_STRING]: {
|
|
2171
2281
|
stackIn: 1,
|
|
2172
2282
|
stackOut: 1,
|
|
2173
2283
|
execute: (e2, t2) => {
|
|
@@ -2179,61 +2289,61 @@ const ae = {
|
|
|
2179
2289
|
pc: e2.pc,
|
|
2180
2290
|
opcode: t2.op
|
|
2181
2291
|
};
|
|
2182
|
-
const
|
|
2183
|
-
e2.stack.push(
|
|
2292
|
+
const s2 = p$1(r2);
|
|
2293
|
+
e2.stack.push(s2);
|
|
2184
2294
|
}
|
|
2185
2295
|
},
|
|
2186
|
-
[
|
|
2296
|
+
[i$2.STRING_INCLUDES]: {
|
|
2187
2297
|
stackIn: 2,
|
|
2188
2298
|
// string, searchString
|
|
2189
2299
|
stackOut: 1,
|
|
2190
2300
|
// boolean
|
|
2191
2301
|
execute: (e2, t$1) => {
|
|
2192
|
-
const r2 = e2.stack.pop(),
|
|
2193
|
-
if (!t(
|
|
2302
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2303
|
+
if (!t(s2))
|
|
2194
2304
|
return {
|
|
2195
2305
|
type: "RuntimeError",
|
|
2196
2306
|
message: "STRING_INCLUDES requires a string",
|
|
2197
2307
|
pc: e2.pc,
|
|
2198
2308
|
opcode: t$1.op
|
|
2199
2309
|
};
|
|
2200
|
-
const
|
|
2201
|
-
e2.stack.push(
|
|
2310
|
+
const o2 = String(r2);
|
|
2311
|
+
e2.stack.push(s2.includes(o2));
|
|
2202
2312
|
}
|
|
2203
2313
|
},
|
|
2204
|
-
[
|
|
2314
|
+
[i$2.STRING_ENDS_WITH]: {
|
|
2205
2315
|
stackIn: 2,
|
|
2206
2316
|
stackOut: 1,
|
|
2207
2317
|
execute: (e2, t$1) => {
|
|
2208
|
-
const r2 = e2.stack.pop(),
|
|
2209
|
-
if (!t(
|
|
2318
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2319
|
+
if (!t(s2))
|
|
2210
2320
|
return {
|
|
2211
2321
|
type: "RuntimeError",
|
|
2212
2322
|
message: "STRING_ENDS_WITH requires a string",
|
|
2213
2323
|
pc: e2.pc,
|
|
2214
2324
|
opcode: t$1.op
|
|
2215
2325
|
};
|
|
2216
|
-
const
|
|
2217
|
-
e2.stack.push(
|
|
2326
|
+
const o2 = String(r2);
|
|
2327
|
+
e2.stack.push(s2.endsWith(o2));
|
|
2218
2328
|
}
|
|
2219
2329
|
},
|
|
2220
|
-
[
|
|
2330
|
+
[i$2.STRING_STARTS_WITH]: {
|
|
2221
2331
|
stackIn: 2,
|
|
2222
2332
|
stackOut: 1,
|
|
2223
2333
|
execute: (e2, t$1) => {
|
|
2224
|
-
const r2 = e2.stack.pop(),
|
|
2225
|
-
if (!t(
|
|
2334
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2335
|
+
if (!t(s2))
|
|
2226
2336
|
return {
|
|
2227
2337
|
type: "RuntimeError",
|
|
2228
2338
|
message: "STRING_STARTS_WITH requires a string",
|
|
2229
2339
|
pc: e2.pc,
|
|
2230
2340
|
opcode: t$1.op
|
|
2231
2341
|
};
|
|
2232
|
-
const
|
|
2233
|
-
e2.stack.push(
|
|
2342
|
+
const o2 = String(r2);
|
|
2343
|
+
e2.stack.push(s2.startsWith(o2));
|
|
2234
2344
|
}
|
|
2235
2345
|
},
|
|
2236
|
-
[
|
|
2346
|
+
[i$2.STRING_TRIM]: {
|
|
2237
2347
|
stackIn: 1,
|
|
2238
2348
|
stackOut: 1,
|
|
2239
2349
|
execute: (e2, t$1) => {
|
|
@@ -2248,7 +2358,7 @@ const ae = {
|
|
|
2248
2358
|
e2.stack.push(r2.trim());
|
|
2249
2359
|
}
|
|
2250
2360
|
},
|
|
2251
|
-
[
|
|
2361
|
+
[i$2.STRING_TRIM_START]: {
|
|
2252
2362
|
stackIn: 1,
|
|
2253
2363
|
stackOut: 1,
|
|
2254
2364
|
execute: (e2, t$1) => {
|
|
@@ -2263,7 +2373,7 @@ const ae = {
|
|
|
2263
2373
|
e2.stack.push(r2.trimStart());
|
|
2264
2374
|
}
|
|
2265
2375
|
},
|
|
2266
|
-
[
|
|
2376
|
+
[i$2.STRING_TRIM_END]: {
|
|
2267
2377
|
stackIn: 1,
|
|
2268
2378
|
stackOut: 1,
|
|
2269
2379
|
execute: (e2, t$1) => {
|
|
@@ -2278,61 +2388,61 @@ const ae = {
|
|
|
2278
2388
|
e2.stack.push(r2.trimEnd());
|
|
2279
2389
|
}
|
|
2280
2390
|
},
|
|
2281
|
-
[
|
|
2391
|
+
[i$2.STRING_REPLACE]: {
|
|
2282
2392
|
stackIn: 3,
|
|
2283
2393
|
// string, search, replacement
|
|
2284
2394
|
stackOut: 1,
|
|
2285
2395
|
execute: (e2, t$1) => {
|
|
2286
|
-
const r2 = e2.stack.pop(),
|
|
2287
|
-
if (!t(
|
|
2396
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
2397
|
+
if (!t(o2))
|
|
2288
2398
|
return {
|
|
2289
2399
|
type: "RuntimeError",
|
|
2290
2400
|
message: "STRING_REPLACE requires a string",
|
|
2291
2401
|
pc: e2.pc,
|
|
2292
2402
|
opcode: t$1.op
|
|
2293
2403
|
};
|
|
2294
|
-
const c2 = String(
|
|
2295
|
-
e2.stack.push(
|
|
2404
|
+
const c2 = String(s2), p2 = String(r2), a2 = o2.indexOf(c2), i2 = a2 === -1 ? o2 : o2.substring(0, a2) + p2 + o2.substring(a2 + c2.length);
|
|
2405
|
+
e2.stack.push(i2);
|
|
2296
2406
|
}
|
|
2297
2407
|
},
|
|
2298
|
-
[
|
|
2408
|
+
[i$2.STRING_REPLACE_ALL]: {
|
|
2299
2409
|
stackIn: 3,
|
|
2300
2410
|
stackOut: 1,
|
|
2301
2411
|
execute: (e2, t$1) => {
|
|
2302
|
-
const r2 = e2.stack.pop(),
|
|
2303
|
-
if (!t(
|
|
2412
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
2413
|
+
if (!t(o2))
|
|
2304
2414
|
return {
|
|
2305
2415
|
type: "RuntimeError",
|
|
2306
2416
|
message: "STRING_REPLACE_ALL requires a string",
|
|
2307
2417
|
pc: e2.pc,
|
|
2308
2418
|
opcode: t$1.op
|
|
2309
2419
|
};
|
|
2310
|
-
const c2 = String(
|
|
2420
|
+
const c2 = String(s2), p2 = String(r2), a2 = o2.split(c2).join(p2);
|
|
2311
2421
|
e2.stack.push(a2);
|
|
2312
2422
|
}
|
|
2313
2423
|
},
|
|
2314
|
-
[
|
|
2424
|
+
[i$2.STRING_LAST_INDEX_OF]: {
|
|
2315
2425
|
stackIn: 2,
|
|
2316
2426
|
stackOut: 1,
|
|
2317
2427
|
execute: (e2, t$1) => {
|
|
2318
|
-
const r2 = e2.stack.pop(),
|
|
2319
|
-
if (!t(
|
|
2428
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2429
|
+
if (!t(s2))
|
|
2320
2430
|
return {
|
|
2321
2431
|
type: "RuntimeError",
|
|
2322
2432
|
message: "STRING_LAST_INDEX_OF requires a string",
|
|
2323
2433
|
pc: e2.pc,
|
|
2324
2434
|
opcode: t$1.op
|
|
2325
2435
|
};
|
|
2326
|
-
const
|
|
2327
|
-
e2.stack.push(
|
|
2436
|
+
const o2 = String(r2);
|
|
2437
|
+
e2.stack.push(s2.lastIndexOf(o2));
|
|
2328
2438
|
}
|
|
2329
2439
|
},
|
|
2330
|
-
[
|
|
2440
|
+
[i$2.STRING_REPEAT]: {
|
|
2331
2441
|
stackIn: 2,
|
|
2332
2442
|
stackOut: 1,
|
|
2333
2443
|
execute: (e2, t$1) => {
|
|
2334
|
-
const r2 = e2.stack.pop(),
|
|
2335
|
-
if (!t(
|
|
2444
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2445
|
+
if (!t(s2))
|
|
2336
2446
|
return {
|
|
2337
2447
|
type: "RuntimeError",
|
|
2338
2448
|
message: "STRING_REPEAT requires a string",
|
|
@@ -2346,23 +2456,23 @@ const ae = {
|
|
|
2346
2456
|
pc: e2.pc,
|
|
2347
2457
|
opcode: t$1.op
|
|
2348
2458
|
};
|
|
2349
|
-
e2.stack.push(
|
|
2459
|
+
e2.stack.push(s2.repeat(Math.floor(r2)));
|
|
2350
2460
|
}
|
|
2351
2461
|
},
|
|
2352
|
-
[
|
|
2462
|
+
[i$2.STRING_PAD_START]: {
|
|
2353
2463
|
stackIn: 3,
|
|
2354
2464
|
// string, targetLength, padString
|
|
2355
2465
|
stackOut: 1,
|
|
2356
2466
|
execute: (e2, t$1) => {
|
|
2357
|
-
const r2 = e2.stack.pop(),
|
|
2358
|
-
if (!t(
|
|
2467
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
2468
|
+
if (!t(o2))
|
|
2359
2469
|
return {
|
|
2360
2470
|
type: "RuntimeError",
|
|
2361
2471
|
message: "STRING_PAD_START requires a string",
|
|
2362
2472
|
pc: e2.pc,
|
|
2363
2473
|
opcode: t$1.op
|
|
2364
2474
|
};
|
|
2365
|
-
if (!i$1(
|
|
2475
|
+
if (!i$1(s2))
|
|
2366
2476
|
return {
|
|
2367
2477
|
type: "RuntimeError",
|
|
2368
2478
|
message: "STRING_PAD_START requires number for length",
|
|
@@ -2370,22 +2480,22 @@ const ae = {
|
|
|
2370
2480
|
opcode: t$1.op
|
|
2371
2481
|
};
|
|
2372
2482
|
const c2 = t(r2) ? r2 : String(r2);
|
|
2373
|
-
e2.stack.push(
|
|
2483
|
+
e2.stack.push(o2.padStart(s2, c2 || " "));
|
|
2374
2484
|
}
|
|
2375
2485
|
},
|
|
2376
|
-
[
|
|
2486
|
+
[i$2.STRING_PAD_END]: {
|
|
2377
2487
|
stackIn: 3,
|
|
2378
2488
|
stackOut: 1,
|
|
2379
2489
|
execute: (e2, t$1) => {
|
|
2380
|
-
const r2 = e2.stack.pop(),
|
|
2381
|
-
if (!t(
|
|
2490
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
2491
|
+
if (!t(o2))
|
|
2382
2492
|
return {
|
|
2383
2493
|
type: "RuntimeError",
|
|
2384
2494
|
message: "STRING_PAD_END requires a string",
|
|
2385
2495
|
pc: e2.pc,
|
|
2386
2496
|
opcode: t$1.op
|
|
2387
2497
|
};
|
|
2388
|
-
if (!i$1(
|
|
2498
|
+
if (!i$1(s2))
|
|
2389
2499
|
return {
|
|
2390
2500
|
type: "RuntimeError",
|
|
2391
2501
|
message: "STRING_PAD_END requires number for length",
|
|
@@ -2393,58 +2503,58 @@ const ae = {
|
|
|
2393
2503
|
opcode: t$1.op
|
|
2394
2504
|
};
|
|
2395
2505
|
const c2 = t(r2) ? r2 : String(r2);
|
|
2396
|
-
e2.stack.push(
|
|
2506
|
+
e2.stack.push(o2.padEnd(s2, c2 || " "));
|
|
2397
2507
|
}
|
|
2398
2508
|
}
|
|
2399
2509
|
};
|
|
2400
|
-
function
|
|
2510
|
+
function j(e2, t2) {
|
|
2401
2511
|
if (u$1(e2)) {
|
|
2402
2512
|
const r2 = t2.get(e2.id);
|
|
2403
|
-
return r2 && r2.type === "array" ? r2.data.elements.map((
|
|
2513
|
+
return r2 && r2.type === "array" ? r2.data.elements.map((o2) => j(o2, t2)) : null;
|
|
2404
2514
|
}
|
|
2405
|
-
if (b
|
|
2515
|
+
if (b(e2)) {
|
|
2406
2516
|
const r2 = t2.get(e2.id);
|
|
2407
2517
|
if (r2 && r2.type === "object") {
|
|
2408
|
-
const
|
|
2409
|
-
for (const [c2, p2] of Object.entries(
|
|
2410
|
-
|
|
2411
|
-
return
|
|
2518
|
+
const s2 = r2.data, o2 = {};
|
|
2519
|
+
for (const [c2, p2] of Object.entries(s2.properties))
|
|
2520
|
+
o2[c2] = j(p2, t2);
|
|
2521
|
+
return o2;
|
|
2412
2522
|
}
|
|
2413
2523
|
return null;
|
|
2414
2524
|
}
|
|
2415
2525
|
if (o(e2))
|
|
2416
|
-
return e2.elements.map((r2) =>
|
|
2526
|
+
return e2.elements.map((r2) => j(r2, t2));
|
|
2417
2527
|
if (y(e2)) {
|
|
2418
2528
|
const r2 = {};
|
|
2419
|
-
for (const [
|
|
2420
|
-
r2[
|
|
2529
|
+
for (const [s2, o2] of Object.entries(e2.properties))
|
|
2530
|
+
r2[s2] = j(o2, t2);
|
|
2421
2531
|
return r2;
|
|
2422
2532
|
}
|
|
2423
2533
|
if (!c(e2))
|
|
2424
2534
|
return e2;
|
|
2425
2535
|
}
|
|
2426
|
-
const
|
|
2427
|
-
[
|
|
2536
|
+
const le = {
|
|
2537
|
+
[i$2.OBJECT_CREATE]: {
|
|
2428
2538
|
stackIn: 0,
|
|
2429
2539
|
stackOut: 1,
|
|
2430
2540
|
execute: (e2) => {
|
|
2431
|
-
const t2 = M
|
|
2541
|
+
const t2 = M(), r2 = e2.heap.allocate("object", t2);
|
|
2432
2542
|
e2.stack.push(r2);
|
|
2433
2543
|
}
|
|
2434
2544
|
},
|
|
2435
|
-
[
|
|
2545
|
+
[i$2.PROPERTY_SET]: {
|
|
2436
2546
|
stackIn: 3,
|
|
2437
2547
|
stackOut: 1,
|
|
2438
2548
|
execute: (e2, t2) => {
|
|
2439
|
-
const r2 =
|
|
2549
|
+
const r2 = d(e2, t2.op);
|
|
2440
2550
|
if (f2(r2)) return r2;
|
|
2441
|
-
const
|
|
2442
|
-
if (f2(o2)) return o2;
|
|
2443
|
-
const s2 = l(e2, t2.op);
|
|
2551
|
+
const s2 = d(e2, t2.op);
|
|
2444
2552
|
if (f2(s2)) return s2;
|
|
2553
|
+
const o2 = d(e2, t2.op);
|
|
2554
|
+
if (f2(o2)) return o2;
|
|
2445
2555
|
let c2;
|
|
2446
|
-
if (b
|
|
2447
|
-
const a2 = e2.heap.get(
|
|
2556
|
+
if (b(o2)) {
|
|
2557
|
+
const a2 = e2.heap.get(o2.id);
|
|
2448
2558
|
if (!a2 || a2.type !== "object")
|
|
2449
2559
|
return {
|
|
2450
2560
|
type: "RuntimeError",
|
|
@@ -2453,37 +2563,37 @@ const de = {
|
|
|
2453
2563
|
opcode: t2.op
|
|
2454
2564
|
};
|
|
2455
2565
|
c2 = a2.data;
|
|
2456
|
-
} else if (y(
|
|
2457
|
-
c2 =
|
|
2566
|
+
} else if (y(o2))
|
|
2567
|
+
c2 = o2;
|
|
2458
2568
|
else
|
|
2459
2569
|
return {
|
|
2460
2570
|
type: "RuntimeError",
|
|
2461
|
-
message: `Cannot set property '${
|
|
2571
|
+
message: `Cannot set property '${s2}' on ${d$2(o2)}`,
|
|
2462
2572
|
pc: e2.pc,
|
|
2463
2573
|
opcode: t2.op
|
|
2464
2574
|
};
|
|
2465
|
-
const p2 = p$1(
|
|
2466
|
-
c2.properties[p2] = r2, e2.stack.push(
|
|
2575
|
+
const p2 = p$1(s2);
|
|
2576
|
+
c2.properties[p2] = r2, e2.stack.push(o2);
|
|
2467
2577
|
}
|
|
2468
2578
|
},
|
|
2469
|
-
[
|
|
2579
|
+
[i$2.PROPERTY_GET]: {
|
|
2470
2580
|
stackIn: 2,
|
|
2471
2581
|
stackOut: 1,
|
|
2472
2582
|
execute: (e2, t2) => {
|
|
2473
|
-
const r2 =
|
|
2583
|
+
const r2 = d(e2, t2.op);
|
|
2474
2584
|
if (f2(r2)) return r2;
|
|
2475
|
-
const
|
|
2476
|
-
if (f2(
|
|
2477
|
-
if (f$2(
|
|
2585
|
+
const s2 = d(e2, t2.op);
|
|
2586
|
+
if (f2(s2)) return s2;
|
|
2587
|
+
if (f$2(s2) || c(s2))
|
|
2478
2588
|
return {
|
|
2479
2589
|
type: "RuntimeError",
|
|
2480
|
-
message: `Cannot read property '${r2}' of ${d$
|
|
2590
|
+
message: `Cannot read property '${r2}' of ${d$2(s2)}`,
|
|
2481
2591
|
pc: e2.pc,
|
|
2482
2592
|
opcode: t2.op
|
|
2483
2593
|
};
|
|
2484
|
-
let
|
|
2485
|
-
if (b
|
|
2486
|
-
const p2 = e2.heap.get(
|
|
2594
|
+
let o2 = null;
|
|
2595
|
+
if (b(s2)) {
|
|
2596
|
+
const p2 = e2.heap.get(s2.id);
|
|
2487
2597
|
if (!p2 || p2.type !== "object")
|
|
2488
2598
|
return {
|
|
2489
2599
|
type: "RuntimeError",
|
|
@@ -2491,36 +2601,110 @@ const de = {
|
|
|
2491
2601
|
pc: e2.pc,
|
|
2492
2602
|
opcode: t2.op
|
|
2493
2603
|
};
|
|
2494
|
-
|
|
2495
|
-
} else if (y(
|
|
2496
|
-
|
|
2604
|
+
o2 = p2.data;
|
|
2605
|
+
} else if (y(s2))
|
|
2606
|
+
o2 = s2;
|
|
2497
2607
|
else {
|
|
2498
|
-
e2.stack.push(C());
|
|
2608
|
+
e2.stack.push(C$1());
|
|
2499
2609
|
return;
|
|
2500
2610
|
}
|
|
2501
|
-
const c$1 =
|
|
2502
|
-
e2.stack.push(c$1 ?? C());
|
|
2611
|
+
const c$1 = o2.properties[p$1(r2)];
|
|
2612
|
+
e2.stack.push(c$1 ?? C$1());
|
|
2503
2613
|
}
|
|
2504
2614
|
},
|
|
2505
|
-
[
|
|
2615
|
+
[i$2.JSON_STRINGIFY]: {
|
|
2506
2616
|
stackIn: 1,
|
|
2507
2617
|
stackOut: 1,
|
|
2508
2618
|
execute: (e2, t2) => {
|
|
2509
|
-
const r2 =
|
|
2619
|
+
const r2 = d(e2, t2.op);
|
|
2620
|
+
if (f2(r2)) return r2;
|
|
2621
|
+
const s2 = j(r2, e2.heap);
|
|
2622
|
+
e2.stack.push(JSON.stringify(s2));
|
|
2623
|
+
}
|
|
2624
|
+
},
|
|
2625
|
+
[i$2.OBJECT_KEYS]: {
|
|
2626
|
+
stackIn: 1,
|
|
2627
|
+
stackOut: 1,
|
|
2628
|
+
execute: (e2, t2) => {
|
|
2629
|
+
const r2 = d(e2, t2.op);
|
|
2630
|
+
if (f2(r2)) return r2;
|
|
2631
|
+
if (b(r2)) {
|
|
2632
|
+
const s2 = e2.heap.get(r2.id);
|
|
2633
|
+
if (s2 && s2.type === "object") {
|
|
2634
|
+
const o2 = s2.data, c2 = Object.keys(o2.properties), p2 = e2.heap.allocate("array", { type: "array", elements: c2 });
|
|
2635
|
+
e2.stack.push(p2);
|
|
2636
|
+
} else
|
|
2637
|
+
e2.stack.push(null);
|
|
2638
|
+
} else if (y(r2)) {
|
|
2639
|
+
const s2 = Object.keys(r2.properties), o2 = e2.heap.allocate("array", { type: "array", elements: s2 });
|
|
2640
|
+
e2.stack.push(o2);
|
|
2641
|
+
} else
|
|
2642
|
+
e2.stack.push(null);
|
|
2643
|
+
}
|
|
2644
|
+
}
|
|
2645
|
+
}, de = {
|
|
2646
|
+
[i$2.OBJECT_ITER_START]: {
|
|
2647
|
+
stackIn: 1,
|
|
2648
|
+
stackOut: 0,
|
|
2649
|
+
execute: (e2, t2) => {
|
|
2650
|
+
const r2 = d(e2, t2.op);
|
|
2510
2651
|
if (f2(r2)) return r2;
|
|
2511
|
-
|
|
2512
|
-
|
|
2652
|
+
if (b(r2)) {
|
|
2653
|
+
const s2 = e2.heap.get(r2.id);
|
|
2654
|
+
if (s2 && s2.type === "object") {
|
|
2655
|
+
const o2 = s2.data, c2 = Object.keys(o2.properties);
|
|
2656
|
+
e2.iterators.push({
|
|
2657
|
+
array: null,
|
|
2658
|
+
keys: c2,
|
|
2659
|
+
index: 0,
|
|
2660
|
+
length: c2.length
|
|
2661
|
+
});
|
|
2662
|
+
} else
|
|
2663
|
+
e2.iterators.push({
|
|
2664
|
+
array: null,
|
|
2665
|
+
keys: [],
|
|
2666
|
+
index: 0,
|
|
2667
|
+
length: 0
|
|
2668
|
+
});
|
|
2669
|
+
} else if (y(r2)) {
|
|
2670
|
+
const s2 = Object.keys(r2.properties);
|
|
2671
|
+
e2.iterators.push({
|
|
2672
|
+
array: null,
|
|
2673
|
+
keys: s2,
|
|
2674
|
+
index: 0,
|
|
2675
|
+
length: s2.length
|
|
2676
|
+
});
|
|
2677
|
+
} else
|
|
2678
|
+
e2.iterators.push({
|
|
2679
|
+
array: null,
|
|
2680
|
+
keys: [],
|
|
2681
|
+
index: 0,
|
|
2682
|
+
length: 0
|
|
2683
|
+
});
|
|
2684
|
+
}
|
|
2685
|
+
},
|
|
2686
|
+
[i$2.OBJECT_ITER_NEXT]: {
|
|
2687
|
+
stackIn: 0,
|
|
2688
|
+
stackOut: 2,
|
|
2689
|
+
// Push key and hasNext
|
|
2690
|
+
execute: (e2, t2) => {
|
|
2691
|
+
const r2 = e2.iterators[e2.iterators.length - 1];
|
|
2692
|
+
if (r2 && r2.index < r2.length && r2.keys) {
|
|
2693
|
+
const s2 = r2.keys[r2.index];
|
|
2694
|
+
e2.stack.push(s2), e2.stack.push(true), r2.index++;
|
|
2695
|
+
} else
|
|
2696
|
+
e2.stack.push(null), e2.stack.push(false);
|
|
2513
2697
|
}
|
|
2514
2698
|
}
|
|
2515
|
-
},
|
|
2516
|
-
[
|
|
2699
|
+
}, fe = {
|
|
2700
|
+
[i$2.GET]: {
|
|
2517
2701
|
stackIn: 2,
|
|
2518
2702
|
stackOut: 1,
|
|
2519
2703
|
execute: (e2, t$1) => {
|
|
2520
|
-
var
|
|
2521
|
-
const r2 = e2.stack.pop(),
|
|
2522
|
-
if (u$1(
|
|
2523
|
-
const c2 = e2.heap.get(
|
|
2704
|
+
var o2;
|
|
2705
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
2706
|
+
if (u$1(s2)) {
|
|
2707
|
+
const c2 = e2.heap.get(s2.id);
|
|
2524
2708
|
if (!c2 || c2.type !== "array")
|
|
2525
2709
|
return {
|
|
2526
2710
|
type: "RuntimeError",
|
|
@@ -2533,11 +2717,11 @@ const de = {
|
|
|
2533
2717
|
if (i$1(r2))
|
|
2534
2718
|
a2 = r2;
|
|
2535
2719
|
else if (t(r2)) {
|
|
2536
|
-
const
|
|
2537
|
-
if (!isNaN(
|
|
2538
|
-
a2 =
|
|
2720
|
+
const u2 = parseInt(r2, 10);
|
|
2721
|
+
if (!isNaN(u2) && u2.toString() === r2 && u2 >= 0)
|
|
2722
|
+
a2 = u2;
|
|
2539
2723
|
else {
|
|
2540
|
-
const y2 = ((
|
|
2724
|
+
const y2 = ((o2 = p2.properties) == null ? void 0 : o2[r2]) ?? C$1();
|
|
2541
2725
|
e2.stack.push(y2);
|
|
2542
2726
|
return;
|
|
2543
2727
|
}
|
|
@@ -2548,11 +2732,11 @@ const de = {
|
|
|
2548
2732
|
pc: e2.pc,
|
|
2549
2733
|
opcode: t$1.op
|
|
2550
2734
|
};
|
|
2551
|
-
const
|
|
2552
|
-
e2.stack.push(
|
|
2735
|
+
const i2 = p2.elements[a2] ?? C$1();
|
|
2736
|
+
e2.stack.push(i2);
|
|
2553
2737
|
return;
|
|
2554
|
-
} else if (b
|
|
2555
|
-
const c2 = e2.heap.get(
|
|
2738
|
+
} else if (b(s2)) {
|
|
2739
|
+
const c2 = e2.heap.get(s2.id);
|
|
2556
2740
|
if (!c2 || c2.type !== "object")
|
|
2557
2741
|
return {
|
|
2558
2742
|
type: "RuntimeError",
|
|
@@ -2560,10 +2744,10 @@ const de = {
|
|
|
2560
2744
|
pc: e2.pc,
|
|
2561
2745
|
opcode: t$1.op
|
|
2562
2746
|
};
|
|
2563
|
-
const p2 = c2.data, a2 = p$1(r2),
|
|
2564
|
-
e2.stack.push(
|
|
2747
|
+
const p2 = c2.data, a2 = p$1(r2), i2 = p2.properties[a2] ?? C$1();
|
|
2748
|
+
e2.stack.push(i2);
|
|
2565
2749
|
return;
|
|
2566
|
-
} else if (t(
|
|
2750
|
+
} else if (t(s2)) {
|
|
2567
2751
|
let c2;
|
|
2568
2752
|
if (i$1(r2))
|
|
2569
2753
|
c2 = r2;
|
|
@@ -2571,7 +2755,7 @@ const de = {
|
|
|
2571
2755
|
const p2 = parseInt(r2, 10);
|
|
2572
2756
|
!isNaN(p2) && p2.toString() === r2 && (c2 = p2);
|
|
2573
2757
|
}
|
|
2574
|
-
c2 !== void 0 && c2 >= 0 && c2 <
|
|
2758
|
+
c2 !== void 0 && c2 >= 0 && c2 < s2.length ? e2.stack.push(s2[c2]) : e2.stack.push(C$1());
|
|
2575
2759
|
return;
|
|
2576
2760
|
} else
|
|
2577
2761
|
return {
|
|
@@ -2582,13 +2766,13 @@ const de = {
|
|
|
2582
2766
|
};
|
|
2583
2767
|
}
|
|
2584
2768
|
},
|
|
2585
|
-
[
|
|
2769
|
+
[i$2.SET]: {
|
|
2586
2770
|
stackIn: 3,
|
|
2587
2771
|
stackOut: 1,
|
|
2588
2772
|
execute: (e2, t$1) => {
|
|
2589
|
-
const r2 = e2.stack.pop(),
|
|
2590
|
-
if (u$1(
|
|
2591
|
-
const c2 = e2.heap.get(
|
|
2773
|
+
const r2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
2774
|
+
if (u$1(o2)) {
|
|
2775
|
+
const c2 = e2.heap.get(o2.id);
|
|
2592
2776
|
if (!c2 || c2.type !== "array")
|
|
2593
2777
|
return {
|
|
2594
2778
|
type: "RuntimeError",
|
|
@@ -2598,14 +2782,14 @@ const de = {
|
|
|
2598
2782
|
};
|
|
2599
2783
|
const p2 = c2.data;
|
|
2600
2784
|
let a2;
|
|
2601
|
-
if (i$1(
|
|
2602
|
-
a2 =
|
|
2603
|
-
else if (t(
|
|
2604
|
-
const
|
|
2605
|
-
if (!isNaN(
|
|
2606
|
-
a2 =
|
|
2785
|
+
if (i$1(s2))
|
|
2786
|
+
a2 = s2;
|
|
2787
|
+
else if (t(s2)) {
|
|
2788
|
+
const u2 = parseInt(s2, 10);
|
|
2789
|
+
if (!isNaN(u2) && u2.toString() === s2 && u2 >= 0)
|
|
2790
|
+
a2 = u2;
|
|
2607
2791
|
else {
|
|
2608
|
-
p2.properties || (p2.properties = {}), p2.properties[
|
|
2792
|
+
p2.properties || (p2.properties = {}), p2.properties[s2] = r2, e2.stack.push(o2);
|
|
2609
2793
|
return;
|
|
2610
2794
|
}
|
|
2611
2795
|
} else
|
|
@@ -2615,18 +2799,18 @@ const de = {
|
|
|
2615
2799
|
pc: e2.pc,
|
|
2616
2800
|
opcode: t$1.op
|
|
2617
2801
|
};
|
|
2618
|
-
const
|
|
2619
|
-
if (
|
|
2802
|
+
const i2 = Math.floor(a2);
|
|
2803
|
+
if (i2 < 0)
|
|
2620
2804
|
return {
|
|
2621
2805
|
type: "RuntimeError",
|
|
2622
2806
|
message: "SET: Negative index not allowed",
|
|
2623
2807
|
pc: e2.pc,
|
|
2624
2808
|
opcode: t$1.op
|
|
2625
2809
|
};
|
|
2626
|
-
p2.elements[
|
|
2810
|
+
p2.elements[i2] = r2, e2.stack.push(o2);
|
|
2627
2811
|
return;
|
|
2628
|
-
} else if (b
|
|
2629
|
-
const c2 = e2.heap.get(
|
|
2812
|
+
} else if (b(o2)) {
|
|
2813
|
+
const c2 = e2.heap.get(o2.id);
|
|
2630
2814
|
if (!c2 || c2.type !== "object")
|
|
2631
2815
|
return {
|
|
2632
2816
|
type: "RuntimeError",
|
|
@@ -2634,8 +2818,8 @@ const de = {
|
|
|
2634
2818
|
pc: e2.pc,
|
|
2635
2819
|
opcode: t$1.op
|
|
2636
2820
|
};
|
|
2637
|
-
const p2 = c2.data, a2 = p$1(
|
|
2638
|
-
p2.properties[a2] = r2, e2.stack.push(
|
|
2821
|
+
const p2 = c2.data, a2 = p$1(s2);
|
|
2822
|
+
p2.properties[a2] = r2, e2.stack.push(o2);
|
|
2639
2823
|
return;
|
|
2640
2824
|
} else
|
|
2641
2825
|
return {
|
|
@@ -2646,40 +2830,80 @@ const de = {
|
|
|
2646
2830
|
};
|
|
2647
2831
|
}
|
|
2648
2832
|
}
|
|
2833
|
+
}, ke = {
|
|
2834
|
+
stackIn: 0,
|
|
2835
|
+
// Consumes no stack items
|
|
2836
|
+
stackOut: 1,
|
|
2837
|
+
// Produces one stack item (heap reference)
|
|
2838
|
+
execute: (e2, t2) => {
|
|
2839
|
+
const r2 = t2.arg;
|
|
2840
|
+
if (!r2 || typeof r2.pattern != "string" || typeof r2.flags != "string")
|
|
2841
|
+
return {
|
|
2842
|
+
type: "TypeError",
|
|
2843
|
+
message: "LOAD_REGEX instruction requires pattern and flags properties",
|
|
2844
|
+
pc: e2.pc,
|
|
2845
|
+
opcode: t2.op
|
|
2846
|
+
};
|
|
2847
|
+
try {
|
|
2848
|
+
const s2 = new RegExp(r2.pattern, r2.flags), o2 = {
|
|
2849
|
+
type: "object",
|
|
2850
|
+
properties: {
|
|
2851
|
+
source: s2.source,
|
|
2852
|
+
flags: s2.flags,
|
|
2853
|
+
global: s2.global,
|
|
2854
|
+
ignoreCase: s2.ignoreCase,
|
|
2855
|
+
multiline: s2.multiline
|
|
2856
|
+
}
|
|
2857
|
+
}, c2 = e2.heap.allocate("object", o2);
|
|
2858
|
+
e2.stack.push(c2);
|
|
2859
|
+
return;
|
|
2860
|
+
} catch (s2) {
|
|
2861
|
+
return {
|
|
2862
|
+
type: "SyntaxError",
|
|
2863
|
+
message: `Invalid regular expression: ${s2.message}`,
|
|
2864
|
+
pc: e2.pc,
|
|
2865
|
+
opcode: t2.op
|
|
2866
|
+
};
|
|
2867
|
+
}
|
|
2868
|
+
}
|
|
2869
|
+
}, me = {
|
|
2870
|
+
[i$2.LOAD_REGEX]: ke
|
|
2649
2871
|
}, F = {
|
|
2650
2872
|
...Z,
|
|
2651
2873
|
...ee,
|
|
2652
2874
|
...re,
|
|
2653
2875
|
...te,
|
|
2654
|
-
...oe,
|
|
2655
2876
|
...se,
|
|
2877
|
+
...oe,
|
|
2656
2878
|
...ce,
|
|
2657
2879
|
...ne,
|
|
2658
2880
|
...pe,
|
|
2659
2881
|
...ae,
|
|
2660
|
-
...ue,
|
|
2661
2882
|
...ie,
|
|
2883
|
+
...ue,
|
|
2884
|
+
...le,
|
|
2662
2885
|
...de,
|
|
2663
|
-
...
|
|
2886
|
+
...fe,
|
|
2887
|
+
...me
|
|
2664
2888
|
};
|
|
2665
|
-
function
|
|
2889
|
+
function w() {
|
|
2666
2890
|
const e2 = /* @__PURE__ */ new Map();
|
|
2667
2891
|
let t2 = 1;
|
|
2668
2892
|
return {
|
|
2669
2893
|
objects: e2,
|
|
2670
2894
|
nextId: t2,
|
|
2671
|
-
allocate(r2,
|
|
2672
|
-
const
|
|
2673
|
-
return e2.set(
|
|
2895
|
+
allocate(r2, s2) {
|
|
2896
|
+
const o2 = t2++, c2 = { id: o2, type: r2, data: s2 };
|
|
2897
|
+
return e2.set(o2, c2), r2 === "array" ? { type: "array-ref", id: o2 } : { type: "object-ref", id: o2 };
|
|
2674
2898
|
},
|
|
2675
2899
|
get(r2) {
|
|
2676
|
-
const
|
|
2677
|
-
if (
|
|
2678
|
-
return
|
|
2900
|
+
const s2 = e2.get(r2);
|
|
2901
|
+
if (s2)
|
|
2902
|
+
return s2;
|
|
2679
2903
|
}
|
|
2680
2904
|
};
|
|
2681
2905
|
}
|
|
2682
|
-
class
|
|
2906
|
+
class C {
|
|
2683
2907
|
createInitialState() {
|
|
2684
2908
|
return {
|
|
2685
2909
|
pc: 0,
|
|
@@ -2688,74 +2912,74 @@ class w {
|
|
|
2688
2912
|
status: "running",
|
|
2689
2913
|
output: [],
|
|
2690
2914
|
iterators: [],
|
|
2691
|
-
heap:
|
|
2915
|
+
heap: w()
|
|
2692
2916
|
};
|
|
2693
2917
|
}
|
|
2694
2918
|
executeInstruction(t2, r2) {
|
|
2695
|
-
const
|
|
2696
|
-
if (!
|
|
2919
|
+
const s2 = F[r2.op];
|
|
2920
|
+
if (!s2)
|
|
2697
2921
|
throw new Error(`Unknown opcode: ${r2.op}`);
|
|
2698
|
-
const
|
|
2699
|
-
if (
|
|
2700
|
-
t2.status = "error", t2.error =
|
|
2922
|
+
const o2 = this.validateStack(s2, r2, t2);
|
|
2923
|
+
if (o2) {
|
|
2924
|
+
t2.status = "error", t2.error = o2.message;
|
|
2701
2925
|
return;
|
|
2702
2926
|
}
|
|
2703
|
-
|
|
2927
|
+
s2.execute(t2, r2), t2.pc++;
|
|
2704
2928
|
}
|
|
2705
|
-
validateStack(t2, r2,
|
|
2706
|
-
if (
|
|
2929
|
+
validateStack(t2, r2, s2) {
|
|
2930
|
+
if (s2.stack.length < t2.stackIn)
|
|
2707
2931
|
return {
|
|
2708
2932
|
type: "StackUnderflow",
|
|
2709
|
-
message: `${
|
|
2710
|
-
pc:
|
|
2933
|
+
message: `${i$2[r2.op]}: Stack underflow`,
|
|
2934
|
+
pc: s2.pc,
|
|
2711
2935
|
opcode: r2.op
|
|
2712
2936
|
};
|
|
2713
2937
|
}
|
|
2714
|
-
execute(t2, r2,
|
|
2715
|
-
const
|
|
2938
|
+
execute(t2, r2, s2) {
|
|
2939
|
+
const o2 = {
|
|
2716
2940
|
pc: (r2 == null ? void 0 : r2.pc) ?? 0,
|
|
2717
2941
|
stack: (r2 == null ? void 0 : r2.stack) ?? [],
|
|
2718
2942
|
variables: (r2 == null ? void 0 : r2.variables) ?? /* @__PURE__ */ new Map(),
|
|
2719
2943
|
status: "running",
|
|
2720
2944
|
output: (r2 == null ? void 0 : r2.output) ?? [],
|
|
2721
2945
|
iterators: (r2 == null ? void 0 : r2.iterators) ?? [],
|
|
2722
|
-
fileSystem:
|
|
2723
|
-
heap: (r2 == null ? void 0 : r2.heap) ??
|
|
2946
|
+
fileSystem: s2,
|
|
2947
|
+
heap: (r2 == null ? void 0 : r2.heap) ?? w(),
|
|
2724
2948
|
...r2
|
|
2725
2949
|
};
|
|
2726
|
-
for (;
|
|
2727
|
-
const c2 = t2[
|
|
2950
|
+
for (; o2.status === "running" && o2.pc < t2.length; ) {
|
|
2951
|
+
const c2 = t2[o2.pc], p2 = F[c2.op];
|
|
2728
2952
|
if (p2) {
|
|
2729
|
-
const a2 = this.validateStack(p2, c2,
|
|
2953
|
+
const a2 = this.validateStack(p2, c2, o2);
|
|
2730
2954
|
if (a2) {
|
|
2731
|
-
|
|
2955
|
+
o2.status = "error", o2.error = a2.message;
|
|
2732
2956
|
break;
|
|
2733
2957
|
}
|
|
2734
|
-
if ((c2.op ===
|
|
2735
|
-
|
|
2736
|
-
const
|
|
2737
|
-
|
|
2958
|
+
if ((c2.op === i$2.JUMP || c2.op === i$2.JUMP_IF_FALSE || c2.op === i$2.JUMP_IF || c2.op === i$2.JUMP_IF_TRUE || c2.op === i$2.BREAK || c2.op === i$2.CONTINUE) && c2.arg !== void 0 && c2.arg >= t2.length) {
|
|
2959
|
+
o2.status = "error";
|
|
2960
|
+
const u2 = c2.op === i$2.JUMP || c2.op === i$2.JUMP_IF_FALSE || c2.op === i$2.JUMP_IF || c2.op === i$2.JUMP_IF_TRUE ? "jump" : c2.op === i$2.BREAK ? "break" : "continue";
|
|
2961
|
+
o2.error = `Invalid ${u2} target: ${c2.arg}`;
|
|
2738
2962
|
break;
|
|
2739
2963
|
}
|
|
2740
|
-
const
|
|
2741
|
-
if (
|
|
2742
|
-
const
|
|
2743
|
-
if (
|
|
2744
|
-
|
|
2964
|
+
const i2 = p2.execute(o2, c2);
|
|
2965
|
+
if (i2) {
|
|
2966
|
+
const u2 = o2.pc + 1;
|
|
2967
|
+
if (u2 < t2.length && t2[u2].op === i$2.CC) {
|
|
2968
|
+
o2.ccPrompt = `ERROR: ${i2.message}. How should I proceed?`, o2.status = "waiting_cc", o2.pc = u2;
|
|
2745
2969
|
break;
|
|
2746
2970
|
}
|
|
2747
|
-
|
|
2971
|
+
o2.status = "error", o2.error = i2.message;
|
|
2748
2972
|
break;
|
|
2749
2973
|
}
|
|
2750
|
-
p2.controlsPC ||
|
|
2974
|
+
p2.controlsPC || o2.pc++;
|
|
2751
2975
|
continue;
|
|
2752
2976
|
}
|
|
2753
|
-
|
|
2977
|
+
o2.status = "error", o2.error = `Unknown opcode: ${i$2[c2.op]}`;
|
|
2754
2978
|
break;
|
|
2755
2979
|
}
|
|
2756
|
-
return
|
|
2980
|
+
return o2;
|
|
2757
2981
|
}
|
|
2758
|
-
resume(t2, r2,
|
|
2982
|
+
resume(t2, r2, s2, o2) {
|
|
2759
2983
|
if (t2.status !== "waiting_cc")
|
|
2760
2984
|
throw new Error("Cannot resume: VM not waiting for CC");
|
|
2761
2985
|
const c2 = {
|
|
@@ -2765,47 +2989,47 @@ class w {
|
|
|
2765
2989
|
ccPrompt: void 0,
|
|
2766
2990
|
pc: t2.pc + 1
|
|
2767
2991
|
};
|
|
2768
|
-
return this.execute(
|
|
2992
|
+
return this.execute(s2, c2, o2 || t2.fileSystem);
|
|
2769
2993
|
}
|
|
2770
2994
|
}
|
|
2771
|
-
class
|
|
2995
|
+
class V {
|
|
2772
2996
|
constructor() {
|
|
2773
|
-
|
|
2997
|
+
_(this, "sandboxPaths", []);
|
|
2774
2998
|
const t2 = process.env.CVM_SANDBOX_PATHS, r2 = process.env.CVM_SANDBOX_ROOT;
|
|
2775
|
-
t2 ? this.sandboxPaths = t2.split(",").map((
|
|
2999
|
+
t2 ? this.sandboxPaths = t2.split(",").map((s2) => r__namespace.resolve(s2.trim())) : r2 && (this.sandboxPaths = [r__namespace.resolve(r2)]);
|
|
2776
3000
|
}
|
|
2777
3001
|
isPathAllowed(t2) {
|
|
2778
3002
|
const r2 = r__namespace.resolve(t2);
|
|
2779
3003
|
return r2.includes("..") || this.sandboxPaths.length === 0 ? false : this.sandboxPaths.some(
|
|
2780
|
-
(
|
|
3004
|
+
(s2) => r2.startsWith(s2)
|
|
2781
3005
|
);
|
|
2782
3006
|
}
|
|
2783
3007
|
listFiles(t2, r2 = {}) {
|
|
2784
|
-
const
|
|
3008
|
+
const s$12 = s();
|
|
2785
3009
|
if (!this.isPathAllowed(t2))
|
|
2786
|
-
return
|
|
3010
|
+
return s$12;
|
|
2787
3011
|
try {
|
|
2788
|
-
const
|
|
2789
|
-
this.listFilesRecursive(
|
|
3012
|
+
const o2 = r__namespace.resolve(t2);
|
|
3013
|
+
this.listFilesRecursive(o2, o2, s$12.elements, r2);
|
|
2790
3014
|
} catch {
|
|
2791
3015
|
}
|
|
2792
|
-
return
|
|
3016
|
+
return s$12;
|
|
2793
3017
|
}
|
|
2794
3018
|
matchesPattern(t2, r2) {
|
|
2795
|
-
let
|
|
2796
|
-
|
|
3019
|
+
let s2 = r2.replace(/\./g, "\\.").replace(/\*\*/g, "__DOUBLESTAR__").replace(/\*/g, "[^/]*").replace(/__DOUBLESTAR__/g, ".*").replace(/\?/g, ".");
|
|
3020
|
+
s2 = "^" + s2 + "$";
|
|
2797
3021
|
try {
|
|
2798
|
-
return new RegExp(
|
|
3022
|
+
return new RegExp(s2).test(t2);
|
|
2799
3023
|
} catch {
|
|
2800
3024
|
return true;
|
|
2801
3025
|
}
|
|
2802
3026
|
}
|
|
2803
|
-
listFilesRecursive(t2, r2,
|
|
3027
|
+
listFilesRecursive(t2, r2, s2, o2, c2 = 0) {
|
|
2804
3028
|
try {
|
|
2805
|
-
const p2 =
|
|
3029
|
+
const p2 = N__namespace.readdirSync(r2, { withFileTypes: true });
|
|
2806
3030
|
for (const a2 of p2) {
|
|
2807
|
-
const
|
|
2808
|
-
a2.isSymbolicLink() ||
|
|
3031
|
+
const i2 = r__namespace.join(r2, a2.name), u2 = r__namespace.relative(t2, i2);
|
|
3032
|
+
a2.isSymbolicLink() || o2.filter && !this.matchesPattern(u2, o2.filter) || (s2.push(i2), a2.isDirectory() && o2.recursive && this.listFilesRecursive(t2, i2, s2, o2, c2 + 1));
|
|
2809
3033
|
}
|
|
2810
3034
|
} catch {
|
|
2811
3035
|
}
|
|
@@ -2814,8 +3038,8 @@ class D {
|
|
|
2814
3038
|
if (!this.isPathAllowed(t2))
|
|
2815
3039
|
return null;
|
|
2816
3040
|
try {
|
|
2817
|
-
const r2 = r__namespace.resolve(t2),
|
|
2818
|
-
return
|
|
3041
|
+
const r2 = r__namespace.resolve(t2), s2 = N__namespace.lstatSync(r2);
|
|
3042
|
+
return s2.isSymbolicLink() || !s2.isFile() ? null : N__namespace.readFileSync(r2, "utf-8");
|
|
2819
3043
|
} catch {
|
|
2820
3044
|
return null;
|
|
2821
3045
|
}
|
|
@@ -2824,29 +3048,29 @@ class D {
|
|
|
2824
3048
|
if (!this.isPathAllowed(t2))
|
|
2825
3049
|
return false;
|
|
2826
3050
|
try {
|
|
2827
|
-
const
|
|
2828
|
-
if (!this.isPathAllowed(
|
|
3051
|
+
const s2 = r__namespace.resolve(t2), o2 = r__namespace.dirname(s2);
|
|
3052
|
+
if (!this.isPathAllowed(o2))
|
|
2829
3053
|
return false;
|
|
2830
3054
|
try {
|
|
2831
|
-
if (
|
|
3055
|
+
if (N__namespace.lstatSync(s2).isSymbolicLink())
|
|
2832
3056
|
return false;
|
|
2833
3057
|
} catch (c2) {
|
|
2834
3058
|
if (c2.code !== "ENOENT")
|
|
2835
3059
|
return false;
|
|
2836
3060
|
}
|
|
2837
|
-
return
|
|
3061
|
+
return N__namespace.mkdirSync(o2, { recursive: true }), N__namespace.writeFileSync(s2, r2, "utf-8"), true;
|
|
2838
3062
|
} catch {
|
|
2839
3063
|
return false;
|
|
2840
3064
|
}
|
|
2841
3065
|
}
|
|
2842
3066
|
}
|
|
2843
|
-
new
|
|
2844
|
-
class
|
|
3067
|
+
new V();
|
|
3068
|
+
class Ie {
|
|
2845
3069
|
constructor(t2, r2) {
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
t2 ? this.storage = t2 : this.storage = E.create(), this.fileSystem = r2 || new
|
|
3070
|
+
_(this, "vms", /* @__PURE__ */ new Map());
|
|
3071
|
+
_(this, "storage");
|
|
3072
|
+
_(this, "fileSystem");
|
|
3073
|
+
t2 ? this.storage = t2 : this.storage = E.create(), this.fileSystem = r2 || new V();
|
|
2850
3074
|
}
|
|
2851
3075
|
/**
|
|
2852
3076
|
* Initialize the VMManager (connect to database)
|
|
@@ -2864,18 +3088,18 @@ class he {
|
|
|
2864
3088
|
* Load and compile a program from source code
|
|
2865
3089
|
*/
|
|
2866
3090
|
async loadProgram(t2, r2) {
|
|
2867
|
-
const
|
|
2868
|
-
if (!
|
|
2869
|
-
throw new Error(`Compilation failed: ${
|
|
2870
|
-
const
|
|
3091
|
+
const s2 = te$1(r2);
|
|
3092
|
+
if (!s2.success)
|
|
3093
|
+
throw new Error(`Compilation failed: ${s2.errors.join(", ")}`);
|
|
3094
|
+
const o2 = {
|
|
2871
3095
|
id: t2,
|
|
2872
3096
|
name: t2,
|
|
2873
3097
|
source: r2,
|
|
2874
|
-
bytecode:
|
|
3098
|
+
bytecode: s2.bytecode,
|
|
2875
3099
|
// VM decides internal format
|
|
2876
3100
|
created: /* @__PURE__ */ new Date()
|
|
2877
3101
|
};
|
|
2878
|
-
await this.storage.saveProgram(
|
|
3102
|
+
await this.storage.saveProgram(o2);
|
|
2879
3103
|
}
|
|
2880
3104
|
/**
|
|
2881
3105
|
* Start execution of a loaded program
|
|
@@ -2883,7 +3107,7 @@ class he {
|
|
|
2883
3107
|
async startExecution(t2, r2) {
|
|
2884
3108
|
if (!await this.storage.getProgram(t2))
|
|
2885
3109
|
throw new Error(`Program not found: ${t2}`);
|
|
2886
|
-
const
|
|
3110
|
+
const o2 = {
|
|
2887
3111
|
id: r2,
|
|
2888
3112
|
programId: t2,
|
|
2889
3113
|
state: "READY",
|
|
@@ -2892,8 +3116,8 @@ class he {
|
|
|
2892
3116
|
variables: {},
|
|
2893
3117
|
created: /* @__PURE__ */ new Date()
|
|
2894
3118
|
};
|
|
2895
|
-
await this.storage.saveExecution(
|
|
2896
|
-
const c2 = new
|
|
3119
|
+
await this.storage.saveExecution(o2);
|
|
3120
|
+
const c2 = new C();
|
|
2897
3121
|
this.vms.set(r2, c2);
|
|
2898
3122
|
}
|
|
2899
3123
|
/**
|
|
@@ -2905,17 +3129,17 @@ class he {
|
|
|
2905
3129
|
if (!r2)
|
|
2906
3130
|
throw new Error(`Execution not found: ${t2}`);
|
|
2907
3131
|
if (r2.state === "READY" || r2.state === "RUNNING") {
|
|
2908
|
-
const
|
|
2909
|
-
if (!
|
|
3132
|
+
const s2 = await this.storage.getProgram(r2.programId);
|
|
3133
|
+
if (!s2)
|
|
2910
3134
|
throw new Error(`Program not found: ${r2.programId}`);
|
|
2911
|
-
let
|
|
2912
|
-
|
|
3135
|
+
let o2 = this.vms.get(t2);
|
|
3136
|
+
o2 || (o2 = new C(), this.vms.set(t2, o2));
|
|
2913
3137
|
const c2 = r2.state === "READY" ? {
|
|
2914
3138
|
pc: 0,
|
|
2915
3139
|
stack: [],
|
|
2916
3140
|
variables: /* @__PURE__ */ new Map(),
|
|
2917
3141
|
output: []
|
|
2918
|
-
} : this.deserializeVMState(r2), p2 =
|
|
3142
|
+
} : this.deserializeVMState(r2), p2 = o2.execute(s2.bytecode, c2, this.fileSystem);
|
|
2919
3143
|
p2.output.length > 0 && await this.storage.appendOutput(t2, p2.output);
|
|
2920
3144
|
const a2 = this.serializeVMState(p2);
|
|
2921
3145
|
if (Object.assign(r2, a2), p2.status === "complete")
|
|
@@ -2956,24 +3180,24 @@ class he {
|
|
|
2956
3180
|
* Report result from cognitive operation and continue execution
|
|
2957
3181
|
*/
|
|
2958
3182
|
async reportCCResult(t2, r2) {
|
|
2959
|
-
const
|
|
2960
|
-
if (!o2)
|
|
2961
|
-
throw new Error(`Execution not found: ${t2}`);
|
|
2962
|
-
const s2 = await this.storage.getProgram(o2.programId);
|
|
3183
|
+
const s2 = await this.storage.getExecution(t2);
|
|
2963
3184
|
if (!s2)
|
|
2964
|
-
throw new Error(`
|
|
3185
|
+
throw new Error(`Execution not found: ${t2}`);
|
|
3186
|
+
const o2 = await this.storage.getProgram(s2.programId);
|
|
3187
|
+
if (!o2)
|
|
3188
|
+
throw new Error(`Program not found: ${s2.programId}`);
|
|
2965
3189
|
let c2 = this.vms.get(t2);
|
|
2966
|
-
c2 || (c2 = new
|
|
3190
|
+
c2 || (c2 = new C(), this.vms.set(t2, c2));
|
|
2967
3191
|
const p2 = {
|
|
2968
|
-
...this.deserializeVMState(
|
|
3192
|
+
...this.deserializeVMState(s2),
|
|
2969
3193
|
status: "waiting_cc",
|
|
2970
3194
|
output: [],
|
|
2971
3195
|
// Start with empty output for resumed execution
|
|
2972
3196
|
ccPrompt: void 0
|
|
2973
|
-
}, a2 = c2.resume(p2, r2,
|
|
3197
|
+
}, a2 = c2.resume(p2, r2, o2.bytecode, this.fileSystem);
|
|
2974
3198
|
a2.output.length > 0 && await this.storage.appendOutput(t2, a2.output);
|
|
2975
|
-
const
|
|
2976
|
-
Object.assign(
|
|
3199
|
+
const i2 = this.serializeVMState(a2);
|
|
3200
|
+
Object.assign(s2, i2), a2.status === "complete" ? (s2.state = "COMPLETED", a2.returnValue !== void 0 && (s2.returnValue = a2.returnValue), this.vms.delete(t2)) : a2.status === "error" ? (s2.state = "ERROR", s2.error = a2.error, this.vms.delete(t2)) : a2.status === "waiting_cc" ? (s2.state = "AWAITING_COGNITIVE_RESULT", s2.ccPrompt = a2.ccPrompt) : s2.state = "RUNNING", await this.storage.saveExecution(s2);
|
|
2977
3201
|
}
|
|
2978
3202
|
/**
|
|
2979
3203
|
* Get current execution status
|
|
@@ -3045,22 +3269,22 @@ class he {
|
|
|
3045
3269
|
* Restart a program (create new execution and set as current)
|
|
3046
3270
|
*/
|
|
3047
3271
|
async restartExecution(t2, r2) {
|
|
3048
|
-
const
|
|
3049
|
-
return await this.startExecution(t2,
|
|
3272
|
+
const s2 = r2 || `${t2}-${Date.now()}`;
|
|
3273
|
+
return await this.startExecution(t2, s2), await this.setCurrentExecutionId(s2), s2;
|
|
3050
3274
|
}
|
|
3051
3275
|
/**
|
|
3052
3276
|
* Serialize heap to storage format
|
|
3053
3277
|
*/
|
|
3054
3278
|
serializeHeap(t2) {
|
|
3055
|
-
const r2 = (
|
|
3056
|
-
return t2.objects.forEach((
|
|
3057
|
-
|
|
3058
|
-
type:
|
|
3279
|
+
const r2 = (o2, c2) => u$1(c2) || b(c2) ? { $ref: c2.id } : c2, s2 = {};
|
|
3280
|
+
return t2.objects.forEach((o2, c2) => {
|
|
3281
|
+
s2[c2] = {
|
|
3282
|
+
type: o2.type,
|
|
3059
3283
|
// Serialize each object's data individually with replacer
|
|
3060
|
-
data: JSON.parse(JSON.stringify(
|
|
3284
|
+
data: JSON.parse(JSON.stringify(o2.data, r2))
|
|
3061
3285
|
};
|
|
3062
3286
|
}), {
|
|
3063
|
-
objects:
|
|
3287
|
+
objects: s2,
|
|
3064
3288
|
nextId: t2.nextId
|
|
3065
3289
|
};
|
|
3066
3290
|
}
|
|
@@ -3068,19 +3292,19 @@ class he {
|
|
|
3068
3292
|
* Deserialize heap from storage format
|
|
3069
3293
|
*/
|
|
3070
3294
|
deserializeHeap(t2) {
|
|
3071
|
-
const r2 =
|
|
3295
|
+
const r2 = w();
|
|
3072
3296
|
r2.nextId = t2.nextId;
|
|
3073
|
-
for (const
|
|
3074
|
-
const
|
|
3075
|
-
r2.objects.set(
|
|
3076
|
-
id:
|
|
3297
|
+
for (const s2 in t2.objects) {
|
|
3298
|
+
const o2 = parseInt(s2, 10), c2 = t2.objects[o2];
|
|
3299
|
+
r2.objects.set(o2, {
|
|
3300
|
+
id: o2,
|
|
3077
3301
|
type: c2.type,
|
|
3078
3302
|
data: c2.data
|
|
3079
3303
|
// Still contains $ref stubs
|
|
3080
3304
|
});
|
|
3081
3305
|
}
|
|
3082
|
-
return r2.objects.forEach((
|
|
3083
|
-
|
|
3306
|
+
return r2.objects.forEach((s2) => {
|
|
3307
|
+
s2.data = this.restoreReferences(s2.data, r2);
|
|
3084
3308
|
}), r2;
|
|
3085
3309
|
}
|
|
3086
3310
|
/**
|
|
@@ -3108,7 +3332,7 @@ class he {
|
|
|
3108
3332
|
pc: t2.pc || 0,
|
|
3109
3333
|
stack: t2.stack || [],
|
|
3110
3334
|
variables: new Map(Object.entries(t2.variables || {})),
|
|
3111
|
-
heap: t2.heap ? this.deserializeHeap(t2.heap) :
|
|
3335
|
+
heap: t2.heap ? this.deserializeHeap(t2.heap) : w(),
|
|
3112
3336
|
iterators: t2.iterators || [],
|
|
3113
3337
|
status: t2.status || "running",
|
|
3114
3338
|
error: t2.error || null,
|
|
@@ -3119,16 +3343,16 @@ class he {
|
|
|
3119
3343
|
}
|
|
3120
3344
|
restoreReferences(t2, r2) {
|
|
3121
3345
|
if (t2 && typeof t2 == "object" && t2.$ref !== void 0) {
|
|
3122
|
-
const
|
|
3123
|
-
return (
|
|
3346
|
+
const s2 = r2.objects.get(t2.$ref);
|
|
3347
|
+
return (s2 == null ? void 0 : s2.type) === "array" ? { type: "array-ref", id: t2.$ref } : (s2 == null ? void 0 : s2.type) === "object" ? { type: "object-ref", id: t2.$ref } : t2;
|
|
3124
3348
|
}
|
|
3125
3349
|
if (Array.isArray(t2))
|
|
3126
|
-
return t2.map((
|
|
3350
|
+
return t2.map((s2) => this.restoreReferences(s2, r2));
|
|
3127
3351
|
if (t2 && typeof t2 == "object") {
|
|
3128
|
-
const
|
|
3129
|
-
for (const
|
|
3130
|
-
o2
|
|
3131
|
-
return
|
|
3352
|
+
const s2 = {};
|
|
3353
|
+
for (const o2 in t2)
|
|
3354
|
+
s2[o2] = this.restoreReferences(t2[o2], r2);
|
|
3355
|
+
return s2;
|
|
3132
3356
|
}
|
|
3133
3357
|
return t2;
|
|
3134
3358
|
}
|
|
@@ -3142,7 +3366,7 @@ class $ {
|
|
|
3142
3366
|
i(this, "transport", null);
|
|
3143
3367
|
i(this, "vmManager");
|
|
3144
3368
|
i(this, "version");
|
|
3145
|
-
this.version = e2, this.vmManager = new
|
|
3369
|
+
this.version = e2, this.vmManager = new Ie(), this.server = new mcp_js.McpServer({
|
|
3146
3370
|
name: "cvm-server",
|
|
3147
3371
|
version: this.version
|
|
3148
3372
|
}), this.setupTools();
|
|
@@ -3180,19 +3404,19 @@ class $ {
|
|
|
3180
3404
|
},
|
|
3181
3405
|
async ({ programId: e2, filePath: r$1 }) => {
|
|
3182
3406
|
try {
|
|
3183
|
-
const t2 = r.resolve(r$1),
|
|
3184
|
-
return await this.vmManager.loadProgram(e2,
|
|
3407
|
+
const t2 = r.resolve(r$1), n = await promises.readFile(t2, "utf-8");
|
|
3408
|
+
return await this.vmManager.loadProgram(e2, n), {
|
|
3185
3409
|
content: [{ type: "text", text: `Program loaded successfully from ${r$1}: ${e2}` }]
|
|
3186
3410
|
};
|
|
3187
3411
|
} catch (t2) {
|
|
3188
3412
|
if (t2 instanceof Error) {
|
|
3189
|
-
const
|
|
3190
|
-
if (
|
|
3413
|
+
const n = t2;
|
|
3414
|
+
if (n.code === "ENOENT")
|
|
3191
3415
|
return {
|
|
3192
3416
|
content: [{ type: "text", text: `Error: File not found: ${r$1}` }],
|
|
3193
3417
|
isError: true
|
|
3194
3418
|
};
|
|
3195
|
-
if (
|
|
3419
|
+
if (n.code === "EACCES")
|
|
3196
3420
|
return {
|
|
3197
3421
|
content: [{ type: "text", text: `Error: Permission denied: ${r$1}` }],
|
|
3198
3422
|
isError: true
|
|
@@ -3216,9 +3440,9 @@ class $ {
|
|
|
3216
3440
|
return await this.vmManager.startExecution(e2, r2), t2 && await this.vmManager.setCurrentExecutionId(r2), {
|
|
3217
3441
|
content: [{ type: "text", text: `Execution started: ${r2}${t2 ? " (set as current)" : ""}` }]
|
|
3218
3442
|
};
|
|
3219
|
-
} catch (
|
|
3443
|
+
} catch (n) {
|
|
3220
3444
|
return {
|
|
3221
|
-
content: [{ type: "text", text: `Error: ${
|
|
3445
|
+
content: [{ type: "text", text: `Error: ${n instanceof Error ? n.message : "Unknown error"}` }],
|
|
3222
3446
|
isError: true
|
|
3223
3447
|
};
|
|
3224
3448
|
}
|
|
@@ -3232,12 +3456,12 @@ class $ {
|
|
|
3232
3456
|
try {
|
|
3233
3457
|
let r2 = e2;
|
|
3234
3458
|
if (!r2) {
|
|
3235
|
-
const
|
|
3236
|
-
if (!
|
|
3459
|
+
const n = await this.vmManager.getCurrentExecutionId();
|
|
3460
|
+
if (!n)
|
|
3237
3461
|
return {
|
|
3238
3462
|
content: [{ type: "text", text: "No current execution set. Use list_executions to see available executions." }]
|
|
3239
3463
|
};
|
|
3240
|
-
r2 =
|
|
3464
|
+
r2 = n;
|
|
3241
3465
|
}
|
|
3242
3466
|
const t2 = await this.vmManager.getNext(r2);
|
|
3243
3467
|
return t2.type === "completed" ? {
|
|
@@ -3268,13 +3492,13 @@ class $ {
|
|
|
3268
3492
|
try {
|
|
3269
3493
|
let t2 = e2;
|
|
3270
3494
|
if (!t2) {
|
|
3271
|
-
const
|
|
3272
|
-
if (!
|
|
3495
|
+
const n = await this.vmManager.getCurrentExecutionId();
|
|
3496
|
+
if (!n)
|
|
3273
3497
|
return {
|
|
3274
3498
|
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
3275
3499
|
isError: true
|
|
3276
3500
|
};
|
|
3277
|
-
t2 =
|
|
3501
|
+
t2 = n;
|
|
3278
3502
|
}
|
|
3279
3503
|
return await this.vmManager.reportCCResult(t2, r2), {
|
|
3280
3504
|
content: [{ type: "text", text: "Execution resumed" }]
|
|
@@ -3295,13 +3519,13 @@ class $ {
|
|
|
3295
3519
|
try {
|
|
3296
3520
|
let r2 = e2;
|
|
3297
3521
|
if (!r2) {
|
|
3298
|
-
const
|
|
3299
|
-
if (!
|
|
3522
|
+
const n = await this.vmManager.getCurrentExecutionId();
|
|
3523
|
+
if (!n)
|
|
3300
3524
|
return {
|
|
3301
3525
|
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
3302
3526
|
isError: true
|
|
3303
3527
|
};
|
|
3304
|
-
r2 =
|
|
3528
|
+
r2 = n;
|
|
3305
3529
|
}
|
|
3306
3530
|
const t2 = await this.vmManager.getExecutionStatus(r2);
|
|
3307
3531
|
return {
|
|
@@ -3319,14 +3543,14 @@ class $ {
|
|
|
3319
3543
|
{},
|
|
3320
3544
|
async () => {
|
|
3321
3545
|
try {
|
|
3322
|
-
const e2 = await this.vmManager.listExecutions(), r2 = await this.vmManager.getCurrentExecutionId(), t2 = e2.map((
|
|
3323
|
-
executionId:
|
|
3324
|
-
programId:
|
|
3325
|
-
state:
|
|
3326
|
-
created:
|
|
3327
|
-
isCurrent:
|
|
3546
|
+
const e2 = await this.vmManager.listExecutions(), r2 = await this.vmManager.getCurrentExecutionId(), t2 = e2.map((n) => ({
|
|
3547
|
+
executionId: n.id,
|
|
3548
|
+
programId: n.programId,
|
|
3549
|
+
state: n.state,
|
|
3550
|
+
created: n.created,
|
|
3551
|
+
isCurrent: n.id === r2,
|
|
3328
3552
|
summary: {
|
|
3329
|
-
currentPrompt:
|
|
3553
|
+
currentPrompt: n.state === "AWAITING_COGNITIVE_RESULT" ? n.ccPrompt : void 0,
|
|
3330
3554
|
tasksCompleted: 0
|
|
3331
3555
|
// TODO: Track this in future
|
|
3332
3556
|
}
|
|
@@ -3358,12 +3582,12 @@ class $ {
|
|
|
3358
3582
|
};
|
|
3359
3583
|
r2 = a2;
|
|
3360
3584
|
}
|
|
3361
|
-
const t2 = await this.vmManager.getExecutionWithAttempts(r2),
|
|
3585
|
+
const t2 = await this.vmManager.getExecutionWithAttempts(r2), n = await this.vmManager.getCurrentExecutionId(), c2 = {
|
|
3362
3586
|
executionId: t2.id,
|
|
3363
3587
|
programId: t2.programId,
|
|
3364
3588
|
state: t2.state,
|
|
3365
3589
|
created: t2.created,
|
|
3366
|
-
isCurrent: t2.id ===
|
|
3590
|
+
isCurrent: t2.id === n,
|
|
3367
3591
|
currentTask: t2.state === "AWAITING_COGNITIVE_RESULT" ? {
|
|
3368
3592
|
prompt: t2.ccPrompt,
|
|
3369
3593
|
attempts: t2.attempts || 1,
|
|
@@ -3620,7 +3844,7 @@ async function main() {
|
|
|
3620
3844
|
];
|
|
3621
3845
|
for (const packageJsonPath of possiblePaths) {
|
|
3622
3846
|
try {
|
|
3623
|
-
const packageJson = JSON.parse(
|
|
3847
|
+
const packageJson = JSON.parse(N$1.readFileSync(packageJsonPath, "utf-8"));
|
|
3624
3848
|
if (packageJson.name === "cvm-server" && packageJson.version) {
|
|
3625
3849
|
version = packageJson.version;
|
|
3626
3850
|
break;
|