cvm-server 0.8.0 → 0.9.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 +621 -472
- package/package.json +1 -1
package/main.cjs
CHANGED
|
@@ -3,7 +3,7 @@ const mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
|
3
3
|
const stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
4
4
|
const zod = require("zod");
|
|
5
5
|
const n$1 = require("typescript");
|
|
6
|
-
const
|
|
6
|
+
const G$1 = require("fs");
|
|
7
7
|
const c$2 = require("path");
|
|
8
8
|
const mongodb = require("mongodb");
|
|
9
9
|
const promises = require("fs/promises");
|
|
@@ -27,24 +27,24 @@ function _interopNamespaceDefault(e2) {
|
|
|
27
27
|
return Object.freeze(n2);
|
|
28
28
|
}
|
|
29
29
|
const n__namespace = /* @__PURE__ */ _interopNamespaceDefault(n$1);
|
|
30
|
-
const
|
|
30
|
+
const G__namespace = /* @__PURE__ */ _interopNamespaceDefault(G$1);
|
|
31
31
|
const c__namespace = /* @__PURE__ */ _interopNamespaceDefault(c$2);
|
|
32
32
|
const dotenv__namespace = /* @__PURE__ */ _interopNamespaceDefault(dotenv);
|
|
33
|
-
var
|
|
34
|
-
var
|
|
35
|
-
var
|
|
36
|
-
var
|
|
37
|
-
function
|
|
38
|
-
const t2 = [],
|
|
33
|
+
var p$2 = Object.defineProperty;
|
|
34
|
+
var f$1 = (e2, t2, s2) => t2 in e2 ? p$2(e2, t2, { enumerable: true, configurable: true, writable: true, value: s2 }) : e2[t2] = s2;
|
|
35
|
+
var x$1 = (e2, t2, s2) => f$1(e2, typeof t2 != "symbol" ? t2 + "" : t2, s2);
|
|
36
|
+
var i$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.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))(i$1 || {});
|
|
37
|
+
function R(e2) {
|
|
38
|
+
const t2 = [], s2 = [];
|
|
39
39
|
let r2 = false, a2 = false;
|
|
40
|
-
const
|
|
40
|
+
const m2 = n__namespace.createSourceFile(
|
|
41
41
|
"program.ts",
|
|
42
42
|
e2,
|
|
43
43
|
n__namespace.ScriptTarget.Latest,
|
|
44
44
|
true
|
|
45
45
|
);
|
|
46
|
-
function
|
|
47
|
-
if (n__namespace.isFunctionDeclaration(o2) && o2.name && o2.name.text === "main" && (r2 = true, o2.parameters.length > 0 && t2.push("main() must not have parameters")), n__namespace.isExpressionStatement(o2) && o2.parent ===
|
|
46
|
+
function l2(o2) {
|
|
47
|
+
if (n__namespace.isFunctionDeclaration(o2) && o2.name && o2.name.text === "main" && (r2 = true, o2.parameters.length > 0 && t2.push("main() must not have parameters")), n__namespace.isExpressionStatement(o2) && o2.parent === m2) {
|
|
48
48
|
const c2 = o2.expression;
|
|
49
49
|
n__namespace.isCallExpression(c2) && n__namespace.isIdentifier(c2.expression) && c2.expression.text === "main" && (a2 = true);
|
|
50
50
|
}
|
|
@@ -52,25 +52,25 @@ function A(e2) {
|
|
|
52
52
|
const c2 = o2.expression.text;
|
|
53
53
|
["setTimeout", "fetch", "require", "import"].includes(c2) && t2.push(`Unsupported function: ${c2}`);
|
|
54
54
|
}
|
|
55
|
-
n__namespace.forEachChild(o2,
|
|
55
|
+
n__namespace.forEachChild(o2, l2);
|
|
56
56
|
}
|
|
57
|
-
return
|
|
58
|
-
bytecode:
|
|
57
|
+
return l2(m2), r2 || t2.push("Program must have a main() function"), r2 && !a2 && t2.push("main() must be called at the top level"), t2.length === 0 && s2.push({ op: i$1.HALT }), {
|
|
58
|
+
bytecode: s2,
|
|
59
59
|
errors: t2,
|
|
60
60
|
hasMain: r2
|
|
61
61
|
};
|
|
62
62
|
}
|
|
63
|
-
class
|
|
63
|
+
let A$1 = class A {
|
|
64
64
|
constructor() {
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
x$1(this, "bytecode", []);
|
|
66
|
+
x$1(this, "contextStack", []);
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Emit an instruction and return its index
|
|
70
70
|
*/
|
|
71
|
-
emit(t2,
|
|
71
|
+
emit(t2, s2) {
|
|
72
72
|
const r2 = this.bytecode.length;
|
|
73
|
-
return this.bytecode.push({ op: t2, arg:
|
|
73
|
+
return this.bytecode.push({ op: t2, arg: s2 }), r2;
|
|
74
74
|
}
|
|
75
75
|
/**
|
|
76
76
|
* Get the current address (next instruction index)
|
|
@@ -81,14 +81,14 @@ class R {
|
|
|
81
81
|
/**
|
|
82
82
|
* Patch a jump instruction with the target address
|
|
83
83
|
*/
|
|
84
|
-
patchJump(t2,
|
|
85
|
-
t2 >= 0 && t2 < this.bytecode.length && (this.bytecode[t2].arg =
|
|
84
|
+
patchJump(t2, s2) {
|
|
85
|
+
t2 >= 0 && t2 < this.bytecode.length && (this.bytecode[t2].arg = s2);
|
|
86
86
|
}
|
|
87
87
|
/**
|
|
88
88
|
* Patch multiple jump instructions with the same target
|
|
89
89
|
*/
|
|
90
|
-
patchJumps(t2,
|
|
91
|
-
t2.forEach((r2) => this.patchJump(r2,
|
|
90
|
+
patchJumps(t2, s2) {
|
|
91
|
+
t2.forEach((r2) => this.patchJump(r2, s2));
|
|
92
92
|
}
|
|
93
93
|
/**
|
|
94
94
|
* Push a new jump context onto the stack
|
|
@@ -113,9 +113,9 @@ class R {
|
|
|
113
113
|
*/
|
|
114
114
|
findLoopContext() {
|
|
115
115
|
for (let t2 = this.contextStack.length - 1; t2 >= 0; t2--) {
|
|
116
|
-
const
|
|
117
|
-
if (
|
|
118
|
-
return
|
|
116
|
+
const s2 = this.contextStack[t2];
|
|
117
|
+
if (s2.type === "loop" || s2.type === "foreach")
|
|
118
|
+
return s2;
|
|
119
119
|
}
|
|
120
120
|
return null;
|
|
121
121
|
}
|
|
@@ -137,330 +137,353 @@ class R {
|
|
|
137
137
|
getUnclosedContexts() {
|
|
138
138
|
return [...this.contextStack];
|
|
139
139
|
}
|
|
140
|
-
}
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
const a2 = t2.emit(
|
|
140
|
+
};
|
|
141
|
+
const P$1 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
142
|
+
s2(e2.expression);
|
|
143
|
+
const a2 = t2.emit(i$1.JUMP_IF_FALSE, -1), m2 = {
|
|
144
144
|
type: "if",
|
|
145
145
|
endTargets: []
|
|
146
146
|
};
|
|
147
|
-
if (e2.elseStatement ?
|
|
148
|
-
const o2 = t2.emit(
|
|
149
|
-
|
|
147
|
+
if (e2.elseStatement ? m2.elseTarget = a2 : m2.endTargets.push(a2), t2.pushContext(m2), r2(e2.thenStatement), e2.elseStatement) {
|
|
148
|
+
const o2 = t2.emit(i$1.JUMP, -1);
|
|
149
|
+
m2.endTargets.push(o2);
|
|
150
150
|
const c2 = t2.currentAddress();
|
|
151
151
|
t2.patchJump(a2, c2), r2(e2.elseStatement);
|
|
152
152
|
}
|
|
153
|
-
const
|
|
154
|
-
if (
|
|
153
|
+
const l2 = t2.popContext();
|
|
154
|
+
if (l2) {
|
|
155
155
|
const o2 = t2.currentAddress();
|
|
156
|
-
t2.patchJumps(
|
|
156
|
+
t2.patchJumps(l2.endTargets, o2);
|
|
157
157
|
}
|
|
158
|
-
}, I = (e2, t2, { compileExpression:
|
|
158
|
+
}, I = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
159
159
|
const a2 = t2.currentAddress();
|
|
160
|
-
|
|
161
|
-
const
|
|
160
|
+
s2(e2.expression);
|
|
161
|
+
const l2 = {
|
|
162
162
|
type: "loop",
|
|
163
|
-
breakTargets: [t2.emit(
|
|
163
|
+
breakTargets: [t2.emit(i$1.JUMP_IF_FALSE, -1)],
|
|
164
164
|
continueTargets: [],
|
|
165
165
|
endTargets: [],
|
|
166
166
|
startAddress: a2
|
|
167
167
|
};
|
|
168
|
-
t2.pushContext(
|
|
168
|
+
t2.pushContext(l2), r2(e2.statement), t2.emit(i$1.JUMP, a2);
|
|
169
169
|
const o2 = t2.popContext();
|
|
170
170
|
if (o2) {
|
|
171
171
|
const c2 = t2.currentAddress();
|
|
172
172
|
t2.patchJumps(o2.breakTargets || [], c2);
|
|
173
173
|
}
|
|
174
|
-
},
|
|
175
|
-
const a2 = e2.initializer,
|
|
176
|
-
let
|
|
174
|
+
}, h$2 = (e2, t2, { compileExpression: s2, compileStatement: r2 }) => {
|
|
175
|
+
const a2 = e2.initializer, m2 = e2.expression;
|
|
176
|
+
let l2;
|
|
177
177
|
if (n__namespace.isVariableDeclarationList(a2))
|
|
178
|
-
|
|
178
|
+
l2 = a2.declarations[0].name.getText();
|
|
179
179
|
else if (n__namespace.isIdentifier(a2))
|
|
180
|
-
|
|
180
|
+
l2 = a2.text;
|
|
181
181
|
else
|
|
182
182
|
throw new Error("Unsupported for-of variable declaration");
|
|
183
|
-
|
|
183
|
+
s2(m2), t2.emit(i$1.ITER_START);
|
|
184
184
|
const o2 = t2.currentAddress();
|
|
185
|
-
t2.emit(
|
|
186
|
-
const c2 = t2.emit(
|
|
187
|
-
t2.emit(
|
|
188
|
-
const
|
|
185
|
+
t2.emit(i$1.ITER_NEXT);
|
|
186
|
+
const c2 = t2.emit(i$1.JUMP_IF_FALSE, -1);
|
|
187
|
+
t2.emit(i$1.STORE, l2);
|
|
188
|
+
const S = {
|
|
189
189
|
type: "foreach",
|
|
190
190
|
breakTargets: [c2],
|
|
191
191
|
continueTargets: [],
|
|
192
192
|
endTargets: [],
|
|
193
193
|
startAddress: o2,
|
|
194
|
-
iterVariable:
|
|
194
|
+
iterVariable: l2
|
|
195
195
|
};
|
|
196
|
-
t2.pushContext(
|
|
196
|
+
t2.pushContext(S), r2(e2.statement), t2.emit(i$1.JUMP, o2);
|
|
197
197
|
const u2 = t2.popContext();
|
|
198
198
|
if (u2) {
|
|
199
|
-
const
|
|
200
|
-
t2.patchJumps(u2.breakTargets || [],
|
|
199
|
+
const E = t2.currentAddress();
|
|
200
|
+
t2.patchJumps(u2.breakTargets || [], E), t2.emit(i$1.ITER_END);
|
|
201
201
|
}
|
|
202
|
-
},
|
|
202
|
+
}, y$1 = (e2, t2, { compileStatement: s2 }) => {
|
|
203
203
|
e2.statements.forEach((r2) => {
|
|
204
|
-
|
|
204
|
+
s2(r2);
|
|
205
205
|
});
|
|
206
|
-
},
|
|
206
|
+
}, N$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
207
207
|
const r2 = e2.declarationList.declarations[0];
|
|
208
|
-
r2.initializer && (
|
|
209
|
-
},
|
|
208
|
+
r2.initializer && (s2(r2.initializer), t2.emit(i$1.STORE, r2.name.getText()));
|
|
209
|
+
}, g$2 = (e2, t2, { compileExpression: s2 }) => {
|
|
210
210
|
const r2 = e2.expression;
|
|
211
211
|
if (n__namespace.isBinaryExpression(r2)) {
|
|
212
212
|
const a2 = r2.operatorToken.kind;
|
|
213
213
|
if (a2 === n__namespace.SyntaxKind.PlusEqualsToken || a2 === n__namespace.SyntaxKind.MinusEqualsToken || a2 === n__namespace.SyntaxKind.AsteriskEqualsToken || a2 === n__namespace.SyntaxKind.SlashEqualsToken || a2 === n__namespace.SyntaxKind.PercentEqualsToken) {
|
|
214
214
|
if (n__namespace.isIdentifier(r2.left)) {
|
|
215
|
-
switch (t2.emit(
|
|
215
|
+
switch (t2.emit(i$1.LOAD, r2.left.text), s2(r2.right), a2) {
|
|
216
216
|
case n__namespace.SyntaxKind.PlusEqualsToken:
|
|
217
|
-
n__namespace.isStringLiteral(r2.right) ? t2.emit(
|
|
217
|
+
n__namespace.isStringLiteral(r2.right) ? t2.emit(i$1.CONCAT) : t2.emit(i$1.ADD);
|
|
218
218
|
break;
|
|
219
219
|
case n__namespace.SyntaxKind.MinusEqualsToken:
|
|
220
|
-
t2.emit(
|
|
220
|
+
t2.emit(i$1.SUB);
|
|
221
221
|
break;
|
|
222
222
|
case n__namespace.SyntaxKind.AsteriskEqualsToken:
|
|
223
|
-
t2.emit(
|
|
223
|
+
t2.emit(i$1.MUL);
|
|
224
224
|
break;
|
|
225
225
|
case n__namespace.SyntaxKind.SlashEqualsToken:
|
|
226
|
-
t2.emit(
|
|
226
|
+
t2.emit(i$1.DIV);
|
|
227
227
|
break;
|
|
228
228
|
case n__namespace.SyntaxKind.PercentEqualsToken:
|
|
229
|
-
t2.emit(
|
|
229
|
+
t2.emit(i$1.MOD);
|
|
230
230
|
break;
|
|
231
231
|
}
|
|
232
|
-
t2.emit(
|
|
232
|
+
t2.emit(i$1.STORE, r2.left.text);
|
|
233
233
|
} else if (n__namespace.isElementAccessExpression(r2.left))
|
|
234
234
|
throw new Error("Compound assignment to array elements not yet supported");
|
|
235
235
|
return;
|
|
236
236
|
} else if (a2 === n__namespace.SyntaxKind.EqualsToken) {
|
|
237
|
-
if (
|
|
238
|
-
t2.emit(
|
|
237
|
+
if (s2(r2.right), n__namespace.isIdentifier(r2.left))
|
|
238
|
+
t2.emit(i$1.STORE, r2.left.text);
|
|
239
239
|
else if (n__namespace.isElementAccessExpression(r2.left)) {
|
|
240
|
-
const
|
|
241
|
-
t2.emit(
|
|
240
|
+
const m2 = `__temp_${t2.getBytecode().length}`;
|
|
241
|
+
t2.emit(i$1.STORE, m2), s2(r2.left.expression), s2(r2.left.argumentExpression), t2.emit(i$1.LOAD, m2), t2.emit(i$1.ARRAY_SET), t2.emit(i$1.POP);
|
|
242
|
+
} else if (n__namespace.isPropertyAccessExpression(r2.left)) {
|
|
243
|
+
const m2 = `__temp_${t2.getBytecode().length}`;
|
|
244
|
+
t2.emit(i$1.STORE, m2), s2(r2.left.expression), t2.emit(i$1.PUSH, r2.left.name.text), t2.emit(i$1.LOAD, m2), t2.emit(i$1.PROPERTY_SET), t2.emit(i$1.POP);
|
|
242
245
|
}
|
|
243
246
|
return;
|
|
244
247
|
}
|
|
245
248
|
}
|
|
246
249
|
n__namespace.isCallExpression(r2) && n__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.expression.getText() === "console" && r2.expression.name.getText() === "log" ? (r2.arguments.forEach((a2) => {
|
|
247
|
-
|
|
248
|
-
}), t2.emit(
|
|
249
|
-
},
|
|
250
|
-
e2.expression ?
|
|
251
|
-
},
|
|
250
|
+
s2(a2);
|
|
251
|
+
}), t2.emit(i$1.PRINT)) : n__namespace.isCallExpression(r2) && n__namespace.isIdentifier(r2.expression) && r2.expression.text === "CC" ? (r2.arguments.length > 0 && s2(r2.arguments[0]), t2.emit(i$1.CC), t2.emit(i$1.POP)) : n__namespace.isCallExpression(r2) && n__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.name.getText() === "push" ? (s2(r2.expression.expression), r2.arguments.length > 0 && s2(r2.arguments[0]), t2.emit(i$1.ARRAY_PUSH)) : (n__namespace.isPostfixUnaryExpression(r2) || n__namespace.isPrefixUnaryExpression(r2)) && (s2(r2), t2.emit(i$1.POP));
|
|
252
|
+
}, _$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
253
|
+
e2.expression ? s2(e2.expression) : t2.emit(i$1.PUSH, null), t2.emit(i$1.RETURN);
|
|
254
|
+
}, k = (e2, t2, s2) => {
|
|
252
255
|
const r2 = t2.findLoopContext();
|
|
253
256
|
if (r2) {
|
|
254
|
-
r2.type === "foreach" && t2.emit(
|
|
255
|
-
const a2 = t2.emit(
|
|
257
|
+
r2.type === "foreach" && t2.emit(i$1.ITER_END);
|
|
258
|
+
const a2 = t2.emit(i$1.BREAK, -1);
|
|
256
259
|
r2.breakTargets = r2.breakTargets || [], r2.breakTargets.push(a2);
|
|
257
260
|
} else
|
|
258
261
|
throw new Error("break statement not in loop");
|
|
259
|
-
}, U
|
|
262
|
+
}, U = (e2, t2, s2) => {
|
|
260
263
|
const r2 = t2.findLoopContext();
|
|
261
264
|
if (r2 && r2.startAddress !== void 0) {
|
|
262
|
-
const a2 = t2.emit(
|
|
265
|
+
const a2 = t2.emit(i$1.CONTINUE, r2.startAddress);
|
|
263
266
|
r2.continueTargets = r2.continueTargets || [], r2.continueTargets.push(a2);
|
|
264
267
|
} else
|
|
265
268
|
throw new Error("continue statement not in loop");
|
|
266
269
|
}, L$1 = {
|
|
267
|
-
[n__namespace.SyntaxKind.IfStatement]:
|
|
270
|
+
[n__namespace.SyntaxKind.IfStatement]: P$1,
|
|
268
271
|
[n__namespace.SyntaxKind.WhileStatement]: I,
|
|
269
|
-
[n__namespace.SyntaxKind.ForOfStatement]:
|
|
270
|
-
[n__namespace.SyntaxKind.Block]:
|
|
271
|
-
[n__namespace.SyntaxKind.VariableStatement]:
|
|
272
|
-
[n__namespace.SyntaxKind.ExpressionStatement]:
|
|
273
|
-
[n__namespace.SyntaxKind.ReturnStatement]:
|
|
274
|
-
[n__namespace.SyntaxKind.BreakStatement]:
|
|
275
|
-
[n__namespace.SyntaxKind.ContinueStatement]: U
|
|
276
|
-
}, d$1 = (e2, t2,
|
|
277
|
-
t2.emit(
|
|
278
|
-
}, K = (e2, t2,
|
|
279
|
-
t2.emit(
|
|
280
|
-
}, b$
|
|
281
|
-
t2.emit(
|
|
282
|
-
}, F$1 = (e2, t2,
|
|
283
|
-
t2.emit(
|
|
284
|
-
}, D$1 = (e2, t2,
|
|
285
|
-
t2.emit(
|
|
286
|
-
}, G
|
|
287
|
-
e2.text === "undefined" ? t2.emit(
|
|
288
|
-
},
|
|
289
|
-
t2.emit(
|
|
290
|
-
|
|
272
|
+
[n__namespace.SyntaxKind.ForOfStatement]: h$2,
|
|
273
|
+
[n__namespace.SyntaxKind.Block]: y$1,
|
|
274
|
+
[n__namespace.SyntaxKind.VariableStatement]: N$1,
|
|
275
|
+
[n__namespace.SyntaxKind.ExpressionStatement]: g$2,
|
|
276
|
+
[n__namespace.SyntaxKind.ReturnStatement]: _$1,
|
|
277
|
+
[n__namespace.SyntaxKind.BreakStatement]: k,
|
|
278
|
+
[n__namespace.SyntaxKind.ContinueStatement]: U
|
|
279
|
+
}, d$1 = (e2, t2, s2) => {
|
|
280
|
+
t2.emit(i$1.PUSH, e2.text);
|
|
281
|
+
}, K = (e2, t2, s2) => {
|
|
282
|
+
t2.emit(i$1.PUSH, Number(e2.text));
|
|
283
|
+
}, b$2 = (e2, t2, s2) => {
|
|
284
|
+
t2.emit(i$1.PUSH, true);
|
|
285
|
+
}, F$1 = (e2, t2, s2) => {
|
|
286
|
+
t2.emit(i$1.PUSH, false);
|
|
287
|
+
}, D$1 = (e2, t2, s2) => {
|
|
288
|
+
t2.emit(i$1.PUSH, null);
|
|
289
|
+
}, G = (e2, t2, s2) => {
|
|
290
|
+
e2.text === "undefined" ? t2.emit(i$1.PUSH_UNDEFINED) : t2.emit(i$1.LOAD, e2.text);
|
|
291
|
+
}, H$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
292
|
+
t2.emit(i$1.ARRAY_NEW), e2.elements.forEach((r2) => {
|
|
293
|
+
s2(r2), t2.emit(i$1.ARRAY_PUSH);
|
|
291
294
|
});
|
|
292
|
-
},
|
|
293
|
-
|
|
294
|
-
},
|
|
295
|
-
e2.name.text === "length"
|
|
296
|
-
},
|
|
297
|
-
|
|
298
|
-
},
|
|
295
|
+
}, M$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
296
|
+
s2(e2.expression);
|
|
297
|
+
}, J$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
298
|
+
e2.name.text === "length" ? (s2(e2.expression), t2.emit(i$1.LENGTH)) : (s2(e2.expression), t2.emit(i$1.PUSH, e2.name.text), t2.emit(i$1.PROPERTY_GET));
|
|
299
|
+
}, C = (e2, t2, { compileExpression: s2, reportError: r2 }) => {
|
|
300
|
+
s2(e2.expression), e2.argumentExpression ? s2(e2.argumentExpression) : r2(e2, "Element access requires an index expression"), t2.emit(i$1.ARRAY_GET);
|
|
301
|
+
}, Y$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
299
302
|
switch (e2.operator) {
|
|
300
303
|
case n__namespace.SyntaxKind.ExclamationToken:
|
|
301
|
-
|
|
304
|
+
s2(e2.operand), t2.emit(i$1.NOT);
|
|
302
305
|
break;
|
|
303
306
|
case n__namespace.SyntaxKind.MinusToken:
|
|
304
|
-
|
|
307
|
+
s2(e2.operand), t2.emit(i$1.UNARY_MINUS);
|
|
305
308
|
break;
|
|
306
309
|
case n__namespace.SyntaxKind.PlusToken:
|
|
307
|
-
|
|
310
|
+
s2(e2.operand), t2.emit(i$1.UNARY_PLUS);
|
|
308
311
|
break;
|
|
309
312
|
case n__namespace.SyntaxKind.PlusPlusToken:
|
|
310
|
-
n__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
313
|
+
n__namespace.isIdentifier(e2.operand) && (t2.emit(i$1.PUSH, e2.operand.text), t2.emit(i$1.INC, false));
|
|
311
314
|
break;
|
|
312
315
|
case n__namespace.SyntaxKind.MinusMinusToken:
|
|
313
|
-
n__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
316
|
+
n__namespace.isIdentifier(e2.operand) && (t2.emit(i$1.PUSH, e2.operand.text), t2.emit(i$1.DEC, false));
|
|
314
317
|
break;
|
|
315
318
|
}
|
|
316
|
-
},
|
|
319
|
+
}, w$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
317
320
|
switch (e2.operator) {
|
|
318
321
|
case n__namespace.SyntaxKind.PlusPlusToken:
|
|
319
|
-
n__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
322
|
+
n__namespace.isIdentifier(e2.operand) && (t2.emit(i$1.PUSH, e2.operand.text), t2.emit(i$1.INC, true));
|
|
320
323
|
break;
|
|
321
324
|
case n__namespace.SyntaxKind.MinusMinusToken:
|
|
322
|
-
n__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
325
|
+
n__namespace.isIdentifier(e2.operand) && (t2.emit(i$1.PUSH, e2.operand.text), t2.emit(i$1.DEC, true));
|
|
323
326
|
break;
|
|
324
327
|
}
|
|
325
328
|
};
|
|
326
|
-
function T
|
|
327
|
-
return !!(n__namespace.isStringLiteral(e2) || n__namespace.isStringLiteral(t2) || n__namespace.isBinaryExpression(e2) && e2.operatorToken.kind === n__namespace.SyntaxKind.PlusToken && T
|
|
329
|
+
function T(e2, t2) {
|
|
330
|
+
return !!(n__namespace.isStringLiteral(e2) || n__namespace.isStringLiteral(t2) || n__namespace.isBinaryExpression(e2) && e2.operatorToken.kind === n__namespace.SyntaxKind.PlusToken && T(e2.left, e2.right) || n__namespace.isBinaryExpression(t2) && t2.operatorToken.kind === n__namespace.SyntaxKind.PlusToken && T(t2.left, t2.right));
|
|
328
331
|
}
|
|
329
|
-
const
|
|
332
|
+
const B$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
330
333
|
const r2 = e2.operatorToken.kind;
|
|
331
|
-
switch (
|
|
334
|
+
switch (s2(e2.left), s2(e2.right), r2) {
|
|
332
335
|
case n__namespace.SyntaxKind.PlusToken:
|
|
333
|
-
T
|
|
336
|
+
T(e2.left, e2.right) ? t2.emit(i$1.CONCAT) : t2.emit(i$1.ADD);
|
|
334
337
|
break;
|
|
335
338
|
case n__namespace.SyntaxKind.MinusToken:
|
|
336
|
-
t2.emit(
|
|
339
|
+
t2.emit(i$1.SUB);
|
|
337
340
|
break;
|
|
338
341
|
case n__namespace.SyntaxKind.AsteriskToken:
|
|
339
|
-
t2.emit(
|
|
342
|
+
t2.emit(i$1.MUL);
|
|
340
343
|
break;
|
|
341
344
|
case n__namespace.SyntaxKind.SlashToken:
|
|
342
|
-
t2.emit(
|
|
345
|
+
t2.emit(i$1.DIV);
|
|
343
346
|
break;
|
|
344
347
|
case n__namespace.SyntaxKind.PercentToken:
|
|
345
|
-
t2.emit(
|
|
348
|
+
t2.emit(i$1.MOD);
|
|
346
349
|
break;
|
|
347
350
|
case n__namespace.SyntaxKind.EqualsEqualsToken:
|
|
348
|
-
t2.emit(
|
|
351
|
+
t2.emit(i$1.EQ);
|
|
349
352
|
break;
|
|
350
353
|
case n__namespace.SyntaxKind.ExclamationEqualsToken:
|
|
351
|
-
t2.emit(
|
|
354
|
+
t2.emit(i$1.NEQ);
|
|
352
355
|
break;
|
|
353
356
|
case n__namespace.SyntaxKind.LessThanToken:
|
|
354
|
-
t2.emit(
|
|
357
|
+
t2.emit(i$1.LT);
|
|
355
358
|
break;
|
|
356
359
|
case n__namespace.SyntaxKind.GreaterThanToken:
|
|
357
|
-
t2.emit(
|
|
360
|
+
t2.emit(i$1.GT);
|
|
358
361
|
break;
|
|
359
362
|
case n__namespace.SyntaxKind.LessThanEqualsToken:
|
|
360
|
-
t2.emit(
|
|
363
|
+
t2.emit(i$1.LTE);
|
|
361
364
|
break;
|
|
362
365
|
case n__namespace.SyntaxKind.GreaterThanEqualsToken:
|
|
363
|
-
t2.emit(
|
|
366
|
+
t2.emit(i$1.GTE);
|
|
364
367
|
break;
|
|
365
368
|
case n__namespace.SyntaxKind.EqualsEqualsEqualsToken:
|
|
366
|
-
t2.emit(
|
|
369
|
+
t2.emit(i$1.EQ_STRICT);
|
|
367
370
|
break;
|
|
368
371
|
case n__namespace.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
369
|
-
t2.emit(
|
|
372
|
+
t2.emit(i$1.NEQ_STRICT);
|
|
370
373
|
break;
|
|
371
374
|
case n__namespace.SyntaxKind.AmpersandAmpersandToken:
|
|
372
|
-
t2.emit(
|
|
375
|
+
t2.emit(i$1.AND);
|
|
373
376
|
break;
|
|
374
377
|
case n__namespace.SyntaxKind.BarBarToken:
|
|
375
|
-
t2.emit(
|
|
378
|
+
t2.emit(i$1.OR);
|
|
376
379
|
break;
|
|
377
380
|
}
|
|
378
|
-
}, q$1 = (e2, t2, { compileExpression:
|
|
379
|
-
|
|
380
|
-
const r2 = t2.emit(
|
|
381
|
-
|
|
382
|
-
const a2 = t2.emit(
|
|
383
|
-
t2.patchJump(r2,
|
|
384
|
-
const
|
|
385
|
-
t2.patchJump(a2,
|
|
386
|
-
},
|
|
387
|
-
|
|
388
|
-
}, V$1 = (e2, t2, { compileExpression:
|
|
381
|
+
}, q$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
382
|
+
s2(e2.condition);
|
|
383
|
+
const r2 = t2.emit(i$1.JUMP_IF_FALSE, -1);
|
|
384
|
+
s2(e2.whenTrue);
|
|
385
|
+
const a2 = t2.emit(i$1.JUMP, -1), m2 = t2.currentAddress();
|
|
386
|
+
t2.patchJump(r2, m2), s2(e2.whenFalse);
|
|
387
|
+
const l2 = t2.currentAddress();
|
|
388
|
+
t2.patchJump(a2, l2);
|
|
389
|
+
}, O = (e2, t2, { compileExpression: s2 }) => {
|
|
390
|
+
s2(e2.expression), t2.emit(i$1.TYPEOF);
|
|
391
|
+
}, V$1 = (e2, t2, { compileExpression: s2 }) => {
|
|
389
392
|
if (n__namespace.isPropertyAccessExpression(e2.expression) && n__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "fs" && e2.expression.name.text === "listFiles")
|
|
390
|
-
e2.arguments.length > 0 ?
|
|
393
|
+
e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(i$1.PUSH, "."), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(i$1.FS_LIST_FILES);
|
|
391
394
|
else if (n__namespace.isPropertyAccessExpression(e2.expression) && n__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "parse")
|
|
392
|
-
e2.arguments.length > 0 &&
|
|
395
|
+
e2.arguments.length > 0 && s2(e2.arguments[0]), t2.emit(i$1.JSON_PARSE);
|
|
396
|
+
else if (n__namespace.isPropertyAccessExpression(e2.expression) && n__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "stringify")
|
|
397
|
+
e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(i$1.PUSH_UNDEFINED), t2.emit(i$1.JSON_STRINGIFY);
|
|
393
398
|
else if (n__namespace.isIdentifier(e2.expression) && e2.expression.text === "CC")
|
|
394
|
-
e2.arguments.length > 0 &&
|
|
399
|
+
e2.arguments.length > 0 && s2(e2.arguments[0]), t2.emit(i$1.CC);
|
|
395
400
|
else if (n__namespace.isPropertyAccessExpression(e2.expression)) {
|
|
396
401
|
const r2 = e2.expression.name.text;
|
|
397
402
|
if (r2 === "substring")
|
|
398
|
-
|
|
403
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(i$1.PUSH, 0), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(i$1.STRING_SUBSTRING);
|
|
399
404
|
else if (r2 === "indexOf")
|
|
400
|
-
|
|
405
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(i$1.PUSH, ""), t2.emit(i$1.STRING_INDEXOF);
|
|
401
406
|
else if (r2 === "split")
|
|
402
|
-
|
|
407
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(i$1.PUSH, ""), t2.emit(i$1.STRING_SPLIT);
|
|
403
408
|
else if (r2 === "slice")
|
|
404
|
-
|
|
409
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(i$1.PUSH, 0), e2.arguments.length > 1 && s2(e2.arguments[1]), t2.emit(i$1.STRING_SLICE);
|
|
405
410
|
else if (r2 === "charAt")
|
|
406
|
-
|
|
411
|
+
s2(e2.expression.expression), e2.arguments.length > 0 ? s2(e2.arguments[0]) : t2.emit(i$1.PUSH, 0), t2.emit(i$1.STRING_CHARAT);
|
|
407
412
|
else if (r2 === "toUpperCase")
|
|
408
|
-
|
|
413
|
+
s2(e2.expression.expression), t2.emit(i$1.STRING_TOUPPERCASE);
|
|
409
414
|
else if (r2 === "toLowerCase")
|
|
410
|
-
|
|
415
|
+
s2(e2.expression.expression), t2.emit(i$1.STRING_TOLOWERCASE);
|
|
411
416
|
else
|
|
412
417
|
throw new Error(`Method call '${r2}' is not supported`);
|
|
413
418
|
} else
|
|
414
419
|
throw new Error("Unsupported call expression");
|
|
420
|
+
}, Q = (e2, t2, { compileExpression: s2 }) => {
|
|
421
|
+
t2.emit(i$1.OBJECT_CREATE);
|
|
422
|
+
for (const r2 of e2.properties)
|
|
423
|
+
if (n__namespace.isPropertyAssignment(r2)) {
|
|
424
|
+
let a2;
|
|
425
|
+
if (n__namespace.isIdentifier(r2.name))
|
|
426
|
+
a2 = r2.name.text;
|
|
427
|
+
else if (n__namespace.isStringLiteral(r2.name))
|
|
428
|
+
a2 = r2.name.text;
|
|
429
|
+
else
|
|
430
|
+
throw new Error("Computed property names are not supported");
|
|
431
|
+
t2.emit(i$1.PUSH, a2), s2(r2.initializer), t2.emit(i$1.PROPERTY_SET);
|
|
432
|
+
} else if (n__namespace.isShorthandPropertyAssignment(r2)) {
|
|
433
|
+
const a2 = r2.name.text;
|
|
434
|
+
t2.emit(i$1.PUSH, a2), t2.emit(i$1.LOAD, a2), t2.emit(i$1.PROPERTY_SET);
|
|
435
|
+
} else
|
|
436
|
+
throw new Error("Unsupported property type in object literal");
|
|
415
437
|
}, v = {
|
|
416
438
|
[n__namespace.SyntaxKind.StringLiteral]: d$1,
|
|
417
439
|
[n__namespace.SyntaxKind.NumericLiteral]: K,
|
|
418
|
-
[n__namespace.SyntaxKind.TrueKeyword]: b$
|
|
440
|
+
[n__namespace.SyntaxKind.TrueKeyword]: b$2,
|
|
419
441
|
[n__namespace.SyntaxKind.FalseKeyword]: F$1,
|
|
420
442
|
[n__namespace.SyntaxKind.NullKeyword]: D$1,
|
|
421
|
-
[n__namespace.SyntaxKind.Identifier]: G
|
|
422
|
-
[n__namespace.SyntaxKind.ArrayLiteralExpression]:
|
|
423
|
-
[n__namespace.SyntaxKind.BinaryExpression]:
|
|
424
|
-
[n__namespace.SyntaxKind.PrefixUnaryExpression]:
|
|
425
|
-
[n__namespace.SyntaxKind.PostfixUnaryExpression]:
|
|
443
|
+
[n__namespace.SyntaxKind.Identifier]: G,
|
|
444
|
+
[n__namespace.SyntaxKind.ArrayLiteralExpression]: H$1,
|
|
445
|
+
[n__namespace.SyntaxKind.BinaryExpression]: B$1,
|
|
446
|
+
[n__namespace.SyntaxKind.PrefixUnaryExpression]: Y$1,
|
|
447
|
+
[n__namespace.SyntaxKind.PostfixUnaryExpression]: w$1,
|
|
426
448
|
[n__namespace.SyntaxKind.CallExpression]: V$1,
|
|
427
|
-
[n__namespace.SyntaxKind.PropertyAccessExpression]:
|
|
428
|
-
[n__namespace.SyntaxKind.ElementAccessExpression]:
|
|
449
|
+
[n__namespace.SyntaxKind.PropertyAccessExpression]: J$1,
|
|
450
|
+
[n__namespace.SyntaxKind.ElementAccessExpression]: C,
|
|
429
451
|
[n__namespace.SyntaxKind.ConditionalExpression]: q$1,
|
|
430
|
-
[n__namespace.SyntaxKind.TypeOfExpression]:
|
|
431
|
-
[n__namespace.SyntaxKind.ParenthesizedExpression]:
|
|
452
|
+
[n__namespace.SyntaxKind.TypeOfExpression]: O,
|
|
453
|
+
[n__namespace.SyntaxKind.ParenthesizedExpression]: M$1,
|
|
454
|
+
[n__namespace.SyntaxKind.ObjectLiteralExpression]: Q
|
|
432
455
|
};
|
|
433
|
-
function
|
|
434
|
-
const t2 =
|
|
456
|
+
function W$1(e2) {
|
|
457
|
+
const t2 = R(e2);
|
|
435
458
|
if (t2.errors.length > 0)
|
|
436
459
|
return {
|
|
437
460
|
success: false,
|
|
438
461
|
bytecode: [],
|
|
439
462
|
errors: t2.errors
|
|
440
463
|
};
|
|
441
|
-
const
|
|
442
|
-
compileStatement:
|
|
443
|
-
compileExpression:
|
|
464
|
+
const s2 = new A$1(), r2 = n__namespace.createSourceFile("program.ts", e2, n__namespace.ScriptTarget.Latest, true), a2 = {
|
|
465
|
+
compileStatement: m2,
|
|
466
|
+
compileExpression: l2,
|
|
444
467
|
reportError: (o2, c2) => {
|
|
445
468
|
throw new Error(c2);
|
|
446
469
|
}
|
|
447
470
|
};
|
|
448
|
-
function
|
|
471
|
+
function m2(o2) {
|
|
449
472
|
const c2 = L$1[o2.kind];
|
|
450
|
-
c2 && c2(o2,
|
|
473
|
+
c2 && c2(o2, s2, a2);
|
|
451
474
|
}
|
|
452
|
-
function
|
|
475
|
+
function l2(o2) {
|
|
453
476
|
const c2 = v[o2.kind];
|
|
454
|
-
c2 && c2(o2,
|
|
477
|
+
c2 && c2(o2, s2, a2);
|
|
455
478
|
}
|
|
456
479
|
return r2.forEachChild((o2) => {
|
|
457
480
|
var c2;
|
|
458
|
-
n__namespace.isFunctionDeclaration(o2) && ((c2 = o2.name) == null ? void 0 : c2.text) === "main" && o2.body && o2.body.statements.forEach((
|
|
459
|
-
|
|
481
|
+
n__namespace.isFunctionDeclaration(o2) && ((c2 = o2.name) == null ? void 0 : c2.text) === "main" && o2.body && o2.body.statements.forEach((S) => {
|
|
482
|
+
m2(S);
|
|
460
483
|
});
|
|
461
|
-
}),
|
|
484
|
+
}), s2.emit(i$1.HALT), {
|
|
462
485
|
success: true,
|
|
463
|
-
bytecode:
|
|
486
|
+
bytecode: s2.getBytecode(),
|
|
464
487
|
errors: []
|
|
465
488
|
};
|
|
466
489
|
}
|
|
@@ -473,45 +496,51 @@ function t(r2) {
|
|
|
473
496
|
function i(r2) {
|
|
474
497
|
return typeof r2 == "boolean";
|
|
475
498
|
}
|
|
476
|
-
function
|
|
499
|
+
function e(r2) {
|
|
477
500
|
return r2 === null;
|
|
478
501
|
}
|
|
479
|
-
function
|
|
502
|
+
function f(r2) {
|
|
480
503
|
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "array";
|
|
481
504
|
}
|
|
482
505
|
function o(r2) {
|
|
483
506
|
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "undefined";
|
|
484
507
|
}
|
|
485
508
|
function c$1(r2) {
|
|
486
|
-
return
|
|
509
|
+
return r2 !== null && typeof r2 == "object" && "type" in r2 && r2.type === "object";
|
|
487
510
|
}
|
|
488
511
|
function y(r2) {
|
|
489
|
-
return
|
|
512
|
+
return n(r2) ? r2 : t(r2) || i(r2) ? r2.toString() : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? `[array:${r2.elements.length}]` : c$1(r2) ? "[object Object]" : String(r2);
|
|
513
|
+
}
|
|
514
|
+
function b$1(r2) {
|
|
515
|
+
return i(r2) ? r2 : e(r2) || o(r2) ? false : t(r2) ? r2 !== 0 : n(r2) ? r2 !== "" : f(r2) || c$1(r2) ? true : !!r2;
|
|
490
516
|
}
|
|
491
|
-
function
|
|
492
|
-
return n(r2) ? "string" : t(r2) ? "number" : i(r2) ? "boolean" :
|
|
517
|
+
function p$1(r2) {
|
|
518
|
+
return n(r2) ? "string" : t(r2) ? "number" : i(r2) ? "boolean" : e(r2) ? "null" : o(r2) ? "undefined" : f(r2) ? "array" : c$1(r2) ? "object" : "unknown";
|
|
493
519
|
}
|
|
494
|
-
function
|
|
520
|
+
function m(r2) {
|
|
495
521
|
if (t(r2)) return r2;
|
|
496
522
|
if (i(r2)) return r2 ? 1 : 0;
|
|
497
|
-
if (
|
|
523
|
+
if (e(r2)) return 0;
|
|
498
524
|
if (o(r2)) return NaN;
|
|
499
525
|
if (n(r2)) {
|
|
500
526
|
const u2 = r2.trim();
|
|
501
527
|
return u2 === "" ? 0 : Number(u2);
|
|
502
528
|
}
|
|
503
|
-
return
|
|
529
|
+
return f(r2) ? NaN : Number(r2);
|
|
504
530
|
}
|
|
505
|
-
function
|
|
531
|
+
function d(r2 = []) {
|
|
506
532
|
return { type: "array", elements: r2 };
|
|
507
533
|
}
|
|
508
534
|
function s$1() {
|
|
509
535
|
return { type: "undefined" };
|
|
510
536
|
}
|
|
537
|
+
function j$1(r2 = {}) {
|
|
538
|
+
return { type: "object", properties: r2 };
|
|
539
|
+
}
|
|
511
540
|
var l = Object.defineProperty;
|
|
512
541
|
var u = (s2, t2, n2) => t2 in s2 ? l(s2, t2, { enumerable: true, configurable: true, writable: true, value: n2 }) : s2[t2] = n2;
|
|
513
542
|
var r = (s2, t2, n2) => u(s2, typeof t2 != "symbol" ? t2 + "" : t2, n2);
|
|
514
|
-
class h {
|
|
543
|
+
let h$1 = class h {
|
|
515
544
|
constructor(t2) {
|
|
516
545
|
r(this, "connected", false);
|
|
517
546
|
r(this, "programsDir");
|
|
@@ -520,7 +549,7 @@ class h {
|
|
|
520
549
|
this.dataDir = t2, this.programsDir = c__namespace.join(t2, "programs"), this.executionsDir = c__namespace.join(t2, "executions"), this.outputsDir = c__namespace.join(t2, "outputs");
|
|
521
550
|
}
|
|
522
551
|
async connect() {
|
|
523
|
-
await
|
|
552
|
+
await G$1.promises.mkdir(this.dataDir, { recursive: true }), await G$1.promises.mkdir(this.programsDir, { recursive: true }), await G$1.promises.mkdir(this.executionsDir, { recursive: true }), await G$1.promises.mkdir(this.outputsDir, { recursive: true }), this.connected = true;
|
|
524
553
|
}
|
|
525
554
|
async disconnect() {
|
|
526
555
|
this.connected = false;
|
|
@@ -531,13 +560,13 @@ class h {
|
|
|
531
560
|
async saveProgram(t2) {
|
|
532
561
|
if (!this.connected) throw new Error("Not connected");
|
|
533
562
|
const n2 = c__namespace.join(this.programsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
|
|
534
|
-
await
|
|
563
|
+
await G$1.promises.writeFile(n2, e2, "utf-8");
|
|
535
564
|
}
|
|
536
565
|
async getProgram(t2) {
|
|
537
566
|
if (!this.connected) throw new Error("Not connected");
|
|
538
567
|
const n2 = c__namespace.join(this.programsDir, `${t2}.json`);
|
|
539
568
|
try {
|
|
540
|
-
const e2 = await
|
|
569
|
+
const e2 = await G$1.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e2);
|
|
541
570
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
542
571
|
} catch (e2) {
|
|
543
572
|
if (e2.code === "ENOENT")
|
|
@@ -548,13 +577,13 @@ class h {
|
|
|
548
577
|
async saveExecution(t2) {
|
|
549
578
|
if (!this.connected) throw new Error("Not connected");
|
|
550
579
|
const n2 = c__namespace.join(this.executionsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
|
|
551
|
-
await
|
|
580
|
+
await G$1.promises.writeFile(n2, e2, "utf-8");
|
|
552
581
|
}
|
|
553
582
|
async getExecution(t2) {
|
|
554
583
|
if (!this.connected) throw new Error("Not connected");
|
|
555
584
|
const n2 = c__namespace.join(this.executionsDir, `${t2}.json`);
|
|
556
585
|
try {
|
|
557
|
-
const e2 = await
|
|
586
|
+
const e2 = await G$1.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e2);
|
|
558
587
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
559
588
|
} catch (e2) {
|
|
560
589
|
if (e2.code === "ENOENT")
|
|
@@ -567,13 +596,13 @@ class h {
|
|
|
567
596
|
const e2 = c__namespace.join(this.outputsDir, `${t2}.output`), o2 = n2.join(`
|
|
568
597
|
`) + `
|
|
569
598
|
`;
|
|
570
|
-
await
|
|
599
|
+
await G$1.promises.appendFile(e2, o2, "utf-8");
|
|
571
600
|
}
|
|
572
601
|
async getOutput(t2) {
|
|
573
602
|
if (!this.connected) throw new Error("Not connected");
|
|
574
603
|
const n2 = c__namespace.join(this.outputsDir, `${t2}.output`);
|
|
575
604
|
try {
|
|
576
|
-
return (await
|
|
605
|
+
return (await G$1.promises.readFile(n2, "utf-8")).split(`
|
|
577
606
|
`).filter((o2) => o2.length > 0);
|
|
578
607
|
} catch (e2) {
|
|
579
608
|
if (e2.code === "ENOENT")
|
|
@@ -581,7 +610,7 @@ class h {
|
|
|
581
610
|
throw e2;
|
|
582
611
|
}
|
|
583
612
|
}
|
|
584
|
-
}
|
|
613
|
+
};
|
|
585
614
|
class p {
|
|
586
615
|
constructor(t2) {
|
|
587
616
|
r(this, "client");
|
|
@@ -643,13 +672,13 @@ class p {
|
|
|
643
672
|
return (e2 == null ? void 0 : e2.lines) || [];
|
|
644
673
|
}
|
|
645
674
|
}
|
|
646
|
-
class g {
|
|
675
|
+
let g$1 = class g {
|
|
647
676
|
static create(t2) {
|
|
648
677
|
const n2 = (t2 == null ? void 0 : t2.type) || process.env.CVM_STORAGE_TYPE || "file";
|
|
649
678
|
switch (n2) {
|
|
650
679
|
case "file": {
|
|
651
680
|
const e2 = (t2 == null ? void 0 : t2.dataDir) || process.env.CVM_DATA_DIR || ".cvm";
|
|
652
|
-
return new h(e2);
|
|
681
|
+
return new h$1(e2);
|
|
653
682
|
}
|
|
654
683
|
case "mongodb": {
|
|
655
684
|
const e2 = (t2 == null ? void 0 : t2.mongoUri) || process.env.MONGODB_URI || "mongodb://localhost:27017/cvm";
|
|
@@ -659,40 +688,40 @@ class g {
|
|
|
659
688
|
throw new Error(`Unsupported storage type: ${n2}`);
|
|
660
689
|
}
|
|
661
690
|
}
|
|
662
|
-
}
|
|
663
|
-
var
|
|
664
|
-
var
|
|
665
|
-
var
|
|
666
|
-
const
|
|
667
|
-
[
|
|
691
|
+
};
|
|
692
|
+
var b = Object.defineProperty;
|
|
693
|
+
var P = (e2, r2, t2) => r2 in e2 ? b(e2, r2, { enumerable: true, configurable: true, writable: true, value: t2 }) : e2[r2] = t2;
|
|
694
|
+
var h2 = (e2, r2, t2) => P(e2, typeof r2 != "symbol" ? r2 + "" : r2, t2);
|
|
695
|
+
const L = {
|
|
696
|
+
[i$1.ADD]: {
|
|
668
697
|
stackIn: 2,
|
|
669
698
|
stackOut: 1,
|
|
670
699
|
execute: (e2) => {
|
|
671
|
-
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 =
|
|
672
|
-
e2.stack.push(s2 +
|
|
700
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
701
|
+
e2.stack.push(s2 + o2);
|
|
673
702
|
}
|
|
674
703
|
},
|
|
675
|
-
[
|
|
704
|
+
[i$1.SUB]: {
|
|
676
705
|
stackIn: 2,
|
|
677
706
|
stackOut: 1,
|
|
678
707
|
execute: (e2) => {
|
|
679
|
-
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 =
|
|
680
|
-
e2.stack.push(s2 -
|
|
708
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
709
|
+
e2.stack.push(s2 - o2);
|
|
681
710
|
}
|
|
682
711
|
},
|
|
683
|
-
[
|
|
712
|
+
[i$1.MUL]: {
|
|
684
713
|
stackIn: 2,
|
|
685
714
|
stackOut: 1,
|
|
686
715
|
execute: (e2) => {
|
|
687
|
-
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 =
|
|
688
|
-
e2.stack.push(s2 *
|
|
716
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
717
|
+
e2.stack.push(s2 * o2);
|
|
689
718
|
}
|
|
690
719
|
},
|
|
691
|
-
[
|
|
720
|
+
[i$1.DIV]: {
|
|
692
721
|
stackIn: 2,
|
|
693
722
|
stackOut: 1,
|
|
694
723
|
execute: (e2, r2) => {
|
|
695
|
-
const t2 = e2.stack.pop(), s2 = e2.stack.pop(),
|
|
724
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = m(s2), n2 = m(t2);
|
|
696
725
|
if (n2 === 0)
|
|
697
726
|
return {
|
|
698
727
|
type: "DivisionByZero",
|
|
@@ -700,76 +729,76 @@ const C = {
|
|
|
700
729
|
pc: e2.pc,
|
|
701
730
|
opcode: r2.op
|
|
702
731
|
};
|
|
703
|
-
e2.stack.push(
|
|
732
|
+
e2.stack.push(o2 / n2);
|
|
704
733
|
}
|
|
705
734
|
},
|
|
706
|
-
[
|
|
735
|
+
[i$1.MOD]: {
|
|
707
736
|
stackIn: 2,
|
|
708
737
|
stackOut: 1,
|
|
709
738
|
execute: (e2) => {
|
|
710
|
-
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 =
|
|
711
|
-
e2.stack.push(s2 %
|
|
739
|
+
const r2 = e2.stack.pop(), t2 = e2.stack.pop(), s2 = m(t2), o2 = m(r2);
|
|
740
|
+
e2.stack.push(s2 % o2);
|
|
712
741
|
}
|
|
713
742
|
},
|
|
714
|
-
[
|
|
743
|
+
[i$1.UNARY_MINUS]: {
|
|
715
744
|
stackIn: 1,
|
|
716
745
|
stackOut: 1,
|
|
717
746
|
execute: (e2) => {
|
|
718
|
-
const r2 = e2.stack.pop(), t2 =
|
|
747
|
+
const r2 = e2.stack.pop(), t2 = m(r2);
|
|
719
748
|
e2.stack.push(-t2);
|
|
720
749
|
}
|
|
721
750
|
},
|
|
722
|
-
[
|
|
751
|
+
[i$1.UNARY_PLUS]: {
|
|
723
752
|
stackIn: 1,
|
|
724
753
|
stackOut: 1,
|
|
725
754
|
execute: (e2) => {
|
|
726
|
-
const r2 = e2.stack.pop(), t2 =
|
|
755
|
+
const r2 = e2.stack.pop(), t2 = m(r2);
|
|
727
756
|
e2.stack.push(t2);
|
|
728
757
|
}
|
|
729
758
|
}
|
|
730
|
-
},
|
|
731
|
-
[
|
|
759
|
+
}, V = {
|
|
760
|
+
[i$1.PUSH]: {
|
|
732
761
|
stackIn: 0,
|
|
733
762
|
stackOut: 1,
|
|
734
763
|
execute: (e2, r2) => {
|
|
735
764
|
e2.stack.push(r2.arg);
|
|
736
765
|
}
|
|
737
766
|
},
|
|
738
|
-
[
|
|
767
|
+
[i$1.PUSH_UNDEFINED]: {
|
|
739
768
|
stackIn: 0,
|
|
740
769
|
stackOut: 1,
|
|
741
770
|
execute: (e2) => {
|
|
742
771
|
e2.stack.push(s$1());
|
|
743
772
|
}
|
|
744
773
|
},
|
|
745
|
-
[
|
|
774
|
+
[i$1.POP]: {
|
|
746
775
|
stackIn: 1,
|
|
747
776
|
stackOut: 0,
|
|
748
777
|
execute: (e2) => {
|
|
749
778
|
e2.stack.pop();
|
|
750
779
|
}
|
|
751
780
|
}
|
|
752
|
-
},
|
|
753
|
-
[
|
|
781
|
+
}, M = {
|
|
782
|
+
[i$1.PRINT]: {
|
|
754
783
|
stackIn: 1,
|
|
755
784
|
stackOut: 0,
|
|
756
785
|
execute: (e2) => {
|
|
757
786
|
const r2 = e2.stack.pop();
|
|
758
|
-
r2 !== void 0 && e2.output.push(
|
|
787
|
+
r2 !== void 0 && e2.output.push(y(r2));
|
|
759
788
|
}
|
|
760
789
|
},
|
|
761
|
-
[
|
|
790
|
+
[i$1.CC]: {
|
|
762
791
|
stackIn: 1,
|
|
763
792
|
stackOut: 0,
|
|
764
793
|
controlsPC: true,
|
|
765
794
|
// CC pauses execution
|
|
766
795
|
execute: (e2, r2) => {
|
|
767
796
|
const t2 = e2.stack.pop();
|
|
768
|
-
e2.ccPrompt =
|
|
797
|
+
e2.ccPrompt = y(t2), e2.status = "waiting_cc";
|
|
769
798
|
}
|
|
770
799
|
}
|
|
771
|
-
},
|
|
772
|
-
[
|
|
800
|
+
}, j = {
|
|
801
|
+
[i$1.HALT]: {
|
|
773
802
|
stackIn: 0,
|
|
774
803
|
stackOut: 0,
|
|
775
804
|
controlsPC: true,
|
|
@@ -777,7 +806,7 @@ const C = {
|
|
|
777
806
|
e2.status = "complete";
|
|
778
807
|
}
|
|
779
808
|
},
|
|
780
|
-
[
|
|
809
|
+
[i$1.JUMP]: {
|
|
781
810
|
stackIn: 0,
|
|
782
811
|
stackOut: 0,
|
|
783
812
|
controlsPC: true,
|
|
@@ -800,7 +829,7 @@ const C = {
|
|
|
800
829
|
e2.pc = t2;
|
|
801
830
|
}
|
|
802
831
|
},
|
|
803
|
-
[
|
|
832
|
+
[i$1.JUMP_IF_FALSE]: {
|
|
804
833
|
stackIn: 1,
|
|
805
834
|
stackOut: 0,
|
|
806
835
|
controlsPC: true,
|
|
@@ -821,11 +850,11 @@ const C = {
|
|
|
821
850
|
pc: e2.pc,
|
|
822
851
|
opcode: r2.op
|
|
823
852
|
};
|
|
824
|
-
|
|
853
|
+
b$1(t2) ? e2.pc++ : e2.pc = s2;
|
|
825
854
|
}
|
|
826
855
|
}
|
|
827
|
-
},
|
|
828
|
-
[
|
|
856
|
+
}, F = {
|
|
857
|
+
[i$1.LOAD]: {
|
|
829
858
|
stackIn: 0,
|
|
830
859
|
stackOut: 1,
|
|
831
860
|
execute: (e2, r2) => {
|
|
@@ -833,7 +862,7 @@ const C = {
|
|
|
833
862
|
e2.variables.has(t2) ? e2.stack.push(e2.variables.get(t2)) : e2.stack.push(s$1());
|
|
834
863
|
}
|
|
835
864
|
},
|
|
836
|
-
[
|
|
865
|
+
[i$1.STORE]: {
|
|
837
866
|
stackIn: 1,
|
|
838
867
|
stackOut: 0,
|
|
839
868
|
execute: (e2, r2) => {
|
|
@@ -841,41 +870,41 @@ const C = {
|
|
|
841
870
|
e2.variables.set(r2.arg, t2);
|
|
842
871
|
}
|
|
843
872
|
}
|
|
844
|
-
},
|
|
845
|
-
[
|
|
873
|
+
}, D = {
|
|
874
|
+
[i$1.ITER_START]: {
|
|
846
875
|
stackIn: 1,
|
|
847
876
|
stackOut: 0,
|
|
848
|
-
execute: (
|
|
849
|
-
const t2 =
|
|
877
|
+
execute: (e2, r2) => {
|
|
878
|
+
const t2 = e2.stack.pop();
|
|
850
879
|
if (t2 == null)
|
|
851
880
|
return {
|
|
852
881
|
type: "TypeError",
|
|
853
882
|
message: "TypeError: Cannot iterate over null or undefined",
|
|
854
|
-
pc:
|
|
883
|
+
pc: e2.pc,
|
|
855
884
|
opcode: r2.op
|
|
856
885
|
};
|
|
857
|
-
if (!
|
|
886
|
+
if (!f(t2))
|
|
858
887
|
return {
|
|
859
888
|
type: "TypeError",
|
|
860
889
|
message: "TypeError: Cannot iterate over non-array value",
|
|
861
|
-
pc:
|
|
890
|
+
pc: e2.pc,
|
|
862
891
|
opcode: r2.op
|
|
863
892
|
};
|
|
864
|
-
if (
|
|
893
|
+
if (e2.iterators.length >= 10)
|
|
865
894
|
return {
|
|
866
895
|
type: "RuntimeError",
|
|
867
896
|
message: "RuntimeError: Maximum iterator depth exceeded",
|
|
868
|
-
pc:
|
|
897
|
+
pc: e2.pc,
|
|
869
898
|
opcode: r2.op
|
|
870
899
|
};
|
|
871
|
-
|
|
900
|
+
e2.iterators.push({
|
|
872
901
|
array: t2,
|
|
873
902
|
index: 0,
|
|
874
903
|
length: t2.elements.length
|
|
875
904
|
});
|
|
876
905
|
}
|
|
877
906
|
},
|
|
878
|
-
[
|
|
907
|
+
[i$1.ITER_NEXT]: {
|
|
879
908
|
stackIn: 0,
|
|
880
909
|
stackOut: 2,
|
|
881
910
|
// Pushes element and hasMore flag
|
|
@@ -891,7 +920,7 @@ const C = {
|
|
|
891
920
|
t2.index < t2.length ? (t2.index < t2.array.elements.length ? e2.stack.push(t2.array.elements[t2.index]) : e2.stack.push(s$1()), e2.stack.push(true), t2.index++) : (e2.stack.push(null), e2.stack.push(false));
|
|
892
921
|
}
|
|
893
922
|
},
|
|
894
|
-
[
|
|
923
|
+
[i$1.ITER_END]: {
|
|
895
924
|
stackIn: 0,
|
|
896
925
|
stackOut: 0,
|
|
897
926
|
execute: (e2, r2) => {
|
|
@@ -906,207 +935,255 @@ const C = {
|
|
|
906
935
|
}
|
|
907
936
|
}
|
|
908
937
|
};
|
|
909
|
-
function
|
|
910
|
-
const s2 = e2.stack.pop(),
|
|
938
|
+
function g2(e2, r2, t2) {
|
|
939
|
+
const s2 = e2.stack.pop(), o2 = e2.stack.pop(), n2 = t2(o2, s2);
|
|
911
940
|
e2.stack.push(n2);
|
|
912
941
|
}
|
|
913
|
-
const
|
|
914
|
-
[
|
|
942
|
+
const q = {
|
|
943
|
+
[i$1.EQ]: {
|
|
915
944
|
stackIn: 2,
|
|
916
945
|
stackOut: 1,
|
|
917
|
-
execute: (
|
|
918
|
-
if (
|
|
946
|
+
execute: (e$1, r2) => g2(e$1, r2, (t2, s2) => {
|
|
947
|
+
if (e(t2) && o(s2) || o(t2) && e(s2))
|
|
919
948
|
return true;
|
|
920
949
|
if (o(t2) && o(s2))
|
|
921
950
|
return true;
|
|
922
951
|
{
|
|
923
|
-
const
|
|
924
|
-
return !isNaN(
|
|
952
|
+
const o2 = m(t2), n2 = m(s2);
|
|
953
|
+
return !isNaN(o2) && !isNaN(n2) ? o2 === n2 : y(t2) === y(s2);
|
|
925
954
|
}
|
|
926
955
|
})
|
|
927
956
|
},
|
|
928
|
-
[
|
|
957
|
+
[i$1.NEQ]: {
|
|
929
958
|
stackIn: 2,
|
|
930
959
|
stackOut: 1,
|
|
931
|
-
execute: (
|
|
932
|
-
if (
|
|
960
|
+
execute: (e$1, r2) => g2(e$1, r2, (t2, s2) => {
|
|
961
|
+
if (e(t2) && o(s2) || o(t2) && e(s2))
|
|
933
962
|
return false;
|
|
934
963
|
if (o(t2) && o(s2))
|
|
935
964
|
return false;
|
|
936
965
|
{
|
|
937
|
-
const
|
|
938
|
-
return !isNaN(
|
|
966
|
+
const o2 = m(t2), n2 = m(s2);
|
|
967
|
+
return !isNaN(o2) && !isNaN(n2) ? o2 !== n2 : y(t2) !== y(s2);
|
|
939
968
|
}
|
|
940
969
|
})
|
|
941
970
|
},
|
|
942
|
-
[
|
|
971
|
+
[i$1.LT]: {
|
|
943
972
|
stackIn: 2,
|
|
944
973
|
stackOut: 1,
|
|
945
|
-
execute: (e2, r2) =>
|
|
946
|
-
const
|
|
947
|
-
return
|
|
974
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
975
|
+
const o2 = m(t2), n2 = m(s2);
|
|
976
|
+
return o2 < n2;
|
|
948
977
|
})
|
|
949
978
|
},
|
|
950
|
-
[
|
|
979
|
+
[i$1.GT]: {
|
|
951
980
|
stackIn: 2,
|
|
952
981
|
stackOut: 1,
|
|
953
|
-
execute: (e2, r2) =>
|
|
954
|
-
const
|
|
955
|
-
return
|
|
982
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
983
|
+
const o2 = m(t2), n2 = m(s2);
|
|
984
|
+
return o2 > n2;
|
|
956
985
|
})
|
|
957
986
|
},
|
|
958
|
-
[
|
|
987
|
+
[i$1.LTE]: {
|
|
959
988
|
stackIn: 2,
|
|
960
989
|
stackOut: 1,
|
|
961
|
-
execute: (e2, r2) =>
|
|
962
|
-
const
|
|
963
|
-
return
|
|
990
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
991
|
+
const o2 = m(t2), n2 = m(s2);
|
|
992
|
+
return o2 <= n2;
|
|
964
993
|
})
|
|
965
994
|
},
|
|
966
|
-
[
|
|
995
|
+
[i$1.GTE]: {
|
|
967
996
|
stackIn: 2,
|
|
968
997
|
stackOut: 1,
|
|
969
|
-
execute: (e2, r2) =>
|
|
970
|
-
const
|
|
971
|
-
return
|
|
998
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => {
|
|
999
|
+
const o2 = m(t2), n2 = m(s2);
|
|
1000
|
+
return o2 >= n2;
|
|
972
1001
|
})
|
|
973
1002
|
},
|
|
974
|
-
[
|
|
1003
|
+
[i$1.EQ_STRICT]: {
|
|
975
1004
|
stackIn: 2,
|
|
976
1005
|
stackOut: 1,
|
|
977
|
-
execute: (e2, r2) =>
|
|
1006
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => t2 === s2)
|
|
978
1007
|
},
|
|
979
|
-
[
|
|
1008
|
+
[i$1.NEQ_STRICT]: {
|
|
980
1009
|
stackIn: 2,
|
|
981
1010
|
stackOut: 1,
|
|
982
|
-
execute: (e2, r2) =>
|
|
1011
|
+
execute: (e2, r2) => g2(e2, r2, (t2, s2) => t2 !== s2)
|
|
983
1012
|
}
|
|
984
|
-
},
|
|
985
|
-
[
|
|
1013
|
+
}, H = {
|
|
1014
|
+
[i$1.AND]: {
|
|
986
1015
|
stackIn: 2,
|
|
987
1016
|
stackOut: 1,
|
|
988
1017
|
execute: (e2, r2) => {
|
|
989
|
-
const t2 = e2.stack.pop(), s2 = e2.stack.pop(),
|
|
990
|
-
e2.stack.push(
|
|
1018
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b$1(s2) ? t2 : s2;
|
|
1019
|
+
e2.stack.push(o2);
|
|
991
1020
|
}
|
|
992
1021
|
},
|
|
993
|
-
[
|
|
1022
|
+
[i$1.OR]: {
|
|
994
1023
|
stackIn: 2,
|
|
995
1024
|
stackOut: 1,
|
|
996
1025
|
execute: (e2, r2) => {
|
|
997
|
-
const t2 = e2.stack.pop(), s2 = e2.stack.pop(),
|
|
998
|
-
e2.stack.push(
|
|
1026
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = b$1(s2) ? s2 : t2;
|
|
1027
|
+
e2.stack.push(o2);
|
|
999
1028
|
}
|
|
1000
1029
|
},
|
|
1001
|
-
[
|
|
1030
|
+
[i$1.NOT]: {
|
|
1002
1031
|
stackIn: 1,
|
|
1003
1032
|
stackOut: 1,
|
|
1004
1033
|
execute: (e2, r2) => {
|
|
1005
|
-
const t2 = e2.stack.pop(), s2 = !
|
|
1034
|
+
const t2 = e2.stack.pop(), s2 = !b$1(t2);
|
|
1006
1035
|
e2.stack.push(s2);
|
|
1007
1036
|
}
|
|
1008
1037
|
}
|
|
1009
|
-
},
|
|
1010
|
-
[
|
|
1038
|
+
}, Y = {
|
|
1039
|
+
[i$1.ARRAY_NEW]: {
|
|
1011
1040
|
stackIn: 0,
|
|
1012
1041
|
stackOut: 1,
|
|
1013
1042
|
execute: (e2, r2) => {
|
|
1014
|
-
e2.stack.push(
|
|
1043
|
+
e2.stack.push(d());
|
|
1015
1044
|
}
|
|
1016
1045
|
},
|
|
1017
|
-
[
|
|
1046
|
+
[i$1.ARRAY_PUSH]: {
|
|
1018
1047
|
stackIn: 2,
|
|
1019
1048
|
stackOut: 1,
|
|
1020
|
-
execute: (
|
|
1021
|
-
const t2 =
|
|
1022
|
-
if (!
|
|
1049
|
+
execute: (e2, r2) => {
|
|
1050
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1051
|
+
if (!f(s2))
|
|
1023
1052
|
return {
|
|
1024
1053
|
type: "RuntimeError",
|
|
1025
1054
|
message: "ARRAY_PUSH requires an array",
|
|
1026
|
-
pc:
|
|
1055
|
+
pc: e2.pc,
|
|
1027
1056
|
opcode: r2.op
|
|
1028
1057
|
};
|
|
1029
|
-
s2.elements.push(t2),
|
|
1058
|
+
s2.elements.push(t2), e2.stack.push(s2);
|
|
1030
1059
|
}
|
|
1031
1060
|
},
|
|
1032
|
-
[
|
|
1061
|
+
[i$1.ARRAY_GET]: {
|
|
1033
1062
|
stackIn: 2,
|
|
1034
1063
|
stackOut: 1,
|
|
1035
|
-
execute: (
|
|
1036
|
-
const t$1 =
|
|
1037
|
-
if (
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1064
|
+
execute: (e2, r2) => {
|
|
1065
|
+
const t$1 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1066
|
+
if (f(s2)) {
|
|
1067
|
+
if (!t(t$1))
|
|
1068
|
+
return {
|
|
1069
|
+
type: "RuntimeError",
|
|
1070
|
+
message: "ARRAY_GET requires numeric index for arrays",
|
|
1071
|
+
pc: e2.pc,
|
|
1072
|
+
opcode: r2.op
|
|
1073
|
+
};
|
|
1074
|
+
const o2 = s2.elements[t$1] ?? null;
|
|
1075
|
+
e2.stack.push(o2);
|
|
1076
|
+
return;
|
|
1077
|
+
}
|
|
1078
|
+
if (c$1(s2)) {
|
|
1079
|
+
if (!n(t$1))
|
|
1080
|
+
return {
|
|
1081
|
+
type: "RuntimeError",
|
|
1082
|
+
message: "ARRAY_GET requires string key for objects",
|
|
1083
|
+
pc: e2.pc,
|
|
1084
|
+
opcode: r2.op
|
|
1085
|
+
};
|
|
1086
|
+
const o2 = s2.properties[t$1] ?? null;
|
|
1087
|
+
e2.stack.push(o2);
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
return {
|
|
1091
|
+
type: "RuntimeError",
|
|
1092
|
+
message: "ARRAY_GET requires an array or object",
|
|
1093
|
+
pc: e2.pc,
|
|
1094
|
+
opcode: r2.op
|
|
1095
|
+
};
|
|
1053
1096
|
}
|
|
1054
1097
|
},
|
|
1055
|
-
[
|
|
1098
|
+
[i$1.ARRAY_SET]: {
|
|
1056
1099
|
stackIn: 3,
|
|
1057
|
-
stackOut:
|
|
1058
|
-
execute: (
|
|
1059
|
-
const t$1 =
|
|
1060
|
-
if (
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1100
|
+
stackOut: 1,
|
|
1101
|
+
execute: (e2, r2) => {
|
|
1102
|
+
const t$1 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1103
|
+
if (f(o2)) {
|
|
1104
|
+
if (!t(s2))
|
|
1105
|
+
return {
|
|
1106
|
+
type: "RuntimeError",
|
|
1107
|
+
message: "ARRAY_SET requires numeric index for arrays",
|
|
1108
|
+
pc: e2.pc,
|
|
1109
|
+
opcode: r2.op
|
|
1110
|
+
};
|
|
1111
|
+
const n2 = Math.floor(s2);
|
|
1112
|
+
if (n2 < 0)
|
|
1113
|
+
return {
|
|
1114
|
+
type: "RuntimeError",
|
|
1115
|
+
message: "ARRAY_SET: Negative index not allowed",
|
|
1116
|
+
pc: e2.pc,
|
|
1117
|
+
opcode: r2.op
|
|
1118
|
+
};
|
|
1119
|
+
o2.elements[n2] = t$1, e2.stack.push(o2);
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
if (c$1(o2)) {
|
|
1123
|
+
if (!n(s2))
|
|
1124
|
+
return {
|
|
1125
|
+
type: "RuntimeError",
|
|
1126
|
+
message: "ARRAY_SET requires string key for objects",
|
|
1127
|
+
pc: e2.pc,
|
|
1128
|
+
opcode: r2.op
|
|
1129
|
+
};
|
|
1130
|
+
o2.properties[s2] = t$1, e2.stack.push(o2);
|
|
1131
|
+
return;
|
|
1132
|
+
}
|
|
1133
|
+
return {
|
|
1134
|
+
type: "RuntimeError",
|
|
1135
|
+
message: "ARRAY_SET requires an array or object",
|
|
1136
|
+
pc: e2.pc,
|
|
1137
|
+
opcode: r2.op
|
|
1138
|
+
};
|
|
1083
1139
|
}
|
|
1084
1140
|
},
|
|
1085
|
-
[
|
|
1141
|
+
[i$1.ARRAY_LEN]: {
|
|
1086
1142
|
stackIn: 1,
|
|
1087
1143
|
stackOut: 1,
|
|
1088
|
-
execute: (
|
|
1089
|
-
const t2 =
|
|
1090
|
-
if (!
|
|
1144
|
+
execute: (e2, r2) => {
|
|
1145
|
+
const t2 = e2.stack.pop();
|
|
1146
|
+
if (!f(t2))
|
|
1091
1147
|
return {
|
|
1092
1148
|
type: "RuntimeError",
|
|
1093
1149
|
message: "ARRAY_LEN requires an array",
|
|
1094
|
-
pc:
|
|
1150
|
+
pc: e2.pc,
|
|
1095
1151
|
opcode: r2.op
|
|
1096
1152
|
};
|
|
1097
|
-
|
|
1153
|
+
e2.stack.push(t2.elements.length);
|
|
1098
1154
|
}
|
|
1099
1155
|
}
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1156
|
+
};
|
|
1157
|
+
function x(e2) {
|
|
1158
|
+
if (e2 === null) return null;
|
|
1159
|
+
if (e2 !== void 0) {
|
|
1160
|
+
if (typeof e2 == "string" || typeof e2 == "number" || typeof e2 == "boolean" || e2 && typeof e2 == "object" && e2.type === "array" && Array.isArray(e2.elements))
|
|
1161
|
+
return e2;
|
|
1162
|
+
if (Array.isArray(e2)) {
|
|
1163
|
+
const r2 = d();
|
|
1164
|
+
return r2.elements = e2.map(x), r2;
|
|
1165
|
+
}
|
|
1166
|
+
if (e2 && typeof e2 == "object" && e2.type === "object" && e2.properties)
|
|
1167
|
+
return e2;
|
|
1168
|
+
if (typeof e2 == "object") {
|
|
1169
|
+
const r2 = j$1();
|
|
1170
|
+
for (const [t2, s2] of Object.entries(e2))
|
|
1171
|
+
r2.properties[t2] = x(s2);
|
|
1172
|
+
return r2;
|
|
1173
|
+
}
|
|
1174
|
+
return null;
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
const $ = {
|
|
1178
|
+
[i$1.CONCAT]: {
|
|
1102
1179
|
stackIn: 2,
|
|
1103
1180
|
stackOut: 1,
|
|
1104
1181
|
execute: (e2, r2) => {
|
|
1105
1182
|
const t2 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1106
|
-
e2.stack.push(
|
|
1183
|
+
e2.stack.push(y(s2) + y(t2));
|
|
1107
1184
|
}
|
|
1108
1185
|
},
|
|
1109
|
-
[
|
|
1186
|
+
[i$1.STRING_LEN]: {
|
|
1110
1187
|
stackIn: 1,
|
|
1111
1188
|
stackOut: 1,
|
|
1112
1189
|
execute: (e2, r2) => {
|
|
@@ -1121,25 +1198,25 @@ const V = {
|
|
|
1121
1198
|
e2.stack.push(t2.length);
|
|
1122
1199
|
}
|
|
1123
1200
|
},
|
|
1124
|
-
[
|
|
1201
|
+
[i$1.LENGTH]: {
|
|
1125
1202
|
stackIn: 1,
|
|
1126
1203
|
stackOut: 1,
|
|
1127
|
-
execute: (
|
|
1128
|
-
const t2 =
|
|
1204
|
+
execute: (e2, r2) => {
|
|
1205
|
+
const t2 = e2.stack.pop();
|
|
1129
1206
|
if (n(t2))
|
|
1130
|
-
|
|
1131
|
-
else if (
|
|
1132
|
-
|
|
1207
|
+
e2.stack.push(t2.length);
|
|
1208
|
+
else if (f(t2))
|
|
1209
|
+
e2.stack.push(t2.elements.length);
|
|
1133
1210
|
else
|
|
1134
1211
|
return {
|
|
1135
1212
|
type: "RuntimeError",
|
|
1136
1213
|
message: "LENGTH requires a string or array",
|
|
1137
|
-
pc:
|
|
1214
|
+
pc: e2.pc,
|
|
1138
1215
|
opcode: r2.op
|
|
1139
1216
|
};
|
|
1140
1217
|
}
|
|
1141
1218
|
},
|
|
1142
|
-
[
|
|
1219
|
+
[i$1.JSON_PARSE]: {
|
|
1143
1220
|
stackIn: 1,
|
|
1144
1221
|
stackOut: 1,
|
|
1145
1222
|
execute: (e2, r2) => {
|
|
@@ -1153,22 +1230,22 @@ const V = {
|
|
|
1153
1230
|
};
|
|
1154
1231
|
try {
|
|
1155
1232
|
const s2 = JSON.parse(t2);
|
|
1156
|
-
|
|
1233
|
+
e2.stack.push(x(s2));
|
|
1157
1234
|
} catch {
|
|
1158
|
-
e2.stack.push(
|
|
1235
|
+
e2.stack.push(null);
|
|
1159
1236
|
}
|
|
1160
1237
|
}
|
|
1161
1238
|
},
|
|
1162
|
-
[
|
|
1239
|
+
[i$1.TYPEOF]: {
|
|
1163
1240
|
stackIn: 1,
|
|
1164
1241
|
stackOut: 1,
|
|
1165
1242
|
execute: (e2, r2) => {
|
|
1166
1243
|
const t2 = e2.stack.pop();
|
|
1167
|
-
e2.stack.push(
|
|
1244
|
+
e2.stack.push(p$1(t2));
|
|
1168
1245
|
}
|
|
1169
1246
|
}
|
|
1170
|
-
},
|
|
1171
|
-
[
|
|
1247
|
+
}, B = {
|
|
1248
|
+
[i$1.INC]: {
|
|
1172
1249
|
stackIn: 1,
|
|
1173
1250
|
stackOut: 1,
|
|
1174
1251
|
execute: (e2, r2) => {
|
|
@@ -1180,13 +1257,13 @@ const V = {
|
|
|
1180
1257
|
pc: e2.pc,
|
|
1181
1258
|
opcode: r2.op
|
|
1182
1259
|
};
|
|
1183
|
-
const s2 = e2.variables.get(t2) ?? 0,
|
|
1184
|
-
e2.variables.set(t2,
|
|
1260
|
+
const s2 = e2.variables.get(t2) ?? 0, o2 = m(s2) + 1;
|
|
1261
|
+
e2.variables.set(t2, o2);
|
|
1185
1262
|
const n2 = r2.arg === true;
|
|
1186
|
-
e2.stack.push(n2 ?
|
|
1263
|
+
e2.stack.push(n2 ? m(s2) : o2);
|
|
1187
1264
|
}
|
|
1188
1265
|
},
|
|
1189
|
-
[
|
|
1266
|
+
[i$1.DEC]: {
|
|
1190
1267
|
stackIn: 1,
|
|
1191
1268
|
stackOut: 1,
|
|
1192
1269
|
execute: (e2, r2) => {
|
|
@@ -1198,14 +1275,14 @@ const V = {
|
|
|
1198
1275
|
pc: e2.pc,
|
|
1199
1276
|
opcode: r2.op
|
|
1200
1277
|
};
|
|
1201
|
-
const s2 = e2.variables.get(t2) ?? 0,
|
|
1202
|
-
e2.variables.set(t2,
|
|
1278
|
+
const s2 = e2.variables.get(t2) ?? 0, o2 = m(s2) - 1;
|
|
1279
|
+
e2.variables.set(t2, o2);
|
|
1203
1280
|
const n2 = r2.arg === true;
|
|
1204
|
-
e2.stack.push(n2 ?
|
|
1281
|
+
e2.stack.push(n2 ? m(s2) : o2);
|
|
1205
1282
|
}
|
|
1206
1283
|
}
|
|
1207
|
-
},
|
|
1208
|
-
[
|
|
1284
|
+
}, J = {
|
|
1285
|
+
[i$1.RETURN]: {
|
|
1209
1286
|
stackIn: 0,
|
|
1210
1287
|
stackOut: 0,
|
|
1211
1288
|
controlsPC: true,
|
|
@@ -1214,7 +1291,7 @@ const V = {
|
|
|
1214
1291
|
e2.returnValue = t2, e2.status = "complete";
|
|
1215
1292
|
}
|
|
1216
1293
|
},
|
|
1217
|
-
[
|
|
1294
|
+
[i$1.BREAK]: {
|
|
1218
1295
|
stackIn: 0,
|
|
1219
1296
|
stackOut: 0,
|
|
1220
1297
|
controlsPC: true,
|
|
@@ -1237,7 +1314,7 @@ const V = {
|
|
|
1237
1314
|
e2.pc = t2;
|
|
1238
1315
|
}
|
|
1239
1316
|
},
|
|
1240
|
-
[
|
|
1317
|
+
[i$1.CONTINUE]: {
|
|
1241
1318
|
stackIn: 0,
|
|
1242
1319
|
stackOut: 0,
|
|
1243
1320
|
controlsPC: true,
|
|
@@ -1260,37 +1337,37 @@ const V = {
|
|
|
1260
1337
|
e2.pc = t2;
|
|
1261
1338
|
}
|
|
1262
1339
|
},
|
|
1263
|
-
[
|
|
1340
|
+
[i$1.FS_LIST_FILES]: {
|
|
1264
1341
|
stackIn: 1,
|
|
1265
1342
|
// Minimum 1 argument (path), optionally 2 (path + options)
|
|
1266
1343
|
stackOut: 0,
|
|
1267
1344
|
controlsPC: true,
|
|
1268
|
-
execute: (
|
|
1269
|
-
if (
|
|
1345
|
+
execute: (e2, r2) => {
|
|
1346
|
+
if (e2.stack.length < 1)
|
|
1270
1347
|
return {
|
|
1271
1348
|
type: "StackUnderflow",
|
|
1272
1349
|
message: "FS_LIST_FILES: Stack underflow",
|
|
1273
|
-
pc:
|
|
1350
|
+
pc: e2.pc,
|
|
1274
1351
|
opcode: r2.op
|
|
1275
1352
|
};
|
|
1276
1353
|
let t2, s2 = {};
|
|
1277
|
-
const
|
|
1278
|
-
if (
|
|
1354
|
+
const o2 = e2.stack[e2.stack.length - 1];
|
|
1355
|
+
if (e2.stack.length >= 2 && typeof o2 == "object" && o2 !== null && !f(o2) && (s2 = e2.stack.pop()), t2 = e2.stack.pop(), !n(t2))
|
|
1279
1356
|
return {
|
|
1280
1357
|
type: "RuntimeError",
|
|
1281
1358
|
message: "FS_LIST_FILES requires a string path",
|
|
1282
|
-
pc:
|
|
1359
|
+
pc: e2.pc,
|
|
1283
1360
|
opcode: r2.op
|
|
1284
1361
|
};
|
|
1285
|
-
|
|
1362
|
+
e2.fsOperation = {
|
|
1286
1363
|
type: "listFiles",
|
|
1287
1364
|
path: t2,
|
|
1288
1365
|
options: s2
|
|
1289
|
-
},
|
|
1366
|
+
}, e2.status = "waiting_fs";
|
|
1290
1367
|
}
|
|
1291
1368
|
},
|
|
1292
1369
|
// String method handlers
|
|
1293
|
-
[
|
|
1370
|
+
[i$1.STRING_SUBSTRING]: {
|
|
1294
1371
|
stackIn: 2,
|
|
1295
1372
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
1296
1373
|
stackOut: 1,
|
|
@@ -1303,29 +1380,29 @@ const V = {
|
|
|
1303
1380
|
opcode: r2.op
|
|
1304
1381
|
};
|
|
1305
1382
|
const t2 = e2.stack.length;
|
|
1306
|
-
let s2,
|
|
1383
|
+
let s2, o2, n$12;
|
|
1307
1384
|
const a2 = e2.stack[t2 - 1], i2 = e2.stack[t2 - 2];
|
|
1308
|
-
if (t2 >= 3 && typeof a2 == "number" && typeof i2 == "number" ? (n$12 = e2.stack.pop(),
|
|
1385
|
+
if (t2 >= 3 && typeof a2 == "number" && typeof i2 == "number" ? (n$12 = e2.stack.pop(), o2 = e2.stack.pop(), s2 = e2.stack.pop()) : (o2 = e2.stack.pop(), s2 = e2.stack.pop(), n$12 = void 0), !n(s2))
|
|
1309
1386
|
return {
|
|
1310
1387
|
type: "RuntimeError",
|
|
1311
1388
|
message: "STRING_SUBSTRING requires a string",
|
|
1312
1389
|
pc: e2.pc,
|
|
1313
1390
|
opcode: r2.op
|
|
1314
1391
|
};
|
|
1315
|
-
if (typeof
|
|
1392
|
+
if (typeof o2 != "number")
|
|
1316
1393
|
return {
|
|
1317
1394
|
type: "RuntimeError",
|
|
1318
1395
|
message: "STRING_SUBSTRING requires numeric start index",
|
|
1319
1396
|
pc: e2.pc,
|
|
1320
1397
|
opcode: r2.op
|
|
1321
1398
|
};
|
|
1322
|
-
const
|
|
1323
|
-
|
|
1324
|
-
const I2 = n$12 !== void 0 ? s2.substring(
|
|
1399
|
+
const u2 = s2.length;
|
|
1400
|
+
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 I2 = n$12 !== void 0 ? s2.substring(o2, n$12) : s2.substring(o2);
|
|
1325
1402
|
e2.stack.push(I2);
|
|
1326
1403
|
}
|
|
1327
1404
|
},
|
|
1328
|
-
[
|
|
1405
|
+
[i$1.STRING_INDEXOF]: {
|
|
1329
1406
|
stackIn: 2,
|
|
1330
1407
|
stackOut: 1,
|
|
1331
1408
|
execute: (e2, r2) => {
|
|
@@ -1340,7 +1417,7 @@ const V = {
|
|
|
1340
1417
|
e2.stack.push(s2.indexOf(t2));
|
|
1341
1418
|
}
|
|
1342
1419
|
},
|
|
1343
|
-
[
|
|
1420
|
+
[i$1.STRING_SPLIT]: {
|
|
1344
1421
|
stackIn: 2,
|
|
1345
1422
|
stackOut: 1,
|
|
1346
1423
|
execute: (e2, r2) => {
|
|
@@ -1352,11 +1429,11 @@ const V = {
|
|
|
1352
1429
|
pc: e2.pc,
|
|
1353
1430
|
opcode: r2.op
|
|
1354
1431
|
};
|
|
1355
|
-
let
|
|
1356
|
-
t2 === "" ?
|
|
1432
|
+
let o2;
|
|
1433
|
+
t2 === "" ? o2 = s2.split("") : o2 = s2.split(t2), e2.stack.push(d(o2));
|
|
1357
1434
|
}
|
|
1358
1435
|
},
|
|
1359
|
-
[
|
|
1436
|
+
[i$1.STRING_SLICE]: {
|
|
1360
1437
|
stackIn: 2,
|
|
1361
1438
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
1362
1439
|
stackOut: 1,
|
|
@@ -1369,27 +1446,27 @@ const V = {
|
|
|
1369
1446
|
opcode: r2.op
|
|
1370
1447
|
};
|
|
1371
1448
|
const t2 = e2.stack.length;
|
|
1372
|
-
let s2,
|
|
1449
|
+
let s2, o2, n$12;
|
|
1373
1450
|
const a2 = e2.stack.length >= 1 ? e2.stack[t2 - 1] : void 0, i2 = e2.stack.length >= 2 ? e2.stack[t2 - 2] : void 0;
|
|
1374
|
-
if (t2 >= 3 && typeof a2 == "number" && typeof i2 == "number" ? (n$12 = e2.stack.pop(),
|
|
1451
|
+
if (t2 >= 3 && typeof a2 == "number" && typeof i2 == "number" ? (n$12 = e2.stack.pop(), o2 = e2.stack.pop(), s2 = e2.stack.pop()) : (o2 = e2.stack.pop(), s2 = e2.stack.pop(), n$12 = void 0), !n(s2))
|
|
1375
1452
|
return {
|
|
1376
1453
|
type: "RuntimeError",
|
|
1377
1454
|
message: "STRING_SLICE requires a string",
|
|
1378
1455
|
pc: e2.pc,
|
|
1379
1456
|
opcode: r2.op
|
|
1380
1457
|
};
|
|
1381
|
-
if (typeof
|
|
1458
|
+
if (typeof o2 != "number")
|
|
1382
1459
|
return {
|
|
1383
1460
|
type: "RuntimeError",
|
|
1384
1461
|
message: "STRING_SLICE requires numeric start index",
|
|
1385
1462
|
pc: e2.pc,
|
|
1386
1463
|
opcode: r2.op
|
|
1387
1464
|
};
|
|
1388
|
-
const
|
|
1389
|
-
e2.stack.push(
|
|
1465
|
+
const u2 = n$12 !== void 0 ? s2.slice(o2, n$12) : s2.slice(o2);
|
|
1466
|
+
e2.stack.push(u2);
|
|
1390
1467
|
}
|
|
1391
1468
|
},
|
|
1392
|
-
[
|
|
1469
|
+
[i$1.STRING_CHARAT]: {
|
|
1393
1470
|
stackIn: 2,
|
|
1394
1471
|
stackOut: 1,
|
|
1395
1472
|
execute: (e2, r2) => {
|
|
@@ -1408,11 +1485,11 @@ const V = {
|
|
|
1408
1485
|
pc: e2.pc,
|
|
1409
1486
|
opcode: r2.op
|
|
1410
1487
|
};
|
|
1411
|
-
const
|
|
1412
|
-
e2.stack.push(
|
|
1488
|
+
const o2 = s2.charAt(t2);
|
|
1489
|
+
e2.stack.push(o2);
|
|
1413
1490
|
}
|
|
1414
1491
|
},
|
|
1415
|
-
[
|
|
1492
|
+
[i$1.STRING_TOUPPERCASE]: {
|
|
1416
1493
|
stackIn: 1,
|
|
1417
1494
|
stackOut: 1,
|
|
1418
1495
|
execute: (e2, r2) => {
|
|
@@ -1427,7 +1504,7 @@ const V = {
|
|
|
1427
1504
|
e2.stack.push(t2.toUpperCase());
|
|
1428
1505
|
}
|
|
1429
1506
|
},
|
|
1430
|
-
[
|
|
1507
|
+
[i$1.STRING_TOLOWERCASE]: {
|
|
1431
1508
|
stackIn: 1,
|
|
1432
1509
|
stackOut: 1,
|
|
1433
1510
|
execute: (e2, r2) => {
|
|
@@ -1442,26 +1519,98 @@ const V = {
|
|
|
1442
1519
|
e2.stack.push(t2.toLowerCase());
|
|
1443
1520
|
}
|
|
1444
1521
|
}
|
|
1445
|
-
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1522
|
+
};
|
|
1523
|
+
function _(e2) {
|
|
1524
|
+
if (f(e2))
|
|
1525
|
+
return e2.elements.map(_);
|
|
1526
|
+
if (c$1(e2)) {
|
|
1527
|
+
const r2 = {};
|
|
1528
|
+
for (const [t2, s2] of Object.entries(e2.properties))
|
|
1529
|
+
r2[t2] = _(s2);
|
|
1530
|
+
return r2;
|
|
1531
|
+
}
|
|
1532
|
+
if (!o(e2))
|
|
1533
|
+
return e2;
|
|
1534
|
+
}
|
|
1535
|
+
const W = {
|
|
1536
|
+
[i$1.OBJECT_CREATE]: {
|
|
1537
|
+
stackIn: 0,
|
|
1538
|
+
stackOut: 1,
|
|
1539
|
+
execute: (e2) => {
|
|
1540
|
+
e2.stack.push(j$1());
|
|
1541
|
+
}
|
|
1542
|
+
},
|
|
1543
|
+
[i$1.PROPERTY_SET]: {
|
|
1544
|
+
stackIn: 3,
|
|
1545
|
+
stackOut: 1,
|
|
1546
|
+
execute: (e2, r2) => {
|
|
1547
|
+
const t2 = e2.stack.pop(), s2 = e2.stack.pop(), o2 = e2.stack.pop();
|
|
1548
|
+
if (!c$1(o2))
|
|
1549
|
+
return {
|
|
1550
|
+
type: "RuntimeError",
|
|
1551
|
+
message: `Cannot set property '${s2}' on ${p$1(o2)}`,
|
|
1552
|
+
pc: e2.pc,
|
|
1553
|
+
opcode: r2.op
|
|
1554
|
+
};
|
|
1555
|
+
if (!n(s2))
|
|
1556
|
+
return {
|
|
1557
|
+
type: "RuntimeError",
|
|
1558
|
+
message: "Property key must be a string",
|
|
1559
|
+
pc: e2.pc,
|
|
1560
|
+
opcode: r2.op
|
|
1561
|
+
};
|
|
1562
|
+
o2.properties[s2] = t2, e2.stack.push(o2);
|
|
1563
|
+
}
|
|
1564
|
+
},
|
|
1565
|
+
[i$1.PROPERTY_GET]: {
|
|
1566
|
+
stackIn: 2,
|
|
1567
|
+
stackOut: 1,
|
|
1568
|
+
execute: (e$1, r2) => {
|
|
1569
|
+
const t2 = e$1.stack.pop(), s2 = e$1.stack.pop();
|
|
1570
|
+
if (e(s2) || o(s2))
|
|
1571
|
+
return {
|
|
1572
|
+
type: "RuntimeError",
|
|
1573
|
+
message: `Cannot read property '${t2}' of ${p$1(s2)}`,
|
|
1574
|
+
pc: e$1.pc,
|
|
1575
|
+
opcode: r2.op
|
|
1576
|
+
};
|
|
1577
|
+
if (!c$1(s2)) {
|
|
1578
|
+
e$1.stack.push(s$1());
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
const o$1 = s2.properties[y(t2)];
|
|
1582
|
+
e$1.stack.push(o$1 ?? s$1());
|
|
1583
|
+
}
|
|
1584
|
+
},
|
|
1585
|
+
[i$1.JSON_STRINGIFY]: {
|
|
1586
|
+
stackIn: 1,
|
|
1587
|
+
stackOut: 1,
|
|
1588
|
+
execute: (e2) => {
|
|
1589
|
+
const r2 = e2.stack.pop(), t2 = _(r2);
|
|
1590
|
+
e2.stack.push(JSON.stringify(t2));
|
|
1591
|
+
}
|
|
1592
|
+
}
|
|
1593
|
+
}, z = {
|
|
1450
1594
|
...L,
|
|
1451
|
-
...M,
|
|
1452
1595
|
...V,
|
|
1596
|
+
...M,
|
|
1597
|
+
...j,
|
|
1453
1598
|
...F,
|
|
1454
1599
|
...D,
|
|
1455
1600
|
...q,
|
|
1456
1601
|
...H,
|
|
1457
|
-
...Y
|
|
1602
|
+
...Y,
|
|
1603
|
+
...$,
|
|
1604
|
+
...B,
|
|
1605
|
+
...J,
|
|
1606
|
+
...W
|
|
1458
1607
|
};
|
|
1459
1608
|
class N {
|
|
1460
1609
|
validateStack(r2, t2, s2) {
|
|
1461
1610
|
if (s2.stack.length < r2.stackIn)
|
|
1462
1611
|
return {
|
|
1463
1612
|
type: "StackUnderflow",
|
|
1464
|
-
message: `${
|
|
1613
|
+
message: `${i$1[t2.op]}: Stack underflow`,
|
|
1465
1614
|
pc: s2.pc,
|
|
1466
1615
|
opcode: t2.op
|
|
1467
1616
|
};
|
|
@@ -1477,20 +1626,20 @@ class N {
|
|
|
1477
1626
|
...t2
|
|
1478
1627
|
};
|
|
1479
1628
|
for (; s2.status === "running" && s2.pc < r2.length; ) {
|
|
1480
|
-
const
|
|
1629
|
+
const o2 = r2[s2.pc], n2 = z[o2.op];
|
|
1481
1630
|
if (n2) {
|
|
1482
|
-
const a2 = this.validateStack(n2,
|
|
1631
|
+
const a2 = this.validateStack(n2, o2, s2);
|
|
1483
1632
|
if (a2) {
|
|
1484
1633
|
s2.status = "error", s2.error = a2.message;
|
|
1485
1634
|
break;
|
|
1486
1635
|
}
|
|
1487
|
-
if ((
|
|
1636
|
+
if ((o2.op === i$1.JUMP || o2.op === i$1.JUMP_IF_FALSE || o2.op === i$1.BREAK || o2.op === i$1.CONTINUE) && o2.arg !== void 0 && o2.arg >= r2.length) {
|
|
1488
1637
|
s2.status = "error";
|
|
1489
|
-
const
|
|
1490
|
-
s2.error = `Invalid ${
|
|
1638
|
+
const u2 = o2.op === i$1.JUMP || o2.op === i$1.JUMP_IF_FALSE ? "jump" : o2.op === i$1.BREAK ? "break" : "continue";
|
|
1639
|
+
s2.error = `Invalid ${u2} target: ${o2.arg}`;
|
|
1491
1640
|
break;
|
|
1492
1641
|
}
|
|
1493
|
-
const i2 = n2.execute(s2,
|
|
1642
|
+
const i2 = n2.execute(s2, o2);
|
|
1494
1643
|
if (i2) {
|
|
1495
1644
|
s2.status = "error", s2.error = i2.message;
|
|
1496
1645
|
break;
|
|
@@ -1498,7 +1647,7 @@ class N {
|
|
|
1498
1647
|
n2.controlsPC || s2.pc++;
|
|
1499
1648
|
continue;
|
|
1500
1649
|
}
|
|
1501
|
-
s2.status = "error", s2.error = `Unknown opcode: ${
|
|
1650
|
+
s2.status = "error", s2.error = `Unknown opcode: ${i$1[o2.op]}`;
|
|
1502
1651
|
break;
|
|
1503
1652
|
}
|
|
1504
1653
|
return s2;
|
|
@@ -1506,31 +1655,31 @@ class N {
|
|
|
1506
1655
|
resume(r2, t2, s2) {
|
|
1507
1656
|
if (r2.status !== "waiting_cc")
|
|
1508
1657
|
throw new Error("Cannot resume: VM not waiting for CC");
|
|
1509
|
-
const
|
|
1658
|
+
const o2 = {
|
|
1510
1659
|
...r2,
|
|
1511
1660
|
stack: [...r2.stack, t2],
|
|
1512
1661
|
status: "running",
|
|
1513
1662
|
ccPrompt: void 0,
|
|
1514
1663
|
pc: r2.pc + 1
|
|
1515
1664
|
};
|
|
1516
|
-
return this.execute(s2,
|
|
1665
|
+
return this.execute(s2, o2);
|
|
1517
1666
|
}
|
|
1518
1667
|
resumeWithFsResult(r2, t2, s2) {
|
|
1519
1668
|
if (r2.status !== "waiting_fs")
|
|
1520
1669
|
throw new Error("Cannot resume: VM not waiting for FS operation");
|
|
1521
|
-
const
|
|
1670
|
+
const o2 = {
|
|
1522
1671
|
...r2,
|
|
1523
1672
|
stack: [...r2.stack, t2],
|
|
1524
1673
|
status: "running",
|
|
1525
1674
|
fsOperation: void 0,
|
|
1526
1675
|
pc: r2.pc + 1
|
|
1527
1676
|
};
|
|
1528
|
-
return this.execute(s2,
|
|
1677
|
+
return this.execute(s2, o2);
|
|
1529
1678
|
}
|
|
1530
1679
|
}
|
|
1531
|
-
class
|
|
1680
|
+
class A2 {
|
|
1532
1681
|
constructor() {
|
|
1533
|
-
|
|
1682
|
+
h2(this, "sandboxPaths", []);
|
|
1534
1683
|
const r2 = process.env.CVM_SANDBOX_PATHS, t2 = process.env.CVM_SANDBOX_ROOT;
|
|
1535
1684
|
r2 ? this.sandboxPaths = r2.split(",").map((s2) => c__namespace.resolve(s2.trim())) : t2 && (this.sandboxPaths = [c__namespace.resolve(t2)]);
|
|
1536
1685
|
}
|
|
@@ -1541,12 +1690,12 @@ class x {
|
|
|
1541
1690
|
);
|
|
1542
1691
|
}
|
|
1543
1692
|
listFiles(r2, t2 = {}) {
|
|
1544
|
-
const s2 =
|
|
1693
|
+
const s2 = d();
|
|
1545
1694
|
if (!this.isPathAllowed(r2))
|
|
1546
1695
|
return s2;
|
|
1547
1696
|
try {
|
|
1548
|
-
const
|
|
1549
|
-
this.listFilesRecursive(
|
|
1697
|
+
const o2 = c__namespace.resolve(r2);
|
|
1698
|
+
this.listFilesRecursive(o2, o2, s2.elements, t2);
|
|
1550
1699
|
} catch {
|
|
1551
1700
|
}
|
|
1552
1701
|
return s2;
|
|
@@ -1560,24 +1709,24 @@ class x {
|
|
|
1560
1709
|
return true;
|
|
1561
1710
|
}
|
|
1562
1711
|
}
|
|
1563
|
-
listFilesRecursive(r2, t2, s2,
|
|
1712
|
+
listFilesRecursive(r2, t2, s2, o2, n2 = 0) {
|
|
1564
1713
|
try {
|
|
1565
|
-
const a2 =
|
|
1714
|
+
const a2 = G__namespace.readdirSync(t2, { withFileTypes: true });
|
|
1566
1715
|
for (const i2 of a2) {
|
|
1567
|
-
const
|
|
1568
|
-
i2.isSymbolicLink() ||
|
|
1716
|
+
const u2 = c__namespace.join(t2, i2.name), I2 = c__namespace.relative(r2, u2);
|
|
1717
|
+
i2.isSymbolicLink() || o2.filter && !this.matchesPattern(I2, o2.filter) || (s2.push(u2), i2.isDirectory() && o2.recursive && this.listFilesRecursive(r2, u2, s2, o2, n2 + 1));
|
|
1569
1718
|
}
|
|
1570
1719
|
} catch {
|
|
1571
1720
|
}
|
|
1572
1721
|
}
|
|
1573
1722
|
}
|
|
1574
|
-
new
|
|
1575
|
-
class
|
|
1723
|
+
new A2();
|
|
1724
|
+
class te {
|
|
1576
1725
|
constructor(r2, t2) {
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
r2 ? this.storage = r2 : this.storage = g.create(), this.fileSystem = t2 || new
|
|
1726
|
+
h2(this, "vms", /* @__PURE__ */ new Map());
|
|
1727
|
+
h2(this, "storage");
|
|
1728
|
+
h2(this, "fileSystem");
|
|
1729
|
+
r2 ? this.storage = r2 : this.storage = g$1.create(), this.fileSystem = t2 || new A2();
|
|
1581
1730
|
}
|
|
1582
1731
|
/**
|
|
1583
1732
|
* Initialize the VMManager (connect to database)
|
|
@@ -1595,10 +1744,10 @@ class X {
|
|
|
1595
1744
|
* Load and compile a program from source code
|
|
1596
1745
|
*/
|
|
1597
1746
|
async loadProgram(r2, t2) {
|
|
1598
|
-
const s2 =
|
|
1747
|
+
const s2 = W$1(t2);
|
|
1599
1748
|
if (!s2.success)
|
|
1600
1749
|
throw new Error(`Compilation failed: ${s2.errors.join(", ")}`);
|
|
1601
|
-
const
|
|
1750
|
+
const o2 = {
|
|
1602
1751
|
id: r2,
|
|
1603
1752
|
name: r2,
|
|
1604
1753
|
source: t2,
|
|
@@ -1606,7 +1755,7 @@ class X {
|
|
|
1606
1755
|
// VM decides internal format
|
|
1607
1756
|
created: /* @__PURE__ */ new Date()
|
|
1608
1757
|
};
|
|
1609
|
-
await this.storage.saveProgram(
|
|
1758
|
+
await this.storage.saveProgram(o2);
|
|
1610
1759
|
}
|
|
1611
1760
|
/**
|
|
1612
1761
|
* Start execution of a loaded program
|
|
@@ -1614,7 +1763,7 @@ class X {
|
|
|
1614
1763
|
async startExecution(r2, t2) {
|
|
1615
1764
|
if (!await this.storage.getProgram(r2))
|
|
1616
1765
|
throw new Error(`Program not found: ${r2}`);
|
|
1617
|
-
const
|
|
1766
|
+
const o2 = {
|
|
1618
1767
|
id: t2,
|
|
1619
1768
|
programId: r2,
|
|
1620
1769
|
state: "READY",
|
|
@@ -1623,7 +1772,7 @@ class X {
|
|
|
1623
1772
|
variables: {},
|
|
1624
1773
|
created: /* @__PURE__ */ new Date()
|
|
1625
1774
|
};
|
|
1626
|
-
await this.storage.saveExecution(
|
|
1775
|
+
await this.storage.saveExecution(o2);
|
|
1627
1776
|
const n2 = new N();
|
|
1628
1777
|
this.vms.set(t2, n2);
|
|
1629
1778
|
}
|
|
@@ -1639,14 +1788,14 @@ class X {
|
|
|
1639
1788
|
const s2 = await this.storage.getProgram(t2.programId);
|
|
1640
1789
|
if (!s2)
|
|
1641
1790
|
throw new Error(`Program not found: ${t2.programId}`);
|
|
1642
|
-
let
|
|
1643
|
-
|
|
1791
|
+
let o2 = this.vms.get(r2);
|
|
1792
|
+
o2 || (o2 = new N(), this.vms.set(r2, o2));
|
|
1644
1793
|
const n2 = {
|
|
1645
1794
|
pc: 0,
|
|
1646
1795
|
stack: [],
|
|
1647
1796
|
variables: /* @__PURE__ */ new Map(),
|
|
1648
1797
|
output: []
|
|
1649
|
-
}, a2 =
|
|
1798
|
+
}, a2 = o2.execute(s2.bytecode, n2);
|
|
1650
1799
|
if (a2.output.length > 0 && await this.storage.appendOutput(r2, a2.output), t2.pc = a2.pc, t2.stack = a2.stack, t2.variables = Object.fromEntries(a2.variables), t2.iterators = a2.iterators, a2.status === "complete")
|
|
1651
1800
|
return t2.state = "COMPLETED", a2.returnValue !== void 0 && (t2.returnValue = a2.returnValue), await this.storage.saveExecution(t2), this.vms.delete(r2), {
|
|
1652
1801
|
type: "completed",
|
|
@@ -1660,17 +1809,17 @@ class X {
|
|
|
1660
1809
|
};
|
|
1661
1810
|
if (a2.status === "waiting_fs") {
|
|
1662
1811
|
if (a2.fsOperation) {
|
|
1663
|
-
const i2 = this.fileSystem.listFiles(a2.fsOperation.path, a2.fsOperation.options),
|
|
1664
|
-
return
|
|
1812
|
+
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(r2, 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(r2), {
|
|
1665
1814
|
type: "completed",
|
|
1666
1815
|
message: "Execution completed",
|
|
1667
|
-
result:
|
|
1668
|
-
}) :
|
|
1816
|
+
result: u2.returnValue
|
|
1817
|
+
}) : u2.status === "error" ? (t2.state = "ERROR", t2.error = u2.error, await this.storage.saveExecution(t2), this.vms.delete(r2), {
|
|
1669
1818
|
type: "error",
|
|
1670
|
-
error:
|
|
1671
|
-
}) :
|
|
1819
|
+
error: u2.error
|
|
1820
|
+
}) : u2.status === "waiting_cc" ? (t2.state = "AWAITING_COGNITIVE_RESULT", t2.ccPrompt = u2.ccPrompt, await this.storage.saveExecution(t2), {
|
|
1672
1821
|
type: "waiting",
|
|
1673
|
-
message:
|
|
1822
|
+
message: u2.ccPrompt || "Waiting for input"
|
|
1674
1823
|
}) : (t2.state = "RUNNING", await this.storage.saveExecution(t2), this.getNext(r2));
|
|
1675
1824
|
}
|
|
1676
1825
|
} else if (a2.status === "error")
|
|
@@ -1703,8 +1852,8 @@ class X {
|
|
|
1703
1852
|
const s2 = await this.storage.getExecution(r2);
|
|
1704
1853
|
if (!s2)
|
|
1705
1854
|
throw new Error(`Execution not found: ${r2}`);
|
|
1706
|
-
const
|
|
1707
|
-
if (!
|
|
1855
|
+
const o2 = await this.storage.getProgram(s2.programId);
|
|
1856
|
+
if (!o2)
|
|
1708
1857
|
throw new Error(`Program not found: ${s2.programId}`);
|
|
1709
1858
|
let n2 = this.vms.get(r2);
|
|
1710
1859
|
n2 || (n2 = new N(), this.vms.set(r2, n2));
|
|
@@ -1717,7 +1866,7 @@ class X {
|
|
|
1717
1866
|
// Start with empty output for resumed execution
|
|
1718
1867
|
ccPrompt: void 0,
|
|
1719
1868
|
iterators: s2.iterators || []
|
|
1720
|
-
}, i2 = n2.resume(a2, t2,
|
|
1869
|
+
}, i2 = n2.resume(a2, t2, o2.bytecode);
|
|
1721
1870
|
i2.output.length > 0 && await this.storage.appendOutput(r2, 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(r2)) : i2.status === "error" ? (s2.state = "ERROR", s2.error = i2.error, this.vms.delete(r2)) : i2.status === "waiting_cc" ? (s2.state = "AWAITING_COGNITIVE_RESULT", s2.ccPrompt = i2.ccPrompt) : s2.state = "RUNNING", await this.storage.saveExecution(s2);
|
|
1722
1871
|
}
|
|
1723
1872
|
/**
|
|
@@ -1751,7 +1900,7 @@ class w {
|
|
|
1751
1900
|
s(this, "transport", null);
|
|
1752
1901
|
s(this, "vmManager");
|
|
1753
1902
|
s(this, "version");
|
|
1754
|
-
this.version = r2, this.vmManager = new
|
|
1903
|
+
this.version = r2, this.vmManager = new te(), this.server = new mcp_js.McpServer({
|
|
1755
1904
|
name: "cvm-server",
|
|
1756
1905
|
version: this.version
|
|
1757
1906
|
}), this.setupTools();
|
|
@@ -2005,7 +2154,7 @@ async function main() {
|
|
|
2005
2154
|
];
|
|
2006
2155
|
for (const packageJsonPath of possiblePaths) {
|
|
2007
2156
|
try {
|
|
2008
|
-
const packageJson = JSON.parse(
|
|
2157
|
+
const packageJson = JSON.parse(G$1.readFileSync(packageJsonPath, "utf-8"));
|
|
2009
2158
|
if (packageJson.name === "cvm-server" && packageJson.version) {
|
|
2010
2159
|
version = packageJson.version;
|
|
2011
2160
|
break;
|