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,359 @@
1
+ /**
2
+ * Functional — Функциональное программирование
3
+ */
4
+
5
+ import { VladXObject } from './vladx-object.js';
6
+
7
+ export class Functional {
8
+ /**
9
+ * Каррирование функции
10
+ */
11
+ static curry(fn) {
12
+ return function curried(...args) {
13
+ if (args.length >= fn.length) {
14
+ return fn(...args);
15
+ }
16
+ return (...more) => curried(...args, ...more);
17
+ };
18
+ }
19
+
20
+ /**
21
+ * Композиция функций (справа налево)
22
+ */
23
+ static compose(...fns) {
24
+ return (arg) => fns.reduceRight((acc, fn) => fn(acc), arg);
25
+ }
26
+
27
+ /**
28
+ * Pipe оператор (слева направо)
29
+ */
30
+ static pipe(...fns) {
31
+ return (arg) => fns.reduce((acc, fn) => fn(acc), arg);
32
+ }
33
+
34
+ /**
35
+ * Мемоизация
36
+ */
37
+ static memoize(fn, keyFn = (...args) => JSON.stringify(args)) {
38
+ const cache = new Map();
39
+
40
+ return (...args) => {
41
+ const key = keyFn(...args);
42
+
43
+ if (cache.has(key)) {
44
+ return cache.get(key);
45
+ }
46
+
47
+ const result = fn(...args);
48
+ cache.set(key, result);
49
+ return result;
50
+ };
51
+ }
52
+
53
+ /**
54
+ * Частичное применение
55
+ */
56
+ static partial(fn, ...presetArgs) {
57
+ return (...args) => fn(...presetArgs, ...args);
58
+ }
59
+
60
+ /**
61
+ * Flip аргументы
62
+ */
63
+ static flip(fn) {
64
+ return (...args) => fn(...args.reverse());
65
+ }
66
+
67
+ /**
68
+ * Lazy evaluation
69
+ */
70
+ static lazy(fn) {
71
+ let cached = null;
72
+ let computed = false;
73
+
74
+ return () => {
75
+ if (!computed) {
76
+ cached = fn();
77
+ computed = true;
78
+ }
79
+ return cached;
80
+ };
81
+ }
82
+
83
+ /**
84
+ * Thunk - задержанное вычисление
85
+ */
86
+ static thunk(fn, ...args) {
87
+ return () => fn(...args);
88
+ }
89
+
90
+ /**
91
+ * Identity функция
92
+ */
93
+ static identity(x) {
94
+ return x;
95
+ }
96
+
97
+ /**
98
+ * Always возвращает всегда одно и то же значение
99
+ */
100
+ static always(x) {
101
+ return () => x;
102
+ }
103
+
104
+ /**
105
+ * Tap - побочный эффект
106
+ */
107
+ static tap(fn) {
108
+ return (x) => {
109
+ fn(x);
110
+ return x;
111
+ };
112
+ }
113
+
114
+ /**
115
+ * Trace - отладочная функция
116
+ */
117
+ static trace(label = 'trace') {
118
+ return (x) => {
119
+ console.log(label, x);
120
+ return x;
121
+ };
122
+ }
123
+
124
+ /**
125
+ * Apply - применить функцию к аргументам
126
+ */
127
+ static apply(fn, args) {
128
+ return fn(...args);
129
+ }
130
+
131
+ /**
132
+ * Uncurry - превращить метод в функцию
133
+ */
134
+ static uncurry(fn) {
135
+ return (obj, ...args) => obj[fn](...args);
136
+ }
137
+
138
+ /**
139
+ * Converge - применить функции к аргументам и передать результаты в другую функцию
140
+ */
141
+ static converge(after, fns) {
142
+ return (...args) => after(...fns.map(fn => fn(...args)));
143
+ }
144
+
145
+ /**
146
+ * Once - функция выполняется только один раз
147
+ */
148
+ static once(fn) {
149
+ let called = false;
150
+ let result;
151
+
152
+ return (...args) => {
153
+ if (called) return result;
154
+ called = true;
155
+ result = fn(...args);
156
+ return result;
157
+ };
158
+ }
159
+
160
+ /**
161
+ * Debounce - задержка выполнения
162
+ */
163
+ static debounce(fn, delay) {
164
+ let timeoutId;
165
+
166
+ return (...args) => {
167
+ clearTimeout(timeoutId);
168
+ timeoutId = setTimeout(() => fn(...args), delay);
169
+ };
170
+ }
171
+
172
+ /**
173
+ * Throttle - ограничение частоты
174
+ */
175
+ static throttle(fn, limit) {
176
+ let inThrottle;
177
+
178
+ return (...args) => {
179
+ if (!inThrottle) {
180
+ fn(...args);
181
+ inThrottle = true;
182
+ setTimeout(() => inThrottle = false, limit);
183
+ }
184
+ };
185
+ }
186
+
187
+ /**
188
+ * Maybe Monad
189
+ */
190
+ static Maybe(value) {
191
+ return {
192
+ isNothing: () => value === null || value === undefined,
193
+ map: (fn) => Functional.Maybe(value === null || value === undefined ? null : fn(value)),
194
+ chain: (fn) => Functional.Maybe(value === null || value === undefined ? null : fn(value)),
195
+ getOrElse: (def) => value === null || value === undefined ? def : value,
196
+ ap: (maybeFn) => Functional.Maybe(value === null || value === undefined ? null : maybeFn.getOrElse(null)(value)),
197
+ join: () => Functional.Maybe(value === null || value === undefined ? null : value.getOrElse ? value.getOrElse(null) : value)
198
+ };
199
+ }
200
+
201
+ /**
202
+ * Either Monad
203
+ */
204
+ static Either(value) {
205
+ return {
206
+ isLeft: () => value instanceof Error,
207
+ isRight: () => !(value instanceof Error),
208
+ map: (fn) => Functional.Either(value instanceof Error ? value : fn(value)),
209
+ chain: (fn) => Functional.Either(value instanceof Error ? value : fn(value)),
210
+ getOrElse: (def) => value instanceof Error ? def : value,
211
+ fold: (onLeft, onRight) => value instanceof Error ? onLeft(value) : onRight(value),
212
+ ap: (eitherFn) => Functional.Either(
213
+ value instanceof Error || eitherFn.isLeft() ? value : eitherFn.getOrElse(null)(value)
214
+ )
215
+ };
216
+ }
217
+
218
+ /**
219
+ * Promise Monad
220
+ */
221
+ static PromiseMonad(value) {
222
+ return Promise.resolve(value);
223
+ }
224
+
225
+ /**
226
+ * Fold (reduce) - свертка
227
+ */
228
+ static fold(fn, initial) {
229
+ return (arr) => arr.reduce(fn, initial);
230
+ }
231
+
232
+ /**
233
+ * Unfold - развертка
234
+ */
235
+ static unfold(fn, seed) {
236
+ const result = [];
237
+ let current = seed;
238
+
239
+ while (true) {
240
+ const [value, next] = fn(current);
241
+ if (value === undefined) break;
242
+ result.push(value);
243
+ current = next;
244
+ }
245
+
246
+ return result;
247
+ }
248
+
249
+ /**
250
+ * Range - создание диапазона
251
+ */
252
+ static range(start, end, step = 1) {
253
+ const result = [];
254
+
255
+ for (let i = start; step > 0 ? i < end : i > end; i += step) {
256
+ result.push(i);
257
+ }
258
+
259
+ return result;
260
+ }
261
+
262
+ /**
263
+ * Zip - объединение массивов
264
+ */
265
+ static zip(...arrays) {
266
+ const maxLength = Math.max(...arrays.map(a => a.length));
267
+ const result = [];
268
+
269
+ for (let i = 0; i < maxLength; i++) {
270
+ result.push(arrays.map(a => a[i]));
271
+ }
272
+
273
+ return result;
274
+ }
275
+
276
+ /**
277
+ * ZipWith - объединение с функцией
278
+ */
279
+ static zipWith(fn, ...arrays) {
280
+ return Functional.zip(...arrays).map(tuple => fn(...tuple));
281
+ }
282
+
283
+ /**
284
+ * Partition - разделение массива
285
+ */
286
+ static partition(fn) {
287
+ return (arr) => arr.reduce(
288
+ (acc, x) => (fn(x) ? (acc[0].push(x), acc) : (acc[1].push(x), acc)),
289
+ [[], []]
290
+ );
291
+ }
292
+
293
+ /**
294
+ * GroupBy - группировка
295
+ */
296
+ static groupBy(fn) {
297
+ return (arr) => arr.reduce((acc, x) => {
298
+ const key = fn(x);
299
+ (acc[key] = acc[key] || []).push(x);
300
+ return acc;
301
+ }, {});
302
+ }
303
+
304
+ /**
305
+ * SortBy - сортировка по ключу
306
+ */
307
+ static sortBy(fn) {
308
+ return (arr) => [...arr].sort((a, b) => {
309
+ const fa = fn(a);
310
+ const fb = fn(b);
311
+ if (fa < fb) return -1;
312
+ if (fa > fb) return 1;
313
+ return 0;
314
+ });
315
+ }
316
+
317
+ /**
318
+ * Take - взять N элементов
319
+ */
320
+ static take(n) {
321
+ return (arr) => arr.slice(0, n);
322
+ }
323
+
324
+ /**
325
+ * TakeWhile - взять пока условие истинно
326
+ */
327
+ static takeWhile(fn) {
328
+ return (arr) => {
329
+ const result = [];
330
+ for (const x of arr) {
331
+ if (!fn(x)) break;
332
+ result.push(x);
333
+ }
334
+ return result;
335
+ };
336
+ }
337
+
338
+ /**
339
+ * Drop - отбросить N элементов
340
+ */
341
+ static drop(n) {
342
+ return (arr) => arr.slice(n);
343
+ }
344
+
345
+ /**
346
+ * DropWhile - отбросить пока условие истинно
347
+ */
348
+ static dropWhile(fn) {
349
+ return (arr) => {
350
+ let index = 0;
351
+ while (index < arr.length && fn(arr[index])) {
352
+ index++;
353
+ }
354
+ return arr.slice(index);
355
+ };
356
+ }
357
+ }
358
+
359
+ export default Functional;