# pylovm2
Create your own programming language in Python on top of [lovm2](https://github.com/lausek/lovm2).
``` bash
pip3 install pylovm2
```
## Example
``` python
from pylovm2 import Expr, ModuleBuilder, Vm
# initialize a new module
module = ModuleBuilder()
# add the main entry point
main_hir = module.entry()
main_hir.assign('n', 2)
# call the module local function `add` with the value of `n`
main_hir.call('print', 'got result:', Expr.call('add', Expr.var('n'), 1), '\n')
main_hir.call('print', 'got result from pyfn:', Expr.call('pyadd', Expr.var('n'), 1), '\n')
# add new entry with arguments `a` and `b`
add_hir = module.add('add', ['a', 'b'])
add_hir.ret(Expr.add(Expr.var('a'), Expr.var('b')))
# add a python function to the module
module.add_pyfn('pyadd', lambda a, b: a.to_py() + b.to_py())
# build the module and print it
module = module.build()
print(module)
# create vm, load and run module
vm = Vm.with_std()
vm.add_module(module)
vm.run()
```
## Building and Publishing
**NOTE:** manylinux wheels are required for distribution
``` bash
sudo docker build -t pylovm2-build .
sudo docker run -it -v $(pwd):/io pylovm2-build
# ... or use `maturin build`
$ maturin publish
```
PyPI 官网下载 | pylovm2-0.4.7.tar.gz
版权申诉
20 浏览量
2022-01-29
10:14:35
上传
评论
收藏 23KB GZ 举报
挣扎的蓝藻
- 粉丝: 13w+
- 资源: 15万+
最新资源
- 后端开发框架探索与选择
- Python课设-学生信息管理系统
- 广东省2021年普通高考音乐表演-器乐类总分分数段统计表(含本、专科层次加分)
- ubuntu20.04安装教程.md
- 广东省2021年普通高考音乐表演-声乐类总分分数段统计表(含本、专科层次加分)
- 广东省2021年普通高考音乐学类总分分数段统计表(含本、专科层次加分)
- 广东省2021年普通高考舞蹈类总分分数段统计表(含本、专科层次加分)
- Python教程-快速入门基础必看课程10-函数基础
- tensorflow-2.9.2-cp39-cp39-win-amd64.whl
- tensorflow-2.9.2-cp37-cp37m-win-amd64.whl
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈