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,250 @@
1
+ /**
2
+ * VladX Object — Объектная система языка
3
+ * Реализует типы данных и обёртки для значений
4
+ */
5
+
6
+ // Типы данных
7
+ export const types = {
8
+ NULL: 'null',
9
+ NUMBER: 'number',
10
+ STRING: 'string',
11
+ BOOLEAN: 'boolean',
12
+ ARRAY: 'array',
13
+ OBJECT: 'object',
14
+ FUNCTION: 'function',
15
+ CLOSURE: 'closure',
16
+ NATIVE: 'native',
17
+ CLASS: 'class',
18
+ INSTANCE: 'instance',
19
+ ERROR: 'error'
20
+ };
21
+
22
+ /**
23
+ * Базовый класс для всех значений VladX
24
+ */
25
+ export class VladXObject {
26
+ constructor(type, value = null, options = {}) {
27
+ this.type = type;
28
+ this.value = value;
29
+ this.isNative = options.isNative || false;
30
+ this.env = options.env || null;
31
+ this.name = options.name || null;
32
+ this.prototype = options.prototype || null;
33
+ this.methods = options.methods || new Map();
34
+ this.staticMethods = options.staticMethods || new Map();
35
+ this.ast = options.ast || null;
36
+ }
37
+
38
+ // Фабричные методы для создания объектов разных типов
39
+
40
+ static null() {
41
+ return new VladXObject(types.NULL, null);
42
+ }
43
+
44
+ static number(value) {
45
+ return new VladXObject(types.NUMBER, Number(value));
46
+ }
47
+
48
+ static string(value) {
49
+ return new VladXObject(types.STRING, String(value));
50
+ }
51
+
52
+ static boolean(value) {
53
+ return new VladXObject(types.BOOLEAN, Boolean(value));
54
+ }
55
+
56
+ static array(value) {
57
+ return new VladXObject(types.ARRAY, value);
58
+ }
59
+
60
+ static object(value) {
61
+ return new VladXObject(types.OBJECT, value || {});
62
+ }
63
+
64
+ static function(value, name = '<function>') {
65
+ return new VladXObject(types.FUNCTION, value, { name, isNative: true });
66
+ }
67
+
68
+ static closure(ast, env, name = '<closure>') {
69
+ return new VladXObject(types.CLOSURE, null, { env, name, ast });
70
+ }
71
+
72
+ static class(name, methods = new Map(), staticMethods = new Map(), superClass = null) {
73
+ return new VladXObject(types.CLASS, null, { name, methods, staticMethods, prototype: superClass });
74
+ }
75
+
76
+ static instance(classObj) {
77
+ return new VladXObject(types.INSTANCE, {}, {
78
+ prototype: classObj,
79
+ name: classObj.name
80
+ });
81
+ }
82
+
83
+ /**
84
+ * Создать VladXObject из обычного JS-значения
85
+ */
86
+ static fromJS(value) {
87
+ if (value === null || value === undefined) {
88
+ return VladXObject.null();
89
+ }
90
+ if (typeof value === 'number') {
91
+ return VladXObject.number(value);
92
+ }
93
+ if (typeof value === 'string') {
94
+ return VladXObject.string(value);
95
+ }
96
+ if (typeof value === 'boolean') {
97
+ return VladXObject.boolean(value);
98
+ }
99
+ if (Array.isArray(value)) {
100
+ return VladXObject.array(value);
101
+ }
102
+ if (typeof value === 'object') {
103
+ return VladXObject.object(value);
104
+ }
105
+ return VladXObject.string(String(value));
106
+ }
107
+
108
+ /**
109
+ * Получить "сырое" значение для операций
110
+ */
111
+ getRawValue() {
112
+ if (this.value === null || this.value === undefined) {
113
+ return null;
114
+ }
115
+ return this.value;
116
+ }
117
+
118
+ // Методы проверки типа
119
+
120
+ isNull() {
121
+ return this.type === types.NULL;
122
+ }
123
+
124
+ isNumber() {
125
+ return this.type === types.NUMBER;
126
+ }
127
+
128
+ isString() {
129
+ return this.type === types.STRING;
130
+ }
131
+
132
+ isBoolean() {
133
+ return this.type === types.BOOLEAN;
134
+ }
135
+
136
+ isArray() {
137
+ return this.type === types.ARRAY;
138
+ }
139
+
140
+ isObject() {
141
+ return this.type === types.OBJECT;
142
+ }
143
+
144
+ isFunction() {
145
+ return this.type === types.FUNCTION;
146
+ }
147
+
148
+ isClosure() {
149
+ return this.type === types.CLOSURE;
150
+ }
151
+
152
+ isNativeFunction() {
153
+ return this.type === types.FUNCTION && this.isNative;
154
+ }
155
+
156
+ isClass() {
157
+ return this.type === types.CLASS;
158
+ }
159
+
160
+ isInstance() {
161
+ return this.type === types.INSTANCE;
162
+ }
163
+
164
+ isError() {
165
+ return this.type === types.ERROR;
166
+ }
167
+
168
+ // Преобразование в строку
169
+
170
+ toString() {
171
+ if (this.value === null) {
172
+ return 'ничто';
173
+ }
174
+
175
+ if (this.type === types.STRING) {
176
+ return this.value;
177
+ }
178
+
179
+ if (this.type === types.NUMBER) {
180
+ return String(this.value);
181
+ }
182
+
183
+ if (this.type === types.BOOLEAN) {
184
+ return this.value ? 'истина' : 'ложь';
185
+ }
186
+
187
+ if (this.type === types.ARRAY) {
188
+ return '[' + this.value.map(v => v?.toString() || String(v)).join(', ') + ']';
189
+ }
190
+
191
+ if (this.type === types.OBJECT) {
192
+ const props = Object.entries(this.value || {})
193
+ .map(([k, v]) => `${k}: ${v?.toString() || String(v)}`)
194
+ .join(', ');
195
+ return '{' + props + '}';
196
+ }
197
+
198
+ if (this.type === types.FUNCTION || this.type === types.CLOSURE) {
199
+ return `[функция: ${this.name}]`;
200
+ }
201
+
202
+ if (this.type === types.CLASS) {
203
+ return `[класс: ${this.name}]`;
204
+ }
205
+
206
+ if (this.type === types.INSTANCE) {
207
+ return `[экземпляр ${this.name}]`;
208
+ }
209
+
210
+ return String(this.value);
211
+ }
212
+
213
+ // Глубокое копирование
214
+
215
+ clone() {
216
+ return new VladXObject(
217
+ this.type,
218
+ this.cloneValue(this.value),
219
+ {
220
+ isNative: this.isNative,
221
+ env: this.env,
222
+ name: this.name,
223
+ prototype: this.prototype,
224
+ methods: this.methods
225
+ }
226
+ );
227
+ }
228
+
229
+ cloneValue(val) {
230
+ if (val === null || val === undefined) {
231
+ return val;
232
+ }
233
+
234
+ if (Array.isArray(val)) {
235
+ return val.map(v => this.cloneValue(v));
236
+ }
237
+
238
+ if (typeof val === 'object') {
239
+ const cloned = {};
240
+ for (const key in val) {
241
+ cloned[key] = this.cloneValue(val[key]);
242
+ }
243
+ return cloned;
244
+ }
245
+
246
+ return val;
247
+ }
248
+ }
249
+
250
+ export default VladXObject;