l0n0lc 0.5.1__py3-none-any.whl → 0.7.1__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.
@@ -1,6 +1,5 @@
1
1
  from typing import Union, List, get_origin, get_args
2
2
  from .通用 import 生成变量Id, toCString
3
- import numpy as np
4
3
  import ctypes
5
4
 
6
5
 
@@ -61,10 +60,6 @@ def py类型转ctypes类型(类型):
61
60
  if 类型 is 指针:
62
61
  return ctypes.c_void_p
63
62
 
64
- # numpy dtype 转换
65
- return numpy类型转ctypes类型(类型)
66
-
67
-
68
63
  额外py转c函数 = []
69
64
 
70
65
 
@@ -104,98 +99,12 @@ def py类型转c类型(类型):
104
99
  val_type = py类型转c类型(args[1])
105
100
  return f"std::unordered_map<{key_type}, {val_type}>&"
106
101
 
107
- # numpy dtype 转换
108
- ret = numpy类型转c类型(类型)
109
- if ret is not None:
110
- return ret
111
-
112
102
  # 直接传字符串类型名
113
103
  if isinstance(类型, str):
114
104
  return 类型
115
105
 
116
106
  return cpp类型.ANY
117
107
 
118
-
119
- 额外numpy转ctypes函数 = []
120
-
121
-
122
- def numpy类型转ctypes类型(npdtype):
123
- ret = 执行额外函数(额外numpy转ctypes函数, npdtype)
124
- if ret is not None:
125
- return ret
126
-
127
- if npdtype == np.int8:
128
- return ctypes.c_int8
129
- if npdtype == np.int16:
130
- return ctypes.c_int16
131
- if npdtype == np.int32:
132
- return ctypes.c_int32
133
- if npdtype == np.int64:
134
- return ctypes.c_int64
135
- if npdtype == np.uint8:
136
- return ctypes.c_uint8
137
- if npdtype == np.uint16:
138
- return ctypes.c_uint16
139
- if npdtype == np.uint32:
140
- return ctypes.c_uint32
141
- if npdtype == np.uint64:
142
- return ctypes.c_uint64
143
- try:
144
- if npdtype == np.bool_:
145
- return ctypes.c_bool
146
- except:
147
- pass
148
- try:
149
- if npdtype == np.bool: # type: ignore
150
- return ctypes.c_bool
151
- except:
152
- pass
153
- if npdtype == np.float32:
154
- return ctypes.c_float
155
- if npdtype == np.float64:
156
- return ctypes.c_double
157
-
158
-
159
- 额外numpy转c函数 = []
160
-
161
-
162
- def numpy类型转c类型(npdtype):
163
- ret = 执行额外函数(额外numpy转c函数, npdtype)
164
- if ret is not None:
165
- return ret
166
-
167
- if npdtype == np.int8:
168
- return cpp类型.INT8_T
169
- if npdtype == np.int16:
170
- return cpp类型.INT16_T
171
- if npdtype == np.int32:
172
- return cpp类型.INT32_T
173
- if npdtype == np.int64:
174
- return cpp类型.INT64_T
175
- if npdtype == np.uint8:
176
- return cpp类型.UINT8_T
177
- if npdtype == np.uint16:
178
- return cpp类型.UINT16_T
179
- if npdtype == np.uint32:
180
- return cpp类型.UINT32_T
181
- if npdtype == np.uint64:
182
- return cpp类型.UINT64_T
183
- try:
184
- if npdtype == np.bool_:
185
- return cpp类型.BOOL
186
- except:
187
- pass
188
- try:
189
- if npdtype == np.bool: # type: ignore
190
- return cpp类型.BOOL
191
- except:
192
- pass
193
- if npdtype == np.float16:
194
- return cpp类型.HALF
195
- if npdtype == np.float32:
196
- return cpp类型.FLOAT
197
-
198
-
199
108
  def cpp类型检查(类型, 支持提示: str):
200
109
  if 类型 not in [int, float, str, bool]:
201
110
  raise Exception(f'{支持提示} 仅支持 [int, float, str, bool]')
@@ -235,15 +144,6 @@ def 从list构建初始化列表(value: List):
235
144
  return list初始化列表(初始化列表, 数据类型列表, len(value))
236
145
 
237
146
 
238
- def 从ndarray构建初始化列表(value: np.ndarray):
239
- value = value.reshape(value.size)
240
- 类型 = numpy类型转c类型(value.dtype)
241
- if 类型 is None:
242
- raise Exception(f'暂不支持{value.dtype}')
243
- 初始化列表 = '{' + ','.join(value) + '}'
244
- return list初始化列表(初始化列表, 类型, value.size)
245
-
246
-
247
147
  class dict初始化列表:
248
148
  def __init__(
249
149
  self,
l0n0lc/jit.py CHANGED
@@ -50,6 +50,18 @@ class c获取索引项目:
50
50
  return f'{self.变量}[{toCString(self.索引)}]'
51
51
 
52
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
+
53
65
  class py2cpp编译器(ast.NodeVisitor):
54
66
  def __init__(self, 被编译的函数: Callable) -> None:
55
67
  self.被编译的函数 = 被编译的函数
@@ -144,7 +156,7 @@ class py2cpp编译器(ast.NodeVisitor):
144
156
  if isinstance(value, ast.Attribute):
145
157
  对象 = self.获取值(value.value)
146
158
  if isinstance(对象, c变量):
147
- return f'{对象}.{value.attr}'
159
+ return c获取属性(对象, value.attr)
148
160
  if 对象 is None:
149
161
  self.抛出代码异常(f'没找到{value.value}', value)
150
162
  return getattr(对象, value.attr)
@@ -290,10 +302,6 @@ class py2cpp编译器(ast.NodeVisitor):
290
302
  参数字符串 = ','.join(参数列表)
291
303
  return f'{fn.__name__}({参数字符串});'
292
304
 
293
- def 获取numpy属性(self, 对象, 属性):
294
- if 属性 == 'size':
295
- pass
296
-
297
305
  def 获取Subscript(self, node: ast.Subscript):
298
306
  对象 = self.获取值(node.value)
299
307
  切片 = node.slice
@@ -1,12 +1,11 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: l0n0lc
3
- Version: 0.5.1
3
+ Version: 0.7.1
4
4
  Summary: 用python写c
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Requires-Python: >=3.10
7
7
  Description-Content-Type: text/markdown
8
8
  License-File: LICENSE
9
- Requires-Dist: numpy>=1.26.0
10
9
  Dynamic: license-file
11
10
 
12
11
  # 将python函数翻译为c++函数并运行
@@ -41,25 +40,34 @@ def test_add(a: int, b: int) -> int:
41
40
  a += i
42
41
  a = math.ceil(12.5)
43
42
  cc = {'a': 1, 'b': 2}
44
- cc['123'] = 111
43
+ cc['c'] = 3
44
+ print('输出map:')
45
+ for ii in cc:
46
+ print(ii.first, ii.second) # type: ignore
45
47
  aa = [1, 3, 2]
46
48
  aa[0] = 134
49
+ print('输出list:')
47
50
  for i in range(3):
48
51
  print(i, aa[i])
49
52
  print('Hello World', a, b)
50
53
  return a + b + 1
51
54
 
52
55
 
53
- print(test_add(1, 3))
56
+ print('结果:', test_add(1, 3))
54
57
  ```
55
58
  ## 执行hello_world.py
56
59
  ```bash
57
60
  $ python hello_world.py
61
+ 输出map:
62
+ c 3
63
+ a 1
64
+ b 2
65
+ 输出list:
58
66
  0 134
59
67
  1 3
60
68
  2 2
61
69
  Hello World 13 3
62
- 17
70
+ 结果: 17
63
71
  ```
64
72
  ## 查看生成的c++代码文件
65
73
  ```bash
@@ -85,7 +93,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
85
93
 
86
94
  ## test_add_@402bbf73254216d8.cpp
87
95
  ```c++
88
- #include "test_add_@402bbf73254216d8.h"
96
+ #include "test_add_@141921ba1aaa0352.h"
89
97
  extern "C" int64_t test_add (int64_t a, int64_t b)
90
98
  {
91
99
  if ((a > 1))
@@ -105,9 +113,16 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
105
113
 
106
114
  a = std::ceil(12.5);;
107
115
  std::unordered_map<std::string, int64_t> cc = {{ u8"a", 1 },{ u8"b", 2 }};
108
- cc[u8"123"] = 111;
116
+ cc[u8"c"] = 3;
117
+ std::cout<< u8"输出map:" << " "<< std::endl;
118
+ for (auto ii : cc)
119
+ {
120
+ std::cout<< ii.first << " "<< ii.second << " "<< std::endl;
121
+ }
122
+
109
123
  int64_t aa[] = {1,3,2};
110
124
  aa[0] = 134;
125
+ std::cout<< u8"输出list:" << " "<< std::endl;
111
126
  for (int64_t i = 0; i < 3; ++i)
112
127
  {
113
128
  std::cout<< i << " "<< aa[i] << " "<< std::endl;
@@ -116,5 +131,4 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
116
131
  std::cout<< u8"Hello World" << " "<< a << " "<< b << " "<< std::endl;
117
132
  return a + b + 1;
118
133
  }
119
-
120
134
  ```
@@ -0,0 +1,12 @@
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=8BjvTeRzRK8CPkRCRvEjTNnFGJslLwC2R5JRE4Plo5o,22998
6
+ l0n0lc/编译.py,sha256=f1ugdTpnKcDOprcGu2Q5zMm_sYdxWMphBeo4ZL-cW3o,2016
7
+ l0n0lc/通用.py,sha256=O_Y4bbW1WzHCJkibxAy9WGACv-aEZJLG-fEeVBcAbBQ,3649
8
+ l0n0lc-0.7.1.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
9
+ l0n0lc-0.7.1.dist-info/METADATA,sha256=f4mekJITeqhyeuP7dZV_FhX58VvgA6-99miKbZJW0KA,2760
10
+ l0n0lc-0.7.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ l0n0lc-0.7.1.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
12
+ l0n0lc-0.7.1.dist-info/RECORD,,
@@ -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=ZJEMxK1MyRAgbUnpfUUZC0ZHj61RCD6UMlhVssCyiCE,8201
5
- l0n0lc/jit.py,sha256=N4R5KDDhRnn0eAmNI_8wOWgiCSdi3D8CP_RogXbj4as,22730
6
- l0n0lc/编译.py,sha256=f1ugdTpnKcDOprcGu2Q5zMm_sYdxWMphBeo4ZL-cW3o,2016
7
- l0n0lc/通用.py,sha256=O_Y4bbW1WzHCJkibxAy9WGACv-aEZJLG-fEeVBcAbBQ,3649
8
- l0n0lc-0.5.1.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
9
- l0n0lc-0.5.1.dist-info/METADATA,sha256=soTH6jJhHdlThj4Ngiapf85P-25SD4OYRfBiaCEWxKA,2429
10
- l0n0lc-0.5.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- l0n0lc-0.5.1.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
12
- l0n0lc-0.5.1.dist-info/RECORD,,
File without changes