tiny linux python,GitHub - linuxmooc/pylite: A tiny python interpreter for educational purpose

What is pylite?

pylite is a hobby python interpreter, which can tell you how python compiler and virtual machine works. It serves for educational purposes, so the code is kept as simple as possible.

pylite consists of two executables: pycom and pyvm. pycom is the compiler, which has 5000 LOC. pyvm is the virtual machine, which has 6000 LOC.

How to build?

build pycom and pyvm

cd pylite && make DEBUG=0

add pycom and pyvm to PATH vaiable

PATH=`pwd`/com:`pwd`/vm:$PATH

run tests

cd tests && ./run

run a simple HttpServer

cd httpd && pyvm server.py

open the browser and access http://localhost:8080

Implemented features:

builtin objects: list/dict/tuple/slice/range

if/while/for

function (closure is not supported)

class (only support single inheritance)

module

exception handling

a simple GC

Known bugs:

pylite only use 4 spaces or TAB for indentation

list/dict/tuple literals must be in single line

pylite介绍

pylite是一个用于编译原理教学的python解释器,通过学习它的源代码可以了解python编译器和虚拟机是如何工作的。

pylite包含两个可执行程序:pycom和pyvm。pycom是编译器,由5000行代码构成。pyvm是虚拟机,由6000行代码构成。

如何编译?

编译pycom和pyvm

cd pylite && make DEBUG=0

将pycom和pyvm所在的目录加入PATH环境变量

PATH=`pwd`/com:`pwd`/vm:$PATH

运行测试

cd tests && ./run

运行一个简单的http服务器(综合了大部分语言特性)

cd httpd && pyvm server.py

已经实现的特征:

常见的内置对象list/dict/tuple/slice/range

控制流语句if/while/for

函数(不支持闭包)

类(只支持单继承)

模块

异常处理

垃圾回收

Known bugs:

在缩进中,只能使用4空格或则TAB

必须在一行完成list/dict/tuple的字面表示,不能跨行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值