Jaspy

一个完全用 JavaScript 从头开始编写的 Python 字节码虚拟机,具有一些独特的功能。「A Python byte code VM written entirely from scratch in JavaScript with some unique features.」

Github星跟踪图

Jaspy

pypi
build
coverage
docs
gitter

Jaspy is a Python VM written entirely from scratch in JavaScript with
some unique features. Jaspy supports multiple threads, comes with an
integrated debugger which offers remote debugging and provides a
flexible preprocessor based architecture. Speed is explicitly not a main
goal of this project. Jaspy aims to illustrate how web programming on
the client side could be done by exploring new ways.

Features

  • suspendable interpreter with support for threading and
    greenlets
  • integrated debugger and interactive remote debugging (CLI,
    PyCharm, ...)
  • flexible preprocessor based architecture to optimize Jaspy for
    your needs
  • easily extensible with native JavaScript modules
    (time,
    dom,
    ...)
  • full support for meta-classes, builtin subclassing and operator
    overloading
  • asynchronous imports and arbitrary-length integers based on
    BigInteger.js

Quickstart

Jaspy comes with an integrated development server and interactive
debugger!

First install the dependencies, if they are not installed already:

pip3 install --user -r requirements.txt
pip3 install --user ptpython pygments

Clone the repository and build the interpreter:

git clone --recursive https://github.com/koehlma/jaspy.git; cd jaspy
python3 build.py  # build the interpreter

Switch to the example directory and start the server in interactive
mode:

cd example
PYTHONPATH=../ python3 -m jaspy.cli --interactive

Visit http://localhost:8080/hello.html in your browser and click run:

Jaspy Screencast{.align-center}

Alternatives

There are already many other Python-to-JavaScript approaches out there:

Most of them are faster than Jaspy but none of them offers the unique
features of Jaspy, which are the fully suspendable interpreter with
threading support, the integrated debugger and the flexible,
preprocessor based architecture.

Speed

Just to get an impression how slow Jaspy really is!


                                              pystones/second

Jaspy (enabled Debugger, enabled Threading) 195

Jaspy (disabled Debugger, enabled Threading) 199

Jaspy (disabled Debugger, disabled Threading) 206

Brython 4184

PyPy.js (cold) 41425

PyPy.js (warm) 847457

However this is a somewhat unfair benchmark because no dom manipulation
or anything else browser specific is going on. Surprisingly threading
and debugging introduces nearly no overhead.

State

This project is still in an alpha state. The APIs are unstable, it is
untested and not ready for productive use. Some of the features listed
above are not yet implemented.

I started this project in my semester break and now, as the new semester
started, I have much less spare time. Therefore it might take a while
until I will be able to invest much more time into it. However I very
welcome all sorts of contributions.

Contributions

If you like the ideas of Jaspy feel free to join, there are many things
to do:

  • implement all the batteries-included-builtin stuff of Python
  • implement native JS modules for the DOM, JS objects and some Web
    APIs
  • improve the debugger and make it fully compatible to the PyDev
    protocol
  • implement a parser and bytecode compiler in JavaScript
  • complete and adjust the implementation of the Python bytecode VM
  • support for Apache Cordova (Jaspy for cross platform mobile
    applications)
  • implement a neat UI library on top of Jaspy (using a flexbox based
    grid)
  • implement a just-in-time compiler to speed things up
  • add a virtual file system (consider using:
    BrowserFS)
  • ... and, of course, your own great ideas and cool features

Do not hesitate to contribute or ask if there is anything unclear about
the code or the process of contributing in general.

Structure

libs

: third-party dependencies

modules

: bundled native JavaScript modules

src

: JavaScript source files (need to be preprocessed)

jaspy

: Python server, converter and remote debugger

Credits

Many thanks to the Brython project for the
inspiration for many parts of code of the builtin-classes. Many thanks
also to the book "500 Lines or
Less"

which is a good starting point if you want to know how the interpreter
works.

主要指标

概览
名称与所有者koehlma/jaspy
主编程语言JavaScript
编程语言JavaScript (语言数: 3)
平台
许可证
所有者活动
创建于2016-02-20 01:41:03
推送于2020-10-16 13:16:34
最后一次提交2016-09-17 20:00:09
发布数1
最新版本名称v0.1.0 (发布于 )
第一版名称v0.1.0 (发布于 )
用户参与
星数578
关注者数25
派生数52
提交数330
已启用问题?
问题数3
打开的问题数1
拉请求数0
打开的拉请求数1
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?