l0n0lc 0.6.0__tar.gz → 0.7.1__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.6.0
3
+ Version: 0.7.1
4
4
  Summary: 用python写c
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Requires-Python: >=3.10
@@ -40,25 +40,34 @@ def test_add(a: int, b: int) -> int:
40
40
  a += i
41
41
  a = math.ceil(12.5)
42
42
  cc = {'a': 1, 'b': 2}
43
- cc['123'] = 111
43
+ cc['c'] = 3
44
+ print('输出map:')
45
+ for ii in cc:
46
+ print(ii.first, ii.second) # type: ignore
44
47
  aa = [1, 3, 2]
45
48
  aa[0] = 134
49
+ print('输出list:')
46
50
  for i in range(3):
47
51
  print(i, aa[i])
48
52
  print('Hello World', a, b)
49
53
  return a + b + 1
50
54
 
51
55
 
52
- print(test_add(1, 3))
56
+ print('结果:', test_add(1, 3))
53
57
  ```
54
58
  ## 执行hello_world.py
55
59
  ```bash
56
60
  $ python hello_world.py
61
+ 输出map:
62
+ c 3
63
+ a 1
64
+ b 2
65
+ 输出list:
57
66
  0 134
58
67
  1 3
59
68
  2 2
60
69
  Hello World 13 3
61
- 17
70
+ 结果: 17
62
71
  ```
63
72
  ## 查看生成的c++代码文件
64
73
  ```bash
@@ -84,7 +93,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
84
93
 
85
94
  ## test_add_@402bbf73254216d8.cpp
86
95
  ```c++
87
- #include "test_add_@402bbf73254216d8.h"
96
+ #include "test_add_@141921ba1aaa0352.h"
88
97
  extern "C" int64_t test_add (int64_t a, int64_t b)
89
98
  {
90
99
  if ((a > 1))
@@ -104,9 +113,16 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
104
113
 
105
114
  a = std::ceil(12.5);;
106
115
  std::unordered_map<std::string, int64_t> cc = {{ u8"a", 1 },{ u8"b", 2 }};
107
- 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
+
108
123
  int64_t aa[] = {1,3,2};
109
124
  aa[0] = 134;
125
+ std::cout<< u8"输出list:" << " "<< std::endl;
110
126
  for (int64_t i = 0; i < 3; ++i)
111
127
  {
112
128
  std::cout<< i << " "<< aa[i] << " "<< std::endl;
@@ -115,5 +131,4 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
115
131
  std::cout<< u8"Hello World" << " "<< a << " "<< b << " "<< std::endl;
116
132
  return a + b + 1;
117
133
  }
118
-
119
134
  ```
@@ -30,25 +30,34 @@ def test_add(a: int, b: int) -> int:
30
30
  a += i
31
31
  a = math.ceil(12.5)
32
32
  cc = {'a': 1, 'b': 2}
33
- cc['123'] = 111
33
+ cc['c'] = 3
34
+ print('输出map:')
35
+ for ii in cc:
36
+ print(ii.first, ii.second) # type: ignore
34
37
  aa = [1, 3, 2]
35
38
  aa[0] = 134
39
+ print('输出list:')
36
40
  for i in range(3):
37
41
  print(i, aa[i])
38
42
  print('Hello World', a, b)
39
43
  return a + b + 1
40
44
 
41
45
 
42
- print(test_add(1, 3))
46
+ print('结果:', test_add(1, 3))
43
47
  ```
44
48
  ## 执行hello_world.py
45
49
  ```bash
46
50
  $ python hello_world.py
51
+ 输出map:
52
+ c 3
53
+ a 1
54
+ b 2
55
+ 输出list:
47
56
  0 134
48
57
  1 3
49
58
  2 2
50
59
  Hello World 13 3
51
- 17
60
+ 结果: 17
52
61
  ```
53
62
  ## 查看生成的c++代码文件
54
63
  ```bash
@@ -74,7 +83,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
74
83
 
75
84
  ## test_add_@402bbf73254216d8.cpp
76
85
  ```c++
77
- #include "test_add_@402bbf73254216d8.h"
86
+ #include "test_add_@141921ba1aaa0352.h"
78
87
  extern "C" int64_t test_add (int64_t a, int64_t b)
79
88
  {
80
89
  if ((a > 1))
@@ -94,9 +103,16 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
94
103
 
95
104
  a = std::ceil(12.5);;
96
105
  std::unordered_map<std::string, int64_t> cc = {{ u8"a", 1 },{ u8"b", 2 }};
97
- cc[u8"123"] = 111;
106
+ cc[u8"c"] = 3;
107
+ std::cout<< u8"输出map:" << " "<< std::endl;
108
+ for (auto ii : cc)
109
+ {
110
+ std::cout<< ii.first << " "<< ii.second << " "<< std::endl;
111
+ }
112
+
98
113
  int64_t aa[] = {1,3,2};
99
114
  aa[0] = 134;
115
+ std::cout<< u8"输出list:" << " "<< std::endl;
100
116
  for (int64_t i = 0; i < 3; ++i)
101
117
  {
102
118
  std::cout<< i << " "<< aa[i] << " "<< std::endl;
@@ -105,5 +121,4 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
105
121
  std::cout<< u8"Hello World" << " "<< a << " "<< b << " "<< std::endl;
106
122
  return a + b + 1;
107
123
  }
108
-
109
124
  ```
@@ -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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: l0n0lc
3
- Version: 0.6.0
3
+ Version: 0.7.1
4
4
  Summary: 用python写c
5
5
  Classifier: Programming Language :: Python :: 3
6
6
  Requires-Python: >=3.10
@@ -40,25 +40,34 @@ def test_add(a: int, b: int) -> int:
40
40
  a += i
41
41
  a = math.ceil(12.5)
42
42
  cc = {'a': 1, 'b': 2}
43
- cc['123'] = 111
43
+ cc['c'] = 3
44
+ print('输出map:')
45
+ for ii in cc:
46
+ print(ii.first, ii.second) # type: ignore
44
47
  aa = [1, 3, 2]
45
48
  aa[0] = 134
49
+ print('输出list:')
46
50
  for i in range(3):
47
51
  print(i, aa[i])
48
52
  print('Hello World', a, b)
49
53
  return a + b + 1
50
54
 
51
55
 
52
- print(test_add(1, 3))
56
+ print('结果:', test_add(1, 3))
53
57
  ```
54
58
  ## 执行hello_world.py
55
59
  ```bash
56
60
  $ python hello_world.py
61
+ 输出map:
62
+ c 3
63
+ a 1
64
+ b 2
65
+ 输出list:
57
66
  0 134
58
67
  1 3
59
68
  2 2
60
69
  Hello World 13 3
61
- 17
70
+ 结果: 17
62
71
  ```
63
72
  ## 查看生成的c++代码文件
64
73
  ```bash
@@ -84,7 +93,7 @@ extern "C" int64_t test_add (int64_t a, int64_t b);
84
93
 
85
94
  ## test_add_@402bbf73254216d8.cpp
86
95
  ```c++
87
- #include "test_add_@402bbf73254216d8.h"
96
+ #include "test_add_@141921ba1aaa0352.h"
88
97
  extern "C" int64_t test_add (int64_t a, int64_t b)
89
98
  {
90
99
  if ((a > 1))
@@ -104,9 +113,16 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
104
113
 
105
114
  a = std::ceil(12.5);;
106
115
  std::unordered_map<std::string, int64_t> cc = {{ u8"a", 1 },{ u8"b", 2 }};
107
- 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
+
108
123
  int64_t aa[] = {1,3,2};
109
124
  aa[0] = 134;
125
+ std::cout<< u8"输出list:" << " "<< std::endl;
110
126
  for (int64_t i = 0; i < 3; ++i)
111
127
  {
112
128
  std::cout<< i << " "<< aa[i] << " "<< std::endl;
@@ -115,5 +131,4 @@ extern "C" int64_t test_add (int64_t a, int64_t b)
115
131
  std::cout<< u8"Hello World" << " "<< a << " "<< b << " "<< std::endl;
116
132
  return a + b + 1;
117
133
  }
118
-
119
134
  ```
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "l0n0lc"
3
- version = "0.6.0"
3
+ version = "0.7.1"
4
4
  description = "用python写c"
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