{"id":27114145,"url":"https://github.com/lux-qaq/llvmpy","last_synced_at":"2026-04-28T11:06:46.221Z","repository":{"id":284738930,"uuid":"955904110","full_name":"lux-QAQ/llvmpy","owner":"lux-QAQ","description":"Simple python code implemented via llvm is converted into a compiler for IR","archived":false,"fork":false,"pushed_at":"2025-04-06T14:48:06.000Z","size":5775,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-06T15:39:30.658Z","etag":null,"topics":["llvm","python"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lux-QAQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-27T11:37:24.000Z","updated_at":"2025-03-28T07:25:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"08312d2a-ddc1-43b4-9659-c113e5625039","html_url":"https://github.com/lux-QAQ/llvmpy","commit_stats":null,"previous_names":["lux-qaq/llvmpy"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2Fllvmpy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2Fllvmpy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2Fllvmpy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lux-QAQ%2Fllvmpy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lux-QAQ","download_url":"https://codeload.github.com/lux-QAQ/llvmpy/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247589829,"owners_count":20963022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llvm","python"],"created_at":"2025-04-07T03:39:15.250Z","updated_at":"2026-04-28T11:06:46.211Z","avatar_url":"https://github.com/lux-QAQ.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# llvmpy v3.0\n中文 | [English](./README_EN.md)\n\n# 简介\n**这是一个`Python`的前端编译器，主要用于把`Python`代码编译成`LLVM`的`IR`代码，最后生成可执行文件的过程由`Clang`来完成。**\n\n\n目前来说这仅仅只是一个玩具的地步，因为要实现真正的编译器不应该一上来就开始搓代码。而是应该先了解`Python`的各种语法和特性之后，先确定下来整体架构在开始编写代码。但是我却逆其道而行之，只是按照自己的印象来实现一个简易的`Python`编译器，估计连`Python`的子集都算不上，因为有很多功能确实和原版`Python`有出入。我不知道我的兴趣还能够支撑这个项目多久。\n\n---\n## 功能介绍\n\u003e 目前该项目完全是按照`example.py`中所需要的功能来实现的，其他的功能暂时没有实现。所以其实暂时没有什么介绍的必要性\n### 数据类型\n- [x] 高精度计算(GMP默认256精度):\n  - [x] 支持`float`浮点数\n  - [x] 支持`int`整数\n  - [x] 支持`bool`布尔值\n  - [ ] 支持`complex`复数(暂无计划)\n\n### 特殊类型\n- [x] 支持`None`空值\n- [x] 支持`Any`任意类型\n- [x] 支持函数对象\n- [ ] 自定义类对象\n- [ ] 支持`Ellipsis`省略号 (暂无计划)\n\n### 容器\n- [x] 支持`string`字符串\n  - [x] 支持转义字符\n  - [x] 支持字符串拼接\n  - [ ] `f-string` (暂无计划)\n- [x] 支持`list`列表\n  - [x] 支持多维列表 ,支持混合类型\n- [x] 支持`dict`字典\n  - [x] 支持混合类型的 **key-value**(RunTime中支持hash的都可以**key-value**)\n- [ ] 支持`set`集合(暂无计划)\n- [ ] 支持`tuple`元组(暂无计划)\n---\n\n### 语法\n- [x] 支持复杂的**加减乘除乘法**运算符\n  - [x] 支撑`string`字符串拼接\n  - [x] 支持`list`的拼接(`[1,2] + [3,4]*2`)\n- [x] 支持大多数运算符:\n  - [x] 支持`==` `!=` `\u003e` `\u003c` `\u003e=` `\u003c=`\n  - [ ] 支持逻辑短路\n  - [ ] 支持`is` `in` `not in` `is not`\n  - [ ] 支持`\u0026` `|` `^` `\u003c\u003c` `\u003e\u003e` (Lexer和RunTime支持了但是,Parser和CodeGen没有)\n  - [ ] 支持容器对象的表比较\n- [x] 支持`if-elif-else`语句\n- [x] 支持`def`函数定义 :\n  - [x] 支持泛型\n  - [x] 支持函数对象\n  - [x] 支撑函数内定义函数\n- [ ] 支持`lambda`表达式\n- [ ] 支持列表推导式\n\n\n- [x] 支持`while-else`语句\n- [x] 支持`for-else`语句\n- [ ] 支持`try-except`语句\n- [ ] 支持`with`语句\n\n- [ ] 支持`class` \n\n- [ ] 支持`async` `await`语句(暂无计划)\n\n\n\n## 多文件\n- [x] 目前只支持单文件main()作为入口点,全局执行也可以\n- [ ] 支持多文件编译\n- [ ] 支持`import` `from-import` `import as` `from-import as`语句\n- [ ] 支持`__name__` `__main__`语句 (暂无计划)\n- [ ] 支持`__all__` (暂无计划)\n- [ ] 支持`__init__.py`\n---\n## 测试案例\n详细的功能测试请参考`tests_auto/`中的测试用例.     \n`alltest.sh`是一个自动化测试脚本,可以自动化运行所有的测试用例:\n- `tests_auto/checkneeds` : 检查return 0\\return 1\\if-else之类最基础功能的是否正常因为他们是接下来其他测试的依赖.他们是特殊的,所以这下面的测试用例需要同名的`*.sh`脚本特判\n- `tests_auto/` : 测试复杂功能,通过自我的`if-else-if`语句来实现,所以需要`tests_auto/checkneeds`的支持\n## 简单使用\n`compile.sh`是一个简单的编译脚本,可以直接编译`./test.py`文件,并且运行\n\n## 关于性能\n- 调用`GMP`的`mpz`来实现高精度计算,但是性能上来说还是有点差的,因为`mpz`的性能比`int`要差很多\n- `LLVM`的`IR`代码生成器是一个简单的实现,所以性能上来说还是有点差的,因为没有做很多的优化\n- 使用了`libffi`来实现未知签名调用,比原生的`C函数`调用要慢1.5倍左右\n- 静态分析做的特别差\n\n## License\n![License: CC BY-NC-SA 4.0](./assets/images/by-nc-sa.svg)\n\n本项目采用  \n[Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/)  \n进行许可。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flux-qaq%2Fllvmpy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flux-qaq%2Fllvmpy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flux-qaq%2Fllvmpy/lists"}