登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
轻量养虾,开箱即用!低 Token + 稳定算力,Gitee & 模力方舟联合出品的 PocketClaw 正式开售!点击了解详情~
代码拉取完成,页面将自动刷新
开源项目
>
程序开发
>
编程语言/脚本语言
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
22
Star
121
Fork
31
木兰编程语言
/
mulan-rework
代码
Issues
20
Pull Requests
3
Wiki
统计
流水线
服务
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
【老手】木兰源码转换为 Python
已完成
#I3QIEL
需求
吴烜
拥有者
创建于
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 例程生成语法树代替。 - 测试用例之外的代码请用中文命名标识符,包括类、变量、方法名等等。 - 如有两位以上达成目标,将按提交顺序等因素选择中标者。
评论 (
31
)
登录
后才可以发表评论
状态
已完成
待办的
已确认
设计中
开发中
已完成
已验收
已拒绝
负责人
未设置
标签
悬赏
未设置
项目
未立项任务
未立项任务
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(8)
Python
1
https://gitee.com/MulanRevive/mulan-rework.git
git@gitee.com:MulanRevive/mulan-rework.git
MulanRevive
mulan-rework
mulan-rework
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册