l0n0lc 0.9.1__py3-none-any.whl → 0.9.3__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/StdMap.py CHANGED
@@ -1,5 +1,4 @@
1
- from .c基础处理 import py类型转c类型, dict初始化列表, c变量, cpp类型
2
- from typing import Tuple, Union, List
1
+ from .c基础处理 import dict初始化列表, c变量
3
2
  from .通用 import toCString
4
3
 
5
4
 
l0n0lc/jit.py CHANGED
@@ -198,25 +198,25 @@ class py2cpp编译器(ast.NodeVisitor):
198
198
  if isinstance(value, ast.UnaryOp):
199
199
  operand = self.获取值(value.operand)
200
200
  if isinstance(value.op, ast.UAdd):
201
- return f'+{operand}'
201
+ return f'(+{operand})'
202
202
  if isinstance(value.op, ast.USub):
203
- return f'-{operand}'
203
+ return f'(-{operand})'
204
204
  if isinstance(value.op, ast.Not):
205
- return f'!{operand}'
205
+ return f'(!{operand})'
206
206
  if isinstance(value.op, ast.Invert):
207
- return f'~{operand}'
207
+ return f'(~{operand})'
208
208
 
209
209
  if isinstance(value, ast.BoolOp):
210
210
  if isinstance(value.op, ast.And):
211
- return '&&'.join([str(self.获取值(v)) for v in value.values])
211
+ return '&&'.join([f'({self.获取值(v)})' for v in value.values])
212
212
  if isinstance(value.op, ast.Or):
213
- return '||'.join([str(self.获取值(v)) for v in value.values])
213
+ return '||'.join([f'({self.获取值(v)})' for v in value.values])
214
214
 
215
215
  if isinstance(value, ast.IfExp):
216
216
  test = self.获取值(value.test)
217
217
  body = self.获取值(value.body)
218
218
  orelse = self.获取值(value.orelse)
219
- return f'({test} ? ({body}) : ({orelse}))'
219
+ return f'(({test}) ? ({body}) : ({orelse}))'
220
220
 
221
221
  if isinstance(value, ast.Compare):
222
222
  return self.计算Compare(value)
@@ -251,19 +251,22 @@ class py2cpp编译器(ast.NodeVisitor):
251
251
  left = left if 输出left else ''
252
252
  right = self.获取值(comp)
253
253
  if isinstance(op, ast.Eq):
254
- ret += f'{left} == {right}'
254
+ ret += f'({left} == {right})'
255
255
  if isinstance(op, ast.NotEq):
256
- ret += f'{left} != {right}'
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
- ret += f'{left} <= {right}'
260
+ ret += f'({left} <= {right})'
261
261
  if isinstance(op, ast.Gt):
262
- ret += f'{left} > {right}'
262
+ ret += f'({left} > {right})'
263
263
  if isinstance(op, ast.GtE):
264
- ret += f'{left} >= {right}'
264
+ ret += f'({left} >= {right})'
265
265
  left = right
266
266
  输出left = False
267
+ # 如果只有一项, 不需要多层括号
268
+ if len(node.ops) == 1:
269
+ return ret[1:]
267
270
  return ret + ')'
268
271
 
269
272
  def 计算二元运算(self, node: ast.BinOp | ast.AugAssign):
@@ -275,25 +278,25 @@ class py2cpp编译器(ast.NodeVisitor):
275
278
  right = self.获取值(node.value)
276
279
  op = node.op
277
280
  if isinstance(op, ast.Add):
278
- return f'{left} + {right}'
281
+ return f'({left} + {right})'
279
282
  if isinstance(op, ast.Sub):
280
- return f'{left} - {right}'
283
+ return f'({left} - {right})'
281
284
  if isinstance(op, ast.Mult):
282
- return f'{left} * {right}'
285
+ return f'({left} * {right})'
283
286
  if isinstance(op, (ast.Div, ast.FloorDiv)):
284
- return f'{left} / {right}'
287
+ return f'({left} / {right})'
285
288
  if isinstance(op, ast.Mod):
286
- return f'{left} % {right}'
289
+ return f'({left} % {right})'
287
290
  if isinstance(op, ast.BitAnd):
288
- return f'{left} & {right}'
291
+ return f'({left} & {right})'
289
292
  if isinstance(op, ast.BitOr):
290
- return f'{left} | {right}'
293
+ return f'({left} | {right})'
291
294
  if isinstance(op, ast.BitXor):
292
- return f'{left} ^ {right}'
295
+ return f'({left} ^ {right})'
293
296
  if isinstance(op, ast.LShift):
294
- return f'{left} << {right}'
297
+ return f'({left} << {right})'
295
298
  if isinstance(op, ast.RShift):
296
- return f'{left} >> {right}'
299
+ return f'({left} >> {right})'
297
300
 
298
301
  self.抛出代码异常(f"暂不支持的运算符: {type(op).__name__}", node)
299
302
 
@@ -556,10 +559,10 @@ class py2cpp编译器(ast.NodeVisitor):
556
559
  值 = self.获取值(node.value)
557
560
  目标类型 = self.获取值(node.annotation)
558
561
  if 目标类型 is None:
559
- self.抛出代码异常(f'不支持的类型嗯{node.annotation}', node)
562
+ self.抛出代码异常(f'不支持的类型:{node.annotation}', node)
560
563
  c类型 = py类型转c类型(目标类型)
561
564
  if c类型 is None:
562
- self.抛出代码异常(f'不支持的类型嗯{目标类型}', node)
565
+ self.抛出代码异常(f'不支持的类型:{目标类型}', node)
563
566
  self._赋值(node.target, 值, node, str(c类型))
564
567
 
565
568
  def 获取定义(self):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: l0n0lc
3
- Version: 0.9.1
3
+ Version: 0.9.3
4
4
  Summary: 一个将python函数翻译为c++函数并运行的jit编译器
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Requires-Python: >=3.10
@@ -69,7 +69,7 @@ class CppVectorInt:
69
69
  return 0
70
70
 
71
71
 
72
- @lc.jit()
72
+ @lc.jit(每次运行都重新编译=True)
73
73
  def jit_all_ops(a: int, b: int) -> int:
74
74
  # 常量与基础赋值
75
75
  x = 42
@@ -81,7 +81,7 @@ def jit_all_ops(a: int, b: int) -> int:
81
81
  mp = {1: 10, 2: 20}
82
82
 
83
83
  # 一元运算
84
- pos = +a
84
+ pos = +(a + 1)
85
85
  neg = -b
86
86
  inv = ~a
87
87
  not_flag = not flag
@@ -162,7 +162,7 @@ def jit_all_ops(a: int, b: int) -> int:
162
162
  @lc.jit(每次运行都重新编译=True)
163
163
  def test_add(a: int, b: int) -> int:
164
164
  if a > 1:
165
- return a + b
165
+ return (a + b) * 123123
166
166
  for i in range(1, 10, 2):
167
167
  a += i
168
168
  for i in [1, 2, 3]:
@@ -189,7 +189,7 @@ def test_add(a: int, b: int) -> int:
189
189
  vv = True and (False or 1)
190
190
  print('vv:', vv)
191
191
  print('测试while:')
192
- while (vv):
192
+ while vv:
193
193
  py_cin(v)
194
194
  if v > 100:
195
195
  break
@@ -235,75 +235,75 @@ vv: 1
235
235
  ```bash
236
236
  ls -al ./l0n0lcoutput
237
237
  total 136
238
- drwxr-xr-x 2 root root 4096 Sep 18 01:26 .
239
- drwxrwxrwx 11 1000 1000 4096 Sep 18 01:26 ..
240
- -rw-r--r-- 1 root root 1693 Sep 18 01:26 jit_all_ops_@0ec883892076cd03.cpp
241
- -rw-r--r-- 1 root root 167 Sep 18 01:26 jit_all_ops_@0ec883892076cd03.h
242
- -rwxr-xr-x 1 root root 23520 Sep 18 01:26 jit_all_ops_@0ec883892076cd03.so
243
- -rw-r--r-- 1 root root 1466 Sep 18 01:26 test_add_@122c4be59097d472.cpp
244
- -rw-r--r-- 1 root root 302 Sep 18 01:26 test_add_@122c4be59097d472.h
245
- -rwxr-xr-x 1 root root 40216 Sep 18 01:26 test_add_@122c4be59097d472.so
246
- -rw-r--r-- 1 root root 121 Sep 18 01:26 test_other_fn_@75fdd928ab58a8e3.cpp
247
- -rw-r--r-- 1 root root 106 Sep 18 01:26 test_other_fn_@75fdd928ab58a8e3.h
248
- -rwxr-xr-x 1 root root 15616 Sep 18 01:26 test_other_fn_@75fdd928ab58a8e3.so
249
- -rw-r--r-- 1 root root 185 Sep 18 01:26 test编译的函数_@3bf4501e0408a243.cpp
250
- -rw-r--r-- 1 root root 164 Sep 18 01:26 test编译的函数_@3bf4501e0408a243.h
251
- -rwxr-xr-x 1 root root 15656 Sep 18 01:26 test编译的函数_@3bf4501e0408a243.so
238
+ drwxr-xr-x 2 root root 4096 Sep 18 02:00 .
239
+ drwxrwxrwx 11 1000 1000 4096 Sep 18 02:00 ..
240
+ -rw-r--r-- 1 root root 1779 Sep 18 02:00 jit_all_ops_@7801528c3d61baf7.cpp
241
+ -rw-r--r-- 1 root root 167 Sep 18 02:00 jit_all_ops_@7801528c3d61baf7.h
242
+ -rwxr-xr-x 1 root root 23520 Sep 18 02:00 jit_all_ops_@7801528c3d61baf7.so
243
+ -rw-r--r-- 1 root root 1499 Sep 18 02:00 test_add_@469de6acaaabc570.cpp
244
+ -rw-r--r-- 1 root root 302 Sep 18 02:00 test_add_@469de6acaaabc570.h
245
+ -rwxr-xr-x 1 root root 40216 Sep 18 02:00 test_add_@469de6acaaabc570.so
246
+ -rw-r--r-- 1 root root 123 Sep 18 02:00 test_other_fn_@75fdd928ab58a8e3.cpp
247
+ -rw-r--r-- 1 root root 106 Sep 18 02:00 test_other_fn_@75fdd928ab58a8e3.h
248
+ -rwxr-xr-x 1 root root 15616 Sep 18 02:00 test_other_fn_@75fdd928ab58a8e3.so
249
+ -rw-r--r-- 1 root root 187 Sep 18 02:00 test编译的函数_@3bf4501e0408a243.cpp
250
+ -rw-r--r-- 1 root root 164 Sep 18 02:00 test编译的函数_@3bf4501e0408a243.h
251
+ -rwxr-xr-x 1 root root 15656 Sep 18 02:00 test编译的函数_@3bf4501e0408a243.so
252
252
 
253
253
  ```
254
- ## 5. jit_all_ops_@0ec883892076cd03.cpp
254
+ ## 5. jit_all_ops_@7801528c3d61baf7.cpp
255
255
  ```c++
256
- #include "jit_all_ops_@0ec883892076cd03.h"
256
+ #include "jit_all_ops_@7801528c3d61baf7.h"
257
257
  extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
258
258
  {
259
259
  auto x = 42;
260
- auto y = ((int64_t)(a + b));
260
+ auto y = ((int64_t)((a + b)));
261
261
  auto z = 3.14;
262
262
  auto flag = true;
263
263
  int64_t nums[] = {1,2,3};
264
264
  int64_t tup[] = {4,5};
265
265
  std::unordered_map<int64_t, int64_t> mp = {{ 1, 10 },{ 2, 20 }};
266
- auto pos = +a;
267
- auto neg = -b;
268
- auto inv = ~a;
269
- auto not_flag = !flag;
270
- auto add = a + b;
271
- auto sub = a - b;
272
- auto mul = a * b;
273
- auto div = a / ((b != 0) ? (b) : (1));
274
- auto mod = a % ((b != 0) ? (b) : (1));
275
- auto band = a & b;
276
- auto bor = a | b;
277
- auto bxor = a ^ b;
278
- auto lshift = a << 1;
279
- auto rshift = a >> 1;
266
+ auto pos = (+(a + 1));
267
+ auto neg = (-b);
268
+ auto inv = (~a);
269
+ auto not_flag = (!flag);
270
+ auto add = (a + b);
271
+ auto sub = (a - b);
272
+ auto mul = (a * b);
273
+ auto div = (a / (((b != 0)) ? (b) : (1)));
274
+ auto mod = (a % (((b != 0)) ? (b) : (1)));
275
+ auto band = (a & b);
276
+ auto bor = (a | b);
277
+ auto bxor = (a ^ b);
278
+ auto lshift = (a << 1);
279
+ auto rshift = (a >> 1);
280
280
  auto cmp1 = (a == b);
281
281
  auto cmp2 = (a != b);
282
282
  auto cmp3 = (a < b);
283
283
  auto cmp4 = (a <= b);
284
284
  auto cmp5 = (a > b);
285
285
  auto cmp6 = (a >= b);
286
- auto logic_and = cmp1&&cmp2;
287
- auto logic_or = cmp3||cmp4;
288
- auto ternary = ((a > b) ? (a) : (b));
286
+ auto logic_and = (cmp1)&&(cmp2);
287
+ auto logic_or = (cmp3)||(cmp4);
288
+ auto ternary = (((a > b)) ? (a) : (b));
289
289
  if ((a > b))
290
290
  {
291
- y = y + 1;
291
+ y = (y + 1);
292
292
  }
293
293
 
294
294
  else
295
295
  {
296
- y = y - 1;
296
+ y = (y - 1);
297
297
  }
298
298
 
299
299
  for (int64_t i = 0; i < 3; ++i)
300
300
  {
301
- y = y + i;
301
+ y = (y + i);
302
302
  }
303
303
 
304
304
  for (auto v : nums)
305
305
  {
306
- y = y + v;
306
+ y = (y + v);
307
307
  if ((v == 2))
308
308
  {
309
309
  continue;
@@ -319,23 +319,23 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
319
319
  auto count = 0;
320
320
  while ((count < 2))
321
321
  {
322
- y = y + count;
323
- count = count + 1;
322
+ y = (y + count);
323
+ count = (count + 1);
324
324
  }
325
325
 
326
- y = y + 5;
327
- y = y - 1;
328
- y = y * 2;
329
- y = y / 2;
330
- y = y % 10;
331
- y = y & 7;
332
- y = y | 3;
333
- y = y ^ 1;
334
- y = y << 1;
335
- y = y >> 1;
326
+ y = (y + 5);
327
+ y = (y - 1);
328
+ y = (y * 2);
329
+ y = (y / 2);
330
+ y = (y % 10);
331
+ y = (y & 7);
332
+ y = (y | 3);
333
+ y = (y ^ 1);
334
+ y = (y << 1);
335
+ y = (y >> 1);
336
336
  auto first_num = nums[0];
337
337
  auto mp_val = mp[1];
338
- y = y + first_num + mp_val;
338
+ y = (y + (first_num + mp_val));
339
339
  auto vector = std::vector<int>();
340
340
  vector.push_back(count);
341
341
  vector.push_back(y);
@@ -348,7 +348,7 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
348
348
  }
349
349
 
350
350
  ```
351
- ## 6. jit_all_ops_@0ec883892076cd03.h
351
+ ## 6. jit_all_ops_@7801528c3d61baf7.h
352
352
  ```c++
353
353
  #pragma once
354
354
  #include <cstdint>
@@ -358,24 +358,24 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
358
358
  #include <vector>
359
359
  extern "C" int64_t jit_all_ops (int64_t a, int64_t b);
360
360
  ```
361
- ## 7. test_add_@122c4be59097d472.cpp
361
+ ## 7. test_add_@469de6acaaabc570.cpp
362
362
  ```c++
363
- #include "test_add_@122c4be59097d472.h"
363
+ #include "test_add_@469de6acaaabc570.h"
364
364
  extern "C" int64_t test_add (int64_t a, int64_t b)
365
365
  {
366
366
  if ((a > 1))
367
367
  {
368
- return a + b;
368
+ return ((a + b) * 123123);
369
369
  }
370
370
 
371
371
  for (int64_t i = 1; i < 10; i += 2)
372
372
  {
373
- a = a + i;
373
+ a = (a + i);
374
374
  }
375
375
 
376
376
  for (auto i : {1,2,3})
377
377
  {
378
- a = a + i;
378
+ a = (a + i);
379
379
  }
380
380
 
381
381
  a = std::ceil(12.5);;
@@ -401,7 +401,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
401
401
  std::cout<< u8"测试所有操作:" << " "<< std::endl;;
402
402
  jit_all_ops(a,b);
403
403
  auto v = 0;
404
- auto vv = true&&false||1;
404
+ auto vv = (true)&&((false)||(1));
405
405
  std::cout<< u8"vv:" << " "<< vv << " "<< std::endl;;
406
406
  std::cout<< u8"测试while:" << " "<< std::endl;;
407
407
  while (vv)
@@ -419,14 +419,14 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
419
419
 
420
420
  }
421
421
 
422
- return a + b + 1 + 123 + v;
422
+ return ((((a + b) + 1) + 123) + v);
423
423
  }
424
424
 
425
425
  ```
426
- ## 8. test_add_@122c4be59097d472.h
426
+ ## 8. test_add_@469de6acaaabc570.h
427
427
  ```c++
428
428
  #pragma once
429
- #include "jit_all_ops_@0ec883892076cd03.h"
429
+ #include "jit_all_ops_@7801528c3d61baf7.h"
430
430
  #include "test_other_fn_@75fdd928ab58a8e3.h"
431
431
  #include "test编译的函数_@3bf4501e0408a243.h"
432
432
  #include <cmath>
@@ -441,7 +441,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
441
441
  #include "test_other_fn_@75fdd928ab58a8e3.h"
442
442
  extern "C" int64_t test_other_fn (int64_t a, int64_t b)
443
443
  {
444
- return a - b;
444
+ return (a - b);
445
445
  }
446
446
 
447
447
  ```
@@ -457,7 +457,7 @@ extern "C" int64_t test_other_fn (int64_t a, int64_t b);
457
457
  #include "test编译的函数_@3bf4501e0408a243.h"
458
458
  extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b)
459
459
  {
460
- return a * b;
460
+ return (a * b);
461
461
  }
462
462
 
463
463
  ```
@@ -0,0 +1,12 @@
1
+ l0n0lc/StdList.py,sha256=0NTIpaRrNHaCiLrRbEVob21pZHa8S8rfaBRALPT-tD0,889
2
+ l0n0lc/StdMap.py,sha256=997LCvP0ewNciabbmGHVL2eUgMakHBsR3c5HQmOwC_E,666
3
+ l0n0lc/__init__.py,sha256=fUC6TMeN_fEL7HDazrBEdoWOQkXi5uSGZb7LZj6juog,137
4
+ l0n0lc/c基础处理.py,sha256=GrCPZpLsyfQD8XZQhOCb5y8v9NCZ6bU4C_xfJGx-pvQ,5723
5
+ l0n0lc/jit.py,sha256=78OtYwz5GHdeVAU_m6MRyKG53ElE9TTeuQ9ZyuRb_QU,25771
6
+ l0n0lc/编译.py,sha256=Ty4gPDHAB1jn8LgnE4w3R06bOAEeYr8iwqahYf6QeHI,2154
7
+ l0n0lc/通用.py,sha256=RkqP9cMhKhl2h4YxOpAWFFftIPXLZTYMyOOD1PuB59M,4630
8
+ l0n0lc-0.9.3.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
9
+ l0n0lc-0.9.3.dist-info/METADATA,sha256=BAPktGzCmMJ2imiv9HPMe71udjcNYyzP9nFugzygXUc,10130
10
+ l0n0lc-0.9.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ l0n0lc-0.9.3.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
12
+ l0n0lc-0.9.3.dist-info/RECORD,,
@@ -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=GrCPZpLsyfQD8XZQhOCb5y8v9NCZ6bU4C_xfJGx-pvQ,5723
5
- l0n0lc/jit.py,sha256=UG5CwhmtD9BJWWiWreFxDCTCFgKgjSOqREhaZuW3sBU,25619
6
- l0n0lc/编译.py,sha256=Ty4gPDHAB1jn8LgnE4w3R06bOAEeYr8iwqahYf6QeHI,2154
7
- l0n0lc/通用.py,sha256=RkqP9cMhKhl2h4YxOpAWFFftIPXLZTYMyOOD1PuB59M,4630
8
- l0n0lc-0.9.1.dist-info/licenses/LICENSE,sha256=1L-MAjulZ3kpbYwsJtlXpDVITRxykna2Ecg_521YfkA,1093
9
- l0n0lc-0.9.1.dist-info/METADATA,sha256=Dp2vjz7C65AR-9SE__1Trhtw1qVvusPbQVXVutZ4OW4,9960
10
- l0n0lc-0.9.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- l0n0lc-0.9.1.dist-info/top_level.txt,sha256=Q21D_eEY_-xgRUPwATGp9YDKSBO4w_7MI2MYxQI1aT4,7
12
- l0n0lc-0.9.1.dist-info/RECORD,,
File without changes