cvm-server 0.15.0 → 0.15.1
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 +581 -578
- package/package.json +1 -1
package/main.cjs
CHANGED
|
@@ -11,31 +11,31 @@ const dotenv = require("dotenv");
|
|
|
11
11
|
const url = require("url");
|
|
12
12
|
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
|
|
13
13
|
function _interopNamespaceDefault(e2) {
|
|
14
|
-
const
|
|
14
|
+
const n2 = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
15
15
|
if (e2) {
|
|
16
16
|
for (const k2 in e2) {
|
|
17
17
|
if (k2 !== "default") {
|
|
18
18
|
const d2 = Object.getOwnPropertyDescriptor(e2, k2);
|
|
19
|
-
Object.defineProperty(
|
|
19
|
+
Object.defineProperty(n2, k2, d2.get ? d2 : {
|
|
20
20
|
enumerable: true,
|
|
21
21
|
get: () => e2[k2]
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
-
|
|
27
|
-
return Object.freeze(
|
|
26
|
+
n2.default = e2;
|
|
27
|
+
return Object.freeze(n2);
|
|
28
28
|
}
|
|
29
29
|
const s__namespace = /* @__PURE__ */ _interopNamespaceDefault(s$1);
|
|
30
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 I = (e2, t2,
|
|
35
|
-
var _$1 = (e2, t2,
|
|
36
|
-
var
|
|
33
|
+
var f$3 = Object.defineProperty;
|
|
34
|
+
var I = (e2, t2, i2) => t2 in e2 ? f$3(e2, t2, { enumerable: true, configurable: true, writable: true, value: i2 }) : e2[t2] = i2;
|
|
35
|
+
var _$1 = (e2, t2, i2) => I(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.ARRAY_SLICE = "ARRAY_SLICE", e2.ARRAY_JOIN = "ARRAY_JOIN", e2.ARRAY_INDEX_OF = "ARRAY_INDEX_OF", e2.STRING_LEN = "STRING_LEN", e2.STRING_SUBSTRING = "STRING_SUBSTRING", e2.STRING_INDEXOF = "STRING_INDEXOF", e2.STRING_SPLIT = "STRING_SPLIT", e2.STRING_SLICE = "STRING_SLICE", e2.STRING_CHARAT = "STRING_CHARAT", e2.STRING_TOUPPERCASE = "STRING_TOUPPERCASE", e2.STRING_TOLOWERCASE = "STRING_TOLOWERCASE", e2.STRING_INCLUDES = "STRING_INCLUDES", e2.STRING_ENDS_WITH = "STRING_ENDS_WITH", e2.STRING_STARTS_WITH = "STRING_STARTS_WITH", e2.STRING_TRIM = "STRING_TRIM", e2.STRING_TRIM_START = "STRING_TRIM_START", e2.STRING_TRIM_END = "STRING_TRIM_END", e2.STRING_REPLACE = "STRING_REPLACE", e2.STRING_REPLACE_ALL = "STRING_REPLACE_ALL", e2.STRING_LAST_INDEX_OF = "STRING_LAST_INDEX_OF", e2.STRING_REPEAT = "STRING_REPEAT", e2.STRING_PAD_START = "STRING_PAD_START", e2.STRING_PAD_END = "STRING_PAD_END", e2.LOAD_REGEX = "LOAD_REGEX", e2.REGEX_TEST = "REGEX_TEST", e2.STRING_MATCH = "STRING_MATCH", e2.STRING_REPLACE_REGEX = "STRING_REPLACE_REGEX", e2.LENGTH = "LENGTH", e2.TO_STRING = "TO_STRING", e2.JSON_PARSE = "JSON_PARSE", e2.TYPEOF = "TYPEOF", e2.ADD = "ADD", e2.SUB = "SUB", e2.MUL = "MUL", e2.DIV = "DIV", e2.MOD = "MOD", e2.UNARY_MINUS = "UNARY_MINUS", e2.UNARY_PLUS = "UNARY_PLUS", e2.INC = "INC", e2.DEC = "DEC", e2.EQ = "EQ", e2.NEQ = "NEQ", e2.LT = "LT", e2.GT = "GT", e2.LTE = "LTE", e2.GTE = "GTE", e2.EQ_STRICT = "EQ_STRICT", e2.NEQ_STRICT = "NEQ_STRICT", e2.JUMP = "JUMP", e2.JUMP_IF = "JUMP_IF", e2.JUMP_IF_FALSE = "JUMP_IF_FALSE", e2.JUMP_IF_TRUE = "JUMP_IF_TRUE", e2.CALL = "CALL", e2.RETURN = "RETURN", e2.AND = "AND", e2.OR = "OR", e2.NOT = "NOT", e2.BREAK = "BREAK", e2.CONTINUE = "CONTINUE", e2.ITER_START = "ITER_START", e2.ITER_NEXT = "ITER_NEXT", e2.ITER_END = "ITER_END", e2.OBJECT_ITER_START = "OBJECT_ITER_START", e2.OBJECT_ITER_NEXT = "OBJECT_ITER_NEXT", e2.FS_LIST_FILES = "FS_LIST_FILES", e2.FS_READ_FILE = "FS_READ_FILE", e2.FS_WRITE_FILE = "FS_WRITE_FILE", e2.OBJECT_CREATE = "OBJECT_CREATE", e2.PROPERTY_GET = "PROPERTY_GET", e2.PROPERTY_SET = "PROPERTY_SET", e2.OBJECT_KEYS = "OBJECT_KEYS", e2.JSON_STRINGIFY = "JSON_STRINGIFY", e2.GET = "GET", e2.SET = "SET", e2.CC = "CC", e2.PRINT = "PRINT", e2.HALT = "HALT", e2))(n || {});
|
|
37
37
|
function A$1(e2) {
|
|
38
|
-
const t2 = [],
|
|
38
|
+
const t2 = [], i2 = [];
|
|
39
39
|
let r2 = false;
|
|
40
40
|
const a2 = s__namespace.createSourceFile(
|
|
41
41
|
"program.ts",
|
|
@@ -43,15 +43,15 @@ function A$1(e2) {
|
|
|
43
43
|
s__namespace.ScriptTarget.Latest,
|
|
44
44
|
true
|
|
45
45
|
);
|
|
46
|
-
function
|
|
47
|
-
if (s__namespace.isFunctionDeclaration(
|
|
48
|
-
const
|
|
49
|
-
["setTimeout", "fetch", "require", "import"].includes(
|
|
46
|
+
function T(S) {
|
|
47
|
+
if (s__namespace.isFunctionDeclaration(S) && S.name && S.name.text === "main" && (r2 = true, S.parameters.length > 0 && t2.push("main() must not have parameters")), s__namespace.isCallExpression(S) && s__namespace.isIdentifier(S.expression)) {
|
|
48
|
+
const c2 = S.expression.text;
|
|
49
|
+
["setTimeout", "fetch", "require", "import"].includes(c2) && t2.push(`Unsupported function: ${c2}`);
|
|
50
50
|
}
|
|
51
|
-
s__namespace.forEachChild(
|
|
51
|
+
s__namespace.forEachChild(S, T);
|
|
52
52
|
}
|
|
53
|
-
return
|
|
54
|
-
bytecode:
|
|
53
|
+
return T(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
|
};
|
|
@@ -65,9 +65,9 @@ class g {
|
|
|
65
65
|
/**
|
|
66
66
|
* Emit an instruction and return its index
|
|
67
67
|
*/
|
|
68
|
-
emit(t2,
|
|
68
|
+
emit(t2, i2) {
|
|
69
69
|
const r2 = this.bytecode.length;
|
|
70
|
-
return this.bytecode.push({ op: t2, arg:
|
|
70
|
+
return this.bytecode.push({ op: t2, arg: i2 }), r2;
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Get the current address (next instruction index)
|
|
@@ -78,14 +78,14 @@ class g {
|
|
|
78
78
|
/**
|
|
79
79
|
* Patch a jump instruction with the target address
|
|
80
80
|
*/
|
|
81
|
-
patchJump(t2,
|
|
82
|
-
t2 >= 0 && t2 < this.bytecode.length && (this.bytecode[t2].arg =
|
|
81
|
+
patchJump(t2, i2) {
|
|
82
|
+
t2 >= 0 && t2 < this.bytecode.length && (this.bytecode[t2].arg = i2);
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
85
85
|
* Patch multiple jump instructions with the same target
|
|
86
86
|
*/
|
|
87
|
-
patchJumps(t2,
|
|
88
|
-
t2.forEach((r2) => this.patchJump(r2,
|
|
87
|
+
patchJumps(t2, i2) {
|
|
88
|
+
t2.forEach((r2) => this.patchJump(r2, i2));
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
91
|
* Push a new jump context onto the stack
|
|
@@ -110,9 +110,9 @@ class g {
|
|
|
110
110
|
*/
|
|
111
111
|
findLoopContext() {
|
|
112
112
|
for (let t2 = this.contextStack.length - 1; t2 >= 0; t2--) {
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
return
|
|
113
|
+
const i2 = this.contextStack[t2];
|
|
114
|
+
if (i2.type === "loop" || i2.type === "foreach")
|
|
115
|
+
return i2;
|
|
116
116
|
}
|
|
117
117
|
return null;
|
|
118
118
|
}
|
|
@@ -141,224 +141,226 @@ class g {
|
|
|
141
141
|
return `__temp${this.tempVarCounter++}`;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
const P = (e2, t2, { compileExpression:
|
|
145
|
-
|
|
146
|
-
const a2 = t2.emit(
|
|
144
|
+
const P = (e2, t2, { compileExpression: i2, compileStatement: r2 }) => {
|
|
145
|
+
i2(e2.expression);
|
|
146
|
+
const a2 = t2.emit(n.JUMP_IF_FALSE, -1), T = {
|
|
147
147
|
type: "if",
|
|
148
148
|
endTargets: []
|
|
149
149
|
};
|
|
150
|
-
if (e2.elseStatement ?
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
t2.patchJump(a2,
|
|
155
|
-
}
|
|
156
|
-
const
|
|
157
|
-
if (
|
|
158
|
-
const
|
|
159
|
-
t2.patchJumps(
|
|
160
|
-
}
|
|
161
|
-
}, N = (e2, t2, { compileExpression:
|
|
150
|
+
if (e2.elseStatement ? T.elseTarget = a2 : T.endTargets.push(a2), t2.pushContext(T), r2(e2.thenStatement), e2.elseStatement) {
|
|
151
|
+
const c2 = t2.emit(n.JUMP, -1);
|
|
152
|
+
T.endTargets.push(c2);
|
|
153
|
+
const m2 = t2.currentAddress();
|
|
154
|
+
t2.patchJump(a2, m2), r2(e2.elseStatement);
|
|
155
|
+
}
|
|
156
|
+
const S = t2.popContext();
|
|
157
|
+
if (S) {
|
|
158
|
+
const c2 = t2.currentAddress();
|
|
159
|
+
t2.patchJumps(S.endTargets, c2);
|
|
160
|
+
}
|
|
161
|
+
}, N = (e2, t2, { compileExpression: i2, compileStatement: r2 }) => {
|
|
162
162
|
const a2 = t2.currentAddress();
|
|
163
|
-
|
|
164
|
-
const
|
|
163
|
+
i2(e2.expression);
|
|
164
|
+
const S = {
|
|
165
165
|
type: "loop",
|
|
166
|
-
breakTargets: [t2.emit(
|
|
166
|
+
breakTargets: [t2.emit(n.JUMP_IF_FALSE, -1)],
|
|
167
167
|
continueTargets: [],
|
|
168
168
|
endTargets: [],
|
|
169
169
|
startAddress: a2
|
|
170
170
|
};
|
|
171
|
-
t2.pushContext(
|
|
172
|
-
const
|
|
173
|
-
if (
|
|
174
|
-
const
|
|
175
|
-
t2.patchJumps(
|
|
171
|
+
t2.pushContext(S), r2(e2.statement), t2.emit(n.JUMP, a2);
|
|
172
|
+
const c2 = t2.popContext();
|
|
173
|
+
if (c2) {
|
|
174
|
+
const m2 = t2.currentAddress();
|
|
175
|
+
t2.patchJumps(c2.breakTargets || [], m2), t2.patchJumps(c2.continueTargets || [], a2);
|
|
176
176
|
}
|
|
177
|
-
}, h$1 = (e2, t2, { compileExpression:
|
|
178
|
-
const a2 = e2.initializer,
|
|
179
|
-
let
|
|
177
|
+
}, h$1 = (e2, t2, { compileExpression: i2, compileStatement: r2 }) => {
|
|
178
|
+
const a2 = e2.initializer, T = e2.expression;
|
|
179
|
+
let S;
|
|
180
180
|
if (s__namespace.isVariableDeclarationList(a2))
|
|
181
|
-
|
|
181
|
+
S = a2.declarations[0].name.getText();
|
|
182
182
|
else if (s__namespace.isIdentifier(a2))
|
|
183
|
-
|
|
183
|
+
S = a2.text;
|
|
184
184
|
else
|
|
185
185
|
throw new Error("Unsupported for-of variable declaration");
|
|
186
|
-
|
|
187
|
-
const
|
|
188
|
-
t2.emit(
|
|
189
|
-
const
|
|
190
|
-
t2.emit(
|
|
186
|
+
i2(T), t2.emit(n.ITER_START);
|
|
187
|
+
const c2 = t2.currentAddress();
|
|
188
|
+
t2.emit(n.ITER_NEXT);
|
|
189
|
+
const m2 = t2.emit(n.JUMP_IF_FALSE, -1);
|
|
190
|
+
t2.emit(n.STORE, S);
|
|
191
191
|
const u2 = {
|
|
192
192
|
type: "foreach",
|
|
193
|
-
breakTargets: [
|
|
193
|
+
breakTargets: [m2],
|
|
194
194
|
continueTargets: [],
|
|
195
195
|
endTargets: [],
|
|
196
|
-
startAddress:
|
|
197
|
-
iterVariable:
|
|
196
|
+
startAddress: c2,
|
|
197
|
+
iterVariable: S
|
|
198
198
|
};
|
|
199
|
-
t2.pushContext(u2), r2(e2.statement), t2.emit(
|
|
200
|
-
const
|
|
201
|
-
if (
|
|
199
|
+
t2.pushContext(u2), r2(e2.statement), t2.emit(n.JUMP, c2);
|
|
200
|
+
const l = t2.popContext();
|
|
201
|
+
if (l) {
|
|
202
202
|
const R = t2.currentAddress();
|
|
203
|
-
t2.patchJumps(
|
|
203
|
+
t2.patchJumps(l.breakTargets || [], R), t2.patchJumps(l.continueTargets || [], c2), t2.emit(n.ITER_END);
|
|
204
204
|
}
|
|
205
|
-
}, p$2 = (e2, t2, { compileExpression:
|
|
206
|
-
const a2 = e2.initializer,
|
|
207
|
-
let
|
|
205
|
+
}, p$2 = (e2, t2, { compileExpression: i2, compileStatement: r2 }) => {
|
|
206
|
+
const a2 = e2.initializer, T = e2.expression;
|
|
207
|
+
let S;
|
|
208
208
|
if (s__namespace.isVariableDeclarationList(a2))
|
|
209
|
-
|
|
209
|
+
S = a2.declarations[0].name.getText();
|
|
210
210
|
else if (s__namespace.isIdentifier(a2))
|
|
211
|
-
|
|
211
|
+
S = a2.text;
|
|
212
212
|
else
|
|
213
213
|
throw new Error("Unsupported for-in variable declaration");
|
|
214
|
-
|
|
215
|
-
const
|
|
216
|
-
t2.emit(
|
|
217
|
-
const
|
|
218
|
-
t2.emit(
|
|
214
|
+
i2(T), t2.emit(n.OBJECT_ITER_START);
|
|
215
|
+
const c2 = t2.currentAddress();
|
|
216
|
+
t2.emit(n.OBJECT_ITER_NEXT);
|
|
217
|
+
const m2 = t2.emit(n.JUMP_IF_FALSE, -1);
|
|
218
|
+
t2.emit(n.STORE, S);
|
|
219
219
|
const u2 = {
|
|
220
220
|
type: "foreach",
|
|
221
|
-
breakTargets: [
|
|
221
|
+
breakTargets: [m2],
|
|
222
222
|
continueTargets: [],
|
|
223
223
|
endTargets: [],
|
|
224
|
-
startAddress:
|
|
225
|
-
iterVariable:
|
|
224
|
+
startAddress: c2,
|
|
225
|
+
iterVariable: S
|
|
226
226
|
};
|
|
227
|
-
t2.pushContext(u2), r2(e2.statement), t2.emit(
|
|
228
|
-
const
|
|
229
|
-
if (
|
|
227
|
+
t2.pushContext(u2), r2(e2.statement), t2.emit(n.JUMP, c2);
|
|
228
|
+
const l = t2.popContext();
|
|
229
|
+
if (l) {
|
|
230
230
|
const R = t2.currentAddress();
|
|
231
|
-
t2.patchJumps(
|
|
231
|
+
t2.patchJumps(l.breakTargets || [], R), t2.patchJumps(l.continueTargets || [], c2), t2.emit(n.ITER_END);
|
|
232
232
|
}
|
|
233
|
-
}, U = (e2, t2, { compileExpression:
|
|
233
|
+
}, U = (e2, t2, { compileExpression: i2, compileStatement: r2 }) => {
|
|
234
234
|
if (e2.initializer)
|
|
235
235
|
if (s__namespace.isVariableDeclarationList(e2.initializer))
|
|
236
|
-
for (const
|
|
237
|
-
|
|
236
|
+
for (const u2 of e2.initializer.declarations)
|
|
237
|
+
u2.initializer && (i2(u2.initializer), t2.emit(n.STORE, u2.name.getText()));
|
|
238
238
|
else
|
|
239
|
-
|
|
239
|
+
i2(e2.initializer), t2.emit(n.POP);
|
|
240
240
|
const a2 = t2.currentAddress();
|
|
241
|
-
let
|
|
242
|
-
e2.condition && (
|
|
243
|
-
const
|
|
241
|
+
let T;
|
|
242
|
+
e2.condition && (i2(e2.condition), T = t2.emit(n.JUMP_IF_FALSE, -1));
|
|
243
|
+
const S = {
|
|
244
244
|
type: "loop",
|
|
245
|
-
breakTargets:
|
|
245
|
+
breakTargets: T ? [T] : [],
|
|
246
246
|
continueTargets: [],
|
|
247
247
|
endTargets: [],
|
|
248
248
|
startAddress: a2
|
|
249
249
|
};
|
|
250
|
-
t2.pushContext(
|
|
251
|
-
const
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
250
|
+
t2.pushContext(S), r2(e2.statement);
|
|
251
|
+
const c2 = t2.currentAddress();
|
|
252
|
+
e2.incrementor && (i2(e2.incrementor), t2.emit(n.POP)), t2.emit(n.JUMP, a2);
|
|
253
|
+
const m2 = t2.popContext();
|
|
254
|
+
if (m2) {
|
|
255
|
+
const u2 = t2.currentAddress();
|
|
256
|
+
t2.patchJumps(m2.breakTargets || [], u2), t2.patchJumps(m2.continueTargets || [], c2);
|
|
257
|
+
}
|
|
258
|
+
}, y$1 = (e2, t2, { compileExpression: i2, compileStatement: r2 }) => {
|
|
257
259
|
const a2 = t2.generateTempVar();
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
let
|
|
261
|
-
if (e2.caseBlock.clauses.forEach((
|
|
262
|
-
if (s__namespace.isCaseClause(
|
|
263
|
-
t2.emit(
|
|
264
|
-
const E2 = t2.emit(
|
|
265
|
-
|
|
266
|
-
} else s__namespace.isDefaultClause(
|
|
267
|
-
}),
|
|
268
|
-
const
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
let
|
|
272
|
-
e2.caseBlock.clauses.forEach((
|
|
273
|
-
if (s__namespace.isCaseClause(
|
|
260
|
+
i2(e2.expression), t2.emit(n.STORE, a2);
|
|
261
|
+
const T = [], S = [];
|
|
262
|
+
let c2 = null;
|
|
263
|
+
if (e2.caseBlock.clauses.forEach((l, R) => {
|
|
264
|
+
if (s__namespace.isCaseClause(l)) {
|
|
265
|
+
t2.emit(n.LOAD, a2), i2(l.expression), t2.emit(n.EQ_STRICT);
|
|
266
|
+
const E2 = t2.emit(n.JUMP_IF_TRUE, -1);
|
|
267
|
+
S.push(E2);
|
|
268
|
+
} else s__namespace.isDefaultClause(l) && (c2 = t2.emit(n.JUMP, -1));
|
|
269
|
+
}), c2 === null) {
|
|
270
|
+
const l = t2.emit(n.JUMP, -1);
|
|
271
|
+
T.push(l);
|
|
272
|
+
}
|
|
273
|
+
let m2 = 0;
|
|
274
|
+
e2.caseBlock.clauses.forEach((l, R) => {
|
|
275
|
+
if (s__namespace.isCaseClause(l)) {
|
|
274
276
|
const E2 = t2.currentAddress();
|
|
275
|
-
t2.patchJumps([
|
|
277
|
+
t2.patchJumps([S[m2]], E2), m2++, l.statements.forEach((x2) => {
|
|
276
278
|
if (s__namespace.isBreakStatement(x2)) {
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
+
const o2 = t2.emit(n.JUMP, -1);
|
|
280
|
+
T.push(o2);
|
|
279
281
|
} else
|
|
280
282
|
r2(x2);
|
|
281
283
|
});
|
|
282
|
-
} else if (s__namespace.isDefaultClause(
|
|
284
|
+
} else if (s__namespace.isDefaultClause(l)) {
|
|
283
285
|
const E2 = t2.currentAddress();
|
|
284
|
-
|
|
286
|
+
c2 !== null && t2.patchJumps([c2], E2), l.statements.forEach((x2) => {
|
|
285
287
|
if (s__namespace.isBreakStatement(x2)) {
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
+
const o2 = t2.emit(n.JUMP, -1);
|
|
289
|
+
T.push(o2);
|
|
288
290
|
} else
|
|
289
291
|
r2(x2);
|
|
290
292
|
});
|
|
291
293
|
}
|
|
292
294
|
});
|
|
293
295
|
const u2 = t2.currentAddress();
|
|
294
|
-
t2.patchJumps(
|
|
295
|
-
}, L = (e2, t2, { compileStatement:
|
|
296
|
+
t2.patchJumps(T, u2);
|
|
297
|
+
}, L = (e2, t2, { compileStatement: i2 }) => {
|
|
296
298
|
e2.statements.forEach((r2) => {
|
|
297
|
-
|
|
299
|
+
i2(r2);
|
|
298
300
|
});
|
|
299
|
-
}, k = (e2, t2, { compileExpression:
|
|
301
|
+
}, k = (e2, t2, { compileExpression: i2 }) => {
|
|
300
302
|
const r2 = e2.declarationList.declarations[0];
|
|
301
|
-
r2.initializer && (
|
|
302
|
-
}, G = (e2, t2, { compileExpression:
|
|
303
|
+
r2.initializer && (i2(r2.initializer), t2.emit(n.STORE, r2.name.getText()));
|
|
304
|
+
}, G = (e2, t2, { compileExpression: i2 }) => {
|
|
303
305
|
const r2 = e2.expression;
|
|
304
306
|
if (s__namespace.isBinaryExpression(r2)) {
|
|
305
307
|
const a2 = r2.operatorToken.kind;
|
|
306
308
|
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) {
|
|
307
309
|
if (s__namespace.isIdentifier(r2.left)) {
|
|
308
|
-
switch (t2.emit(
|
|
310
|
+
switch (t2.emit(n.LOAD, r2.left.text), i2(r2.right), a2) {
|
|
309
311
|
case s__namespace.SyntaxKind.PlusEqualsToken:
|
|
310
|
-
t2.emit(
|
|
312
|
+
t2.emit(n.ADD);
|
|
311
313
|
break;
|
|
312
314
|
case s__namespace.SyntaxKind.MinusEqualsToken:
|
|
313
|
-
t2.emit(
|
|
315
|
+
t2.emit(n.SUB);
|
|
314
316
|
break;
|
|
315
317
|
case s__namespace.SyntaxKind.AsteriskEqualsToken:
|
|
316
|
-
t2.emit(
|
|
318
|
+
t2.emit(n.MUL);
|
|
317
319
|
break;
|
|
318
320
|
case s__namespace.SyntaxKind.SlashEqualsToken:
|
|
319
|
-
t2.emit(
|
|
321
|
+
t2.emit(n.DIV);
|
|
320
322
|
break;
|
|
321
323
|
case s__namespace.SyntaxKind.PercentEqualsToken:
|
|
322
|
-
t2.emit(
|
|
324
|
+
t2.emit(n.MOD);
|
|
323
325
|
break;
|
|
324
326
|
}
|
|
325
|
-
t2.emit(
|
|
327
|
+
t2.emit(n.STORE, r2.left.text);
|
|
326
328
|
} else if (s__namespace.isElementAccessExpression(r2.left))
|
|
327
329
|
throw new Error("Compound assignment to array elements not yet supported");
|
|
328
330
|
return;
|
|
329
331
|
} else if (a2 === s__namespace.SyntaxKind.EqualsToken) {
|
|
330
|
-
if (
|
|
331
|
-
t2.emit(
|
|
332
|
+
if (i2(r2.right), s__namespace.isIdentifier(r2.left))
|
|
333
|
+
t2.emit(n.STORE, r2.left.text);
|
|
332
334
|
else if (s__namespace.isElementAccessExpression(r2.left)) {
|
|
333
|
-
const
|
|
334
|
-
t2.emit(
|
|
335
|
+
const T = `__temp_${t2.getBytecode().length}`;
|
|
336
|
+
t2.emit(n.STORE, T), i2(r2.left.expression), i2(r2.left.argumentExpression), t2.emit(n.LOAD, T), t2.emit(n.ARRAY_SET), t2.emit(n.POP);
|
|
335
337
|
} else if (s__namespace.isPropertyAccessExpression(r2.left)) {
|
|
336
|
-
const
|
|
337
|
-
t2.emit(
|
|
338
|
+
const T = `__temp_${t2.getBytecode().length}`;
|
|
339
|
+
t2.emit(n.STORE, T), i2(r2.left.expression), t2.emit(n.PUSH, r2.left.name.text), t2.emit(n.LOAD, T), t2.emit(n.PROPERTY_SET), t2.emit(n.POP);
|
|
338
340
|
}
|
|
339
341
|
return;
|
|
340
342
|
}
|
|
341
343
|
}
|
|
342
344
|
s__namespace.isCallExpression(r2) && s__namespace.isPropertyAccessExpression(r2.expression) && r2.expression.expression.getText() === "console" && r2.expression.name.getText() === "log" ? (r2.arguments.forEach((a2) => {
|
|
343
|
-
|
|
344
|
-
}), t2.emit(
|
|
345
|
-
}, D = (e2, t2, { compileExpression:
|
|
346
|
-
e2.expression ?
|
|
347
|
-
}, F$1 = (e2, t2,
|
|
345
|
+
i2(a2);
|
|
346
|
+
}), 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));
|
|
347
|
+
}, D = (e2, t2, { compileExpression: i2 }) => {
|
|
348
|
+
e2.expression ? i2(e2.expression) : t2.emit(n.PUSH, null), t2.emit(n.RETURN);
|
|
349
|
+
}, F$1 = (e2, t2, i2) => {
|
|
348
350
|
const r2 = t2.findLoopContext();
|
|
349
351
|
if (r2) {
|
|
350
|
-
r2.type === "foreach" && t2.emit(
|
|
351
|
-
const a2 = t2.emit(
|
|
352
|
+
r2.type === "foreach" && t2.emit(n.ITER_END);
|
|
353
|
+
const a2 = t2.emit(n.BREAK, -1);
|
|
352
354
|
r2.breakTargets = r2.breakTargets || [], r2.breakTargets.push(a2);
|
|
353
355
|
} else
|
|
354
|
-
|
|
355
|
-
}, b$1 = (e2, t2,
|
|
356
|
+
i2.reportError(e2, "break statement not in loop");
|
|
357
|
+
}, b$1 = (e2, t2, i2) => {
|
|
356
358
|
const r2 = t2.findLoopContext();
|
|
357
359
|
if (r2 && r2.startAddress !== void 0) {
|
|
358
|
-
const a2 = t2.emit(
|
|
360
|
+
const a2 = t2.emit(n.CONTINUE, -1);
|
|
359
361
|
r2.continueTargets = r2.continueTargets || [], r2.continueTargets.push(a2);
|
|
360
362
|
} else
|
|
361
|
-
|
|
363
|
+
i2.reportError(e2, "continue statement not in loop");
|
|
362
364
|
}, K = {
|
|
363
365
|
[s__namespace.SyntaxKind.IfStatement]: P,
|
|
364
366
|
[s__namespace.SyntaxKind.WhileStatement]: N,
|
|
@@ -372,206 +374,206 @@ const P = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
|
372
374
|
[s__namespace.SyntaxKind.ReturnStatement]: D,
|
|
373
375
|
[s__namespace.SyntaxKind.BreakStatement]: F$1,
|
|
374
376
|
[s__namespace.SyntaxKind.ContinueStatement]: b$1
|
|
375
|
-
},
|
|
376
|
-
t2.emit(
|
|
377
|
-
},
|
|
378
|
-
t2.emit(
|
|
379
|
-
}, M$2 = (e2, t2,
|
|
380
|
-
t2.emit(
|
|
381
|
-
}, Y = (e2, t2,
|
|
382
|
-
t2.emit(
|
|
383
|
-
},
|
|
384
|
-
t2.emit(
|
|
385
|
-
},
|
|
386
|
-
const r2 = e2.text, a2 = r2.lastIndexOf("/"),
|
|
387
|
-
t2.emit(
|
|
388
|
-
}, w$1 = (e2, t2,
|
|
389
|
-
e2.text === "undefined" ? t2.emit(
|
|
390
|
-
}, q = (e2, t2, { compileExpression:
|
|
391
|
-
t2.emit(
|
|
392
|
-
|
|
377
|
+
}, J = (e2, t2, i2) => {
|
|
378
|
+
t2.emit(n.PUSH, e2.text);
|
|
379
|
+
}, H = (e2, t2, i2) => {
|
|
380
|
+
t2.emit(n.PUSH, Number(e2.text));
|
|
381
|
+
}, M$2 = (e2, t2, i2) => {
|
|
382
|
+
t2.emit(n.PUSH, true);
|
|
383
|
+
}, Y = (e2, t2, i2) => {
|
|
384
|
+
t2.emit(n.PUSH, false);
|
|
385
|
+
}, B$1 = (e2, t2, i2) => {
|
|
386
|
+
t2.emit(n.PUSH, null);
|
|
387
|
+
}, C$2 = (e2, t2, i2) => {
|
|
388
|
+
const r2 = e2.text, a2 = r2.lastIndexOf("/"), T = r2.substring(1, a2), S = r2.substring(a2 + 1);
|
|
389
|
+
t2.emit(n.LOAD_REGEX, { pattern: T, flags: S });
|
|
390
|
+
}, w$1 = (e2, t2, i2) => {
|
|
391
|
+
e2.text === "undefined" ? t2.emit(n.PUSH_UNDEFINED) : t2.emit(n.LOAD, e2.text);
|
|
392
|
+
}, q = (e2, t2, { compileExpression: i2 }) => {
|
|
393
|
+
t2.emit(n.ARRAY_NEW), e2.elements.forEach((r2) => {
|
|
394
|
+
i2(r2), t2.emit(n.ARRAY_PUSH);
|
|
393
395
|
});
|
|
394
|
-
}, O = (e2, t2, { compileExpression:
|
|
395
|
-
|
|
396
|
-
},
|
|
397
|
-
e2.name.text === "length" ? (
|
|
398
|
-
},
|
|
399
|
-
|
|
400
|
-
},
|
|
396
|
+
}, O = (e2, t2, { compileExpression: i2 }) => {
|
|
397
|
+
i2(e2.expression);
|
|
398
|
+
}, d$3 = (e2, t2, { compileExpression: i2 }) => {
|
|
399
|
+
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));
|
|
400
|
+
}, X = (e2, t2, { compileExpression: i2, reportError: r2 }) => {
|
|
401
|
+
i2(e2.expression), e2.argumentExpression ? i2(e2.argumentExpression) : r2(e2, "Element access requires an index expression"), t2.emit(n.ARRAY_GET);
|
|
402
|
+
}, V$1 = (e2, t2, { compileExpression: i2 }) => {
|
|
401
403
|
switch (e2.operator) {
|
|
402
404
|
case s__namespace.SyntaxKind.ExclamationToken:
|
|
403
|
-
|
|
405
|
+
i2(e2.operand), t2.emit(n.NOT);
|
|
404
406
|
break;
|
|
405
407
|
case s__namespace.SyntaxKind.MinusToken:
|
|
406
|
-
|
|
408
|
+
i2(e2.operand), t2.emit(n.UNARY_MINUS);
|
|
407
409
|
break;
|
|
408
410
|
case s__namespace.SyntaxKind.PlusToken:
|
|
409
|
-
|
|
411
|
+
i2(e2.operand), t2.emit(n.UNARY_PLUS);
|
|
410
412
|
break;
|
|
411
413
|
case s__namespace.SyntaxKind.PlusPlusToken:
|
|
412
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
414
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(n.PUSH, e2.operand.text), t2.emit(n.INC, false));
|
|
413
415
|
break;
|
|
414
416
|
case s__namespace.SyntaxKind.MinusMinusToken:
|
|
415
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
417
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(n.PUSH, e2.operand.text), t2.emit(n.DEC, false));
|
|
416
418
|
break;
|
|
417
419
|
}
|
|
418
|
-
},
|
|
420
|
+
}, W$1 = (e2, t2, { compileExpression: i2 }) => {
|
|
419
421
|
switch (e2.operator) {
|
|
420
422
|
case s__namespace.SyntaxKind.PlusPlusToken:
|
|
421
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
423
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(n.PUSH, e2.operand.text), t2.emit(n.INC, true));
|
|
422
424
|
break;
|
|
423
425
|
case s__namespace.SyntaxKind.MinusMinusToken:
|
|
424
|
-
s__namespace.isIdentifier(e2.operand) && (t2.emit(
|
|
426
|
+
s__namespace.isIdentifier(e2.operand) && (t2.emit(n.PUSH, e2.operand.text), t2.emit(n.DEC, true));
|
|
425
427
|
break;
|
|
426
428
|
}
|
|
427
|
-
}, j$1 = (e2, t2, { compileExpression:
|
|
429
|
+
}, j$1 = (e2, t2, { compileExpression: i2 }) => {
|
|
428
430
|
const r2 = e2.operatorToken.kind;
|
|
429
|
-
switch (
|
|
431
|
+
switch (i2(e2.left), i2(e2.right), r2) {
|
|
430
432
|
case s__namespace.SyntaxKind.PlusToken:
|
|
431
|
-
t2.emit(
|
|
433
|
+
t2.emit(n.ADD);
|
|
432
434
|
break;
|
|
433
435
|
case s__namespace.SyntaxKind.MinusToken:
|
|
434
|
-
t2.emit(
|
|
436
|
+
t2.emit(n.SUB);
|
|
435
437
|
break;
|
|
436
438
|
case s__namespace.SyntaxKind.AsteriskToken:
|
|
437
|
-
t2.emit(
|
|
439
|
+
t2.emit(n.MUL);
|
|
438
440
|
break;
|
|
439
441
|
case s__namespace.SyntaxKind.SlashToken:
|
|
440
|
-
t2.emit(
|
|
442
|
+
t2.emit(n.DIV);
|
|
441
443
|
break;
|
|
442
444
|
case s__namespace.SyntaxKind.PercentToken:
|
|
443
|
-
t2.emit(
|
|
445
|
+
t2.emit(n.MOD);
|
|
444
446
|
break;
|
|
445
447
|
case s__namespace.SyntaxKind.EqualsEqualsToken:
|
|
446
|
-
t2.emit(
|
|
448
|
+
t2.emit(n.EQ);
|
|
447
449
|
break;
|
|
448
450
|
case s__namespace.SyntaxKind.ExclamationEqualsToken:
|
|
449
|
-
t2.emit(
|
|
451
|
+
t2.emit(n.NEQ);
|
|
450
452
|
break;
|
|
451
453
|
case s__namespace.SyntaxKind.LessThanToken:
|
|
452
|
-
t2.emit(
|
|
454
|
+
t2.emit(n.LT);
|
|
453
455
|
break;
|
|
454
456
|
case s__namespace.SyntaxKind.GreaterThanToken:
|
|
455
|
-
t2.emit(
|
|
457
|
+
t2.emit(n.GT);
|
|
456
458
|
break;
|
|
457
459
|
case s__namespace.SyntaxKind.LessThanEqualsToken:
|
|
458
|
-
t2.emit(
|
|
460
|
+
t2.emit(n.LTE);
|
|
459
461
|
break;
|
|
460
462
|
case s__namespace.SyntaxKind.GreaterThanEqualsToken:
|
|
461
|
-
t2.emit(
|
|
463
|
+
t2.emit(n.GTE);
|
|
462
464
|
break;
|
|
463
465
|
case s__namespace.SyntaxKind.EqualsEqualsEqualsToken:
|
|
464
|
-
t2.emit(
|
|
466
|
+
t2.emit(n.EQ_STRICT);
|
|
465
467
|
break;
|
|
466
468
|
case s__namespace.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
467
|
-
t2.emit(
|
|
469
|
+
t2.emit(n.NEQ_STRICT);
|
|
468
470
|
break;
|
|
469
471
|
case s__namespace.SyntaxKind.AmpersandAmpersandToken:
|
|
470
|
-
t2.emit(
|
|
472
|
+
t2.emit(n.AND);
|
|
471
473
|
break;
|
|
472
474
|
case s__namespace.SyntaxKind.BarBarToken:
|
|
473
|
-
t2.emit(
|
|
475
|
+
t2.emit(n.OR);
|
|
474
476
|
break;
|
|
475
477
|
}
|
|
476
|
-
}, v$1 = (e2, t2, { compileExpression:
|
|
477
|
-
|
|
478
|
-
const r2 = t2.emit(
|
|
479
|
-
|
|
480
|
-
const a2 = t2.emit(
|
|
481
|
-
t2.patchJump(r2,
|
|
482
|
-
const
|
|
483
|
-
t2.patchJump(a2,
|
|
484
|
-
}, z = (e2, t2, { compileExpression:
|
|
485
|
-
|
|
486
|
-
}, Q$1 = (e2, t2, { compileExpression:
|
|
478
|
+
}, v$1 = (e2, t2, { compileExpression: i2 }) => {
|
|
479
|
+
i2(e2.condition);
|
|
480
|
+
const r2 = t2.emit(n.JUMP_IF_FALSE, -1);
|
|
481
|
+
i2(e2.whenTrue);
|
|
482
|
+
const a2 = t2.emit(n.JUMP, -1), T = t2.currentAddress();
|
|
483
|
+
t2.patchJump(r2, T), i2(e2.whenFalse);
|
|
484
|
+
const S = t2.currentAddress();
|
|
485
|
+
t2.patchJump(a2, S);
|
|
486
|
+
}, z = (e2, t2, { compileExpression: i2 }) => {
|
|
487
|
+
i2(e2.expression), t2.emit(n.TYPEOF);
|
|
488
|
+
}, Q$1 = (e2, t2, { compileExpression: i2, reportError: r2 }) => {
|
|
487
489
|
if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "fs") {
|
|
488
490
|
const a2 = e2.expression.name.text;
|
|
489
491
|
if (a2 === "listFiles")
|
|
490
|
-
e2.arguments.length > 0 ?
|
|
492
|
+
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);
|
|
491
493
|
else if (a2 === "readFile")
|
|
492
|
-
e2.arguments.length > 0 ? (
|
|
494
|
+
e2.arguments.length > 0 ? (i2(e2.arguments[0]), t2.emit(n.FS_READ_FILE)) : r2(e2, "fs.readFile() requires a path argument");
|
|
493
495
|
else if (a2 === "writeFile") {
|
|
494
496
|
if (e2.arguments.length < 2) {
|
|
495
497
|
r2(e2, "fs.writeFile() requires path and content arguments");
|
|
496
498
|
return;
|
|
497
499
|
}
|
|
498
|
-
|
|
500
|
+
i2(e2.arguments[0]), i2(e2.arguments[1]), t2.emit(n.FS_WRITE_FILE);
|
|
499
501
|
} else
|
|
500
502
|
r2(e2, `Unsupported fs method: ${a2}`);
|
|
501
503
|
} else if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "parse")
|
|
502
|
-
e2.arguments.length > 0 &&
|
|
504
|
+
e2.arguments.length > 0 && i2(e2.arguments[0]), t2.emit(n.JSON_PARSE);
|
|
503
505
|
else if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "JSON" && e2.expression.name.text === "stringify")
|
|
504
|
-
e2.arguments.length > 0 ?
|
|
506
|
+
e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH_UNDEFINED), t2.emit(n.JSON_STRINGIFY);
|
|
505
507
|
else if (s__namespace.isPropertyAccessExpression(e2.expression) && s__namespace.isIdentifier(e2.expression.expression) && e2.expression.expression.text === "Object" && e2.expression.name.text === "keys") {
|
|
506
508
|
if (e2.arguments.length !== 1) {
|
|
507
509
|
r2(e2, "Object.keys() requires exactly one argument");
|
|
508
510
|
return;
|
|
509
511
|
}
|
|
510
|
-
|
|
512
|
+
i2(e2.arguments[0]), t2.emit(n.OBJECT_KEYS);
|
|
511
513
|
} else if (s__namespace.isIdentifier(e2.expression) && e2.expression.text === "CC")
|
|
512
|
-
e2.arguments.length > 0 &&
|
|
514
|
+
e2.arguments.length > 0 && i2(e2.arguments[0]), t2.emit(n.CC);
|
|
513
515
|
else if (s__namespace.isPropertyAccessExpression(e2.expression)) {
|
|
514
516
|
const a2 = e2.expression.name.text;
|
|
515
517
|
if (a2 === "substring")
|
|
516
|
-
|
|
518
|
+
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);
|
|
517
519
|
else if (a2 === "indexOf")
|
|
518
|
-
|
|
520
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_INDEXOF);
|
|
519
521
|
else if (a2 === "split")
|
|
520
|
-
|
|
522
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_SPLIT);
|
|
521
523
|
else if (a2 === "slice")
|
|
522
|
-
|
|
524
|
+
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.PUSH_UNDEFINED), t2.emit(n.STRING_SLICE);
|
|
523
525
|
else if (a2 === "join")
|
|
524
|
-
|
|
526
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ","), t2.emit(n.ARRAY_JOIN);
|
|
525
527
|
else if (a2 === "charAt")
|
|
526
|
-
|
|
528
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, 0), t2.emit(n.STRING_CHARAT);
|
|
527
529
|
else if (a2 === "toUpperCase")
|
|
528
|
-
|
|
530
|
+
i2(e2.expression.expression), t2.emit(n.STRING_TOUPPERCASE);
|
|
529
531
|
else if (a2 === "toLowerCase")
|
|
530
|
-
|
|
532
|
+
i2(e2.expression.expression), t2.emit(n.STRING_TOLOWERCASE);
|
|
531
533
|
else if (a2 === "toString")
|
|
532
|
-
|
|
534
|
+
i2(e2.expression.expression), t2.emit(n.TO_STRING);
|
|
533
535
|
else if (a2 === "includes")
|
|
534
|
-
|
|
536
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_INCLUDES);
|
|
535
537
|
else if (a2 === "endsWith")
|
|
536
|
-
|
|
538
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_ENDS_WITH);
|
|
537
539
|
else if (a2 === "startsWith")
|
|
538
|
-
|
|
540
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_STARTS_WITH);
|
|
539
541
|
else if (a2 === "trim")
|
|
540
|
-
|
|
542
|
+
i2(e2.expression.expression), t2.emit(n.STRING_TRIM);
|
|
541
543
|
else if (a2 === "trimStart")
|
|
542
|
-
|
|
544
|
+
i2(e2.expression.expression), t2.emit(n.STRING_TRIM_START);
|
|
543
545
|
else if (a2 === "trimEnd")
|
|
544
|
-
|
|
546
|
+
i2(e2.expression.expression), t2.emit(n.STRING_TRIM_END);
|
|
545
547
|
else if (a2 === "test")
|
|
546
|
-
|
|
548
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), t2.emit(n.REGEX_TEST);
|
|
547
549
|
else if (a2 === "match") {
|
|
548
|
-
if (
|
|
549
|
-
|
|
550
|
+
if (i2(e2.expression.expression), e2.arguments.length > 0)
|
|
551
|
+
i2(e2.arguments[0]);
|
|
550
552
|
else {
|
|
551
553
|
r2(e2, "match() requires a regex argument");
|
|
552
554
|
return;
|
|
553
555
|
}
|
|
554
|
-
t2.emit(
|
|
556
|
+
t2.emit(n.STRING_MATCH);
|
|
555
557
|
} else if (a2 === "replace")
|
|
556
|
-
|
|
558
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), e2.arguments.length > 1 ? i2(e2.arguments[1]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_REPLACE_REGEX);
|
|
557
559
|
else if (a2 === "replaceAll")
|
|
558
|
-
|
|
560
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), e2.arguments.length > 1 ? i2(e2.arguments[1]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_REPLACE_ALL);
|
|
559
561
|
else if (a2 === "lastIndexOf")
|
|
560
|
-
|
|
562
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, ""), t2.emit(n.STRING_LAST_INDEX_OF);
|
|
561
563
|
else if (a2 === "repeat")
|
|
562
|
-
|
|
564
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH, 0), t2.emit(n.STRING_REPEAT);
|
|
563
565
|
else if (a2 === "padStart")
|
|
564
|
-
|
|
566
|
+
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.PUSH, " "), t2.emit(n.STRING_PAD_START);
|
|
565
567
|
else if (a2 === "padEnd")
|
|
566
|
-
|
|
568
|
+
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.PUSH, " "), t2.emit(n.STRING_PAD_END);
|
|
567
569
|
else if (a2 === "push")
|
|
568
|
-
|
|
570
|
+
i2(e2.expression.expression), e2.arguments.length > 0 ? i2(e2.arguments[0]) : t2.emit(n.PUSH_UNDEFINED), t2.emit(n.ARRAY_PUSH);
|
|
569
571
|
else
|
|
570
572
|
throw new Error(`Method call '${a2}' is not supported`);
|
|
571
573
|
} else
|
|
572
574
|
throw new Error("Unsupported call expression");
|
|
573
|
-
}, $$1 = (e2, t2, { compileExpression:
|
|
574
|
-
t2.emit(
|
|
575
|
+
}, $$1 = (e2, t2, { compileExpression: i2 }) => {
|
|
576
|
+
t2.emit(n.OBJECT_CREATE);
|
|
575
577
|
for (const r2 of e2.properties)
|
|
576
578
|
if (s__namespace.isPropertyAssignment(r2)) {
|
|
577
579
|
let a2;
|
|
@@ -581,93 +583,93 @@ const P = (e2, t2, { compileExpression: n, compileStatement: r2 }) => {
|
|
|
581
583
|
a2 = r2.name.text;
|
|
582
584
|
else
|
|
583
585
|
throw new Error("Computed property names are not supported");
|
|
584
|
-
t2.emit(
|
|
586
|
+
t2.emit(n.PUSH, a2), i2(r2.initializer), t2.emit(n.PROPERTY_SET);
|
|
585
587
|
} else if (s__namespace.isShorthandPropertyAssignment(r2)) {
|
|
586
588
|
const a2 = r2.name.text;
|
|
587
|
-
t2.emit(
|
|
589
|
+
t2.emit(n.PUSH, a2), t2.emit(n.LOAD, a2), t2.emit(n.PROPERTY_SET);
|
|
588
590
|
} else
|
|
589
591
|
throw new Error("Unsupported property type in object literal");
|
|
590
592
|
}, Z$1 = {
|
|
591
|
-
[s__namespace.SyntaxKind.StringLiteral]:
|
|
592
|
-
[s__namespace.SyntaxKind.NumericLiteral]:
|
|
593
|
+
[s__namespace.SyntaxKind.StringLiteral]: J,
|
|
594
|
+
[s__namespace.SyntaxKind.NumericLiteral]: H,
|
|
593
595
|
[s__namespace.SyntaxKind.TrueKeyword]: M$2,
|
|
594
596
|
[s__namespace.SyntaxKind.FalseKeyword]: Y,
|
|
595
|
-
[s__namespace.SyntaxKind.NullKeyword]:
|
|
596
|
-
[s__namespace.SyntaxKind.RegularExpressionLiteral]:
|
|
597
|
+
[s__namespace.SyntaxKind.NullKeyword]: B$1,
|
|
598
|
+
[s__namespace.SyntaxKind.RegularExpressionLiteral]: C$2,
|
|
597
599
|
[s__namespace.SyntaxKind.Identifier]: w$1,
|
|
598
600
|
[s__namespace.SyntaxKind.ArrayLiteralExpression]: q,
|
|
599
601
|
[s__namespace.SyntaxKind.BinaryExpression]: j$1,
|
|
600
|
-
[s__namespace.SyntaxKind.PrefixUnaryExpression]:
|
|
601
|
-
[s__namespace.SyntaxKind.PostfixUnaryExpression]:
|
|
602
|
+
[s__namespace.SyntaxKind.PrefixUnaryExpression]: V$1,
|
|
603
|
+
[s__namespace.SyntaxKind.PostfixUnaryExpression]: W$1,
|
|
602
604
|
[s__namespace.SyntaxKind.CallExpression]: Q$1,
|
|
603
|
-
[s__namespace.SyntaxKind.PropertyAccessExpression]:
|
|
604
|
-
[s__namespace.SyntaxKind.ElementAccessExpression]:
|
|
605
|
+
[s__namespace.SyntaxKind.PropertyAccessExpression]: d$3,
|
|
606
|
+
[s__namespace.SyntaxKind.ElementAccessExpression]: X,
|
|
605
607
|
[s__namespace.SyntaxKind.ConditionalExpression]: v$1,
|
|
606
608
|
[s__namespace.SyntaxKind.TypeOfExpression]: z,
|
|
607
609
|
[s__namespace.SyntaxKind.ParenthesizedExpression]: O,
|
|
608
610
|
[s__namespace.SyntaxKind.ObjectLiteralExpression]: $$1
|
|
609
611
|
};
|
|
610
612
|
function te$1(e2) {
|
|
611
|
-
const t2 = [],
|
|
612
|
-
if (
|
|
613
|
+
const t2 = [], i2 = A$1(e2);
|
|
614
|
+
if (i2.errors.length > 0)
|
|
613
615
|
return {
|
|
614
616
|
success: false,
|
|
615
617
|
bytecode: [],
|
|
616
|
-
errors:
|
|
617
|
-
message:
|
|
618
|
+
errors: i2.errors.map((m2) => ({
|
|
619
|
+
message: m2,
|
|
618
620
|
line: 0,
|
|
619
621
|
character: 0
|
|
620
622
|
}))
|
|
621
623
|
};
|
|
622
|
-
const r2 = new g(), a2 = s__namespace.createSourceFile("program.ts", e2, s__namespace.ScriptTarget.Latest, true),
|
|
623
|
-
compileStatement:
|
|
624
|
-
compileExpression:
|
|
625
|
-
reportError: (
|
|
626
|
-
const { line:
|
|
624
|
+
const r2 = new g(), a2 = s__namespace.createSourceFile("program.ts", e2, s__namespace.ScriptTarget.Latest, true), T = {
|
|
625
|
+
compileStatement: S,
|
|
626
|
+
compileExpression: c2,
|
|
627
|
+
reportError: (m2, u2) => {
|
|
628
|
+
const { line: l, character: R } = a2.getLineAndCharacterOfPosition(m2.getStart());
|
|
627
629
|
throw t2.push({
|
|
628
630
|
message: u2,
|
|
629
|
-
line:
|
|
631
|
+
line: l + 1,
|
|
630
632
|
// TypeScript uses 0-based lines
|
|
631
633
|
character: R + 1
|
|
632
634
|
// TypeScript uses 0-based columns
|
|
633
635
|
}), new Error(u2);
|
|
634
636
|
}
|
|
635
637
|
};
|
|
636
|
-
function
|
|
637
|
-
const u2 = K[
|
|
638
|
+
function S(m2) {
|
|
639
|
+
const u2 = K[m2.kind];
|
|
638
640
|
if (u2)
|
|
639
|
-
u2(
|
|
641
|
+
u2(m2, r2, T);
|
|
640
642
|
else {
|
|
641
|
-
const { line:
|
|
643
|
+
const { line: l, character: R } = a2.getLineAndCharacterOfPosition(m2.getStart());
|
|
642
644
|
t2.push({
|
|
643
|
-
message: `Unsupported statement: ${s__namespace.SyntaxKind[
|
|
644
|
-
line:
|
|
645
|
+
message: `Unsupported statement: ${s__namespace.SyntaxKind[m2.kind]}`,
|
|
646
|
+
line: l + 1,
|
|
645
647
|
character: R + 1
|
|
646
648
|
});
|
|
647
649
|
}
|
|
648
650
|
}
|
|
649
|
-
function
|
|
650
|
-
const u2 = Z$1[
|
|
651
|
+
function c2(m2) {
|
|
652
|
+
const u2 = Z$1[m2.kind];
|
|
651
653
|
if (u2)
|
|
652
|
-
u2(
|
|
654
|
+
u2(m2, r2, T);
|
|
653
655
|
else {
|
|
654
|
-
const { line:
|
|
656
|
+
const { line: l, character: R } = a2.getLineAndCharacterOfPosition(m2.getStart());
|
|
655
657
|
t2.push({
|
|
656
|
-
message: `Unsupported expression: ${s__namespace.SyntaxKind[
|
|
657
|
-
line:
|
|
658
|
+
message: `Unsupported expression: ${s__namespace.SyntaxKind[m2.kind]}`,
|
|
659
|
+
line: l + 1,
|
|
658
660
|
character: R + 1
|
|
659
661
|
});
|
|
660
662
|
}
|
|
661
663
|
}
|
|
662
|
-
return a2.forEachChild((
|
|
664
|
+
return a2.forEachChild((m2) => {
|
|
663
665
|
var u2;
|
|
664
|
-
s__namespace.isFunctionDeclaration(
|
|
666
|
+
s__namespace.isFunctionDeclaration(m2) && ((u2 = m2.name) == null ? void 0 : u2.text) === "main" && m2.body && m2.body.statements.forEach((l) => {
|
|
665
667
|
try {
|
|
666
|
-
|
|
668
|
+
S(l);
|
|
667
669
|
} catch {
|
|
668
670
|
}
|
|
669
671
|
});
|
|
670
|
-
}), r2.emit(
|
|
672
|
+
}), r2.emit(n.HALT), {
|
|
671
673
|
success: t2.length === 0,
|
|
672
674
|
bytecode: r2.getBytecode(),
|
|
673
675
|
errors: t2
|
|
@@ -715,13 +717,13 @@ function m(r2) {
|
|
|
715
717
|
if (f$2(r2)) return 0;
|
|
716
718
|
if (c(r2)) return NaN;
|
|
717
719
|
if (t(r2)) {
|
|
718
|
-
const
|
|
719
|
-
return
|
|
720
|
+
const n2 = r2.trim();
|
|
721
|
+
return n2 === "" ? 0 : Number(n2);
|
|
720
722
|
}
|
|
721
723
|
return o(r2) ? NaN : Number(r2);
|
|
722
724
|
}
|
|
723
|
-
function s(r2 = [],
|
|
724
|
-
return
|
|
725
|
+
function s(r2 = [], n2) {
|
|
726
|
+
return n2 ? { type: "array", elements: r2, properties: n2 } : { type: "array", elements: r2 };
|
|
725
727
|
}
|
|
726
728
|
function C$1() {
|
|
727
729
|
return { type: "undefined" };
|
|
@@ -730,8 +732,8 @@ function M$1(r2 = {}) {
|
|
|
730
732
|
return { type: "object", properties: r2 };
|
|
731
733
|
}
|
|
732
734
|
var d$1 = Object.defineProperty;
|
|
733
|
-
var h = (s2, t2,
|
|
734
|
-
var a = (s2, t2,
|
|
735
|
+
var h = (s2, t2, n2) => t2 in s2 ? d$1(s2, t2, { enumerable: true, configurable: true, writable: true, value: n2 }) : s2[t2] = n2;
|
|
736
|
+
var a = (s2, t2, n2) => h(s2, typeof t2 != "symbol" ? t2 + "" : t2, n2);
|
|
735
737
|
class p {
|
|
736
738
|
constructor(t2) {
|
|
737
739
|
a(this, "connected", false);
|
|
@@ -754,14 +756,14 @@ class p {
|
|
|
754
756
|
}
|
|
755
757
|
async saveProgram(t2) {
|
|
756
758
|
if (!this.connected) throw new Error("Not connected");
|
|
757
|
-
const
|
|
758
|
-
await b$2.promises.writeFile(
|
|
759
|
+
const n2 = r__namespace.join(this.programsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
|
|
760
|
+
await b$2.promises.writeFile(n2, e2, "utf-8");
|
|
759
761
|
}
|
|
760
762
|
async getProgram(t2) {
|
|
761
763
|
if (!this.connected) throw new Error("Not connected");
|
|
762
|
-
const
|
|
764
|
+
const n2 = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
763
765
|
try {
|
|
764
|
-
const e2 = await b$2.promises.readFile(
|
|
766
|
+
const e2 = await b$2.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e2);
|
|
765
767
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
766
768
|
} catch (e2) {
|
|
767
769
|
if (e2.code === "ENOENT")
|
|
@@ -771,14 +773,14 @@ class p {
|
|
|
771
773
|
}
|
|
772
774
|
async saveExecution(t2) {
|
|
773
775
|
if (!this.connected) throw new Error("Not connected");
|
|
774
|
-
const
|
|
775
|
-
await b$2.promises.writeFile(
|
|
776
|
+
const n2 = r__namespace.join(this.executionsDir, `${t2.id}.json`), e2 = JSON.stringify(t2, null, 2);
|
|
777
|
+
await b$2.promises.writeFile(n2, e2, "utf-8");
|
|
776
778
|
}
|
|
777
779
|
async getExecution(t2) {
|
|
778
780
|
if (!this.connected) throw new Error("Not connected");
|
|
779
|
-
const
|
|
781
|
+
const n2 = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
780
782
|
try {
|
|
781
|
-
const e2 = await b$2.promises.readFile(
|
|
783
|
+
const e2 = await b$2.promises.readFile(n2, "utf-8"), o2 = JSON.parse(e2);
|
|
782
784
|
return o2.created = new Date(o2.created), o2.updated && (o2.updated = new Date(o2.updated)), o2;
|
|
783
785
|
} catch (e2) {
|
|
784
786
|
if (e2.code === "ENOENT")
|
|
@@ -786,18 +788,18 @@ class p {
|
|
|
786
788
|
throw e2;
|
|
787
789
|
}
|
|
788
790
|
}
|
|
789
|
-
async appendOutput(t2,
|
|
791
|
+
async appendOutput(t2, n2) {
|
|
790
792
|
if (!this.connected) throw new Error("Not connected");
|
|
791
|
-
const e2 = r__namespace.join(this.outputsDir, `${t2}.output`), o2 =
|
|
793
|
+
const e2 = r__namespace.join(this.outputsDir, `${t2}.output`), o2 = n2.join(`
|
|
792
794
|
`) + `
|
|
793
795
|
`;
|
|
794
796
|
await b$2.promises.appendFile(e2, o2, "utf-8");
|
|
795
797
|
}
|
|
796
798
|
async getOutput(t2) {
|
|
797
799
|
if (!this.connected) throw new Error("Not connected");
|
|
798
|
-
const
|
|
800
|
+
const n2 = r__namespace.join(this.outputsDir, `${t2}.output`);
|
|
799
801
|
try {
|
|
800
|
-
return (await b$2.promises.readFile(
|
|
802
|
+
return (await b$2.promises.readFile(n2, "utf-8")).split(`
|
|
801
803
|
`).filter((o2) => o2.length > 0);
|
|
802
804
|
} catch (e2) {
|
|
803
805
|
if (e2.code === "ENOENT")
|
|
@@ -807,13 +809,13 @@ class p {
|
|
|
807
809
|
}
|
|
808
810
|
async listExecutions() {
|
|
809
811
|
if (!this.connected) throw new Error("Not connected");
|
|
810
|
-
const t2 = await b$2.promises.readdir(this.executionsDir),
|
|
812
|
+
const t2 = await b$2.promises.readdir(this.executionsDir), n2 = [];
|
|
811
813
|
for (const e2 of t2)
|
|
812
814
|
if (e2.endsWith(".json")) {
|
|
813
815
|
const o2 = e2.slice(0, -5), i2 = await this.getExecution(o2);
|
|
814
|
-
i2 &&
|
|
816
|
+
i2 && n2.push(i2);
|
|
815
817
|
}
|
|
816
|
-
return
|
|
818
|
+
return n2;
|
|
817
819
|
}
|
|
818
820
|
async getCurrentExecutionId() {
|
|
819
821
|
if (!this.connected) throw new Error("Not connected");
|
|
@@ -828,14 +830,14 @@ class p {
|
|
|
828
830
|
}
|
|
829
831
|
async setCurrentExecutionId(t2) {
|
|
830
832
|
if (!this.connected) throw new Error("Not connected");
|
|
831
|
-
const
|
|
832
|
-
await b$2.promises.writeFile(this.metadataFile, JSON.stringify(
|
|
833
|
+
const n2 = { currentExecutionId: t2 };
|
|
834
|
+
await b$2.promises.writeFile(this.metadataFile, JSON.stringify(n2, null, 2), "utf-8");
|
|
833
835
|
}
|
|
834
836
|
async deleteExecution(t2) {
|
|
835
837
|
if (!this.connected) throw new Error("Not connected");
|
|
836
|
-
const
|
|
838
|
+
const n2 = r__namespace.join(this.executionsDir, `${t2}.json`);
|
|
837
839
|
try {
|
|
838
|
-
await b$2.promises.unlink(
|
|
840
|
+
await b$2.promises.unlink(n2);
|
|
839
841
|
} catch (i2) {
|
|
840
842
|
if (i2.code !== "ENOENT") throw i2;
|
|
841
843
|
}
|
|
@@ -849,19 +851,19 @@ class p {
|
|
|
849
851
|
}
|
|
850
852
|
async listPrograms() {
|
|
851
853
|
if (!this.connected) throw new Error("Not connected");
|
|
852
|
-
const t2 = await b$2.promises.readdir(this.programsDir),
|
|
854
|
+
const t2 = await b$2.promises.readdir(this.programsDir), n2 = [];
|
|
853
855
|
for (const e2 of t2)
|
|
854
856
|
if (e2.endsWith(".json")) {
|
|
855
857
|
const o2 = e2.slice(0, -5), i2 = await this.getProgram(o2);
|
|
856
|
-
i2 &&
|
|
858
|
+
i2 && n2.push(i2);
|
|
857
859
|
}
|
|
858
|
-
return
|
|
860
|
+
return n2;
|
|
859
861
|
}
|
|
860
862
|
async deleteProgram(t2) {
|
|
861
863
|
if (!this.connected) throw new Error("Not connected");
|
|
862
|
-
const
|
|
864
|
+
const n2 = r__namespace.join(this.programsDir, `${t2}.json`);
|
|
863
865
|
try {
|
|
864
|
-
await b$2.promises.unlink(
|
|
866
|
+
await b$2.promises.unlink(n2);
|
|
865
867
|
} catch (e2) {
|
|
866
868
|
if (e2.code !== "ENOENT") throw e2;
|
|
867
869
|
}
|
|
@@ -890,7 +892,7 @@ let f$1 = class f {
|
|
|
890
892
|
}
|
|
891
893
|
async getCollections() {
|
|
892
894
|
if (!this.db) throw new Error("Not connected to database");
|
|
893
|
-
return (await this.db.listCollections().toArray()).map((
|
|
895
|
+
return (await this.db.listCollections().toArray()).map((n2) => n2.name);
|
|
894
896
|
}
|
|
895
897
|
getCollection(t2) {
|
|
896
898
|
if (!this.db) throw new Error("Not connected to database");
|
|
@@ -916,12 +918,12 @@ let f$1 = class f {
|
|
|
916
918
|
async getExecution(t2) {
|
|
917
919
|
return await this.getCollection("executions").findOne({ id: t2 });
|
|
918
920
|
}
|
|
919
|
-
async appendOutput(t2,
|
|
921
|
+
async appendOutput(t2, n2) {
|
|
920
922
|
const e2 = this.getCollection("outputs");
|
|
921
923
|
await e2.findOne({ executionId: t2 }) ? await e2.updateOne(
|
|
922
924
|
{ executionId: t2 },
|
|
923
|
-
{ $push: { lines: { $each:
|
|
924
|
-
) : await e2.insertOne({ executionId: t2, lines:
|
|
925
|
+
{ $push: { lines: { $each: n2 } } }
|
|
926
|
+
) : await e2.insertOne({ executionId: t2, lines: n2 });
|
|
925
927
|
}
|
|
926
928
|
async getOutput(t2) {
|
|
927
929
|
const e2 = await this.getCollection("outputs").findOne({ executionId: t2 });
|
|
@@ -931,8 +933,8 @@ let f$1 = class f {
|
|
|
931
933
|
return await this.getCollection("executions").find({}).toArray();
|
|
932
934
|
}
|
|
933
935
|
async getCurrentExecutionId() {
|
|
934
|
-
const
|
|
935
|
-
return (
|
|
936
|
+
const n2 = await this.getCollection("metadata").findOne({ _id: "current" });
|
|
937
|
+
return (n2 == null ? void 0 : n2.currentExecutionId) || null;
|
|
936
938
|
}
|
|
937
939
|
async setCurrentExecutionId(t2) {
|
|
938
940
|
await this.getCollection("metadata").replaceOne(
|
|
@@ -943,7 +945,7 @@ let f$1 = class f {
|
|
|
943
945
|
}
|
|
944
946
|
async deleteExecution(t2) {
|
|
945
947
|
var o2;
|
|
946
|
-
let
|
|
948
|
+
let n2 = true;
|
|
947
949
|
const e2 = this.client.startSession();
|
|
948
950
|
try {
|
|
949
951
|
await e2.withTransaction(async () => {
|
|
@@ -955,13 +957,13 @@ let f$1 = class f {
|
|
|
955
957
|
});
|
|
956
958
|
} catch (i2) {
|
|
957
959
|
if ((o2 = i2 == null ? void 0 : i2.message) != null && o2.includes("Transaction numbers are only allowed"))
|
|
958
|
-
|
|
960
|
+
n2 = false;
|
|
959
961
|
else
|
|
960
962
|
throw i2;
|
|
961
963
|
} finally {
|
|
962
964
|
await e2.endSession();
|
|
963
965
|
}
|
|
964
|
-
|
|
966
|
+
n2 || (await this.getCollection("executions").deleteOne({ id: t2 }), await this.getCollection("outputs").deleteMany({ executionId: t2 }), await this.getCurrentExecutionId() === t2 && await this.setCurrentExecutionId(null));
|
|
965
967
|
}
|
|
966
968
|
async listPrograms() {
|
|
967
969
|
return await this.getCollection("programs").find({}).toArray();
|
|
@@ -972,8 +974,8 @@ let f$1 = class f {
|
|
|
972
974
|
};
|
|
973
975
|
class E {
|
|
974
976
|
static create(t2) {
|
|
975
|
-
const
|
|
976
|
-
switch (
|
|
977
|
+
const n2 = (t2 == null ? void 0 : t2.type) || process.env.CVM_STORAGE_TYPE || "file";
|
|
978
|
+
switch (n2) {
|
|
977
979
|
case "file": {
|
|
978
980
|
const e2 = (t2 == null ? void 0 : t2.dataDir) || process.env.CVM_DATA_DIR || ".cvm";
|
|
979
981
|
return new p(e2);
|
|
@@ -983,7 +985,7 @@ class E {
|
|
|
983
985
|
return new f$1(e2);
|
|
984
986
|
}
|
|
985
987
|
default:
|
|
986
|
-
throw new Error(`Unsupported storage type: ${
|
|
988
|
+
throw new Error(`Unsupported storage type: ${n2}`);
|
|
987
989
|
}
|
|
988
990
|
}
|
|
989
991
|
}
|
|
@@ -998,11 +1000,11 @@ function d(e2, t2) {
|
|
|
998
1000
|
type: "RuntimeError",
|
|
999
1001
|
message: "Stack underflow",
|
|
1000
1002
|
pc: e2.pc,
|
|
1001
|
-
opcode: t2 ||
|
|
1003
|
+
opcode: t2 || n.POP
|
|
1002
1004
|
} : e2.stack.pop();
|
|
1003
1005
|
}
|
|
1004
1006
|
const f2 = Q, Z = {
|
|
1005
|
-
[
|
|
1007
|
+
[n.ADD]: {
|
|
1006
1008
|
stackIn: 2,
|
|
1007
1009
|
stackOut: 1,
|
|
1008
1010
|
execute: (e2, t$1) => {
|
|
@@ -1018,7 +1020,7 @@ const f2 = Q, Z = {
|
|
|
1018
1020
|
}
|
|
1019
1021
|
}
|
|
1020
1022
|
},
|
|
1021
|
-
[
|
|
1023
|
+
[n.SUB]: {
|
|
1022
1024
|
stackIn: 2,
|
|
1023
1025
|
stackOut: 1,
|
|
1024
1026
|
execute: (e2, t2) => {
|
|
@@ -1030,7 +1032,7 @@ const f2 = Q, Z = {
|
|
|
1030
1032
|
e2.stack.push(s2 - c2);
|
|
1031
1033
|
}
|
|
1032
1034
|
},
|
|
1033
|
-
[
|
|
1035
|
+
[n.MUL]: {
|
|
1034
1036
|
stackIn: 2,
|
|
1035
1037
|
stackOut: 1,
|
|
1036
1038
|
execute: (e2, t2) => {
|
|
@@ -1042,7 +1044,7 @@ const f2 = Q, Z = {
|
|
|
1042
1044
|
e2.stack.push(s2 * c2);
|
|
1043
1045
|
}
|
|
1044
1046
|
},
|
|
1045
|
-
[
|
|
1047
|
+
[n.DIV]: {
|
|
1046
1048
|
stackIn: 2,
|
|
1047
1049
|
stackOut: 1,
|
|
1048
1050
|
execute: (e2, t2) => {
|
|
@@ -1061,7 +1063,7 @@ const f2 = Q, Z = {
|
|
|
1061
1063
|
e2.stack.push(s2 / c2);
|
|
1062
1064
|
}
|
|
1063
1065
|
},
|
|
1064
|
-
[
|
|
1066
|
+
[n.MOD]: {
|
|
1065
1067
|
stackIn: 2,
|
|
1066
1068
|
stackOut: 1,
|
|
1067
1069
|
execute: (e2, t2) => {
|
|
@@ -1073,7 +1075,7 @@ const f2 = Q, Z = {
|
|
|
1073
1075
|
e2.stack.push(s2 % c2);
|
|
1074
1076
|
}
|
|
1075
1077
|
},
|
|
1076
|
-
[
|
|
1078
|
+
[n.UNARY_MINUS]: {
|
|
1077
1079
|
stackIn: 1,
|
|
1078
1080
|
stackOut: 1,
|
|
1079
1081
|
execute: (e2, t2) => {
|
|
@@ -1083,7 +1085,7 @@ const f2 = Q, Z = {
|
|
|
1083
1085
|
e2.stack.push(-o2);
|
|
1084
1086
|
}
|
|
1085
1087
|
},
|
|
1086
|
-
[
|
|
1088
|
+
[n.UNARY_PLUS]: {
|
|
1087
1089
|
stackIn: 1,
|
|
1088
1090
|
stackOut: 1,
|
|
1089
1091
|
execute: (e2, t2) => {
|
|
@@ -1094,28 +1096,28 @@ const f2 = Q, Z = {
|
|
|
1094
1096
|
}
|
|
1095
1097
|
}
|
|
1096
1098
|
}, ee = {
|
|
1097
|
-
[
|
|
1099
|
+
[n.PUSH]: {
|
|
1098
1100
|
stackIn: 0,
|
|
1099
1101
|
stackOut: 1,
|
|
1100
1102
|
execute: (e2, t2) => {
|
|
1101
1103
|
e2.stack.push(t2.arg);
|
|
1102
1104
|
}
|
|
1103
1105
|
},
|
|
1104
|
-
[
|
|
1106
|
+
[n.PUSH_UNDEFINED]: {
|
|
1105
1107
|
stackIn: 0,
|
|
1106
1108
|
stackOut: 1,
|
|
1107
1109
|
execute: (e2) => {
|
|
1108
1110
|
e2.stack.push(C$1());
|
|
1109
1111
|
}
|
|
1110
1112
|
},
|
|
1111
|
-
[
|
|
1113
|
+
[n.POP]: {
|
|
1112
1114
|
stackIn: 1,
|
|
1113
1115
|
stackOut: 0,
|
|
1114
1116
|
execute: (e2) => {
|
|
1115
1117
|
e2.stack.pop();
|
|
1116
1118
|
}
|
|
1117
1119
|
},
|
|
1118
|
-
[
|
|
1120
|
+
[n.DUP]: {
|
|
1119
1121
|
stackIn: 1,
|
|
1120
1122
|
stackOut: 2,
|
|
1121
1123
|
execute: (e2, t2) => {
|
|
@@ -1123,7 +1125,7 @@ const f2 = Q, Z = {
|
|
|
1123
1125
|
e2.stack.push(r2), e2.stack.push(r2);
|
|
1124
1126
|
}
|
|
1125
1127
|
},
|
|
1126
|
-
[
|
|
1128
|
+
[n.SWAP]: {
|
|
1127
1129
|
stackIn: 2,
|
|
1128
1130
|
stackOut: 2,
|
|
1129
1131
|
execute: (e2, t2) => {
|
|
@@ -1131,7 +1133,7 @@ const f2 = Q, Z = {
|
|
|
1131
1133
|
e2.stack.push(r2), e2.stack.push(o2);
|
|
1132
1134
|
}
|
|
1133
1135
|
},
|
|
1134
|
-
[
|
|
1136
|
+
[n.DUP2]: {
|
|
1135
1137
|
stackIn: 2,
|
|
1136
1138
|
stackOut: 4,
|
|
1137
1139
|
execute: (e2, t2) => {
|
|
@@ -1140,7 +1142,7 @@ const f2 = Q, Z = {
|
|
|
1140
1142
|
}
|
|
1141
1143
|
}
|
|
1142
1144
|
}, re = {
|
|
1143
|
-
[
|
|
1145
|
+
[n.PRINT]: {
|
|
1144
1146
|
stackIn: 1,
|
|
1145
1147
|
stackOut: 0,
|
|
1146
1148
|
execute: (e2) => {
|
|
@@ -1148,7 +1150,7 @@ const f2 = Q, Z = {
|
|
|
1148
1150
|
t2 !== void 0 && e2.output.push(p$1(t2));
|
|
1149
1151
|
}
|
|
1150
1152
|
},
|
|
1151
|
-
[
|
|
1153
|
+
[n.CC]: {
|
|
1152
1154
|
stackIn: 1,
|
|
1153
1155
|
stackOut: 0,
|
|
1154
1156
|
controlsPC: true,
|
|
@@ -1159,7 +1161,7 @@ const f2 = Q, Z = {
|
|
|
1159
1161
|
}
|
|
1160
1162
|
}
|
|
1161
1163
|
}, te = {
|
|
1162
|
-
[
|
|
1164
|
+
[n.HALT]: {
|
|
1163
1165
|
stackIn: 0,
|
|
1164
1166
|
stackOut: 0,
|
|
1165
1167
|
controlsPC: true,
|
|
@@ -1167,7 +1169,7 @@ const f2 = Q, Z = {
|
|
|
1167
1169
|
e2.status = "complete";
|
|
1168
1170
|
}
|
|
1169
1171
|
},
|
|
1170
|
-
[
|
|
1172
|
+
[n.JUMP]: {
|
|
1171
1173
|
stackIn: 0,
|
|
1172
1174
|
stackOut: 0,
|
|
1173
1175
|
controlsPC: true,
|
|
@@ -1190,7 +1192,7 @@ const f2 = Q, Z = {
|
|
|
1190
1192
|
e2.pc = r2;
|
|
1191
1193
|
}
|
|
1192
1194
|
},
|
|
1193
|
-
[
|
|
1195
|
+
[n.JUMP_IF_FALSE]: {
|
|
1194
1196
|
stackIn: 1,
|
|
1195
1197
|
stackOut: 0,
|
|
1196
1198
|
controlsPC: true,
|
|
@@ -1214,7 +1216,7 @@ const f2 = Q, Z = {
|
|
|
1214
1216
|
j(r2) ? e2.pc++ : e2.pc = o2;
|
|
1215
1217
|
}
|
|
1216
1218
|
},
|
|
1217
|
-
[
|
|
1219
|
+
[n.JUMP_IF]: {
|
|
1218
1220
|
stackIn: 1,
|
|
1219
1221
|
stackOut: 0,
|
|
1220
1222
|
controlsPC: true,
|
|
@@ -1238,7 +1240,7 @@ const f2 = Q, Z = {
|
|
|
1238
1240
|
j(r2) ? e2.pc = o2 : e2.pc++;
|
|
1239
1241
|
}
|
|
1240
1242
|
},
|
|
1241
|
-
[
|
|
1243
|
+
[n.JUMP_IF_TRUE]: {
|
|
1242
1244
|
stackIn: 1,
|
|
1243
1245
|
stackOut: 0,
|
|
1244
1246
|
controlsPC: true,
|
|
@@ -1262,7 +1264,7 @@ const f2 = Q, Z = {
|
|
|
1262
1264
|
j(r2) ? e2.pc = o2 : e2.pc++;
|
|
1263
1265
|
}
|
|
1264
1266
|
},
|
|
1265
|
-
[
|
|
1267
|
+
[n.CALL]: {
|
|
1266
1268
|
stackIn: 1,
|
|
1267
1269
|
stackOut: 0,
|
|
1268
1270
|
controlsPC: false,
|
|
@@ -1270,11 +1272,11 @@ const f2 = Q, Z = {
|
|
|
1270
1272
|
type: "RuntimeError",
|
|
1271
1273
|
message: "Functions not implemented",
|
|
1272
1274
|
pc: e2.pc,
|
|
1273
|
-
opcode:
|
|
1275
|
+
opcode: n.CALL
|
|
1274
1276
|
})
|
|
1275
1277
|
}
|
|
1276
1278
|
}, oe = {
|
|
1277
|
-
[
|
|
1279
|
+
[n.LOAD]: {
|
|
1278
1280
|
stackIn: 0,
|
|
1279
1281
|
stackOut: 1,
|
|
1280
1282
|
execute: (e2, t2) => {
|
|
@@ -1282,7 +1284,7 @@ const f2 = Q, Z = {
|
|
|
1282
1284
|
e2.variables.has(r2) ? e2.stack.push(e2.variables.get(r2)) : e2.stack.push(C$1());
|
|
1283
1285
|
}
|
|
1284
1286
|
},
|
|
1285
|
-
[
|
|
1287
|
+
[n.STORE]: {
|
|
1286
1288
|
stackIn: 1,
|
|
1287
1289
|
stackOut: 0,
|
|
1288
1290
|
execute: (e2, t2) => {
|
|
@@ -1291,7 +1293,7 @@ const f2 = Q, Z = {
|
|
|
1291
1293
|
}
|
|
1292
1294
|
}
|
|
1293
1295
|
}, se = {
|
|
1294
|
-
[
|
|
1296
|
+
[n.ITER_START]: {
|
|
1295
1297
|
stackIn: 1,
|
|
1296
1298
|
stackOut: 0,
|
|
1297
1299
|
execute: (e2, t2) => {
|
|
@@ -1303,7 +1305,7 @@ const f2 = Q, Z = {
|
|
|
1303
1305
|
pc: e2.pc,
|
|
1304
1306
|
opcode: t2.op
|
|
1305
1307
|
};
|
|
1306
|
-
let o$
|
|
1308
|
+
let o$1;
|
|
1307
1309
|
if (u$1(r2)) {
|
|
1308
1310
|
const s2 = e2.heap.get(r2.id);
|
|
1309
1311
|
if (!s2 || s2.type !== "array")
|
|
@@ -1313,9 +1315,9 @@ const f2 = Q, Z = {
|
|
|
1313
1315
|
pc: e2.pc,
|
|
1314
1316
|
opcode: t2.op
|
|
1315
1317
|
};
|
|
1316
|
-
o$
|
|
1318
|
+
o$1 = s2.data;
|
|
1317
1319
|
} else if (o(r2))
|
|
1318
|
-
o$
|
|
1320
|
+
o$1 = r2;
|
|
1319
1321
|
else
|
|
1320
1322
|
return {
|
|
1321
1323
|
type: "TypeError",
|
|
@@ -1331,13 +1333,13 @@ const f2 = Q, Z = {
|
|
|
1331
1333
|
opcode: t2.op
|
|
1332
1334
|
};
|
|
1333
1335
|
e2.iterators.push({
|
|
1334
|
-
array: o$
|
|
1336
|
+
array: o$1,
|
|
1335
1337
|
index: 0,
|
|
1336
|
-
length: o$
|
|
1338
|
+
length: o$1.elements.length
|
|
1337
1339
|
});
|
|
1338
1340
|
}
|
|
1339
1341
|
},
|
|
1340
|
-
[
|
|
1342
|
+
[n.ITER_NEXT]: {
|
|
1341
1343
|
stackIn: 0,
|
|
1342
1344
|
stackOut: 2,
|
|
1343
1345
|
// Pushes element and hasMore flag
|
|
@@ -1353,7 +1355,7 @@ const f2 = Q, Z = {
|
|
|
1353
1355
|
r2.index < r2.length ? (r2.array && r2.index < r2.array.elements.length ? e2.stack.push(r2.array.elements[r2.index]) : e2.stack.push(C$1()), e2.stack.push(true), r2.index++) : (e2.stack.push(null), e2.stack.push(false));
|
|
1354
1356
|
}
|
|
1355
1357
|
},
|
|
1356
|
-
[
|
|
1358
|
+
[n.ITER_END]: {
|
|
1357
1359
|
stackIn: 0,
|
|
1358
1360
|
stackOut: 0,
|
|
1359
1361
|
execute: (e2, t2) => {
|
|
@@ -1377,7 +1379,7 @@ function v(e2, t2, r2) {
|
|
|
1377
1379
|
e2.stack.push(c2);
|
|
1378
1380
|
}
|
|
1379
1381
|
const ce = {
|
|
1380
|
-
[
|
|
1382
|
+
[n.EQ]: {
|
|
1381
1383
|
stackIn: 2,
|
|
1382
1384
|
stackOut: 1,
|
|
1383
1385
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => {
|
|
@@ -1393,7 +1395,7 @@ const ce = {
|
|
|
1393
1395
|
}
|
|
1394
1396
|
})
|
|
1395
1397
|
},
|
|
1396
|
-
[
|
|
1398
|
+
[n.NEQ]: {
|
|
1397
1399
|
stackIn: 2,
|
|
1398
1400
|
stackOut: 1,
|
|
1399
1401
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => {
|
|
@@ -1409,7 +1411,7 @@ const ce = {
|
|
|
1409
1411
|
}
|
|
1410
1412
|
})
|
|
1411
1413
|
},
|
|
1412
|
-
[
|
|
1414
|
+
[n.LT]: {
|
|
1413
1415
|
stackIn: 2,
|
|
1414
1416
|
stackOut: 1,
|
|
1415
1417
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => {
|
|
@@ -1417,7 +1419,7 @@ const ce = {
|
|
|
1417
1419
|
return s2 < c2;
|
|
1418
1420
|
})
|
|
1419
1421
|
},
|
|
1420
|
-
[
|
|
1422
|
+
[n.GT]: {
|
|
1421
1423
|
stackIn: 2,
|
|
1422
1424
|
stackOut: 1,
|
|
1423
1425
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => {
|
|
@@ -1425,7 +1427,7 @@ const ce = {
|
|
|
1425
1427
|
return s2 > c2;
|
|
1426
1428
|
})
|
|
1427
1429
|
},
|
|
1428
|
-
[
|
|
1430
|
+
[n.LTE]: {
|
|
1429
1431
|
stackIn: 2,
|
|
1430
1432
|
stackOut: 1,
|
|
1431
1433
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => {
|
|
@@ -1433,7 +1435,7 @@ const ce = {
|
|
|
1433
1435
|
return s2 <= c2;
|
|
1434
1436
|
})
|
|
1435
1437
|
},
|
|
1436
|
-
[
|
|
1438
|
+
[n.GTE]: {
|
|
1437
1439
|
stackIn: 2,
|
|
1438
1440
|
stackOut: 1,
|
|
1439
1441
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => {
|
|
@@ -1441,18 +1443,18 @@ const ce = {
|
|
|
1441
1443
|
return s2 >= c2;
|
|
1442
1444
|
})
|
|
1443
1445
|
},
|
|
1444
|
-
[
|
|
1446
|
+
[n.EQ_STRICT]: {
|
|
1445
1447
|
stackIn: 2,
|
|
1446
1448
|
stackOut: 1,
|
|
1447
1449
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => u$1(r2) && u$1(o2) || b(r2) && b(o2) ? r2.id === o2.id : r2 === o2)
|
|
1448
1450
|
},
|
|
1449
|
-
[
|
|
1451
|
+
[n.NEQ_STRICT]: {
|
|
1450
1452
|
stackIn: 2,
|
|
1451
1453
|
stackOut: 1,
|
|
1452
1454
|
execute: (e2, t2) => v(e2, t2, (r2, o2) => u$1(r2) && u$1(o2) || b(r2) && b(o2) ? r2.id !== o2.id : r2 !== o2)
|
|
1453
1455
|
}
|
|
1454
1456
|
}, ne = {
|
|
1455
|
-
[
|
|
1457
|
+
[n.AND]: {
|
|
1456
1458
|
stackIn: 2,
|
|
1457
1459
|
stackOut: 1,
|
|
1458
1460
|
execute: (e2, t2) => {
|
|
@@ -1464,7 +1466,7 @@ const ce = {
|
|
|
1464
1466
|
e2.stack.push(s2);
|
|
1465
1467
|
}
|
|
1466
1468
|
},
|
|
1467
|
-
[
|
|
1469
|
+
[n.OR]: {
|
|
1468
1470
|
stackIn: 2,
|
|
1469
1471
|
stackOut: 1,
|
|
1470
1472
|
execute: (e2, t2) => {
|
|
@@ -1476,7 +1478,7 @@ const ce = {
|
|
|
1476
1478
|
e2.stack.push(s2);
|
|
1477
1479
|
}
|
|
1478
1480
|
},
|
|
1479
|
-
[
|
|
1481
|
+
[n.NOT]: {
|
|
1480
1482
|
stackIn: 1,
|
|
1481
1483
|
stackOut: 1,
|
|
1482
1484
|
execute: (e2, t2) => {
|
|
@@ -1491,7 +1493,7 @@ const ce = {
|
|
|
1491
1493
|
* ARRAY_NEW: Creates a new empty array on the heap
|
|
1492
1494
|
* Stack: [] -> [array-ref]
|
|
1493
1495
|
*/
|
|
1494
|
-
[
|
|
1496
|
+
[n.ARRAY_NEW]: {
|
|
1495
1497
|
stackIn: 0,
|
|
1496
1498
|
stackOut: 1,
|
|
1497
1499
|
execute: (e2, t2) => {
|
|
@@ -1503,14 +1505,14 @@ const ce = {
|
|
|
1503
1505
|
* ARRAY_PUSH: Pushes a value to the end of an array
|
|
1504
1506
|
* Stack: [array-ref, value] -> [array-ref]
|
|
1505
1507
|
*/
|
|
1506
|
-
[
|
|
1508
|
+
[n.ARRAY_PUSH]: {
|
|
1507
1509
|
stackIn: 2,
|
|
1508
1510
|
stackOut: 1,
|
|
1509
1511
|
execute: (e2, t2) => {
|
|
1510
|
-
const r2 = e2.stack.pop(), o$
|
|
1512
|
+
const r2 = e2.stack.pop(), o$1 = e2.stack.pop();
|
|
1511
1513
|
let s2;
|
|
1512
|
-
if (u$1(o$
|
|
1513
|
-
const c2 = e2.heap.get(o$
|
|
1514
|
+
if (u$1(o$1)) {
|
|
1515
|
+
const c2 = e2.heap.get(o$1.id);
|
|
1514
1516
|
if (!c2 || c2.type !== "array")
|
|
1515
1517
|
return {
|
|
1516
1518
|
type: "RuntimeError",
|
|
@@ -1519,8 +1521,8 @@ const ce = {
|
|
|
1519
1521
|
opcode: t2.op
|
|
1520
1522
|
};
|
|
1521
1523
|
s2 = c2.data;
|
|
1522
|
-
} else if (o(o$
|
|
1523
|
-
s2 = o$
|
|
1524
|
+
} else if (o(o$1))
|
|
1525
|
+
s2 = o$1;
|
|
1524
1526
|
else
|
|
1525
1527
|
return {
|
|
1526
1528
|
type: "RuntimeError",
|
|
@@ -1528,49 +1530,49 @@ const ce = {
|
|
|
1528
1530
|
pc: e2.pc,
|
|
1529
1531
|
opcode: t2.op
|
|
1530
1532
|
};
|
|
1531
|
-
s2.elements.push(r2), e2.stack.push(o$
|
|
1533
|
+
s2.elements.push(r2), e2.stack.push(o$1);
|
|
1532
1534
|
}
|
|
1533
1535
|
},
|
|
1534
|
-
[
|
|
1536
|
+
[n.ARRAY_GET]: {
|
|
1535
1537
|
stackIn: 2,
|
|
1536
1538
|
stackOut: 1,
|
|
1537
1539
|
execute: (e2, t$1) => {
|
|
1538
1540
|
var a2;
|
|
1539
|
-
const r2 = e2.stack.pop(), o$
|
|
1541
|
+
const r2 = e2.stack.pop(), o$1 = e2.stack.pop();
|
|
1540
1542
|
let s2;
|
|
1541
|
-
if (u$1(o$
|
|
1542
|
-
const
|
|
1543
|
-
if (!
|
|
1543
|
+
if (u$1(o$1)) {
|
|
1544
|
+
const i2 = e2.heap.get(o$1.id);
|
|
1545
|
+
if (!i2 || i2.type !== "array")
|
|
1544
1546
|
return {
|
|
1545
1547
|
type: "RuntimeError",
|
|
1546
1548
|
message: "Invalid array reference",
|
|
1547
1549
|
pc: e2.pc,
|
|
1548
1550
|
opcode: t$1.op
|
|
1549
1551
|
};
|
|
1550
|
-
s2 =
|
|
1551
|
-
} else if (b(o$
|
|
1552
|
-
const
|
|
1553
|
-
if (!
|
|
1552
|
+
s2 = i2.data;
|
|
1553
|
+
} else if (b(o$1)) {
|
|
1554
|
+
const i2 = e2.heap.get(o$1.id);
|
|
1555
|
+
if (!i2 || i2.type !== "object")
|
|
1554
1556
|
return {
|
|
1555
1557
|
type: "RuntimeError",
|
|
1556
1558
|
message: "Invalid object reference",
|
|
1557
1559
|
pc: e2.pc,
|
|
1558
1560
|
opcode: t$1.op
|
|
1559
1561
|
};
|
|
1560
|
-
const
|
|
1562
|
+
const u2 = i2.data, y2 = p$1(r2), E2 = u2.properties[y2] ?? C$1();
|
|
1561
1563
|
e2.stack.push(E2);
|
|
1562
1564
|
return;
|
|
1563
|
-
} else if (o(o$
|
|
1564
|
-
s2 = o$
|
|
1565
|
-
else if (t(o$
|
|
1566
|
-
let
|
|
1565
|
+
} else if (o(o$1))
|
|
1566
|
+
s2 = o$1;
|
|
1567
|
+
else if (t(o$1)) {
|
|
1568
|
+
let i2;
|
|
1567
1569
|
if (i$1(r2))
|
|
1568
|
-
|
|
1570
|
+
i2 = r2;
|
|
1569
1571
|
else if (t(r2)) {
|
|
1570
|
-
const
|
|
1571
|
-
!isNaN(
|
|
1572
|
+
const u2 = parseInt(r2, 10);
|
|
1573
|
+
!isNaN(u2) && u2.toString() === r2 && (i2 = u2);
|
|
1572
1574
|
}
|
|
1573
|
-
|
|
1575
|
+
i2 !== void 0 && i2 >= 0 && i2 < o$1.length ? e2.stack.push(o$1[i2]) : e2.stack.push(C$1());
|
|
1574
1576
|
return;
|
|
1575
1577
|
} else
|
|
1576
1578
|
return {
|
|
@@ -1583,12 +1585,12 @@ const ce = {
|
|
|
1583
1585
|
if (i$1(r2))
|
|
1584
1586
|
c2 = r2;
|
|
1585
1587
|
else if (t(r2)) {
|
|
1586
|
-
const
|
|
1587
|
-
if (!isNaN(
|
|
1588
|
-
c2 =
|
|
1588
|
+
const i2 = parseInt(r2, 10);
|
|
1589
|
+
if (!isNaN(i2) && i2.toString() === r2 && i2 >= 0)
|
|
1590
|
+
c2 = i2;
|
|
1589
1591
|
else {
|
|
1590
|
-
const
|
|
1591
|
-
e2.stack.push(
|
|
1592
|
+
const u2 = ((a2 = s2.properties) == null ? void 0 : a2[r2]) ?? C$1();
|
|
1593
|
+
e2.stack.push(u2);
|
|
1592
1594
|
return;
|
|
1593
1595
|
}
|
|
1594
1596
|
} else
|
|
@@ -1602,33 +1604,33 @@ const ce = {
|
|
|
1602
1604
|
e2.stack.push(p2);
|
|
1603
1605
|
}
|
|
1604
1606
|
},
|
|
1605
|
-
[
|
|
1607
|
+
[n.ARRAY_SET]: {
|
|
1606
1608
|
stackIn: 3,
|
|
1607
1609
|
stackOut: 1,
|
|
1608
1610
|
execute: (e2, t$1) => {
|
|
1609
|
-
const r2 = e2.stack.pop(), o$
|
|
1611
|
+
const r2 = e2.stack.pop(), o$1 = e2.stack.pop(), s2 = e2.stack.pop();
|
|
1610
1612
|
let c2;
|
|
1611
1613
|
if (u$1(s2)) {
|
|
1612
|
-
const
|
|
1613
|
-
if (!
|
|
1614
|
+
const i2 = e2.heap.get(s2.id);
|
|
1615
|
+
if (!i2 || i2.type !== "array")
|
|
1614
1616
|
return {
|
|
1615
1617
|
type: "RuntimeError",
|
|
1616
1618
|
message: "Invalid array reference",
|
|
1617
1619
|
pc: e2.pc,
|
|
1618
1620
|
opcode: t$1.op
|
|
1619
1621
|
};
|
|
1620
|
-
c2 =
|
|
1622
|
+
c2 = i2.data;
|
|
1621
1623
|
} else if (b(s2)) {
|
|
1622
|
-
const
|
|
1623
|
-
if (!
|
|
1624
|
+
const i2 = e2.heap.get(s2.id);
|
|
1625
|
+
if (!i2 || i2.type !== "object")
|
|
1624
1626
|
return {
|
|
1625
1627
|
type: "RuntimeError",
|
|
1626
1628
|
message: "Invalid object reference",
|
|
1627
1629
|
pc: e2.pc,
|
|
1628
1630
|
opcode: t$1.op
|
|
1629
1631
|
};
|
|
1630
|
-
const
|
|
1631
|
-
|
|
1632
|
+
const u2 = i2.data, y2 = p$1(o$1);
|
|
1633
|
+
u2.properties[y2] = r2, e2.stack.push(s2);
|
|
1632
1634
|
return;
|
|
1633
1635
|
} else if (o(s2))
|
|
1634
1636
|
c2 = s2;
|
|
@@ -1640,14 +1642,14 @@ const ce = {
|
|
|
1640
1642
|
opcode: t$1.op
|
|
1641
1643
|
};
|
|
1642
1644
|
let p2;
|
|
1643
|
-
if (i$1(o$
|
|
1644
|
-
p2 = o$
|
|
1645
|
-
else if (t(o$
|
|
1646
|
-
const
|
|
1647
|
-
if (!isNaN(
|
|
1648
|
-
p2 =
|
|
1645
|
+
if (i$1(o$1))
|
|
1646
|
+
p2 = o$1;
|
|
1647
|
+
else if (t(o$1)) {
|
|
1648
|
+
const i2 = parseInt(o$1, 10);
|
|
1649
|
+
if (!isNaN(i2) && i2.toString() === o$1 && i2 >= 0)
|
|
1650
|
+
p2 = i2;
|
|
1649
1651
|
else {
|
|
1650
|
-
c2.properties || (c2.properties = {}), c2.properties[o$
|
|
1652
|
+
c2.properties || (c2.properties = {}), c2.properties[o$1] = r2, e2.stack.push(s2);
|
|
1651
1653
|
return;
|
|
1652
1654
|
}
|
|
1653
1655
|
} else
|
|
@@ -1668,12 +1670,12 @@ const ce = {
|
|
|
1668
1670
|
c2.elements[a2] = r2, e2.stack.push(s2);
|
|
1669
1671
|
}
|
|
1670
1672
|
},
|
|
1671
|
-
[
|
|
1673
|
+
[n.ARRAY_LEN]: {
|
|
1672
1674
|
stackIn: 1,
|
|
1673
1675
|
stackOut: 1,
|
|
1674
1676
|
execute: (e2, t2) => {
|
|
1675
1677
|
const r2 = e2.stack.pop();
|
|
1676
|
-
let o$
|
|
1678
|
+
let o$1;
|
|
1677
1679
|
if (u$1(r2)) {
|
|
1678
1680
|
const s2 = e2.heap.get(r2.id);
|
|
1679
1681
|
if (!s2 || s2.type !== "array")
|
|
@@ -1683,9 +1685,9 @@ const ce = {
|
|
|
1683
1685
|
pc: e2.pc,
|
|
1684
1686
|
opcode: t2.op
|
|
1685
1687
|
};
|
|
1686
|
-
o$
|
|
1688
|
+
o$1 = s2.data;
|
|
1687
1689
|
} else if (o(r2))
|
|
1688
|
-
o$
|
|
1690
|
+
o$1 = r2;
|
|
1689
1691
|
else
|
|
1690
1692
|
return {
|
|
1691
1693
|
type: "RuntimeError",
|
|
@@ -1693,10 +1695,10 @@ const ce = {
|
|
|
1693
1695
|
pc: e2.pc,
|
|
1694
1696
|
opcode: t2.op
|
|
1695
1697
|
};
|
|
1696
|
-
e2.stack.push(o$
|
|
1698
|
+
e2.stack.push(o$1.elements.length);
|
|
1697
1699
|
}
|
|
1698
1700
|
},
|
|
1699
|
-
[
|
|
1701
|
+
[n.ARRAY_MAP_PROP]: {
|
|
1700
1702
|
stackIn: 2,
|
|
1701
1703
|
stackOut: 1,
|
|
1702
1704
|
execute: (e2, t2) => {
|
|
@@ -1717,11 +1719,11 @@ const ce = {
|
|
|
1717
1719
|
opcode: t2.op
|
|
1718
1720
|
};
|
|
1719
1721
|
const c2 = s$12.data, p2 = s();
|
|
1720
|
-
for (const
|
|
1721
|
-
if (b(
|
|
1722
|
-
const
|
|
1723
|
-
if (
|
|
1724
|
-
const y2 =
|
|
1722
|
+
for (const i2 of c2.elements)
|
|
1723
|
+
if (b(i2)) {
|
|
1724
|
+
const u2 = e2.heap.get(i2.id);
|
|
1725
|
+
if (u2 && u2.type === "object") {
|
|
1726
|
+
const y2 = u2.data, E2 = p$1(r2);
|
|
1725
1727
|
p2.elements.push(y2.properties[E2] || null);
|
|
1726
1728
|
} else
|
|
1727
1729
|
p2.elements.push(null);
|
|
@@ -1731,7 +1733,7 @@ const ce = {
|
|
|
1731
1733
|
e2.stack.push(a2);
|
|
1732
1734
|
}
|
|
1733
1735
|
},
|
|
1734
|
-
[
|
|
1736
|
+
[n.ARRAY_FILTER_PROP]: {
|
|
1735
1737
|
stackIn: 2,
|
|
1736
1738
|
stackOut: 1,
|
|
1737
1739
|
execute: (e2, t2) => {
|
|
@@ -1752,19 +1754,19 @@ const ce = {
|
|
|
1752
1754
|
opcode: t2.op
|
|
1753
1755
|
};
|
|
1754
1756
|
const c2 = s$12.data, p2 = s();
|
|
1755
|
-
for (const
|
|
1756
|
-
if (b(
|
|
1757
|
-
const
|
|
1758
|
-
if (
|
|
1759
|
-
const y2 =
|
|
1760
|
-
E2 in y2.properties && y2.properties[E2] && p2.elements.push(
|
|
1757
|
+
for (const i2 of c2.elements)
|
|
1758
|
+
if (b(i2)) {
|
|
1759
|
+
const u2 = e2.heap.get(i2.id);
|
|
1760
|
+
if (u2 && u2.type === "object") {
|
|
1761
|
+
const y2 = u2.data, E2 = p$1(r2);
|
|
1762
|
+
E2 in y2.properties && y2.properties[E2] && p2.elements.push(i2);
|
|
1761
1763
|
}
|
|
1762
1764
|
}
|
|
1763
1765
|
const a2 = e2.heap.allocate("array", p2);
|
|
1764
1766
|
e2.stack.push(a2);
|
|
1765
1767
|
}
|
|
1766
1768
|
},
|
|
1767
|
-
[
|
|
1769
|
+
[n.ARRAY_SLICE]: {
|
|
1768
1770
|
stackIn: 3,
|
|
1769
1771
|
// array, start, end
|
|
1770
1772
|
stackOut: 1,
|
|
@@ -1782,11 +1784,11 @@ const ce = {
|
|
|
1782
1784
|
pc: e2.pc,
|
|
1783
1785
|
opcode: t2.op
|
|
1784
1786
|
};
|
|
1785
|
-
const a2 = e2.heap.get(s$12.id).data,
|
|
1787
|
+
const a2 = e2.heap.get(s$12.id).data, i2 = i$1(o2) ? o2 : 0, u2 = r2 === void 0 ? a2.elements.length : i$1(r2) ? r2 : a2.elements.length, y2 = i2 < 0 ? Math.max(0, a2.elements.length + i2) : i2, E2 = u2 < 0 ? Math.max(0, a2.elements.length + u2) : u2, J2 = a2.elements.slice(y2, E2), Y2 = s(J2), z2 = e2.heap.allocate("array", Y2);
|
|
1786
1788
|
e2.stack.push(z2);
|
|
1787
1789
|
}
|
|
1788
1790
|
},
|
|
1789
|
-
[
|
|
1791
|
+
[n.ARRAY_JOIN]: {
|
|
1790
1792
|
stackIn: 2,
|
|
1791
1793
|
// array, separator
|
|
1792
1794
|
stackOut: 1,
|
|
@@ -1805,11 +1807,11 @@ const ce = {
|
|
|
1805
1807
|
pc: e2.pc,
|
|
1806
1808
|
opcode: t$1.op
|
|
1807
1809
|
};
|
|
1808
|
-
const p2 = e2.heap.get(o2.id).data, a2 = t(r2) ? r2 : String(r2),
|
|
1809
|
-
e2.stack.push(
|
|
1810
|
+
const p2 = e2.heap.get(o2.id).data, a2 = t(r2) ? r2 : String(r2), u2 = p2.elements.map((y2) => y2 === null ? "null" : y2 === void 0 || c(y2) ? "undefined" : String(y2)).join(a2);
|
|
1811
|
+
e2.stack.push(u2);
|
|
1810
1812
|
}
|
|
1811
1813
|
},
|
|
1812
|
-
[
|
|
1814
|
+
[n.ARRAY_INDEX_OF]: {
|
|
1813
1815
|
stackIn: 2,
|
|
1814
1816
|
// array, searchElement
|
|
1815
1817
|
stackOut: 1,
|
|
@@ -1819,8 +1821,8 @@ const ce = {
|
|
|
1819
1821
|
if (!((a2) => {
|
|
1820
1822
|
if (!u$1(a2))
|
|
1821
1823
|
return false;
|
|
1822
|
-
const
|
|
1823
|
-
return
|
|
1824
|
+
const i2 = e2.heap.get(a2.id);
|
|
1825
|
+
return i2 !== void 0 && i2.type === "array";
|
|
1824
1826
|
})(o2))
|
|
1825
1827
|
return {
|
|
1826
1828
|
type: "RuntimeError",
|
|
@@ -1859,7 +1861,7 @@ function M(e2, t2) {
|
|
|
1859
1861
|
}
|
|
1860
1862
|
}
|
|
1861
1863
|
const ae = {
|
|
1862
|
-
[
|
|
1864
|
+
[n.CONCAT]: {
|
|
1863
1865
|
stackIn: 2,
|
|
1864
1866
|
stackOut: 1,
|
|
1865
1867
|
execute: (e2, t2) => {
|
|
@@ -1870,7 +1872,7 @@ const ae = {
|
|
|
1870
1872
|
e2.stack.push(p$1(o2) + p$1(r2));
|
|
1871
1873
|
}
|
|
1872
1874
|
},
|
|
1873
|
-
[
|
|
1875
|
+
[n.STRING_LEN]: {
|
|
1874
1876
|
stackIn: 1,
|
|
1875
1877
|
stackOut: 1,
|
|
1876
1878
|
execute: (e2, t$1) => {
|
|
@@ -1886,7 +1888,7 @@ const ae = {
|
|
|
1886
1888
|
e2.stack.push(r2.length);
|
|
1887
1889
|
}
|
|
1888
1890
|
},
|
|
1889
|
-
[
|
|
1891
|
+
[n.LENGTH]: {
|
|
1890
1892
|
stackIn: 1,
|
|
1891
1893
|
stackOut: 1,
|
|
1892
1894
|
execute: (e2, t$1) => {
|
|
@@ -1916,7 +1918,7 @@ const ae = {
|
|
|
1916
1918
|
};
|
|
1917
1919
|
}
|
|
1918
1920
|
},
|
|
1919
|
-
[
|
|
1921
|
+
[n.JSON_PARSE]: {
|
|
1920
1922
|
stackIn: 1,
|
|
1921
1923
|
stackOut: 1,
|
|
1922
1924
|
execute: (e2, t$1) => {
|
|
@@ -1937,7 +1939,7 @@ const ae = {
|
|
|
1937
1939
|
}
|
|
1938
1940
|
}
|
|
1939
1941
|
},
|
|
1940
|
-
[
|
|
1942
|
+
[n.TYPEOF]: {
|
|
1941
1943
|
stackIn: 1,
|
|
1942
1944
|
stackOut: 1,
|
|
1943
1945
|
execute: (e2, t2) => {
|
|
@@ -1946,8 +1948,8 @@ const ae = {
|
|
|
1946
1948
|
e2.stack.push(d$2(r2));
|
|
1947
1949
|
}
|
|
1948
1950
|
}
|
|
1949
|
-
},
|
|
1950
|
-
[
|
|
1951
|
+
}, ie = {
|
|
1952
|
+
[n.INC]: {
|
|
1951
1953
|
stackIn: 1,
|
|
1952
1954
|
stackOut: 1,
|
|
1953
1955
|
execute: (e2, t2) => {
|
|
@@ -1965,7 +1967,7 @@ const ae = {
|
|
|
1965
1967
|
e2.stack.push(c2 ? m(o2) : s2);
|
|
1966
1968
|
}
|
|
1967
1969
|
},
|
|
1968
|
-
[
|
|
1970
|
+
[n.DEC]: {
|
|
1969
1971
|
stackIn: 1,
|
|
1970
1972
|
stackOut: 1,
|
|
1971
1973
|
execute: (e2, t2) => {
|
|
@@ -1983,8 +1985,8 @@ const ae = {
|
|
|
1983
1985
|
e2.stack.push(c2 ? m(o2) : s2);
|
|
1984
1986
|
}
|
|
1985
1987
|
}
|
|
1986
|
-
},
|
|
1987
|
-
[
|
|
1988
|
+
}, ue = {
|
|
1989
|
+
[n.RETURN]: {
|
|
1988
1990
|
stackIn: 0,
|
|
1989
1991
|
stackOut: 0,
|
|
1990
1992
|
controlsPC: true,
|
|
@@ -1993,7 +1995,7 @@ const ae = {
|
|
|
1993
1995
|
e2.returnValue = r2, e2.status = "complete";
|
|
1994
1996
|
}
|
|
1995
1997
|
},
|
|
1996
|
-
[
|
|
1998
|
+
[n.BREAK]: {
|
|
1997
1999
|
stackIn: 0,
|
|
1998
2000
|
stackOut: 0,
|
|
1999
2001
|
controlsPC: true,
|
|
@@ -2016,7 +2018,7 @@ const ae = {
|
|
|
2016
2018
|
e2.pc = r2;
|
|
2017
2019
|
}
|
|
2018
2020
|
},
|
|
2019
|
-
[
|
|
2021
|
+
[n.CONTINUE]: {
|
|
2020
2022
|
stackIn: 0,
|
|
2021
2023
|
stackOut: 0,
|
|
2022
2024
|
controlsPC: true,
|
|
@@ -2029,17 +2031,17 @@ const ae = {
|
|
|
2029
2031
|
opcode: t2.op
|
|
2030
2032
|
};
|
|
2031
2033
|
const r2 = t2.arg;
|
|
2032
|
-
if (r2 < 0)
|
|
2034
|
+
if (r2 < 0 || r2 === -1)
|
|
2033
2035
|
return {
|
|
2034
2036
|
type: "RuntimeError",
|
|
2035
|
-
message: `Invalid continue target: ${r2}`,
|
|
2037
|
+
message: `Invalid continue target: ${r2} (not patched properly during compilation)`,
|
|
2036
2038
|
pc: e2.pc,
|
|
2037
2039
|
opcode: t2.op
|
|
2038
2040
|
};
|
|
2039
2041
|
e2.pc = r2;
|
|
2040
2042
|
}
|
|
2041
2043
|
},
|
|
2042
|
-
[
|
|
2044
|
+
[n.FS_LIST_FILES]: {
|
|
2043
2045
|
stackIn: 1,
|
|
2044
2046
|
// Minimum 1 argument (path), optionally 2 (path + options)
|
|
2045
2047
|
stackOut: 1,
|
|
@@ -2051,9 +2053,9 @@ const ae = {
|
|
|
2051
2053
|
pc: e2.pc,
|
|
2052
2054
|
opcode: t$1.op
|
|
2053
2055
|
};
|
|
2054
|
-
let r2, o$
|
|
2056
|
+
let r2, o$1 = {};
|
|
2055
2057
|
const s2 = e2.stack[e2.stack.length - 1];
|
|
2056
|
-
if (e2.stack.length >= 2 && typeof s2 == "object" && s2 !== null && !o(s2) && (o$
|
|
2058
|
+
if (e2.stack.length >= 2 && typeof s2 == "object" && s2 !== null && !o(s2) && (o$1 = e2.stack.pop()), r2 = e2.stack.pop(), !t(r2))
|
|
2057
2059
|
return {
|
|
2058
2060
|
type: "RuntimeError",
|
|
2059
2061
|
message: "FS_LIST_FILES requires a string path",
|
|
@@ -2067,7 +2069,7 @@ const ae = {
|
|
|
2067
2069
|
pc: e2.pc,
|
|
2068
2070
|
opcode: t$1.op
|
|
2069
2071
|
};
|
|
2070
|
-
const c2 = e2.fileSystem.listFiles(r2, o$
|
|
2072
|
+
const c2 = e2.fileSystem.listFiles(r2, o$1);
|
|
2071
2073
|
if (o(c2)) {
|
|
2072
2074
|
const p2 = e2.heap.allocate("array", c2);
|
|
2073
2075
|
e2.stack.push(p2);
|
|
@@ -2075,7 +2077,7 @@ const ae = {
|
|
|
2075
2077
|
e2.stack.push(c2);
|
|
2076
2078
|
}
|
|
2077
2079
|
},
|
|
2078
|
-
[
|
|
2080
|
+
[n.FS_READ_FILE]: {
|
|
2079
2081
|
stackIn: 1,
|
|
2080
2082
|
// path
|
|
2081
2083
|
stackOut: 1,
|
|
@@ -2100,7 +2102,7 @@ const ae = {
|
|
|
2100
2102
|
e2.stack.push(o2);
|
|
2101
2103
|
}
|
|
2102
2104
|
},
|
|
2103
|
-
[
|
|
2105
|
+
[n.FS_WRITE_FILE]: {
|
|
2104
2106
|
stackIn: 2,
|
|
2105
2107
|
// path, content
|
|
2106
2108
|
stackOut: 1,
|
|
@@ -2133,7 +2135,7 @@ const ae = {
|
|
|
2133
2135
|
}
|
|
2134
2136
|
},
|
|
2135
2137
|
// String method handlers
|
|
2136
|
-
[
|
|
2138
|
+
[n.STRING_SUBSTRING]: {
|
|
2137
2139
|
stackIn: 2,
|
|
2138
2140
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
2139
2141
|
stackOut: 1,
|
|
@@ -2162,13 +2164,13 @@ const ae = {
|
|
|
2162
2164
|
pc: e2.pc,
|
|
2163
2165
|
opcode: t$1.op
|
|
2164
2166
|
};
|
|
2165
|
-
const
|
|
2166
|
-
s2 < 0 && (s2 = Math.max(0,
|
|
2167
|
-
const
|
|
2168
|
-
e2.stack.push(
|
|
2167
|
+
const i2 = o2.length;
|
|
2168
|
+
s2 < 0 && (s2 = Math.max(0, i2 + s2)), c2 !== void 0 && c2 < 0 && (c2 = Math.max(0, i2 + c2));
|
|
2169
|
+
const u2 = c2 !== void 0 ? o2.substring(s2, c2) : o2.substring(s2);
|
|
2170
|
+
e2.stack.push(u2);
|
|
2169
2171
|
}
|
|
2170
2172
|
},
|
|
2171
|
-
[
|
|
2173
|
+
[n.STRING_INDEXOF]: {
|
|
2172
2174
|
stackIn: 2,
|
|
2173
2175
|
stackOut: 1,
|
|
2174
2176
|
execute: (e2, t$1) => {
|
|
@@ -2183,7 +2185,7 @@ const ae = {
|
|
|
2183
2185
|
e2.stack.push(o2.indexOf(r2));
|
|
2184
2186
|
}
|
|
2185
2187
|
},
|
|
2186
|
-
[
|
|
2188
|
+
[n.STRING_SPLIT]: {
|
|
2187
2189
|
stackIn: 2,
|
|
2188
2190
|
stackOut: 1,
|
|
2189
2191
|
execute: (e2, t$1) => {
|
|
@@ -2201,7 +2203,7 @@ const ae = {
|
|
|
2201
2203
|
e2.stack.push(p2);
|
|
2202
2204
|
}
|
|
2203
2205
|
},
|
|
2204
|
-
[
|
|
2206
|
+
[n.STRING_SLICE]: {
|
|
2205
2207
|
stackIn: 2,
|
|
2206
2208
|
// Minimum 2 (string, start), optionally 3 (string, start, end)
|
|
2207
2209
|
stackOut: 1,
|
|
@@ -2230,11 +2232,11 @@ const ae = {
|
|
|
2230
2232
|
pc: e2.pc,
|
|
2231
2233
|
opcode: t$1.op
|
|
2232
2234
|
};
|
|
2233
|
-
const
|
|
2234
|
-
e2.stack.push(
|
|
2235
|
+
const i2 = c2 !== void 0 ? o2.slice(s2, c2) : o2.slice(s2);
|
|
2236
|
+
e2.stack.push(i2);
|
|
2235
2237
|
}
|
|
2236
2238
|
},
|
|
2237
|
-
[
|
|
2239
|
+
[n.STRING_CHARAT]: {
|
|
2238
2240
|
stackIn: 2,
|
|
2239
2241
|
stackOut: 1,
|
|
2240
2242
|
execute: (e2, t$1) => {
|
|
@@ -2257,7 +2259,7 @@ const ae = {
|
|
|
2257
2259
|
e2.stack.push(s2);
|
|
2258
2260
|
}
|
|
2259
2261
|
},
|
|
2260
|
-
[
|
|
2262
|
+
[n.STRING_TOUPPERCASE]: {
|
|
2261
2263
|
stackIn: 1,
|
|
2262
2264
|
stackOut: 1,
|
|
2263
2265
|
execute: (e2, t$1) => {
|
|
@@ -2272,7 +2274,7 @@ const ae = {
|
|
|
2272
2274
|
e2.stack.push(r2.toUpperCase());
|
|
2273
2275
|
}
|
|
2274
2276
|
},
|
|
2275
|
-
[
|
|
2277
|
+
[n.STRING_TOLOWERCASE]: {
|
|
2276
2278
|
stackIn: 1,
|
|
2277
2279
|
stackOut: 1,
|
|
2278
2280
|
execute: (e2, t$1) => {
|
|
@@ -2287,7 +2289,7 @@ const ae = {
|
|
|
2287
2289
|
e2.stack.push(r2.toLowerCase());
|
|
2288
2290
|
}
|
|
2289
2291
|
},
|
|
2290
|
-
[
|
|
2292
|
+
[n.TO_STRING]: {
|
|
2291
2293
|
stackIn: 1,
|
|
2292
2294
|
stackOut: 1,
|
|
2293
2295
|
execute: (e2, t2) => {
|
|
@@ -2303,7 +2305,7 @@ const ae = {
|
|
|
2303
2305
|
e2.stack.push(o2);
|
|
2304
2306
|
}
|
|
2305
2307
|
},
|
|
2306
|
-
[
|
|
2308
|
+
[n.STRING_INCLUDES]: {
|
|
2307
2309
|
stackIn: 2,
|
|
2308
2310
|
// string, searchString
|
|
2309
2311
|
stackOut: 1,
|
|
@@ -2321,7 +2323,7 @@ const ae = {
|
|
|
2321
2323
|
e2.stack.push(o2.includes(s2));
|
|
2322
2324
|
}
|
|
2323
2325
|
},
|
|
2324
|
-
[
|
|
2326
|
+
[n.STRING_ENDS_WITH]: {
|
|
2325
2327
|
stackIn: 2,
|
|
2326
2328
|
stackOut: 1,
|
|
2327
2329
|
execute: (e2, t$1) => {
|
|
@@ -2337,7 +2339,7 @@ const ae = {
|
|
|
2337
2339
|
e2.stack.push(o2.endsWith(s2));
|
|
2338
2340
|
}
|
|
2339
2341
|
},
|
|
2340
|
-
[
|
|
2342
|
+
[n.STRING_STARTS_WITH]: {
|
|
2341
2343
|
stackIn: 2,
|
|
2342
2344
|
stackOut: 1,
|
|
2343
2345
|
execute: (e2, t$1) => {
|
|
@@ -2353,7 +2355,7 @@ const ae = {
|
|
|
2353
2355
|
e2.stack.push(o2.startsWith(s2));
|
|
2354
2356
|
}
|
|
2355
2357
|
},
|
|
2356
|
-
[
|
|
2358
|
+
[n.STRING_TRIM]: {
|
|
2357
2359
|
stackIn: 1,
|
|
2358
2360
|
stackOut: 1,
|
|
2359
2361
|
execute: (e2, t$1) => {
|
|
@@ -2368,7 +2370,7 @@ const ae = {
|
|
|
2368
2370
|
e2.stack.push(r2.trim());
|
|
2369
2371
|
}
|
|
2370
2372
|
},
|
|
2371
|
-
[
|
|
2373
|
+
[n.STRING_TRIM_START]: {
|
|
2372
2374
|
stackIn: 1,
|
|
2373
2375
|
stackOut: 1,
|
|
2374
2376
|
execute: (e2, t$1) => {
|
|
@@ -2383,7 +2385,7 @@ const ae = {
|
|
|
2383
2385
|
e2.stack.push(r2.trimStart());
|
|
2384
2386
|
}
|
|
2385
2387
|
},
|
|
2386
|
-
[
|
|
2388
|
+
[n.STRING_TRIM_END]: {
|
|
2387
2389
|
stackIn: 1,
|
|
2388
2390
|
stackOut: 1,
|
|
2389
2391
|
execute: (e2, t$1) => {
|
|
@@ -2398,7 +2400,7 @@ const ae = {
|
|
|
2398
2400
|
e2.stack.push(r2.trimEnd());
|
|
2399
2401
|
}
|
|
2400
2402
|
},
|
|
2401
|
-
[
|
|
2403
|
+
[n.STRING_REPLACE]: {
|
|
2402
2404
|
stackIn: 3,
|
|
2403
2405
|
// string, search, replacement
|
|
2404
2406
|
stackOut: 1,
|
|
@@ -2411,11 +2413,11 @@ const ae = {
|
|
|
2411
2413
|
pc: e2.pc,
|
|
2412
2414
|
opcode: t$1.op
|
|
2413
2415
|
};
|
|
2414
|
-
const c2 = String(
|
|
2415
|
-
e2.stack.push(
|
|
2416
|
+
const c2 = String(r2), p2 = String(o2), a2 = s2.indexOf(p2), i2 = a2 === -1 ? s2 : s2.substring(0, a2) + c2 + s2.substring(a2 + p2.length);
|
|
2417
|
+
e2.stack.push(i2);
|
|
2416
2418
|
}
|
|
2417
2419
|
},
|
|
2418
|
-
[
|
|
2420
|
+
[n.STRING_REPLACE_ALL]: {
|
|
2419
2421
|
stackIn: 3,
|
|
2420
2422
|
stackOut: 1,
|
|
2421
2423
|
execute: (e2, t$1) => {
|
|
@@ -2431,7 +2433,7 @@ const ae = {
|
|
|
2431
2433
|
e2.stack.push(a2);
|
|
2432
2434
|
}
|
|
2433
2435
|
},
|
|
2434
|
-
[
|
|
2436
|
+
[n.STRING_LAST_INDEX_OF]: {
|
|
2435
2437
|
stackIn: 2,
|
|
2436
2438
|
stackOut: 1,
|
|
2437
2439
|
execute: (e2, t$1) => {
|
|
@@ -2447,7 +2449,7 @@ const ae = {
|
|
|
2447
2449
|
e2.stack.push(o2.lastIndexOf(s2));
|
|
2448
2450
|
}
|
|
2449
2451
|
},
|
|
2450
|
-
[
|
|
2452
|
+
[n.STRING_REPEAT]: {
|
|
2451
2453
|
stackIn: 2,
|
|
2452
2454
|
stackOut: 1,
|
|
2453
2455
|
execute: (e2, t$1) => {
|
|
@@ -2469,7 +2471,7 @@ const ae = {
|
|
|
2469
2471
|
e2.stack.push(o2.repeat(Math.floor(r2)));
|
|
2470
2472
|
}
|
|
2471
2473
|
},
|
|
2472
|
-
[
|
|
2474
|
+
[n.STRING_PAD_START]: {
|
|
2473
2475
|
stackIn: 3,
|
|
2474
2476
|
// string, targetLength, padString
|
|
2475
2477
|
stackOut: 1,
|
|
@@ -2493,7 +2495,7 @@ const ae = {
|
|
|
2493
2495
|
e2.stack.push(s2.padStart(o2, c2 || " "));
|
|
2494
2496
|
}
|
|
2495
2497
|
},
|
|
2496
|
-
[
|
|
2498
|
+
[n.STRING_PAD_END]: {
|
|
2497
2499
|
stackIn: 3,
|
|
2498
2500
|
stackOut: 1,
|
|
2499
2501
|
execute: (e2, t$1) => {
|
|
@@ -2544,7 +2546,7 @@ function A(e2, t2) {
|
|
|
2544
2546
|
return e2;
|
|
2545
2547
|
}
|
|
2546
2548
|
const le = {
|
|
2547
|
-
[
|
|
2549
|
+
[n.OBJECT_CREATE]: {
|
|
2548
2550
|
stackIn: 0,
|
|
2549
2551
|
stackOut: 1,
|
|
2550
2552
|
execute: (e2) => {
|
|
@@ -2552,7 +2554,7 @@ const le = {
|
|
|
2552
2554
|
e2.stack.push(r2);
|
|
2553
2555
|
}
|
|
2554
2556
|
},
|
|
2555
|
-
[
|
|
2557
|
+
[n.PROPERTY_SET]: {
|
|
2556
2558
|
stackIn: 3,
|
|
2557
2559
|
stackOut: 1,
|
|
2558
2560
|
execute: (e2, t2) => {
|
|
@@ -2586,7 +2588,7 @@ const le = {
|
|
|
2586
2588
|
c2.properties[p2] = r2, e2.stack.push(s2);
|
|
2587
2589
|
}
|
|
2588
2590
|
},
|
|
2589
|
-
[
|
|
2591
|
+
[n.PROPERTY_GET]: {
|
|
2590
2592
|
stackIn: 2,
|
|
2591
2593
|
stackOut: 1,
|
|
2592
2594
|
execute: (e2, t2) => {
|
|
@@ -2622,7 +2624,7 @@ const le = {
|
|
|
2622
2624
|
e2.stack.push(c$1 ?? C$1());
|
|
2623
2625
|
}
|
|
2624
2626
|
},
|
|
2625
|
-
[
|
|
2627
|
+
[n.JSON_STRINGIFY]: {
|
|
2626
2628
|
stackIn: 1,
|
|
2627
2629
|
stackOut: 1,
|
|
2628
2630
|
execute: (e2, t2) => {
|
|
@@ -2632,7 +2634,7 @@ const le = {
|
|
|
2632
2634
|
e2.stack.push(JSON.stringify(o2));
|
|
2633
2635
|
}
|
|
2634
2636
|
},
|
|
2635
|
-
[
|
|
2637
|
+
[n.OBJECT_KEYS]: {
|
|
2636
2638
|
stackIn: 1,
|
|
2637
2639
|
stackOut: 1,
|
|
2638
2640
|
execute: (e2, t2) => {
|
|
@@ -2653,7 +2655,7 @@ const le = {
|
|
|
2653
2655
|
}
|
|
2654
2656
|
}
|
|
2655
2657
|
}, de = {
|
|
2656
|
-
[
|
|
2658
|
+
[n.OBJECT_ITER_START]: {
|
|
2657
2659
|
stackIn: 1,
|
|
2658
2660
|
stackOut: 0,
|
|
2659
2661
|
execute: (e2, t2) => {
|
|
@@ -2693,7 +2695,7 @@ const le = {
|
|
|
2693
2695
|
});
|
|
2694
2696
|
}
|
|
2695
2697
|
},
|
|
2696
|
-
[
|
|
2698
|
+
[n.OBJECT_ITER_NEXT]: {
|
|
2697
2699
|
stackIn: 0,
|
|
2698
2700
|
stackOut: 2,
|
|
2699
2701
|
// Push key and hasNext
|
|
@@ -2707,7 +2709,7 @@ const le = {
|
|
|
2707
2709
|
}
|
|
2708
2710
|
}
|
|
2709
2711
|
}, fe = {
|
|
2710
|
-
[
|
|
2712
|
+
[n.GET]: {
|
|
2711
2713
|
stackIn: 2,
|
|
2712
2714
|
stackOut: 1,
|
|
2713
2715
|
execute: (e2, t$1) => {
|
|
@@ -2727,9 +2729,9 @@ const le = {
|
|
|
2727
2729
|
if (i$1(r2))
|
|
2728
2730
|
a2 = r2;
|
|
2729
2731
|
else if (t(r2)) {
|
|
2730
|
-
const
|
|
2731
|
-
if (!isNaN(
|
|
2732
|
-
a2 =
|
|
2732
|
+
const u2 = parseInt(r2, 10);
|
|
2733
|
+
if (!isNaN(u2) && u2.toString() === r2 && u2 >= 0)
|
|
2734
|
+
a2 = u2;
|
|
2733
2735
|
else {
|
|
2734
2736
|
const y2 = ((s2 = p2.properties) == null ? void 0 : s2[r2]) ?? C$1();
|
|
2735
2737
|
e2.stack.push(y2);
|
|
@@ -2742,8 +2744,8 @@ const le = {
|
|
|
2742
2744
|
pc: e2.pc,
|
|
2743
2745
|
opcode: t$1.op
|
|
2744
2746
|
};
|
|
2745
|
-
const
|
|
2746
|
-
e2.stack.push(
|
|
2747
|
+
const i2 = p2.elements[a2] ?? C$1();
|
|
2748
|
+
e2.stack.push(i2);
|
|
2747
2749
|
return;
|
|
2748
2750
|
} else if (b(o2)) {
|
|
2749
2751
|
const c2 = e2.heap.get(o2.id);
|
|
@@ -2754,8 +2756,8 @@ const le = {
|
|
|
2754
2756
|
pc: e2.pc,
|
|
2755
2757
|
opcode: t$1.op
|
|
2756
2758
|
};
|
|
2757
|
-
const p2 = c2.data, a2 = p$1(r2),
|
|
2758
|
-
e2.stack.push(
|
|
2759
|
+
const p2 = c2.data, a2 = p$1(r2), i2 = p2.properties[a2] ?? C$1();
|
|
2760
|
+
e2.stack.push(i2);
|
|
2759
2761
|
return;
|
|
2760
2762
|
} else if (t(o2)) {
|
|
2761
2763
|
let c2;
|
|
@@ -2776,7 +2778,7 @@ const le = {
|
|
|
2776
2778
|
};
|
|
2777
2779
|
}
|
|
2778
2780
|
},
|
|
2779
|
-
[
|
|
2781
|
+
[n.SET]: {
|
|
2780
2782
|
stackIn: 3,
|
|
2781
2783
|
stackOut: 1,
|
|
2782
2784
|
execute: (e2, t$1) => {
|
|
@@ -2795,9 +2797,9 @@ const le = {
|
|
|
2795
2797
|
if (i$1(o2))
|
|
2796
2798
|
a2 = o2;
|
|
2797
2799
|
else if (t(o2)) {
|
|
2798
|
-
const
|
|
2799
|
-
if (!isNaN(
|
|
2800
|
-
a2 =
|
|
2800
|
+
const u2 = parseInt(o2, 10);
|
|
2801
|
+
if (!isNaN(u2) && u2.toString() === o2 && u2 >= 0)
|
|
2802
|
+
a2 = u2;
|
|
2801
2803
|
else {
|
|
2802
2804
|
p2.properties || (p2.properties = {}), p2.properties[o2] = r2, e2.stack.push(s2);
|
|
2803
2805
|
return;
|
|
@@ -2809,15 +2811,15 @@ const le = {
|
|
|
2809
2811
|
pc: e2.pc,
|
|
2810
2812
|
opcode: t$1.op
|
|
2811
2813
|
};
|
|
2812
|
-
const
|
|
2813
|
-
if (
|
|
2814
|
+
const i2 = Math.floor(a2);
|
|
2815
|
+
if (i2 < 0)
|
|
2814
2816
|
return {
|
|
2815
2817
|
type: "RuntimeError",
|
|
2816
2818
|
message: "SET: Negative index not allowed",
|
|
2817
2819
|
pc: e2.pc,
|
|
2818
2820
|
opcode: t$1.op
|
|
2819
2821
|
};
|
|
2820
|
-
p2.elements[
|
|
2822
|
+
p2.elements[i2] = r2, e2.stack.push(s2);
|
|
2821
2823
|
return;
|
|
2822
2824
|
} else if (b(s2)) {
|
|
2823
2825
|
const c2 = e2.heap.get(s2.id);
|
|
@@ -2917,8 +2919,8 @@ const le = {
|
|
|
2917
2919
|
pc: e2.pc,
|
|
2918
2920
|
opcode: t2.op
|
|
2919
2921
|
};
|
|
2920
|
-
const
|
|
2921
|
-
e2.stack.push(
|
|
2922
|
+
const u2 = new RegExp(p2, a2).test(r2);
|
|
2923
|
+
e2.stack.push(u2);
|
|
2922
2924
|
return;
|
|
2923
2925
|
} catch (c2) {
|
|
2924
2926
|
return {
|
|
@@ -2970,13 +2972,13 @@ const le = {
|
|
|
2970
2972
|
pc: e2.pc,
|
|
2971
2973
|
opcode: t2.op
|
|
2972
2974
|
};
|
|
2973
|
-
const
|
|
2974
|
-
if (
|
|
2975
|
+
const i2 = new RegExp(p2, a2), u2 = o2.match(i2);
|
|
2976
|
+
if (u2 === null)
|
|
2975
2977
|
e2.stack.push(null);
|
|
2976
2978
|
else {
|
|
2977
2979
|
const y2 = {
|
|
2978
2980
|
type: "array",
|
|
2979
|
-
elements: [...
|
|
2981
|
+
elements: [...u2]
|
|
2980
2982
|
// Copy all match results
|
|
2981
2983
|
}, E2 = e2.heap.allocate("array", y2);
|
|
2982
2984
|
e2.stack.push(E2);
|
|
@@ -3010,13 +3012,11 @@ const le = {
|
|
|
3010
3012
|
pc: e2.pc,
|
|
3011
3013
|
opcode: t2.op
|
|
3012
3014
|
};
|
|
3013
|
-
if (!b(o2))
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
opcode: t2.op
|
|
3019
|
-
};
|
|
3015
|
+
if (!b(o2)) {
|
|
3016
|
+
const p2 = String(o2), a2 = String(r2), i2 = s2.indexOf(p2), u2 = i2 === -1 ? s2 : s2.substring(0, i2) + a2 + s2.substring(i2 + p2.length);
|
|
3017
|
+
e2.stack.push(u2);
|
|
3018
|
+
return;
|
|
3019
|
+
}
|
|
3020
3020
|
if (typeof r2 != "string")
|
|
3021
3021
|
return {
|
|
3022
3022
|
type: "TypeError",
|
|
@@ -3033,15 +3033,15 @@ const le = {
|
|
|
3033
3033
|
opcode: t2.op
|
|
3034
3034
|
};
|
|
3035
3035
|
try {
|
|
3036
|
-
const p2 = c2.data, a2 = p2.properties.source,
|
|
3037
|
-
if (typeof a2 != "string" || typeof
|
|
3036
|
+
const p2 = c2.data, a2 = p2.properties.source, i2 = p2.properties.flags;
|
|
3037
|
+
if (typeof a2 != "string" || typeof i2 != "string")
|
|
3038
3038
|
return {
|
|
3039
3039
|
type: "TypeError",
|
|
3040
3040
|
message: "Invalid regex object structure",
|
|
3041
3041
|
pc: e2.pc,
|
|
3042
3042
|
opcode: t2.op
|
|
3043
3043
|
};
|
|
3044
|
-
const
|
|
3044
|
+
const u2 = new RegExp(a2, i2), y2 = s2.replace(u2, r2);
|
|
3045
3045
|
e2.stack.push(y2);
|
|
3046
3046
|
return;
|
|
3047
3047
|
} catch (p2) {
|
|
@@ -3054,10 +3054,10 @@ const le = {
|
|
|
3054
3054
|
}
|
|
3055
3055
|
}
|
|
3056
3056
|
}, he = {
|
|
3057
|
-
[
|
|
3058
|
-
[
|
|
3059
|
-
[
|
|
3060
|
-
[
|
|
3057
|
+
[n.LOAD_REGEX]: ge,
|
|
3058
|
+
[n.REGEX_TEST]: me,
|
|
3059
|
+
[n.STRING_MATCH]: ke,
|
|
3060
|
+
[n.STRING_REPLACE_REGEX]: ye
|
|
3061
3061
|
}, F = {
|
|
3062
3062
|
...Z,
|
|
3063
3063
|
...ee,
|
|
@@ -3069,21 +3069,19 @@ const le = {
|
|
|
3069
3069
|
...ne,
|
|
3070
3070
|
...pe,
|
|
3071
3071
|
...ae,
|
|
3072
|
-
...ue,
|
|
3073
3072
|
...ie,
|
|
3073
|
+
...ue,
|
|
3074
3074
|
...le,
|
|
3075
3075
|
...de,
|
|
3076
3076
|
...fe,
|
|
3077
3077
|
...he
|
|
3078
3078
|
};
|
|
3079
3079
|
function w() {
|
|
3080
|
-
const e2 = /* @__PURE__ */ new Map()
|
|
3081
|
-
let t2 = 1;
|
|
3082
|
-
return {
|
|
3080
|
+
const e2 = /* @__PURE__ */ new Map(), t2 = {
|
|
3083
3081
|
objects: e2,
|
|
3084
|
-
nextId:
|
|
3082
|
+
nextId: 1,
|
|
3085
3083
|
allocate(r2, o2) {
|
|
3086
|
-
const s2 = t2++, c2 = { id: s2, type: r2, data: o2 };
|
|
3084
|
+
const s2 = t2.nextId++, c2 = { id: s2, type: r2, data: o2 };
|
|
3087
3085
|
return e2.set(s2, c2), r2 === "array" ? { type: "array-ref", id: s2 } : { type: "object-ref", id: s2 };
|
|
3088
3086
|
},
|
|
3089
3087
|
get(r2) {
|
|
@@ -3092,6 +3090,7 @@ function w() {
|
|
|
3092
3090
|
return o2;
|
|
3093
3091
|
}
|
|
3094
3092
|
};
|
|
3093
|
+
return t2;
|
|
3095
3094
|
}
|
|
3096
3095
|
class C {
|
|
3097
3096
|
createInitialState() {
|
|
@@ -3120,7 +3119,7 @@ class C {
|
|
|
3120
3119
|
if (o2.stack.length < t2.stackIn)
|
|
3121
3120
|
return {
|
|
3122
3121
|
type: "StackUnderflow",
|
|
3123
|
-
message: `${
|
|
3122
|
+
message: `${n[r2.op]}: Stack underflow`,
|
|
3124
3123
|
pc: o2.pc,
|
|
3125
3124
|
opcode: r2.op
|
|
3126
3125
|
};
|
|
@@ -3145,26 +3144,26 @@ class C {
|
|
|
3145
3144
|
s2.status = "error", s2.error = a2.message;
|
|
3146
3145
|
break;
|
|
3147
3146
|
}
|
|
3148
|
-
if ((c2.op ===
|
|
3147
|
+
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) {
|
|
3149
3148
|
s2.status = "error";
|
|
3150
|
-
const
|
|
3151
|
-
s2.error = `Invalid ${
|
|
3149
|
+
const u2 = 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";
|
|
3150
|
+
s2.error = `Invalid ${u2} target: ${c2.arg}`;
|
|
3152
3151
|
break;
|
|
3153
3152
|
}
|
|
3154
|
-
const
|
|
3155
|
-
if (
|
|
3156
|
-
const
|
|
3157
|
-
if (
|
|
3158
|
-
s2.ccPrompt = `ERROR: ${
|
|
3153
|
+
const i2 = p2.execute(s2, c2);
|
|
3154
|
+
if (i2) {
|
|
3155
|
+
const u2 = s2.pc + 1;
|
|
3156
|
+
if (u2 < t2.length && t2[u2].op === n.CC) {
|
|
3157
|
+
s2.ccPrompt = `ERROR: ${i2.message}. How should I proceed?`, s2.status = "waiting_cc", s2.pc = u2;
|
|
3159
3158
|
break;
|
|
3160
3159
|
}
|
|
3161
|
-
s2.status = "error", s2.error =
|
|
3160
|
+
s2.status = "error", s2.error = i2.message;
|
|
3162
3161
|
break;
|
|
3163
3162
|
}
|
|
3164
3163
|
p2.controlsPC || s2.pc++;
|
|
3165
3164
|
continue;
|
|
3166
3165
|
}
|
|
3167
|
-
s2.status = "error", s2.error = `Unknown opcode: ${
|
|
3166
|
+
s2.status = "error", s2.error = `Unknown opcode: ${n[c2.op]}`;
|
|
3168
3167
|
break;
|
|
3169
3168
|
}
|
|
3170
3169
|
return s2;
|
|
@@ -3218,8 +3217,8 @@ class V {
|
|
|
3218
3217
|
try {
|
|
3219
3218
|
const p2 = b__namespace.readdirSync(r2, { withFileTypes: true });
|
|
3220
3219
|
for (const a2 of p2) {
|
|
3221
|
-
const
|
|
3222
|
-
a2.isSymbolicLink() || s2.filter && !this.matchesPattern(
|
|
3220
|
+
const i2 = r__namespace.join(r2, a2.name), u2 = r__namespace.relative(t2, i2);
|
|
3221
|
+
a2.isSymbolicLink() || s2.filter && !this.matchesPattern(u2, s2.filter) || (o2.push(i2), a2.isDirectory() && s2.recursive && this.listFilesRecursive(t2, i2, o2, s2, c2 + 1));
|
|
3223
3222
|
}
|
|
3224
3223
|
} catch {
|
|
3225
3224
|
}
|
|
@@ -3279,8 +3278,12 @@ class Se {
|
|
|
3279
3278
|
*/
|
|
3280
3279
|
async loadProgram(t2, r2) {
|
|
3281
3280
|
const o2 = te$1(r2);
|
|
3282
|
-
if (!o2.success)
|
|
3283
|
-
|
|
3281
|
+
if (!o2.success) {
|
|
3282
|
+
const c2 = o2.errors.map(
|
|
3283
|
+
(p2) => `${p2.message} at line ${p2.line}, column ${p2.character}`
|
|
3284
|
+
);
|
|
3285
|
+
throw new Error(`Compilation failed: ${c2.join("; ")}`);
|
|
3286
|
+
}
|
|
3284
3287
|
const s2 = {
|
|
3285
3288
|
id: t2,
|
|
3286
3289
|
name: t2,
|
|
@@ -3386,8 +3389,8 @@ class Se {
|
|
|
3386
3389
|
ccPrompt: void 0
|
|
3387
3390
|
}, a2 = c2.resume(p2, r2, s2.bytecode, this.fileSystem);
|
|
3388
3391
|
a2.output.length > 0 && await this.storage.appendOutput(t2, a2.output);
|
|
3389
|
-
const
|
|
3390
|
-
Object.assign(o2,
|
|
3392
|
+
const i2 = this.serializeVMState(a2);
|
|
3393
|
+
Object.assign(o2, i2), a2.status === "complete" ? (o2.state = "COMPLETED", a2.returnValue !== void 0 && (o2.returnValue = a2.returnValue), this.vms.delete(t2)) : a2.status === "error" ? (o2.state = "ERROR", o2.error = a2.error, this.vms.delete(t2)) : a2.status === "waiting_cc" ? (o2.state = "AWAITING_COGNITIVE_RESULT", o2.ccPrompt = a2.ccPrompt) : o2.state = "RUNNING", await this.storage.saveExecution(o2);
|
|
3391
3394
|
}
|
|
3392
3395
|
/**
|
|
3393
3396
|
* Get current execution status
|
|
@@ -3594,19 +3597,19 @@ class $ {
|
|
|
3594
3597
|
},
|
|
3595
3598
|
async ({ programId: e2, filePath: r$1 }) => {
|
|
3596
3599
|
try {
|
|
3597
|
-
const t2 = r.resolve(r$1),
|
|
3598
|
-
return await this.vmManager.loadProgram(e2,
|
|
3600
|
+
const t2 = r.resolve(r$1), n2 = await promises.readFile(t2, "utf-8");
|
|
3601
|
+
return await this.vmManager.loadProgram(e2, n2), {
|
|
3599
3602
|
content: [{ type: "text", text: `Program loaded successfully from ${r$1}: ${e2}` }]
|
|
3600
3603
|
};
|
|
3601
3604
|
} catch (t2) {
|
|
3602
3605
|
if (t2 instanceof Error) {
|
|
3603
|
-
const
|
|
3604
|
-
if (
|
|
3606
|
+
const n2 = t2;
|
|
3607
|
+
if (n2.code === "ENOENT")
|
|
3605
3608
|
return {
|
|
3606
3609
|
content: [{ type: "text", text: `Error: File not found: ${r$1}` }],
|
|
3607
3610
|
isError: true
|
|
3608
3611
|
};
|
|
3609
|
-
if (
|
|
3612
|
+
if (n2.code === "EACCES")
|
|
3610
3613
|
return {
|
|
3611
3614
|
content: [{ type: "text", text: `Error: Permission denied: ${r$1}` }],
|
|
3612
3615
|
isError: true
|
|
@@ -3630,9 +3633,9 @@ class $ {
|
|
|
3630
3633
|
return await this.vmManager.startExecution(e2, r2), t2 && await this.vmManager.setCurrentExecutionId(r2), {
|
|
3631
3634
|
content: [{ type: "text", text: `Execution started: ${r2}${t2 ? " (set as current)" : ""}` }]
|
|
3632
3635
|
};
|
|
3633
|
-
} catch (
|
|
3636
|
+
} catch (n2) {
|
|
3634
3637
|
return {
|
|
3635
|
-
content: [{ type: "text", text: `Error: ${
|
|
3638
|
+
content: [{ type: "text", text: `Error: ${n2 instanceof Error ? n2.message : "Unknown error"}` }],
|
|
3636
3639
|
isError: true
|
|
3637
3640
|
};
|
|
3638
3641
|
}
|
|
@@ -3646,12 +3649,12 @@ class $ {
|
|
|
3646
3649
|
try {
|
|
3647
3650
|
let r2 = e2;
|
|
3648
3651
|
if (!r2) {
|
|
3649
|
-
const
|
|
3650
|
-
if (!
|
|
3652
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
3653
|
+
if (!n2)
|
|
3651
3654
|
return {
|
|
3652
3655
|
content: [{ type: "text", text: "No current execution set. Use list_executions to see available executions." }]
|
|
3653
3656
|
};
|
|
3654
|
-
r2 =
|
|
3657
|
+
r2 = n2;
|
|
3655
3658
|
}
|
|
3656
3659
|
const t2 = await this.vmManager.getNext(r2);
|
|
3657
3660
|
return t2.type === "completed" ? {
|
|
@@ -3682,13 +3685,13 @@ class $ {
|
|
|
3682
3685
|
try {
|
|
3683
3686
|
let t2 = e2;
|
|
3684
3687
|
if (!t2) {
|
|
3685
|
-
const
|
|
3686
|
-
if (!
|
|
3688
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
3689
|
+
if (!n2)
|
|
3687
3690
|
return {
|
|
3688
3691
|
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
3689
3692
|
isError: true
|
|
3690
3693
|
};
|
|
3691
|
-
t2 =
|
|
3694
|
+
t2 = n2;
|
|
3692
3695
|
}
|
|
3693
3696
|
return await this.vmManager.reportCCResult(t2, r2), {
|
|
3694
3697
|
content: [{ type: "text", text: "Execution resumed" }]
|
|
@@ -3709,13 +3712,13 @@ class $ {
|
|
|
3709
3712
|
try {
|
|
3710
3713
|
let r2 = e2;
|
|
3711
3714
|
if (!r2) {
|
|
3712
|
-
const
|
|
3713
|
-
if (!
|
|
3715
|
+
const n2 = await this.vmManager.getCurrentExecutionId();
|
|
3716
|
+
if (!n2)
|
|
3714
3717
|
return {
|
|
3715
3718
|
content: [{ type: "text", text: "Error: No current execution set" }],
|
|
3716
3719
|
isError: true
|
|
3717
3720
|
};
|
|
3718
|
-
r2 =
|
|
3721
|
+
r2 = n2;
|
|
3719
3722
|
}
|
|
3720
3723
|
const t2 = await this.vmManager.getExecutionStatus(r2);
|
|
3721
3724
|
return {
|
|
@@ -3733,14 +3736,14 @@ class $ {
|
|
|
3733
3736
|
{},
|
|
3734
3737
|
async () => {
|
|
3735
3738
|
try {
|
|
3736
|
-
const e2 = await this.vmManager.listExecutions(), r2 = await this.vmManager.getCurrentExecutionId(), t2 = e2.map((
|
|
3737
|
-
executionId:
|
|
3738
|
-
programId:
|
|
3739
|
-
state:
|
|
3740
|
-
created:
|
|
3741
|
-
isCurrent:
|
|
3739
|
+
const e2 = await this.vmManager.listExecutions(), r2 = await this.vmManager.getCurrentExecutionId(), t2 = e2.map((n2) => ({
|
|
3740
|
+
executionId: n2.id,
|
|
3741
|
+
programId: n2.programId,
|
|
3742
|
+
state: n2.state,
|
|
3743
|
+
created: n2.created,
|
|
3744
|
+
isCurrent: n2.id === r2,
|
|
3742
3745
|
summary: {
|
|
3743
|
-
currentPrompt:
|
|
3746
|
+
currentPrompt: n2.state === "AWAITING_COGNITIVE_RESULT" ? n2.ccPrompt : void 0,
|
|
3744
3747
|
tasksCompleted: 0
|
|
3745
3748
|
// TODO: Track this in future
|
|
3746
3749
|
}
|
|
@@ -3772,12 +3775,12 @@ class $ {
|
|
|
3772
3775
|
};
|
|
3773
3776
|
r2 = a2;
|
|
3774
3777
|
}
|
|
3775
|
-
const t2 = await this.vmManager.getExecutionWithAttempts(r2),
|
|
3778
|
+
const t2 = await this.vmManager.getExecutionWithAttempts(r2), n2 = await this.vmManager.getCurrentExecutionId(), c2 = {
|
|
3776
3779
|
executionId: t2.id,
|
|
3777
3780
|
programId: t2.programId,
|
|
3778
3781
|
state: t2.state,
|
|
3779
3782
|
created: t2.created,
|
|
3780
|
-
isCurrent: t2.id ===
|
|
3783
|
+
isCurrent: t2.id === n2,
|
|
3781
3784
|
currentTask: t2.state === "AWAITING_COGNITIVE_RESULT" ? {
|
|
3782
3785
|
prompt: t2.ccPrompt,
|
|
3783
3786
|
attempts: t2.attempts || 1,
|