Git Product home page Git Product logo

minipy's Introduction

 __    __     __     __   __     __     ______   __  __    
/\ "-./  \   /\ \   /\ "-.\ \   /\ \   /\  == \ /\ \_\ \   
\ \ \-./\ \  \ \ \  \ \ \-.  \  \ \ \  \ \  _-/ \ \____ \  
 \ \_\ \ \_\  \ \_\  \ \_\\"\_\  \ \_\  \ \_\    \/\_____\ 
  \/_/  \/_/   \/_/   \/_/ \/_/   \/_/   \/_/     \/_____/ 
                                                           

minipy

Build Status

迷你Python解释器,Python实现的编译器+C语言实现的VM.

如何开始

cd minipy
make && make test

# and enjoy yourself ^_^

特性

编译器

位于 /src/python

  1. tmcode.py 字节码定义
  2. lex.py 词法分析器
  3. parse.py 手写递归解析器
  4. encode.py 代码生成器,运行 python encode.py {script.py} 可以打印出字节码(未处理过的)

特性

  • 基于栈的计算机模型,字节码定义在 src/python/tmcode.py
  • 支持异常处理,基于setjmp/longjmp实现
  • 支持Native方法扩展
  • 支持常用的Python类型
  • Mark-Sweep垃圾回收
  • 字符串常量池
  • 尾调用优化

工具

  1. minipy -dis {test.py} 打印字节码(常量处理过)

代码结构

  1. vm.c 虚拟机入口
  2. interp.c 解释器
  3. builtins.c 一些常用的内置方法
  4. ops.c 操作符实现
  5. tmarg.c 函数调用参数API
  6. exception.c 异常处理
  7. gc.c 垃圾回收器
  8. string.c
  9. number.c
  10. list.c
  11. dict.c
  12. function.c

类型系统

  1. string, 是不可变对象
  2. number, 全部使用double类型
  3. list, 列表
  4. dict, dict对象目前不是使用hashtable实现的,
  5. function, 包括native的C函数和自定义的Python函数
  6. None
  7. data, data类型可以使用C语言自由扩展

协议

  • MIT

minipy's People

Contributors

xupingmao avatar yangluoshen avatar

Stargazers

 avatar

Watchers

 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.