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.
- package/README.md +256 -0
- package/bin/cli.js +486 -0
- package/bin/vlad.js +539 -0
- package/bin/vladpm.js +710 -0
- package/bin/vladx.js +491 -0
- package/package.json +57 -0
- package/src/engine/jit-compiler.js +285 -0
- package/src/engine/vladx-engine.js +941 -0
- package/src/index.js +44 -0
- package/src/interpreter/interpreter.js +2114 -0
- package/src/lexer/lexer.js +658 -0
- package/src/lexer/optimized-lexer.js +106 -0
- package/src/lexer/regex-cache.js +83 -0
- package/src/parser/ast-nodes.js +472 -0
- package/src/parser/parser.js +1408 -0
- package/src/runtime/advanced-type-system.js +209 -0
- package/src/runtime/async-manager.js +252 -0
- package/src/runtime/builtins.js +143 -0
- package/src/runtime/bundler.js +422 -0
- package/src/runtime/cache-manager.js +126 -0
- package/src/runtime/data-structures.js +612 -0
- package/src/runtime/debugger.js +260 -0
- package/src/runtime/enhanced-module-system.js +196 -0
- package/src/runtime/environment-enhanced.js +272 -0
- package/src/runtime/environment.js +140 -0
- package/src/runtime/event-emitter.js +232 -0
- package/src/runtime/formatter.js +280 -0
- package/src/runtime/functional.js +359 -0
- package/src/runtime/io-operations.js +390 -0
- package/src/runtime/linter.js +374 -0
- package/src/runtime/logging.js +314 -0
- package/src/runtime/minifier.js +242 -0
- package/src/runtime/module-system.js +377 -0
- package/src/runtime/network-operations.js +373 -0
- package/src/runtime/profiler.js +295 -0
- package/src/runtime/repl.js +336 -0
- package/src/runtime/security-manager.js +244 -0
- package/src/runtime/source-map-generator.js +208 -0
- package/src/runtime/test-runner.js +394 -0
- package/src/runtime/transformer.js +277 -0
- package/src/runtime/type-system.js +244 -0
- package/src/runtime/vladx-object.js +250 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AdvancedTypeSystem — Расширенная система типов
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { TypeSystem } from './type-system.js';
|
|
6
|
+
|
|
7
|
+
export class AdvancedTypeSystem extends TypeSystem {
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.typeAliases = new Map();
|
|
11
|
+
this.unionTypes = new Map();
|
|
12
|
+
this.intersectionTypes = new Map();
|
|
13
|
+
this.genericTypes = new Map();
|
|
14
|
+
this.initializeAdvancedTypes();
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Инициализация расширенных типов
|
|
19
|
+
*/
|
|
20
|
+
initializeAdvancedTypes() {
|
|
21
|
+
// Union types
|
|
22
|
+
this.types.set('числоилистрока', {
|
|
23
|
+
name: 'числоилистрока',
|
|
24
|
+
check: (value) => {
|
|
25
|
+
if (value && typeof value === 'object' && 'value' in value) {
|
|
26
|
+
return value.type === 'number' || value.type === 'string';
|
|
27
|
+
}
|
|
28
|
+
return typeof value === 'number' || typeof value === 'string';
|
|
29
|
+
},
|
|
30
|
+
defaultValue: 0
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Tuple types (массивы фиксированной длины)
|
|
34
|
+
this.types.set('пара', {
|
|
35
|
+
name: 'пара',
|
|
36
|
+
check: (value) => Array.isArray(value) && value.length === 2,
|
|
37
|
+
defaultValue: [null, null]
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
this.types.set('тройка', {
|
|
41
|
+
name: 'тройка',
|
|
42
|
+
check: (value) => Array.isArray(value) && value.length === 3,
|
|
43
|
+
defaultValue: [null, null, null]
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Создать union type
|
|
49
|
+
*/
|
|
50
|
+
createUnionType(name, ...typeNames) {
|
|
51
|
+
const typeCheckers = typeNames.map(tn => {
|
|
52
|
+
const typeDef = this.types.get(tn);
|
|
53
|
+
return typeDef ? typeDef.check : (() => false);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
this.unionTypes.set(name, typeNames);
|
|
57
|
+
this.types.set(name, {
|
|
58
|
+
name,
|
|
59
|
+
check: (value) => typeCheckers.some(checker => checker(value)),
|
|
60
|
+
defaultValue: this.types.get(typeNames[0])?.defaultValue || null
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Создать intersection type
|
|
68
|
+
*/
|
|
69
|
+
createIntersectionType(name, ...typeNames) {
|
|
70
|
+
const typeCheckers = typeNames.map(tn => {
|
|
71
|
+
const typeDef = this.types.get(tn);
|
|
72
|
+
return typeDef ? typeDef.check : (() => true);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
this.intersectionTypes.set(name, typeNames);
|
|
76
|
+
this.types.set(name, {
|
|
77
|
+
name,
|
|
78
|
+
check: (value) => typeCheckers.every(checker => checker(value)),
|
|
79
|
+
defaultValue: null
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return this;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Создать generic type
|
|
87
|
+
*/
|
|
88
|
+
createGenericType(name, baseTypeName) {
|
|
89
|
+
const baseType = this.types.get(baseTypeName);
|
|
90
|
+
if (!baseType) {
|
|
91
|
+
throw new Error(`Базовый тип не найден: ${baseTypeName}`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
this.genericTypes.set(name, {
|
|
95
|
+
baseType: baseTypeName,
|
|
96
|
+
typeParameters: []
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
this.types.set(name, {
|
|
100
|
+
name,
|
|
101
|
+
check: baseType.check,
|
|
102
|
+
defaultValue: baseType.defaultValue
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Создать alias для типа
|
|
110
|
+
*/
|
|
111
|
+
createTypeAlias(aliasName, originalTypeName) {
|
|
112
|
+
const originalType = this.types.get(originalTypeName);
|
|
113
|
+
if (!originalType) {
|
|
114
|
+
throw new Error(`Тип не найден: ${originalTypeName}`);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.typeAliases.set(aliasName, originalTypeName);
|
|
118
|
+
this.types.set(aliasName, originalType);
|
|
119
|
+
|
|
120
|
+
return this;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Инференс типа с поддержкой union и intersection
|
|
125
|
+
*/
|
|
126
|
+
inferType(value) {
|
|
127
|
+
if (value === null || value === undefined) return 'ничто';
|
|
128
|
+
|
|
129
|
+
// Если это VladXObject
|
|
130
|
+
if (value && typeof value === 'object' && 'type' in value) {
|
|
131
|
+
switch (value.type) {
|
|
132
|
+
case 'number': return 'число';
|
|
133
|
+
case 'string': return 'строка';
|
|
134
|
+
case 'boolean': return 'логический';
|
|
135
|
+
case 'array':
|
|
136
|
+
// Проверка на tuple types
|
|
137
|
+
if (Array.isArray(value.value)) {
|
|
138
|
+
if (value.value.length === 2) return 'пара';
|
|
139
|
+
if (value.value.length === 3) return 'тройка';
|
|
140
|
+
}
|
|
141
|
+
return 'массив';
|
|
142
|
+
case 'object': return 'объект';
|
|
143
|
+
case 'function':
|
|
144
|
+
case 'closure': return 'функция';
|
|
145
|
+
case 'null': return 'ничто';
|
|
146
|
+
default: return 'любой';
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (typeof value === 'number') return 'число';
|
|
151
|
+
if (typeof value === 'string') return 'строка';
|
|
152
|
+
if (typeof value === 'boolean') return 'логический';
|
|
153
|
+
if (Array.isArray(value)) {
|
|
154
|
+
if (value.length === 2) return 'пара';
|
|
155
|
+
if (value.length === 3) return 'тройка';
|
|
156
|
+
return 'массив';
|
|
157
|
+
}
|
|
158
|
+
if (typeof value === 'function') return 'функция';
|
|
159
|
+
if (typeof value === 'object') return 'объект';
|
|
160
|
+
return 'любой';
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Проверить совместимость типов
|
|
165
|
+
*/
|
|
166
|
+
isTypeCompatible(type1, type2) {
|
|
167
|
+
if (type1 === type2) return true;
|
|
168
|
+
if (type1 === 'любой' || type2 === 'любой') return true;
|
|
169
|
+
|
|
170
|
+
// Проверка union types
|
|
171
|
+
if (this.unionTypes.has(type1)) {
|
|
172
|
+
const types = this.unionTypes.get(type1);
|
|
173
|
+
return types.includes(type2);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (this.unionTypes.has(type2)) {
|
|
177
|
+
const types = this.unionTypes.get(type2);
|
|
178
|
+
return types.includes(type1);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Проверка type aliases
|
|
182
|
+
if (this.typeAliases.has(type1)) {
|
|
183
|
+
const original = this.typeAliases.get(type1);
|
|
184
|
+
return this.isTypeCompatible(original, type2);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (this.typeAliases.has(type2)) {
|
|
188
|
+
const original = this.typeAliases.get(type2);
|
|
189
|
+
return this.isTypeCompatible(type1, original);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Получить все типы
|
|
197
|
+
*/
|
|
198
|
+
getAllTypes() {
|
|
199
|
+
return {
|
|
200
|
+
basic: Array.from(this.types.keys()),
|
|
201
|
+
unions: Array.from(this.unionTypes.keys()),
|
|
202
|
+
intersections: Array.from(this.intersectionTypes.keys()),
|
|
203
|
+
generics: Array.from(this.genericTypes.keys()),
|
|
204
|
+
aliases: Array.from(this.typeAliases.keys())
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export default AdvancedTypeSystem;
|
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AsyncManager — Управление асинхронными операциями
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { VladXObject } from './vladx-object.js';
|
|
6
|
+
|
|
7
|
+
export class AsyncManager {
|
|
8
|
+
constructor(options = {}) {
|
|
9
|
+
this.maxConcurrent = options.maxConcurrent || 10;
|
|
10
|
+
this.timeout = options.timeout || 30000;
|
|
11
|
+
this.activePromises = new Set();
|
|
12
|
+
this.queue = [];
|
|
13
|
+
this.stats = {
|
|
14
|
+
total: 0,
|
|
15
|
+
completed: 0,
|
|
16
|
+
failed: 0,
|
|
17
|
+
timeout: 0
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Параллельное выполнение
|
|
23
|
+
*/
|
|
24
|
+
async parallel(tasks, options = {}) {
|
|
25
|
+
const maxConcurrency = options.maxConcurrency || this.maxConcurrent;
|
|
26
|
+
const timeout = options.timeout || this.timeout;
|
|
27
|
+
|
|
28
|
+
if (tasks.length === 0) {
|
|
29
|
+
return VladXObject.array([]);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const results = [];
|
|
33
|
+
const executing = new Set();
|
|
34
|
+
|
|
35
|
+
const processTask = async (task, index) => {
|
|
36
|
+
try {
|
|
37
|
+
const result = await Promise.race([
|
|
38
|
+
task(),
|
|
39
|
+
new Promise((_, reject) =>
|
|
40
|
+
setTimeout(() => reject(new Error('Timeout')), timeout)
|
|
41
|
+
)
|
|
42
|
+
]);
|
|
43
|
+
results[index] = result;
|
|
44
|
+
this.stats.completed++;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
results[index] = { error: error.message };
|
|
47
|
+
this.stats.failed++;
|
|
48
|
+
} finally {
|
|
49
|
+
executing.delete(processTask);
|
|
50
|
+
|
|
51
|
+
if (this.queue.length > 0) {
|
|
52
|
+
const next = this.queue.shift();
|
|
53
|
+
executing.add(next);
|
|
54
|
+
next();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
for (let i = 0; i < tasks.length; i++) {
|
|
60
|
+
if (executing.size >= maxConcurrency) {
|
|
61
|
+
await new Promise(resolve => {
|
|
62
|
+
const taskWrapper = () => {
|
|
63
|
+
processTask(tasks[i], i).then(resolve);
|
|
64
|
+
};
|
|
65
|
+
this.queue.push(taskWrapper);
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
const promise = processTask(tasks[i], i);
|
|
69
|
+
executing.add(promise);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await Promise.all(executing);
|
|
74
|
+
this.stats.total += tasks.length;
|
|
75
|
+
|
|
76
|
+
return VladXObject.array(results);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Sequential выполнение
|
|
81
|
+
*/
|
|
82
|
+
async sequential(tasks) {
|
|
83
|
+
const results = [];
|
|
84
|
+
|
|
85
|
+
for (const task of tasks) {
|
|
86
|
+
try {
|
|
87
|
+
const result = await Promise.race([
|
|
88
|
+
task(),
|
|
89
|
+
new Promise((_, reject) =>
|
|
90
|
+
setTimeout(() => reject(new Error('Timeout')), this.timeout)
|
|
91
|
+
)
|
|
92
|
+
]);
|
|
93
|
+
results.push(result);
|
|
94
|
+
this.stats.completed++;
|
|
95
|
+
} catch (error) {
|
|
96
|
+
results.push({ error: error.message });
|
|
97
|
+
this.stats.failed++;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.stats.total += tasks.length;
|
|
102
|
+
return VladXObject.array(results);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Race - первый завершившийся промис
|
|
107
|
+
*/
|
|
108
|
+
async race(tasks) {
|
|
109
|
+
if (tasks.length === 0) {
|
|
110
|
+
return VladXObject.null();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
try {
|
|
114
|
+
const result = await Promise.race([
|
|
115
|
+
Promise.race(tasks.map(t => t())),
|
|
116
|
+
new Promise((_, reject) =>
|
|
117
|
+
setTimeout(() => reject(new Error('Timeout')), this.timeout)
|
|
118
|
+
)
|
|
119
|
+
]);
|
|
120
|
+
return VladXObject.fromJS(result);
|
|
121
|
+
} catch (error) {
|
|
122
|
+
this.stats.failed++;
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* AllSettled - все промисы завершены (включая rejected)
|
|
129
|
+
*/
|
|
130
|
+
async allSettled(tasks) {
|
|
131
|
+
if (tasks.length === 0) {
|
|
132
|
+
return VladXObject.array([]);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const results = await Promise.allSettled(
|
|
136
|
+
tasks.map(task =>
|
|
137
|
+
Promise.race([
|
|
138
|
+
task(),
|
|
139
|
+
new Promise((_, reject) =>
|
|
140
|
+
setTimeout(() => reject(new Error('Timeout')), this.timeout)
|
|
141
|
+
)
|
|
142
|
+
])
|
|
143
|
+
)
|
|
144
|
+
);
|
|
145
|
+
|
|
146
|
+
this.stats.total += tasks.length;
|
|
147
|
+
return VladXObject.array(
|
|
148
|
+
results.map(result => ({
|
|
149
|
+
status: result.status,
|
|
150
|
+
value: result.status === 'fulfilled' ? result.value : result.reason
|
|
151
|
+
}))
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Any - первый успешно завершившийся
|
|
157
|
+
*/
|
|
158
|
+
async any(tasks) {
|
|
159
|
+
if (tasks.length === 0) {
|
|
160
|
+
throw new Error('Нет задач для выполнения');
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
try {
|
|
164
|
+
const result = await Promise.any(
|
|
165
|
+
tasks.map(task =>
|
|
166
|
+
Promise.race([
|
|
167
|
+
task(),
|
|
168
|
+
new Promise((_, reject) =>
|
|
169
|
+
setTimeout(() => reject(new Error('Timeout')), this.timeout)
|
|
170
|
+
)
|
|
171
|
+
])
|
|
172
|
+
)
|
|
173
|
+
);
|
|
174
|
+
return VladXObject.fromJS(result);
|
|
175
|
+
} catch (error) {
|
|
176
|
+
this.stats.failed++;
|
|
177
|
+
throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Debounce - задержка выполнения
|
|
183
|
+
*/
|
|
184
|
+
debounce(func, delay) {
|
|
185
|
+
let timeoutId;
|
|
186
|
+
|
|
187
|
+
return (...args) => {
|
|
188
|
+
clearTimeout(timeoutId);
|
|
189
|
+
return new Promise((resolve) => {
|
|
190
|
+
timeoutId = setTimeout(() => {
|
|
191
|
+
resolve(func(...args));
|
|
192
|
+
}, delay);
|
|
193
|
+
});
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Throttle - ограничение частоты выполнения
|
|
199
|
+
*/
|
|
200
|
+
throttle(func, limit) {
|
|
201
|
+
let inThrottle;
|
|
202
|
+
|
|
203
|
+
return (...args) => {
|
|
204
|
+
if (!inThrottle) {
|
|
205
|
+
func(...args);
|
|
206
|
+
inThrottle = true;
|
|
207
|
+
setTimeout(() => inThrottle = false, limit);
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Retry - повторная попытка при ошибке
|
|
214
|
+
*/
|
|
215
|
+
async retry(func, maxAttempts = 3, delay = 1000) {
|
|
216
|
+
let lastError;
|
|
217
|
+
|
|
218
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
219
|
+
try {
|
|
220
|
+
return await func();
|
|
221
|
+
} catch (error) {
|
|
222
|
+
lastError = error;
|
|
223
|
+
if (attempt < maxAttempts) {
|
|
224
|
+
await new Promise(resolve => setTimeout(resolve, delay * attempt));
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
throw lastError;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Очистка активных промисов
|
|
234
|
+
*/
|
|
235
|
+
clear() {
|
|
236
|
+
this.activePromises.clear();
|
|
237
|
+
this.queue = [];
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Получить статистику
|
|
242
|
+
*/
|
|
243
|
+
getStats() {
|
|
244
|
+
return {
|
|
245
|
+
...this.stats,
|
|
246
|
+
active: this.activePromises.size,
|
|
247
|
+
queued: this.queue.length
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
export default AsyncManager;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VladX Builtins — Встроенные модули и функции
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { VladXObject } from './vladx-object.js';
|
|
6
|
+
|
|
7
|
+
export class Builtins {
|
|
8
|
+
constructor(interpreter) {
|
|
9
|
+
this.interpreter = interpreter;
|
|
10
|
+
this.modules = new Map();
|
|
11
|
+
this.registerCoreModules();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Регистрация основных модулей
|
|
16
|
+
*/
|
|
17
|
+
registerCoreModules() {
|
|
18
|
+
// Модуль для работы с консолью
|
|
19
|
+
this.modules.set('консоль', {
|
|
20
|
+
печать: (...args) => {
|
|
21
|
+
console.log(...args.map(arg =>
|
|
22
|
+
typeof arg === 'object' ? JSON.stringify(arg, null, 2) : String(arg)
|
|
23
|
+
));
|
|
24
|
+
return VladXObject.null();
|
|
25
|
+
},
|
|
26
|
+
вывод: (...args) => {
|
|
27
|
+
process.stdout.write(args.join(' '));
|
|
28
|
+
return VladXObject.null();
|
|
29
|
+
},
|
|
30
|
+
ошибка: (...args) => {
|
|
31
|
+
console.error(...args);
|
|
32
|
+
return VladXObject.null();
|
|
33
|
+
},
|
|
34
|
+
время: () => {
|
|
35
|
+
const now = new Date();
|
|
36
|
+
return VladXObject.object({
|
|
37
|
+
миллисекунды: now.getTime(),
|
|
38
|
+
год: now.getFullYear(),
|
|
39
|
+
месяц: now.getMonth() + 1,
|
|
40
|
+
день: now.getDate(),
|
|
41
|
+
час: now.getHours(),
|
|
42
|
+
минута: now.getMinutes(),
|
|
43
|
+
секунда: now.getSeconds()
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Модуль для работы с файловой системой
|
|
50
|
+
this.modules.set('файловаяСистема', {
|
|
51
|
+
существует: async (path) => {
|
|
52
|
+
const fs = await import('fs');
|
|
53
|
+
return VladXObject.boolean(fs.existsSync(path));
|
|
54
|
+
},
|
|
55
|
+
читать: async (path) => {
|
|
56
|
+
const fs = await import('fs');
|
|
57
|
+
try {
|
|
58
|
+
return VladXObject.string(fs.readFileSync(path, 'utf-8'));
|
|
59
|
+
} catch (e) {
|
|
60
|
+
throw new Error(`Не удалось прочитать файл: ${e.message}`);
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
писать: async (path, content) => {
|
|
64
|
+
const fs = await import('fs');
|
|
65
|
+
try {
|
|
66
|
+
fs.writeFileSync(path, content, 'utf-8');
|
|
67
|
+
return VladXObject.boolean(true);
|
|
68
|
+
} catch (e) {
|
|
69
|
+
throw new Error(`Не удалось записать файл: ${e.message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Модуль для работы с JSON
|
|
75
|
+
this.modules.set('json', {
|
|
76
|
+
сериализовать: (obj) => {
|
|
77
|
+
try {
|
|
78
|
+
return VladXObject.string(JSON.stringify(obj));
|
|
79
|
+
} catch (e) {
|
|
80
|
+
throw new Error(`Ошибка сериализации: ${e.message}`);
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
десериализовать: (str) => {
|
|
84
|
+
try {
|
|
85
|
+
return VladXObject.object(JSON.parse(str));
|
|
86
|
+
} catch (e) {
|
|
87
|
+
throw new Error(`Ошибка десериализации: ${e.message}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Модуль для работы с датой и временем
|
|
93
|
+
this.modules.set('дата', {
|
|
94
|
+
сейчас: () => {
|
|
95
|
+
return VladXObject.object({
|
|
96
|
+
год: new Date().getFullYear(),
|
|
97
|
+
месяц: new Date().getMonth() + 1,
|
|
98
|
+
день: new Date().getDate(),
|
|
99
|
+
час: new Date().getHours(),
|
|
100
|
+
минута: new Date().getMinutes(),
|
|
101
|
+
секунда: new Date().getSeconds()
|
|
102
|
+
});
|
|
103
|
+
},
|
|
104
|
+
миллисекунды: () => {
|
|
105
|
+
return VladXObject.number(Date.now());
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Загрузка модуля
|
|
112
|
+
*/
|
|
113
|
+
async loadModule(moduleName) {
|
|
114
|
+
if (this.modules.has(moduleName)) {
|
|
115
|
+
return this.modules.get(moduleName);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Внешние модули должны загружаться через module-system
|
|
119
|
+
throw new Error(`Встроенный модуль "${moduleName}" не найден. Используйте import для внешних модулей.`);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Импорт модуля
|
|
124
|
+
*/
|
|
125
|
+
async importModule(moduleName, options = {}) {
|
|
126
|
+
const module = await this.loadModule(moduleName);
|
|
127
|
+
|
|
128
|
+
// Создание объекта модуля
|
|
129
|
+
const moduleObj = VladXObject.object({});
|
|
130
|
+
|
|
131
|
+
for (const [key, value] of Object.entries(module)) {
|
|
132
|
+
if (typeof value === 'function') {
|
|
133
|
+
moduleObj.value[key] = VladXObject.function(value, key);
|
|
134
|
+
} else {
|
|
135
|
+
moduleObj.value[key] = VladXObject.object(value);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return moduleObj;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export default Builtins;
|