Giter Site home page Giter Site logo

rspython's Introduction

RsPython

**ATTENTION: project superseeded by: ** https://github.com/RustPython/RustPython

Rust implementation of the python language ๐Ÿ ๐Ÿ˜ฑ ๐Ÿค˜.

ATTENTION: project in prototyping phase!

Build Status Join the chat at https://gitter.im/ppci-dev/rspython

Introduction

This package aims to implement the python 3 language in rust. Current implementations of the python3 language are:

  • CPython3 (reference implementation in C)
  • PyPy3 (python implemented in python)
  • IronPython3 (python implementation in .NET)
  • MicroPython (python implementation in C for microcontrollers)
  • RsPython (you are reading the readme now)

Use cases for RsPython:

  • Compile RsPython to webassembly and run python3 scripts in the browser
  • Port python to Redox-os.
  • Provide an alternative implementation next to CPython
  • Combine rust with python in a more natural way

Usage

$ git clone https://github.com/windelbouwman/rspython
$ cd rspython
$ cat demos/simple.py
print('a=', 2 - 22)
$ cargo run demos/simple.py
a= -20
$ python demos/simple.py
a= -20

To get a whole lot of logging, use:

$ RUST_LOG=trace ./target/debug/rspython demos/simple.py

Planning

  • Phase 1: Minimal demo with built in print function and integer variables
  • Phase 2: Add function definitions
  • Phase 3: Add class definitions

Design

The design follows that of CPython. The code is first parsed into an AST (abstract syntax tree). Then it is compiled into bytecode. This bytecode is then executed by a virtual machine. The virtual machine has access to several built-in python types such as int, tuple, list, set, dict and iter.

Parsing

A handwritten lexer is combined with a LALRPOP generated parser. To deal with indentation, the lexer inserts INDENT and DEDENT tokens at the appropriate points.

Compilation

The AST is transformed in bytecode. The available bytecode operations are loosely based upon the ones in CPython

Ideas / notes

  • Instead of compiling to bytecode, the abstract syntax tree can be compiled into rust code and compiled with the language runtime objects. This would give a speedup?
  • A compatible bytecode would be beneficial in order to be able to exchange bytecode files between CPython / micropython.

rspython's People

Contributors

takluyver avatar windelbouwman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

takluyver

rspython's Issues

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.