vladx 1.0.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.
Files changed (42) hide show
  1. package/README.md +256 -0
  2. package/bin/cli.js +486 -0
  3. package/bin/vlad.js +539 -0
  4. package/bin/vladpm.js +710 -0
  5. package/bin/vladx.js +491 -0
  6. package/package.json +57 -0
  7. package/src/engine/jit-compiler.js +285 -0
  8. package/src/engine/vladx-engine.js +941 -0
  9. package/src/index.js +44 -0
  10. package/src/interpreter/interpreter.js +2114 -0
  11. package/src/lexer/lexer.js +658 -0
  12. package/src/lexer/optimized-lexer.js +106 -0
  13. package/src/lexer/regex-cache.js +83 -0
  14. package/src/parser/ast-nodes.js +472 -0
  15. package/src/parser/parser.js +1408 -0
  16. package/src/runtime/advanced-type-system.js +209 -0
  17. package/src/runtime/async-manager.js +252 -0
  18. package/src/runtime/builtins.js +143 -0
  19. package/src/runtime/bundler.js +422 -0
  20. package/src/runtime/cache-manager.js +126 -0
  21. package/src/runtime/data-structures.js +612 -0
  22. package/src/runtime/debugger.js +260 -0
  23. package/src/runtime/enhanced-module-system.js +196 -0
  24. package/src/runtime/environment-enhanced.js +272 -0
  25. package/src/runtime/environment.js +140 -0
  26. package/src/runtime/event-emitter.js +232 -0
  27. package/src/runtime/formatter.js +280 -0
  28. package/src/runtime/functional.js +359 -0
  29. package/src/runtime/io-operations.js +390 -0
  30. package/src/runtime/linter.js +374 -0
  31. package/src/runtime/logging.js +314 -0
  32. package/src/runtime/minifier.js +242 -0
  33. package/src/runtime/module-system.js +377 -0
  34. package/src/runtime/network-operations.js +373 -0
  35. package/src/runtime/profiler.js +295 -0
  36. package/src/runtime/repl.js +336 -0
  37. package/src/runtime/security-manager.js +244 -0
  38. package/src/runtime/source-map-generator.js +208 -0
  39. package/src/runtime/test-runner.js +394 -0
  40. package/src/runtime/transformer.js +277 -0
  41. package/src/runtime/type-system.js +244 -0
  42. package/src/runtime/vladx-object.js +250 -0
@@ -0,0 +1,612 @@
1
+ /**
2
+ * DataStructures — Структуры данных
3
+ */
4
+
5
+ import { VladXObject } from './vladx-object.js';
6
+
7
+ export class Stack {
8
+ constructor() {
9
+ this.items = [];
10
+ }
11
+
12
+ push(item) {
13
+ this.items.push(item);
14
+ }
15
+
16
+ pop() {
17
+ if (this.items.length === 0) {
18
+ throw new Error('Стек пуст');
19
+ }
20
+ return this.items.pop();
21
+ }
22
+
23
+ peek() {
24
+ if (this.items.length === 0) {
25
+ return null;
26
+ }
27
+ return this.items[this.items.length - 1];
28
+ }
29
+
30
+ isEmpty() {
31
+ return this.items.length === 0;
32
+ }
33
+
34
+ size() {
35
+ return this.items.length;
36
+ }
37
+
38
+ clear() {
39
+ this.items = [];
40
+ }
41
+
42
+ toArray() {
43
+ return [...this.items];
44
+ }
45
+ }
46
+
47
+ export class Queue {
48
+ constructor() {
49
+ this.items = [];
50
+ }
51
+
52
+ enqueue(item) {
53
+ this.items.push(item);
54
+ }
55
+
56
+ dequeue() {
57
+ if (this.items.length === 0) {
58
+ throw new Error('Очередь пуста');
59
+ }
60
+ return this.items.shift();
61
+ }
62
+
63
+ peek() {
64
+ if (this.items.length === 0) {
65
+ return null;
66
+ }
67
+ return this.items[0];
68
+ }
69
+
70
+ isEmpty() {
71
+ return this.items.length === 0;
72
+ }
73
+
74
+ size() {
75
+ return this.items.length;
76
+ }
77
+
78
+ clear() {
79
+ this.items = [];
80
+ }
81
+
82
+ toArray() {
83
+ return [...this.items];
84
+ }
85
+ }
86
+
87
+ export class LinkedList {
88
+ constructor() {
89
+ this.head = null;
90
+ this.tail = null;
91
+ this.size = 0;
92
+ }
93
+
94
+ append(value) {
95
+ const node = { value, next: null };
96
+
97
+ if (!this.head) {
98
+ this.head = node;
99
+ this.tail = node;
100
+ } else {
101
+ this.tail.next = node;
102
+ this.tail = node;
103
+ }
104
+
105
+ this.size++;
106
+ }
107
+
108
+ prepend(value) {
109
+ const node = { value, next: this.head };
110
+
111
+ if (!this.head) {
112
+ this.tail = node;
113
+ }
114
+
115
+ this.head = node;
116
+ this.size++;
117
+ }
118
+
119
+ remove(value) {
120
+ if (!this.head) return false;
121
+
122
+ if (this.head.value === value) {
123
+ this.head = this.head.next;
124
+ if (!this.head) this.tail = null;
125
+ this.size--;
126
+ return true;
127
+ }
128
+
129
+ let current = this.head;
130
+ while (current.next) {
131
+ if (current.next.value === value) {
132
+ if (!current.next.next) {
133
+ this.tail = current;
134
+ }
135
+ current.next = current.next.next;
136
+ this.size--;
137
+ return true;
138
+ }
139
+ current = current.next;
140
+ }
141
+
142
+ return false;
143
+ }
144
+
145
+ contains(value) {
146
+ let current = this.head;
147
+ while (current) {
148
+ if (current.value === value) return true;
149
+ current = current.next;
150
+ }
151
+ return false;
152
+ }
153
+
154
+ toArray() {
155
+ const result = [];
156
+ let current = this.head;
157
+ while (current) {
158
+ result.push(current.value);
159
+ current = current.next;
160
+ }
161
+ return result;
162
+ }
163
+
164
+ getSize() {
165
+ return this.size;
166
+ }
167
+
168
+ isEmpty() {
169
+ return this.size === 0;
170
+ }
171
+
172
+ clear() {
173
+ this.head = null;
174
+ this.tail = null;
175
+ this.size = 0;
176
+ }
177
+ }
178
+
179
+ export class PriorityQueue {
180
+ constructor(comparator = (a, b) => a < b) {
181
+ this.items = [];
182
+ this.comparator = comparator;
183
+ }
184
+
185
+ enqueue(item, priority = 0) {
186
+ const element = { item, priority };
187
+ let added = false;
188
+
189
+ for (let i = 0; i < this.items.length; i++) {
190
+ if (this.comparator(priority, this.items[i].priority)) {
191
+ this.items.splice(i, 0, element);
192
+ added = true;
193
+ break;
194
+ }
195
+ }
196
+
197
+ if (!added) {
198
+ this.items.push(element);
199
+ }
200
+ }
201
+
202
+ dequeue() {
203
+ if (this.items.length === 0) {
204
+ throw new Error('Очередь пуста');
205
+ }
206
+ return this.items.shift().item;
207
+ }
208
+
209
+ peek() {
210
+ if (this.items.length === 0) {
211
+ return null;
212
+ }
213
+ return this.items[0].item;
214
+ }
215
+
216
+ isEmpty() {
217
+ return this.items.length === 0;
218
+ }
219
+
220
+ size() {
221
+ return this.items.length;
222
+ }
223
+
224
+ clear() {
225
+ this.items = [];
226
+ }
227
+ }
228
+
229
+ export class SetCustom {
230
+ constructor() {
231
+ this.items = new Map();
232
+ }
233
+
234
+ add(value) {
235
+ const key = JSON.stringify(value);
236
+ if (!this.items.has(key)) {
237
+ this.items.set(key, value);
238
+ }
239
+ }
240
+
241
+ has(value) {
242
+ const key = JSON.stringify(value);
243
+ return this.items.has(key);
244
+ }
245
+
246
+ delete(value) {
247
+ const key = JSON.stringify(value);
248
+ return this.items.delete(key);
249
+ }
250
+
251
+ values() {
252
+ return Array.from(this.items.values());
253
+ }
254
+
255
+ size() {
256
+ return this.items.size;
257
+ }
258
+
259
+ isEmpty() {
260
+ return this.items.size === 0;
261
+ }
262
+
263
+ clear() {
264
+ this.items.clear();
265
+ }
266
+
267
+ union(otherSet) {
268
+ const unionSet = new SetCustom();
269
+ this.values().forEach(value => unionSet.add(value));
270
+ otherSet.values().forEach(value => unionSet.add(value));
271
+ return unionSet;
272
+ }
273
+
274
+ intersection(otherSet) {
275
+ const intersectionSet = new SetCustom();
276
+ this.values().forEach(value => {
277
+ if (otherSet.has(value)) {
278
+ intersectionSet.add(value);
279
+ }
280
+ });
281
+ return intersectionSet;
282
+ }
283
+
284
+ difference(otherSet) {
285
+ const differenceSet = new SetCustom();
286
+ this.values().forEach(value => {
287
+ if (!otherSet.has(value)) {
288
+ differenceSet.add(value);
289
+ }
290
+ });
291
+ return differenceSet;
292
+ }
293
+
294
+ isSubset(otherSet) {
295
+ return this.values().every(value => otherSet.has(value));
296
+ }
297
+ }
298
+
299
+ export class MapCustom {
300
+ constructor() {
301
+ this.items = new Map();
302
+ }
303
+
304
+ set(key, value) {
305
+ const hashKey = JSON.stringify(key);
306
+ this.items.set(hashKey, { key, value });
307
+ }
308
+
309
+ get(key) {
310
+ const hashKey = JSON.stringify(key);
311
+ const entry = this.items.get(hashKey);
312
+ return entry ? entry.value : undefined;
313
+ }
314
+
315
+ has(key) {
316
+ const hashKey = JSON.stringify(key);
317
+ return this.items.has(hashKey);
318
+ }
319
+
320
+ delete(key) {
321
+ const hashKey = JSON.stringify(key);
322
+ return this.items.delete(hashKey);
323
+ }
324
+
325
+ keys() {
326
+ return Array.from(this.items.values()).map(entry => entry.key);
327
+ }
328
+
329
+ values() {
330
+ return Array.from(this.items.values()).map(entry => entry.value);
331
+ }
332
+
333
+ entries() {
334
+ return Array.from(this.items.values()).map(entry => [entry.key, entry.value]);
335
+ }
336
+
337
+ size() {
338
+ return this.items.size;
339
+ }
340
+
341
+ isEmpty() {
342
+ return this.items.size === 0;
343
+ }
344
+
345
+ clear() {
346
+ this.items.clear();
347
+ }
348
+ }
349
+
350
+ export class TrieNode {
351
+ constructor() {
352
+ this.children = new Map();
353
+ this.isEndOfWord = false;
354
+ }
355
+ }
356
+
357
+ export class Trie {
358
+ constructor() {
359
+ this.root = new TrieNode();
360
+ }
361
+
362
+ insert(word) {
363
+ let node = this.root;
364
+
365
+ for (const char of word) {
366
+ if (!node.children.has(char)) {
367
+ node.children.set(char, new TrieNode());
368
+ }
369
+ node = node.children.get(char);
370
+ }
371
+
372
+ node.isEndOfWord = true;
373
+ }
374
+
375
+ search(word) {
376
+ let node = this.root;
377
+
378
+ for (const char of word) {
379
+ if (!node.children.has(char)) {
380
+ return false;
381
+ }
382
+ node = node.children.get(char);
383
+ }
384
+
385
+ return node.isEndOfWord;
386
+ }
387
+
388
+ startsWith(prefix) {
389
+ let node = this.root;
390
+
391
+ for (const char of prefix) {
392
+ if (!node.children.has(char)) {
393
+ return false;
394
+ }
395
+ node = node.children.get(char);
396
+ }
397
+
398
+ return true;
399
+ }
400
+
401
+ delete(word) {
402
+ const deleteRecursive = (node, word, index) => {
403
+ if (index === word.length) {
404
+ if (!node.isEndOfWord) return false;
405
+ node.isEndOfWord = false;
406
+ return node.children.size === 0;
407
+ }
408
+
409
+ const char = word[index];
410
+ const child = node.children.get(char);
411
+
412
+ if (!child) return false;
413
+
414
+ const shouldDeleteChild = deleteRecursive(child, word, index + 1);
415
+
416
+ if (shouldDeleteChild) {
417
+ node.children.delete(char);
418
+ return node.children.size === 0 && !node.isEndOfWord;
419
+ }
420
+
421
+ return false;
422
+ };
423
+
424
+ deleteRecursive(this.root, word, 0);
425
+ }
426
+
427
+ getAllWords(prefix = '') {
428
+ const words = [];
429
+ let node = this.root;
430
+
431
+ for (const char of prefix) {
432
+ if (!node.children.has(char)) return words;
433
+ node = node.children.get(char);
434
+ }
435
+
436
+ const collectWords = (currentNode, currentPrefix) => {
437
+ if (currentNode.isEndOfWord) {
438
+ words.push(currentPrefix);
439
+ }
440
+
441
+ for (const [char, child] of currentNode.children) {
442
+ collectWords(child, currentPrefix + char);
443
+ }
444
+ };
445
+
446
+ collectWords(node, prefix);
447
+ return words;
448
+ }
449
+ }
450
+
451
+ export class BinarySearchTree {
452
+ constructor(compareFn = (a, b) => a - b) {
453
+ this.root = null;
454
+ this.compareFn = compareFn;
455
+ }
456
+
457
+ insert(value) {
458
+ const newNode = { value, left: null, right: null };
459
+
460
+ if (!this.root) {
461
+ this.root = newNode;
462
+ } else {
463
+ this.insertNode(this.root, newNode);
464
+ }
465
+ }
466
+
467
+ insertNode(node, newNode) {
468
+ const comparison = this.compareFn(newNode.value, node.value);
469
+
470
+ if (comparison < 0) {
471
+ if (!node.left) {
472
+ node.left = newNode;
473
+ } else {
474
+ this.insertNode(node.left, newNode);
475
+ }
476
+ } else {
477
+ if (!node.right) {
478
+ node.right = newNode;
479
+ } else {
480
+ this.insertNode(node.right, newNode);
481
+ }
482
+ }
483
+ }
484
+
485
+ search(value) {
486
+ return this.searchNode(this.root, value);
487
+ }
488
+
489
+ searchNode(node, value) {
490
+ if (!node) return null;
491
+
492
+ const comparison = this.compareFn(value, node.value);
493
+
494
+ if (comparison === 0) return node;
495
+ if (comparison < 0) return this.searchNode(node.left, value);
496
+ return this.searchNode(node.right, value);
497
+ }
498
+
499
+ inOrderTraversal(callback) {
500
+ this.inOrderTraversalNode(this.root, callback);
501
+ }
502
+
503
+ inOrderTraversalNode(node, callback) {
504
+ if (!node) return;
505
+
506
+ this.inOrderTraversalNode(node.left, callback);
507
+ callback(node.value);
508
+ this.inOrderTraversalNode(node.right, callback);
509
+ }
510
+
511
+ preOrderTraversal(callback) {
512
+ this.preOrderTraversalNode(this.root, callback);
513
+ }
514
+
515
+ preOrderTraversalNode(node, callback) {
516
+ if (!node) return;
517
+
518
+ callback(node.value);
519
+ this.preOrderTraversalNode(node.left, callback);
520
+ this.preOrderTraversalNode(node.right, callback);
521
+ }
522
+
523
+ postOrderTraversal(callback) {
524
+ this.postOrderTraversalNode(this.root, callback);
525
+ }
526
+
527
+ postOrderTraversalNode(node, callback) {
528
+ if (!node) return;
529
+
530
+ this.postOrderTraversalNode(node.left, callback);
531
+ this.postOrderTraversalNode(node.right, callback);
532
+ callback(node.value);
533
+ }
534
+
535
+ min() {
536
+ if (!this.root) return null;
537
+
538
+ let node = this.root;
539
+ while (node.left) {
540
+ node = node.left;
541
+ }
542
+ return node.value;
543
+ }
544
+
545
+ max() {
546
+ if (!this.root) return null;
547
+
548
+ let node = this.root;
549
+ while (node.right) {
550
+ node = node.right;
551
+ }
552
+ return node.value;
553
+ }
554
+
555
+ remove(value) {
556
+ this.root = this.removeNode(this.root, value);
557
+ }
558
+
559
+ removeNode(node, value) {
560
+ if (!node) return null;
561
+
562
+ const comparison = this.compareFn(value, node.value);
563
+
564
+ if (comparison < 0) {
565
+ node.left = this.removeNode(node.left, value);
566
+ } else if (comparison > 0) {
567
+ node.right = this.removeNode(node.right, value);
568
+ } else {
569
+ if (!node.left && !node.right) {
570
+ return null;
571
+ }
572
+
573
+ if (!node.left) {
574
+ return node.right;
575
+ }
576
+
577
+ if (!node.right) {
578
+ return node.left;
579
+ }
580
+
581
+ const minRight = this.findMinNode(node.right);
582
+ node.value = minRight.value;
583
+ node.right = this.removeNode(node.right, minRight.value);
584
+ }
585
+
586
+ return node;
587
+ }
588
+
589
+ findMinNode(node) {
590
+ while (node.left) {
591
+ node = node.left;
592
+ }
593
+ return node;
594
+ }
595
+
596
+ toArray() {
597
+ const result = [];
598
+ this.inOrderTraversal(value => result.push(value));
599
+ return result;
600
+ }
601
+ }
602
+
603
+ export default {
604
+ Stack,
605
+ Queue,
606
+ LinkedList,
607
+ PriorityQueue,
608
+ SetCustom,
609
+ MapCustom,
610
+ Trie,
611
+ BinarySearchTree
612
+ };