l0n0lc 0.8.4__py3-none-any.whl → 1.0.0__py3-none-any.whl

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 (47) hide show
  1. l0n0lc/Py/350/275/254Cpp/350/275/254/350/257/221/345/231/250.py +579 -0
  2. l0n0lc/__init__.py +75 -6
  3. l0n0lc/aot/347/274/226/350/257/221.py +679 -0
  4. l0n0lc/ast/350/256/277/351/227/256/350/200/205.py +599 -0
  5. l0n0lc/cpp/347/261/273/345/236/213.py +330 -0
  6. l0n0lc/cpp/347/274/226/350/257/221/345/231/250.py +317 -0
  7. l0n0lc/simd/344/274/230/345/214/226.py +260 -0
  8. l0n0lc/std_map.py +153 -0
  9. l0n0lc/std_set.py +185 -0
  10. l0n0lc/std_vector.py +96 -0
  11. l0n0lc//344/273/243/347/240/201/344/274/230/345/214/226.py +302 -0
  12. l0n0lc//344/273/243/347/240/201/347/224/237/346/210/220.py +546 -0
  13. l0n0lc//344/276/235/350/265/226/346/263/250/345/205/245.py +155 -0
  14. l0n0lc//345/215/263/346/227/266/347/274/226/350/257/221.py +192 -0
  15. l0n0lc//345/217/230/351/207/217/347/256/241/347/220/206/345/231/250.py +123 -0
  16. l0n0lc//345/237/272/347/241/200/346/230/240/345/260/204.py +103 -0
  17. l0n0lc//345/237/272/347/241/200/346/267/267/345/205/245.py +147 -0
  18. l0n0lc//345/256/271/345/231/250/346/236/204/345/273/272/345/231/250.py +214 -0
  19. l0n0lc//345/267/245/345/205/267.py +285 -0
  20. l0n0lc//345/271/266/350/241/214/347/274/226/350/257/221/345/231/250.py +412 -0
  21. l0n0lc//345/274/202/345/270/270.py +474 -0
  22. l0n0lc//346/225/260/347/273/204/345/257/271/350/261/241/346/261/240.py +248 -0
  23. l0n0lc//346/226/207/344/273/266/347/256/241/347/220/206/345/231/250.py +286 -0
  24. l0n0lc//346/227/245/345/277/227/345/267/245/345/205/267.py +152 -0
  25. l0n0lc//347/261/273/345/236/213/346/216/250/346/226/255/345/267/245/345/205/267.py +352 -0
  26. l0n0lc//347/261/273/345/236/213/350/275/254/346/215/242.py +210 -0
  27. l0n0lc//347/261/273/346/224/257/346/214/201.py +372 -0
  28. l0n0lc//347/274/226/350/257/221/344/270/212/344/270/213/346/226/207.py +132 -0
  29. l0n0lc//347/274/226/350/257/221/347/256/241/347/220/206/345/231/250.py +171 -0
  30. l0n0lc//350/241/250/350/276/276/345/274/217/345/244/204/347/220/206.py +462 -0
  31. l0n0lc//350/275/254/350/257/221/345/231/250/345/267/245/345/205/267.py +49 -0
  32. l0n0lc//350/277/220/350/241/214/346/227/266/345/212/240/350/275/275.py +217 -0
  33. l0n0lc//351/200/232/347/224/250/345/267/245/345/205/267.py +149 -0
  34. l0n0lc-1.0.0.dist-info/METADATA +363 -0
  35. l0n0lc-1.0.0.dist-info/RECORD +39 -0
  36. {l0n0lc-0.8.4.dist-info → l0n0lc-1.0.0.dist-info}/WHEEL +1 -1
  37. l0n0lc-1.0.0.dist-info/entry_points.txt +2 -0
  38. {l0n0lc-0.8.4.dist-info → l0n0lc-1.0.0.dist-info}/licenses/LICENSE +0 -0
  39. l0n0lc/StdList.py +0 -24
  40. l0n0lc/StdMap.py +0 -21
  41. l0n0lc/c/345/237/272/347/241/200/345/244/204/347/220/206.py +0 -207
  42. l0n0lc/jit.py +0 -604
  43. l0n0lc//347/274/226/350/257/221.py +0 -58
  44. l0n0lc//351/200/232/347/224/250.py +0 -134
  45. l0n0lc-0.8.4.dist-info/METADATA +0 -241
  46. l0n0lc-0.8.4.dist-info/RECORD +0 -12
  47. {l0n0lc-0.8.4.dist-info → l0n0lc-1.0.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,412 @@
1
+ """
2
+ 并行编译器模块
3
+
4
+ 提供并行编译依赖函数的功能,减少总编译时间。
5
+ """
6
+ import os
7
+ from typing import List, Optional, Set, Dict, Any
8
+ import multiprocessing
9
+
10
+
11
+ def 编译单个依赖(依赖信息: Dict[str, Any]) -> Dict[str, Any]:
12
+ """
13
+ 在子进程中编译单个依赖函数
14
+
15
+ Args:
16
+ 依赖信息: 包含转译器实例和编译所需信息的字典
17
+
18
+ Returns:
19
+ 编译结果字典
20
+ """
21
+ from .Py转Cpp转译器 import Py转Cpp转译器
22
+
23
+ transpiler: Py转Cpp转译器 = 依赖信息['transpiler']
24
+ 函数名 = 依赖信息['函数名']
25
+
26
+ try:
27
+ # 检查是否已编译
28
+ if transpiler.已编译:
29
+ return {
30
+ '函数名': 函数名,
31
+ '状态': '已编译',
32
+ '库路径': transpiler.文件管理器.获取完整路径(transpiler.获取库文件名())
33
+ }
34
+
35
+ # 检查缓存
36
+ 库路径 = transpiler.文件管理器.获取完整路径(transpiler.获取库文件名())
37
+ if os.path.exists(库路径):
38
+ from .日志工具 import 日志
39
+ 日志.缓存信息("加载依赖缓存", 函数名)
40
+ transpiler.分析(True)
41
+ transpiler.已编译 = True
42
+ return {
43
+ '函数名': 函数名,
44
+ '状态': '缓存命中',
45
+ '库路径': 库路径
46
+ }
47
+
48
+ # 编译
49
+ from .日志工具 import 日志
50
+ 日志.缓存信息("并行编译依赖", 函数名)
51
+ transpiler.编译()
52
+ transpiler.已编译 = True
53
+
54
+ return {
55
+ '函数名': 函数名,
56
+ '状态': '编译成功',
57
+ '库路径': 库路径
58
+ }
59
+
60
+ except Exception as e:
61
+ return {
62
+ '函数名': 函数名,
63
+ '状态': '编译失败',
64
+ '错误': str(e)
65
+ }
66
+
67
+
68
+ class 并行编译管理器:
69
+ """
70
+ 并行编译管理器
71
+
72
+ 分析依赖关系,并行编译独立的依赖函数。
73
+ """
74
+
75
+ def __init__(self, 最大进程数: Optional[int] = None):
76
+ """
77
+ 初始化并行编译管理器
78
+
79
+ Args:
80
+ 最大进程数: 最大并行进程数,默认为 CPU 核心数
81
+ """
82
+ if 最大进程数 is None:
83
+ # 默认使用 CPU 核心数,但至少为 1,最多为 8
84
+ self.最大进程数 = max(1, min(multiprocessing.cpu_count(), 8))
85
+ else:
86
+ self.最大进程数 = max(1, 最大进程数)
87
+
88
+ def 分析依赖层级(self, 依赖列表: List["Py转Cpp转译器"]) -> List[List["Py转Cpp转译器"]]: # type: ignore
89
+ """
90
+ 分析依赖关系,按层级分组
91
+
92
+ 返回的列表中,每个元素是一组可以并行编译的依赖。
93
+ 后面的层依赖前面的层。
94
+
95
+ Args:
96
+ 依赖列表: 依赖函数的转译器列表
97
+
98
+ Returns:
99
+ 分层后的依赖列表
100
+ """
101
+ from .日志工具 import 日志
102
+
103
+ # 收集所有依赖(包括递归依赖)
104
+ 所有依赖 = set()
105
+ 已处理 = set()
106
+
107
+ def 递归收集(dep):
108
+ if dep in 已处理:
109
+ return
110
+ 已处理.add(dep)
111
+ 所有依赖.add(dep)
112
+ for sub_dep in dep.依赖函数:
113
+ 递归收集(sub_dep)
114
+
115
+ for dep in 依赖列表:
116
+ 递归收集(dep)
117
+
118
+ if not 所有依赖:
119
+ 日志.调试("没有需要编译的依赖")
120
+ return []
121
+
122
+ # 计算每个依赖的深度(最长的依赖链)
123
+ 深度映射 = {}
124
+
125
+ def 计算深度(dep):
126
+ if dep in 深度映射:
127
+ return 深度映射[dep]
128
+
129
+ if not dep.依赖函数:
130
+ 深度映射[dep] = 0
131
+ else:
132
+ 最大子深度 = max(计算深度(sub_dep) for sub_dep in dep.依赖函数)
133
+ 深度映射[dep] = 最大子深度 + 1
134
+
135
+ return 深度映射[dep]
136
+
137
+ for dep in 所有依赖:
138
+ 计算深度(dep)
139
+
140
+ # 按深度分组
141
+ 层级映射: Dict[int, Set["Py转Cpp转译器"]] = {} # type: ignore
142
+ for dep, depth in 深度映射.items():
143
+ if depth not in 层级映射:
144
+ 层级映射[depth] = set()
145
+ 层级映射[depth].add(dep)
146
+
147
+ # 按层级排序
148
+ 层级列表 = []
149
+ for depth in sorted(层级映射.keys()):
150
+ 层级列表.append(list(层级映射[depth]))
151
+
152
+ 日志.调试(f"依赖分析完成:共 {len(所有依赖)} 个依赖,分为 {len(层级列表)} 个层级")
153
+
154
+ return 层级列表
155
+
156
+ def 并行编译依赖(
157
+ self,
158
+ 依赖列表: List["Py转Cpp转译器"], # type: ignore
159
+ 启用并行: bool = True
160
+ ) -> Dict[str, Any]:
161
+ """
162
+ 并行编译依赖函数
163
+
164
+ Args:
165
+ 依赖列表: 依赖函数的转译器列表
166
+ 启用并行: 是否启用并行编译
167
+
168
+ Returns:
169
+ 编译结果统计
170
+ """
171
+ from .日志工具 import 日志
172
+
173
+ if not 依赖列表:
174
+ 日志.调试("依赖列表为空,跳过并行编译")
175
+ return {
176
+ '总数': 0,
177
+ '成功': 0,
178
+ '失败': 0,
179
+ '缓存命中': 0,
180
+ '结果列表': []
181
+ }
182
+
183
+ if not 启用并行 or self.最大进程数 <= 1:
184
+ 日志.调试("并行编译未启用,使用串行编译")
185
+ return self._串行编译(依赖列表)
186
+
187
+ # 分析依赖层级
188
+ 层级列表 = self.分析依赖层级(依赖列表)
189
+
190
+ if not 层级列表:
191
+ return {
192
+ '总数': 0,
193
+ '成功': 0,
194
+ '失败': 0,
195
+ '缓存命中': 0,
196
+ '结果列表': []
197
+ }
198
+
199
+ 统计 = {
200
+ '总数': 0,
201
+ '成功': 0,
202
+ '失败': 0,
203
+ '缓存命中': 0,
204
+ '结果列表': []
205
+ }
206
+
207
+ # 按层级并行编译
208
+ for 层级索引, 当前层依赖 in enumerate(层级列表):
209
+ 日志.调试(f"编译第 {层级索引 + 1}/{len(层级列表)} 层,共 {len(当前层依赖)} 个依赖")
210
+
211
+ # 构建编译任务
212
+ 编译任务 = []
213
+ for dep in 当前层依赖:
214
+ 统计['总数'] += 1
215
+ 编译任务.append({
216
+ 'transpiler': dep,
217
+ '函数名': dep.函数名
218
+ })
219
+
220
+ # 并行编译当前层
221
+ 层级结果 = self._并行编译层级(编译任务)
222
+
223
+ # 统计结果
224
+ for 结果 in 层级结果:
225
+ 统计['结果列表'].append(结果)
226
+ if 结果['状态'] == '编译成功':
227
+ 统计['成功'] += 1
228
+ elif 结果['状态'] == '缓存命中':
229
+ 统计['缓存命中'] += 1
230
+ 统计['成功'] += 1
231
+ elif 结果['状态'] == '已编译':
232
+ 统计['成功'] += 1
233
+ else:
234
+ 统计['失败'] += 1
235
+
236
+ 日志.调试(
237
+ f"并行编译完成: 总数={统计['总数']}, "
238
+ f"成功={统计['成功']}, 失败={统计['失败']}, "
239
+ f"缓存命中={统计['缓存命中']}"
240
+ )
241
+
242
+ return 统计
243
+
244
+ def _并行编译层级(self, 编译任务: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
245
+ """
246
+ 并行编译单个层级的依赖
247
+
248
+ Args:
249
+ 编译任务: 编译任务列表
250
+
251
+ Returns:
252
+ 编译结果列表
253
+ """
254
+ from .日志工具 import 日志
255
+ from .Py转Cpp转译器 import Py转Cpp转译器
256
+ 结果列表 = []
257
+
258
+ # 由于 Python 的 multiprocessing 限制,无法直接序列化转译器实例
259
+ # 这里使用线程池而不是进程池
260
+ # 在实际编译中,C++ 编译器本身会并行处理
261
+ # Python 端的串行调用不会成为瓶颈
262
+
263
+ for 任务 in 编译任务:
264
+ transpiler: Py转Cpp转译器 = 任务['transpiler']
265
+ 函数名 = 任务['函数名']
266
+
267
+ try:
268
+ # 检查是否已编译
269
+ if transpiler.已编译:
270
+ 结果列表.append({
271
+ '函数名': 函数名,
272
+ '状态': '已编译',
273
+ '库路径': transpiler.文件管理器.获取完整路径(transpiler.获取库文件名())
274
+ })
275
+ continue
276
+
277
+ # 检查缓存
278
+ 库路径 = transpiler.文件管理器.获取完整路径(transpiler.获取库文件名())
279
+ if os.path.exists(库路径):
280
+ 日志.缓存信息("加载依赖缓存", 函数名)
281
+ transpiler.分析(True)
282
+ transpiler.已编译 = True
283
+ 结果列表.append({
284
+ '函数名': 函数名,
285
+ '状态': '缓存命中',
286
+ '库路径': 库路径
287
+ })
288
+ continue
289
+
290
+ # 编译
291
+ 日志.缓存信息("编译依赖", 函数名)
292
+ transpiler.编译()
293
+ transpiler.已编译 = True
294
+
295
+ 结果列表.append({
296
+ '函数名': 函数名,
297
+ '状态': '编译成功',
298
+ '库路径': 库路径
299
+ })
300
+
301
+ except Exception as e:
302
+ 结果列表.append({
303
+ '函数名': 函数名,
304
+ '状态': '编译失败',
305
+ '错误': str(e)
306
+ })
307
+
308
+ return 结果列表
309
+
310
+ def _串行编译(self, 依赖列表: List["Py转Cpp转译器"]) -> Dict[str, Any]: # type: ignore
311
+ """
312
+ 串行编译依赖函数(回退方案)
313
+
314
+ Args:
315
+ 依赖列表: 依赖函数的转译器列表
316
+
317
+ Returns:
318
+ 编译结果统计
319
+ """
320
+ from .日志工具 import 日志
321
+
322
+ # 递归收集所有依赖
323
+ 所有依赖 = set()
324
+ 已处理 = set()
325
+
326
+ def 递归收集(dep):
327
+ if dep in 已处理:
328
+ return
329
+ 已处理.add(dep)
330
+ 所有依赖.add(dep)
331
+ for sub_dep in dep.依赖函数:
332
+ 递归收集(sub_dep)
333
+
334
+ for dep in 依赖列表:
335
+ 递归收集(dep)
336
+
337
+ 统计 = {
338
+ '总数': len(所有依赖),
339
+ '成功': 0,
340
+ '失败': 0,
341
+ '缓存命中': 0,
342
+ '结果列表': []
343
+ }
344
+
345
+ for dep in 所有依赖:
346
+ 函数名 = dep.函数名
347
+
348
+ try:
349
+ # 检查是否已编译
350
+ if dep.已编译:
351
+ 统计['成功'] += 1
352
+ 统计['结果列表'].append({
353
+ '函数名': 函数名,
354
+ '状态': '已编译'
355
+ })
356
+ continue
357
+
358
+ # 检查缓存
359
+ 库路径 = dep.文件管理器.获取完整路径(dep.获取库文件名())
360
+ if os.path.exists(库路径):
361
+ 日志.缓存信息("加载依赖缓存", 函数名)
362
+ dep.分析(True)
363
+ dep.已编译 = True
364
+ 统计['成功'] += 1
365
+ 统计['缓存命中'] += 1
366
+ 统计['结果列表'].append({
367
+ '函数名': 函数名,
368
+ '状态': '缓存命中',
369
+ '库路径': 库路径
370
+ })
371
+ continue
372
+
373
+ # 编译
374
+ 日志.缓存信息("编译依赖", 函数名)
375
+ dep.编译()
376
+ dep.已编译 = True
377
+ 统计['成功'] += 1
378
+ 统计['结果列表'].append({
379
+ '函数名': 函数名,
380
+ '状态': '编译成功',
381
+ '库路径': 库路径
382
+ })
383
+
384
+ except Exception as e:
385
+ 统计['失败'] += 1
386
+ 统计['结果列表'].append({
387
+ '函数名': 函数名,
388
+ '状态': '编译失败',
389
+ '错误': str(e)
390
+ })
391
+
392
+ return 统计
393
+
394
+
395
+ def 获取最大进程数() -> int:
396
+ """
397
+ 获取默认的最大进程数
398
+
399
+ 可以通过环境变量 L0N0LC_MAX_PROCESSES 覆盖
400
+
401
+ Returns:
402
+ 最大进程数
403
+ """
404
+ 环境变量值 = os.environ.get('L0N0LC_MAX_PROCESSES')
405
+ if 环境变量值:
406
+ try:
407
+ return max(1, min(int(环境变量值), 16))
408
+ except ValueError:
409
+ pass
410
+
411
+ # 默认使用 CPU 核心数,但至少为 1,最多为 8
412
+ return max(1, min(multiprocessing.cpu_count(), 8))