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
@@ -1,134 +0,0 @@
1
- import re
2
- import os
3
- import inspect
4
- from typing import List, Optional, Any, Dict
5
-
6
-
7
- def 变量名(var):
8
- frame = inspect.currentframe()
9
- if frame is None:
10
- return
11
- frame = frame.f_back
12
- if frame is None:
13
- return
14
- for name, value in frame.f_locals.items():
15
- if value is var:
16
- return name
17
- for name, value in frame.f_globals.items():
18
- if value is var:
19
- return name
20
- return None
21
-
22
-
23
- def 上层变量名(var):
24
- frame = inspect.currentframe()
25
- if frame is None:
26
- return
27
- frame = frame.f_back
28
- if frame is None:
29
- return
30
- counter = 0
31
- for name, value in frame.f_locals.items():
32
- if value is var:
33
- counter += 1
34
- if counter > 1:
35
- return name
36
- for name, value in frame.f_globals.items():
37
- if value is var:
38
- counter += 1
39
- if counter > 1:
40
- return name
41
- return None
42
-
43
-
44
- def 十进制转换为其他进制(数值: int, 进制: int, digits="0123456789ABCDEF"):
45
- if 数值 == 0:
46
- return "0"
47
- result = ""
48
- is_negative = 数值 < 0
49
- 数值 = abs(数值)
50
- while 数值 > 0:
51
- 数值, remainder = divmod(数值, 进制) # 除基取余
52
- result = digits[remainder] + result # 余数映射字符
53
- return ("-" if is_negative else "") + result
54
-
55
-
56
- class c函数映射:
57
- def __init__(
58
- self, 目标函数,
59
- include目录: Optional[List[str]],
60
- 库列表: Optional[List[str]],
61
- 库目录: Optional[List[str]]) -> None:
62
- self.目标函数 = 目标函数
63
- self.include目录 = include目录 or []
64
- self.库列表 = 库列表 or []
65
- self.库目录 = 库目录 or []
66
-
67
-
68
- class 通用信息:
69
- 直接调用函数 = set()
70
- 函数映射表: Dict[Any, c函数映射] = {}
71
- include表 = set()
72
- 连接库表 = set()
73
- 变量最大ID = 0
74
- python内置映射 = {}
75
- 使用unicode编程 = True
76
- 工作文件夹地址 = './l0n0lcoutput'
77
-
78
- @staticmethod
79
- def 缓存接调用函数():
80
- 通用信息.直接调用函数.add(range)
81
-
82
- @staticmethod
83
- def 添加内置映射(v):
84
- 通用信息.python内置映射[v.__name__] = v
85
-
86
- @staticmethod
87
- def 内置映射():
88
- for v in [int, float, str, bool, range, complex, set, tuple, list, dict,
89
- print, input, abs, round, pow, divmod, sum, min, max,
90
- isinstance, len, open, ]:
91
- 通用信息.添加内置映射(v)
92
-
93
-
94
- 通用信息.内置映射()
95
-
96
-
97
- def 直接调用函数(fn):
98
- 通用信息.直接调用函数.add(fn)
99
- return fn
100
-
101
-
102
- def 映射函数(
103
- 被映射函数,
104
- include目录: Optional[List[str]] = None,
105
- 链接库列表: Optional[List[str]] = None,
106
- 库目录列表: Optional[List[str]] = None):
107
- def 装饰器(映射目标):
108
- 通用信息.函数映射表[被映射函数] = c函数映射(映射目标, include目录, 链接库列表, 库目录列表)
109
- return 映射目标
110
- return 装饰器
111
-
112
-
113
- def 有非英文变量字符(s):
114
- return bool(re.search(r'[^A-Za-z0-9_]', s))
115
-
116
-
117
- def 生成变量Id(原始名字: str | None = None):
118
- if 原始名字 is not None and (通用信息.使用unicode编程 or not 有非英文变量字符(原始名字)):
119
- return 原始名字
120
- ret = f'_{通用信息.变量最大ID}'
121
- 通用信息.变量最大ID += 1
122
- return ret
123
-
124
-
125
- def 尝试创建文件夹(文件夹名: str):
126
- if os.path.exists(文件夹名):
127
- return
128
- os.mkdir(文件夹名)
129
-
130
-
131
- def toCString(v):
132
- if isinstance(v, str):
133
- return f'u8"{v}"'
134
- return str(v)
@@ -1,241 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: l0n0lc
3
- Version: 0.8.4
4
- Summary: 一个将python函数翻译为c++函数并运行的jit编译器
5
- Classifier: Programming Language :: Python :: 3
6
- Requires-Python: >=3.10
7
- Description-Content-Type: text/markdown
8
- License-File: LICENSE
9
- Dynamic: license-file
10
-
11
-
12
- # 将python函数翻译为c++函数并运行
13
- ## 1. 安装
14
- ```
15
- pip install l0n0lc
16
- ```
17
- ## 2. hello_world.py
18
- ```python
19
- import l0n0lc as lc
20
- import math
21
-
22
-
23
- @lc.映射函数(math.ceil, ['<cmath>'])
24
- def cpp_ceil(v):
25
- return f'std::ceil({lc.toCString(v)});'
26
-
27
-
28
- @lc.映射函数(print, ['<iostream>'])
29
- def cpp_cout(*args):
30
- code = f'std::cout'
31
- for arg in args:
32
- code += f'<< {lc.toCString(arg)} << " "'
33
- code += '<< std::endl;'
34
- return code
35
-
36
-
37
- def py_cin(v):
38
- pass
39
-
40
-
41
- @lc.映射函数(py_cin, ['<iostream>'])
42
- def cpp_cin(v):
43
- return f'std::cout << u8"请输入>>>"; std::cin >> {v};'
44
-
45
-
46
- @lc.直接调用函数
47
- def test_直接调用():
48
- return 123
49
-
50
-
51
- def test_other_fn(a: int, b: int) -> int:
52
- return a - b
53
-
54
-
55
- @lc.jit()
56
- def test编译的函数(a: int, b: int) -> int:
57
- return a * b
58
-
59
-
60
- @lc.jit(每次运行都重新编译=True)
61
- def test_add(a: int, b: int) -> int:
62
- if a > 1:
63
- return a + b
64
- for i in range(1, 10, 2):
65
- a += i
66
- for i in [1, 2, 3]:
67
- a += i
68
- a = math.ceil(12.5)
69
- cc = {'a': 1, 'b': 2}
70
- cc['c'] = 3
71
- print('输出map:')
72
- for ii in cc:
73
- print(ii.first, ii.second) # type: ignore
74
- aa = [1, 3, 2]
75
- aa[0] = 134
76
- print('输出list:')
77
- for i in range(3):
78
- print(i, aa[i])
79
- print('Hello World', a, b)
80
- print('test_other_fn', test_other_fn(a, b))
81
- print('test编译的函数', test编译的函数(a, b))
82
- v = 0
83
- vv = True and (False or 1)
84
- print('vv:', vv)
85
- while (True):
86
- py_cin(v)
87
- if v > 100:
88
- break
89
- else:
90
- print('输入的', v, '小于等于100')
91
- return a + b + 1 + test_直接调用() + v
92
-
93
-
94
- print('结果:', test_add(1, 3))
95
-
96
- ```
97
-
98
- ## 3. 运行hello_world.py
99
- ```
100
- uv run tests/hello_world.py
101
- # 输入: b'1\n2\n100\n101\n'
102
- ```
103
- ```bash
104
- 输出map:
105
- c 3
106
- a 1
107
- b 2
108
- 输出list:
109
- 0 134
110
- 1 3
111
- 2 2
112
- Hello World 13 3
113
- test_other_fn 10
114
- test编译的函数 39
115
- vv: 1
116
- 请输入>>>输入的 1 小于等于100
117
- 请输入>>>输入的 2 小于等于100
118
- 请输入>>>输入的 100 小于等于100
119
- 请输入>>>结果: 241
120
-
121
- ```
122
-
123
- ## 4. 查看输出文件
124
- ```bash
125
- ls -al ./l0n0lcoutput
126
- total 96
127
- drwxr-xr-x 2 root root 4096 Sep 16 01:49 .
128
- drwxrwxrwx 11 1000 1000 4096 Sep 16 01:41 ..
129
- -rw-r--r-- 1 root root 1318 Sep 16 01:49 test_add_@6a812a013615c16d.cpp
130
- -rw-r--r-- 1 root root 246 Sep 16 01:49 test_add_@6a812a013615c16d.h
131
- -rwxr-xr-x 1 root root 29968 Sep 16 01:49 test_add_@6a812a013615c16d.so
132
- -rw-r--r-- 1 root root 121 Sep 16 01:49 test_other_fn_@75fdd928ab58a8e3.cpp
133
- -rw-r--r-- 1 root root 93 Sep 16 01:49 test_other_fn_@75fdd928ab58a8e3.h
134
- -rwxr-xr-x 1 root root 15616 Sep 16 01:49 test_other_fn_@75fdd928ab58a8e3.so
135
- -rw-r--r-- 1 root root 185 Sep 16 01:41 test编译的函数_@3bf4501e0408a243.cpp
136
- -rw-r--r-- 1 root root 151 Sep 16 01:41 test编译的函数_@3bf4501e0408a243.h
137
- -rwxr-xr-x 1 root root 15656 Sep 16 01:41 test编译的函数_@3bf4501e0408a243.so
138
-
139
- ```
140
- ## 5. test_add_@6a812a013615c16d.cpp
141
- ```c++
142
- #include "test_add_@6a812a013615c16d.h"
143
- extern "C" int64_t test_add (int64_t a, int64_t b)
144
- {
145
- if ((a > 1))
146
- {
147
- return a + b;
148
- }
149
-
150
- for (int64_t i = 1; i < 10; i += 2)
151
- {
152
- a = a + i;
153
- }
154
-
155
- for (auto i : {1,2,3})
156
- {
157
- a = a + i;
158
- }
159
-
160
- a = std::ceil(12.5);;
161
- std::unordered_map<std::string, int64_t> cc = {{ u8"a", 1 },{ u8"b", 2 }};
162
- cc[u8"c"] = 3;
163
- std::cout<< u8"输出map:" << " "<< std::endl;
164
- for (auto ii : cc)
165
- {
166
- std::cout<< ii.first << " "<< ii.second << " "<< std::endl;
167
- }
168
-
169
- int64_t aa[] = {1,3,2};
170
- aa[0] = 134;
171
- std::cout<< u8"输出list:" << " "<< std::endl;
172
- for (int64_t i = 0; i < 3; ++i)
173
- {
174
- std::cout<< i << " "<< aa[i] << " "<< std::endl;
175
- }
176
-
177
- std::cout<< u8"Hello World" << " "<< a << " "<< b << " "<< std::endl;
178
- std::cout<< u8"test_other_fn" << " "<< test_other_fn(a,b) << " "<< std::endl;
179
- std::cout<< u8"test编译的函数" << " "<< function_74657374e7bc96e8af91e79a84e587bde695b0(a,b) << " "<< std::endl;
180
- auto v = 0;
181
- auto vv = true&&false||1;
182
- std::cout<< u8"vv:" << " "<< vv << " "<< std::endl;
183
- while (true)
184
- {
185
- std::cout << u8"请输入>>>"; std::cin >> v;
186
- if ((v > 100))
187
- {
188
- break;
189
- }
190
-
191
- {
192
- std::cout<< u8"输入的" << " "<< v << " "<< u8"小于等于100" << " "<< std::endl;
193
- }
194
-
195
- }
196
-
197
- return a + b + 1 + 123 + v;
198
- }
199
-
200
- ```
201
- ## 6. test_add_@6a812a013615c16d.h
202
- ```c++
203
- #include "test_other_fn_@75fdd928ab58a8e3.h"
204
- #include "test编译的函数_@3bf4501e0408a243.h"
205
- #include <cmath>
206
- #include <cstdint>
207
- #include <iostream>
208
- #include <string>
209
- #include <unordered_map>
210
- extern "C" int64_t test_add (int64_t a, int64_t b);
211
- ```
212
- ## 7. test_other_fn_@75fdd928ab58a8e3.cpp
213
- ```c++
214
- #include "test_other_fn_@75fdd928ab58a8e3.h"
215
- extern "C" int64_t test_other_fn (int64_t a, int64_t b)
216
- {
217
- return a - b;
218
- }
219
-
220
- ```
221
- ## 8. test_other_fn_@75fdd928ab58a8e3.h
222
- ```c++
223
- #include <cstdint>
224
- #include <string>
225
- extern "C" int64_t test_other_fn (int64_t a, int64_t b);
226
- ```
227
- ## 9. test编译的函数_@3bf4501e0408a243.cpp
228
- ```c++
229
- #include "test编译的函数_@3bf4501e0408a243.h"
230
- extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b)
231
- {
232
- return a * b;
233
- }
234
-
235
- ```
236
- ## 10. test编译的函数_@3bf4501e0408a243.h
237
- ```c++
238
- #include <cstdint>
239
- #include <string>
240
- extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b);
241
- ```
@@ -1,12 +0,0 @@
1
- l0n0lc/StdList.py,sha256=fA6sWAfW2JgDUhQDK2Hlx_PPuSdLwTcCTk5aha4zA-Q,863
2
- l0n0lc/StdMap.py,sha256=TIVKqhT078cjLIM0Zlq-TwGFSy-KwOyJe00BLFPVxr8,735
3
- l0n0lc/__init__.py,sha256=fUC6TMeN_fEL7HDazrBEdoWOQkXi5uSGZb7LZj6juog,137
4
- l0n0lc/c基础处理.py,sha256=FMauoVx4-33JXl4OLpUl1D6NCkLjk6yBH7do9WnT0Wg,5671
5
- l0n0lc/jit.py,sha256=MNvtnt_SPqwdJWzvkZKOSwrdN7zqjCx6KLhy5Z5bJAo,23946
6
- l0n0lc/编译.py,sha256=Ty4gPDHAB1jn8LgnE4w3R06bOAEeYr8iwqahYf6QeHI,2154
7
- l0n0lc/通用.py,sha256=O_Y4bbW1WzHCJkibxAy9WGACv-aEZJLG-fEeVBcAbBQ,3649
8
- l0n0lc-0.8.4.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
9
- l0n0lc-0.8.4.dist-info/METADATA,sha256=FM7tcMjK56Kteal4Er5l8MB2pGGaU77UDaWRH2E2em0,5660
10
- l0n0lc-0.8.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- l0n0lc-0.8.4.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
12
- l0n0lc-0.8.4.dist-info/RECORD,,