当前位置: 首页 > 工具软件 > Tiny httpd > 使用案例 >

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

干亮
2023-12-01

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的字面表示,不能跨行

 类似资料: