Git Product home page Git Product logo

minipy's Introduction

MiniPy Compiler

Abstract

A compiler compiles python to LLVM-IR.

Environment

Windows

This repo should work on linux too, but a few things around the environment need to be altered...

  • flex ~= 2.6.4
  • bison ~= 3.8.2
  • make ~= 4.4.1
  • gcc ~= 13.1.0

Build

make clean
make  # or `make all`

Run

Use the commands below to compile the demo file test.py, and the outputs will print to log.txt and result_ir.ll.

make help  # help message of this compiler
make test  # or `make show` if you want to print to terminal colorfully, :)
make sample  # compile all testsamples in testsample/

To see the usage you can use the flag --help, and the output will be shown as below.

# help
compiler -h

# run
compiler \
    <input_file> \
    [-i [-o <output_file>]] \
    [-d <debug_mode> [-e <debug_output_file>]] \
    [-O <num>] [-t] [-s]
-h == --help
-i == --ir:
-o == --out:
-d == --debug:
<debug_mode> can be shell, lex, parse, ast, sym
-e == --debug_out:
-O == --optimize:
-t == --time:
-s == --show 

Be free to do whatever you like.

build\compiler.exe --help
build\compiler.exe test.py -i -o out.ll --debug ast -e ast.txt --time --show
...

Notes (Chinese)

由于 bison 的 lookahead 的限制,很多语法并不能直接交给 bison 处理。所以 parser.y 中的语法其实上是 python 的超集,需要后续符号表扫描时提供更多的检查。

文件的依赖关系是严格的:

color   timing
 │       ╽
 ╰────━ log ─────╮
         ╽       ╽
        lexer   shell
         ╽
        parser
         ╽
        symbol
         ╽
        ir
         ╽
        compiler

另外,修改了 enum 记得重新编译所有内容(make all -B),因为其他文件的 enum 仍然是按照 int 记录的,没有改变。会导致奇奇怪怪的错误。

Todo list (Chinese)

  • 配置 makefile
  • 沿用以前写的 log,微调
  • 完成泛用 shell(以后可以给别的程序用)
  • 添加 Graphviz 好看的显示
  • Lexer: 完成架构
  • Lexer: 完成 indent dedent 相关
  • Lexer: 完成 indent dedent 接触 EOF 时的特殊操作
  • AST: 完成架构
  • AST: 完成基础 expression
  • AST: 完成基础 assign, tuple-assign
  • AST: 完成 dot, index, function-call 的文法
  • AST: 完善 str, list, tuple, set 的文法
  • AST: 完成绝大多数 simple statements 的文法
  • AST: 完成绝大多数 block statements 的文法
  • Symbol: 完成架构
  • Symbol: 完成表的树状扫描搜索函数
  • Symbol: 完成基本类型、复合类型、函数、类的不同构造
  • Symbol (Search AST): 完成基本类型的解析
  • Symbol (Search AST): 完成函数的解析
  • Symbol (Search AST): 完成函数泛型(动态类型)的实例化
  • Symbol (Search AST): 完善 class 的数据类型和继承类型的的保存
  • LLVM-IR: 完成架构
  • LLVM-IR: 完成表达式和赋值等基本语句的转化
  • LLVM-IR: 完成循环、跳转的转化
  • LLVM-IR: 完成函数的转化
  • LLVM-IR: 完成类的转化

minipy's People

Contributors

tastror 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.