vladx 1.3.0 → 1.5.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/bin/vladpm.js CHANGED
@@ -56,7 +56,7 @@ class VladPM {
56
56
  const packageFile = join(process.cwd(), 'vladx.json');
57
57
 
58
58
  if (existsSync(packageFile)) {
59
- this.logger.info('vladvx.json уже существует');
59
+ this.logger.info('vladx.json уже существует');
60
60
  return;
61
61
  }
62
62
 
@@ -112,7 +112,7 @@ class VladPM {
112
112
  const packageFile = join(process.cwd(), 'vladx.json');
113
113
 
114
114
  if (!existsSync(packageFile)) {
115
- throw new Error('vladvx.json не найден. Запустите "vladpm init"');
115
+ throw new Error('vladx.json не найден. Запустите "vladpm init"');
116
116
  }
117
117
 
118
118
  const packageJson = JSON.parse(readFileSync(packageFile, 'utf-8'));
@@ -174,10 +174,10 @@ class VladPM {
174
174
  * Удалить локально
175
175
  */
176
176
  uninstallLocal(packageName, isDev = false) {
177
- const packageFile = join(process.cwd(), 'vladvx.json');
177
+ const packageFile = join(process.cwd(), 'vladx.json');
178
178
 
179
179
  if (!existsSync(packageFile)) {
180
- throw new Error('vladvx.json не найден');
180
+ throw new Error('vladx.json не найден');
181
181
  }
182
182
 
183
183
  const packageJson = JSON.parse(readFileSync(packageFile, 'utf-8'));
@@ -332,10 +332,10 @@ class VladPM {
332
332
  * Список локальных пакетов
333
333
  */
334
334
  listLocal() {
335
- const packageFile = join(process.cwd(), 'vladvx.json');
335
+ const packageFile = join(process.cwd(), 'vladx.json');
336
336
 
337
337
  if (!existsSync(packageFile)) {
338
- this.logger.info('vladvx.json не найден');
338
+ this.logger.info('vladx.json не найден');
339
339
  return;
340
340
  }
341
341
 
@@ -399,10 +399,10 @@ class VladPM {
399
399
  * Публикация пакета
400
400
  */
401
401
  async publish(options = {}) {
402
- const packageFile = join(process.cwd(), 'vladvx.json');
402
+ const packageFile = join(process.cwd(), 'vladx.json');
403
403
 
404
404
  if (!existsSync(packageFile)) {
405
- throw new Error('vladvx.json не найден');
405
+ throw new Error('vladx.json не найден');
406
406
  }
407
407
 
408
408
  const packageJson = JSON.parse(readFileSync(packageFile, 'utf-8'));
package/bin/vladx.js CHANGED
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vladx",
3
- "version": "1.3.0",
3
+ "version": "1.5.0",
4
4
  "description": "Мощный интерпретируемый язык программирования с русским синтаксисом",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -676,6 +676,18 @@ export class VladXEngine {
676
676
  this.interpreter.builtins.set('можетБыть', Functional.Maybe);
677
677
  this.interpreter.builtins.set('илиИначе', (maybe, defaultValue) => maybe.getOrElse(defaultValue));
678
678
 
679
+ // Класс Error
680
+ const errorMethods = new Map();
681
+ errorMethods.set('constructor', function(message) {
682
+ const msg = message && message.value !== undefined ? message.value : message;
683
+ this.value = msg || '';
684
+ });
685
+ errorMethods.set('toString', function() {
686
+ return VladXObject.string(this.value);
687
+ });
688
+ this.interpreter.globalEnv.define('Ошибка', VladXObject.class('Ошибка', errorMethods), true);
689
+ this.interpreter.globalEnv.define('Error', VladXObject.class('Error', errorMethods), true);
690
+
679
691
  // Структуры данных
680
692
  this.interpreter.builtins.set('Стек', () => new DataStructures.Stack());
681
693
  this.interpreter.builtins.set('Очередь', () => new DataStructures.Queue());
@@ -36,6 +36,7 @@ export class Interpreter {
36
36
  this.asyncManager = new AsyncManager(options.async);
37
37
  this.currentFilename = '<unknown>';
38
38
  this.currentLine = 0;
39
+ this.callStack = [];
39
40
 
40
41
  this.registerBuiltins();
41
42
  }
@@ -623,6 +624,8 @@ export class Interpreter {
623
624
  }
624
625
  }
625
626
 
627
+ // Специальная обработка для класса Error
628
+ const isErrorClass = callee.name === 'Ошибка' || callee.name === 'Error';
626
629
  const instance = VladXObject.instance(callee);
627
630
 
628
631
  const args = [];
@@ -637,6 +640,10 @@ export class Interpreter {
637
640
  this.currentInstance = instance;
638
641
  try {
639
642
  await this.executeFunction(constructorMethod, args);
643
+ // Для класса Error, если это первый аргумент - строка, используем её как значение экземпляра
644
+ if (isErrorClass && args[0] && args[0].type === 'string') {
645
+ instance.value = args[0].value;
646
+ }
640
647
  } finally {
641
648
  this.currentInstance = previousInstance;
642
649
  }
@@ -1738,6 +1745,12 @@ export class Interpreter {
1738
1745
  async evaluateThrowStatement(stmt) {
1739
1746
  const value = await this.evaluateExpression(stmt.argument);
1740
1747
  const val = value && value.value !== undefined ? value.value : value;
1748
+
1749
+ // Если это экземпляр класса Error или Error, используем его сообщение
1750
+ if (value && (value.type === 'instance' || value.type === 'error') && value.value !== undefined) {
1751
+ throw new Error(value.value);
1752
+ }
1753
+
1741
1754
  throw new Error(String(val));
1742
1755
  }
1743
1756
 
@@ -355,6 +355,7 @@ export class Lexer {
355
355
  'наконец': 'FINALLY',
356
356
  'throw': 'THROW',
357
357
  'бросить': 'THROW',
358
+ 'выбросить': 'THROW',
358
359
  'break': 'BREAK',
359
360
  'прервать': 'BREAK',
360
361
  'continue': 'CONTINUE',