l0n0lc 0.8.6__py3-none-any.whl → 0.8.8__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.
- l0n0lc/c/345/237/272/347/241/200/345/244/204/347/220/206.py +18 -22
- l0n0lc/jit.py +38 -18
- l0n0lc//351/200/232/347/224/250.py +29 -0
- l0n0lc-0.8.8.dist-info/METADATA +489 -0
- l0n0lc-0.8.8.dist-info/RECORD +12 -0
- l0n0lc-0.8.6.dist-info/METADATA +0 -587
- l0n0lc-0.8.6.dist-info/RECORD +0 -12
- {l0n0lc-0.8.6.dist-info → l0n0lc-0.8.8.dist-info}/WHEEL +0 -0
- {l0n0lc-0.8.6.dist-info → l0n0lc-0.8.8.dist-info}/licenses/LICENSE +0 -0
- {l0n0lc-0.8.6.dist-info → l0n0lc-0.8.8.dist-info}/top_level.txt +0 -0
@@ -41,27 +41,30 @@ def 执行额外函数(函数列表: List, *args):
|
|
41
41
|
|
42
42
|
|
43
43
|
额外py转ctypes函数 = []
|
44
|
+
py2ctypes映射表 = {
|
45
|
+
int: ctypes.c_int64,
|
46
|
+
float: ctypes.c_float,
|
47
|
+
str: ctypes.c_char_p,
|
48
|
+
bool: ctypes.c_bool,
|
49
|
+
指针: ctypes.c_void_p,
|
50
|
+
}
|
44
51
|
|
45
52
|
|
46
53
|
def py类型转ctypes类型(类型):
|
47
54
|
ret = 执行额外函数(额外py转ctypes函数, 类型)
|
48
55
|
if ret is not None:
|
49
56
|
return ret
|
50
|
-
|
51
|
-
# 基础类型
|
52
|
-
if 类型 is int:
|
53
|
-
return ctypes.c_int64
|
54
|
-
if 类型 is float:
|
55
|
-
return ctypes.c_float
|
56
|
-
if 类型 is str:
|
57
|
-
return ctypes.c_char_p
|
58
|
-
if 类型 is bool:
|
59
|
-
return ctypes.c_bool
|
60
|
-
if 类型 is 指针:
|
61
|
-
return ctypes.c_void_p
|
57
|
+
return py2ctypes映射表.get(类型)
|
62
58
|
|
63
59
|
|
64
60
|
额外py转c函数 = []
|
61
|
+
py2c类型映射表 = {
|
62
|
+
int: cpp类型.INT16_T,
|
63
|
+
float: cpp类型.FLOAT,
|
64
|
+
str: cpp类型.STRING,
|
65
|
+
bool: cpp类型.BOOL,
|
66
|
+
指针: cpp类型.VOID_P,
|
67
|
+
}
|
65
68
|
|
66
69
|
|
67
70
|
def py类型转c类型(类型):
|
@@ -70,16 +73,9 @@ def py类型转c类型(类型):
|
|
70
73
|
return ret
|
71
74
|
|
72
75
|
# 基础类型
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
return cpp类型.FLOAT
|
77
|
-
if 类型 is str:
|
78
|
-
return cpp类型.STRING
|
79
|
-
if 类型 is bool:
|
80
|
-
return cpp类型.BOOL
|
81
|
-
if 类型 is 指针:
|
82
|
-
return cpp类型.VOID_P
|
76
|
+
ret = py2c类型映射表.get(类型)
|
77
|
+
if ret is not None:
|
78
|
+
return ret
|
83
79
|
|
84
80
|
origin = get_origin(类型)
|
85
81
|
args = get_args(类型)
|
l0n0lc/jit.py
CHANGED
@@ -6,7 +6,7 @@ from typing import Callable, Any, List, Dict
|
|
6
6
|
from .c基础处理 import *
|
7
7
|
from .StdList import StdList
|
8
8
|
from .StdMap import StdUnorderedMap
|
9
|
-
from .通用 import 通用信息, 有非英文变量字符,
|
9
|
+
from .通用 import 通用信息, 有非英文变量字符, 尝试创建文件夹, c类型映射
|
10
10
|
from .编译 import cpp编译器
|
11
11
|
|
12
12
|
|
@@ -119,17 +119,17 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
119
119
|
语法树 = ast.parse(self.源代码)
|
120
120
|
self.visit(语法树)
|
121
121
|
# 读取依赖函数
|
122
|
-
cpps = [f'{通用信息.工作文件夹地址}/{self.获取cpp文件名()}']
|
122
|
+
cpps = set([f'{通用信息.工作文件夹地址}/{self.获取cpp文件名()}'])
|
123
123
|
for b in self.依赖函数:
|
124
124
|
self.include目录.add(f'"{b.获取h文件名()}"')
|
125
|
-
cpps.
|
125
|
+
cpps.add(f'{通用信息.工作文件夹地址}/{b.获取cpp文件名()}')
|
126
126
|
|
127
127
|
self.将代码保存到文件()
|
128
128
|
self.c编译器.include目录列表 = list(self.include目录)
|
129
129
|
self.c编译器.库目录列表 = list(self.库目录)
|
130
130
|
self.c编译器.链接库 = list(self.链接库列表)
|
131
131
|
输出路径 = f'{通用信息.工作文件夹地址}/{self.获取库文件名()}'
|
132
|
-
self.c编译器.编译为动态库(cpps, 输出路径=输出路径)
|
132
|
+
self.c编译器.编译为动态库(list(cpps), 输出路径=输出路径)
|
133
133
|
|
134
134
|
def 添加c代码(self, 代码: str):
|
135
135
|
self.代码序列.append(c代码(代码, self.当前上下文层级))
|
@@ -189,7 +189,7 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
189
189
|
|
190
190
|
if isinstance(value, ast.Attribute):
|
191
191
|
对象 = self.获取值(value.value)
|
192
|
-
if isinstance(对象, c
|
192
|
+
if isinstance(对象, (c变量, c类型映射)):
|
193
193
|
return c获取属性(对象, value.attr)
|
194
194
|
if 对象 is None:
|
195
195
|
self.抛出代码异常(f'没找到{value.value}', value)
|
@@ -255,7 +255,7 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
255
255
|
if isinstance(op, ast.NotEq):
|
256
256
|
ret += f'{left} != {right}'
|
257
257
|
if isinstance(op, ast.Lt):
|
258
|
-
ret += f'{left} < {right}
|
258
|
+
ret += f'{left} < {right}'
|
259
259
|
if isinstance(op, ast.LtE):
|
260
260
|
ret += f'{left} <= {right}'
|
261
261
|
if isinstance(op, ast.Gt):
|
@@ -284,8 +284,6 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
284
284
|
return f'{left} / {right}'
|
285
285
|
if isinstance(op, ast.Mod):
|
286
286
|
return f'{left} % {right}'
|
287
|
-
if isinstance(op, ast.Pow):
|
288
|
-
return f'{left} ** {right}'
|
289
287
|
if isinstance(op, ast.BitAnd):
|
290
288
|
return f'{left} & {right}'
|
291
289
|
if isinstance(op, ast.BitOr):
|
@@ -299,14 +297,34 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
299
297
|
|
300
298
|
self.抛出代码异常(f"暂不支持的运算符: {type(op).__name__}", node)
|
301
299
|
|
300
|
+
def 构建参数列表文本(self, args: List[ast.expr]):
|
301
|
+
参数列表 = [str(self.获取值(arg)) for arg in args]
|
302
|
+
return ','.join(参数列表)
|
303
|
+
|
302
304
|
def 调用Call(self, node: ast.Call):
|
303
|
-
#
|
305
|
+
# 获取函数
|
304
306
|
fn = self.获取值(node.func)
|
307
|
+
|
308
|
+
# 如果是创建类型
|
309
|
+
if inspect.isclass(fn):
|
310
|
+
c类型 = 通用信息.类型映射表.get(fn)
|
311
|
+
if c类型 is not None:
|
312
|
+
for include目录 in c类型.include目录:
|
313
|
+
self.include目录.add(include目录)
|
314
|
+
for 链接库 in c类型.库列表:
|
315
|
+
self.链接库列表.add(链接库)
|
316
|
+
for 库目录 in c类型.库目录:
|
317
|
+
self.库目录.add(库目录)
|
318
|
+
参数文本 = self.构建参数列表文本(node.args)
|
319
|
+
return c函数调用(c类型, 参数文本)
|
320
|
+
|
321
|
+
# 直接调用函数
|
305
322
|
if fn in 通用信息.直接调用函数:
|
306
323
|
参数列表 = [self.获取值(arg) for arg in node.args]
|
307
324
|
self.正在调用直接函数 = True
|
308
325
|
return fn(*参数列表)
|
309
326
|
|
327
|
+
# python函数对应的c++函数
|
310
328
|
映射函数 = 通用信息.函数映射表.get(fn)
|
311
329
|
if 映射函数 is not None:
|
312
330
|
参数列表 = [self.获取值(arg) for arg in node.args]
|
@@ -319,23 +337,25 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
319
337
|
|
320
338
|
return 映射函数.目标函数(*参数列表)
|
321
339
|
|
322
|
-
if not isinstance(fn, Callable):
|
340
|
+
if not isinstance(fn, Callable) and not isinstance(fn, c获取属性):
|
323
341
|
self.抛出代码异常(f'{ast.dump(node.func)} 没找到', node)
|
324
342
|
|
325
343
|
if len(node.keywords) > 0:
|
326
|
-
self
|
327
|
-
|
328
|
-
参数列表 = [str(self.获取值(arg)) for arg in node.args]
|
329
|
-
参数字符串 = ','.join(参数列表)
|
344
|
+
self.抛出代码异常('暂不支持 keywords 函数调用', node)
|
330
345
|
|
346
|
+
参数文本 = self.构建参数列表文本(node.args)
|
347
|
+
# 是否是编译好的函数
|
331
348
|
if isinstance(fn, py2cpp编译器):
|
332
349
|
self.依赖函数.append(fn)
|
333
|
-
return c函数调用(fn.c函数名,
|
350
|
+
return c函数调用(fn.c函数名, 参数文本)
|
351
|
+
elif isinstance(fn, c获取属性):
|
352
|
+
return c函数调用(fn, 参数文本)
|
353
|
+
# 编译该函数
|
334
354
|
else:
|
335
355
|
依赖函数编译器 = self.__class__(fn, self.c编译器)
|
336
356
|
依赖函数编译器.编译()
|
337
357
|
self.依赖函数.append(依赖函数编译器)
|
338
|
-
return c函数调用(fn.__name__,
|
358
|
+
return c函数调用(fn.__name__, 参数文本)
|
339
359
|
|
340
360
|
def 获取Subscript(self, node: ast.Subscript):
|
341
361
|
对象 = self.获取值(node.value)
|
@@ -490,7 +510,7 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
490
510
|
|
491
511
|
def visit_Call(self, node: ast.Call) -> Any:
|
492
512
|
代码 = self.调用Call(node)
|
493
|
-
self.添加c代码(
|
513
|
+
self.添加c代码(f'{代码};')
|
494
514
|
|
495
515
|
def _赋值(self, target, 值, node, c强转类型: str | None = None):
|
496
516
|
目标 = self.获取值(target)
|
@@ -557,7 +577,7 @@ class py2cpp编译器(ast.NodeVisitor):
|
|
557
577
|
return '\n'.join(include代码列表)
|
558
578
|
|
559
579
|
def 获取h代码(self):
|
560
|
-
return self.获取includes() + '\n' + self.获取定义() + ';'
|
580
|
+
return '#pragma once\n' + self.获取includes() + '\n' + self.获取定义() + ';'
|
561
581
|
|
562
582
|
def 获取无后缀文件名(self):
|
563
583
|
return f'{self.文件前缀}{self.代码哈希值}'
|
@@ -64,10 +64,29 @@ class c函数映射:
|
|
64
64
|
self.库列表 = 库列表 or []
|
65
65
|
self.库目录 = 库目录 or []
|
66
66
|
|
67
|
+
def __str__(self) -> str:
|
68
|
+
return self.目标函数
|
69
|
+
|
70
|
+
|
71
|
+
class c类型映射:
|
72
|
+
def __init__(
|
73
|
+
self, 目标类型,
|
74
|
+
include目录: Optional[List[str]],
|
75
|
+
库列表: Optional[List[str]],
|
76
|
+
库目录: Optional[List[str]]) -> None:
|
77
|
+
self.目标类型 = 目标类型
|
78
|
+
self.include目录 = include目录 or []
|
79
|
+
self.库列表 = 库列表 or []
|
80
|
+
self.库目录 = 库目录 or []
|
81
|
+
|
82
|
+
def __str__(self) -> str:
|
83
|
+
return self.目标类型
|
84
|
+
|
67
85
|
|
68
86
|
class 通用信息:
|
69
87
|
直接调用函数 = set()
|
70
88
|
函数映射表: Dict[Any, c函数映射] = {}
|
89
|
+
类型映射表: Dict[Any, c类型映射] = {}
|
71
90
|
include表 = set()
|
72
91
|
连接库表 = set()
|
73
92
|
变量最大ID = 0
|
@@ -110,6 +129,16 @@ def 映射函数(
|
|
110
129
|
return 装饰器
|
111
130
|
|
112
131
|
|
132
|
+
def 映射类型(被映射类型,
|
133
|
+
include目录: Optional[List[str]] = None,
|
134
|
+
链接库列表: Optional[List[str]] = None,
|
135
|
+
库目录列表: Optional[List[str]] = None):
|
136
|
+
def 装饰器(映射目标):
|
137
|
+
通用信息.类型映射表[映射目标] = c类型映射(被映射类型, include目录, 链接库列表, 库目录列表)
|
138
|
+
return 映射目标
|
139
|
+
return 装饰器
|
140
|
+
|
141
|
+
|
113
142
|
def 有非英文变量字符(s):
|
114
143
|
return bool(re.search(r'[^A-Za-z0-9_]', s))
|
115
144
|
|
@@ -0,0 +1,489 @@
|
|
1
|
+
Metadata-Version: 2.4
|
2
|
+
Name: l0n0lc
|
3
|
+
Version: 0.8.8
|
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.映射类型('std::vector<int>', ['<vector>'])
|
61
|
+
class CppVectorInt:
|
62
|
+
def push_back(self, v):
|
63
|
+
pass
|
64
|
+
|
65
|
+
def size(self):
|
66
|
+
return 0
|
67
|
+
|
68
|
+
def __getitem__(self, key):
|
69
|
+
return 0
|
70
|
+
|
71
|
+
|
72
|
+
@lc.jit()
|
73
|
+
def jit_all_ops(a: int, b: int) -> int:
|
74
|
+
# 常量与基础赋值
|
75
|
+
x = 42
|
76
|
+
y: int = a + b
|
77
|
+
z = 3.14
|
78
|
+
flag = True
|
79
|
+
nums = [1, 2, 3]
|
80
|
+
tup = (4, 5)
|
81
|
+
mp = {1: 10, 2: 20}
|
82
|
+
|
83
|
+
# 一元运算
|
84
|
+
pos = +a
|
85
|
+
neg = -b
|
86
|
+
inv = ~a
|
87
|
+
not_flag = not flag
|
88
|
+
|
89
|
+
# 二元运算
|
90
|
+
add = a + b
|
91
|
+
sub = a - b
|
92
|
+
mul = a * b
|
93
|
+
div = a / (b if b != 0 else 1)
|
94
|
+
mod = a % (b if b != 0 else 1)
|
95
|
+
band = a & b
|
96
|
+
bor = a | b
|
97
|
+
bxor = a ^ b
|
98
|
+
lshift = a << 1
|
99
|
+
rshift = a >> 1
|
100
|
+
|
101
|
+
# 比较运算
|
102
|
+
cmp1 = a == b
|
103
|
+
cmp2 = a != b
|
104
|
+
cmp3 = a < b
|
105
|
+
cmp4 = a <= b
|
106
|
+
cmp5 = a > b
|
107
|
+
cmp6 = a >= b
|
108
|
+
|
109
|
+
# 逻辑运算与三元表达式
|
110
|
+
logic_and = cmp1 and cmp2
|
111
|
+
logic_or = cmp3 or cmp4
|
112
|
+
ternary = a if a > b else b
|
113
|
+
|
114
|
+
# if / else
|
115
|
+
if a > b:
|
116
|
+
y += 1
|
117
|
+
else:
|
118
|
+
y -= 1
|
119
|
+
|
120
|
+
# for 循环 range
|
121
|
+
for i in range(3):
|
122
|
+
y += i
|
123
|
+
|
124
|
+
# for 循环 列表
|
125
|
+
for v in nums:
|
126
|
+
y += v
|
127
|
+
if v == 2:
|
128
|
+
continue
|
129
|
+
if v == 3:
|
130
|
+
break
|
131
|
+
|
132
|
+
# while 循环
|
133
|
+
count = 0
|
134
|
+
while count < 2:
|
135
|
+
y += count
|
136
|
+
count += 1
|
137
|
+
|
138
|
+
# 增强赋值
|
139
|
+
y += 5
|
140
|
+
y -= 1
|
141
|
+
y *= 2
|
142
|
+
y //= 2
|
143
|
+
y %= 10
|
144
|
+
y &= 7
|
145
|
+
y |= 3
|
146
|
+
y ^= 1
|
147
|
+
y <<= 1
|
148
|
+
y >>= 1
|
149
|
+
|
150
|
+
# 下标访问
|
151
|
+
first_num = nums[0]
|
152
|
+
mp_val = mp[1]
|
153
|
+
y += first_num + mp_val
|
154
|
+
|
155
|
+
vector = CppVectorInt()
|
156
|
+
vector.push_back(count)
|
157
|
+
vector.push_back(y)
|
158
|
+
for i in range(vector.size()):
|
159
|
+
print('vector->', i, '=', vector[i])
|
160
|
+
return y
|
161
|
+
|
162
|
+
@lc.jit(每次运行都重新编译=True)
|
163
|
+
def test_add(a: int, b: int) -> int:
|
164
|
+
if a > 1:
|
165
|
+
return a + b
|
166
|
+
for i in range(1, 10, 2):
|
167
|
+
a += i
|
168
|
+
for i in [1, 2, 3]:
|
169
|
+
a += i
|
170
|
+
a = math.ceil(12.5)
|
171
|
+
cc = {'a': 1, 'b': 2}
|
172
|
+
cc['c'] = 3
|
173
|
+
print('输出map:')
|
174
|
+
for ii in cc:
|
175
|
+
print(ii.first, ii.second) # type: ignore
|
176
|
+
aa = [1, 3, 2]
|
177
|
+
aa[0] = 134
|
178
|
+
print('输出list:')
|
179
|
+
for i in range(3):
|
180
|
+
print(i, aa[i])
|
181
|
+
print('Hello World', a, b)
|
182
|
+
print('test_other_fn', test_other_fn(a, b))
|
183
|
+
print('test编译的函数', test编译的函数(a, b))
|
184
|
+
|
185
|
+
print('测试所有操作:')
|
186
|
+
jit_all_ops(a, b)
|
187
|
+
|
188
|
+
v = 0
|
189
|
+
vv = True and (False or 1)
|
190
|
+
print('vv:', vv)
|
191
|
+
print('测试while:')
|
192
|
+
while (vv):
|
193
|
+
py_cin(v)
|
194
|
+
if v > 100:
|
195
|
+
break
|
196
|
+
else:
|
197
|
+
print('输入的', v, '小于等于100')
|
198
|
+
return a + b + 1 + test_直接调用() + v
|
199
|
+
|
200
|
+
|
201
|
+
print('结果:', test_add(1, 3))
|
202
|
+
|
203
|
+
```
|
204
|
+
|
205
|
+
## 3. 运行hello_world.py
|
206
|
+
```
|
207
|
+
uv run tests/hello_world.py
|
208
|
+
# 输入: b'1\n2\n100\n101\n'
|
209
|
+
```
|
210
|
+
```bash
|
211
|
+
输出map:
|
212
|
+
c 3
|
213
|
+
a 1
|
214
|
+
b 2
|
215
|
+
输出list:
|
216
|
+
0 134
|
217
|
+
1 3
|
218
|
+
2 2
|
219
|
+
Hello World 13 3
|
220
|
+
test_other_fn 10
|
221
|
+
test编译的函数 39
|
222
|
+
测试所有操作:
|
223
|
+
vector-> 0 = 2
|
224
|
+
vector-> 1 = 13
|
225
|
+
vv: 1
|
226
|
+
测试while:
|
227
|
+
请输入>>>输入的 1 小于等于100
|
228
|
+
请输入>>>输入的 2 小于等于100
|
229
|
+
请输入>>>输入的 100 小于等于100
|
230
|
+
请输入>>>结果: 241
|
231
|
+
|
232
|
+
```
|
233
|
+
|
234
|
+
## 4. 查看输出文件
|
235
|
+
```bash
|
236
|
+
ls -al ./l0n0lcoutput
|
237
|
+
total 160
|
238
|
+
drwxr-xr-x 2 root root 4096 Sep 18 01:09 .
|
239
|
+
drwxrwxrwx 11 1000 1000 4096 Sep 17 03:11 ..
|
240
|
+
-rw-r--r-- 1 root root 96 Sep 18 01:05 helper_@a9eebb1639a5f08c.cpp
|
241
|
+
-rw-r--r-- 1 root root 88 Sep 18 01:05 helper_@a9eebb1639a5f08c.h
|
242
|
+
-rwxr-xr-x 1 root root 15600 Sep 18 01:05 helper_@a9eebb1639a5f08c.so
|
243
|
+
-rw-r--r-- 1 root root 1693 Sep 18 01:09 jit_all_ops_@0ec883892076cd03.cpp
|
244
|
+
-rw-r--r-- 1 root root 167 Sep 18 01:09 jit_all_ops_@0ec883892076cd03.h
|
245
|
+
-rwxr-xr-x 1 root root 23520 Sep 18 01:09 jit_all_ops_@0ec883892076cd03.so
|
246
|
+
-rw-r--r-- 1 root root 1466 Sep 18 01:09 test_add_@122c4be59097d472.cpp
|
247
|
+
-rw-r--r-- 1 root root 302 Sep 18 01:09 test_add_@122c4be59097d472.h
|
248
|
+
-rwxr-xr-x 1 root root 40264 Sep 18 01:09 test_add_@122c4be59097d472.so
|
249
|
+
-rw-r--r-- 1 root root 121 Sep 18 01:09 test_other_fn_@75fdd928ab58a8e3.cpp
|
250
|
+
-rw-r--r-- 1 root root 106 Sep 18 01:09 test_other_fn_@75fdd928ab58a8e3.h
|
251
|
+
-rwxr-xr-x 1 root root 15616 Sep 18 01:09 test_other_fn_@75fdd928ab58a8e3.so
|
252
|
+
-rw-r--r-- 1 root root 185 Sep 18 01:07 test编译的函数_@3bf4501e0408a243.cpp
|
253
|
+
-rw-r--r-- 1 root root 164 Sep 18 01:07 test编译的函数_@3bf4501e0408a243.h
|
254
|
+
-rwxr-xr-x 1 root root 15656 Sep 18 01:07 test编译的函数_@3bf4501e0408a243.so
|
255
|
+
|
256
|
+
```
|
257
|
+
## 5. helper_@a9eebb1639a5f08c.cpp
|
258
|
+
```c++
|
259
|
+
#include "helper_@a9eebb1639a5f08c.h"
|
260
|
+
extern "C" int16_t helper (int16_t p)
|
261
|
+
{
|
262
|
+
return p * 2;
|
263
|
+
}
|
264
|
+
|
265
|
+
```
|
266
|
+
## 6. helper_@a9eebb1639a5f08c.h
|
267
|
+
```c++
|
268
|
+
#pragma once
|
269
|
+
#include <cstdint>
|
270
|
+
#include <string>
|
271
|
+
extern "C" int16_t helper (int16_t p);
|
272
|
+
```
|
273
|
+
## 7. jit_all_ops_@0ec883892076cd03.cpp
|
274
|
+
```c++
|
275
|
+
#include "jit_all_ops_@0ec883892076cd03.h"
|
276
|
+
extern "C" int16_t jit_all_ops (int16_t a, int16_t b)
|
277
|
+
{
|
278
|
+
auto x = 42;
|
279
|
+
auto y = ((int16_t)(a + b));
|
280
|
+
auto z = 3.14;
|
281
|
+
auto flag = true;
|
282
|
+
int16_t nums[] = {1,2,3};
|
283
|
+
int16_t tup[] = {4,5};
|
284
|
+
std::unordered_map<int16_t, int16_t> mp = {{ 1, 10 },{ 2, 20 }};
|
285
|
+
auto pos = +a;
|
286
|
+
auto neg = -b;
|
287
|
+
auto inv = ~a;
|
288
|
+
auto not_flag = !flag;
|
289
|
+
auto add = a + b;
|
290
|
+
auto sub = a - b;
|
291
|
+
auto mul = a * b;
|
292
|
+
auto div = a / ((b != 0) ? (b) : (1));
|
293
|
+
auto mod = a % ((b != 0) ? (b) : (1));
|
294
|
+
auto band = a & b;
|
295
|
+
auto bor = a | b;
|
296
|
+
auto bxor = a ^ b;
|
297
|
+
auto lshift = a << 1;
|
298
|
+
auto rshift = a >> 1;
|
299
|
+
auto cmp1 = (a == b);
|
300
|
+
auto cmp2 = (a != b);
|
301
|
+
auto cmp3 = (a < b);
|
302
|
+
auto cmp4 = (a <= b);
|
303
|
+
auto cmp5 = (a > b);
|
304
|
+
auto cmp6 = (a >= b);
|
305
|
+
auto logic_and = cmp1&&cmp2;
|
306
|
+
auto logic_or = cmp3||cmp4;
|
307
|
+
auto ternary = ((a > b) ? (a) : (b));
|
308
|
+
if ((a > b))
|
309
|
+
{
|
310
|
+
y = y + 1;
|
311
|
+
}
|
312
|
+
|
313
|
+
else
|
314
|
+
{
|
315
|
+
y = y - 1;
|
316
|
+
}
|
317
|
+
|
318
|
+
for (int64_t i = 0; i < 3; ++i)
|
319
|
+
{
|
320
|
+
y = y + i;
|
321
|
+
}
|
322
|
+
|
323
|
+
for (auto v : nums)
|
324
|
+
{
|
325
|
+
y = y + v;
|
326
|
+
if ((v == 2))
|
327
|
+
{
|
328
|
+
continue;
|
329
|
+
}
|
330
|
+
|
331
|
+
if ((v == 3))
|
332
|
+
{
|
333
|
+
break;
|
334
|
+
}
|
335
|
+
|
336
|
+
}
|
337
|
+
|
338
|
+
auto count = 0;
|
339
|
+
while ((count < 2))
|
340
|
+
{
|
341
|
+
y = y + count;
|
342
|
+
count = count + 1;
|
343
|
+
}
|
344
|
+
|
345
|
+
y = y + 5;
|
346
|
+
y = y - 1;
|
347
|
+
y = y * 2;
|
348
|
+
y = y / 2;
|
349
|
+
y = y % 10;
|
350
|
+
y = y & 7;
|
351
|
+
y = y | 3;
|
352
|
+
y = y ^ 1;
|
353
|
+
y = y << 1;
|
354
|
+
y = y >> 1;
|
355
|
+
auto first_num = nums[0];
|
356
|
+
auto mp_val = mp[1];
|
357
|
+
y = y + first_num + mp_val;
|
358
|
+
auto vector = std::vector<int>();
|
359
|
+
vector.push_back(count);
|
360
|
+
vector.push_back(y);
|
361
|
+
for (int64_t i = 0; i < vector.size(); ++i)
|
362
|
+
{
|
363
|
+
std::cout<< u8"vector->" << " "<< i << " "<< u8"=" << " "<< vector[i] << " "<< std::endl;;
|
364
|
+
}
|
365
|
+
|
366
|
+
return y;
|
367
|
+
}
|
368
|
+
|
369
|
+
```
|
370
|
+
## 8. jit_all_ops_@0ec883892076cd03.h
|
371
|
+
```c++
|
372
|
+
#pragma once
|
373
|
+
#include <cstdint>
|
374
|
+
#include <iostream>
|
375
|
+
#include <string>
|
376
|
+
#include <unordered_map>
|
377
|
+
#include <vector>
|
378
|
+
extern "C" int16_t jit_all_ops (int16_t a, int16_t b);
|
379
|
+
```
|
380
|
+
## 9. test_add_@122c4be59097d472.cpp
|
381
|
+
```c++
|
382
|
+
#include "test_add_@122c4be59097d472.h"
|
383
|
+
extern "C" int16_t test_add (int16_t a, int16_t b)
|
384
|
+
{
|
385
|
+
if ((a > 1))
|
386
|
+
{
|
387
|
+
return a + b;
|
388
|
+
}
|
389
|
+
|
390
|
+
for (int64_t i = 1; i < 10; i += 2)
|
391
|
+
{
|
392
|
+
a = a + i;
|
393
|
+
}
|
394
|
+
|
395
|
+
for (auto i : {1,2,3})
|
396
|
+
{
|
397
|
+
a = a + i;
|
398
|
+
}
|
399
|
+
|
400
|
+
a = std::ceil(12.5);;
|
401
|
+
std::unordered_map<std::string, int16_t> cc = {{ u8"a", 1 },{ u8"b", 2 }};
|
402
|
+
cc[u8"c"] = 3;
|
403
|
+
std::cout<< u8"输出map:" << " "<< std::endl;;
|
404
|
+
for (auto ii : cc)
|
405
|
+
{
|
406
|
+
std::cout<< ii.first << " "<< ii.second << " "<< std::endl;;
|
407
|
+
}
|
408
|
+
|
409
|
+
int16_t aa[] = {1,3,2};
|
410
|
+
aa[0] = 134;
|
411
|
+
std::cout<< u8"输出list:" << " "<< std::endl;;
|
412
|
+
for (int64_t i = 0; i < 3; ++i)
|
413
|
+
{
|
414
|
+
std::cout<< i << " "<< aa[i] << " "<< std::endl;;
|
415
|
+
}
|
416
|
+
|
417
|
+
std::cout<< u8"Hello World" << " "<< a << " "<< b << " "<< std::endl;;
|
418
|
+
std::cout<< u8"test_other_fn" << " "<< test_other_fn(a,b) << " "<< std::endl;;
|
419
|
+
std::cout<< u8"test编译的函数" << " "<< function_74657374e7bc96e8af91e79a84e587bde695b0(a,b) << " "<< std::endl;;
|
420
|
+
std::cout<< u8"测试所有操作:" << " "<< std::endl;;
|
421
|
+
jit_all_ops(a,b);
|
422
|
+
auto v = 0;
|
423
|
+
auto vv = true&&false||1;
|
424
|
+
std::cout<< u8"vv:" << " "<< vv << " "<< std::endl;;
|
425
|
+
std::cout<< u8"测试while:" << " "<< std::endl;;
|
426
|
+
while (vv)
|
427
|
+
{
|
428
|
+
std::cout << u8"请输入>>>"; std::cin >> v;;
|
429
|
+
if ((v > 100))
|
430
|
+
{
|
431
|
+
break;
|
432
|
+
}
|
433
|
+
|
434
|
+
else
|
435
|
+
{
|
436
|
+
std::cout<< u8"输入的" << " "<< v << " "<< u8"小于等于100" << " "<< std::endl;;
|
437
|
+
}
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
return a + b + 1 + 123 + v;
|
442
|
+
}
|
443
|
+
|
444
|
+
```
|
445
|
+
## 10. test_add_@122c4be59097d472.h
|
446
|
+
```c++
|
447
|
+
#pragma once
|
448
|
+
#include "jit_all_ops_@0ec883892076cd03.h"
|
449
|
+
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
450
|
+
#include "test编译的函数_@3bf4501e0408a243.h"
|
451
|
+
#include <cmath>
|
452
|
+
#include <cstdint>
|
453
|
+
#include <iostream>
|
454
|
+
#include <string>
|
455
|
+
#include <unordered_map>
|
456
|
+
extern "C" int16_t test_add (int16_t a, int16_t b);
|
457
|
+
```
|
458
|
+
## 11. test_other_fn_@75fdd928ab58a8e3.cpp
|
459
|
+
```c++
|
460
|
+
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
461
|
+
extern "C" int16_t test_other_fn (int16_t a, int16_t b)
|
462
|
+
{
|
463
|
+
return a - b;
|
464
|
+
}
|
465
|
+
|
466
|
+
```
|
467
|
+
## 12. test_other_fn_@75fdd928ab58a8e3.h
|
468
|
+
```c++
|
469
|
+
#pragma once
|
470
|
+
#include <cstdint>
|
471
|
+
#include <string>
|
472
|
+
extern "C" int16_t test_other_fn (int16_t a, int16_t b);
|
473
|
+
```
|
474
|
+
## 13. test编译的函数_@3bf4501e0408a243.cpp
|
475
|
+
```c++
|
476
|
+
#include "test编译的函数_@3bf4501e0408a243.h"
|
477
|
+
extern "C" int16_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int16_t a, int16_t b)
|
478
|
+
{
|
479
|
+
return a * b;
|
480
|
+
}
|
481
|
+
|
482
|
+
```
|
483
|
+
## 14. test编译的函数_@3bf4501e0408a243.h
|
484
|
+
```c++
|
485
|
+
#pragma once
|
486
|
+
#include <cstdint>
|
487
|
+
#include <string>
|
488
|
+
extern "C" int16_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int16_t a, int16_t b);
|
489
|
+
```
|
@@ -0,0 +1,12 @@
|
|
1
|
+
l0n0lc/StdList.py,sha256=0NTIpaRrNHaCiLrRbEVob21pZHa8S8rfaBRALPT-tD0,889
|
2
|
+
l0n0lc/StdMap.py,sha256=TIVKqhT078cjLIM0Zlq-TwGFSy-KwOyJe00BLFPVxr8,735
|
3
|
+
l0n0lc/__init__.py,sha256=fUC6TMeN_fEL7HDazrBEdoWOQkXi5uSGZb7LZj6juog,137
|
4
|
+
l0n0lc/c基础处理.py,sha256=ata-iQTp64kM0Ea_ktfQhaGPrejRzls3YZ7GcnjRlqE,5723
|
5
|
+
l0n0lc/jit.py,sha256=UG5CwhmtD9BJWWiWreFxDCTCFgKgjSOqREhaZuW3sBU,25619
|
6
|
+
l0n0lc/编译.py,sha256=Ty4gPDHAB1jn8LgnE4w3R06bOAEeYr8iwqahYf6QeHI,2154
|
7
|
+
l0n0lc/通用.py,sha256=RkqP9cMhKhl2h4YxOpAWFFftIPXLZTYMyOOD1PuB59M,4630
|
8
|
+
l0n0lc-0.8.8.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
|
9
|
+
l0n0lc-0.8.8.dist-info/METADATA,sha256=Dtn6HX9s4q8gr22r3070KzipY3saxyxC9xNy9P8rTwA,10451
|
10
|
+
l0n0lc-0.8.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
+
l0n0lc-0.8.8.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
|
12
|
+
l0n0lc-0.8.8.dist-info/RECORD,,
|
l0n0lc-0.8.6.dist-info/METADATA
DELETED
@@ -1,587 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.4
|
2
|
-
Name: l0n0lc
|
3
|
-
Version: 0.8.6
|
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
|
-
Module(
|
105
|
-
body=[
|
106
|
-
FunctionDef(
|
107
|
-
name='test编译的函数',
|
108
|
-
args=arguments(
|
109
|
-
posonlyargs=[],
|
110
|
-
args=[
|
111
|
-
arg(
|
112
|
-
arg='a',
|
113
|
-
annotation=Name(id='int', ctx=Load())),
|
114
|
-
arg(
|
115
|
-
arg='b',
|
116
|
-
annotation=Name(id='int', ctx=Load()))],
|
117
|
-
kwonlyargs=[],
|
118
|
-
kw_defaults=[],
|
119
|
-
defaults=[]),
|
120
|
-
body=[
|
121
|
-
Return(
|
122
|
-
value=BinOp(
|
123
|
-
left=Name(id='a', ctx=Load()),
|
124
|
-
op=Mult(),
|
125
|
-
right=Name(id='b', ctx=Load())))],
|
126
|
-
decorator_list=[
|
127
|
-
Call(
|
128
|
-
func=Attribute(
|
129
|
-
value=Name(id='lc', ctx=Load()),
|
130
|
-
attr='jit',
|
131
|
-
ctx=Load()),
|
132
|
-
args=[],
|
133
|
-
keywords=[])],
|
134
|
-
returns=Name(id='int', ctx=Load()))],
|
135
|
-
type_ignores=[])
|
136
|
-
Module(
|
137
|
-
body=[
|
138
|
-
FunctionDef(
|
139
|
-
name='test_add',
|
140
|
-
args=arguments(
|
141
|
-
posonlyargs=[],
|
142
|
-
args=[
|
143
|
-
arg(
|
144
|
-
arg='a',
|
145
|
-
annotation=Name(id='int', ctx=Load())),
|
146
|
-
arg(
|
147
|
-
arg='b',
|
148
|
-
annotation=Name(id='int', ctx=Load()))],
|
149
|
-
kwonlyargs=[],
|
150
|
-
kw_defaults=[],
|
151
|
-
defaults=[]),
|
152
|
-
body=[
|
153
|
-
If(
|
154
|
-
test=Compare(
|
155
|
-
left=Name(id='a', ctx=Load()),
|
156
|
-
ops=[
|
157
|
-
Gt()],
|
158
|
-
comparators=[
|
159
|
-
Constant(value=1)]),
|
160
|
-
body=[
|
161
|
-
Return(
|
162
|
-
value=BinOp(
|
163
|
-
left=Name(id='a', ctx=Load()),
|
164
|
-
op=Add(),
|
165
|
-
right=Name(id='b', ctx=Load())))],
|
166
|
-
orelse=[]),
|
167
|
-
For(
|
168
|
-
target=Name(id='i', ctx=Store()),
|
169
|
-
iter=Call(
|
170
|
-
func=Name(id='range', ctx=Load()),
|
171
|
-
args=[
|
172
|
-
Constant(value=1),
|
173
|
-
Constant(value=10),
|
174
|
-
Constant(value=2)],
|
175
|
-
keywords=[]),
|
176
|
-
body=[
|
177
|
-
AugAssign(
|
178
|
-
target=Name(id='a', ctx=Store()),
|
179
|
-
op=Add(),
|
180
|
-
value=Name(id='i', ctx=Load()))],
|
181
|
-
orelse=[]),
|
182
|
-
For(
|
183
|
-
target=Name(id='i', ctx=Store()),
|
184
|
-
iter=List(
|
185
|
-
elts=[
|
186
|
-
Constant(value=1),
|
187
|
-
Constant(value=2),
|
188
|
-
Constant(value=3)],
|
189
|
-
ctx=Load()),
|
190
|
-
body=[
|
191
|
-
AugAssign(
|
192
|
-
target=Name(id='a', ctx=Store()),
|
193
|
-
op=Add(),
|
194
|
-
value=Name(id='i', ctx=Load()))],
|
195
|
-
orelse=[]),
|
196
|
-
Assign(
|
197
|
-
targets=[
|
198
|
-
Name(id='a', ctx=Store())],
|
199
|
-
value=Call(
|
200
|
-
func=Attribute(
|
201
|
-
value=Name(id='math', ctx=Load()),
|
202
|
-
attr='ceil',
|
203
|
-
ctx=Load()),
|
204
|
-
args=[
|
205
|
-
Constant(value=12.5)],
|
206
|
-
keywords=[])),
|
207
|
-
Assign(
|
208
|
-
targets=[
|
209
|
-
Name(id='cc', ctx=Store())],
|
210
|
-
value=Dict(
|
211
|
-
keys=[
|
212
|
-
Constant(value='a'),
|
213
|
-
Constant(value='b')],
|
214
|
-
values=[
|
215
|
-
Constant(value=1),
|
216
|
-
Constant(value=2)])),
|
217
|
-
Assign(
|
218
|
-
targets=[
|
219
|
-
Subscript(
|
220
|
-
value=Name(id='cc', ctx=Load()),
|
221
|
-
slice=Constant(value='c'),
|
222
|
-
ctx=Store())],
|
223
|
-
value=Constant(value=3)),
|
224
|
-
Expr(
|
225
|
-
value=Call(
|
226
|
-
func=Name(id='print', ctx=Load()),
|
227
|
-
args=[
|
228
|
-
Constant(value='输出map:')],
|
229
|
-
keywords=[])),
|
230
|
-
For(
|
231
|
-
target=Name(id='ii', ctx=Store()),
|
232
|
-
iter=Name(id='cc', ctx=Load()),
|
233
|
-
body=[
|
234
|
-
Expr(
|
235
|
-
value=Call(
|
236
|
-
func=Name(id='print', ctx=Load()),
|
237
|
-
args=[
|
238
|
-
Attribute(
|
239
|
-
value=Name(id='ii', ctx=Load()),
|
240
|
-
attr='first',
|
241
|
-
ctx=Load()),
|
242
|
-
Attribute(
|
243
|
-
value=Name(id='ii', ctx=Load()),
|
244
|
-
attr='second',
|
245
|
-
ctx=Load())],
|
246
|
-
keywords=[]))],
|
247
|
-
orelse=[]),
|
248
|
-
Assign(
|
249
|
-
targets=[
|
250
|
-
Name(id='aa', ctx=Store())],
|
251
|
-
value=List(
|
252
|
-
elts=[
|
253
|
-
Constant(value=1),
|
254
|
-
Constant(value=3),
|
255
|
-
Constant(value=2)],
|
256
|
-
ctx=Load())),
|
257
|
-
Assign(
|
258
|
-
targets=[
|
259
|
-
Subscript(
|
260
|
-
value=Name(id='aa', ctx=Load()),
|
261
|
-
slice=Constant(value=0),
|
262
|
-
ctx=Store())],
|
263
|
-
value=Constant(value=134)),
|
264
|
-
Expr(
|
265
|
-
value=Call(
|
266
|
-
func=Name(id='print', ctx=Load()),
|
267
|
-
args=[
|
268
|
-
Constant(value='输出list:')],
|
269
|
-
keywords=[])),
|
270
|
-
For(
|
271
|
-
target=Name(id='i', ctx=Store()),
|
272
|
-
iter=Call(
|
273
|
-
func=Name(id='range', ctx=Load()),
|
274
|
-
args=[
|
275
|
-
Constant(value=3)],
|
276
|
-
keywords=[]),
|
277
|
-
body=[
|
278
|
-
Expr(
|
279
|
-
value=Call(
|
280
|
-
func=Name(id='print', ctx=Load()),
|
281
|
-
args=[
|
282
|
-
Name(id='i', ctx=Load()),
|
283
|
-
Subscript(
|
284
|
-
value=Name(id='aa', ctx=Load()),
|
285
|
-
slice=Name(id='i', ctx=Load()),
|
286
|
-
ctx=Load())],
|
287
|
-
keywords=[]))],
|
288
|
-
orelse=[]),
|
289
|
-
Expr(
|
290
|
-
value=Call(
|
291
|
-
func=Name(id='print', ctx=Load()),
|
292
|
-
args=[
|
293
|
-
Constant(value='Hello World'),
|
294
|
-
Name(id='a', ctx=Load()),
|
295
|
-
Name(id='b', ctx=Load())],
|
296
|
-
keywords=[])),
|
297
|
-
Expr(
|
298
|
-
value=Call(
|
299
|
-
func=Name(id='print', ctx=Load()),
|
300
|
-
args=[
|
301
|
-
Constant(value='test_other_fn'),
|
302
|
-
Call(
|
303
|
-
func=Name(id='test_other_fn', ctx=Load()),
|
304
|
-
args=[
|
305
|
-
Name(id='a', ctx=Load()),
|
306
|
-
Name(id='b', ctx=Load())],
|
307
|
-
keywords=[])],
|
308
|
-
keywords=[])),
|
309
|
-
Expr(
|
310
|
-
value=Call(
|
311
|
-
func=Name(id='print', ctx=Load()),
|
312
|
-
args=[
|
313
|
-
Constant(value='test编译的函数'),
|
314
|
-
Call(
|
315
|
-
func=Name(id='test编译的函数', ctx=Load()),
|
316
|
-
args=[
|
317
|
-
Name(id='a', ctx=Load()),
|
318
|
-
Name(id='b', ctx=Load())],
|
319
|
-
keywords=[])],
|
320
|
-
keywords=[])),
|
321
|
-
Assign(
|
322
|
-
targets=[
|
323
|
-
Name(id='v', ctx=Store())],
|
324
|
-
value=Constant(value=0)),
|
325
|
-
Assign(
|
326
|
-
targets=[
|
327
|
-
Name(id='vv', ctx=Store())],
|
328
|
-
value=BoolOp(
|
329
|
-
op=And(),
|
330
|
-
values=[
|
331
|
-
Constant(value=True),
|
332
|
-
BoolOp(
|
333
|
-
op=Or(),
|
334
|
-
values=[
|
335
|
-
Constant(value=False),
|
336
|
-
Constant(value=1)])])),
|
337
|
-
Expr(
|
338
|
-
value=Call(
|
339
|
-
func=Name(id='print', ctx=Load()),
|
340
|
-
args=[
|
341
|
-
Constant(value='vv:'),
|
342
|
-
Name(id='vv', ctx=Load())],
|
343
|
-
keywords=[])),
|
344
|
-
While(
|
345
|
-
test=Constant(value=True),
|
346
|
-
body=[
|
347
|
-
Expr(
|
348
|
-
value=Call(
|
349
|
-
func=Name(id='py_cin', ctx=Load()),
|
350
|
-
args=[
|
351
|
-
Name(id='v', ctx=Load())],
|
352
|
-
keywords=[])),
|
353
|
-
If(
|
354
|
-
test=Compare(
|
355
|
-
left=Name(id='v', ctx=Load()),
|
356
|
-
ops=[
|
357
|
-
Gt()],
|
358
|
-
comparators=[
|
359
|
-
Constant(value=100)]),
|
360
|
-
body=[
|
361
|
-
Break()],
|
362
|
-
orelse=[
|
363
|
-
Expr(
|
364
|
-
value=Call(
|
365
|
-
func=Name(id='print', ctx=Load()),
|
366
|
-
args=[
|
367
|
-
Constant(value='输入的'),
|
368
|
-
Name(id='v', ctx=Load()),
|
369
|
-
Constant(value='小于等于100')],
|
370
|
-
keywords=[]))])],
|
371
|
-
orelse=[]),
|
372
|
-
Return(
|
373
|
-
value=BinOp(
|
374
|
-
left=BinOp(
|
375
|
-
left=BinOp(
|
376
|
-
left=BinOp(
|
377
|
-
left=Name(id='a', ctx=Load()),
|
378
|
-
op=Add(),
|
379
|
-
right=Name(id='b', ctx=Load())),
|
380
|
-
op=Add(),
|
381
|
-
right=Constant(value=1)),
|
382
|
-
op=Add(),
|
383
|
-
right=Call(
|
384
|
-
func=Name(id='test_直接调用', ctx=Load()),
|
385
|
-
args=[],
|
386
|
-
keywords=[])),
|
387
|
-
op=Add(),
|
388
|
-
right=Name(id='v', ctx=Load())))],
|
389
|
-
decorator_list=[
|
390
|
-
Call(
|
391
|
-
func=Attribute(
|
392
|
-
value=Name(id='lc', ctx=Load()),
|
393
|
-
attr='jit',
|
394
|
-
ctx=Load()),
|
395
|
-
args=[],
|
396
|
-
keywords=[
|
397
|
-
keyword(
|
398
|
-
arg='每次运行都重新编译',
|
399
|
-
value=Constant(value=True))])],
|
400
|
-
returns=Name(id='int', ctx=Load()))],
|
401
|
-
type_ignores=[])
|
402
|
-
输出map:
|
403
|
-
c 3
|
404
|
-
a 1
|
405
|
-
b 2
|
406
|
-
输出list:
|
407
|
-
0 134
|
408
|
-
1 3
|
409
|
-
2 2
|
410
|
-
Hello World 13 3
|
411
|
-
test_other_fn 10
|
412
|
-
test编译的函数 39
|
413
|
-
vv: 1
|
414
|
-
请输入>>>输入的 1 小于等于100
|
415
|
-
请输入>>>输入的 2 小于等于100
|
416
|
-
请输入>>>输入的 100 小于等于100
|
417
|
-
请输入>>>Module(
|
418
|
-
body=[
|
419
|
-
FunctionDef(
|
420
|
-
name='test_other_fn',
|
421
|
-
args=arguments(
|
422
|
-
posonlyargs=[],
|
423
|
-
args=[
|
424
|
-
arg(
|
425
|
-
arg='a',
|
426
|
-
annotation=Name(id='int', ctx=Load())),
|
427
|
-
arg(
|
428
|
-
arg='b',
|
429
|
-
annotation=Name(id='int', ctx=Load()))],
|
430
|
-
kwonlyargs=[],
|
431
|
-
kw_defaults=[],
|
432
|
-
defaults=[]),
|
433
|
-
body=[
|
434
|
-
Return(
|
435
|
-
value=BinOp(
|
436
|
-
left=Name(id='a', ctx=Load()),
|
437
|
-
op=Sub(),
|
438
|
-
right=Name(id='b', ctx=Load())))],
|
439
|
-
decorator_list=[],
|
440
|
-
returns=Name(id='int', ctx=Load()))],
|
441
|
-
type_ignores=[])
|
442
|
-
结果: 241
|
443
|
-
|
444
|
-
```
|
445
|
-
|
446
|
-
## 4. 查看输出文件
|
447
|
-
```bash
|
448
|
-
ls -al ./l0n0lcoutput
|
449
|
-
total 32
|
450
|
-
drwxr-xr-x 2 root root 4096 Sep 16 03:28 .
|
451
|
-
drwxrwxrwx 11 1000 1000 4096 Sep 16 03:18 ..
|
452
|
-
-rw-r--r-- 1 root root 284 Sep 16 03:28 sum_and_filter_@e48c1f185531e3af.cpp
|
453
|
-
-rw-r--r-- 1 root root 83 Sep 16 03:28 sum_and_filter_@e48c1f185531e3af.h
|
454
|
-
-rwxr-xr-x 1 root root 15616 Sep 16 03:28 sum_and_filter_@e48c1f185531e3af.so
|
455
|
-
|
456
|
-
```
|
457
|
-
## 5. sum_and_filter_@e48c1f185531e3af.cpp
|
458
|
-
```c++
|
459
|
-
#include "sum_and_filter_@e48c1f185531e3af.h"
|
460
|
-
extern "C" int64_t sum_and_filter (int64_t n)
|
461
|
-
{
|
462
|
-
auto total = ((int64_t)(0));
|
463
|
-
for (int64_t x = 0; x < n; ++x)
|
464
|
-
{
|
465
|
-
if ((x % 2 == 0))
|
466
|
-
{
|
467
|
-
total = total + x;
|
468
|
-
}
|
469
|
-
|
470
|
-
{
|
471
|
-
total = total - x;
|
472
|
-
}
|
473
|
-
|
474
|
-
}
|
475
|
-
|
476
|
-
return total;
|
477
|
-
}
|
478
|
-
|
479
|
-
```
|
480
|
-
## 6. sum_and_filter_@e48c1f185531e3af.h
|
481
|
-
```c++
|
482
|
-
#include <cstdint>
|
483
|
-
#include <string>
|
484
|
-
extern "C" int64_t sum_and_filter (int64_t n);
|
485
|
-
```
|
486
|
-
## 7. test_add_@6a812a013615c16d.cpp
|
487
|
-
```c++
|
488
|
-
#include "test_add_@6a812a013615c16d.h"
|
489
|
-
extern "C" int64_t test_add (int64_t a, int64_t b)
|
490
|
-
{
|
491
|
-
if ((a > 1))
|
492
|
-
{
|
493
|
-
return a + b;
|
494
|
-
}
|
495
|
-
|
496
|
-
for (int64_t i = 1; i < 10; i += 2)
|
497
|
-
{
|
498
|
-
a = a + i;
|
499
|
-
}
|
500
|
-
|
501
|
-
for (auto i : {1,2,3})
|
502
|
-
{
|
503
|
-
a = a + i;
|
504
|
-
}
|
505
|
-
|
506
|
-
a = std::ceil(12.5);;
|
507
|
-
std::unordered_map<std::string, int64_t> cc = {{ u8"a", 1 },{ u8"b", 2 }};
|
508
|
-
cc[u8"c"] = 3;
|
509
|
-
std::cout<< u8"输出map:" << " "<< std::endl;
|
510
|
-
for (auto ii : cc)
|
511
|
-
{
|
512
|
-
std::cout<< ii.first << " "<< ii.second << " "<< std::endl;
|
513
|
-
}
|
514
|
-
|
515
|
-
int64_t aa[] = {1,3,2};
|
516
|
-
aa[0] = 134;
|
517
|
-
std::cout<< u8"输出list:" << " "<< std::endl;
|
518
|
-
for (int64_t i = 0; i < 3; ++i)
|
519
|
-
{
|
520
|
-
std::cout<< i << " "<< aa[i] << " "<< std::endl;
|
521
|
-
}
|
522
|
-
|
523
|
-
std::cout<< u8"Hello World" << " "<< a << " "<< b << " "<< std::endl;
|
524
|
-
std::cout<< u8"test_other_fn" << " "<< test_other_fn(a,b) << " "<< std::endl;
|
525
|
-
std::cout<< u8"test编译的函数" << " "<< function_74657374e7bc96e8af91e79a84e587bde695b0(a,b) << " "<< std::endl;
|
526
|
-
auto v = 0;
|
527
|
-
auto vv = true&&false||1;
|
528
|
-
std::cout<< u8"vv:" << " "<< vv << " "<< std::endl;
|
529
|
-
while (true)
|
530
|
-
{
|
531
|
-
std::cout << u8"请输入>>>"; std::cin >> v;
|
532
|
-
if ((v > 100))
|
533
|
-
{
|
534
|
-
break;
|
535
|
-
}
|
536
|
-
|
537
|
-
{
|
538
|
-
std::cout<< u8"输入的" << " "<< v << " "<< u8"小于等于100" << " "<< std::endl;
|
539
|
-
}
|
540
|
-
|
541
|
-
}
|
542
|
-
|
543
|
-
return a + b + 1 + 123 + v;
|
544
|
-
}
|
545
|
-
|
546
|
-
```
|
547
|
-
## 8. test_add_@6a812a013615c16d.h
|
548
|
-
```c++
|
549
|
-
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
550
|
-
#include "test编译的函数_@3bf4501e0408a243.h"
|
551
|
-
#include <cmath>
|
552
|
-
#include <cstdint>
|
553
|
-
#include <iostream>
|
554
|
-
#include <string>
|
555
|
-
#include <unordered_map>
|
556
|
-
extern "C" int64_t test_add (int64_t a, int64_t b);
|
557
|
-
```
|
558
|
-
## 9. test_other_fn_@75fdd928ab58a8e3.cpp
|
559
|
-
```c++
|
560
|
-
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
561
|
-
extern "C" int64_t test_other_fn (int64_t a, int64_t b)
|
562
|
-
{
|
563
|
-
return a - b;
|
564
|
-
}
|
565
|
-
|
566
|
-
```
|
567
|
-
## 10. test_other_fn_@75fdd928ab58a8e3.h
|
568
|
-
```c++
|
569
|
-
#include <cstdint>
|
570
|
-
#include <string>
|
571
|
-
extern "C" int64_t test_other_fn (int64_t a, int64_t b);
|
572
|
-
```
|
573
|
-
## 11. test编译的函数_@3bf4501e0408a243.cpp
|
574
|
-
```c++
|
575
|
-
#include "test编译的函数_@3bf4501e0408a243.h"
|
576
|
-
extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b)
|
577
|
-
{
|
578
|
-
return a * b;
|
579
|
-
}
|
580
|
-
|
581
|
-
```
|
582
|
-
## 12. test编译的函数_@3bf4501e0408a243.h
|
583
|
-
```c++
|
584
|
-
#include <cstdint>
|
585
|
-
#include <string>
|
586
|
-
extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b);
|
587
|
-
```
|
l0n0lc-0.8.6.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
l0n0lc/StdList.py,sha256=0NTIpaRrNHaCiLrRbEVob21pZHa8S8rfaBRALPT-tD0,889
|
2
|
-
l0n0lc/StdMap.py,sha256=TIVKqhT078cjLIM0Zlq-TwGFSy-KwOyJe00BLFPVxr8,735
|
3
|
-
l0n0lc/__init__.py,sha256=fUC6TMeN_fEL7HDazrBEdoWOQkXi5uSGZb7LZj6juog,137
|
4
|
-
l0n0lc/c基础处理.py,sha256=9YT2fC8dsHymyrmtQGGmc0KBfenzP1QYJX5SVUNBu3I,5835
|
5
|
-
l0n0lc/jit.py,sha256=nocYOYiORnaOyYPGs7pLRacKWhzBdP-7Sux9ubm7QOY,24647
|
6
|
-
l0n0lc/编译.py,sha256=Ty4gPDHAB1jn8LgnE4w3R06bOAEeYr8iwqahYf6QeHI,2154
|
7
|
-
l0n0lc/通用.py,sha256=O_Y4bbW1WzHCJkibxAy9WGACv-aEZJLG-fEeVBcAbBQ,3649
|
8
|
-
l0n0lc-0.8.6.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
|
9
|
-
l0n0lc-0.8.6.dist-info/METADATA,sha256=3z1lqqULiw7i5xO6Wz8mZwAthAVK3ulO3nnmcQ1z03c,15058
|
10
|
-
l0n0lc-0.8.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
11
|
-
l0n0lc-0.8.6.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
|
12
|
-
l0n0lc-0.8.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|