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