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