gpython is a python interpreter written in go "batteries not included"
Switch branches/tags
Clone or download
ncw repl/web: apply wasm_exec.js.patch to fix print() under wasm
The patch was committed in the initial commit but it wasn't applied!
Latest commit b715616 Oct 18, 2018
Permalink
Failed to load latest commit information.
ast Add copyright headers to all files Aug 21, 2018
bin bin: script to install python 3.4 Sep 3, 2018
builtin Add support for print to file and file flush. Sep 12, 2018
ci gpython: add code coverage support Aug 22, 2018
compile all: apply gofmt simplify Aug 22, 2018
examples Add copyright headers to all files Aug 21, 2018
importlib Add copyright headers to all files Aug 21, 2018
marshal Add copyright headers to all files Aug 21, 2018
math math: tests: Rename math.py -> mathtests.py so "import math" works pr… Sep 3, 2018
parser parser: Update from go tool yacc into goyacc (#22) Sep 3, 2018
py complex: added __str__ and __repr__ plus missing properties Oct 10, 2018
pytest Add support for print to file and file flush. Sep 12, 2018
repl repl/web: apply wasm_exec.js.patch to fix print() under wasm Oct 18, 2018
symtable all: apply gofmt simplify Aug 22, 2018
sys Initial work at implementing file methods: Sep 5, 2018
time all: apply gofmt simplify Aug 22, 2018
vm vm: make PrintExpr hook for steering the output of PRINT_EXPR in the … Oct 11, 2018
.gitignore Tidy junk files Aug 5, 2018
.goreleaser.yml Add goreleaser to make packages on github Aug 5, 2018
.travis.yml build: run py3test.py, installing python3.4 if necessary Sep 3, 2018
CONTRIBUTE.md Relicense the project under BSD License with the go-python organisation Aug 21, 2018
LICENSE Relicense the project under BSD License with the go-python organisation Aug 21, 2018
README.md Implement a web based REPL using gpython Oct 11, 2018
RELEASE.md Update release docs Aug 21, 2018
appveyor.yml ci: add Go1.11, drop Go1.8 (#17) Aug 30, 2018
go.mod Implement a web based REPL using gpython Oct 11, 2018
go.sum Implement a web based REPL using gpython Oct 11, 2018
main.go Factor REPL into CLI part and agnostic part and add tests Oct 11, 2018
notes.txt Fix imports and docs after move to go-python org Aug 21, 2018
py3test.py Revamp py3test Sep 3, 2018

README.md

gpython

Build Status codecov GoDoc License

gpython is a part re-implementation / part port of the Python 3.4 interpreter to the Go language, "batteries not included".

It includes:

  • runtime - using compatible byte code to python3.4
  • lexer
  • parser
  • compiler
  • interactive mode (REPL) (try online!)

It does not include very many python modules as many of the core modules are written in C not python. The converted modules are:

  • builtins
  • marshal
  • math
  • time
  • sys

Install

Gpython is a Go program and comes as a single binary file.

Download the relevant binary from here: https://github.com/go-python/gpython/releases

Or alternatively if you have Go installed use

go get github.com/go-python/gpython

and this will build the binary in $GOPATH/bin. You can then modify the source and submit patches.

Objectives

Gpython was written as a learning experiment to investigate how hard porting Python to Go might be. It turns out that all those C modules are a significant barrier to making a fully functional port.

Status

The project works well enough to parse all the code in the python 3.4 distribution and to compile and run python 3 programs which don't depend on a module gpython doesn't support.

See the examples directory for some python programs which run with gpython.

Speed hasn't been a goal of the conversions however it runs pystone at about 20% of the speed of cpython. The pi test runs quicker under gpython as I think the Go long integer primitives are faster than the Python ones.

There are many directions this project could go in. I think the most profitable would be to re-use the grumpy runtime (which would mean changing the object model). This would give access to the C modules that need to be ported and would give grumpy access to a compiler and interpreter (gpython does support eval for instance).

I (@ncw) haven't had much time to work on gpython (I started it in 2013 and have worked on it very sporadically) so someone who wants to take it in the next direction would be much appreciated.

Limitations and Bugs

Lots!

Similar projects

  • grumpy - a python to go transpiler

License

This is licensed under the MIT licence, however it contains code which was ported fairly directly directly from the cpython source code under the (PSF LICENSE)[https://github.com/python/cpython/blob/master/LICENSE].