l0n0lc 0.9.0__tar.gz → 0.9.2__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.
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/PKG-INFO +69 -54
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/README.md +68 -53
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc/StdMap.py +1 -2
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc/jit.py +26 -23
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc.egg-info/PKG-INFO +69 -54
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/pyproject.toml +1 -1
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/LICENSE +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc/StdList.py +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc/__init__.py +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc/c/345/237/272/347/241/200/345/244/204/347/220/206.py" +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc//347/274/226/350/257/221.py" +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc//351/200/232/347/224/250.py" +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc.egg-info/SOURCES.txt +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc.egg-info/dependency_links.txt +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/l0n0lc.egg-info/top_level.txt +0 -0
- {l0n0lc-0.9.0 → l0n0lc-0.9.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: l0n0lc
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.2
|
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
|
192
|
+
while vv:
|
193
193
|
py_cin(v)
|
194
194
|
if v > 100:
|
195
195
|
break
|
@@ -234,61 +234,76 @@ vv: 1
|
|
234
234
|
## 4. 查看输出文件
|
235
235
|
```bash
|
236
236
|
ls -al ./l0n0lcoutput
|
237
|
+
total 136
|
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
|
237
252
|
|
238
253
|
```
|
239
|
-
## 5. jit_all_ops_@
|
254
|
+
## 5. jit_all_ops_@7801528c3d61baf7.cpp
|
240
255
|
```c++
|
241
|
-
#include "jit_all_ops_@
|
256
|
+
#include "jit_all_ops_@7801528c3d61baf7.h"
|
242
257
|
extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
243
258
|
{
|
244
259
|
auto x = 42;
|
245
|
-
auto y = ((int64_t)(a + b));
|
260
|
+
auto y = ((int64_t)((a + b)));
|
246
261
|
auto z = 3.14;
|
247
262
|
auto flag = true;
|
248
263
|
int64_t nums[] = {1,2,3};
|
249
264
|
int64_t tup[] = {4,5};
|
250
265
|
std::unordered_map<int64_t, int64_t> mp = {{ 1, 10 },{ 2, 20 }};
|
251
|
-
auto pos = +a;
|
252
|
-
auto neg = -b;
|
253
|
-
auto inv = ~a;
|
254
|
-
auto not_flag = !flag;
|
255
|
-
auto add = a + b;
|
256
|
-
auto sub = a - b;
|
257
|
-
auto mul = a * b;
|
258
|
-
auto div = a / ((b != 0) ? (b) : (1));
|
259
|
-
auto mod = a % ((b != 0) ? (b) : (1));
|
260
|
-
auto band = a & b;
|
261
|
-
auto bor = a | b;
|
262
|
-
auto bxor = a ^ b;
|
263
|
-
auto lshift = a << 1;
|
264
|
-
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);
|
265
280
|
auto cmp1 = (a == b);
|
266
281
|
auto cmp2 = (a != b);
|
267
282
|
auto cmp3 = (a < b);
|
268
283
|
auto cmp4 = (a <= b);
|
269
284
|
auto cmp5 = (a > b);
|
270
285
|
auto cmp6 = (a >= b);
|
271
|
-
auto logic_and = cmp1&&cmp2;
|
272
|
-
auto logic_or = cmp3||cmp4;
|
273
|
-
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));
|
274
289
|
if ((a > b))
|
275
290
|
{
|
276
|
-
y = y + 1;
|
291
|
+
y = (y + 1);
|
277
292
|
}
|
278
293
|
|
279
294
|
else
|
280
295
|
{
|
281
|
-
y = y - 1;
|
296
|
+
y = (y - 1);
|
282
297
|
}
|
283
298
|
|
284
299
|
for (int64_t i = 0; i < 3; ++i)
|
285
300
|
{
|
286
|
-
y = y + i;
|
301
|
+
y = (y + i);
|
287
302
|
}
|
288
303
|
|
289
304
|
for (auto v : nums)
|
290
305
|
{
|
291
|
-
y = y + v;
|
306
|
+
y = (y + v);
|
292
307
|
if ((v == 2))
|
293
308
|
{
|
294
309
|
continue;
|
@@ -304,23 +319,23 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
304
319
|
auto count = 0;
|
305
320
|
while ((count < 2))
|
306
321
|
{
|
307
|
-
y = y + count;
|
308
|
-
count = count + 1;
|
322
|
+
y = (y + count);
|
323
|
+
count = (count + 1);
|
309
324
|
}
|
310
325
|
|
311
|
-
y = y + 5;
|
312
|
-
y = y - 1;
|
313
|
-
y = y * 2;
|
314
|
-
y = y / 2;
|
315
|
-
y = y % 10;
|
316
|
-
y = y & 7;
|
317
|
-
y = y | 3;
|
318
|
-
y = y ^ 1;
|
319
|
-
y = y << 1;
|
320
|
-
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);
|
321
336
|
auto first_num = nums[0];
|
322
337
|
auto mp_val = mp[1];
|
323
|
-
y = y + first_num + mp_val;
|
338
|
+
y = (y + (first_num + mp_val));
|
324
339
|
auto vector = std::vector<int>();
|
325
340
|
vector.push_back(count);
|
326
341
|
vector.push_back(y);
|
@@ -333,7 +348,7 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
333
348
|
}
|
334
349
|
|
335
350
|
```
|
336
|
-
## 6. jit_all_ops_@
|
351
|
+
## 6. jit_all_ops_@7801528c3d61baf7.h
|
337
352
|
```c++
|
338
353
|
#pragma once
|
339
354
|
#include <cstdint>
|
@@ -343,24 +358,24 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
343
358
|
#include <vector>
|
344
359
|
extern "C" int64_t jit_all_ops (int64_t a, int64_t b);
|
345
360
|
```
|
346
|
-
## 7. test_add_@
|
361
|
+
## 7. test_add_@469de6acaaabc570.cpp
|
347
362
|
```c++
|
348
|
-
#include "test_add_@
|
363
|
+
#include "test_add_@469de6acaaabc570.h"
|
349
364
|
extern "C" int64_t test_add (int64_t a, int64_t b)
|
350
365
|
{
|
351
366
|
if ((a > 1))
|
352
367
|
{
|
353
|
-
return a + b;
|
368
|
+
return ((a + b) * 123123);
|
354
369
|
}
|
355
370
|
|
356
371
|
for (int64_t i = 1; i < 10; i += 2)
|
357
372
|
{
|
358
|
-
a = a + i;
|
373
|
+
a = (a + i);
|
359
374
|
}
|
360
375
|
|
361
376
|
for (auto i : {1,2,3})
|
362
377
|
{
|
363
|
-
a = a + i;
|
378
|
+
a = (a + i);
|
364
379
|
}
|
365
380
|
|
366
381
|
a = std::ceil(12.5);;
|
@@ -386,7 +401,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
|
|
386
401
|
std::cout<< u8"测试所有操作:" << " "<< std::endl;;
|
387
402
|
jit_all_ops(a,b);
|
388
403
|
auto v = 0;
|
389
|
-
auto vv = true&&false||1;
|
404
|
+
auto vv = (true)&&((false)||(1));
|
390
405
|
std::cout<< u8"vv:" << " "<< vv << " "<< std::endl;;
|
391
406
|
std::cout<< u8"测试while:" << " "<< std::endl;;
|
392
407
|
while (vv)
|
@@ -404,14 +419,14 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
|
|
404
419
|
|
405
420
|
}
|
406
421
|
|
407
|
-
return a + b + 1 + 123 + v;
|
422
|
+
return ((((a + b) + 1) + 123) + v);
|
408
423
|
}
|
409
424
|
|
410
425
|
```
|
411
|
-
## 8. test_add_@
|
426
|
+
## 8. test_add_@469de6acaaabc570.h
|
412
427
|
```c++
|
413
428
|
#pragma once
|
414
|
-
#include "jit_all_ops_@
|
429
|
+
#include "jit_all_ops_@7801528c3d61baf7.h"
|
415
430
|
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
416
431
|
#include "test编译的函数_@3bf4501e0408a243.h"
|
417
432
|
#include <cmath>
|
@@ -426,7 +441,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
|
|
426
441
|
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
427
442
|
extern "C" int64_t test_other_fn (int64_t a, int64_t b)
|
428
443
|
{
|
429
|
-
return a - b;
|
444
|
+
return (a - b);
|
430
445
|
}
|
431
446
|
|
432
447
|
```
|
@@ -442,7 +457,7 @@ extern "C" int64_t test_other_fn (int64_t a, int64_t b);
|
|
442
457
|
#include "test编译的函数_@3bf4501e0408a243.h"
|
443
458
|
extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b)
|
444
459
|
{
|
445
|
-
return a * b;
|
460
|
+
return (a * b);
|
446
461
|
}
|
447
462
|
|
448
463
|
```
|
@@ -59,7 +59,7 @@ class CppVectorInt:
|
|
59
59
|
return 0
|
60
60
|
|
61
61
|
|
62
|
-
@lc.jit()
|
62
|
+
@lc.jit(每次运行都重新编译=True)
|
63
63
|
def jit_all_ops(a: int, b: int) -> int:
|
64
64
|
# 常量与基础赋值
|
65
65
|
x = 42
|
@@ -71,7 +71,7 @@ def jit_all_ops(a: int, b: int) -> int:
|
|
71
71
|
mp = {1: 10, 2: 20}
|
72
72
|
|
73
73
|
# 一元运算
|
74
|
-
pos = +a
|
74
|
+
pos = +(a + 1)
|
75
75
|
neg = -b
|
76
76
|
inv = ~a
|
77
77
|
not_flag = not flag
|
@@ -152,7 +152,7 @@ def jit_all_ops(a: int, b: int) -> int:
|
|
152
152
|
@lc.jit(每次运行都重新编译=True)
|
153
153
|
def test_add(a: int, b: int) -> int:
|
154
154
|
if a > 1:
|
155
|
-
return a + b
|
155
|
+
return (a + b) * 123123
|
156
156
|
for i in range(1, 10, 2):
|
157
157
|
a += i
|
158
158
|
for i in [1, 2, 3]:
|
@@ -179,7 +179,7 @@ def test_add(a: int, b: int) -> int:
|
|
179
179
|
vv = True and (False or 1)
|
180
180
|
print('vv:', vv)
|
181
181
|
print('测试while:')
|
182
|
-
while
|
182
|
+
while vv:
|
183
183
|
py_cin(v)
|
184
184
|
if v > 100:
|
185
185
|
break
|
@@ -224,61 +224,76 @@ vv: 1
|
|
224
224
|
## 4. 查看输出文件
|
225
225
|
```bash
|
226
226
|
ls -al ./l0n0lcoutput
|
227
|
+
total 136
|
228
|
+
drwxr-xr-x 2 root root 4096 Sep 18 02:00 .
|
229
|
+
drwxrwxrwx 11 1000 1000 4096 Sep 18 02:00 ..
|
230
|
+
-rw-r--r-- 1 root root 1779 Sep 18 02:00 jit_all_ops_@7801528c3d61baf7.cpp
|
231
|
+
-rw-r--r-- 1 root root 167 Sep 18 02:00 jit_all_ops_@7801528c3d61baf7.h
|
232
|
+
-rwxr-xr-x 1 root root 23520 Sep 18 02:00 jit_all_ops_@7801528c3d61baf7.so
|
233
|
+
-rw-r--r-- 1 root root 1499 Sep 18 02:00 test_add_@469de6acaaabc570.cpp
|
234
|
+
-rw-r--r-- 1 root root 302 Sep 18 02:00 test_add_@469de6acaaabc570.h
|
235
|
+
-rwxr-xr-x 1 root root 40216 Sep 18 02:00 test_add_@469de6acaaabc570.so
|
236
|
+
-rw-r--r-- 1 root root 123 Sep 18 02:00 test_other_fn_@75fdd928ab58a8e3.cpp
|
237
|
+
-rw-r--r-- 1 root root 106 Sep 18 02:00 test_other_fn_@75fdd928ab58a8e3.h
|
238
|
+
-rwxr-xr-x 1 root root 15616 Sep 18 02:00 test_other_fn_@75fdd928ab58a8e3.so
|
239
|
+
-rw-r--r-- 1 root root 187 Sep 18 02:00 test编译的函数_@3bf4501e0408a243.cpp
|
240
|
+
-rw-r--r-- 1 root root 164 Sep 18 02:00 test编译的函数_@3bf4501e0408a243.h
|
241
|
+
-rwxr-xr-x 1 root root 15656 Sep 18 02:00 test编译的函数_@3bf4501e0408a243.so
|
227
242
|
|
228
243
|
```
|
229
|
-
## 5. jit_all_ops_@
|
244
|
+
## 5. jit_all_ops_@7801528c3d61baf7.cpp
|
230
245
|
```c++
|
231
|
-
#include "jit_all_ops_@
|
246
|
+
#include "jit_all_ops_@7801528c3d61baf7.h"
|
232
247
|
extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
233
248
|
{
|
234
249
|
auto x = 42;
|
235
|
-
auto y = ((int64_t)(a + b));
|
250
|
+
auto y = ((int64_t)((a + b)));
|
236
251
|
auto z = 3.14;
|
237
252
|
auto flag = true;
|
238
253
|
int64_t nums[] = {1,2,3};
|
239
254
|
int64_t tup[] = {4,5};
|
240
255
|
std::unordered_map<int64_t, int64_t> mp = {{ 1, 10 },{ 2, 20 }};
|
241
|
-
auto pos = +a;
|
242
|
-
auto neg = -b;
|
243
|
-
auto inv = ~a;
|
244
|
-
auto not_flag = !flag;
|
245
|
-
auto add = a + b;
|
246
|
-
auto sub = a - b;
|
247
|
-
auto mul = a * b;
|
248
|
-
auto div = a / ((b != 0) ? (b) : (1));
|
249
|
-
auto mod = a % ((b != 0) ? (b) : (1));
|
250
|
-
auto band = a & b;
|
251
|
-
auto bor = a | b;
|
252
|
-
auto bxor = a ^ b;
|
253
|
-
auto lshift = a << 1;
|
254
|
-
auto rshift = a >> 1;
|
256
|
+
auto pos = (+(a + 1));
|
257
|
+
auto neg = (-b);
|
258
|
+
auto inv = (~a);
|
259
|
+
auto not_flag = (!flag);
|
260
|
+
auto add = (a + b);
|
261
|
+
auto sub = (a - b);
|
262
|
+
auto mul = (a * b);
|
263
|
+
auto div = (a / (((b != 0)) ? (b) : (1)));
|
264
|
+
auto mod = (a % (((b != 0)) ? (b) : (1)));
|
265
|
+
auto band = (a & b);
|
266
|
+
auto bor = (a | b);
|
267
|
+
auto bxor = (a ^ b);
|
268
|
+
auto lshift = (a << 1);
|
269
|
+
auto rshift = (a >> 1);
|
255
270
|
auto cmp1 = (a == b);
|
256
271
|
auto cmp2 = (a != b);
|
257
272
|
auto cmp3 = (a < b);
|
258
273
|
auto cmp4 = (a <= b);
|
259
274
|
auto cmp5 = (a > b);
|
260
275
|
auto cmp6 = (a >= b);
|
261
|
-
auto logic_and = cmp1&&cmp2;
|
262
|
-
auto logic_or = cmp3||cmp4;
|
263
|
-
auto ternary = ((a > b) ? (a) : (b));
|
276
|
+
auto logic_and = (cmp1)&&(cmp2);
|
277
|
+
auto logic_or = (cmp3)||(cmp4);
|
278
|
+
auto ternary = (((a > b)) ? (a) : (b));
|
264
279
|
if ((a > b))
|
265
280
|
{
|
266
|
-
y = y + 1;
|
281
|
+
y = (y + 1);
|
267
282
|
}
|
268
283
|
|
269
284
|
else
|
270
285
|
{
|
271
|
-
y = y - 1;
|
286
|
+
y = (y - 1);
|
272
287
|
}
|
273
288
|
|
274
289
|
for (int64_t i = 0; i < 3; ++i)
|
275
290
|
{
|
276
|
-
y = y + i;
|
291
|
+
y = (y + i);
|
277
292
|
}
|
278
293
|
|
279
294
|
for (auto v : nums)
|
280
295
|
{
|
281
|
-
y = y + v;
|
296
|
+
y = (y + v);
|
282
297
|
if ((v == 2))
|
283
298
|
{
|
284
299
|
continue;
|
@@ -294,23 +309,23 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
294
309
|
auto count = 0;
|
295
310
|
while ((count < 2))
|
296
311
|
{
|
297
|
-
y = y + count;
|
298
|
-
count = count + 1;
|
312
|
+
y = (y + count);
|
313
|
+
count = (count + 1);
|
299
314
|
}
|
300
315
|
|
301
|
-
y = y + 5;
|
302
|
-
y = y - 1;
|
303
|
-
y = y * 2;
|
304
|
-
y = y / 2;
|
305
|
-
y = y % 10;
|
306
|
-
y = y & 7;
|
307
|
-
y = y | 3;
|
308
|
-
y = y ^ 1;
|
309
|
-
y = y << 1;
|
310
|
-
y = y >> 1;
|
316
|
+
y = (y + 5);
|
317
|
+
y = (y - 1);
|
318
|
+
y = (y * 2);
|
319
|
+
y = (y / 2);
|
320
|
+
y = (y % 10);
|
321
|
+
y = (y & 7);
|
322
|
+
y = (y | 3);
|
323
|
+
y = (y ^ 1);
|
324
|
+
y = (y << 1);
|
325
|
+
y = (y >> 1);
|
311
326
|
auto first_num = nums[0];
|
312
327
|
auto mp_val = mp[1];
|
313
|
-
y = y + first_num + mp_val;
|
328
|
+
y = (y + (first_num + mp_val));
|
314
329
|
auto vector = std::vector<int>();
|
315
330
|
vector.push_back(count);
|
316
331
|
vector.push_back(y);
|
@@ -323,7 +338,7 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
323
338
|
}
|
324
339
|
|
325
340
|
```
|
326
|
-
## 6. jit_all_ops_@
|
341
|
+
## 6. jit_all_ops_@7801528c3d61baf7.h
|
327
342
|
```c++
|
328
343
|
#pragma once
|
329
344
|
#include <cstdint>
|
@@ -333,24 +348,24 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
333
348
|
#include <vector>
|
334
349
|
extern "C" int64_t jit_all_ops (int64_t a, int64_t b);
|
335
350
|
```
|
336
|
-
## 7. test_add_@
|
351
|
+
## 7. test_add_@469de6acaaabc570.cpp
|
337
352
|
```c++
|
338
|
-
#include "test_add_@
|
353
|
+
#include "test_add_@469de6acaaabc570.h"
|
339
354
|
extern "C" int64_t test_add (int64_t a, int64_t b)
|
340
355
|
{
|
341
356
|
if ((a > 1))
|
342
357
|
{
|
343
|
-
return a + b;
|
358
|
+
return ((a + b) * 123123);
|
344
359
|
}
|
345
360
|
|
346
361
|
for (int64_t i = 1; i < 10; i += 2)
|
347
362
|
{
|
348
|
-
a = a + i;
|
363
|
+
a = (a + i);
|
349
364
|
}
|
350
365
|
|
351
366
|
for (auto i : {1,2,3})
|
352
367
|
{
|
353
|
-
a = a + i;
|
368
|
+
a = (a + i);
|
354
369
|
}
|
355
370
|
|
356
371
|
a = std::ceil(12.5);;
|
@@ -376,7 +391,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
|
|
376
391
|
std::cout<< u8"测试所有操作:" << " "<< std::endl;;
|
377
392
|
jit_all_ops(a,b);
|
378
393
|
auto v = 0;
|
379
|
-
auto vv = true&&false||1;
|
394
|
+
auto vv = (true)&&((false)||(1));
|
380
395
|
std::cout<< u8"vv:" << " "<< vv << " "<< std::endl;;
|
381
396
|
std::cout<< u8"测试while:" << " "<< std::endl;;
|
382
397
|
while (vv)
|
@@ -394,14 +409,14 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
|
|
394
409
|
|
395
410
|
}
|
396
411
|
|
397
|
-
return a + b + 1 + 123 + v;
|
412
|
+
return ((((a + b) + 1) + 123) + v);
|
398
413
|
}
|
399
414
|
|
400
415
|
```
|
401
|
-
## 8. test_add_@
|
416
|
+
## 8. test_add_@469de6acaaabc570.h
|
402
417
|
```c++
|
403
418
|
#pragma once
|
404
|
-
#include "jit_all_ops_@
|
419
|
+
#include "jit_all_ops_@7801528c3d61baf7.h"
|
405
420
|
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
406
421
|
#include "test编译的函数_@3bf4501e0408a243.h"
|
407
422
|
#include <cmath>
|
@@ -416,7 +431,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
|
|
416
431
|
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
417
432
|
extern "C" int64_t test_other_fn (int64_t a, int64_t b)
|
418
433
|
{
|
419
|
-
return a - b;
|
434
|
+
return (a - b);
|
420
435
|
}
|
421
436
|
|
422
437
|
```
|
@@ -432,7 +447,7 @@ extern "C" int64_t test_other_fn (int64_t a, int64_t b);
|
|
432
447
|
#include "test编译的函数_@3bf4501e0408a243.h"
|
433
448
|
extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b)
|
434
449
|
{
|
435
|
-
return a * b;
|
450
|
+
return (a * b);
|
436
451
|
}
|
437
452
|
|
438
453
|
```
|
@@ -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([
|
211
|
+
return '&&'.join([f'({self.获取值(v)})' for v in value.values])
|
212
212
|
if isinstance(value.op, ast.Or):
|
213
|
-
return '||'.join([
|
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
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: l0n0lc
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.2
|
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
|
192
|
+
while vv:
|
193
193
|
py_cin(v)
|
194
194
|
if v > 100:
|
195
195
|
break
|
@@ -234,61 +234,76 @@ vv: 1
|
|
234
234
|
## 4. 查看输出文件
|
235
235
|
```bash
|
236
236
|
ls -al ./l0n0lcoutput
|
237
|
+
total 136
|
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
|
237
252
|
|
238
253
|
```
|
239
|
-
## 5. jit_all_ops_@
|
254
|
+
## 5. jit_all_ops_@7801528c3d61baf7.cpp
|
240
255
|
```c++
|
241
|
-
#include "jit_all_ops_@
|
256
|
+
#include "jit_all_ops_@7801528c3d61baf7.h"
|
242
257
|
extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
243
258
|
{
|
244
259
|
auto x = 42;
|
245
|
-
auto y = ((int64_t)(a + b));
|
260
|
+
auto y = ((int64_t)((a + b)));
|
246
261
|
auto z = 3.14;
|
247
262
|
auto flag = true;
|
248
263
|
int64_t nums[] = {1,2,3};
|
249
264
|
int64_t tup[] = {4,5};
|
250
265
|
std::unordered_map<int64_t, int64_t> mp = {{ 1, 10 },{ 2, 20 }};
|
251
|
-
auto pos = +a;
|
252
|
-
auto neg = -b;
|
253
|
-
auto inv = ~a;
|
254
|
-
auto not_flag = !flag;
|
255
|
-
auto add = a + b;
|
256
|
-
auto sub = a - b;
|
257
|
-
auto mul = a * b;
|
258
|
-
auto div = a / ((b != 0) ? (b) : (1));
|
259
|
-
auto mod = a % ((b != 0) ? (b) : (1));
|
260
|
-
auto band = a & b;
|
261
|
-
auto bor = a | b;
|
262
|
-
auto bxor = a ^ b;
|
263
|
-
auto lshift = a << 1;
|
264
|
-
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);
|
265
280
|
auto cmp1 = (a == b);
|
266
281
|
auto cmp2 = (a != b);
|
267
282
|
auto cmp3 = (a < b);
|
268
283
|
auto cmp4 = (a <= b);
|
269
284
|
auto cmp5 = (a > b);
|
270
285
|
auto cmp6 = (a >= b);
|
271
|
-
auto logic_and = cmp1&&cmp2;
|
272
|
-
auto logic_or = cmp3||cmp4;
|
273
|
-
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));
|
274
289
|
if ((a > b))
|
275
290
|
{
|
276
|
-
y = y + 1;
|
291
|
+
y = (y + 1);
|
277
292
|
}
|
278
293
|
|
279
294
|
else
|
280
295
|
{
|
281
|
-
y = y - 1;
|
296
|
+
y = (y - 1);
|
282
297
|
}
|
283
298
|
|
284
299
|
for (int64_t i = 0; i < 3; ++i)
|
285
300
|
{
|
286
|
-
y = y + i;
|
301
|
+
y = (y + i);
|
287
302
|
}
|
288
303
|
|
289
304
|
for (auto v : nums)
|
290
305
|
{
|
291
|
-
y = y + v;
|
306
|
+
y = (y + v);
|
292
307
|
if ((v == 2))
|
293
308
|
{
|
294
309
|
continue;
|
@@ -304,23 +319,23 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
304
319
|
auto count = 0;
|
305
320
|
while ((count < 2))
|
306
321
|
{
|
307
|
-
y = y + count;
|
308
|
-
count = count + 1;
|
322
|
+
y = (y + count);
|
323
|
+
count = (count + 1);
|
309
324
|
}
|
310
325
|
|
311
|
-
y = y + 5;
|
312
|
-
y = y - 1;
|
313
|
-
y = y * 2;
|
314
|
-
y = y / 2;
|
315
|
-
y = y % 10;
|
316
|
-
y = y & 7;
|
317
|
-
y = y | 3;
|
318
|
-
y = y ^ 1;
|
319
|
-
y = y << 1;
|
320
|
-
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);
|
321
336
|
auto first_num = nums[0];
|
322
337
|
auto mp_val = mp[1];
|
323
|
-
y = y + first_num + mp_val;
|
338
|
+
y = (y + (first_num + mp_val));
|
324
339
|
auto vector = std::vector<int>();
|
325
340
|
vector.push_back(count);
|
326
341
|
vector.push_back(y);
|
@@ -333,7 +348,7 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
333
348
|
}
|
334
349
|
|
335
350
|
```
|
336
|
-
## 6. jit_all_ops_@
|
351
|
+
## 6. jit_all_ops_@7801528c3d61baf7.h
|
337
352
|
```c++
|
338
353
|
#pragma once
|
339
354
|
#include <cstdint>
|
@@ -343,24 +358,24 @@ extern "C" int64_t jit_all_ops (int64_t a, int64_t b)
|
|
343
358
|
#include <vector>
|
344
359
|
extern "C" int64_t jit_all_ops (int64_t a, int64_t b);
|
345
360
|
```
|
346
|
-
## 7. test_add_@
|
361
|
+
## 7. test_add_@469de6acaaabc570.cpp
|
347
362
|
```c++
|
348
|
-
#include "test_add_@
|
363
|
+
#include "test_add_@469de6acaaabc570.h"
|
349
364
|
extern "C" int64_t test_add (int64_t a, int64_t b)
|
350
365
|
{
|
351
366
|
if ((a > 1))
|
352
367
|
{
|
353
|
-
return a + b;
|
368
|
+
return ((a + b) * 123123);
|
354
369
|
}
|
355
370
|
|
356
371
|
for (int64_t i = 1; i < 10; i += 2)
|
357
372
|
{
|
358
|
-
a = a + i;
|
373
|
+
a = (a + i);
|
359
374
|
}
|
360
375
|
|
361
376
|
for (auto i : {1,2,3})
|
362
377
|
{
|
363
|
-
a = a + i;
|
378
|
+
a = (a + i);
|
364
379
|
}
|
365
380
|
|
366
381
|
a = std::ceil(12.5);;
|
@@ -386,7 +401,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
|
|
386
401
|
std::cout<< u8"测试所有操作:" << " "<< std::endl;;
|
387
402
|
jit_all_ops(a,b);
|
388
403
|
auto v = 0;
|
389
|
-
auto vv = true&&false||1;
|
404
|
+
auto vv = (true)&&((false)||(1));
|
390
405
|
std::cout<< u8"vv:" << " "<< vv << " "<< std::endl;;
|
391
406
|
std::cout<< u8"测试while:" << " "<< std::endl;;
|
392
407
|
while (vv)
|
@@ -404,14 +419,14 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
|
|
404
419
|
|
405
420
|
}
|
406
421
|
|
407
|
-
return a + b + 1 + 123 + v;
|
422
|
+
return ((((a + b) + 1) + 123) + v);
|
408
423
|
}
|
409
424
|
|
410
425
|
```
|
411
|
-
## 8. test_add_@
|
426
|
+
## 8. test_add_@469de6acaaabc570.h
|
412
427
|
```c++
|
413
428
|
#pragma once
|
414
|
-
#include "jit_all_ops_@
|
429
|
+
#include "jit_all_ops_@7801528c3d61baf7.h"
|
415
430
|
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
416
431
|
#include "test编译的函数_@3bf4501e0408a243.h"
|
417
432
|
#include <cmath>
|
@@ -426,7 +441,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
|
|
426
441
|
#include "test_other_fn_@75fdd928ab58a8e3.h"
|
427
442
|
extern "C" int64_t test_other_fn (int64_t a, int64_t b)
|
428
443
|
{
|
429
|
-
return a - b;
|
444
|
+
return (a - b);
|
430
445
|
}
|
431
446
|
|
432
447
|
```
|
@@ -442,7 +457,7 @@ extern "C" int64_t test_other_fn (int64_t a, int64_t b);
|
|
442
457
|
#include "test编译的函数_@3bf4501e0408a243.h"
|
443
458
|
extern "C" int64_t /*test编译的函数*/ function_74657374e7bc96e8af91e79a84e587bde695b0 (int64_t a, int64_t b)
|
444
459
|
{
|
445
|
-
return a * b;
|
460
|
+
return (a * b);
|
446
461
|
}
|
447
462
|
|
448
463
|
```
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|