Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Open Source
>
Development Lib
>
Programming Language/Scripting Language
&&
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
22
Star
121
Fork
31
木兰编程语言
/
mulan-rework
Code
Issues
20
Pull Requests
3
Wiki
Insights
Pipelines
Service
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
【老手】木兰源码转换为 Python
Done
#I3QIEL
Requirement
吴烜
owner
Opened this issue
2021-05-09 17:00
[木兰原始可执行文件](https://gitee.com/MulanRevive/bounty/tree/master/%E5%8E%9F%E5%A7%8B%E8%B5%84%E6%96%99/%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6) 的 --dump-python 命令行选项可以将木兰源码转换为 Python 源码。 以 [超类.ul](https://gitee.com/MulanRevive/mulan-rework/blob/master/%E6%B5%8B%E8%AF%95/unittest/%E6%BA%90%E7%A0%81%E7%94%9F%E6%88%90/%E7%B1%BB%E5%9E%8B/%E8%B6%85%E7%B1%BB.ul) 为例: ``` type Animal { func $Animal() { println(1) } func $run(n) { println(n) } } type WildAnimal { func $WildAnimal(name) { println(name) } } type Person : Animal { func $Person() { super() } func $go() { super.run(3) } } type Wolf : WildAnimal { func $Wolf() { super(2) } } Person() Wolf() Person().go() ``` 运行: ``` > .\ulang-0.2.2.exe --dump-python 测试\unittest\源码生成\类型\超类.ul ``` 输出 Python 源码如下: ```python import sys from math import * ARGV = sys.argv[1:] class Animal: def __init__(self): print(1) def run(self, n): print(n) class WildAnimal: def __init__(self, name): print(name) class Person(Animal): def __init__(self): super().__init__() def go(self): super().run(3) class Wolf(WildAnimal): def __init__(self): super().__init__(2) Person() Wolf() Person().go() ``` ### 任务目标 复现此功能,包括完备的测试用例,即从木兰源码文件可以生成对应的 Python 源码文件。实现上,除 [逆向工程](https://github.com/MulanRevive/mulan/blob/master/ulang/codegen/python.py) 之外,可参考已部分实现的从语法树生成木兰源码的功能,[测试运行脚本在此](https://gitee.com/MulanRevive/mulan-rework/blob/master/%E6%B5%8B%E8%AF%95/unittest/%E7%94%9F%E6%88%90.py)。测试用例应覆盖实现的所有逻辑分支。 ### 要求 - 在实现前,讨论决定如何拆分实现到多个提交(git commit),并在第一个提交时就创建 PR,以便于及时交流代码避免过大偏差。 - 确保添加的测试用例能集成到 [两项测试中](https://gitee.com/MulanRevive/mulan-rework/#%E8%BF%90%E8%A1%8C%E6%B5%8B%E8%AF%95) 一并运行并通过。 - 如果有木兰语法尚未支持导致测试用例无法通过,请用 Python 例程生成语法树代替。 - 测试用例之外的代码请用中文命名标识符,包括类、变量、方法名等等。 - 如有两位以上达成目标,将按提交顺序等因素选择中标者。
[木兰原始可执行文件](https://gitee.com/MulanRevive/bounty/tree/master/%E5%8E%9F%E5%A7%8B%E8%B5%84%E6%96%99/%E5%8F%AF%E6%89%A7%E8%A1%8C%E6%96%87%E4%BB%B6) 的 --dump-python 命令行选项可以将木兰源码转换为 Python 源码。 以 [超类.ul](https://gitee.com/MulanRevive/mulan-rework/blob/master/%E6%B5%8B%E8%AF%95/unittest/%E6%BA%90%E7%A0%81%E7%94%9F%E6%88%90/%E7%B1%BB%E5%9E%8B/%E8%B6%85%E7%B1%BB.ul) 为例: ``` type Animal { func $Animal() { println(1) } func $run(n) { println(n) } } type WildAnimal { func $WildAnimal(name) { println(name) } } type Person : Animal { func $Person() { super() } func $go() { super.run(3) } } type Wolf : WildAnimal { func $Wolf() { super(2) } } Person() Wolf() Person().go() ``` 运行: ``` > .\ulang-0.2.2.exe --dump-python 测试\unittest\源码生成\类型\超类.ul ``` 输出 Python 源码如下: ```python import sys from math import * ARGV = sys.argv[1:] class Animal: def __init__(self): print(1) def run(self, n): print(n) class WildAnimal: def __init__(self, name): print(name) class Person(Animal): def __init__(self): super().__init__() def go(self): super().run(3) class Wolf(WildAnimal): def __init__(self): super().__init__(2) Person() Wolf() Person().go() ``` ### 任务目标 复现此功能,包括完备的测试用例,即从木兰源码文件可以生成对应的 Python 源码文件。实现上,除 [逆向工程](https://github.com/MulanRevive/mulan/blob/master/ulang/codegen/python.py) 之外,可参考已部分实现的从语法树生成木兰源码的功能,[测试运行脚本在此](https://gitee.com/MulanRevive/mulan-rework/blob/master/%E6%B5%8B%E8%AF%95/unittest/%E7%94%9F%E6%88%90.py)。测试用例应覆盖实现的所有逻辑分支。 ### 要求 - 在实现前,讨论决定如何拆分实现到多个提交(git commit),并在第一个提交时就创建 PR,以便于及时交流代码避免过大偏差。 - 确保添加的测试用例能集成到 [两项测试中](https://gitee.com/MulanRevive/mulan-rework/#%E8%BF%90%E8%A1%8C%E6%B5%8B%E8%AF%95) 一并运行并通过。 - 如果有木兰语法尚未支持导致测试用例无法通过,请用 Python 例程生成语法树代替。 - 测试用例之外的代码请用中文命名标识符,包括类、变量、方法名等等。 - 如有两位以上达成目标,将按提交顺序等因素选择中标者。
Comments (
31
)
Sign in
to comment
Status
Done
Backlog
Confirmed
In Design
In Development
Done
Accepted
Declined
Assignees
Not set
Labels
悬赏
Not set
Projects
Unprojected
Unprojected
Milestones
No related milestones
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
Duration
(hours)
参与者(8)
Python
1
https://gitee.com/MulanRevive/mulan-rework.git
git@gitee.com:MulanRevive/mulan-rework.git
MulanRevive
mulan-rework
mulan-rework
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register