Comments (7)
好奇这个要怎么做 感觉现有ast感觉很难控制模块的scoping 但如果precompile成Python再植入的话变量名感觉又会起冲突
from dongbei.
我觉着 precompile 成 py 可行。
from dongbei.
precompile成Py的话这个issue的blocker可能是要先调整一下现在dongbei 编译到 python 时候lexical addressing的方法
现在所有的变量在被编译到Python是就已经被flatten成 _db_var*
的格式了 precompile的时候如果保持这个模式 用原先的方法做单纯地python import 在dongbei应该没有办法正确的refer原先东北代码里的variable
举个🌰:
这是东北lib 弄他.dongbei
的src
听见啥弄他 装 "你瞅啥"。
按照现在的方法 precompile成Python 这个lib会变成 弄他.py
_db_var1 = "你瞅啥"
然后假设我们import弄他
翠花,上 弄他。
唠唠:弄他.听见啥弄他。 # 弄他.听见啥弄他 must be undefined.
from dongbei.
现在变量名已经不再转换成 _db_var* 了。源程序里啥名转成 python 还是啥名。
这样理论上是有一些漏洞,但实际问题不大。
from dongbei.
beautiful 看来我应该升级一下interpreter了lol
这个方案等基本同于用中文字符写python,source的编码可能是唯一问题。
py_compile
可以对dongbei的python intermediate做binary precompile 直接实现dongbei -> pyc 的转换 performance可以更进一步
from dongbei.
可以通过修改importlib.machinery.SourceFileLoader.SOURCE_SUFFIXES
和importlib.machinery.SourceFileLoader.source_to_code
的方式支持导入.dongbei
模块。修改后可以像导入普通Python模块一样导入.dongbei
模块。这里有个例子。
AST方面推荐转成使用Python自带的ast
模块里的对象,这样解析完成后获得的ast.Module
对象可以直接传给原来的importlib.machinery.SourceFileLoader.source_to_code
函数实现模块加载,省去了转成Python源码这一中间步骤。这样做有个很大的好处是,代码执行报错时可以直接定位到.dongbei
源码的行和列(需在构建Python的AST对象时提供对应的行列信息)。
from dongbei.
此计甚妙!!
from dongbei.
Related Issues (20)
- 可以添加年度流行语,热词,作为语言提供的API函数名
- 三个井号->python三引号
- 建议再加个PyCharm语法高亮的插件
- 在?把项目改名为 `dongbai` 如何 ? HOT 1
- 讨论如何实现扯犊子 HOT 1
- dongbei -> dongbai 😆
- 报错信息与语法风格一致化
- 支持一步N蹿磨叽 HOT 2
- 为识别带有关键词的标识符,可以尝试按语法分词 HOT 2
- 在Windows机器上运行 dongbei脚本发生FileNotFoundError HOT 3
- 我感觉这个语言可以再改进一下,把缩进以外的空格全都去掉,这样就完美了。 HOT 10
- 隔壁入墨答的来整个活 HOT 2
- 点星星了,鉴定为好活
- 哥太有才了,真的笑死,star了
- 把“唠唠”改成“嘀咕”? HOT 5
- yield 东北话咋说 HOT 3
- 文件名改成东北话 HOT 1
- 笑疯了的同学都在这个issues里发就好啦 HOT 19
- 1
- 建议这玩意儿可以包装下,学学“中科院木兰事件”,号称100%国产自主研发,技术可控,去骗个几亿经费 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dongbei.