Giter Club home page Giter Club logo

pylite's Introduction

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?

  1. build pycom and pyvm
    • cd pylite && make DEBUG=0
  2. add pycom and pyvm to PATH vaiable
    • PATH=`pwd`/com:`pwd`/vm:$PATH
  3. run tests
    • cd tests && ./run
  4. run a simple HttpServer

Implemented features:

  1. builtin objects: list/dict/tuple/slice/range
  2. if/while/for
  3. function (closure is not supported)
  4. class (only support single inheritance)
  5. module
  6. exception handling
  7. a simple GC

Known bugs:

  1. pylite only use 4 spaces or TAB for indentation
  2. list/dict/tuple literals must be in single line

pylite介绍

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

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

如何编译?

  1. 编译pycom和pyvm
    • cd pylite && make DEBUG=0
  2. 将pycom和pyvm所在的目录加入PATH环境变量
    • PATH=`pwd`/com:`pwd`/vm:$PATH
  3. 运行测试
    • cd tests && ./run
  4. 运行一个简单的http服务器(综合了大部分语言特性)

已经实现的特征:

  1. 常见的内置对象list/dict/tuple/slice/range
  2. 控制流语句if/while/for
  3. 函数(不支持闭包)
  4. 类(只支持单继承)
  5. 模块
  6. 异常处理
  7. 垃圾回收

Known bugs:

  1. 在缩进中,只能使用4空格或则TAB
  2. 必须在一行完成list/dict/tuple的字面表示,不能跨行

pylite's People

Contributors

linuxmooc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.