l0n0lc 0.10.1__tar.gz → 0.10.3__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: l0n0lc
3
- Version: 0.10.1
3
+ Version: 0.10.3
4
4
  Summary: 一个将python函数翻译为c++函数并运行的jit编译器
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Requires-Python: >=3.10
@@ -63,6 +63,7 @@ import l0n0lc as lc
63
63
  import math
64
64
  import 测试可执行
65
65
 
66
+
66
67
  @lc.映射函数(math.ceil, ['<cmath>'])
67
68
  def cpp_ceil(v):
68
69
  return f'std::ceil({lc.toCString(v)});'
@@ -112,6 +113,12 @@ class CppVectorInt:
112
113
  return 0
113
114
 
114
115
 
116
+ @lc.映射类型('short')
117
+ class ShortInt:
118
+ def __init__(self, v) -> None:
119
+ pass
120
+
121
+
115
122
  @lc.jit(每次运行都重新编译=True)
116
123
  def jit_all_ops(a: int, b: int) -> int:
117
124
  # 常量与基础赋值
@@ -120,8 +127,10 @@ def jit_all_ops(a: int, b: int) -> int:
120
127
  z = 3.14
121
128
  flag = True
122
129
  nums = [1, 2, 3]
130
+ numsshorts = [ShortInt(1), ShortInt(2), ShortInt(3)]
123
131
  tup = (4, 5)
124
132
  mp = {1: 10, 2: 20}
133
+ mp2 = {ShortInt(1): 10, ShortInt(2): 20}
125
134
 
126
135
  # 一元运算
127
136
  pos = +(a + 1)
@@ -202,6 +211,7 @@ def jit_all_ops(a: int, b: int) -> int:
202
211
  print('vector->', i, '=', vector[i])
203
212
  return y
204
213
 
214
+
205
215
  @lc.jit(每次运行都重新编译=True)
206
216
  def test_add(a: int, b: int) -> int:
207
217
  if a > 1:
@@ -243,7 +253,6 @@ def test_add(a: int, b: int) -> int:
243
253
 
244
254
  print('结果:', test_add(1, 3))
245
255
 
246
-
247
256
  ```
248
257
 
249
258
  ## 4. 运行hello_world.py
@@ -282,24 +291,24 @@ vv: 1
282
291
  ## 5. 查看输出文件
283
292
  ```bash
284
293
  ls -al ./l0n0lcoutput
285
- total 164
286
- drwxr-xr-x 2 root root 4096 Oct 16 01:39 .
287
- drwxrwxrwx 11 1000 1000 4096 Oct 16 01:39 ..
288
- -rw-r--r-- 1 root root 298 Oct 16 01:39 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
289
- -rw-r--r-- 1 root root 128 Oct 16 01:39 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.h
290
- -rw-r--r-- 1 root root 1811 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.cpp
291
- -rw-r--r-- 1 root root 167 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h
292
- -rwxr-xr-x 1 root root 23584 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.so
293
- -rw-r--r-- 1 root root 1531 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.cpp
294
- -rw-r--r-- 1 root root 398 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
295
- -rwxr-xr-x 1 root root 40408 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.so
296
- -rw-r--r-- 1 root root 155 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.cpp
297
- -rw-r--r-- 1 root root 106 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h
298
- -rwxr-xr-x 1 root root 15648 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.so
299
- -rw-r--r-- 1 root root 219 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.cpp
300
- -rw-r--r-- 1 root root 164 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h
301
- -rwxr-xr-x 1 root root 15688 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.so
302
- -rwxr-xr-x 1 root root 17248 Oct 16 01:39 测试可执行文件
294
+ total 176
295
+ drwxr-xr-x 2 root root 4096 Oct 22 02:25 .
296
+ drwxrwxrwx 11 1000 1000 4096 Oct 22 02:25 ..
297
+ -rw-r--r-- 1 root root 298 Oct 22 02:25 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
298
+ -rw-r--r-- 1 root root 128 Oct 22 02:25 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.h
299
+ -rw-r--r-- 1 root root 1944 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.cpp
300
+ -rw-r--r-- 1 root root 167 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h
301
+ -rwxr-xr-x 1 root root 29000 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.so
302
+ -rw-r--r-- 1 root root 1531 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.cpp
303
+ -rw-r--r-- 1 root root 398 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
304
+ -rwxr-xr-x 1 root root 41728 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.so
305
+ -rw-r--r-- 1 root root 155 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.cpp
306
+ -rw-r--r-- 1 root root 106 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h
307
+ -rwxr-xr-x 1 root root 15648 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.so
308
+ -rw-r--r-- 1 root root 219 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.cpp
309
+ -rw-r--r-- 1 root root 164 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h
310
+ -rwxr-xr-x 1 root root 15688 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.so
311
+ -rwxr-xr-x 1 root root 17248 Oct 22 02:25 测试可执行文件
303
312
 
304
313
  ```
305
314
  ## 6. 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
@@ -325,9 +334,9 @@ extern "C" int /*可执行*/ main (int argc, char** argv)
325
334
  #include <string>
326
335
  extern "C" int /*可执行*/ main (int argc, char** argv);
327
336
  ```
328
- ## 8. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.cpp
337
+ ## 8. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.cpp
329
338
  ```c++
330
- #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h"
339
+ #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h"
331
340
  extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
332
341
  {
333
342
  auto x = 42;
@@ -335,8 +344,10 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
335
344
  auto z = 3.14;
336
345
  auto flag = true;
337
346
  int64_t nums[] = {1,2,3};
347
+ short numsshorts[] = {short(1),short(2),short(3)};
338
348
  int64_t tup[] = {4,5};
339
349
  std::unordered_map<int64_t, int64_t> mp = {{ 1, 10 },{ 2, 20 }};
350
+ std::unordered_map<short, int64_t> mp2 = {{ short(1), 10 },{ short(2), 20 }};
340
351
  auto pos = (+(a + 1));
341
352
  auto neg = (-b);
342
353
  auto inv = (~a);
@@ -422,7 +433,7 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
422
433
  }
423
434
 
424
435
  ```
425
- ## 9. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h
436
+ ## 9. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h
426
437
  ```c++
427
438
  #pragma once
428
439
  #include <cstdint>
@@ -500,7 +511,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
500
511
  ## 11. c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
501
512
  ```c++
502
513
  #pragma once
503
- #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h"
514
+ #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h"
504
515
  #include "c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h"
505
516
  #include "c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h"
506
517
  #include <cmath>
@@ -53,6 +53,7 @@ import l0n0lc as lc
53
53
  import math
54
54
  import 测试可执行
55
55
 
56
+
56
57
  @lc.映射函数(math.ceil, ['<cmath>'])
57
58
  def cpp_ceil(v):
58
59
  return f'std::ceil({lc.toCString(v)});'
@@ -102,6 +103,12 @@ class CppVectorInt:
102
103
  return 0
103
104
 
104
105
 
106
+ @lc.映射类型('short')
107
+ class ShortInt:
108
+ def __init__(self, v) -> None:
109
+ pass
110
+
111
+
105
112
  @lc.jit(每次运行都重新编译=True)
106
113
  def jit_all_ops(a: int, b: int) -> int:
107
114
  # 常量与基础赋值
@@ -110,8 +117,10 @@ def jit_all_ops(a: int, b: int) -> int:
110
117
  z = 3.14
111
118
  flag = True
112
119
  nums = [1, 2, 3]
120
+ numsshorts = [ShortInt(1), ShortInt(2), ShortInt(3)]
113
121
  tup = (4, 5)
114
122
  mp = {1: 10, 2: 20}
123
+ mp2 = {ShortInt(1): 10, ShortInt(2): 20}
115
124
 
116
125
  # 一元运算
117
126
  pos = +(a + 1)
@@ -192,6 +201,7 @@ def jit_all_ops(a: int, b: int) -> int:
192
201
  print('vector->', i, '=', vector[i])
193
202
  return y
194
203
 
204
+
195
205
  @lc.jit(每次运行都重新编译=True)
196
206
  def test_add(a: int, b: int) -> int:
197
207
  if a > 1:
@@ -233,7 +243,6 @@ def test_add(a: int, b: int) -> int:
233
243
 
234
244
  print('结果:', test_add(1, 3))
235
245
 
236
-
237
246
  ```
238
247
 
239
248
  ## 4. 运行hello_world.py
@@ -272,24 +281,24 @@ vv: 1
272
281
  ## 5. 查看输出文件
273
282
  ```bash
274
283
  ls -al ./l0n0lcoutput
275
- total 164
276
- drwxr-xr-x 2 root root 4096 Oct 16 01:39 .
277
- drwxrwxrwx 11 1000 1000 4096 Oct 16 01:39 ..
278
- -rw-r--r-- 1 root root 298 Oct 16 01:39 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
279
- -rw-r--r-- 1 root root 128 Oct 16 01:39 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.h
280
- -rw-r--r-- 1 root root 1811 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.cpp
281
- -rw-r--r-- 1 root root 167 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h
282
- -rwxr-xr-x 1 root root 23584 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.so
283
- -rw-r--r-- 1 root root 1531 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.cpp
284
- -rw-r--r-- 1 root root 398 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
285
- -rwxr-xr-x 1 root root 40408 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.so
286
- -rw-r--r-- 1 root root 155 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.cpp
287
- -rw-r--r-- 1 root root 106 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h
288
- -rwxr-xr-x 1 root root 15648 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.so
289
- -rw-r--r-- 1 root root 219 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.cpp
290
- -rw-r--r-- 1 root root 164 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h
291
- -rwxr-xr-x 1 root root 15688 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.so
292
- -rwxr-xr-x 1 root root 17248 Oct 16 01:39 测试可执行文件
284
+ total 176
285
+ drwxr-xr-x 2 root root 4096 Oct 22 02:25 .
286
+ drwxrwxrwx 11 1000 1000 4096 Oct 22 02:25 ..
287
+ -rw-r--r-- 1 root root 298 Oct 22 02:25 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
288
+ -rw-r--r-- 1 root root 128 Oct 22 02:25 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.h
289
+ -rw-r--r-- 1 root root 1944 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.cpp
290
+ -rw-r--r-- 1 root root 167 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h
291
+ -rwxr-xr-x 1 root root 29000 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.so
292
+ -rw-r--r-- 1 root root 1531 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.cpp
293
+ -rw-r--r-- 1 root root 398 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
294
+ -rwxr-xr-x 1 root root 41728 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.so
295
+ -rw-r--r-- 1 root root 155 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.cpp
296
+ -rw-r--r-- 1 root root 106 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h
297
+ -rwxr-xr-x 1 root root 15648 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.so
298
+ -rw-r--r-- 1 root root 219 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.cpp
299
+ -rw-r--r-- 1 root root 164 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h
300
+ -rwxr-xr-x 1 root root 15688 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.so
301
+ -rwxr-xr-x 1 root root 17248 Oct 22 02:25 测试可执行文件
293
302
 
294
303
  ```
295
304
  ## 6. 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
@@ -315,9 +324,9 @@ extern "C" int /*可执行*/ main (int argc, char** argv)
315
324
  #include <string>
316
325
  extern "C" int /*可执行*/ main (int argc, char** argv);
317
326
  ```
318
- ## 8. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.cpp
327
+ ## 8. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.cpp
319
328
  ```c++
320
- #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h"
329
+ #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h"
321
330
  extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
322
331
  {
323
332
  auto x = 42;
@@ -325,8 +334,10 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
325
334
  auto z = 3.14;
326
335
  auto flag = true;
327
336
  int64_t nums[] = {1,2,3};
337
+ short numsshorts[] = {short(1),short(2),short(3)};
328
338
  int64_t tup[] = {4,5};
329
339
  std::unordered_map<int64_t, int64_t> mp = {{ 1, 10 },{ 2, 20 }};
340
+ std::unordered_map<short, int64_t> mp2 = {{ short(1), 10 },{ short(2), 20 }};
330
341
  auto pos = (+(a + 1));
331
342
  auto neg = (-b);
332
343
  auto inv = (~a);
@@ -412,7 +423,7 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
412
423
  }
413
424
 
414
425
  ```
415
- ## 9. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h
426
+ ## 9. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h
416
427
  ```c++
417
428
  #pragma once
418
429
  #include <cstdint>
@@ -490,7 +501,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
490
501
  ## 11. c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
491
502
  ```c++
492
503
  #pragma once
493
- #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h"
504
+ #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h"
494
505
  #include "c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h"
495
506
  #include "c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h"
496
507
  #include <cmath>
@@ -29,6 +29,69 @@ class 指针:
29
29
  return f'{self.基础类型}*'
30
30
 
31
31
 
32
+ class 花括号:
33
+ def __init__(self, 编译器) -> None:
34
+ self.编译器 = 编译器
35
+
36
+ def __enter__(self, *args, **kwargs):
37
+ self.编译器.添加c代码('{')
38
+ self.编译器.进入新作用域()
39
+
40
+ def __exit__(self, *args, **kwargs):
41
+ self.编译器.退出作用域()
42
+ self.编译器.添加c代码('}\n')
43
+
44
+
45
+ class c代码:
46
+ def __init__(self, 代码: str, 层级: int) -> None:
47
+ self.代码 = 代码
48
+ self.层级 = 层级
49
+
50
+ def __str__(self) -> str:
51
+ return ' ' * self.层级 + self.代码
52
+
53
+
54
+ class c获取索引项目:
55
+ def __init__(self, 变量, 索引) -> None:
56
+ self.变量 = 变量
57
+ self.索引 = 索引
58
+
59
+ def __str__(self) -> str:
60
+ return f'{self.变量}[{toCString(self.索引)}]'
61
+
62
+
63
+ class c获取属性:
64
+ def __init__(self, 变量, 属性) -> None:
65
+ self.变量 = 变量
66
+ self.属性 = 属性
67
+
68
+ def __str__(self) -> str:
69
+ if isinstance(self.变量, c变量):
70
+ if self.变量.类型.endswith('*'):
71
+ return f'{self.变量}->{self.属性}'
72
+ return f'{self.变量}.{self.属性}'
73
+
74
+
75
+ class c函数调用:
76
+ def __init__(self, 函数名, 参数字符串, 返回的c类型=None) -> None:
77
+ self.函数名 = 函数名
78
+ self.参数字符串 = 参数字符串
79
+ self.返回的c类型 = 返回的c类型
80
+
81
+ def __str__(self) -> str:
82
+ return f'{self.函数名}({self.参数字符串})'
83
+
84
+
85
+ class c布尔:
86
+ def __init__(self, v) -> None:
87
+ self.v = v
88
+
89
+ def __str__(self) -> str:
90
+ if self.v:
91
+ return 'true'
92
+ return 'false'
93
+
94
+
32
95
  def 执行额外函数(函数列表: List, *args):
33
96
  for fn in 函数列表:
34
97
  ret = fn(*args)
@@ -68,7 +131,7 @@ py2c类型映射表 = {
68
131
  }
69
132
 
70
133
 
71
- def py类型转c类型(类型):
134
+ def py类型转c类型(类型, 类型实例=None):
72
135
  ret = 执行额外函数(额外py转c函数, 类型)
73
136
  if ret is not None:
74
137
  return ret
@@ -105,24 +168,24 @@ def py类型转c类型(类型):
105
168
  if isinstance(类型, str):
106
169
  return 类型
107
170
 
108
- return cpp类型.ANY
171
+ if 类型 is c布尔:
172
+ return cpp类型.BOOL
109
173
 
174
+ if isinstance(类型实例, c函数调用) and 类型实例.返回的c类型 is not None:
175
+ return 类型实例.返回的c类型
110
176
 
111
- def cpp类型检查(类型, 支持提示: str):
112
- if 类型 not in [int, float, str, bool]:
113
- raise Exception(f'{支持提示} 仅支持 [int, float, str, bool]')
177
+ raise Exception("不支持的类型", 类型, 类型实例)
114
178
 
115
179
 
116
180
  class list初始化列表:
117
181
  def __init__(
118
182
  self,
119
183
  代码: str,
120
- 类型列表: Union[List[Union[int, float, bool, str]],
121
- int, float, bool, str],
184
+ 类型列表,
122
185
  长度: int) -> None:
123
186
  self.代码 = 代码
124
- self.类型列表 = 类型列表
125
- self.类型 = py类型转c类型(类型列表)
187
+ self.类型列表 = 类型列表[0]
188
+ self.类型 = py类型转c类型(*类型列表)
126
189
  self.长度 = 长度
127
190
 
128
191
  def __str__(self) -> str:
@@ -134,15 +197,16 @@ def 从list构建初始化列表(value: List):
134
197
  初始化列表 = []
135
198
  for v in value:
136
199
  dtype = type(v)
137
- cpp类型检查(dtype, 'List')
138
- 数据类型列表.append(dtype)
200
+ 数据类型列表.append((dtype, v))
139
201
  初始化列表.append(toCString(v))
140
202
  # 构建初始化列表
141
203
  初始化列表 = '{' + ','.join(初始化列表) + '}'
142
204
 
143
205
  # 构建类型列表
144
- if all(类型 == 数据类型列表[0] for 类型 in 数据类型列表):
206
+ if all(类型[0] == 数据类型列表[0][0] for 类型 in 数据类型列表):
145
207
  数据类型列表 = 数据类型列表[0]
208
+ else:
209
+ raise Exception(f"列表内数据类型必须相同{value}")
146
210
 
147
211
  return list初始化列表(初始化列表, 数据类型列表, len(value))
148
212
 
@@ -151,15 +215,13 @@ class dict初始化列表:
151
215
  def __init__(
152
216
  self,
153
217
  代码: str,
154
- key类型列表: Union[List[Union[int, float, bool, str]],
155
- int, float, bool, str],
156
- value类型列表: Union[List[Union[int, float, bool, str]],
157
- int, float, bool, str]) -> None:
218
+ key类型列表,
219
+ value类型列表) -> None:
158
220
  self.代码 = 代码
159
- self.key类型列表 = key类型列表
160
- self.value类型列表 = value类型列表
161
- self.key类型 = py类型转c类型(key类型列表)
162
- self.value类型 = py类型转c类型(value类型列表)
221
+ self.keyPy类型 = key类型列表[0]
222
+ self.valuePy类型 = value类型列表[0]
223
+ self.key类型 = py类型转c类型(*key类型列表)
224
+ self.value类型 = py类型转c类型(*value类型列表)
163
225
 
164
226
  def __str__(self) -> str:
165
227
  return self.代码
@@ -171,19 +233,21 @@ def 从dict构建初始化列表(value: dict):
171
233
  value类型列表 = []
172
234
  for k, v in value.items():
173
235
  key类型 = type(k)
174
- cpp类型检查(key类型, 'Map')
175
236
  value类型 = type(v)
176
- cpp类型检查(value类型, 'Map')
177
237
  key类型列表.append(key类型)
178
238
  value类型列表.append(value类型)
179
239
  code.append(f'{{ {toCString(k)}, {v} }}')
180
240
 
181
241
  # 构建类型列表
182
242
  if all(类型 == key类型列表[0] for 类型 in key类型列表):
183
- key类型列表 = key类型列表[0]
243
+ key类型列表 = (key类型列表[0], k)
244
+ else:
245
+ raise Exception(f"key数据类型必须相同{value.keys()}")
184
246
 
185
247
  if all(类型 == value类型列表[0] for 类型 in value类型列表):
186
- value类型列表 = value类型列表[0]
248
+ value类型列表 = (value类型列表[0], v)
249
+ else:
250
+ raise Exception(f"value数据类型必须相同{value.values()}")
187
251
 
188
252
  # 构建初始化列表
189
253
  初始化列表 = '{' + ','.join(code) + '}'
@@ -19,68 +19,6 @@ class 代码异常抛出器:
19
19
  f'{错误信息} {self.代码行[node.lineno][node.col_offset:node.end_col_offset]}')
20
20
 
21
21
 
22
- class 花括号:
23
- def __init__(self, 编译器) -> None:
24
- self.编译器: py2cpp编译器 = 编译器
25
-
26
- def __enter__(self, *args, **kwargs):
27
- self.编译器.添加c代码('{')
28
- self.编译器.进入新作用域()
29
-
30
- def __exit__(self, *args, **kwargs):
31
- self.编译器.退出作用域()
32
- self.编译器.添加c代码('}\n')
33
-
34
-
35
- class c代码:
36
- def __init__(self, 代码: str, 层级: int) -> None:
37
- self.代码 = 代码
38
- self.层级 = 层级
39
-
40
- def __str__(self) -> str:
41
- return ' ' * self.层级 + self.代码
42
-
43
-
44
- class c获取索引项目:
45
- def __init__(self, 变量, 索引) -> None:
46
- self.变量 = 变量
47
- self.索引 = 索引
48
-
49
- def __str__(self) -> str:
50
- return f'{self.变量}[{toCString(self.索引)}]'
51
-
52
-
53
- class c获取属性:
54
- def __init__(self, 变量, 属性) -> None:
55
- self.变量 = 变量
56
- self.属性 = 属性
57
-
58
- def __str__(self) -> str:
59
- if isinstance(self.变量, c变量):
60
- if self.变量.类型.endswith('*'):
61
- return f'{self.变量}->{self.属性}'
62
- return f'{self.变量}.{self.属性}'
63
-
64
-
65
- class c函数调用:
66
- def __init__(self, 函数名, 参数字符串) -> None:
67
- self.函数名 = 函数名
68
- self.参数字符串 = 参数字符串
69
-
70
- def __str__(self) -> str:
71
- return f'{self.函数名}({self.参数字符串})'
72
-
73
-
74
- class c布尔:
75
- def __init__(self, v) -> None:
76
- self.v = v
77
-
78
- def __str__(self) -> str:
79
- if self.v:
80
- return 'true'
81
- return 'false'
82
-
83
-
84
22
  class py2cpp编译器(ast.NodeVisitor):
85
23
  def __init__(self, 被编译的函数: Callable, c编译器, 编译为可执行文件文件名: str | None = None) -> None:
86
24
  self.被编译的函数 = 被编译的函数
@@ -329,7 +267,7 @@ class py2cpp编译器(ast.NodeVisitor):
329
267
  for 库目录 in c类型.库目录:
330
268
  self.库目录.add(库目录)
331
269
  参数文本 = self.构建参数列表文本(node.args)
332
- return c函数调用(c类型, 参数文本)
270
+ return c函数调用(c类型, 参数文本, c类型.目标类型)
333
271
 
334
272
  # 直接调用函数
335
273
  if fn in 通用信息.直接调用函数:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: l0n0lc
3
- Version: 0.10.1
3
+ Version: 0.10.3
4
4
  Summary: 一个将python函数翻译为c++函数并运行的jit编译器
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Requires-Python: >=3.10
@@ -63,6 +63,7 @@ import l0n0lc as lc
63
63
  import math
64
64
  import 测试可执行
65
65
 
66
+
66
67
  @lc.映射函数(math.ceil, ['<cmath>'])
67
68
  def cpp_ceil(v):
68
69
  return f'std::ceil({lc.toCString(v)});'
@@ -112,6 +113,12 @@ class CppVectorInt:
112
113
  return 0
113
114
 
114
115
 
116
+ @lc.映射类型('short')
117
+ class ShortInt:
118
+ def __init__(self, v) -> None:
119
+ pass
120
+
121
+
115
122
  @lc.jit(每次运行都重新编译=True)
116
123
  def jit_all_ops(a: int, b: int) -> int:
117
124
  # 常量与基础赋值
@@ -120,8 +127,10 @@ def jit_all_ops(a: int, b: int) -> int:
120
127
  z = 3.14
121
128
  flag = True
122
129
  nums = [1, 2, 3]
130
+ numsshorts = [ShortInt(1), ShortInt(2), ShortInt(3)]
123
131
  tup = (4, 5)
124
132
  mp = {1: 10, 2: 20}
133
+ mp2 = {ShortInt(1): 10, ShortInt(2): 20}
125
134
 
126
135
  # 一元运算
127
136
  pos = +(a + 1)
@@ -202,6 +211,7 @@ def jit_all_ops(a: int, b: int) -> int:
202
211
  print('vector->', i, '=', vector[i])
203
212
  return y
204
213
 
214
+
205
215
  @lc.jit(每次运行都重新编译=True)
206
216
  def test_add(a: int, b: int) -> int:
207
217
  if a > 1:
@@ -243,7 +253,6 @@ def test_add(a: int, b: int) -> int:
243
253
 
244
254
  print('结果:', test_add(1, 3))
245
255
 
246
-
247
256
  ```
248
257
 
249
258
  ## 4. 运行hello_world.py
@@ -282,24 +291,24 @@ vv: 1
282
291
  ## 5. 查看输出文件
283
292
  ```bash
284
293
  ls -al ./l0n0lcoutput
285
- total 164
286
- drwxr-xr-x 2 root root 4096 Oct 16 01:39 .
287
- drwxrwxrwx 11 1000 1000 4096 Oct 16 01:39 ..
288
- -rw-r--r-- 1 root root 298 Oct 16 01:39 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
289
- -rw-r--r-- 1 root root 128 Oct 16 01:39 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.h
290
- -rw-r--r-- 1 root root 1811 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.cpp
291
- -rw-r--r-- 1 root root 167 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h
292
- -rwxr-xr-x 1 root root 23584 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.so
293
- -rw-r--r-- 1 root root 1531 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.cpp
294
- -rw-r--r-- 1 root root 398 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
295
- -rwxr-xr-x 1 root root 40408 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.so
296
- -rw-r--r-- 1 root root 155 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.cpp
297
- -rw-r--r-- 1 root root 106 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h
298
- -rwxr-xr-x 1 root root 15648 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.so
299
- -rw-r--r-- 1 root root 219 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.cpp
300
- -rw-r--r-- 1 root root 164 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h
301
- -rwxr-xr-x 1 root root 15688 Oct 16 01:39 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.so
302
- -rwxr-xr-x 1 root root 17248 Oct 16 01:39 测试可执行文件
294
+ total 176
295
+ drwxr-xr-x 2 root root 4096 Oct 22 02:25 .
296
+ drwxrwxrwx 11 1000 1000 4096 Oct 22 02:25 ..
297
+ -rw-r--r-- 1 root root 298 Oct 22 02:25 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
298
+ -rw-r--r-- 1 root root 128 Oct 22 02:25 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.h
299
+ -rw-r--r-- 1 root root 1944 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.cpp
300
+ -rw-r--r-- 1 root root 167 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h
301
+ -rwxr-xr-x 1 root root 29000 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.so
302
+ -rw-r--r-- 1 root root 1531 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.cpp
303
+ -rw-r--r-- 1 root root 398 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
304
+ -rwxr-xr-x 1 root root 41728 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.so
305
+ -rw-r--r-- 1 root root 155 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.cpp
306
+ -rw-r--r-- 1 root root 106 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h
307
+ -rwxr-xr-x 1 root root 15648 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.so
308
+ -rw-r--r-- 1 root root 219 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.cpp
309
+ -rw-r--r-- 1 root root 164 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h
310
+ -rwxr-xr-x 1 root root 15688 Oct 22 02:25 c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.so
311
+ -rwxr-xr-x 1 root root 17248 Oct 22 02:25 测试可执行文件
303
312
 
304
313
  ```
305
314
  ## 6. 6cbfb68e317eace4_测试可执行.py_可执行_@d82ed7910ac3268c.cpp
@@ -325,9 +334,9 @@ extern "C" int /*可执行*/ main (int argc, char** argv)
325
334
  #include <string>
326
335
  extern "C" int /*可执行*/ main (int argc, char** argv);
327
336
  ```
328
- ## 8. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.cpp
337
+ ## 8. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.cpp
329
338
  ```c++
330
- #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h"
339
+ #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h"
331
340
  extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
332
341
  {
333
342
  auto x = 42;
@@ -335,8 +344,10 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
335
344
  auto z = 3.14;
336
345
  auto flag = true;
337
346
  int64_t nums[] = {1,2,3};
347
+ short numsshorts[] = {short(1),short(2),short(3)};
338
348
  int64_t tup[] = {4,5};
339
349
  std::unordered_map<int64_t, int64_t> mp = {{ 1, 10 },{ 2, 20 }};
350
+ std::unordered_map<short, int64_t> mp2 = {{ short(1), 10 },{ short(2), 20 }};
340
351
  auto pos = (+(a + 1));
341
352
  auto neg = (-b);
342
353
  auto inv = (~a);
@@ -422,7 +433,7 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
422
433
  }
423
434
 
424
435
  ```
425
- ## 9. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h
436
+ ## 9. c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h
426
437
  ```c++
427
438
  #pragma once
428
439
  #include <cstdint>
@@ -500,7 +511,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
500
511
  ## 11. c31f68e99ed4ce3c_hello_world.py_test_add_@469de6acaaabc570.h
501
512
  ```c++
502
513
  #pragma once
503
- #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@7801528c3d61baf7.h"
514
+ #include "c31f68e99ed4ce3c_hello_world.py_jit_all_ops_@c636865fefd2fd71.h"
504
515
  #include "c31f68e99ed4ce3c_hello_world.py_test_other_fn_@75fdd928ab58a8e3.h"
505
516
  #include "c31f68e99ed4ce3c_hello_world.py_test编译的函数_@3bf4501e0408a243.h"
506
517
  #include <cmath>
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "l0n0lc"
3
- version = "0.10.1"
3
+ version = "0.10.3"
4
4
  description = "一个将python函数翻译为c++函数并运行的jit编译器"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
File without changes
File without changes
File without changes
File without changes
File without changes