cvm-server 0.9.1 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/main.cjs +997 -679
- package/package.json +1 -1
package/main.cjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
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
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const c$
|
|
5
|
+
const i$2 = require("typescript");
|
|
6
|
+
const M$2 = require("fs");
|
|
7
|
+
const c$1 = require("path");
|
|
8
8
|
const mongodb = require("mongodb");
|
|
9
9
|
const promises = require("fs/promises");
|
|
10
10
|
const dotenv = require("dotenv");
|
|
@@ -26,51 +26,47 @@ function _interopNamespaceDefault(e2) {
|
|
|
26
26
|
n2.default = e2;
|
|
27
27
|
return Object.freeze(n2);
|
|
28
28
|
}
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const c__namespace = /* @__PURE__ */ _interopNamespaceDefault(c$
|
|
29
|
+
const i__namespace = /* @__PURE__ */ _interopNamespaceDefault(i$2);
|
|
30
|
+
const M__namespace = /* @__PURE__ */ _interopNamespaceDefault(M$2);
|
|
31
|
+
const c__namespace = /* @__PURE__ */ _interopNamespaceDefault(c$1);
|
|
32
32
|
const dotenv__namespace = /* @__PURE__ */ _interopNamespaceDefault(dotenv);
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
33
|
+
var f$1 = Object.defineProperty;
|
|
34
|
+
var p$1 = (e2, t2, s2) => t2 in e2 ? f$1(e2, t2, { enumerable: true, configurable: true, writable: true, value: s2 }) : e2[t2] = s2;
|
|
35
|
+
var T$1 = (e2, t2, s2) => p$1(e2, typeof t2 != "symbol" ? t2 + "" : t2, s2);
|
|
36
|
+
var n$1 = /* @__PURE__ */ ((e2) => (e2.PUSH = "PUSH", e2.PUSH_UNDEFINED = "PUSH_UNDEFINED", e2.POP = "POP", 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.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.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.FS_LIST_FILES = "FS_LIST_FILES", e2.OBJECT_CREATE = "OBJECT_CREATE", e2.PROPERTY_GET = "PROPERTY_GET", e2.PROPERTY_SET = "PROPERTY_SET", e2.JSON_STRINGIFY = "JSON_STRINGIFY", e2.CC = "CC", e2.PRINT = "PRINT", e2.HALT = "HALT", e2))(n$1 || {});
|
|
37
37
|
function R(e2) {
|
|
38
38
|
const t2 = [], s2 = [];
|
|
39
|
-
let
|
|
40
|
-
const
|
|
39
|
+
let r = false;
|
|
40
|
+
const a2 = i__namespace.createSourceFile(
|
|
41
41
|
"program.ts",
|
|
42
42
|
e2,
|
|
43
|
-
|
|
43
|
+
i__namespace.ScriptTarget.Latest,
|
|
44
44
|
true
|
|
45
45
|
);
|
|
46
|
-
function
|
|
47
|
-
if (
|
|
48
|
-
const
|
|
49
|
-
|
|
46
|
+
function S(c2) {
|
|
47
|
+
if (i__namespace.isFunctionDeclaration(c2) && c2.name && c2.name.text === "main" && (r = true, c2.parameters.length > 0 && t2.push("main() must not have parameters")), i__namespace.isCallExpression(c2) && i__namespace.isIdentifier(c2.expression)) {
|
|
48
|
+
const o2 = c2.expression.text;
|
|
49
|
+
["setTimeout", "fetch", "require", "import"].includes(o2) && t2.push(`Unsupported function: ${o2}`);
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
const c2 = o2.expression.text;
|
|
53
|
-
["setTimeout", "fetch", "require", "import"].includes(c2) && t2.push(`Unsupported function: ${c2}`);
|
|
54
|
-
}
|
|
55
|
-
n__namespace.forEachChild(o2, l2);
|
|
51
|
+
i__namespace.forEachChild(c2, S);
|
|
56
52
|
}
|
|
57
|
-
return
|
|
53
|
+
return S(a2), r || t2.push("Program must have a main() function"), t2.length === 0 && s2.push({ op: n$1.HALT }), {
|
|
58
54
|
bytecode: s2,
|
|
59
55
|
errors: t2,
|
|
60
|
-
hasMain:
|
|
56
|
+
hasMain: r
|
|
61
57
|
};
|
|
62
58
|
}
|
|
63
59
|
let A$1 = class A {
|
|
64
60
|
constructor() {
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
T$1(this, "bytecode", []);
|
|
62
|
+
T$1(this, "contextStack", []);
|
|
67
63
|
}
|
|
68
64
|
/**
|
|
69
65
|
* Emit an instruction and return its index
|
|
70
66
|
*/
|
|
71
67
|
emit(t2, s2) {
|
|
72
|
-
const
|
|
73
|
-
return this.bytecode.push({ op: t2, arg: s2 }),
|
|
68
|
+
const r = this.bytecode.length;
|
|
69
|
+
return this.bytecode.push({ op: t2, arg: s2 }), r;
|
|
74
70
|
}
|
|
75
71
|
/**
|
|
76
72
|
* Get the current address (next instruction index)
|
|
@@ -88,7 +84,7 @@ let A$1 = class A {
|
|
|
88
84
|
* Patch multiple jump instructions with the same target
|
|
89
85
|
*/
|
|
90
86
|
patchJumps(t2, s2) {
|
|
91
|
-
t2.forEach((
|
|
87
|
+
t2.forEach((r) => this.patchJump(r, s2));
|
|
92
88
|
}
|
|
93
89
|
/**
|
|
94
90
|
* Push a new jump context onto the stack
|
|
@@ -138,320 +134,322 @@ let A$1 = class A {
|
|
|
138
134
|
return [...this.contextStack];
|
|
139
135
|
}
|
|
140
136
|
};
|
|
141
|
-
const P$1 = (e2, t2, { compileExpression: s2, compileStatement:
|
|
137
|
+
const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
142
138
|
s2(e2.expression);
|
|
143
|
-
const a2 = t2.emit(
|
|
139
|
+
const a2 = t2.emit(n$1.JUMP_IF_FALSE, -1), S = {
|
|
144
140
|
type: "if",
|
|
145
141
|
endTargets: []
|
|
146
142
|
};
|
|
147
|
-
if (e2.elseStatement ?
|
|
148
|
-
const o2 = t2.emit(
|
|
149
|
-
|
|
150
|
-
const
|
|
151
|
-
t2.patchJump(a2,
|
|
152
|
-
}
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
143
|
+
if (e2.elseStatement ? S.elseTarget = a2 : S.endTargets.push(a2), t2.pushContext(S), r(e2.thenStatement), e2.elseStatement) {
|
|
144
|
+
const o2 = t2.emit(n$1.JUMP, -1);
|
|
145
|
+
S.endTargets.push(o2);
|
|
146
|
+
const m2 = t2.currentAddress();
|
|
147
|
+
t2.patchJump(a2, m2), r(e2.elseStatement);
|
|
148
|
+
}
|
|
149
|
+
const c2 = t2.popContext();
|
|
150
|
+
if (c2) {
|
|
155
151
|
const o2 = t2.currentAddress();
|
|
156
|
-
t2.patchJumps(
|
|
152
|
+
t2.patchJumps(c2.endTargets, o2);
|
|
157
153
|
}
|
|
158
|
-
}, I = (e2, t2, { compileExpression: s2, compileStatement:
|
|
154
|
+
}, I = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
159
155
|
const a2 = t2.currentAddress();
|
|
160
156
|
s2(e2.expression);
|
|
161
|
-
const
|
|
157
|
+
const c2 = {
|
|
162
158
|
type: "loop",
|
|
163
|
-
breakTargets: [t2.emit(
|
|
159
|
+
breakTargets: [t2.emit(n$1.JUMP_IF_FALSE, -1)],
|
|
164
160
|
continueTargets: [],
|
|
165
161
|
endTargets: [],
|
|
166
162
|
startAddress: a2
|
|
167
163
|
};
|
|
168
|
-
t2.pushContext(
|
|
164
|
+
t2.pushContext(c2), r(e2.statement), t2.emit(n$1.JUMP, a2);
|
|
169
165
|
const o2 = t2.popContext();
|
|
170
166
|
if (o2) {
|
|
171
|
-
const
|
|
172
|
-
t2.patchJumps(o2.breakTargets || [],
|
|
173
|
-
}
|
|
174
|
-
}, h$2 = (e2, t2, { compileExpression: s2, compileStatement:
|
|
175
|
-
const a2 = e2.initializer,
|
|
176
|
-
let
|
|
177
|
-
if (
|
|
178
|
-
|
|
179
|
-
else if (
|
|
180
|
-
|
|
167
|
+
const m2 = t2.currentAddress();
|
|
168
|
+
t2.patchJumps(o2.breakTargets || [], m2);
|
|
169
|
+
}
|
|
170
|
+
}, h$2 = (e2, t2, { compileExpression: s2, compileStatement: r }) => {
|
|
171
|
+
const a2 = e2.initializer, S = e2.expression;
|
|
172
|
+
let c2;
|
|
173
|
+
if (i__namespace.isVariableDeclarationList(a2))
|
|
174
|
+
c2 = a2.declarations[0].name.getText();
|
|
175
|
+
else if (i__namespace.isIdentifier(a2))
|
|
176
|
+
c2 = a2.text;
|
|
181
177
|
else
|
|
182
178
|
throw new Error("Unsupported for-of variable declaration");
|
|
183
|
-
s2(
|
|
179
|
+
s2(S), t2.emit(n$1.ITER_START);
|
|
184
180
|
const o2 = t2.currentAddress();
|
|
185
|
-
t2.emit(
|
|
186
|
-
const
|
|
187
|
-
t2.emit(
|
|
188
|
-
const
|
|
181
|
+
t2.emit(n$1.ITER_NEXT);
|
|
182
|
+
const m2 = t2.emit(n$1.JUMP_IF_FALSE, -1);
|
|
183
|
+
t2.emit(n$1.STORE, c2);
|
|
184
|
+
const l2 = {
|
|
189
185
|
type: "foreach",
|
|
190
|
-
breakTargets: [
|
|
186
|
+
breakTargets: [m2],
|
|
191
187
|
continueTargets: [],
|
|
192
188
|
endTargets: [],
|
|
193
189
|
startAddress: o2,
|
|
194
|
-
iterVariable:
|
|
190
|
+
iterVariable: c2
|
|
195
191
|
};
|
|
196
|
-
t2.pushContext(
|
|
192
|
+
t2.pushContext(l2), r(e2.statement), t2.emit(n$1.JUMP, o2);
|
|
197
193
|
const u2 = t2.popContext();
|
|
198
194
|
if (u2) {
|
|
199
|
-
const
|
|
200
|
-
t2.patchJumps(u2.breakTargets || [],
|
|
195
|
+
const E2 = t2.currentAddress();
|
|
196
|
+
t2.patchJumps(u2.breakTargets || [], E2), t2.emit(n$1.ITER_END);
|
|
201
197
|
}
|
|
202
198
|
}, y$1 = (e2, t2, { compileStatement: s2 }) => {
|
|
203
|
-
e2.statements.forEach((
|
|
204
|
-
s2(
|
|
199
|
+
e2.statements.forEach((r) => {
|
|
200
|
+
s2(r);
|
|
205
201
|
});
|
|
206
202
|
}, N$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
},
|
|
210
|
-
const
|
|
211
|
-
if (
|
|
212
|
-
const a2 =
|
|
213
|
-
if (a2 ===
|
|
214
|
-
if (
|
|
215
|
-
switch (t2.emit(
|
|
216
|
-
case
|
|
217
|
-
|
|
203
|
+
const r = e2.declarationList.declarations[0];
|
|
204
|
+
r.initializer && (s2(r.initializer), t2.emit(n$1.STORE, r.name.getText()));
|
|
205
|
+
}, _$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
206
|
+
const r = e2.expression;
|
|
207
|
+
if (i__namespace.isBinaryExpression(r)) {
|
|
208
|
+
const a2 = r.operatorToken.kind;
|
|
209
|
+
if (a2 === i__namespace.SyntaxKind.PlusEqualsToken || a2 === i__namespace.SyntaxKind.MinusEqualsToken || a2 === i__namespace.SyntaxKind.AsteriskEqualsToken || a2 === i__namespace.SyntaxKind.SlashEqualsToken || a2 === i__namespace.SyntaxKind.PercentEqualsToken) {
|
|
210
|
+
if (i__namespace.isIdentifier(r.left)) {
|
|
211
|
+
switch (t2.emit(n$1.LOAD, r.left.text), s2(r.right), a2) {
|
|
212
|
+
case i__namespace.SyntaxKind.PlusEqualsToken:
|
|
213
|
+
i__namespace.isStringLiteral(r.right) ? t2.emit(n$1.CONCAT) : t2.emit(n$1.ADD);
|
|
218
214
|
break;
|
|
219
|
-
case
|
|
220
|
-
t2.emit(
|
|
215
|
+
case i__namespace.SyntaxKind.MinusEqualsToken:
|
|
216
|
+
t2.emit(n$1.SUB);
|
|
221
217
|
break;
|
|
222
|
-
case
|
|
223
|
-
t2.emit(
|
|
218
|
+
case i__namespace.SyntaxKind.AsteriskEqualsToken:
|
|
219
|
+
t2.emit(n$1.MUL);
|
|
224
220
|
break;
|
|
225
|
-
case
|
|
226
|
-
t2.emit(
|
|
221
|
+
case i__namespace.SyntaxKind.SlashEqualsToken:
|
|
222
|
+
t2.emit(n$1.DIV);
|
|
227
223
|
break;
|
|
228
|
-
case
|
|
229
|
-
t2.emit(
|
|
224
|
+
case i__namespace.SyntaxKind.PercentEqualsToken:
|
|
225
|
+
t2.emit(n$1.MOD);
|
|
230
226
|
break;
|
|
231
227
|
}
|
|
232
|
-
t2.emit(
|
|
233
|
-
} else if (
|
|
228
|
+
t2.emit(n$1.STORE, r.left.text);
|
|
229
|
+
} else if (i__namespace.isElementAccessExpression(r.left))
|
|
234
230
|
throw new Error("Compound assignment to array elements not yet supported");
|
|
235
231
|
return;
|
|
236
|
-
} else if (a2 ===
|
|
237
|
-
if (s2(
|
|
238
|
-
t2.emit(
|
|
239
|
-
else if (
|
|
240
|
-
const
|
|
241
|
-
t2.emit(
|
|
242
|
-
} else if (
|
|
243
|
-
const
|
|
244
|
-
t2.emit(
|
|
232
|
+
} else if (a2 === i__namespace.SyntaxKind.EqualsToken) {
|
|
233
|
+
if (s2(r.right), i__namespace.isIdentifier(r.left))
|
|
234
|
+
t2.emit(n$1.STORE, r.left.text);
|
|
235
|
+
else if (i__namespace.isElementAccessExpression(r.left)) {
|
|
236
|
+
const S = `__temp_${t2.getBytecode().length}`;
|
|
237
|
+
t2.emit(n$1.STORE, S), s2(r.left.expression), s2(r.left.argumentExpression), t2.emit(n$1.LOAD, S), t2.emit(n$1.ARRAY_SET), t2.emit(n$1.POP);
|
|
238
|
+
} else if (i__namespace.isPropertyAccessExpression(r.left)) {
|
|
239
|
+
const S = `__temp_${t2.getBytecode().length}`;
|
|
240
|
+
t2.emit(n$1.STORE, S), s2(r.left.expression), t2.emit(n$1.PUSH, r.left.name.text), t2.emit(n$1.LOAD, S), t2.emit(n$1.PROPERTY_SET), t2.emit(n$1.POP);
|
|
245
241
|
}
|
|
246
242
|
return;
|
|
247
243
|
}
|
|
248
244
|
}
|
|
249
|
-
|
|
245
|
+
i__namespace.isCallExpression(r) && i__namespace.isPropertyAccessExpression(r.expression) && r.expression.expression.getText() === "console" && r.expression.name.getText() === "log" ? (r.arguments.forEach((a2) => {
|
|
250
246
|
s2(a2);
|
|
251
|
-
}), t2.emit(
|
|
252
|
-
},
|
|
253
|
-
e2.expression ? s2(e2.expression) : t2.emit(
|
|
247
|
+
}), t2.emit(n$1.PRINT)) : i__namespace.isCallExpression(r) && i__namespace.isIdentifier(r.expression) && r.expression.text === "CC" ? (r.arguments.length > 0 && s2(r.arguments[0]), t2.emit(n$1.CC), t2.emit(n$1.POP)) : i__namespace.isCallExpression(r) && i__namespace.isPropertyAccessExpression(r.expression) && r.expression.name.getText() === "push" ? (s2(r.expression.expression), r.arguments.length > 0 && s2(r.arguments[0]), t2.emit(n$1.ARRAY_PUSH)) : (i__namespace.isPostfixUnaryExpression(r) || i__namespace.isPrefixUnaryExpression(r)) && (s2(r), t2.emit(n$1.POP));
|
|
248
|
+
}, g$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
249
|
+
e2.expression ? s2(e2.expression) : t2.emit(n$1.PUSH, null), t2.emit(n$1.RETURN);
|
|
254
250
|
}, k = (e2, t2, s2) => {
|
|
255
|
-
const
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
const a2 = t2.emit(
|
|
259
|
-
|
|
251
|
+
const r = t2.findLoopContext();
|
|
252
|
+
if (r) {
|
|
253
|
+
r.type === "foreach" && t2.emit(n$1.ITER_END);
|
|
254
|
+
const a2 = t2.emit(n$1.BREAK, -1);
|
|
255
|
+
r.breakTargets = r.breakTargets || [], r.breakTargets.push(a2);
|
|
260
256
|
} else
|
|
261
257
|
throw new Error("break statement not in loop");
|
|
262
258
|
}, U = (e2, t2, s2) => {
|
|
263
|
-
const
|
|
264
|
-
if (
|
|
265
|
-
const a2 = t2.emit(
|
|
266
|
-
|
|
259
|
+
const r = t2.findLoopContext();
|
|
260
|
+
if (r && r.startAddress !== void 0) {
|
|
261
|
+
const a2 = t2.emit(n$1.CONTINUE, r.startAddress);
|
|
262
|
+
r.continueTargets = r.continueTargets || [], r.continueTargets.push(a2);
|
|
267
263
|
} else
|
|
268
264
|
throw new Error("continue statement not in loop");
|
|
269
265
|
}, L$1 = {
|
|
270
|
-
[
|
|
271
|
-
[
|
|
272
|
-
[
|
|
273
|
-
[
|
|
274
|
-
[
|
|
275
|
-
[
|
|
276
|
-
[
|
|
277
|
-
[
|
|
278
|
-
[
|
|
279
|
-
}, d$1 = (e2, t2, s2) => {
|
|
280
|
-
t2.emit(i$1.PUSH, e2.text);
|
|
266
|
+
[i__namespace.SyntaxKind.IfStatement]: P$1,
|
|
267
|
+
[i__namespace.SyntaxKind.WhileStatement]: I,
|
|
268
|
+
[i__namespace.SyntaxKind.ForOfStatement]: h$2,
|
|
269
|
+
[i__namespace.SyntaxKind.Block]: y$1,
|
|
270
|
+
[i__namespace.SyntaxKind.VariableStatement]: N$1,
|
|
271
|
+
[i__namespace.SyntaxKind.ExpressionStatement]: _$1,
|
|
272
|
+
[i__namespace.SyntaxKind.ReturnStatement]: g$1,
|
|
273
|
+
[i__namespace.SyntaxKind.BreakStatement]: k,
|
|
274
|
+
[i__namespace.SyntaxKind.ContinueStatement]: U
|
|
281
275
|
}, K = (e2, t2, s2) => {
|
|
282
|
-
t2.emit(
|
|
276
|
+
t2.emit(n$1.PUSH, e2.text);
|
|
277
|
+
}, d$1 = (e2, t2, s2) => {
|
|
278
|
+
t2.emit(n$1.PUSH, Number(e2.text));
|
|
283
279
|
}, b$2 = (e2, t2, s2) => {
|
|
284
|
-
t2.emit(
|
|
280
|
+
t2.emit(n$1.PUSH, true);
|
|
285
281
|
}, F$1 = (e2, t2, s2) => {
|
|
286
|
-
t2.emit(
|
|
282
|
+
t2.emit(n$1.PUSH, false);
|
|
283
|
+
}, G$1 = (e2, t2, s2) => {
|
|
284
|
+
t2.emit(n$1.PUSH, null);
|
|
287
285
|
}, D$1 = (e2, t2, s2) => {
|
|
288
|
-
t2.emit(
|
|
289
|
-
}, G = (e2, t2, s2) => {
|
|
290
|
-
e2.text === "undefined" ? t2.emit(i$1.PUSH_UNDEFINED) : t2.emit(i$1.LOAD, e2.text);
|
|
286
|
+
e2.text === "undefined" ? t2.emit(n$1.PUSH_UNDEFINED) : t2.emit(n$1.LOAD, e2.text);
|
|
291
287
|
}, H$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
292
|
-
t2.emit(
|
|
293
|
-
s2(
|
|
288
|
+
t2.emit(n$1.ARRAY_NEW), e2.elements.forEach((r) => {
|
|
289
|
+
s2(r), t2.emit(n$1.ARRAY_PUSH);
|
|
294
290
|
});
|
|
295
291
|
}, M$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
296
292
|
s2(e2.expression);
|
|
297
293
|
}, J$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
298
|
-
e2.name.text === "length" ? (s2(e2.expression), t2.emit(
|
|
299
|
-
},
|
|
300
|
-
s2(e2.expression), e2.argumentExpression ? s2(e2.argumentExpression) :
|
|
301
|
-
},
|
|
294
|
+
e2.name.text === "length" ? (s2(e2.expression), t2.emit(n$1.LENGTH)) : (s2(e2.expression), t2.emit(n$1.PUSH, e2.name.text), t2.emit(n$1.PROPERTY_GET));
|
|
295
|
+
}, Y$1 = (e2, t2, { compileExpression: s2, reportError: r }) => {
|
|
296
|
+
s2(e2.expression), e2.argumentExpression ? s2(e2.argumentExpression) : r(e2, "Element access requires an index expression"), t2.emit(n$1.ARRAY_GET);
|
|
297
|
+
}, C = (e2, t2, { compileExpression: s2 }) => {
|
|
302
298
|
switch (e2.operator) {
|
|
303
|
-
case
|
|
304
|
-
s2(e2.operand), t2.emit(
|
|
299
|
+
case i__namespace.SyntaxKind.ExclamationToken:
|
|
300
|
+
s2(e2.operand), t2.emit(n$1.NOT);
|
|
305
301
|
break;
|
|
306
|
-
case
|
|
307
|
-
s2(e2.operand), t2.emit(
|
|
302
|
+
case i__namespace.SyntaxKind.MinusToken:
|
|
303
|
+
s2(e2.operand), t2.emit(n$1.UNARY_MINUS);
|
|
308
304
|
break;
|
|
309
|
-
case
|
|
310
|
-
s2(e2.operand), t2.emit(
|
|
305
|
+
case i__namespace.SyntaxKind.PlusToken:
|
|
306
|
+
s2(e2.operand), t2.emit(n$1.UNARY_PLUS);
|
|
311
307
|
break;
|
|
312
|
-
case
|
|
313
|
-
|
|
308
|
+
case i__namespace.SyntaxKind.PlusPlusToken:
|
|
309
|
+
i__namespace.isIdentifier(e2.operand) && (t2.emit(n$1.PUSH, e2.operand.text), t2.emit(n$1.INC, false));
|
|
314
310
|
break;
|
|
315
|
-
case
|
|
316
|
-
|
|
311
|
+
case i__namespace.SyntaxKind.MinusMinusToken:
|
|
312
|
+
i__namespace.isIdentifier(e2.operand) && (t2.emit(n$1.PUSH, e2.operand.text), t2.emit(n$1.DEC, false));
|
|
317
313
|
break;
|
|
318
314
|
}
|
|
319
315
|
}, w$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
320
316
|
switch (e2.operator) {
|
|
321
|
-
case
|
|
322
|
-
|
|
317
|
+
case i__namespace.SyntaxKind.PlusPlusToken:
|
|
318
|
+
i__namespace.isIdentifier(e2.operand) && (t2.emit(n$1.PUSH, e2.operand.text), t2.emit(n$1.INC, true));
|
|
323
319
|
break;
|
|
324
|
-
case
|
|
325
|
-
|
|
320
|
+
case i__namespace.SyntaxKind.MinusMinusToken:
|
|
321
|
+
i__namespace.isIdentifier(e2.operand) && (t2.emit(n$1.PUSH, e2.operand.text), t2.emit(n$1.DEC, true));
|
|
326
322
|
break;
|
|
327
323
|
}
|
|
328
324
|
};
|
|
329
|
-
function
|
|
330
|
-
return !!(
|
|
325
|
+
function x$1(e2, t2) {
|
|
326
|
+
return !!(i__namespace.isStringLiteral(e2) || i__namespace.isStringLiteral(t2) || i__namespace.isBinaryExpression(e2) && e2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$1(e2.left, e2.right) || i__namespace.isBinaryExpression(t2) && t2.operatorToken.kind === i__namespace.SyntaxKind.PlusToken && x$1(t2.left, t2.right));
|
|
331
327
|
}
|
|
332
328
|
const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
333
|
-
const
|
|
334
|
-
switch (s2(e2.left), s2(e2.right),
|
|
335
|
-
case
|
|
336
|
-
|
|
329
|
+
const r = e2.operatorToken.kind;
|
|
330
|
+
switch (s2(e2.left), s2(e2.right), r) {
|
|
331
|
+
case i__namespace.SyntaxKind.PlusToken:
|
|
332
|
+
x$1(e2.left, e2.right) ? t2.emit(n$1.CONCAT) : t2.emit(n$1.ADD);
|
|
337
333
|
break;
|
|
338
|
-
case
|
|
339
|
-
t2.emit(
|
|
334
|
+
case i__namespace.SyntaxKind.MinusToken:
|
|
335
|
+
t2.emit(n$1.SUB);
|
|
340
336
|
break;
|
|
341
|
-
case
|
|
342
|
-
t2.emit(
|
|
337
|
+
case i__namespace.SyntaxKind.AsteriskToken:
|
|
338
|
+
t2.emit(n$1.MUL);
|
|
343
339
|
break;
|
|
344
|
-
case
|
|
345
|
-
t2.emit(
|
|
340
|
+
case i__namespace.SyntaxKind.SlashToken:
|
|
341
|
+
t2.emit(n$1.DIV);
|
|
346
342
|
break;
|
|
347
|
-
case
|
|
348
|
-
t2.emit(
|
|
343
|
+
case i__namespace.SyntaxKind.PercentToken:
|
|
344
|
+
t2.emit(n$1.MOD);
|
|
349
345
|
break;
|
|
350
|
-
case
|
|
351
|
-
t2.emit(
|
|
346
|
+
case i__namespace.SyntaxKind.EqualsEqualsToken:
|
|
347
|
+
t2.emit(n$1.EQ);
|
|
352
348
|
break;
|
|
353
|
-
case
|
|
354
|
-
t2.emit(
|
|
349
|
+
case i__namespace.SyntaxKind.ExclamationEqualsToken:
|
|
350
|
+
t2.emit(n$1.NEQ);
|
|
355
351
|
break;
|
|
356
|
-
case
|
|
357
|
-
t2.emit(
|
|
352
|
+
case i__namespace.SyntaxKind.LessThanToken:
|
|
353
|
+
t2.emit(n$1.LT);
|
|
358
354
|
break;
|
|
359
|
-
case
|
|
360
|
-
t2.emit(
|
|
355
|
+
case i__namespace.SyntaxKind.GreaterThanToken:
|
|
356
|
+
t2.emit(n$1.GT);
|
|
361
357
|
break;
|
|
362
|
-
case
|
|
363
|
-
t2.emit(
|
|
358
|
+
case i__namespace.SyntaxKind.LessThanEqualsToken:
|
|
359
|
+
t2.emit(n$1.LTE);
|
|
364
360
|
break;
|
|
365
|
-
case
|
|
366
|
-
t2.emit(
|
|
361
|
+
case i__namespace.SyntaxKind.GreaterThanEqualsToken:
|
|
362
|
+
t2.emit(n$1.GTE);
|
|
367
363
|
break;
|
|
368
|
-
case
|
|
369
|
-
t2.emit(
|
|
364
|
+
case i__namespace.SyntaxKind.EqualsEqualsEqualsToken:
|
|
365
|
+
t2.emit(n$1.EQ_STRICT);
|
|
370
366
|
break;
|
|
371
|
-
case
|
|
372
|
-
t2.emit(
|
|
367
|
+
case i__namespace.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
368
|
+
t2.emit(n$1.NEQ_STRICT);
|
|
373
369
|
break;
|
|
374
|
-
case
|
|
375
|
-
t2.emit(
|
|
370
|
+
case i__namespace.SyntaxKind.AmpersandAmpersandToken:
|
|
371
|
+
t2.emit(n$1.AND);
|
|
376
372
|
break;
|
|
377
|
-
case
|
|
378
|
-
t2.emit(
|
|
373
|
+
case i__namespace.SyntaxKind.BarBarToken:
|
|
374
|
+
t2.emit(n$1.OR);
|
|
379
375
|
break;
|
|
380
376
|
}
|
|
381
377
|
}, q$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
382
378
|
s2(e2.condition);
|
|
383
|
-
const
|
|
379
|
+
const r = t2.emit(n$1.JUMP_IF_FALSE, -1);
|
|
384
380
|
s2(e2.whenTrue);
|
|
385
|
-
const a2 = t2.emit(
|
|
386
|
-
t2.patchJump(
|
|
387
|
-
const
|
|
388
|
-
t2.patchJump(a2,
|
|
381
|
+
const a2 = t2.emit(n$1.JUMP, -1), S = t2.currentAddress();
|
|
382
|
+
t2.patchJump(r, S), s2(e2.whenFalse);
|
|
383
|
+
const c2 = t2.currentAddress();
|
|
384
|
+
t2.patchJump(a2, c2);
|
|
389
385
|
}, O = (e2, t2, { compileExpression: s2 }) => {
|
|
390
|
-
s2(e2.expression), t2.emit(
|
|
386
|
+
s2(e2.expression), t2.emit(n$1.TYPEOF);
|
|
391
387
|
}, V$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
392
|
-
if (
|
|
393
|
-
e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(
|
|
394
|
-
else if (
|
|
395
|
-
e2.arguments.length > 0 && s2(e2.arguments[0]), t2.emit(
|
|
396
|
-
else if (
|
|
397
|
-
e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(
|
|
398
|
-
else if (
|
|
399
|
-
e2.arguments.length > 0 && s2(e2.arguments[0]), t2.emit(
|
|
400
|
-
else if (
|
|
401
|
-
const
|
|
402
|
-
if (
|
|
403
|
-
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(
|
|
404
|
-
else if (
|
|
405
|
-
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(
|
|
406
|
-
else if (
|
|
407
|
-
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(
|
|
408
|
-
else if (
|
|
409
|
-
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(
|
|
410
|
-
else if (
|
|
411
|
-
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(
|
|
412
|
-
else if (
|
|
413
|
-
s2(e2.expression.expression), t2.emit(
|
|
414
|
-
else if (
|
|
415
|
-
s2(e2.expression.expression), t2.emit(
|
|
388
|
+
if (i__namespace.isPropertyAccessExpression(e2.expression) && i__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "fs" && e2.expression.name.text === "listFiles")
|
|
389
|
+
e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, "."), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(n$1.FS_LIST_FILES);
|
|
390
|
+
else if (i__namespace.isPropertyAccessExpression(e2.expression) && i__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "parse")
|
|
391
|
+
e2.arguments.length > 0 && s2(e2.arguments[0]), t2.emit(n$1.JSON_PARSE);
|
|
392
|
+
else if (i__namespace.isPropertyAccessExpression(e2.expression) && i__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "stringify")
|
|
393
|
+
e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH_UNDEFINED), t2.emit(n$1.JSON_STRINGIFY);
|
|
394
|
+
else if (i__namespace.isIdentifier(e2.expression) && e2.expression.text === "CC")
|
|
395
|
+
e2.arguments.length > 0 && s2(e2.arguments[0]), t2.emit(n$1.CC);
|
|
396
|
+
else if (i__namespace.isPropertyAccessExpression(e2.expression)) {
|
|
397
|
+
const r = e2.expression.name.text;
|
|
398
|
+
if (r === "substring")
|
|
399
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, 0), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(n$1.STRING_SUBSTRING);
|
|
400
|
+
else if (r === "indexOf")
|
|
401
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, ""), t2.emit(n$1.STRING_INDEXOF);
|
|
402
|
+
else if (r === "split")
|
|
403
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, ""), t2.emit(n$1.STRING_SPLIT);
|
|
404
|
+
else if (r === "slice")
|
|
405
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, 0), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(n$1.STRING_SLICE);
|
|
406
|
+
else if (r === "charAt")
|
|
407
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(n$1.PUSH, 0), t2.emit(n$1.STRING_CHARAT);
|
|
408
|
+
else if (r === "toUpperCase")
|
|
409
|
+
s2(e2.expression.expression), t2.emit(n$1.STRING_TOUPPERCASE);
|
|
410
|
+
else if (r === "toLowerCase")
|
|
411
|
+
s2(e2.expression.expression), t2.emit(n$1.STRING_TOLOWERCASE);
|
|
412
|
+
else if (r === "toString")
|
|
413
|
+
s2(e2.expression.expression), t2.emit(n$1.TO_STRING);
|
|
416
414
|
else
|
|
417
|
-
throw new Error(`Method call '${
|
|
415
|
+
throw new Error(`Method call '${r}' is not supported`);
|
|
418
416
|
} else
|
|
419
417
|
throw new Error("Unsupported call expression");
|
|
420
418
|
}, Q = (e2, t2, { compileExpression: s2 }) => {
|
|
421
|
-
t2.emit(
|
|
422
|
-
for (const
|
|
423
|
-
if (
|
|
419
|
+
t2.emit(n$1.OBJECT_CREATE);
|
|
420
|
+
for (const r of e2.properties)
|
|
421
|
+
if (i__namespace.isPropertyAssignment(r)) {
|
|
424
422
|
let a2;
|
|
425
|
-
if (
|
|
426
|
-
a2 =
|
|
427
|
-
else if (
|
|
428
|
-
a2 =
|
|
423
|
+
if (i__namespace.isIdentifier(r.name))
|
|
424
|
+
a2 = r.name.text;
|
|
425
|
+
else if (i__namespace.isStringLiteral(r.name))
|
|
426
|
+
a2 = r.name.text;
|
|
429
427
|
else
|
|
430
428
|
throw new Error("Computed property names are not supported");
|
|
431
|
-
t2.emit(
|
|
432
|
-
} else if (
|
|
433
|
-
const a2 =
|
|
434
|
-
t2.emit(
|
|
429
|
+
t2.emit(n$1.PUSH, a2), s2(r.initializer), t2.emit(n$1.PROPERTY_SET);
|
|
430
|
+
} else if (i__namespace.isShorthandPropertyAssignment(r)) {
|
|
431
|
+
const a2 = r.name.text;
|
|
432
|
+
t2.emit(n$1.PUSH, a2), t2.emit(n$1.LOAD, a2), t2.emit(n$1.PROPERTY_SET);
|
|
435
433
|
} else
|
|
436
434
|
throw new Error("Unsupported property type in object literal");
|
|
437
|
-
},
|
|
438
|
-
[
|
|
439
|
-
[
|
|
440
|
-
[
|
|
441
|
-
[
|
|
442
|
-
[
|
|
443
|
-
[
|
|
444
|
-
[
|
|
445
|
-
[
|
|
446
|
-
[
|
|
447
|
-
[
|
|
448
|
-
[
|
|
449
|
-
[
|
|
450
|
-
[
|
|
451
|
-
[
|
|
452
|
-
[
|
|
453
|
-
[
|
|
454
|
-
[
|
|
435
|
+
}, j$2 = {
|
|
436
|
+
[i__namespace.SyntaxKind.StringLiteral]: K,
|
|
437
|
+
[i__namespace.SyntaxKind.NumericLiteral]: d$1,
|
|
438
|
+
[i__namespace.SyntaxKind.TrueKeyword]: b$2,
|
|
439
|
+
[i__namespace.SyntaxKind.FalseKeyword]: F$1,
|
|
440
|
+
[i__namespace.SyntaxKind.NullKeyword]: G$1,
|
|
441
|
+
[i__namespace.SyntaxKind.Identifier]: D$1,
|
|
442
|
+
[i__namespace.SyntaxKind.ArrayLiteralExpression]: H$1,
|
|
443
|
+
[i__namespace.SyntaxKind.BinaryExpression]: B$1,
|
|
444
|
+
[i__namespace.SyntaxKind.PrefixUnaryExpression]: C,
|
|
445
|
+
[i__namespace.SyntaxKind.PostfixUnaryExpression]: w$1,
|
|
446
|
+
[i__namespace.SyntaxKind.CallExpression]: V$1,
|
|
447
|
+
[i__namespace.SyntaxKind.PropertyAccessExpression]: J$1,
|
|
448
|
+
[i__namespace.SyntaxKind.ElementAccessExpression]: Y$1,
|
|
449
|
+
[i__namespace.SyntaxKind.ConditionalExpression]: q$1,
|
|
450
|
+
[i__namespace.SyntaxKind.TypeOfExpression]: O,
|
|
451
|
+
[i__namespace.SyntaxKind.ParenthesizedExpression]: M$1,
|
|
452
|
+
[i__namespace.SyntaxKind.ObjectLiteralExpression]: Q
|
|
455
453
|
};
|
|
456
454
|
function W$1(e2) {
|
|
457
455
|
const t2 = R(e2);
|
|
@@ -461,95 +459,98 @@ function W$1(e2) {
|
|
|
461
459
|
bytecode: [],
|
|
462
460
|
errors: t2.errors
|
|
463
461
|
};
|
|
464
|
-
const s2 = new A$1(),
|
|
465
|
-
compileStatement:
|
|
466
|
-
compileExpression:
|
|
467
|
-
reportError: (o2,
|
|
468
|
-
throw new Error(
|
|
462
|
+
const s2 = new A$1(), r = i__namespace.createSourceFile("program.ts", e2, i__namespace.ScriptTarget.Latest, true), a2 = {
|
|
463
|
+
compileStatement: S,
|
|
464
|
+
compileExpression: c2,
|
|
465
|
+
reportError: (o2, m2) => {
|
|
466
|
+
throw new Error(m2);
|
|
469
467
|
}
|
|
470
468
|
};
|
|
471
|
-
function
|
|
472
|
-
const
|
|
473
|
-
|
|
474
|
-
}
|
|
475
|
-
function
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
}
|
|
479
|
-
return
|
|
480
|
-
var
|
|
481
|
-
|
|
482
|
-
|
|
469
|
+
function S(o2) {
|
|
470
|
+
const m2 = L$1[o2.kind];
|
|
471
|
+
m2 && m2(o2, s2, a2);
|
|
472
|
+
}
|
|
473
|
+
function c2(o2) {
|
|
474
|
+
const m2 = j$2[o2.kind];
|
|
475
|
+
m2 && m2(o2, s2, a2);
|
|
476
|
+
}
|
|
477
|
+
return r.forEachChild((o2) => {
|
|
478
|
+
var m2;
|
|
479
|
+
i__namespace.isFunctionDeclaration(o2) && ((m2 = o2.name) == null ? void 0 : m2.text) === "main" && o2.body && o2.body.statements.forEach((l2) => {
|
|
480
|
+
S(l2);
|
|
483
481
|
});
|
|
484
|
-
}), s2.emit(
|
|
482
|
+
}), s2.emit(n$1.HALT), {
|
|
485
483
|
success: true,
|
|
486
484
|
bytecode: s2.getBytecode(),
|
|
487
485
|
errors: []
|
|
488
486
|
};
|
|
489
487
|
}
|
|
490
|
-
function n(
|
|
491
|
-
return typeof
|
|
488
|
+
function n(r) {
|
|
489
|
+
return typeof r == "string";
|
|
492
490
|
}
|
|
493
|
-
function t(
|
|
494
|
-
return typeof
|
|
491
|
+
function t(r) {
|
|
492
|
+
return typeof r == "number";
|
|
495
493
|
}
|
|
496
|
-
function i(
|
|
497
|
-
return typeof
|
|
494
|
+
function i$1(r) {
|
|
495
|
+
return typeof r == "boolean";
|
|
498
496
|
}
|
|
499
|
-
function e(
|
|
500
|
-
return
|
|
497
|
+
function e(r) {
|
|
498
|
+
return r === null;
|
|
501
499
|
}
|
|
502
|
-
function f(
|
|
503
|
-
return
|
|
500
|
+
function f(r) {
|
|
501
|
+
return r !== null && typeof r == "object" && "type" in r && r.type === "array";
|
|
504
502
|
}
|
|
505
|
-
function o(
|
|
506
|
-
return
|
|
503
|
+
function o(r) {
|
|
504
|
+
return r !== null && typeof r == "object" && "type" in r && r.type === "undefined";
|
|
507
505
|
}
|
|
508
|
-
function c
|
|
509
|
-
return
|
|
506
|
+
function c(r) {
|
|
507
|
+
return r !== null && typeof r == "object" && "type" in r && r.type === "object";
|
|
510
508
|
}
|
|
511
|
-
function y(
|
|
512
|
-
return n(
|
|
509
|
+
function y(r) {
|
|
510
|
+
return n(r) ? r : t(r) || i$1(r) ? r.toString() : e(r) ? "null" : o(r) ? "undefined" : f(r) ? `[array:${r.elements.length}]` : c(r) ? "[object Object]" : String(r);
|
|
513
511
|
}
|
|
514
|
-
function b$1(
|
|
515
|
-
return i(
|
|
512
|
+
function b$1(r) {
|
|
513
|
+
return i$1(r) ? r : e(r) || o(r) ? false : t(r) ? r !== 0 : n(r) ? r !== "" : f(r) || c(r) ? true : !!r;
|
|
516
514
|
}
|
|
517
|
-
function p
|
|
518
|
-
return n(
|
|
515
|
+
function p(r) {
|
|
516
|
+
return n(r) ? "string" : t(r) ? "number" : i$1(r) ? "boolean" : e(r) ? "null" : o(r) ? "undefined" : f(r) ? "array" : c(r) ? "object" : "unknown";
|
|
519
517
|
}
|
|
520
|
-
function m(
|
|
521
|
-
if (t(
|
|
522
|
-
if (i(
|
|
523
|
-
if (e(
|
|
524
|
-
if (o(
|
|
525
|
-
if (n(
|
|
526
|
-
const u2 =
|
|
518
|
+
function m(r) {
|
|
519
|
+
if (t(r)) return r;
|
|
520
|
+
if (i$1(r)) return r ? 1 : 0;
|
|
521
|
+
if (e(r)) return 0;
|
|
522
|
+
if (o(r)) return NaN;
|
|
523
|
+
if (n(r)) {
|
|
524
|
+
const u2 = r.trim();
|
|
527
525
|
return u2 === "" ? 0 : Number(u2);
|
|
528
526
|
}
|
|
529
|
-
return f(
|
|
527
|
+
return f(r) ? NaN : Number(r);
|
|
530
528
|
}
|
|
531
|
-
function d(
|
|
532
|
-
return { type: "array", elements:
|
|
529
|
+
function d(r = []) {
|
|
530
|
+
return { type: "array", elements: r };
|
|
533
531
|
}
|
|
534
|
-
function s
|
|
532
|
+
function s() {
|
|
535
533
|
return { type: "undefined" };
|
|
536
534
|
}
|
|
537
|
-
function j$1(
|
|
538
|
-
return { type: "object", properties:
|
|
535
|
+
function j$1(r = {}) {
|
|
536
|
+
return { type: "object", properties: r };
|
|
539
537
|
}
|
|
540
538
|
var l = Object.defineProperty;
|
|
541
|
-
var u = (s2, t2,
|
|
542
|
-
var
|
|
539
|
+
var u$1 = (s2, t2, e2) => t2 in s2 ? l(s2, t2, { enumerable: true, configurable: true, writable: true, value: e2 }) : s2[t2] = e2;
|
|
540
|
+
var a = (s2, t2, e2) => u$1(s2, typeof t2 != "symbol" ? t2 + "" : t2, e2);
|
|
543
541
|
let h$1 = class h {
|
|
544
542
|
constructor(t2) {
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
543
|
+
a(this, "connected", false);
|
|
544
|
+
a(this, "programsDir");
|
|
545
|
+
a(this, "executionsDir");
|
|
546
|
+
a(this, "outputsDir");
|
|
549
547
|
this.dataDir = t2, this.programsDir = c__namespace.join(t2, "programs"), this.executionsDir = c__namespace.join(t2, "executions"), this.outputsDir = c__namespace.join(t2, "outputs");
|
|
550
548
|
}
|
|
549
|
+
get metadataFile() {
|
|
550
|
+
return c__namespace.join(this.dataDir, "metadata.json");
|
|
551
|
+
}
|
|
551
552
|
async connect() {
|
|
552
|
-
await
|
|
553
|
+
await M$2.promises.mkdir(this.dataDir, { recursive: true }), await M$2.promises.mkdir(this.programsDir, { recursive: true }), await M$2.promises.mkdir(this.executionsDir, { recursive: true }), await M$2.promises.mkdir(this.outputsDir, { recursive: true }), this.connected = true;
|
|
553
554
|
}
|
|
554
555
|
async disconnect() {
|
|
555
556
|
this.connected = false;
|
|
@@ -559,63 +560,105 @@ let h$1 = class h {
|
|
|
559
560
|
}
|
|
560
561
|
async saveProgram(t2) {
|
|
561
562
|
if (!this.connected) throw new Error("Not connected");
|
|
562
|
-
const
|
|
563
|
-
await
|
|
563
|
+
const e2 = c__namespace.join(this.programsDir, `${t2.id}.json`), n2 = JSON.stringify(t2, null, 2);
|
|
564
|
+
await M$2.promises.writeFile(e2, n2, "utf-8");
|
|
564
565
|
}
|
|
565
566
|
async getProgram(t2) {
|
|
566
567
|
if (!this.connected) throw new Error("Not connected");
|
|
567
|
-
const
|
|
568
|
+
const e2 = c__namespace.join(this.programsDir, `${t2}.json`);
|
|
568
569
|
try {
|
|
569
|
-
const
|
|
570
|
+
const n2 = await M$2.promises.readFile(e2, "utf-8"), o2 = JSON.parse(n2);
|
|
570
571
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
571
|
-
} catch (
|
|
572
|
-
if (
|
|
572
|
+
} catch (n2) {
|
|
573
|
+
if (n2.code === "ENOENT")
|
|
573
574
|
return null;
|
|
574
|
-
throw
|
|
575
|
+
throw n2;
|
|
575
576
|
}
|
|
576
577
|
}
|
|
577
578
|
async saveExecution(t2) {
|
|
578
579
|
if (!this.connected) throw new Error("Not connected");
|
|
579
|
-
const
|
|
580
|
-
await
|
|
580
|
+
const e2 = c__namespace.join(this.executionsDir, `${t2.id}.json`), n2 = JSON.stringify(t2, null, 2);
|
|
581
|
+
await M$2.promises.writeFile(e2, n2, "utf-8");
|
|
581
582
|
}
|
|
582
583
|
async getExecution(t2) {
|
|
583
584
|
if (!this.connected) throw new Error("Not connected");
|
|
584
|
-
const
|
|
585
|
+
const e2 = c__namespace.join(this.executionsDir, `${t2}.json`);
|
|
585
586
|
try {
|
|
586
|
-
const
|
|
587
|
+
const n2 = await M$2.promises.readFile(e2, "utf-8"), o2 = JSON.parse(n2);
|
|
587
588
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
588
|
-
} catch (
|
|
589
|
-
if (
|
|
589
|
+
} catch (n2) {
|
|
590
|
+
if (n2.code === "ENOENT")
|
|
590
591
|
return null;
|
|
591
|
-
throw
|
|
592
|
+
throw n2;
|
|
592
593
|
}
|
|
593
594
|
}
|
|
594
|
-
async appendOutput(t2,
|
|
595
|
+
async appendOutput(t2, e2) {
|
|
595
596
|
if (!this.connected) throw new Error("Not connected");
|
|
596
|
-
const
|
|
597
|
+
const n2 = c__namespace.join(this.outputsDir, `${t2}.output`), o2 = e2.join(`
|
|
597
598
|
`) + `
|
|
598
599
|
`;
|
|
599
|
-
await
|
|
600
|
+
await M$2.promises.appendFile(n2, o2, "utf-8");
|
|
600
601
|
}
|
|
601
602
|
async getOutput(t2) {
|
|
602
603
|
if (!this.connected) throw new Error("Not connected");
|
|
603
|
-
const
|
|
604
|
+
const e2 = c__namespace.join(this.outputsDir, `${t2}.output`);
|
|
604
605
|
try {
|
|
605
|
-
return (await
|
|
606
|
+
return (await M$2.promises.readFile(e2, "utf-8")).split(`
|
|
606
607
|
`).filter((o2) => o2.length > 0);
|
|
607
|
-
} catch (
|
|
608
|
-
if (
|
|
608
|
+
} catch (n2) {
|
|
609
|
+
if (n2.code === "ENOENT")
|
|
609
610
|
return [];
|
|
610
|
-
throw
|
|
611
|
+
throw n2;
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
async listExecutions() {
|
|
615
|
+
if (!this.connected) throw new Error("Not connected");
|
|
616
|
+
const t2 = await M$2.promises.readdir(this.executionsDir), e2 = [];
|
|
617
|
+
for (const n2 of t2)
|
|
618
|
+
if (n2.endsWith(".json")) {
|
|
619
|
+
const o2 = n2.slice(0, -5), r = await this.getExecution(o2);
|
|
620
|
+
r && e2.push(r);
|
|
621
|
+
}
|
|
622
|
+
return e2;
|
|
623
|
+
}
|
|
624
|
+
async getCurrentExecutionId() {
|
|
625
|
+
if (!this.connected) throw new Error("Not connected");
|
|
626
|
+
try {
|
|
627
|
+
const t2 = await M$2.promises.readFile(this.metadataFile, "utf-8");
|
|
628
|
+
return JSON.parse(t2).currentExecutionId || null;
|
|
629
|
+
} catch (t2) {
|
|
630
|
+
if (t2.code === "ENOENT")
|
|
631
|
+
return null;
|
|
632
|
+
throw t2;
|
|
611
633
|
}
|
|
612
634
|
}
|
|
635
|
+
async setCurrentExecutionId(t2) {
|
|
636
|
+
if (!this.connected) throw new Error("Not connected");
|
|
637
|
+
const e2 = { currentExecutionId: t2 };
|
|
638
|
+
await M$2.promises.writeFile(this.metadataFile, JSON.stringify(e2, null, 2), "utf-8");
|
|
639
|
+
}
|
|
640
|
+
async deleteExecution(t2) {
|
|
641
|
+
if (!this.connected) throw new Error("Not connected");
|
|
642
|
+
const e2 = c__namespace.join(this.executionsDir, `${t2}.json`);
|
|
643
|
+
try {
|
|
644
|
+
await M$2.promises.unlink(e2);
|
|
645
|
+
} catch (r) {
|
|
646
|
+
if (r.code !== "ENOENT") throw r;
|
|
647
|
+
}
|
|
648
|
+
const n2 = c__namespace.join(this.outputsDir, `${t2}.output`);
|
|
649
|
+
try {
|
|
650
|
+
await M$2.promises.unlink(n2);
|
|
651
|
+
} catch (r) {
|
|
652
|
+
if (r.code !== "ENOENT") throw r;
|
|
653
|
+
}
|
|
654
|
+
await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null);
|
|
655
|
+
}
|
|
613
656
|
};
|
|
614
|
-
class
|
|
657
|
+
class w {
|
|
615
658
|
constructor(t2) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
659
|
+
a(this, "client");
|
|
660
|
+
a(this, "db", null);
|
|
661
|
+
a(this, "connected", false);
|
|
619
662
|
this.connectionString = t2, this.client = new mongodb.MongoClient(t2);
|
|
620
663
|
}
|
|
621
664
|
async connect() {
|
|
@@ -623,8 +666,8 @@ class p {
|
|
|
623
666
|
await this.client.connect();
|
|
624
667
|
const t2 = ((o2 = this.connectionString.split("/").pop()) == null ? void 0 : o2.split("?")[0]) || "cvm";
|
|
625
668
|
this.db = this.client.db(t2), this.connected = true;
|
|
626
|
-
const
|
|
627
|
-
|
|
669
|
+
const n2 = (await this.db.listCollections().toArray()).map((r) => r.name);
|
|
670
|
+
n2.includes("programs") || await this.db.createCollection("programs"), n2.includes("executions") || await this.db.createCollection("executions"), n2.includes("outputs") || await this.db.createCollection("outputs"), n2.includes("metadata") || await this.db.createCollection("metadata");
|
|
628
671
|
}
|
|
629
672
|
async disconnect() {
|
|
630
673
|
await this.client.close(), this.connected = false, this.db = null;
|
|
@@ -634,7 +677,7 @@ class p {
|
|
|
634
677
|
}
|
|
635
678
|
async getCollections() {
|
|
636
679
|
if (!this.db) throw new Error("Not connected to database");
|
|
637
|
-
return (await this.db.listCollections().toArray()).map((
|
|
680
|
+
return (await this.db.listCollections().toArray()).map((e2) => e2.name);
|
|
638
681
|
}
|
|
639
682
|
getCollection(t2) {
|
|
640
683
|
if (!this.db) throw new Error("Not connected to database");
|
|
@@ -660,145 +703,162 @@ class p {
|
|
|
660
703
|
async getExecution(t2) {
|
|
661
704
|
return await this.getCollection("executions").findOne({ id: t2 });
|
|
662
705
|
}
|
|
663
|
-
async appendOutput(t2,
|
|
664
|
-
const
|
|
665
|
-
await
|
|
706
|
+
async appendOutput(t2, e2) {
|
|
707
|
+
const n2 = this.getCollection("outputs");
|
|
708
|
+
await n2.findOne({ executionId: t2 }) ? await n2.updateOne(
|
|
666
709
|
{ executionId: t2 },
|
|
667
|
-
{ $push: { lines: { $each:
|
|
668
|
-
) : await
|
|
710
|
+
{ $push: { lines: { $each: e2 } } }
|
|
711
|
+
) : await n2.insertOne({ executionId: t2, lines: e2 });
|
|
669
712
|
}
|
|
670
713
|
async getOutput(t2) {
|
|
671
|
-
const
|
|
672
|
-
return (
|
|
714
|
+
const n2 = await this.getCollection("outputs").findOne({ executionId: t2 });
|
|
715
|
+
return (n2 == null ? void 0 : n2.lines) || [];
|
|
716
|
+
}
|
|
717
|
+
async listExecutions() {
|
|
718
|
+
return await this.getCollection("executions").find({}).toArray();
|
|
719
|
+
}
|
|
720
|
+
async getCurrentExecutionId() {
|
|
721
|
+
const e2 = await this.getCollection("metadata").findOne({ _id: "current" });
|
|
722
|
+
return (e2 == null ? void 0 : e2.currentExecutionId) || null;
|
|
723
|
+
}
|
|
724
|
+
async setCurrentExecutionId(t2) {
|
|
725
|
+
await this.getCollection("metadata").replaceOne(
|
|
726
|
+
{ _id: "current" },
|
|
727
|
+
{ _id: "current", currentExecutionId: t2 },
|
|
728
|
+
{ upsert: true }
|
|
729
|
+
);
|
|
730
|
+
}
|
|
731
|
+
async deleteExecution(t2) {
|
|
732
|
+
await this.getCollection("executions").deleteOne({ id: t2 }), await this.getCollection("outputs").deleteOne({ executionId: t2 }), await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null);
|
|
673
733
|
}
|
|
674
734
|
}
|
|
675
|
-
|
|
735
|
+
class E {
|
|
676
736
|
static create(t2) {
|
|
677
|
-
const
|
|
678
|
-
switch (
|
|
737
|
+
const e2 = (t2 == null ? void 0 : t2.type) || process.env.CVM_STORAGE_TYPE || "file";
|
|
738
|
+
switch (e2) {
|
|
679
739
|
case "file": {
|
|
680
|
-
const
|
|
681
|
-
return new h$1(
|
|
740
|
+
const n2 = (t2 == null ? void 0 : t2.dataDir) || process.env.CVM_DATA_DIR || ".cvm";
|
|
741
|
+
return new h$1(n2);
|
|
682
742
|
}
|
|
683
743
|
case "mongodb": {
|
|
684
|
-
const
|
|
685
|
-
return new
|
|
744
|
+
const n2 = (t2 == null ? void 0 : t2.mongoUri) || process.env.MONGODB_URI || "mongodb://localhost:27017/cvm";
|
|
745
|
+
return new w(n2);
|
|
686
746
|
}
|
|
687
747
|
default:
|
|
688
|
-
throw new Error(`Unsupported storage type: ${
|
|
748
|
+
throw new Error(`Unsupported storage type: ${e2}`);
|
|
689
749
|
}
|
|
690
750
|
}
|
|
691
|
-
}
|
|
692
|
-
var
|
|
693
|
-
var
|
|
694
|
-
var h2 = (e2,
|
|
695
|
-
const
|
|
696
|
-
[
|
|
751
|
+
}
|
|
752
|
+
var A2 = Object.defineProperty;
|
|
753
|
+
var b = (e2, r, t2) => r in e2 ? A2(e2, r, { enumerable: true, configurable: true, writable: true, value: t2 }) : e2[r] = t2;
|
|
754
|
+
var h2 = (e2, r, t2) => b(e2, typeof r != "symbol" ? r + "" : r, t2);
|
|
755
|
+
const G = {
|
|
756
|
+
[n$1.ADD]: {
|
|
697
757
|
stackIn: 2,
|
|
698
758
|
stackOut: 1,
|
|
699
759
|
execute: (e2) => {
|
|
700
|
-
const
|
|
760
|
+
const r = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r);
|
|
701
761
|
e2.stack.push(s2 + o2);
|
|
702
762
|
}
|
|
703
763
|
},
|
|
704
|
-
[
|
|
764
|
+
[n$1.SUB]: {
|
|
705
765
|
stackIn: 2,
|
|
706
766
|
stackOut: 1,
|
|
707
767
|
execute: (e2) => {
|
|
708
|
-
const
|
|
768
|
+
const r = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r);
|
|
709
769
|
e2.stack.push(s2 - o2);
|
|
710
770
|
}
|
|
711
771
|
},
|
|
712
|
-
[
|
|
772
|
+
[n$1.MUL]: {
|
|
713
773
|
stackIn: 2,
|
|
714
774
|
stackOut: 1,
|
|
715
775
|
execute: (e2) => {
|
|
716
|
-
const
|
|
776
|
+
const r = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r);
|
|
717
777
|
e2.stack.push(s2 * o2);
|
|
718
778
|
}
|
|
719
779
|
},
|
|
720
|
-
[
|
|
780
|
+
[n$1.DIV]: {
|
|
721
781
|
stackIn: 2,
|
|
722
782
|
stackOut: 1,
|
|
723
|
-
execute: (e2,
|
|
783
|
+
execute: (e2, r) => {
|
|
724
784
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = m(s2), n2 = m(t2);
|
|
725
785
|
if (n2 === 0)
|
|
726
786
|
return {
|
|
727
787
|
type: "DivisionByZero",
|
|
728
788
|
message: "Division by zero",
|
|
729
789
|
pc: e2.pc,
|
|
730
|
-
opcode:
|
|
790
|
+
opcode: r.op
|
|
731
791
|
};
|
|
732
792
|
e2.stack.push(o2 / n2);
|
|
733
793
|
}
|
|
734
794
|
},
|
|
735
|
-
[
|
|
795
|
+
[n$1.MOD]: {
|
|
736
796
|
stackIn: 2,
|
|
737
797
|
stackOut: 1,
|
|
738
798
|
execute: (e2) => {
|
|
739
|
-
const
|
|
799
|
+
const r = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r);
|
|
740
800
|
e2.stack.push(s2 % o2);
|
|
741
801
|
}
|
|
742
802
|
},
|
|
743
|
-
[
|
|
803
|
+
[n$1.UNARY_MINUS]: {
|
|
744
804
|
stackIn: 1,
|
|
745
805
|
stackOut: 1,
|
|
746
806
|
execute: (e2) => {
|
|
747
|
-
const
|
|
807
|
+
const r = e2.stack.pop(), t2 = m(r);
|
|
748
808
|
e2.stack.push(-t2);
|
|
749
809
|
}
|
|
750
810
|
},
|
|
751
|
-
[
|
|
811
|
+
[n$1.UNARY_PLUS]: {
|
|
752
812
|
stackIn: 1,
|
|
753
813
|
stackOut: 1,
|
|
754
814
|
execute: (e2) => {
|
|
755
|
-
const
|
|
815
|
+
const r = e2.stack.pop(), t2 = m(r);
|
|
756
816
|
e2.stack.push(t2);
|
|
757
817
|
}
|
|
758
818
|
}
|
|
759
|
-
},
|
|
760
|
-
[
|
|
819
|
+
}, L = {
|
|
820
|
+
[n$1.PUSH]: {
|
|
761
821
|
stackIn: 0,
|
|
762
822
|
stackOut: 1,
|
|
763
|
-
execute: (e2,
|
|
764
|
-
e2.stack.push(
|
|
823
|
+
execute: (e2, r) => {
|
|
824
|
+
e2.stack.push(r.arg);
|
|
765
825
|
}
|
|
766
826
|
},
|
|
767
|
-
[
|
|
827
|
+
[n$1.PUSH_UNDEFINED]: {
|
|
768
828
|
stackIn: 0,
|
|
769
829
|
stackOut: 1,
|
|
770
830
|
execute: (e2) => {
|
|
771
|
-
e2.stack.push(s
|
|
831
|
+
e2.stack.push(s());
|
|
772
832
|
}
|
|
773
833
|
},
|
|
774
|
-
[
|
|
834
|
+
[n$1.POP]: {
|
|
775
835
|
stackIn: 1,
|
|
776
836
|
stackOut: 0,
|
|
777
837
|
execute: (e2) => {
|
|
778
838
|
e2.stack.pop();
|
|
779
839
|
}
|
|
780
840
|
}
|
|
781
|
-
},
|
|
782
|
-
[
|
|
841
|
+
}, V = {
|
|
842
|
+
[n$1.PRINT]: {
|
|
783
843
|
stackIn: 1,
|
|
784
844
|
stackOut: 0,
|
|
785
845
|
execute: (e2) => {
|
|
786
|
-
const
|
|
787
|
-
|
|
846
|
+
const r = e2.stack.pop();
|
|
847
|
+
r !== void 0 && e2.output.push(y(r));
|
|
788
848
|
}
|
|
789
849
|
},
|
|
790
|
-
[
|
|
850
|
+
[n$1.CC]: {
|
|
791
851
|
stackIn: 1,
|
|
792
852
|
stackOut: 0,
|
|
793
853
|
controlsPC: true,
|
|
794
854
|
// CC pauses execution
|
|
795
|
-
execute: (e2,
|
|
855
|
+
execute: (e2, r) => {
|
|
796
856
|
const t2 = e2.stack.pop();
|
|
797
857
|
e2.ccPrompt = y(t2), e2.status = "waiting_cc";
|
|
798
858
|
}
|
|
799
859
|
}
|
|
800
|
-
},
|
|
801
|
-
[
|
|
860
|
+
}, F = {
|
|
861
|
+
[n$1.HALT]: {
|
|
802
862
|
stackIn: 0,
|
|
803
863
|
stackOut: 0,
|
|
804
864
|
controlsPC: true,
|
|
@@ -806,96 +866,155 @@ const L = {
|
|
|
806
866
|
e2.status = "complete";
|
|
807
867
|
}
|
|
808
868
|
},
|
|
809
|
-
[
|
|
869
|
+
[n$1.JUMP]: {
|
|
810
870
|
stackIn: 0,
|
|
811
871
|
stackOut: 0,
|
|
812
872
|
controlsPC: true,
|
|
813
|
-
execute: (e2,
|
|
814
|
-
if (
|
|
873
|
+
execute: (e2, r) => {
|
|
874
|
+
if (r.arg === void 0)
|
|
815
875
|
return {
|
|
816
876
|
type: "RuntimeError",
|
|
817
877
|
message: "JUMP requires a target address",
|
|
818
878
|
pc: e2.pc,
|
|
819
|
-
opcode:
|
|
879
|
+
opcode: r.op
|
|
820
880
|
};
|
|
821
|
-
const t2 =
|
|
881
|
+
const t2 = r.arg;
|
|
822
882
|
if (t2 < 0)
|
|
823
883
|
return {
|
|
824
884
|
type: "RuntimeError",
|
|
825
885
|
message: `Invalid jump target: ${t2}`,
|
|
826
886
|
pc: e2.pc,
|
|
827
|
-
opcode:
|
|
887
|
+
opcode: r.op
|
|
828
888
|
};
|
|
829
889
|
e2.pc = t2;
|
|
830
890
|
}
|
|
831
891
|
},
|
|
832
|
-
[
|
|
892
|
+
[n$1.JUMP_IF_FALSE]: {
|
|
833
893
|
stackIn: 1,
|
|
834
894
|
stackOut: 0,
|
|
835
895
|
controlsPC: true,
|
|
836
|
-
execute: (e2,
|
|
896
|
+
execute: (e2, r) => {
|
|
837
897
|
const t2 = e2.stack.pop();
|
|
838
|
-
if (
|
|
898
|
+
if (r.arg === void 0)
|
|
839
899
|
return {
|
|
840
900
|
type: "RuntimeError",
|
|
841
901
|
message: "JUMP_IF_FALSE requires a target address",
|
|
842
902
|
pc: e2.pc,
|
|
843
|
-
opcode:
|
|
903
|
+
opcode: r.op
|
|
844
904
|
};
|
|
845
|
-
const s2 =
|
|
905
|
+
const s2 = r.arg;
|
|
846
906
|
if (s2 < 0)
|
|
847
907
|
return {
|
|
848
908
|
type: "RuntimeError",
|
|
849
909
|
message: `Invalid jump target: ${s2}`,
|
|
850
910
|
pc: e2.pc,
|
|
851
|
-
opcode:
|
|
911
|
+
opcode: r.op
|
|
852
912
|
};
|
|
853
913
|
b$1(t2) ? e2.pc++ : e2.pc = s2;
|
|
854
914
|
}
|
|
915
|
+
},
|
|
916
|
+
[n$1.JUMP_IF]: {
|
|
917
|
+
stackIn: 1,
|
|
918
|
+
stackOut: 0,
|
|
919
|
+
controlsPC: true,
|
|
920
|
+
execute: (e2, r) => {
|
|
921
|
+
const t2 = e2.stack.pop();
|
|
922
|
+
if (r.arg === void 0)
|
|
923
|
+
return {
|
|
924
|
+
type: "RuntimeError",
|
|
925
|
+
message: "JUMP_IF requires a target address",
|
|
926
|
+
pc: e2.pc,
|
|
927
|
+
opcode: r.op
|
|
928
|
+
};
|
|
929
|
+
const s2 = r.arg;
|
|
930
|
+
if (s2 < 0)
|
|
931
|
+
return {
|
|
932
|
+
type: "RuntimeError",
|
|
933
|
+
message: `Invalid jump target: ${s2}`,
|
|
934
|
+
pc: e2.pc,
|
|
935
|
+
opcode: r.op
|
|
936
|
+
};
|
|
937
|
+
b$1(t2) ? e2.pc = s2 : e2.pc++;
|
|
938
|
+
}
|
|
939
|
+
},
|
|
940
|
+
[n$1.JUMP_IF_TRUE]: {
|
|
941
|
+
stackIn: 1,
|
|
942
|
+
stackOut: 0,
|
|
943
|
+
controlsPC: true,
|
|
944
|
+
execute: (e2, r) => {
|
|
945
|
+
const t2 = e2.stack.pop();
|
|
946
|
+
if (r.arg === void 0)
|
|
947
|
+
return {
|
|
948
|
+
type: "RuntimeError",
|
|
949
|
+
message: "JUMP_IF_TRUE requires a target address",
|
|
950
|
+
pc: e2.pc,
|
|
951
|
+
opcode: r.op
|
|
952
|
+
};
|
|
953
|
+
const s2 = r.arg;
|
|
954
|
+
if (s2 < 0)
|
|
955
|
+
return {
|
|
956
|
+
type: "RuntimeError",
|
|
957
|
+
message: `Invalid jump target: ${s2}`,
|
|
958
|
+
pc: e2.pc,
|
|
959
|
+
opcode: r.op
|
|
960
|
+
};
|
|
961
|
+
b$1(t2) ? e2.pc = s2 : e2.pc++;
|
|
962
|
+
}
|
|
963
|
+
},
|
|
964
|
+
[n$1.CALL]: {
|
|
965
|
+
stackIn: 1,
|
|
966
|
+
stackOut: 0,
|
|
967
|
+
controlsPC: false,
|
|
968
|
+
execute: (e2) => (e2.stack.pop(), {
|
|
969
|
+
type: "RuntimeError",
|
|
970
|
+
message: "Functions not implemented",
|
|
971
|
+
pc: e2.pc,
|
|
972
|
+
opcode: n$1.CALL
|
|
973
|
+
})
|
|
855
974
|
}
|
|
856
|
-
},
|
|
857
|
-
[
|
|
975
|
+
}, j = {
|
|
976
|
+
[n$1.LOAD]: {
|
|
858
977
|
stackIn: 0,
|
|
859
978
|
stackOut: 1,
|
|
860
|
-
execute: (e2,
|
|
861
|
-
const t2 =
|
|
862
|
-
e2.variables.has(t2) ? e2.stack.push(e2.variables.get(t2)) : e2.stack.push(s
|
|
979
|
+
execute: (e2, r) => {
|
|
980
|
+
const t2 = r.arg;
|
|
981
|
+
e2.variables.has(t2) ? e2.stack.push(e2.variables.get(t2)) : e2.stack.push(s());
|
|
863
982
|
}
|
|
864
983
|
},
|
|
865
|
-
[
|
|
984
|
+
[n$1.STORE]: {
|
|
866
985
|
stackIn: 1,
|
|
867
986
|
stackOut: 0,
|
|
868
|
-
execute: (e2,
|
|
987
|
+
execute: (e2, r) => {
|
|
869
988
|
const t2 = e2.stack.pop();
|
|
870
|
-
e2.variables.set(
|
|
989
|
+
e2.variables.set(r.arg, t2);
|
|
871
990
|
}
|
|
872
991
|
}
|
|
873
992
|
}, D = {
|
|
874
|
-
[
|
|
993
|
+
[n$1.ITER_START]: {
|
|
875
994
|
stackIn: 1,
|
|
876
995
|
stackOut: 0,
|
|
877
|
-
execute: (e2,
|
|
996
|
+
execute: (e2, r) => {
|
|
878
997
|
const t2 = e2.stack.pop();
|
|
879
998
|
if (t2 == null)
|
|
880
999
|
return {
|
|
881
1000
|
type: "TypeError",
|
|
882
1001
|
message: "TypeError: Cannot iterate over null or undefined",
|
|
883
1002
|
pc: e2.pc,
|
|
884
|
-
opcode:
|
|
1003
|
+
opcode: r.op
|
|
885
1004
|
};
|
|
886
1005
|
if (!f(t2))
|
|
887
1006
|
return {
|
|
888
1007
|
type: "TypeError",
|
|
889
1008
|
message: "TypeError: Cannot iterate over non-array value",
|
|
890
1009
|
pc: e2.pc,
|
|
891
|
-
opcode:
|
|
1010
|
+
opcode: r.op
|
|
892
1011
|
};
|
|
893
1012
|
if (e2.iterators.length >= 10)
|
|
894
1013
|
return {
|
|
895
1014
|
type: "RuntimeError",
|
|
896
1015
|
message: "RuntimeError: Maximum iterator depth exceeded",
|
|
897
1016
|
pc: e2.pc,
|
|
898
|
-
opcode:
|
|
1017
|
+
opcode: r.op
|
|
899
1018
|
};
|
|
900
1019
|
e2.iterators.push({
|
|
901
1020
|
array: t2,
|
|
@@ -904,46 +1023,46 @@ const L = {
|
|
|
904
1023
|
});
|
|
905
1024
|
}
|
|
906
1025
|
},
|
|
907
|
-
[
|
|
1026
|
+
[n$1.ITER_NEXT]: {
|
|
908
1027
|
stackIn: 0,
|
|
909
1028
|
stackOut: 2,
|
|
910
1029
|
// Pushes element and hasMore flag
|
|
911
|
-
execute: (e2,
|
|
1030
|
+
execute: (e2, r) => {
|
|
912
1031
|
if (e2.iterators.length === 0)
|
|
913
1032
|
return {
|
|
914
1033
|
type: "RuntimeError",
|
|
915
1034
|
message: "ITER_NEXT: No active iterator",
|
|
916
1035
|
pc: e2.pc,
|
|
917
|
-
opcode:
|
|
1036
|
+
opcode: r.op
|
|
918
1037
|
};
|
|
919
1038
|
const t2 = e2.iterators[e2.iterators.length - 1];
|
|
920
|
-
t2.index < t2.length ? (t2.index < t2.array.elements.length ? e2.stack.push(t2.array.elements[t2.index]) : e2.stack.push(s
|
|
1039
|
+
t2.index < t2.length ? (t2.index < t2.array.elements.length ? e2.stack.push(t2.array.elements[t2.index]) : e2.stack.push(s()), e2.stack.push(true), t2.index++) : (e2.stack.push(null), e2.stack.push(false));
|
|
921
1040
|
}
|
|
922
1041
|
},
|
|
923
|
-
[
|
|
1042
|
+
[n$1.ITER_END]: {
|
|
924
1043
|
stackIn: 0,
|
|
925
1044
|
stackOut: 0,
|
|
926
|
-
execute: (e2,
|
|
1045
|
+
execute: (e2, r) => {
|
|
927
1046
|
if (e2.iterators.length === 0)
|
|
928
1047
|
return {
|
|
929
1048
|
type: "RuntimeError",
|
|
930
1049
|
message: "ITER_END: No active iterator",
|
|
931
1050
|
pc: e2.pc,
|
|
932
|
-
opcode:
|
|
1051
|
+
opcode: r.op
|
|
933
1052
|
};
|
|
934
1053
|
e2.iterators.pop();
|
|
935
1054
|
}
|
|
936
1055
|
}
|
|
937
1056
|
};
|
|
938
|
-
function
|
|
1057
|
+
function g(e2, r, t2) {
|
|
939
1058
|
const s2 = e2.stack.pop(), o2 = e2.stack.pop(), n2 = t2(o2, s2);
|
|
940
1059
|
e2.stack.push(n2);
|
|
941
1060
|
}
|
|
942
1061
|
const q = {
|
|
943
|
-
[
|
|
1062
|
+
[n$1.EQ]: {
|
|
944
1063
|
stackIn: 2,
|
|
945
1064
|
stackOut: 1,
|
|
946
|
-
execute: (e$1,
|
|
1065
|
+
execute: (e$1, r) => g(e$1, r, (t2, s2) => {
|
|
947
1066
|
if (e(t2) && o(s2) || o(t2) && e(s2))
|
|
948
1067
|
return true;
|
|
949
1068
|
if (o(t2) && o(s2))
|
|
@@ -954,10 +1073,10 @@ const q = {
|
|
|
954
1073
|
}
|
|
955
1074
|
})
|
|
956
1075
|
},
|
|
957
|
-
[
|
|
1076
|
+
[n$1.NEQ]: {
|
|
958
1077
|
stackIn: 2,
|
|
959
1078
|
stackOut: 1,
|
|
960
|
-
execute: (e$1,
|
|
1079
|
+
execute: (e$1, r) => g(e$1, r, (t2, s2) => {
|
|
961
1080
|
if (e(t2) && o(s2) || o(t2) && e(s2))
|
|
962
1081
|
return false;
|
|
963
1082
|
if (o(t2) && o(s2))
|
|
@@ -968,100 +1087,100 @@ const q = {
|
|
|
968
1087
|
}
|
|
969
1088
|
})
|
|
970
1089
|
},
|
|
971
|
-
[
|
|
1090
|
+
[n$1.LT]: {
|
|
972
1091
|
stackIn: 2,
|
|
973
1092
|
stackOut: 1,
|
|
974
|
-
execute: (e2,
|
|
1093
|
+
execute: (e2, r) => g(e2, r, (t2, s2) => {
|
|
975
1094
|
const o2 = m(t2), n2 = m(s2);
|
|
976
1095
|
return o2 < n2;
|
|
977
1096
|
})
|
|
978
1097
|
},
|
|
979
|
-
[
|
|
1098
|
+
[n$1.GT]: {
|
|
980
1099
|
stackIn: 2,
|
|
981
1100
|
stackOut: 1,
|
|
982
|
-
execute: (e2,
|
|
1101
|
+
execute: (e2, r) => g(e2, r, (t2, s2) => {
|
|
983
1102
|
const o2 = m(t2), n2 = m(s2);
|
|
984
1103
|
return o2 > n2;
|
|
985
1104
|
})
|
|
986
1105
|
},
|
|
987
|
-
[
|
|
1106
|
+
[n$1.LTE]: {
|
|
988
1107
|
stackIn: 2,
|
|
989
1108
|
stackOut: 1,
|
|
990
|
-
execute: (e2,
|
|
1109
|
+
execute: (e2, r) => g(e2, r, (t2, s2) => {
|
|
991
1110
|
const o2 = m(t2), n2 = m(s2);
|
|
992
1111
|
return o2 <= n2;
|
|
993
1112
|
})
|
|
994
1113
|
},
|
|
995
|
-
[
|
|
1114
|
+
[n$1.GTE]: {
|
|
996
1115
|
stackIn: 2,
|
|
997
1116
|
stackOut: 1,
|
|
998
|
-
execute: (e2,
|
|
1117
|
+
execute: (e2, r) => g(e2, r, (t2, s2) => {
|
|
999
1118
|
const o2 = m(t2), n2 = m(s2);
|
|
1000
1119
|
return o2 >= n2;
|
|
1001
1120
|
})
|
|
1002
1121
|
},
|
|
1003
|
-
[
|
|
1122
|
+
[n$1.EQ_STRICT]: {
|
|
1004
1123
|
stackIn: 2,
|
|
1005
1124
|
stackOut: 1,
|
|
1006
|
-
execute: (e2,
|
|
1125
|
+
execute: (e2, r) => g(e2, r, (t2, s2) => t2 === s2)
|
|
1007
1126
|
},
|
|
1008
|
-
[
|
|
1127
|
+
[n$1.NEQ_STRICT]: {
|
|
1009
1128
|
stackIn: 2,
|
|
1010
1129
|
stackOut: 1,
|
|
1011
|
-
execute: (e2,
|
|
1130
|
+
execute: (e2, r) => g(e2, r, (t2, s2) => t2 !== s2)
|
|
1012
1131
|
}
|
|
1013
1132
|
}, H = {
|
|
1014
|
-
[
|
|
1133
|
+
[n$1.AND]: {
|
|
1015
1134
|
stackIn: 2,
|
|
1016
1135
|
stackOut: 1,
|
|
1017
|
-
execute: (e2,
|
|
1136
|
+
execute: (e2, r) => {
|
|
1018
1137
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b$1(s2) ? t2 : s2;
|
|
1019
1138
|
e2.stack.push(o2);
|
|
1020
1139
|
}
|
|
1021
1140
|
},
|
|
1022
|
-
[
|
|
1141
|
+
[n$1.OR]: {
|
|
1023
1142
|
stackIn: 2,
|
|
1024
1143
|
stackOut: 1,
|
|
1025
|
-
execute: (e2,
|
|
1144
|
+
execute: (e2, r) => {
|
|
1026
1145
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b$1(s2) ? s2 : t2;
|
|
1027
1146
|
e2.stack.push(o2);
|
|
1028
1147
|
}
|
|
1029
1148
|
},
|
|
1030
|
-
[
|
|
1149
|
+
[n$1.NOT]: {
|
|
1031
1150
|
stackIn: 1,
|
|
1032
1151
|
stackOut: 1,
|
|
1033
|
-
execute: (e2,
|
|
1152
|
+
execute: (e2, r) => {
|
|
1034
1153
|
const t2 = e2.stack.pop(), s2 = !b$1(t2);
|
|
1035
1154
|
e2.stack.push(s2);
|
|
1036
1155
|
}
|
|
1037
1156
|
}
|
|
1038
|
-
},
|
|
1039
|
-
[
|
|
1157
|
+
}, $ = {
|
|
1158
|
+
[n$1.ARRAY_NEW]: {
|
|
1040
1159
|
stackIn: 0,
|
|
1041
1160
|
stackOut: 1,
|
|
1042
|
-
execute: (e2,
|
|
1161
|
+
execute: (e2, r) => {
|
|
1043
1162
|
e2.stack.push(d());
|
|
1044
1163
|
}
|
|
1045
1164
|
},
|
|
1046
|
-
[
|
|
1165
|
+
[n$1.ARRAY_PUSH]: {
|
|
1047
1166
|
stackIn: 2,
|
|
1048
1167
|
stackOut: 1,
|
|
1049
|
-
execute: (e2,
|
|
1168
|
+
execute: (e2, r) => {
|
|
1050
1169
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1051
1170
|
if (!f(s2))
|
|
1052
1171
|
return {
|
|
1053
1172
|
type: "RuntimeError",
|
|
1054
1173
|
message: "ARRAY_PUSH requires an array",
|
|
1055
1174
|
pc: e2.pc,
|
|
1056
|
-
opcode:
|
|
1175
|
+
opcode: r.op
|
|
1057
1176
|
};
|
|
1058
1177
|
s2.elements.push(t2), e2.stack.push(s2);
|
|
1059
1178
|
}
|
|
1060
1179
|
},
|
|
1061
|
-
[
|
|
1180
|
+
[n$1.ARRAY_GET]: {
|
|
1062
1181
|
stackIn: 2,
|
|
1063
1182
|
stackOut: 1,
|
|
1064
|
-
execute: (e2,
|
|
1183
|
+
execute: (e2, r) => {
|
|
1065
1184
|
const t$1 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1066
1185
|
if (f(s2)) {
|
|
1067
1186
|
if (!t(t$1))
|
|
@@ -1069,19 +1188,19 @@ const q = {
|
|
|
1069
1188
|
type: "RuntimeError",
|
|
1070
1189
|
message: "ARRAY_GET requires numeric index for arrays",
|
|
1071
1190
|
pc: e2.pc,
|
|
1072
|
-
opcode:
|
|
1191
|
+
opcode: r.op
|
|
1073
1192
|
};
|
|
1074
1193
|
const o2 = s2.elements[t$1] ?? null;
|
|
1075
1194
|
e2.stack.push(o2);
|
|
1076
1195
|
return;
|
|
1077
1196
|
}
|
|
1078
|
-
if (c
|
|
1197
|
+
if (c(s2)) {
|
|
1079
1198
|
if (!n(t$1))
|
|
1080
1199
|
return {
|
|
1081
1200
|
type: "RuntimeError",
|
|
1082
1201
|
message: "ARRAY_GET requires string key for objects",
|
|
1083
1202
|
pc: e2.pc,
|
|
1084
|
-
opcode:
|
|
1203
|
+
opcode: r.op
|
|
1085
1204
|
};
|
|
1086
1205
|
const o2 = s2.properties[t$1] ?? null;
|
|
1087
1206
|
e2.stack.push(o2);
|
|
@@ -1091,14 +1210,14 @@ const q = {
|
|
|
1091
1210
|
type: "RuntimeError",
|
|
1092
1211
|
message: "ARRAY_GET requires an array or object",
|
|
1093
1212
|
pc: e2.pc,
|
|
1094
|
-
opcode:
|
|
1213
|
+
opcode: r.op
|
|
1095
1214
|
};
|
|
1096
1215
|
}
|
|
1097
1216
|
},
|
|
1098
|
-
[
|
|
1217
|
+
[n$1.ARRAY_SET]: {
|
|
1099
1218
|
stackIn: 3,
|
|
1100
1219
|
stackOut: 1,
|
|
1101
|
-
execute: (e2,
|
|
1220
|
+
execute: (e2, r) => {
|
|
1102
1221
|
const t$1 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1103
1222
|
if (f(o2)) {
|
|
1104
1223
|
if (!t(s2))
|
|
@@ -1106,7 +1225,7 @@ const q = {
|
|
|
1106
1225
|
type: "RuntimeError",
|
|
1107
1226
|
message: "ARRAY_SET requires numeric index for arrays",
|
|
1108
1227
|
pc: e2.pc,
|
|
1109
|
-
opcode:
|
|
1228
|
+
opcode: r.op
|
|
1110
1229
|
};
|
|
1111
1230
|
const n2 = Math.floor(s2);
|
|
1112
1231
|
if (n2 < 0)
|
|
@@ -1114,18 +1233,18 @@ const q = {
|
|
|
1114
1233
|
type: "RuntimeError",
|
|
1115
1234
|
message: "ARRAY_SET: Negative index not allowed",
|
|
1116
1235
|
pc: e2.pc,
|
|
1117
|
-
opcode:
|
|
1236
|
+
opcode: r.op
|
|
1118
1237
|
};
|
|
1119
1238
|
o2.elements[n2] = t$1, e2.stack.push(o2);
|
|
1120
1239
|
return;
|
|
1121
1240
|
}
|
|
1122
|
-
if (c
|
|
1241
|
+
if (c(o2)) {
|
|
1123
1242
|
if (!n(s2))
|
|
1124
1243
|
return {
|
|
1125
1244
|
type: "RuntimeError",
|
|
1126
1245
|
message: "ARRAY_SET requires string key for objects",
|
|
1127
1246
|
pc: e2.pc,
|
|
1128
|
-
opcode:
|
|
1247
|
+
opcode: r.op
|
|
1129
1248
|
};
|
|
1130
1249
|
o2.properties[s2] = t$1, e2.stack.push(o2);
|
|
1131
1250
|
return;
|
|
@@ -1134,74 +1253,74 @@ const q = {
|
|
|
1134
1253
|
type: "RuntimeError",
|
|
1135
1254
|
message: "ARRAY_SET requires an array or object",
|
|
1136
1255
|
pc: e2.pc,
|
|
1137
|
-
opcode:
|
|
1256
|
+
opcode: r.op
|
|
1138
1257
|
};
|
|
1139
1258
|
}
|
|
1140
1259
|
},
|
|
1141
|
-
[
|
|
1260
|
+
[n$1.ARRAY_LEN]: {
|
|
1142
1261
|
stackIn: 1,
|
|
1143
1262
|
stackOut: 1,
|
|
1144
|
-
execute: (e2,
|
|
1263
|
+
execute: (e2, r) => {
|
|
1145
1264
|
const t2 = e2.stack.pop();
|
|
1146
1265
|
if (!f(t2))
|
|
1147
1266
|
return {
|
|
1148
1267
|
type: "RuntimeError",
|
|
1149
1268
|
message: "ARRAY_LEN requires an array",
|
|
1150
1269
|
pc: e2.pc,
|
|
1151
|
-
opcode:
|
|
1270
|
+
opcode: r.op
|
|
1152
1271
|
};
|
|
1153
1272
|
e2.stack.push(t2.elements.length);
|
|
1154
1273
|
}
|
|
1155
1274
|
}
|
|
1156
1275
|
};
|
|
1157
|
-
function
|
|
1276
|
+
function T(e2) {
|
|
1158
1277
|
if (e2 === null) return null;
|
|
1159
1278
|
if (e2 !== void 0) {
|
|
1160
1279
|
if (typeof e2 == "string" || typeof e2 == "number" || typeof e2 == "boolean" || e2 && typeof e2 == "object" && e2.type === "array" && Array.isArray(e2.elements))
|
|
1161
1280
|
return e2;
|
|
1162
1281
|
if (Array.isArray(e2)) {
|
|
1163
|
-
const
|
|
1164
|
-
return
|
|
1282
|
+
const r = d();
|
|
1283
|
+
return r.elements = e2.map(T), r;
|
|
1165
1284
|
}
|
|
1166
1285
|
if (e2 && typeof e2 == "object" && e2.type === "object" && e2.properties)
|
|
1167
1286
|
return e2;
|
|
1168
1287
|
if (typeof e2 == "object") {
|
|
1169
|
-
const
|
|
1288
|
+
const r = j$1();
|
|
1170
1289
|
for (const [t2, s2] of Object.entries(e2))
|
|
1171
|
-
|
|
1172
|
-
return
|
|
1290
|
+
r.properties[t2] = T(s2);
|
|
1291
|
+
return r;
|
|
1173
1292
|
}
|
|
1174
1293
|
return null;
|
|
1175
1294
|
}
|
|
1176
1295
|
}
|
|
1177
|
-
const
|
|
1178
|
-
[
|
|
1296
|
+
const J = {
|
|
1297
|
+
[n$1.CONCAT]: {
|
|
1179
1298
|
stackIn: 2,
|
|
1180
1299
|
stackOut: 1,
|
|
1181
|
-
execute: (e2,
|
|
1300
|
+
execute: (e2, r) => {
|
|
1182
1301
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1183
1302
|
e2.stack.push(y(s2) + y(t2));
|
|
1184
1303
|
}
|
|
1185
1304
|
},
|
|
1186
|
-
[
|
|
1305
|
+
[n$1.STRING_LEN]: {
|
|
1187
1306
|
stackIn: 1,
|
|
1188
1307
|
stackOut: 1,
|
|
1189
|
-
execute: (e2,
|
|
1308
|
+
execute: (e2, r) => {
|
|
1190
1309
|
const t2 = e2.stack.pop();
|
|
1191
1310
|
if (!n(t2))
|
|
1192
1311
|
return {
|
|
1193
1312
|
type: "RuntimeError",
|
|
1194
1313
|
message: "STRING_LEN requires a string",
|
|
1195
1314
|
pc: e2.pc,
|
|
1196
|
-
opcode:
|
|
1315
|
+
opcode: r.op
|
|
1197
1316
|
};
|
|
1198
1317
|
e2.stack.push(t2.length);
|
|
1199
1318
|
}
|
|
1200
1319
|
},
|
|
1201
|
-
[
|
|
1320
|
+
[n$1.LENGTH]: {
|
|
1202
1321
|
stackIn: 1,
|
|
1203
1322
|
stackOut: 1,
|
|
1204
|
-
execute: (e2,
|
|
1323
|
+
execute: (e2, r) => {
|
|
1205
1324
|
const t2 = e2.stack.pop();
|
|
1206
1325
|
if (n(t2))
|
|
1207
1326
|
e2.stack.push(t2.length);
|
|
@@ -1212,143 +1331,143 @@ const $ = {
|
|
|
1212
1331
|
type: "RuntimeError",
|
|
1213
1332
|
message: "LENGTH requires a string or array",
|
|
1214
1333
|
pc: e2.pc,
|
|
1215
|
-
opcode:
|
|
1334
|
+
opcode: r.op
|
|
1216
1335
|
};
|
|
1217
1336
|
}
|
|
1218
1337
|
},
|
|
1219
|
-
[
|
|
1338
|
+
[n$1.JSON_PARSE]: {
|
|
1220
1339
|
stackIn: 1,
|
|
1221
1340
|
stackOut: 1,
|
|
1222
|
-
execute: (e2,
|
|
1341
|
+
execute: (e2, r) => {
|
|
1223
1342
|
const t2 = e2.stack.pop();
|
|
1224
1343
|
if (!n(t2))
|
|
1225
1344
|
return {
|
|
1226
1345
|
type: "RuntimeError",
|
|
1227
1346
|
message: "JSON_PARSE requires a string",
|
|
1228
1347
|
pc: e2.pc,
|
|
1229
|
-
opcode:
|
|
1348
|
+
opcode: r.op
|
|
1230
1349
|
};
|
|
1231
1350
|
try {
|
|
1232
1351
|
const s2 = JSON.parse(t2);
|
|
1233
|
-
e2.stack.push(
|
|
1352
|
+
e2.stack.push(T(s2));
|
|
1234
1353
|
} catch {
|
|
1235
1354
|
e2.stack.push(null);
|
|
1236
1355
|
}
|
|
1237
1356
|
}
|
|
1238
1357
|
},
|
|
1239
|
-
[
|
|
1358
|
+
[n$1.TYPEOF]: {
|
|
1240
1359
|
stackIn: 1,
|
|
1241
1360
|
stackOut: 1,
|
|
1242
|
-
execute: (e2,
|
|
1361
|
+
execute: (e2, r) => {
|
|
1243
1362
|
const t2 = e2.stack.pop();
|
|
1244
|
-
e2.stack.push(p
|
|
1363
|
+
e2.stack.push(p(t2));
|
|
1245
1364
|
}
|
|
1246
1365
|
}
|
|
1247
|
-
},
|
|
1248
|
-
[
|
|
1366
|
+
}, Y = {
|
|
1367
|
+
[n$1.INC]: {
|
|
1249
1368
|
stackIn: 1,
|
|
1250
1369
|
stackOut: 1,
|
|
1251
|
-
execute: (e2,
|
|
1370
|
+
execute: (e2, r) => {
|
|
1252
1371
|
const t2 = e2.stack.pop();
|
|
1253
1372
|
if (typeof t2 != "string")
|
|
1254
1373
|
return {
|
|
1255
1374
|
type: "RuntimeError",
|
|
1256
1375
|
message: "INC: Invalid variable name",
|
|
1257
1376
|
pc: e2.pc,
|
|
1258
|
-
opcode:
|
|
1377
|
+
opcode: r.op
|
|
1259
1378
|
};
|
|
1260
1379
|
const s2 = e2.variables.get(t2) ?? 0, o2 = m(s2) + 1;
|
|
1261
1380
|
e2.variables.set(t2, o2);
|
|
1262
|
-
const n2 =
|
|
1381
|
+
const n2 = r.arg === true;
|
|
1263
1382
|
e2.stack.push(n2 ? m(s2) : o2);
|
|
1264
1383
|
}
|
|
1265
1384
|
},
|
|
1266
|
-
[
|
|
1385
|
+
[n$1.DEC]: {
|
|
1267
1386
|
stackIn: 1,
|
|
1268
1387
|
stackOut: 1,
|
|
1269
|
-
execute: (e2,
|
|
1388
|
+
execute: (e2, r) => {
|
|
1270
1389
|
const t2 = e2.stack.pop();
|
|
1271
1390
|
if (typeof t2 != "string")
|
|
1272
1391
|
return {
|
|
1273
1392
|
type: "RuntimeError",
|
|
1274
1393
|
message: "DEC: Invalid variable name",
|
|
1275
1394
|
pc: e2.pc,
|
|
1276
|
-
opcode:
|
|
1395
|
+
opcode: r.op
|
|
1277
1396
|
};
|
|
1278
1397
|
const s2 = e2.variables.get(t2) ?? 0, o2 = m(s2) - 1;
|
|
1279
1398
|
e2.variables.set(t2, o2);
|
|
1280
|
-
const n2 =
|
|
1399
|
+
const n2 = r.arg === true;
|
|
1281
1400
|
e2.stack.push(n2 ? m(s2) : o2);
|
|
1282
1401
|
}
|
|
1283
1402
|
}
|
|
1284
|
-
},
|
|
1285
|
-
[
|
|
1403
|
+
}, B = {
|
|
1404
|
+
[n$1.RETURN]: {
|
|
1286
1405
|
stackIn: 0,
|
|
1287
1406
|
stackOut: 0,
|
|
1288
1407
|
controlsPC: true,
|
|
1289
|
-
execute: (e2,
|
|
1408
|
+
execute: (e2, r) => {
|
|
1290
1409
|
const t2 = e2.stack.pop() ?? null;
|
|
1291
1410
|
e2.returnValue = t2, e2.status = "complete";
|
|
1292
1411
|
}
|
|
1293
1412
|
},
|
|
1294
|
-
[
|
|
1413
|
+
[n$1.BREAK]: {
|
|
1295
1414
|
stackIn: 0,
|
|
1296
1415
|
stackOut: 0,
|
|
1297
1416
|
controlsPC: true,
|
|
1298
|
-
execute: (e2,
|
|
1299
|
-
if (
|
|
1417
|
+
execute: (e2, r) => {
|
|
1418
|
+
if (r.arg === void 0)
|
|
1300
1419
|
return {
|
|
1301
1420
|
type: "RuntimeError",
|
|
1302
1421
|
message: "BREAK requires a target address",
|
|
1303
1422
|
pc: e2.pc,
|
|
1304
|
-
opcode:
|
|
1423
|
+
opcode: r.op
|
|
1305
1424
|
};
|
|
1306
|
-
const t2 =
|
|
1425
|
+
const t2 = r.arg;
|
|
1307
1426
|
if (t2 < 0)
|
|
1308
1427
|
return {
|
|
1309
1428
|
type: "RuntimeError",
|
|
1310
1429
|
message: `Invalid break target: ${t2}`,
|
|
1311
1430
|
pc: e2.pc,
|
|
1312
|
-
opcode:
|
|
1431
|
+
opcode: r.op
|
|
1313
1432
|
};
|
|
1314
1433
|
e2.pc = t2;
|
|
1315
1434
|
}
|
|
1316
1435
|
},
|
|
1317
|
-
[
|
|
1436
|
+
[n$1.CONTINUE]: {
|
|
1318
1437
|
stackIn: 0,
|
|
1319
1438
|
stackOut: 0,
|
|
1320
1439
|
controlsPC: true,
|
|
1321
|
-
execute: (e2,
|
|
1322
|
-
if (
|
|
1440
|
+
execute: (e2, r) => {
|
|
1441
|
+
if (r.arg === void 0)
|
|
1323
1442
|
return {
|
|
1324
1443
|
type: "RuntimeError",
|
|
1325
1444
|
message: "CONTINUE requires a target address",
|
|
1326
1445
|
pc: e2.pc,
|
|
1327
|
-
opcode:
|
|
1446
|
+
opcode: r.op
|
|
1328
1447
|
};
|
|
1329
|
-
const t2 =
|
|
1448
|
+
const t2 = r.arg;
|
|
1330
1449
|
if (t2 < 0)
|
|
1331
1450
|
return {
|
|
1332
1451
|
type: "RuntimeError",
|
|
1333
1452
|
message: `Invalid continue target: ${t2}`,
|
|
1334
1453
|
pc: e2.pc,
|
|
1335
|
-
opcode:
|
|
1454
|
+
opcode: r.op
|
|
1336
1455
|
};
|
|
1337
1456
|
e2.pc = t2;
|
|
1338
1457
|
}
|
|
1339
1458
|
},
|
|
1340
|
-
[
|
|
1459
|
+
[n$1.FS_LIST_FILES]: {
|
|
1341
1460
|
stackIn: 1,
|
|
1342
1461
|
// Minimum 1 argument (path), optionally 2 (path + options)
|
|
1343
1462
|
stackOut: 0,
|
|
1344
1463
|
controlsPC: true,
|
|
1345
|
-
execute: (e2,
|
|
1464
|
+
execute: (e2, r) => {
|
|
1346
1465
|
if (e2.stack.length < 1)
|
|
1347
1466
|
return {
|
|
1348
1467
|
type: "StackUnderflow",
|
|
1349
1468
|
message: "FS_LIST_FILES: Stack underflow",
|
|
1350
1469
|
pc: e2.pc,
|
|
1351
|
-
opcode:
|
|
1470
|
+
opcode: r.op
|
|
1352
1471
|
};
|
|
1353
1472
|
let t2, s2 = {};
|
|
1354
1473
|
const o2 = e2.stack[e2.stack.length - 1];
|
|
@@ -1357,7 +1476,7 @@ const $ = {
|
|
|
1357
1476
|
type: "RuntimeError",
|
|
1358
1477
|
message: "FS_LIST_FILES requires a string path",
|
|
1359
1478
|
pc: e2.pc,
|
|
1360
|
-
opcode:
|
|
1479
|
+
opcode: r.op
|
|
1361
1480
|
};
|
|
1362
1481
|
e2.fsOperation = {
|
|
1363
1482
|
type: "listFiles",
|
|
@@ -1367,17 +1486,17 @@ const $ = {
|
|
|
1367
1486
|
}
|
|
1368
1487
|
},
|
|
1369
1488
|
// String method handlers
|
|
1370
|
-
[
|
|
1489
|
+
[n$1.STRING_SUBSTRING]: {
|
|
1371
1490
|
stackIn: 2,
|
|
1372
1491
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
1373
1492
|
stackOut: 1,
|
|
1374
|
-
execute: (e2,
|
|
1493
|
+
execute: (e2, r) => {
|
|
1375
1494
|
if (e2.stack.length < 2)
|
|
1376
1495
|
return {
|
|
1377
1496
|
type: "StackUnderflow",
|
|
1378
1497
|
message: "STRING_SUBSTRING: Stack underflow",
|
|
1379
1498
|
pc: e2.pc,
|
|
1380
|
-
opcode:
|
|
1499
|
+
opcode: r.op
|
|
1381
1500
|
};
|
|
1382
1501
|
const t2 = e2.stack.length;
|
|
1383
1502
|
let s2, o2, n$12;
|
|
@@ -1387,63 +1506,63 @@ const $ = {
|
|
|
1387
1506
|
type: "RuntimeError",
|
|
1388
1507
|
message: "STRING_SUBSTRING requires a string",
|
|
1389
1508
|
pc: e2.pc,
|
|
1390
|
-
opcode:
|
|
1509
|
+
opcode: r.op
|
|
1391
1510
|
};
|
|
1392
1511
|
if (typeof o2 != "number")
|
|
1393
1512
|
return {
|
|
1394
1513
|
type: "RuntimeError",
|
|
1395
1514
|
message: "STRING_SUBSTRING requires numeric start index",
|
|
1396
1515
|
pc: e2.pc,
|
|
1397
|
-
opcode:
|
|
1516
|
+
opcode: r.op
|
|
1398
1517
|
};
|
|
1399
1518
|
const u2 = s2.length;
|
|
1400
1519
|
o2 < 0 && (o2 = Math.max(0, u2 + o2)), n$12 !== void 0 && n$12 < 0 && (n$12 = Math.max(0, u2 + n$12));
|
|
1401
|
-
const
|
|
1402
|
-
e2.stack.push(
|
|
1520
|
+
const O2 = n$12 !== void 0 ? s2.substring(o2, n$12) : s2.substring(o2);
|
|
1521
|
+
e2.stack.push(O2);
|
|
1403
1522
|
}
|
|
1404
1523
|
},
|
|
1405
|
-
[
|
|
1524
|
+
[n$1.STRING_INDEXOF]: {
|
|
1406
1525
|
stackIn: 2,
|
|
1407
1526
|
stackOut: 1,
|
|
1408
|
-
execute: (e2,
|
|
1527
|
+
execute: (e2, r) => {
|
|
1409
1528
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1410
1529
|
if (!n(s2) || !n(t2))
|
|
1411
1530
|
return {
|
|
1412
1531
|
type: "RuntimeError",
|
|
1413
1532
|
message: "STRING_INDEXOF requires string arguments",
|
|
1414
1533
|
pc: e2.pc,
|
|
1415
|
-
opcode:
|
|
1534
|
+
opcode: r.op
|
|
1416
1535
|
};
|
|
1417
1536
|
e2.stack.push(s2.indexOf(t2));
|
|
1418
1537
|
}
|
|
1419
1538
|
},
|
|
1420
|
-
[
|
|
1539
|
+
[n$1.STRING_SPLIT]: {
|
|
1421
1540
|
stackIn: 2,
|
|
1422
1541
|
stackOut: 1,
|
|
1423
|
-
execute: (e2,
|
|
1542
|
+
execute: (e2, r) => {
|
|
1424
1543
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1425
1544
|
if (!n(s2) || !n(t2))
|
|
1426
1545
|
return {
|
|
1427
1546
|
type: "RuntimeError",
|
|
1428
1547
|
message: "STRING_SPLIT requires string arguments",
|
|
1429
1548
|
pc: e2.pc,
|
|
1430
|
-
opcode:
|
|
1549
|
+
opcode: r.op
|
|
1431
1550
|
};
|
|
1432
1551
|
let o2;
|
|
1433
1552
|
t2 === "" ? o2 = s2.split("") : o2 = s2.split(t2), e2.stack.push(d(o2));
|
|
1434
1553
|
}
|
|
1435
1554
|
},
|
|
1436
|
-
[
|
|
1555
|
+
[n$1.STRING_SLICE]: {
|
|
1437
1556
|
stackIn: 2,
|
|
1438
1557
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
1439
1558
|
stackOut: 1,
|
|
1440
|
-
execute: (e2,
|
|
1559
|
+
execute: (e2, r) => {
|
|
1441
1560
|
if (e2.stack.length < 2)
|
|
1442
1561
|
return {
|
|
1443
1562
|
type: "StackUnderflow",
|
|
1444
1563
|
message: "STRING_SLICE: Stack underflow",
|
|
1445
1564
|
pc: e2.pc,
|
|
1446
|
-
opcode:
|
|
1565
|
+
opcode: r.op
|
|
1447
1566
|
};
|
|
1448
1567
|
const t2 = e2.stack.length;
|
|
1449
1568
|
let s2, o2, n$12;
|
|
@@ -1453,169 +1572,185 @@ const $ = {
|
|
|
1453
1572
|
type: "RuntimeError",
|
|
1454
1573
|
message: "STRING_SLICE requires a string",
|
|
1455
1574
|
pc: e2.pc,
|
|
1456
|
-
opcode:
|
|
1575
|
+
opcode: r.op
|
|
1457
1576
|
};
|
|
1458
1577
|
if (typeof o2 != "number")
|
|
1459
1578
|
return {
|
|
1460
1579
|
type: "RuntimeError",
|
|
1461
1580
|
message: "STRING_SLICE requires numeric start index",
|
|
1462
1581
|
pc: e2.pc,
|
|
1463
|
-
opcode:
|
|
1582
|
+
opcode: r.op
|
|
1464
1583
|
};
|
|
1465
1584
|
const u2 = n$12 !== void 0 ? s2.slice(o2, n$12) : s2.slice(o2);
|
|
1466
1585
|
e2.stack.push(u2);
|
|
1467
1586
|
}
|
|
1468
1587
|
},
|
|
1469
|
-
[
|
|
1588
|
+
[n$1.STRING_CHARAT]: {
|
|
1470
1589
|
stackIn: 2,
|
|
1471
1590
|
stackOut: 1,
|
|
1472
|
-
execute: (e2,
|
|
1591
|
+
execute: (e2, r) => {
|
|
1473
1592
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1474
1593
|
if (!n(s2))
|
|
1475
1594
|
return {
|
|
1476
1595
|
type: "RuntimeError",
|
|
1477
1596
|
message: "STRING_CHARAT requires a string",
|
|
1478
1597
|
pc: e2.pc,
|
|
1479
|
-
opcode:
|
|
1598
|
+
opcode: r.op
|
|
1480
1599
|
};
|
|
1481
1600
|
if (typeof t2 != "number")
|
|
1482
1601
|
return {
|
|
1483
1602
|
type: "RuntimeError",
|
|
1484
1603
|
message: "STRING_CHARAT requires numeric index",
|
|
1485
1604
|
pc: e2.pc,
|
|
1486
|
-
opcode:
|
|
1605
|
+
opcode: r.op
|
|
1487
1606
|
};
|
|
1488
1607
|
const o2 = s2.charAt(t2);
|
|
1489
1608
|
e2.stack.push(o2);
|
|
1490
1609
|
}
|
|
1491
1610
|
},
|
|
1492
|
-
[
|
|
1611
|
+
[n$1.STRING_TOUPPERCASE]: {
|
|
1493
1612
|
stackIn: 1,
|
|
1494
1613
|
stackOut: 1,
|
|
1495
|
-
execute: (e2,
|
|
1614
|
+
execute: (e2, r) => {
|
|
1496
1615
|
const t2 = e2.stack.pop();
|
|
1497
1616
|
if (!n(t2))
|
|
1498
1617
|
return {
|
|
1499
1618
|
type: "RuntimeError",
|
|
1500
1619
|
message: "STRING_TOUPPERCASE requires a string",
|
|
1501
1620
|
pc: e2.pc,
|
|
1502
|
-
opcode:
|
|
1621
|
+
opcode: r.op
|
|
1503
1622
|
};
|
|
1504
1623
|
e2.stack.push(t2.toUpperCase());
|
|
1505
1624
|
}
|
|
1506
1625
|
},
|
|
1507
|
-
[
|
|
1626
|
+
[n$1.STRING_TOLOWERCASE]: {
|
|
1508
1627
|
stackIn: 1,
|
|
1509
1628
|
stackOut: 1,
|
|
1510
|
-
execute: (e2,
|
|
1629
|
+
execute: (e2, r) => {
|
|
1511
1630
|
const t2 = e2.stack.pop();
|
|
1512
1631
|
if (!n(t2))
|
|
1513
1632
|
return {
|
|
1514
1633
|
type: "RuntimeError",
|
|
1515
1634
|
message: "STRING_TOLOWERCASE requires a string",
|
|
1516
1635
|
pc: e2.pc,
|
|
1517
|
-
opcode:
|
|
1636
|
+
opcode: r.op
|
|
1518
1637
|
};
|
|
1519
1638
|
e2.stack.push(t2.toLowerCase());
|
|
1520
1639
|
}
|
|
1640
|
+
},
|
|
1641
|
+
[n$1.TO_STRING]: {
|
|
1642
|
+
stackIn: 1,
|
|
1643
|
+
stackOut: 1,
|
|
1644
|
+
execute: (e2, r) => {
|
|
1645
|
+
const t2 = e2.stack.pop();
|
|
1646
|
+
if (t2 === void 0)
|
|
1647
|
+
return {
|
|
1648
|
+
type: "StackUnderflow",
|
|
1649
|
+
message: "TO_STRING: Stack underflow",
|
|
1650
|
+
pc: e2.pc,
|
|
1651
|
+
opcode: r.op
|
|
1652
|
+
};
|
|
1653
|
+
const s2 = y(t2);
|
|
1654
|
+
e2.stack.push(s2);
|
|
1655
|
+
}
|
|
1521
1656
|
}
|
|
1522
1657
|
};
|
|
1523
1658
|
function _(e2) {
|
|
1524
1659
|
if (f(e2))
|
|
1525
1660
|
return e2.elements.map(_);
|
|
1526
|
-
if (c
|
|
1527
|
-
const
|
|
1661
|
+
if (c(e2)) {
|
|
1662
|
+
const r = {};
|
|
1528
1663
|
for (const [t2, s2] of Object.entries(e2.properties))
|
|
1529
|
-
|
|
1530
|
-
return
|
|
1664
|
+
r[t2] = _(s2);
|
|
1665
|
+
return r;
|
|
1531
1666
|
}
|
|
1532
1667
|
if (!o(e2))
|
|
1533
1668
|
return e2;
|
|
1534
1669
|
}
|
|
1535
1670
|
const W = {
|
|
1536
|
-
[
|
|
1671
|
+
[n$1.OBJECT_CREATE]: {
|
|
1537
1672
|
stackIn: 0,
|
|
1538
1673
|
stackOut: 1,
|
|
1539
1674
|
execute: (e2) => {
|
|
1540
1675
|
e2.stack.push(j$1());
|
|
1541
1676
|
}
|
|
1542
1677
|
},
|
|
1543
|
-
[
|
|
1678
|
+
[n$1.PROPERTY_SET]: {
|
|
1544
1679
|
stackIn: 3,
|
|
1545
1680
|
stackOut: 1,
|
|
1546
|
-
execute: (e2,
|
|
1681
|
+
execute: (e2, r) => {
|
|
1547
1682
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1548
|
-
if (!c
|
|
1683
|
+
if (!c(o2))
|
|
1549
1684
|
return {
|
|
1550
1685
|
type: "RuntimeError",
|
|
1551
|
-
message: `Cannot set property '${s2}' on ${p
|
|
1686
|
+
message: `Cannot set property '${s2}' on ${p(o2)}`,
|
|
1552
1687
|
pc: e2.pc,
|
|
1553
|
-
opcode:
|
|
1688
|
+
opcode: r.op
|
|
1554
1689
|
};
|
|
1555
1690
|
if (!n(s2))
|
|
1556
1691
|
return {
|
|
1557
1692
|
type: "RuntimeError",
|
|
1558
1693
|
message: "Property key must be a string",
|
|
1559
1694
|
pc: e2.pc,
|
|
1560
|
-
opcode:
|
|
1695
|
+
opcode: r.op
|
|
1561
1696
|
};
|
|
1562
1697
|
o2.properties[s2] = t2, e2.stack.push(o2);
|
|
1563
1698
|
}
|
|
1564
1699
|
},
|
|
1565
|
-
[
|
|
1700
|
+
[n$1.PROPERTY_GET]: {
|
|
1566
1701
|
stackIn: 2,
|
|
1567
1702
|
stackOut: 1,
|
|
1568
|
-
execute: (e$1,
|
|
1569
|
-
const t2 = e$1.stack.pop(),
|
|
1570
|
-
if (e(
|
|
1703
|
+
execute: (e$1, r) => {
|
|
1704
|
+
const t2 = e$1.stack.pop(), s$1 = e$1.stack.pop();
|
|
1705
|
+
if (e(s$1) || o(s$1))
|
|
1571
1706
|
return {
|
|
1572
1707
|
type: "RuntimeError",
|
|
1573
|
-
message: `Cannot read property '${t2}' of ${p$1
|
|
1708
|
+
message: `Cannot read property '${t2}' of ${p(s$1)}`,
|
|
1574
1709
|
pc: e$1.pc,
|
|
1575
|
-
opcode:
|
|
1710
|
+
opcode: r.op
|
|
1576
1711
|
};
|
|
1577
|
-
if (!c$1
|
|
1578
|
-
e$1.stack.push(s
|
|
1712
|
+
if (!c(s$1)) {
|
|
1713
|
+
e$1.stack.push(s());
|
|
1579
1714
|
return;
|
|
1580
1715
|
}
|
|
1581
|
-
const o$1 =
|
|
1582
|
-
e$1.stack.push(o$1 ?? s
|
|
1716
|
+
const o$1 = s$1.properties[y(t2)];
|
|
1717
|
+
e$1.stack.push(o$1 ?? s());
|
|
1583
1718
|
}
|
|
1584
1719
|
},
|
|
1585
|
-
[
|
|
1720
|
+
[n$1.JSON_STRINGIFY]: {
|
|
1586
1721
|
stackIn: 1,
|
|
1587
1722
|
stackOut: 1,
|
|
1588
1723
|
execute: (e2) => {
|
|
1589
|
-
const
|
|
1724
|
+
const r = e2.stack.pop(), t2 = _(r);
|
|
1590
1725
|
e2.stack.push(JSON.stringify(t2));
|
|
1591
1726
|
}
|
|
1592
1727
|
}
|
|
1593
1728
|
}, z = {
|
|
1729
|
+
...G,
|
|
1594
1730
|
...L,
|
|
1595
1731
|
...V,
|
|
1596
|
-
...M,
|
|
1597
|
-
...j,
|
|
1598
1732
|
...F,
|
|
1733
|
+
...j,
|
|
1599
1734
|
...D,
|
|
1600
1735
|
...q,
|
|
1601
1736
|
...H,
|
|
1602
|
-
...Y,
|
|
1603
1737
|
...$,
|
|
1604
|
-
...B,
|
|
1605
1738
|
...J,
|
|
1739
|
+
...Y,
|
|
1740
|
+
...B,
|
|
1606
1741
|
...W
|
|
1607
1742
|
};
|
|
1608
1743
|
class N {
|
|
1609
|
-
validateStack(
|
|
1610
|
-
if (s2.stack.length <
|
|
1744
|
+
validateStack(r, t2, s2) {
|
|
1745
|
+
if (s2.stack.length < r.stackIn)
|
|
1611
1746
|
return {
|
|
1612
1747
|
type: "StackUnderflow",
|
|
1613
|
-
message: `${
|
|
1748
|
+
message: `${n$1[t2.op]}: Stack underflow`,
|
|
1614
1749
|
pc: s2.pc,
|
|
1615
1750
|
opcode: t2.op
|
|
1616
1751
|
};
|
|
1617
1752
|
}
|
|
1618
|
-
execute(
|
|
1753
|
+
execute(r, t2) {
|
|
1619
1754
|
const s2 = {
|
|
1620
1755
|
pc: (t2 == null ? void 0 : t2.pc) ?? 0,
|
|
1621
1756
|
stack: (t2 == null ? void 0 : t2.stack) ?? [],
|
|
@@ -1625,17 +1760,17 @@ class N {
|
|
|
1625
1760
|
iterators: (t2 == null ? void 0 : t2.iterators) ?? [],
|
|
1626
1761
|
...t2
|
|
1627
1762
|
};
|
|
1628
|
-
for (; s2.status === "running" && s2.pc <
|
|
1629
|
-
const o2 =
|
|
1763
|
+
for (; s2.status === "running" && s2.pc < r.length; ) {
|
|
1764
|
+
const o2 = r[s2.pc], n2 = z[o2.op];
|
|
1630
1765
|
if (n2) {
|
|
1631
1766
|
const a2 = this.validateStack(n2, o2, s2);
|
|
1632
1767
|
if (a2) {
|
|
1633
1768
|
s2.status = "error", s2.error = a2.message;
|
|
1634
1769
|
break;
|
|
1635
1770
|
}
|
|
1636
|
-
if ((o2.op ===
|
|
1771
|
+
if ((o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.JUMP_IF || o2.op === n$1.JUMP_IF_TRUE || o2.op === n$1.BREAK || o2.op === n$1.CONTINUE) && o2.arg !== void 0 && o2.arg >= r.length) {
|
|
1637
1772
|
s2.status = "error";
|
|
1638
|
-
const u2 = o2.op ===
|
|
1773
|
+
const u2 = o2.op === n$1.JUMP || o2.op === n$1.JUMP_IF_FALSE || o2.op === n$1.JUMP_IF || o2.op === n$1.JUMP_IF_TRUE ? "jump" : o2.op === n$1.BREAK ? "break" : "continue";
|
|
1639
1774
|
s2.error = `Invalid ${u2} target: ${o2.arg}`;
|
|
1640
1775
|
break;
|
|
1641
1776
|
}
|
|
@@ -1647,86 +1782,86 @@ class N {
|
|
|
1647
1782
|
n2.controlsPC || s2.pc++;
|
|
1648
1783
|
continue;
|
|
1649
1784
|
}
|
|
1650
|
-
s2.status = "error", s2.error = `Unknown opcode: ${
|
|
1785
|
+
s2.status = "error", s2.error = `Unknown opcode: ${n$1[o2.op]}`;
|
|
1651
1786
|
break;
|
|
1652
1787
|
}
|
|
1653
1788
|
return s2;
|
|
1654
1789
|
}
|
|
1655
|
-
resume(
|
|
1656
|
-
if (
|
|
1790
|
+
resume(r, t2, s2) {
|
|
1791
|
+
if (r.status !== "waiting_cc")
|
|
1657
1792
|
throw new Error("Cannot resume: VM not waiting for CC");
|
|
1658
1793
|
const o2 = {
|
|
1659
|
-
...
|
|
1660
|
-
stack: [...
|
|
1794
|
+
...r,
|
|
1795
|
+
stack: [...r.stack, t2],
|
|
1661
1796
|
status: "running",
|
|
1662
1797
|
ccPrompt: void 0,
|
|
1663
|
-
pc:
|
|
1798
|
+
pc: r.pc + 1
|
|
1664
1799
|
};
|
|
1665
1800
|
return this.execute(s2, o2);
|
|
1666
1801
|
}
|
|
1667
|
-
resumeWithFsResult(
|
|
1668
|
-
if (
|
|
1802
|
+
resumeWithFsResult(r, t2, s2) {
|
|
1803
|
+
if (r.status !== "waiting_fs")
|
|
1669
1804
|
throw new Error("Cannot resume: VM not waiting for FS operation");
|
|
1670
1805
|
const o2 = {
|
|
1671
|
-
...
|
|
1672
|
-
stack: [...
|
|
1806
|
+
...r,
|
|
1807
|
+
stack: [...r.stack, t2],
|
|
1673
1808
|
status: "running",
|
|
1674
1809
|
fsOperation: void 0,
|
|
1675
|
-
pc:
|
|
1810
|
+
pc: r.pc + 1
|
|
1676
1811
|
};
|
|
1677
1812
|
return this.execute(s2, o2);
|
|
1678
1813
|
}
|
|
1679
1814
|
}
|
|
1680
|
-
class
|
|
1815
|
+
class P {
|
|
1681
1816
|
constructor() {
|
|
1682
1817
|
h2(this, "sandboxPaths", []);
|
|
1683
|
-
const
|
|
1684
|
-
|
|
1818
|
+
const r = process.env.CVM_SANDBOX_PATHS, t2 = process.env.CVM_SANDBOX_ROOT;
|
|
1819
|
+
r ? this.sandboxPaths = r.split(",").map((s2) => c__namespace.resolve(s2.trim())) : t2 && (this.sandboxPaths = [c__namespace.resolve(t2)]);
|
|
1685
1820
|
}
|
|
1686
|
-
isPathAllowed(
|
|
1687
|
-
const t2 = c__namespace.resolve(
|
|
1821
|
+
isPathAllowed(r) {
|
|
1822
|
+
const t2 = c__namespace.resolve(r);
|
|
1688
1823
|
return t2.includes("..") || this.sandboxPaths.length === 0 ? false : this.sandboxPaths.some(
|
|
1689
1824
|
(s2) => t2.startsWith(s2)
|
|
1690
1825
|
);
|
|
1691
1826
|
}
|
|
1692
|
-
listFiles(
|
|
1827
|
+
listFiles(r, t2 = {}) {
|
|
1693
1828
|
const s2 = d();
|
|
1694
|
-
if (!this.isPathAllowed(
|
|
1829
|
+
if (!this.isPathAllowed(r))
|
|
1695
1830
|
return s2;
|
|
1696
1831
|
try {
|
|
1697
|
-
const o2 = c__namespace.resolve(
|
|
1832
|
+
const o2 = c__namespace.resolve(r);
|
|
1698
1833
|
this.listFilesRecursive(o2, o2, s2.elements, t2);
|
|
1699
1834
|
} catch {
|
|
1700
1835
|
}
|
|
1701
1836
|
return s2;
|
|
1702
1837
|
}
|
|
1703
|
-
matchesPattern(
|
|
1838
|
+
matchesPattern(r, t2) {
|
|
1704
1839
|
let s2 = t2.replace(/\./g, "\\.").replace(/\*\*/g, "__DOUBLESTAR__").replace(/\*/g, "[^/]*").replace(/__DOUBLESTAR__/g, ".*").replace(/\?/g, ".");
|
|
1705
1840
|
s2 = "^" + s2 + "$";
|
|
1706
1841
|
try {
|
|
1707
|
-
return new RegExp(s2).test(
|
|
1842
|
+
return new RegExp(s2).test(r);
|
|
1708
1843
|
} catch {
|
|
1709
1844
|
return true;
|
|
1710
1845
|
}
|
|
1711
1846
|
}
|
|
1712
|
-
listFilesRecursive(
|
|
1847
|
+
listFilesRecursive(r, t2, s2, o2, n2 = 0) {
|
|
1713
1848
|
try {
|
|
1714
|
-
const a2 =
|
|
1849
|
+
const a2 = M__namespace.readdirSync(t2, { withFileTypes: true });
|
|
1715
1850
|
for (const i2 of a2) {
|
|
1716
|
-
const u2 = c__namespace.join(t2, i2.name),
|
|
1717
|
-
i2.isSymbolicLink() || o2.filter && !this.matchesPattern(
|
|
1851
|
+
const u2 = c__namespace.join(t2, i2.name), O2 = c__namespace.relative(r, u2);
|
|
1852
|
+
i2.isSymbolicLink() || o2.filter && !this.matchesPattern(O2, o2.filter) || (s2.push(u2), i2.isDirectory() && o2.recursive && this.listFilesRecursive(r, u2, s2, o2, n2 + 1));
|
|
1718
1853
|
}
|
|
1719
1854
|
} catch {
|
|
1720
1855
|
}
|
|
1721
1856
|
}
|
|
1722
1857
|
}
|
|
1723
|
-
new
|
|
1858
|
+
new P();
|
|
1724
1859
|
class te {
|
|
1725
|
-
constructor(
|
|
1860
|
+
constructor(r, t2) {
|
|
1726
1861
|
h2(this, "vms", /* @__PURE__ */ new Map());
|
|
1727
1862
|
h2(this, "storage");
|
|
1728
1863
|
h2(this, "fileSystem");
|
|
1729
|
-
|
|
1864
|
+
r ? this.storage = r : this.storage = E.create(), this.fileSystem = t2 || new P();
|
|
1730
1865
|
}
|
|
1731
1866
|
/**
|
|
1732
1867
|
* Initialize the VMManager (connect to database)
|
|
@@ -1743,13 +1878,13 @@ class te {
|
|
|
1743
1878
|
/**
|
|
1744
1879
|
* Load and compile a program from source code
|
|
1745
1880
|
*/
|
|
1746
|
-
async loadProgram(
|
|
1881
|
+
async loadProgram(r, t2) {
|
|
1747
1882
|
const s2 = W$1(t2);
|
|
1748
1883
|
if (!s2.success)
|
|
1749
1884
|
throw new Error(`Compilation failed: ${s2.errors.join(", ")}`);
|
|
1750
1885
|
const o2 = {
|
|
1751
|
-
id:
|
|
1752
|
-
name:
|
|
1886
|
+
id: r,
|
|
1887
|
+
name: r,
|
|
1753
1888
|
source: t2,
|
|
1754
1889
|
bytecode: s2.bytecode,
|
|
1755
1890
|
// VM decides internal format
|
|
@@ -1760,12 +1895,12 @@ class te {
|
|
|
1760
1895
|
/**
|
|
1761
1896
|
* Start execution of a loaded program
|
|
1762
1897
|
*/
|
|
1763
|
-
async startExecution(
|
|
1764
|
-
if (!await this.storage.getProgram(
|
|
1765
|
-
throw new Error(`Program not found: ${
|
|
1898
|
+
async startExecution(r, t2) {
|
|
1899
|
+
if (!await this.storage.getProgram(r))
|
|
1900
|
+
throw new Error(`Program not found: ${r}`);
|
|
1766
1901
|
const o2 = {
|
|
1767
1902
|
id: t2,
|
|
1768
|
-
programId:
|
|
1903
|
+
programId: r,
|
|
1769
1904
|
state: "READY",
|
|
1770
1905
|
pc: 0,
|
|
1771
1906
|
stack: [],
|
|
@@ -1780,24 +1915,24 @@ class te {
|
|
|
1780
1915
|
* Get next action from execution (Claude polls this)
|
|
1781
1916
|
* This is READ-ONLY - just returns current state
|
|
1782
1917
|
*/
|
|
1783
|
-
async getNext(
|
|
1784
|
-
const t2 = await this.storage.getExecution(
|
|
1918
|
+
async getNext(r) {
|
|
1919
|
+
const t2 = await this.storage.getExecution(r);
|
|
1785
1920
|
if (!t2)
|
|
1786
|
-
throw new Error(`Execution not found: ${
|
|
1921
|
+
throw new Error(`Execution not found: ${r}`);
|
|
1787
1922
|
if (t2.state === "READY") {
|
|
1788
1923
|
const s2 = await this.storage.getProgram(t2.programId);
|
|
1789
1924
|
if (!s2)
|
|
1790
1925
|
throw new Error(`Program not found: ${t2.programId}`);
|
|
1791
|
-
let o2 = this.vms.get(
|
|
1792
|
-
o2 || (o2 = new N(), this.vms.set(
|
|
1926
|
+
let o2 = this.vms.get(r);
|
|
1927
|
+
o2 || (o2 = new N(), this.vms.set(r, o2));
|
|
1793
1928
|
const n2 = {
|
|
1794
1929
|
pc: 0,
|
|
1795
1930
|
stack: [],
|
|
1796
1931
|
variables: /* @__PURE__ */ new Map(),
|
|
1797
1932
|
output: []
|
|
1798
1933
|
}, a2 = o2.execute(s2.bytecode, n2);
|
|
1799
|
-
if (a2.output.length > 0 && await this.storage.appendOutput(
|
|
1800
|
-
return t2.state = "COMPLETED", a2.returnValue !== void 0 && (t2.returnValue = a2.returnValue), await this.storage.saveExecution(t2), this.vms.delete(
|
|
1934
|
+
if (a2.output.length > 0 && await this.storage.appendOutput(r, a2.output), t2.pc = a2.pc, t2.stack = a2.stack, t2.variables = Object.fromEntries(a2.variables), t2.iterators = a2.iterators, a2.status === "complete")
|
|
1935
|
+
return t2.state = "COMPLETED", a2.returnValue !== void 0 && (t2.returnValue = a2.returnValue), await this.storage.saveExecution(t2), this.vms.delete(r), {
|
|
1801
1936
|
type: "completed",
|
|
1802
1937
|
message: "Execution completed",
|
|
1803
1938
|
result: a2.returnValue
|
|
@@ -1810,20 +1945,20 @@ class te {
|
|
|
1810
1945
|
if (a2.status === "waiting_fs") {
|
|
1811
1946
|
if (a2.fsOperation) {
|
|
1812
1947
|
const i2 = this.fileSystem.listFiles(a2.fsOperation.path, a2.fsOperation.options), u2 = o2.resumeWithFsResult(a2, i2, s2.bytecode);
|
|
1813
|
-
return u2.output.length > 0 && await this.storage.appendOutput(
|
|
1948
|
+
return u2.output.length > 0 && await this.storage.appendOutput(r, u2.output), t2.pc = u2.pc, t2.stack = u2.stack, t2.variables = Object.fromEntries(u2.variables), t2.iterators = u2.iterators, u2.status === "complete" ? (t2.state = "COMPLETED", u2.returnValue !== void 0 && (t2.returnValue = u2.returnValue), await this.storage.saveExecution(t2), this.vms.delete(r), {
|
|
1814
1949
|
type: "completed",
|
|
1815
1950
|
message: "Execution completed",
|
|
1816
1951
|
result: u2.returnValue
|
|
1817
|
-
}) : u2.status === "error" ? (t2.state = "ERROR", t2.error = u2.error, await this.storage.saveExecution(t2), this.vms.delete(
|
|
1952
|
+
}) : u2.status === "error" ? (t2.state = "ERROR", t2.error = u2.error, await this.storage.saveExecution(t2), this.vms.delete(r), {
|
|
1818
1953
|
type: "error",
|
|
1819
1954
|
error: u2.error
|
|
1820
1955
|
}) : u2.status === "waiting_cc" ? (t2.state = "AWAITING_COGNITIVE_RESULT", t2.ccPrompt = u2.ccPrompt, await this.storage.saveExecution(t2), {
|
|
1821
1956
|
type: "waiting",
|
|
1822
1957
|
message: u2.ccPrompt || "Waiting for input"
|
|
1823
|
-
}) : (t2.state = "RUNNING", await this.storage.saveExecution(t2), this.getNext(
|
|
1958
|
+
}) : (t2.state = "RUNNING", await this.storage.saveExecution(t2), this.getNext(r));
|
|
1824
1959
|
}
|
|
1825
1960
|
} else if (a2.status === "error")
|
|
1826
|
-
return t2.state = "ERROR", t2.error = a2.error, await this.storage.saveExecution(t2), this.vms.delete(
|
|
1961
|
+
return t2.state = "ERROR", t2.error = a2.error, await this.storage.saveExecution(t2), this.vms.delete(r), {
|
|
1827
1962
|
type: "error",
|
|
1828
1963
|
error: a2.error
|
|
1829
1964
|
};
|
|
@@ -1848,15 +1983,15 @@ class te {
|
|
|
1848
1983
|
/**
|
|
1849
1984
|
* Report result from cognitive operation and continue execution
|
|
1850
1985
|
*/
|
|
1851
|
-
async reportCCResult(
|
|
1852
|
-
const s2 = await this.storage.getExecution(
|
|
1986
|
+
async reportCCResult(r, t2) {
|
|
1987
|
+
const s2 = await this.storage.getExecution(r);
|
|
1853
1988
|
if (!s2)
|
|
1854
|
-
throw new Error(`Execution not found: ${
|
|
1989
|
+
throw new Error(`Execution not found: ${r}`);
|
|
1855
1990
|
const o2 = await this.storage.getProgram(s2.programId);
|
|
1856
1991
|
if (!o2)
|
|
1857
1992
|
throw new Error(`Program not found: ${s2.programId}`);
|
|
1858
|
-
let n2 = this.vms.get(
|
|
1859
|
-
n2 || (n2 = new N(), this.vms.set(
|
|
1993
|
+
let n2 = this.vms.get(r);
|
|
1994
|
+
n2 || (n2 = new N(), this.vms.set(r, n2));
|
|
1860
1995
|
const a2 = {
|
|
1861
1996
|
pc: s2.pc,
|
|
1862
1997
|
stack: s2.stack,
|
|
@@ -1867,15 +2002,15 @@ class te {
|
|
|
1867
2002
|
ccPrompt: void 0,
|
|
1868
2003
|
iterators: s2.iterators || []
|
|
1869
2004
|
}, i2 = n2.resume(a2, t2, o2.bytecode);
|
|
1870
|
-
i2.output.length > 0 && await this.storage.appendOutput(
|
|
2005
|
+
i2.output.length > 0 && await this.storage.appendOutput(r, i2.output), s2.pc = i2.pc, s2.stack = i2.stack, s2.variables = Object.fromEntries(i2.variables), s2.iterators = i2.iterators, i2.status === "complete" ? (s2.state = "COMPLETED", i2.returnValue !== void 0 && (s2.returnValue = i2.returnValue), this.vms.delete(r)) : i2.status === "error" ? (s2.state = "ERROR", s2.error = i2.error, this.vms.delete(r)) : i2.status === "waiting_cc" ? (s2.state = "AWAITING_COGNITIVE_RESULT", s2.ccPrompt = i2.ccPrompt) : s2.state = "RUNNING", await this.storage.saveExecution(s2);
|
|
1871
2006
|
}
|
|
1872
2007
|
/**
|
|
1873
2008
|
* Get current execution status
|
|
1874
2009
|
*/
|
|
1875
|
-
async getExecutionStatus(
|
|
1876
|
-
const t2 = await this.storage.getExecution(
|
|
2010
|
+
async getExecutionStatus(r) {
|
|
2011
|
+
const t2 = await this.storage.getExecution(r);
|
|
1877
2012
|
if (!t2)
|
|
1878
|
-
throw new Error(`Execution not found: ${
|
|
2013
|
+
throw new Error(`Execution not found: ${r}`);
|
|
1879
2014
|
return {
|
|
1880
2015
|
id: t2.id,
|
|
1881
2016
|
state: t2.state,
|
|
@@ -1887,20 +2022,53 @@ class te {
|
|
|
1887
2022
|
/**
|
|
1888
2023
|
* Get output for an execution
|
|
1889
2024
|
*/
|
|
1890
|
-
async getExecutionOutput(
|
|
1891
|
-
return await this.storage.getOutput(
|
|
2025
|
+
async getExecutionOutput(r) {
|
|
2026
|
+
return await this.storage.getOutput(r);
|
|
2027
|
+
}
|
|
2028
|
+
/**
|
|
2029
|
+
* List all executions
|
|
2030
|
+
*/
|
|
2031
|
+
async listExecutions() {
|
|
2032
|
+
return await this.storage.listExecutions();
|
|
2033
|
+
}
|
|
2034
|
+
/**
|
|
2035
|
+
* Get current execution ID
|
|
2036
|
+
*/
|
|
2037
|
+
async getCurrentExecutionId() {
|
|
2038
|
+
return await this.storage.getCurrentExecutionId();
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* Set current execution ID
|
|
2042
|
+
*/
|
|
2043
|
+
async setCurrentExecutionId(r) {
|
|
2044
|
+
return await this.storage.setCurrentExecutionId(r);
|
|
2045
|
+
}
|
|
2046
|
+
/**
|
|
2047
|
+
* Delete an execution
|
|
2048
|
+
*/
|
|
2049
|
+
async deleteExecution(r) {
|
|
2050
|
+
return await this.storage.deleteExecution(r);
|
|
2051
|
+
}
|
|
2052
|
+
/**
|
|
2053
|
+
* Get execution with attempt tracking
|
|
2054
|
+
*/
|
|
2055
|
+
async getExecutionWithAttempts(r) {
|
|
2056
|
+
const t2 = await this.storage.getExecution(r);
|
|
2057
|
+
if (!t2)
|
|
2058
|
+
throw new Error(`Execution not found: ${r}`);
|
|
2059
|
+
return t2;
|
|
1892
2060
|
}
|
|
1893
2061
|
}
|
|
1894
|
-
var
|
|
1895
|
-
var
|
|
1896
|
-
var
|
|
1897
|
-
class
|
|
1898
|
-
constructor(
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
this.version =
|
|
2062
|
+
var u = Object.defineProperty;
|
|
2063
|
+
var x = (s2, r, e2) => r in s2 ? u(s2, r, { enumerable: true, configurable: true, writable: true, value: e2 }) : s2[r] = e2;
|
|
2064
|
+
var i = (s2, r, e2) => x(s2, typeof r != "symbol" ? r + "" : r, e2);
|
|
2065
|
+
class M {
|
|
2066
|
+
constructor(r = "0.0.1") {
|
|
2067
|
+
i(this, "server");
|
|
2068
|
+
i(this, "transport", null);
|
|
2069
|
+
i(this, "vmManager");
|
|
2070
|
+
i(this, "version");
|
|
2071
|
+
this.version = r, this.vmManager = new te(), this.server = new mcp_js.McpServer({
|
|
1904
2072
|
name: "cvm-server",
|
|
1905
2073
|
version: this.version
|
|
1906
2074
|
}), this.setupTools();
|
|
@@ -1918,14 +2086,14 @@ class w {
|
|
|
1918
2086
|
programId: zod.z.string(),
|
|
1919
2087
|
source: zod.z.string()
|
|
1920
2088
|
},
|
|
1921
|
-
async ({ programId:
|
|
2089
|
+
async ({ programId: r, source: e2 }) => {
|
|
1922
2090
|
try {
|
|
1923
|
-
return await this.vmManager.loadProgram(
|
|
1924
|
-
content: [{ type: "text", text: `Program loaded successfully: ${
|
|
2091
|
+
return await this.vmManager.loadProgram(r, e2), {
|
|
2092
|
+
content: [{ type: "text", text: `Program loaded successfully: ${r}` }]
|
|
1925
2093
|
};
|
|
1926
|
-
} catch (
|
|
2094
|
+
} catch (t2) {
|
|
1927
2095
|
return {
|
|
1928
|
-
content: [{ type: "text", text: `Error: ${
|
|
2096
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
1929
2097
|
isError: true
|
|
1930
2098
|
};
|
|
1931
2099
|
}
|
|
@@ -1936,28 +2104,28 @@ class w {
|
|
|
1936
2104
|
programId: zod.z.string(),
|
|
1937
2105
|
filePath: zod.z.string()
|
|
1938
2106
|
},
|
|
1939
|
-
async ({ programId:
|
|
2107
|
+
async ({ programId: r, filePath: e2 }) => {
|
|
1940
2108
|
try {
|
|
1941
|
-
const
|
|
1942
|
-
return await this.vmManager.loadProgram(
|
|
1943
|
-
content: [{ type: "text", text: `Program loaded successfully from ${
|
|
2109
|
+
const t2 = c$1.resolve(e2), n2 = await promises.readFile(t2, "utf-8");
|
|
2110
|
+
return await this.vmManager.loadProgram(r, n2), {
|
|
2111
|
+
content: [{ type: "text", text: `Program loaded successfully from ${e2}: ${r}` }]
|
|
1944
2112
|
};
|
|
1945
|
-
} catch (
|
|
1946
|
-
if (
|
|
1947
|
-
const
|
|
1948
|
-
if (
|
|
2113
|
+
} catch (t2) {
|
|
2114
|
+
if (t2 instanceof Error) {
|
|
2115
|
+
const n2 = t2;
|
|
2116
|
+
if (n2.code === "ENOENT")
|
|
1949
2117
|
return {
|
|
1950
|
-
content: [{ type: "text", text: `Error: File not found: ${
|
|
2118
|
+
content: [{ type: "text", text: `Error: File not found: ${e2}` }],
|
|
1951
2119
|
isError: true
|
|
1952
2120
|
};
|
|
1953
|
-
if (
|
|
2121
|
+
if (n2.code === "EACCES")
|
|
1954
2122
|
return {
|
|
1955
|
-
content: [{ type: "text", text: `Error: Permission denied: ${
|
|
2123
|
+
content: [{ type: "text", text: `Error: Permission denied: ${e2}` }],
|
|
1956
2124
|
isError: true
|
|
1957
2125
|
};
|
|
1958
2126
|
}
|
|
1959
2127
|
return {
|
|
1960
|
-
content: [{ type: "text", text: `Error: ${
|
|
2128
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
1961
2129
|
isError: true
|
|
1962
2130
|
};
|
|
1963
2131
|
}
|
|
@@ -1966,16 +2134,17 @@ class w {
|
|
|
1966
2134
|
"start",
|
|
1967
2135
|
{
|
|
1968
2136
|
programId: zod.z.string(),
|
|
1969
|
-
executionId: zod.z.string()
|
|
2137
|
+
executionId: zod.z.string(),
|
|
2138
|
+
setCurrent: zod.z.boolean().optional()
|
|
1970
2139
|
},
|
|
1971
|
-
async ({ programId:
|
|
2140
|
+
async ({ programId: r, executionId: e2, setCurrent: t2 = true }) => {
|
|
1972
2141
|
try {
|
|
1973
|
-
return await this.vmManager.startExecution(
|
|
1974
|
-
content: [{ type: "text", text: `Execution started: ${t2}` }]
|
|
2142
|
+
return await this.vmManager.startExecution(r, e2), t2 && await this.vmManager.setCurrentExecutionId(e2), {
|
|
2143
|
+
content: [{ type: "text", text: `Execution started: ${e2}${t2 ? " (set as current)" : ""}` }]
|
|
1975
2144
|
};
|
|
1976
|
-
} catch (
|
|
2145
|
+
} catch (n2) {
|
|
1977
2146
|
return {
|
|
1978
|
-
content: [{ type: "text", text: `Error: ${
|
|
2147
|
+
content: [{ type: "text", text: `Error: ${n2 instanceof Error ? n2.message : "Unknown error"}` }],
|
|
1979
2148
|
isError: true
|
|
1980
2149
|
};
|
|
1981
2150
|
}
|
|
@@ -1983,11 +2152,20 @@ class w {
|
|
|
1983
2152
|
), this.server.tool(
|
|
1984
2153
|
"getTask",
|
|
1985
2154
|
{
|
|
1986
|
-
executionId: zod.z.string()
|
|
2155
|
+
executionId: zod.z.string().optional()
|
|
1987
2156
|
},
|
|
1988
|
-
async ({ executionId:
|
|
2157
|
+
async ({ executionId: r }) => {
|
|
1989
2158
|
try {
|
|
1990
|
-
|
|
2159
|
+
let e2 = r;
|
|
2160
|
+
if (!e2) {
|
|
2161
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2162
|
+
if (!n2)
|
|
2163
|
+
return {
|
|
2164
|
+
content: [{ type: "text", text: "No current execution set. Use list_executions to see available executions." }]
|
|
2165
|
+
};
|
|
2166
|
+
e2 = n2;
|
|
2167
|
+
}
|
|
2168
|
+
const t2 = await this.vmManager.getNext(e2);
|
|
1991
2169
|
return t2.type === "completed" ? {
|
|
1992
2170
|
content: [{ type: "text", text: t2.result !== void 0 ? `Execution completed with result: ${JSON.stringify(t2.result)}` : "Execution completed" }]
|
|
1993
2171
|
} : t2.type === "waiting" ? {
|
|
@@ -1999,9 +2177,9 @@ class w {
|
|
|
1999
2177
|
content: [{ type: "text", text: "Unexpected state" }],
|
|
2000
2178
|
isError: true
|
|
2001
2179
|
};
|
|
2002
|
-
} catch (
|
|
2180
|
+
} catch (e2) {
|
|
2003
2181
|
return {
|
|
2004
|
-
content: [{ type: "text", text: `Error: ${
|
|
2182
|
+
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
2005
2183
|
isError: true
|
|
2006
2184
|
};
|
|
2007
2185
|
}
|
|
@@ -2009,14 +2187,52 @@ class w {
|
|
|
2009
2187
|
), this.server.tool(
|
|
2010
2188
|
"submitTask",
|
|
2011
2189
|
{
|
|
2012
|
-
executionId: zod.z.string(),
|
|
2190
|
+
executionId: zod.z.string().optional(),
|
|
2013
2191
|
result: zod.z.string()
|
|
2014
2192
|
},
|
|
2015
|
-
async ({ executionId:
|
|
2193
|
+
async ({ executionId: r, result: e2 }) => {
|
|
2016
2194
|
try {
|
|
2017
|
-
|
|
2195
|
+
let t2 = r;
|
|
2196
|
+
if (!t2) {
|
|
2197
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2198
|
+
if (!n2)
|
|
2199
|
+
return {
|
|
2200
|
+
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2201
|
+
isError: true
|
|
2202
|
+
};
|
|
2203
|
+
t2 = n2;
|
|
2204
|
+
}
|
|
2205
|
+
return await this.vmManager.reportCCResult(t2, e2), {
|
|
2018
2206
|
content: [{ type: "text", text: "Execution resumed" }]
|
|
2019
2207
|
};
|
|
2208
|
+
} catch (t2) {
|
|
2209
|
+
return {
|
|
2210
|
+
content: [{ type: "text", text: `Error: ${t2 instanceof Error ? t2.message : "Unknown error"}` }],
|
|
2211
|
+
isError: true
|
|
2212
|
+
};
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
), this.server.tool(
|
|
2216
|
+
"status",
|
|
2217
|
+
{
|
|
2218
|
+
executionId: zod.z.string().optional()
|
|
2219
|
+
},
|
|
2220
|
+
async ({ executionId: r }) => {
|
|
2221
|
+
try {
|
|
2222
|
+
let e2 = r;
|
|
2223
|
+
if (!e2) {
|
|
2224
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
2225
|
+
if (!n2)
|
|
2226
|
+
return {
|
|
2227
|
+
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2228
|
+
isError: true
|
|
2229
|
+
};
|
|
2230
|
+
e2 = n2;
|
|
2231
|
+
}
|
|
2232
|
+
const t2 = await this.vmManager.getExecutionStatus(e2);
|
|
2233
|
+
return {
|
|
2234
|
+
content: [{ type: "text", text: JSON.stringify(t2, null, 2) }]
|
|
2235
|
+
};
|
|
2020
2236
|
} catch (e2) {
|
|
2021
2237
|
return {
|
|
2022
2238
|
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
@@ -2025,15 +2241,117 @@ class w {
|
|
|
2025
2241
|
}
|
|
2026
2242
|
}
|
|
2027
2243
|
), this.server.tool(
|
|
2028
|
-
"
|
|
2244
|
+
"list_executions",
|
|
2245
|
+
{},
|
|
2246
|
+
async () => {
|
|
2247
|
+
try {
|
|
2248
|
+
const r = await this.vmManager.listExecutions(), e2 = await this.vmManager.getCurrentExecutionId(), t2 = r.map((n2) => ({
|
|
2249
|
+
executionId: n2.id,
|
|
2250
|
+
programId: n2.programId,
|
|
2251
|
+
state: n2.state,
|
|
2252
|
+
created: n2.created,
|
|
2253
|
+
isCurrent: n2.id === e2,
|
|
2254
|
+
summary: {
|
|
2255
|
+
currentPrompt: n2.state === "AWAITING_COGNITIVE_RESULT" ? n2.ccPrompt : void 0,
|
|
2256
|
+
tasksCompleted: 0
|
|
2257
|
+
// TODO: Track this in future
|
|
2258
|
+
}
|
|
2259
|
+
}));
|
|
2260
|
+
return {
|
|
2261
|
+
content: [{ type: "text", text: JSON.stringify(t2, null, 2) }]
|
|
2262
|
+
};
|
|
2263
|
+
} catch (r) {
|
|
2264
|
+
return {
|
|
2265
|
+
content: [{ type: "text", text: `Error: ${r instanceof Error ? r.message : "Unknown error"}` }],
|
|
2266
|
+
isError: true
|
|
2267
|
+
};
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
), this.server.tool(
|
|
2271
|
+
"get_execution",
|
|
2272
|
+
{
|
|
2273
|
+
executionId: zod.z.string().optional()
|
|
2274
|
+
},
|
|
2275
|
+
async ({ executionId: r }) => {
|
|
2276
|
+
try {
|
|
2277
|
+
let e2 = r;
|
|
2278
|
+
if (!e2) {
|
|
2279
|
+
const a2 = await this.vmManager.getCurrentExecutionId();
|
|
2280
|
+
if (!a2)
|
|
2281
|
+
return {
|
|
2282
|
+
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
2283
|
+
isError: true
|
|
2284
|
+
};
|
|
2285
|
+
e2 = a2;
|
|
2286
|
+
}
|
|
2287
|
+
const t2 = await this.vmManager.getExecutionWithAttempts(e2), n2 = await this.vmManager.getCurrentExecutionId(), c2 = {
|
|
2288
|
+
executionId: t2.id,
|
|
2289
|
+
programId: t2.programId,
|
|
2290
|
+
state: t2.state,
|
|
2291
|
+
created: t2.created,
|
|
2292
|
+
isCurrent: t2.id === n2,
|
|
2293
|
+
currentTask: t2.state === "AWAITING_COGNITIVE_RESULT" ? {
|
|
2294
|
+
prompt: t2.ccPrompt,
|
|
2295
|
+
attempts: t2.attempts || 1,
|
|
2296
|
+
firstAttemptAt: t2.firstAttemptAt || t2.created,
|
|
2297
|
+
lastAttemptAt: t2.lastAttemptAt || t2.created
|
|
2298
|
+
} : void 0,
|
|
2299
|
+
variables: t2.variables,
|
|
2300
|
+
stats: {
|
|
2301
|
+
tasksCompleted: 0
|
|
2302
|
+
// TODO: Track this
|
|
2303
|
+
}
|
|
2304
|
+
};
|
|
2305
|
+
return {
|
|
2306
|
+
content: [{ type: "text", text: JSON.stringify(c2, null, 2) }]
|
|
2307
|
+
};
|
|
2308
|
+
} catch (e2) {
|
|
2309
|
+
return {
|
|
2310
|
+
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
2311
|
+
isError: true
|
|
2312
|
+
};
|
|
2313
|
+
}
|
|
2314
|
+
}
|
|
2315
|
+
), this.server.tool(
|
|
2316
|
+
"set_current",
|
|
2029
2317
|
{
|
|
2030
2318
|
executionId: zod.z.string()
|
|
2031
2319
|
},
|
|
2032
|
-
async ({ executionId:
|
|
2320
|
+
async ({ executionId: r }) => {
|
|
2033
2321
|
try {
|
|
2034
|
-
|
|
2322
|
+
return await this.vmManager.setCurrentExecutionId(r), {
|
|
2323
|
+
content: [{ type: "text", text: `Current execution set to: ${r}` }]
|
|
2324
|
+
};
|
|
2325
|
+
} catch (e2) {
|
|
2035
2326
|
return {
|
|
2036
|
-
content: [{ type: "text", text:
|
|
2327
|
+
content: [{ type: "text", text: `Error: ${e2 instanceof Error ? e2.message : "Unknown error"}` }],
|
|
2328
|
+
isError: true
|
|
2329
|
+
};
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
), this.server.tool(
|
|
2333
|
+
"delete_execution",
|
|
2334
|
+
{
|
|
2335
|
+
executionId: zod.z.string(),
|
|
2336
|
+
confirmToken: zod.z.string().optional()
|
|
2337
|
+
},
|
|
2338
|
+
async ({ executionId: r, confirmToken: e2 }) => {
|
|
2339
|
+
try {
|
|
2340
|
+
const t2 = `delete-${r}-${Date.now()}`;
|
|
2341
|
+
return e2 ? e2 && e2.startsWith(`delete-${r}-`) ? (await this.vmManager.deleteExecution(r), {
|
|
2342
|
+
content: [{ type: "text", text: `Execution deleted: ${r}` }]
|
|
2343
|
+
}) : {
|
|
2344
|
+
content: [{ type: "text", text: "Invalid confirmation token" }],
|
|
2345
|
+
isError: true
|
|
2346
|
+
} : {
|
|
2347
|
+
content: [{
|
|
2348
|
+
type: "text",
|
|
2349
|
+
text: JSON.stringify({
|
|
2350
|
+
confirmationRequired: true,
|
|
2351
|
+
message: `To delete execution '${r}', call this tool again with the confirmation token`,
|
|
2352
|
+
token: t2
|
|
2353
|
+
}, null, 2)
|
|
2354
|
+
}]
|
|
2037
2355
|
};
|
|
2038
2356
|
} catch (t2) {
|
|
2039
2357
|
return {
|
|
@@ -2044,8 +2362,8 @@ class w {
|
|
|
2044
2362
|
}
|
|
2045
2363
|
);
|
|
2046
2364
|
}
|
|
2047
|
-
async start(
|
|
2048
|
-
await this.vmManager.initialize(), this.transport =
|
|
2365
|
+
async start(r) {
|
|
2366
|
+
await this.vmManager.initialize(), this.transport = r || new stdio_js.StdioServerTransport(), await this.server.connect(this.transport);
|
|
2049
2367
|
}
|
|
2050
2368
|
async stop() {
|
|
2051
2369
|
this.transport && (await this.transport.close(), this.transport = null), await this.vmManager.dispose();
|
|
@@ -2055,7 +2373,7 @@ class w {
|
|
|
2055
2373
|
return this.vmManager;
|
|
2056
2374
|
}
|
|
2057
2375
|
}
|
|
2058
|
-
dotenv__namespace.config({ path: c$
|
|
2376
|
+
dotenv__namespace.config({ path: c$1.resolve(__dirname, "../../../.env") });
|
|
2059
2377
|
function loadConfig() {
|
|
2060
2378
|
const env = process.env.NODE_ENV || "development";
|
|
2061
2379
|
const storageType = process.env.CVM_STORAGE_TYPE || "file";
|
|
@@ -2136,7 +2454,7 @@ function getLogger() {
|
|
|
2136
2454
|
return logger;
|
|
2137
2455
|
}
|
|
2138
2456
|
const __filename$1 = url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("main.cjs", document.baseURI).href);
|
|
2139
|
-
const __dirname$1 = c$
|
|
2457
|
+
const __dirname$1 = c$1.dirname(__filename$1);
|
|
2140
2458
|
async function main() {
|
|
2141
2459
|
let cvmServer;
|
|
2142
2460
|
try {
|
|
@@ -2145,16 +2463,16 @@ async function main() {
|
|
|
2145
2463
|
const logger2 = getLogger();
|
|
2146
2464
|
let version = "0.4.3";
|
|
2147
2465
|
const possiblePaths = [
|
|
2148
|
-
c$
|
|
2466
|
+
c$1.join(__dirname$1, "..", "package.json"),
|
|
2149
2467
|
// Development
|
|
2150
|
-
c$
|
|
2468
|
+
c$1.join(__dirname$1, "package.json"),
|
|
2151
2469
|
// Bundled dist
|
|
2152
|
-
c$
|
|
2470
|
+
c$1.join(process.cwd(), "package.json")
|
|
2153
2471
|
// Current directory
|
|
2154
2472
|
];
|
|
2155
2473
|
for (const packageJsonPath of possiblePaths) {
|
|
2156
2474
|
try {
|
|
2157
|
-
const packageJson = JSON.parse(
|
|
2475
|
+
const packageJson = JSON.parse(M$2.readFileSync(packageJsonPath, "utf-8"));
|
|
2158
2476
|
if (packageJson.name === "cvm-server" && packageJson.version) {
|
|
2159
2477
|
version = packageJson.version;
|
|
2160
2478
|
break;
|
|
@@ -2169,13 +2487,13 @@ async function main() {
|
|
|
2169
2487
|
});
|
|
2170
2488
|
if (config.storage.type === "file") {
|
|
2171
2489
|
const dataDir = config.storage.dataDir || ".cvm";
|
|
2172
|
-
const fullPath = c$
|
|
2490
|
+
const fullPath = c$1.resolve(process.cwd(), dataDir);
|
|
2173
2491
|
logger2.info(`[CVM] Initializing file storage in: ${fullPath}`);
|
|
2174
2492
|
logger2.warn(`[CVM] ⚠️ Remember to add '${dataDir}/' to your .gitignore file!`);
|
|
2175
2493
|
} else {
|
|
2176
2494
|
logger2.info("[CVM] Using MongoDB storage");
|
|
2177
2495
|
}
|
|
2178
|
-
cvmServer = new
|
|
2496
|
+
cvmServer = new M(version);
|
|
2179
2497
|
await cvmServer.start();
|
|
2180
2498
|
logger2.info("CVM Server is running and ready to accept MCP connections");
|
|
2181
2499
|
process.on("SIGINT", async () => {
|