https://github.com/fawdlstty/fawpy
a project to translate python code to cpp code
https://github.com/fawdlstty/fawpy
Last synced: 29 days ago
JSON representation
a project to translate python code to cpp code
- Host: GitHub
- URL: https://github.com/fawdlstty/fawpy
- Owner: fawdlstty
- Created: 2018-04-24T16:02:31.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-05-14T08:47:24.000Z (almost 7 years ago)
- Last Synced: 2025-01-30T03:15:56.445Z (3 months ago)
- Language: C++
- Homepage:
- Size: 83 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# FawPy
将Python源码翻译为C艹源码的项目
Python最被大众诟病的主要因素就是速度慢,毕竟虚拟机解释执行,这就从根本上限制了Python无法开发超大型架构的项目,因为项目源码越多,项目就越慢。所以我在此发起这个项目,用于将Python翻译为C艹,给Python提速,使Python也可以自由自在的开发超大型项目而不用考虑速度因素。
原始调用方式比较麻烦,在此简化为web端在线翻译。链接如下:http://111.230.39.240:4545/tools/fawpy
示例Python代码如下(test1.py):
```python
def fun_a ():
return 'hello world'def fun_b (b):
return b + 1def fun_c (a, b):
return a*2-b/3class cls_a ():
def fun_cls_d (self):
return selfif (__name__ == '__main__'):
a = fun_a ()
print (a)
b = fun_b (2)
print (b)
c = fun_c (4, 5)
print (c)
```转换后的效果如下所示:
```cpp
#include
#includeauto fun_a () {
return "hello world";
}auto fun_b (int b) {
return (b+1);
}auto fun_c (int a, int b) {
return ((a*2)-(b/3));
}struct cls_a {
auto fun_cls_d () {
return this;
}
};int main (int argc, char* argv[]) {
auto a = fun_a ();
std::cout << a << std::endl;
auto b = fun_b (2);
std::cout << b << std::endl;
auto c = fun_c (4, 5);
std::cout << c << std::endl;
}
```经测试,生成的代码编译成功。目前这个项目是测试版,翻译的不够完美,能翻译的结构有限,问题也较多,也有明确的弱点,比如生成器,截止C艹17还没有这玩意,所以从实现上就比较蛋疼了;另外还有模块的`__name=='__main__'`,etc...
各位大佬如果有什么好的建议及遇到什么问题欢迎提issue,同时也欢迎对这个项目感兴趣的大佬参与进来一起开发。
个人博客地址:https://www.fawdlstty.com,欢迎到访。