vladx 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -235
- package/bin/vladx.js +5 -10
- package/package.json +1 -1
- package/src/engine/vladx-engine.js +2 -0
- package/src/index-standalone.js +1326 -0
- package/src/interpreter/interpreter.js +27 -65
- package/src/runtime/logging.js +2 -1
|
@@ -90,6 +90,17 @@ export class Interpreter {
|
|
|
90
90
|
|
|
91
91
|
return result;
|
|
92
92
|
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Запуск выполнения
|
|
96
|
+
*/
|
|
97
|
+
startExecution() {
|
|
98
|
+
if (this.maxExecutionTime > 0 && !this.executionTimer) {
|
|
99
|
+
this.executionTimer = setTimeout(() => {
|
|
100
|
+
this.stopExecution();
|
|
101
|
+
throw new Error(`Превышено максимальное время выполнения (${this.maxExecutionTime}мс)`);
|
|
102
|
+
}, this.maxExecutionTime);
|
|
103
|
+
}
|
|
93
104
|
}
|
|
94
105
|
|
|
95
106
|
/**
|
|
@@ -113,7 +124,7 @@ export class Interpreter {
|
|
|
113
124
|
const callee = await this.evaluateExpression(expr.callee);
|
|
114
125
|
const args = [];
|
|
115
126
|
|
|
116
|
-
for (const arg of expr.args) {
|
|
127
|
+
for (const arg of expr.args || []) {
|
|
117
128
|
if (arg && arg.type === 'SpreadElement') {
|
|
118
129
|
const spreadValue = await this.evaluateExpression(arg.argument);
|
|
119
130
|
const spreadArray = spreadValue && spreadValue.value ? spreadValue.value : [];
|
|
@@ -203,8 +214,9 @@ export class Interpreter {
|
|
|
203
214
|
try {
|
|
204
215
|
this.currentEnv = closureEnv;
|
|
205
216
|
|
|
206
|
-
|
|
207
|
-
|
|
217
|
+
const params = callee.params || [];
|
|
218
|
+
for (let i = 0; i < params.length; i++) {
|
|
219
|
+
const paramName = params[i]?.name || `arg${i}`;
|
|
208
220
|
this.currentEnv.define(paramName, VladXObject.fromJS(args[i]));
|
|
209
221
|
}
|
|
210
222
|
|
|
@@ -254,7 +266,6 @@ export class Interpreter {
|
|
|
254
266
|
async evaluateStatementDebug(stmt) {
|
|
255
267
|
return await this.evaluateStatement(stmt);
|
|
256
268
|
}
|
|
257
|
-
}
|
|
258
269
|
|
|
259
270
|
/**
|
|
260
271
|
* Интерпретация AST
|
|
@@ -330,14 +341,24 @@ export class Interpreter {
|
|
|
330
341
|
if (this.builtinsRegistered) {
|
|
331
342
|
return; // Уже зарегистрировано
|
|
332
343
|
}
|
|
333
|
-
|
|
344
|
+
|
|
334
345
|
for (const [name, fn] of this.builtins) {
|
|
335
346
|
this.globalEnv.define(name, VladXObject.function(fn, name), true);
|
|
336
347
|
}
|
|
337
|
-
|
|
348
|
+
|
|
338
349
|
this.builtinsRegistered = true;
|
|
339
350
|
}
|
|
340
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Обновить окружение с текущими встроенными функциями
|
|
354
|
+
*/
|
|
355
|
+
refreshBuiltins() {
|
|
356
|
+
// Register all built-ins in the global environment
|
|
357
|
+
for (const [name, fn] of this.builtins) {
|
|
358
|
+
this.globalEnv.define(name, VladXObject.function(fn, name), true);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
341
362
|
/**
|
|
342
363
|
* Выполнение программы
|
|
343
364
|
*/
|
|
@@ -1968,65 +1989,6 @@ export class Interpreter {
|
|
|
1968
1989
|
}
|
|
1969
1990
|
}
|
|
1970
1991
|
|
|
1971
|
-
// Evaluate cases
|
|
1972
|
-
for (const caseStmt of stmt.cases) {
|
|
1973
|
-
if (!matched) {
|
|
1974
|
-
const caseValue = await this.evaluateExpression(caseStmt.test);
|
|
1975
|
-
const caseValueValue = caseValue && caseValue.value !== undefined ? caseValue.value : caseValue;
|
|
1976
|
-
|
|
1977
|
-
// Strict equality comparison
|
|
1978
|
-
if (caseValueValue === discriminantValue) {
|
|
1979
|
-
matched = true;
|
|
1980
|
-
}
|
|
1981
|
-
}
|
|
1982
|
-
|
|
1983
|
-
if (matched) {
|
|
1984
|
-
// Execute case body
|
|
1985
|
-
for (const statement of caseStmt.consequent) {
|
|
1986
|
-
try {
|
|
1987
|
-
result = await this.evaluateStatement(statement);
|
|
1988
|
-
|
|
1989
|
-
// If we encounter a return, exit the switch
|
|
1990
|
-
if (this.isReturn) {
|
|
1991
|
-
return result;
|
|
1992
|
-
}
|
|
1993
|
-
} catch (e) {
|
|
1994
|
-
// If it's a break statement, exit the entire switch
|
|
1995
|
-
if (e.message === 'break') {
|
|
1996
|
-
return result; // Exit the entire switch
|
|
1997
|
-
} else {
|
|
1998
|
-
// Re-throw other errors
|
|
1999
|
-
throw e;
|
|
2000
|
-
}
|
|
2001
|
-
}
|
|
2002
|
-
}
|
|
2003
|
-
}
|
|
2004
|
-
}
|
|
2005
|
-
|
|
2006
|
-
// If no case matched and there's a default case
|
|
2007
|
-
if (!matched && stmt.defaultCase) {
|
|
2008
|
-
for (const statement of stmt.defaultCase.consequent) {
|
|
2009
|
-
try {
|
|
2010
|
-
result = await this.evaluateStatement(statement);
|
|
2011
|
-
|
|
2012
|
-
// If we encounter a return, exit the switch
|
|
2013
|
-
if (this.isReturn) {
|
|
2014
|
-
return result;
|
|
2015
|
-
}
|
|
2016
|
-
} catch (e) {
|
|
2017
|
-
// If it's a break statement, exit the entire switch
|
|
2018
|
-
if (e.message === 'break') {
|
|
2019
|
-
return result; // Exit the entire switch
|
|
2020
|
-
} else {
|
|
2021
|
-
// Re-throw other errors
|
|
2022
|
-
throw e;
|
|
2023
|
-
}
|
|
2024
|
-
}
|
|
2025
|
-
}
|
|
2026
|
-
}
|
|
2027
|
-
|
|
2028
|
-
return result;
|
|
2029
|
-
}
|
|
2030
1992
|
|
|
2031
1993
|
/**
|
|
2032
1994
|
* Вычисление выражения (обёртка)
|
package/src/runtime/logging.js
CHANGED