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