gpython is a python interpreter written in go "batteries not included"



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


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

Download the relevant binary from here:

Or alternatively if you have Go installed use

go get

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


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.


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


Similar projects

  • grumpy - a python to go transpiler


You can chat with the go-python community (or which gpython is part) at [email protected] or on the Gophers Slack in the #go-python channel.


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.

  • Add OS module

    Add OS module

    OS Module

    I added some of the basic functions/globals of the OS module, these include;

    • Functions
      • os.getcwd()
      • os.getcwdb()
      • os.chdir()
      • os.getenv()
      • os.getpid()
      • os.putenv()
      • os.unsetenv()
      • os._exit()
      • os.system()
    • Globals
      • os.error
      • os.environ

    I also added a py.Println function, in which you can find the definition for in py/ It looks something like this

    func Println(self Object, args ...string) (int,error)

    This is my first contribution to gpython, so please give me feedback and other things I should add. The first two commits were tests i made to figure out how to create a module; I was going to make a JSON module, but then I saw that gpython didnt have an OS module, and I thought that was more important than a JSON module at this time. I've also included, a file which you can run with gpython to check if the OS module is working properly.


    opened by glaukiol1 22
  • Multi-context execution (py.Context)

    Multi-context execution (py.Context)

    Hi Seb, it's a been a couple months but things are well here.

    With this PR, I am pleased to share gpython with multi-context execution! Check out type Context interface and vm/vm_test.go for a quick start.

    My intention with this PR is get feedback from you on what you want me to alter or massage so that you are satisfied. I am totally open if you want me to shift, rename, or organize code in ways that you would prefer, so kindly please just let me know. I think many will be highly interested in a multi-ctx gpython (as many have asked for it as you already know).

    So if you like things as they are, you can merge this PR. Otherwise, just give me a list of things you want changed and I'll resubmit a new PR with that. Or, perhaps merge this PR as is, insert edits as you see fit, tag it into a new release and version, and then I will follow your lead and ditch my fork and we can be on our way. :)

    We are definitely using gpython here for our classified particle research project and would love to join forces with you on maintaining gpython. I think it is highly reasonable, especially with this PR, that gpython is picked up (sponsored) since it serves the Google, Python, and Go communities quite uniquely.

    opened by drew-512 18
  • Fix comments in REPL - fixes #78

    Fix comments in REPL - fixes #78

    Before this change, entering a comment in the REPL caused the REPL to read the comment indefinitely effectively breaking it.

    After this change the behaviour should be exactly the same as python3/

    opened by ncw 10
  • Embedding Go objects

    Embedding Go objects

    Hi friends, love gpython and would be into contributing. I'm looking to expose a particle physics Go module that I maintain via a module in gpython. Problem is, Objects in gpython only offer embedded Go methods. Yes, I suppose I could make a new closure for each Go struct/interface to embed, but we can all agree that is painfully wasteful.

    If someone here can give me some guidance on how to approach this, I'd be into adding this code. This physics module is rerally exciting and we expect it to get some major traction in the physics community (the LHC for starters) -- and I'd much rather use gpython than lua!

    opened by drew-512 8
  • builtin: Update builtin_all and builtin_any for Python3

    builtin: Update builtin_all and builtin_any for Python3

    Update builtin_all and builtin_any for Python3 reference:



    opened by corona10 8
  • Improve some things around how errors are reported when parsing a file

    Improve some things around how errors are reported when parsing a file

    Given the malformed input "/Users/jpoole/gpython/":

    def foo(name : str):
        return name
    foo(name = "test"))


    Exception &py.Exception{Base:(*py.Type)(0xc00012dc20), Args:py.Tuple{"invalid syntax"}, Traceback:py.Object(nil), Context:py.Object(nil), Cause:py.Object(nil), SuppressContext:false, Dict:py.StringDict{"filename":"<string>", "line":"", "lineno":10, "offset":0}}
    -- No traceback available --
    2022/04/10 18:31:19 
      File "<string>", line 10, offset 0
    SyntaxError: 'invalid syntax'


      File "/Users/jpoole/gpython/", line 10, offset 0
    SyntaxError: 'unexpected EOF while parsing'
    -- No traceback available --
    opened by Tatskaari 7
  • Errors are suppressed in generator comprehensions

    Errors are suppressed in generator comprehensions

    >>> list(i for x in range(10))

    Which should have output

    >>> list(i for x in range(10))
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 1, in <genexpr>
    NameError: name 'i' is not defined
    opened by ncw 7
  • Implement set operation

    Implement set operation

    These operations should be implemented

    >>> a = {1, 2, 3}
    >>> b = {2, 3, 4, 5}
    >>> a | b
    {1, 2, 3, 4, 5}
    >>> a & b
    {2, 3}
    >>> a - b
    >>> a ^ b
    {1, 4, 5}
    opened by corona10 6
  • SyntaxError of global declaration don't stop program

    SyntaxError of global declaration don't stop program

    a = 3
    global a
    b = 2 + 5

    This code generate syntax error, but gpython doesn't stop program

    Expected Result

    Hyeockz:bin hyeockjinkim$ python3 
      File "", line 2
        global a
    SyntaxError: name 'a' is assigned to before global declaration

    Actual Result

    2019/09/09 00:08:36 name 'a' is assigned to before global declaration

    SyntaxError in python3 is Error, not warning. So I think it should be modified.

    bug Contributhon2019 
    opened by HyeockJinKim 6
  • builtin: Implement builtin function any, all.

    builtin: Implement builtin function any, all.

    Hi, I have highly interested in this project. I've experienced to work on the grumpy project also.

    Anyway, this might be my first PR, Please take a look.

    opened by corona10 6
  • How would i go about writing a new module?

    How would i go about writing a new module?


    I want to contribute to this project by writing a module; specifically the JSON module (the one that is in python's standard library). I have seen the source code and have an idea of how I should go about this. So my question is; do I create a folder and put the .go file in there? Something like json/json.go? Also any tips on writing modules would help, thanks!

    opened by glaukiol1 5
  • Getting started on asyncio

    Getting started on asyncio

    I've been trying to understand how this project works, and also how we can support newer language versions. I've done some reading into how asyncio works, and I thought I would share that here. Sorry if this is not news to anybody, I'm not much of a python developer.

    The co-routine introduced in python3.5 seem to be the biggest language feature we need to support to become current. The op codes can be found here:

    A basic example program looks like:

    import asyncio
    async def foo():
        return "test"
    async def bar():
        return await foo()

    And produces the following bytecode:

      1           0 LOAD_CONST               0 (0)
                  2 LOAD_CONST               1 (None)
                  4 IMPORT_NAME              0 (asyncio)
                  6 STORE_NAME               0 (asyncio)
      3           8 LOAD_CONST               2 (<code object foo at 0x0000021C72C52130, file "", line 3>)
                 10 LOAD_CONST               3 ('foo')
                 12 MAKE_FUNCTION            0
                 14 STORE_NAME               1 (foo)
      6          16 LOAD_CONST               4 (<code object bar at 0x0000021C72C521E0, file "", line 6>)
                 18 LOAD_CONST               5 ('bar')
                 20 MAKE_FUNCTION            0
                 22 STORE_NAME               2 (bar)
     10          24 LOAD_NAME                3 (print)
                 26 LOAD_NAME                0 (asyncio)
                 28 LOAD_METHOD              4 (run)
                 30 LOAD_NAME                2 (bar)
                 32 CALL_FUNCTION            0
                 34 CALL_METHOD              1
                 36 CALL_FUNCTION            1
                 38 POP_TOP
                 40 LOAD_CONST               1 (None)
                 42 RETURN_VALUE
    Disassembly of <code object foo at 0x0000021C72C52130, file "", line 3>:
                  0 GEN_START                1
      4           2 LOAD_CONST               1 ('test')
                  4 RETURN_VALUE
    Disassembly of <code object bar at 0x0000021C72C521E0, file "", line 6>:
                  0 GEN_START                1
      7           2 LOAD_GLOBAL              0 (foo)
                  4 CALL_FUNCTION            0
                  6 GET_AWAITABLE
                  8 LOAD_CONST               0 (None)
                 10 YIELD_FROM
                 12 RETURN_VALUE

    The byte code of calling the functions is actually unchanged. The functions marked with async just have to return a co-routine object. The GET_AWAITABLE opcode seems to cast the other await-able types e.g. generators or classes that implement self.__await__.

    We might be able to implement this fairly easily by just wrapping the Function type in a co-routine type. To get any actual concurrency out of this implementation though, we need to implement the event loop API.,asyncio%20functions%2C%20such%20as%20asyncio.

    This is the hard part which actually allows creation of futures and tasks. I'm not sure if the await for byte code that was already implemented in 3.4 has all the features we need, but it looks like we can get pretty far with the byte code we have already.

    The last piece of the puzzle is select() which allows us to wait on a socket while executing another co-routine.

    There's a good write-up here:

    opened by Tatskaari 0
  • builtin: input() function not defined.

    builtin: input() function not defined.

    There should definitely be a input() function; to get user input. This would be implemented in the builtin function.

    Doc in;

    If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. Example:

    >>> s = input('--> ')  
    --> Monty Python's Flying Circus
    >>> s  
    "Monty Python's Flying Circus"

    If the readline module was loaded, then input() will use it to provide elaborate line editing and history features.

    Raises an auditing event builtins.input with argument prompt before reading input

    Raises an auditing event builtins.input/result with the result after successfully reading input.

    opened by glaukiol1 0
  • Revise gpython 'About'?

    Revise gpython 'About'?

    @sbinet @ncw and anyone interested...

    Currently, gpython's 'About' line on github is:

    gpython is a python interpreter written in go "batteries not included"

    After the upcoming worklist, I think it would be good time to consider shifting this project's tagline to something that speaks to its strengths and how it offers value now and future forward. I see gpython as a leading choice for a Go developers looking for an interpreter to embed for real-world use -- especially if their "customers" tend to be non-professional developers, such as scientists.

    Some ideas that seem in the right direction...

    gpython is a Python interpreter written in Go,
    offering concurrent execution and new ways to (offer|deploy|use) your Go packages

    gpython is a Go-based Python interpreter consistent with Go concurrency,
    offering new ways to (offer|deploy|use) your Go packages

    And is it "Python" or "python", I can never know. Proper noun right? I definitely like "Go" over "go" when writing it in sentences to humans, so I'm inclined to be consistent with referring to Python. Or maybe there is Python the language but there is python code. I would love for someone to lmk to put my squirrel brain to rest on this. 🐿️


    opened by drew-512 0
  • Upcoming gpython worklist

    Upcoming gpython worklist

    Below is my upcoming worklist I plan to take on in the coming weeks/months:

    1. Add stack limit value to py.ContextOpts and implement (Issue 143)
    2. Additions to py.utils, including funcs that use reflect to auto-populate Go structs from a given py.Object
    3. Add exit() (Issue 140)
    4. Add a shared set of golden util funcs to pytest/pytest.go so the same boilerplate doesn't have to appear for each golden main_test.go etc
    5. Enhance examples/multi-context into a golden test.
    6. Add real, imag, conjugate properties to py.Int, py.Float, py.BigInt, py.Bool plus tests (Issue 73)
    7. For cleanliness and organization, I suggest we move all the built-in modules into the modules dir. In a future where gpython gets traction as an embedded interpreter and more and more modules appear, it makes sense to me that they show up the modules dir, not the project root dir. This is basically just a bunch of dirs moving and a few import lines changing. I would be happy to do this first or as soon as makes sense (since something like this is better done sooner than later). I think this is also very helpful (self-documenting) for newcomers to understand the project structure and organization.
    8. Introduce py.ModuleImpl for os, offering support for a few commonly used functions -- e.g. os.system()
      • This is a security concern (e.g. python web demo). Thinking I add flags to py.ContextOpts that correspond to new py.Method flags which are checked when a py.Module is populated during an initial py.Context module import (instantiation).
      • I would add tests that test each security mode / flag
    9. Add support for .format using pyfmt (Issue 116)
      • Before doing this, I would appreciate sign-off on pyfmt so I don't start investing time into that and then we don't want to add that as a dependency. We can cross this bridge as it comes, but I wanted to express the value here and that pyfmt is a natural fit with gpython!
      • I left a note to the dev

    Also please lmk what order I should do these in if that's something that matters to people. Otherwise, I listed them in the order that makes the most sense to me.

    @sbinet @ncw, please lmk how the PRs should show up. By default, I'll do a separate PR for each numbered item (citing the Issue # in the PR)


    opened by drew-512 3
  • Recursive call crashes gpython

    Recursive call crashes gpython

    We define a function and recursive call the function in crashing gpython. This case cannot crash CPython and it reports a RecursionError.

    def f():

    Expected output: RecursionError

    Actual output: runtime: goroutine stack exceeds 1000000000-byte limit fatal error: stack overflow

    runtime stack: runtime.throw(0x66c609, 0xe) /opt/go/go1.11/src/runtime/panic.go:608 +0x72 runtime.newstack() /opt/go/go1.11/src/runtime/stack.go:1008 +0x729 runtime.morestack() /opt/go/go1.11/src/runtime/asm_amd64.s:429 +0x8f goroutine 1 [running]: runtime.heapBitsSetType(0xc0027a3440, 0x30, 0x30, 0x658180) /opt/go/go1.11/src/runtime/mbitmap.go:911 +0xa30 fp=0xc0226e2390 sp=0xc0226e2388 pc=0x416c80 runtime.mallocgc(0x30, 0x658180, 0x1, 0x0) /home/ncw/go/src/ +0x40 fp=0xc0226e83c8 sp=0xc0226e8378 pc=0x5b33d0 ...additional frames elided... ....................... goroutine 19 [syscall]: os/signal.signal_recv(0x0) /opt/go/go1.11/src/runtime/sigqueue.go:139 +0x9c os/signal.loop() /opt/go/go1.11/src/os/signal/signal_unix.go:23 +0x22 created by os/signal.init.0 /opt/go/go1.11/src/os/signal/signal_unix.go:29 +0x41

    version: Gpython3.4.0 on Ubuntu 16.04

    opened by xiaxinmeng 3
  • No functional exit function.

    No functional exit function.

    Consider the following code

    $ ./gpython 
    Python 3.4.0 (none, unknown)
    [Gpython dev]
    - os/arch: linux/amd64
    - go version: go1.16.6
    >>> exit()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
        FIXME line of source goes here
    NameError: "name 'exit' is not defined"
    >>> import sys
    >>> sys.exit()
    <SystemExit instance at 0xc000208180>
    >>> quit()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
        FIXME line of source goes here
    NameError: "name 'quit' is not defined"

    Unable to exit REPL of gpython by function.

    opened by stevenleeS0ht 0
  • v0.1.0(Feb 15, 2022)

    This release ships with a new multi-context interpreter.

    Many thanks to @drew-512 for this work are in order.

    What's Changed

    • ci: use latest patch version of Go releases by @sbinet in
    • Go mod by @sbinet in
    • ci: add appveyor build (windows) by @sbinet in
    • all: apply gofmt simplify by @sbinet in
    • appveyor.yml: Fix gcc issue on go test -race ./... by @corona10 in
    • ci: add Go1.11, drop Go1.8 by @sbinet in
    • builtin: Update builtin_all and builtin_any for Python3 by @corona10 in
    • gpython: use peterh/[email protected] by @sbinet in
    • parser: Update from go tool yacc into goyacc by @corona10 in
    • builtin: Implement builtin sum by @corona10 in
    • Initial work at implementing file methods by @raff in
    • print should use str or repr when available by @raff in
    • Add support for print to file and file flush. by @raff in
    • Added str and repr plus missing properties by @raff in
    • py: Fix TracebackDump not to dump duplicated exception type by @corona10 in
    • parser: Update by @corona10 in
    • py: Fix errors are suppressed in generator comprehensions by @corona10 in
    • py: Support len of rangetype. by @corona10 in
    • builtin: Implement enumerate feature by @corona10 in
    • py: Fix range to support negative step by @corona10 in
    • py: Support zip builtin feature by @corona10 in
    • py: Implement range M__getitem__ by @corona10 in
    • Implement benchmark framework for gpython along with a couple of benchmarks by @ncw in
    • builtin: Implement min/max builtin function by @corona10 in
    • builtin: Implement builtin_iter by @corona10 in
    • builtin: Implement delattr by @corona10 in
    • Fix initialisation of function, staticmethod and classmethod dict by @ncw in
    • #44 Display build information by @kislenko-artem in
    • Adding split method to string class by @kellrott in
    • Adding iterator method to Dict by @kellrott in
    • String and List Methods by @kellrott in
    • fix: ~/.gpyhistory: no such file or directory by @msAlcantara in
    • dict: Implement contains of dict by @corona10 in
    • py: Fix mul of list and tuple on negative case by @corona10 in
    • builtin: Implement builtin_ascii by @corona10 in
    • builtin: Implement builtin_bin by @corona10 in
    • Generate SyntaxError of global declaration by @HyeockJinKim in
    • Implement and of set by @DoDaek in
    • set: Implement or of set by @DoDaek in
    • Implement range object by @HyeockJinKim in
    • set: Implement sub and xor of set by @DoDaek in
    • Fix "end" option in print func by @Sungmin-Joo in
    • Add Slice function for range type by @HyeockJinKim in
    • Revert "Fix "end" option in print func" by @corona10 in
    • Fix comments in REPL - fixes #78 by @ncw in
    • set: Implement initialization set with sequence by @SanggiHong in
    • Add new function and property of slice by @HyeockJinKim in
    • Add sorted and list.sort in
    • Change repr(float) if float(int(f)) == f in
    • Handle the non-integer return of index by @HyeockJinKim in
    • ci: drop Go-1.9+1.10, add Go-1.12.x and Go-1.13.x by @sbinet in
    • Implement float is_integer method by @DoDaek in
    • Implementing the "get" function on a "Dictionary" by @Sungmin-Joo in
    • ne of dict return NotImplemented by @HyeockJinKim in
    • ne of set return NotImplemented by @HyeockJinKim in
    • Implement eq, ne for slice by @HyeockJinKim in
    • Implement set repr by @xarus01 in
    • Implement isinstance by @xarus01 in
    • Initial attempt at gometalinter rules by @sbinet in
    • ci: add go-import-path to handle fork builds by @sbinet in
    • Cleanup Go Module, remove spurious coverage file by @sbinet in
    • builtin,vm: add implementation for builtin hex function by @sbinet in
    • Fix bug in "items" function by @Sungmin-Joo in
    • all: add GitHub Actions CI by @sbinet in
    • ci: update CI scaffolding by @sbinet in
    • time: add time_ns function by @sbinet in
    • Ci no travis by @sbinet in
    • kwarg testing (exposes bugs in py.ParseTupleAndKeywords) by @drew-512 in
    • resolved benign Go warnings by @drew-512 in
    • better Int.abs() and test coverage by @drew-512 in
    • Add list type safety, helpers; remove cruft by @drew-512 in
    • Add multi context by @drew-512 in
    • gpython: blank-import gpython/modules by @sbinet in
    • added examples and py utils by @drew-512 in
    • examples/{embedding,multi-context}: add LICENSE blurb, cosmetics by @sbinet in
    • proper example completeness by @drew-512 in
    • updated README by @drew-512 in

    New Contributors

    • @sbinet made their first contribution in
    • @raff made their first contribution in
    • @ncw made their first contribution in
    • @kislenko-artem made their first contribution in
    • @kellrott made their first contribution in
    • @msAlcantara made their first contribution in
    • @HyeockJinKim made their first contribution in
    • @DoDaek made their first contribution in
    • @Sungmin-Joo made their first contribution in
    • @SanggiHong made their first contribution in
    • @xarus01 made their first contribution in
    • @drew-512 made their first contribution in

    Full Changelog:

    Source code(tar.gz)
    Source code(zip)
  • v0.0.3(Dec 5, 2018)


    f4ab05f Initial attempt at gometalinter rules f7ea0a4 Add a Community section to the README 734fbaa py: Fix errors are suppressed in generator comprehensions 0773b68 parser: Update 2981ee9 py: Fix TracebackDump not to dump duplicated exception type b715616 repl/web: apply wasm_exec.js.patch to fix print() under wasm 50cd487 Implement a web based REPL using gpython 08903fc Factor REPL into CLI part and agnostic part and add tests d13383c vm: make PrintExpr hook for steering the output of PRINT_EXPR in the REPL d05bbcc complex: added str and repr plus missing properties 4f66e54 Add support for print to file and file flush. 8cee534 Make getattr return methods implemented in go - fixes #28 ee952c8 print should use str or repr when available 6e7b5ec Initial work at implementing file methods: - open (builtin) - - File.write - File.close 09f14d0 builtin: Implement builtin sum (#21) eaa7d28 build: run, installing python3.4 if necessary bf8d938 Revamp py3test a5185a2 bin: script to install python 3.4 f7ce7c0 math: tests: Rename -> so "import math" works properly 6ded9bc parser: Update from go tool yacc into goyacc (#22) ed3c651 ci: enable GO111MODULE=on for master a182849 gpython: use peterh/[email protected] b55db0b builtin: Update builtin_all and builtin_any for Python3 c6c49d2 ci: add Go1.11, drop Go1.8 (#17) 60ae876 appveyor.yml: Fix gcc issue on go test -race ./... 6a2b593 all: apply gofmt simplify 16e9ec3 gpython: point to new home of grumpy dd41cdd gpython: add code coverage support e9df6dc ci: add appveyor build (windows) e9ee2ff gpython: add license badge 43a6207 gpython: add initial support for Go modules c37be76 ci: use latest patch version of Go releases

    Automated with GoReleaser Built with go version go1.11.2 linux/amd64

    Source code(tar.gz)
    Source code(zip)
    gpython_0.0.3_checksums.txt(1.31 KB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB)
  • v0.0.0(Aug 5, 2018)


    c0de7de travis: don't test on go1.7 as it fails the math tests 46f8028 math: comment out some expm1 tests which fail on 32 bit a910f3b travis: run tests in 32 bit mode as well 32e35ae math: fix compile on 32 bit systems 9e5c0d4 Change Type.Flags to uint to make gpython compile on 32 bit OSes f75f21e Tidy junk files 9442150 Add goreleaser to make packages on github 77dde64 Test gpython with Travis CI 8b45fd5 Fix link to PSF licence 7418ece Add LICENSE, README and examples 5e6dfca Note about clang tools 97e4a0f compile: add line numbers to compiler and create line number table (lnotab) bbab811 compile, symtable, parse: get lineno, offset, file into SyntaxErrors 4fc4f37 testparser: make it compile too and make a py3 comparison c8b83ac py, parse: float - fix parsing of out of range floats and floats with spaces bdc70db parser: testparser - script to parse all the python source 132a9f5 py: int - fix base conversion with base and sigil c61c054 Make tests past with python3 too b9545a4 py: type - fix initialisation and repr eb7e8f3 py: fix GoInt and GoInt64 for BigInts af1ba18 py: list fix add 066aaa7 math: implement math module 7e4f791 py: method - add eq and ne 40a2528 py: make == and != complain if comparing the same type with no eq method f148ad3 Notes on dict implementation 20fb671 builtin: implement exec() and eval() d0c72a9 vm: stop dict literals or dict comp panicing with non string keys f16c0ab py: int: fix multiply bf7e345 repl: allow """ strings to span lines e1bc5aa parser: return correct errors for unterminated triple quoted strings d9667bc repl: implement multi line code input with continuation lines e352670 parser: fix "single" mode and return correct EOF error 5775015 repl: line editing with history and completion 5148b8e py: repr and str for bool, bytes, dict, ellipsis, list, module, none, string, tuple 3f14f3d py, builtin, vm: make str() and repr() and implement some str and repr de8c04a builtin: make print end= and sep= work 1a6a2dd Remove debug print messages bf490cc builtins: slightly improve print() 833d4da py: string - slightly better implementation of % operator 440aa7c to run the unit tests with python3 as a cross check d831b11 py: string: make getitem and contains work and unit tests d95eafb py: fix Eq and Ne 7bea4c3 Fix errors spotted by go vet 648fc13 parser: fix error on setting someting which can't be set, eg f()=1 927e70d parser: fix reporting of errors and parsing of decimals with leading zeros 60d12b3 parser: implement string escapes 6125042 py: int: Fix neg(IntMin) and round(IntMin) 0e6bb4c py: implement round() for int/long, float() and complex() 2bc7a53 builtin: implement divmod db8950c py: int: tests for *, <<, >> and fixes 313e2cb py: int: fix floor divide to be exactly the same as python 0dce941 py: Implement BigInt to extend Int and tests for it b6756c7 py: fix arithmetic operations code generator and code f863723 Make sys.args accurate and implement -cpuprofile flag 00ffff0 vm: keep locals local (5% speedup) cf0f887 vm: compile debug out with a constant - 180% speed improvement! 4b9bdd5 Change from panic/recover error handling to go style error values 9d45873 vm, builtin, py: locals(), globals() and builtin fixes 4f76837 vm,py: fix generators called after end of code 8e7ded6 py: Fix SetAttr 28b616d pytest: factor python testing framework into own module 71b65b7 py: import - make work better in REPL and look for 4ccf870 repl: very basic REPL cae96e7 vm: implement CALL_FUNCTION, fast locals and make function calling work properly 7f90811 compile: fix kwonlyargs and raise SyntaxError on duplicated keywords e4ed532 py: exception: bodge to return Exception.args 3a20288 py: code: remove extra brackets db28072 py: dict: implement eq and ne b306413 symtable: fix functions with no normal arguments (only args etc) 6a2dcc9 vm: Implement SETUP_WITH and WITH_CLEANUP 1d7e528 compile: fix continue in with block e2cd6ef py: eq and ne for type 07d321a vm: tidy tests 7c07fd2 vm: tests for generators 447496c vm: give opcode its own type 0838829 vm: raise tests 30367ff vm: rename variables to be more like the python original code 87adad3 vm: fix continue 3d425a8 vm: fix exception handling 4865ebf py: ExceptionInfo - check for nil 5a57a8b compile: make SyntaxError on return outside function 19f32cb vm: Tests for STORE_ATTR, LOAD_ATTR, DELETE_ATTR d059504 vm: implement IMPORT_NAME, IMPORT_FROM, IMPORT_STAR; py: factor Attribute code a20d443 vm: implement in, not in; py: changed args to Iterate acaa5df vm: more tests for lists and DELETE_SUBSCR, UNPACK_EX, UNPACK_SEQUENCE etc bb6f44c py: implement DelItem 194e817 py: tuple - Reverse method 3a897b0 py: float and int - check for divide by zero 5a56e32 vm: tests for loops ceed469 vm: remove STORE_LOCALS opcode as it is no longer used 5546ccd py: failing test for IsSubtype 0d4a6d4 vm: tests and fixes for exceptions 5ceac9c compile: more tests on exception handling bf0f523 vm: class definitions 114c283 vm: functions & DELETE_NAME, DELETE_GLOBAL, LOAD_NAME, LOAD_GLOBAL, STORE_DEREF, DELETE_DEREF f570f95 vm: tests for comprehensinos, SET_ADD and MAP_ADD opcodes 7ac88d9 py: dict.setitem and dict.getitem 4a7ad17 py: temporary set.eq and 44242f0 Remove emacs noise and coverage from .gitignore 1305651 vm: start of test suite 0273331 py: fix <<= for int 9402ed8 compile: improve coverage and tidy code 08f7c83 compile: Fix continue and loops in general 3965a79 compile: implement subscript and fix attribute cd8c5fa compile: implement starred assignment e03f367 compile: use c.Exprs where appropriate 5602724 compile: implement Ellipsis 43c7838 py: implement eq and ne for Ellipsis 069f460 compile: implement yield and yield from cc7bc38 symtable: fix yield/yield from to set generator flag 6c151b7 compile: import/from import 8072a76 compile: implement try/except/finally 54e8dcb compile: with statement ebc723a compile: implement comprehensions 3c0ad78 compile: class definitions and module docstrings 8f4bd41 py: code: add eq and ne methods 99c3f74 compile: make decorators for functions work 7686a57 compile: finish lambdas including closures 5a2a35a compile: make closures compile properly 329523c symtable: add Find() method f0cbe48 compile: re-organise code cc59dde Fix uses of Compile e1d9f2c compile: implement return, docstrings, global 0acb046 compile: Fix Varnames c7d19e1 compile: remove disassembly from test data which makes it stable and shorter a0c3930 compile: make a simple function compile f7003ed symtable: remove unused import * checking code 7a5b132 symtable: correct package name and stop panic's escaping the package 21129d0 symtable: make definitions public 08446c2 symtable: fix functions, add classes, lambda, increase coverage efe2b0e ast: Walk - fix ExceptHandler traversal 88dcf55 symtable: fix tests after move 0f4c714 symtable: factor out from compile de6c5dd compile: symtable: implement list/set/dict/generator comprehensions 940b430 compile: symtable: test and fix flags 44e6f63 compile: symtable: global and nonlocal 5d621d0 compiler: fill out symtable machinery 39eaaff compiler: symtable - stringer and fix test f1c2c69 compiler: symbol table framework, plus test machinery 611c8dc ast: Walk - fix null pointer deref and increase test coverage 8eb8664 ast: implement Walk() function 3079681 compile: function definitions without body a39de11 tuple: implement eq and ne ff5d114 compiler: implement call 669e0e4 compile: implement for loop 50cdc44 compler: break, continue and framework for testing exceptions 1cfd200 compile: note that diffs are caused by bugs in python 3.4 6ab7061 lexer: fix whitespace issues 8d5c74e compile: Implement while and if ac9ca13 compiler: del and raise de8f9c5 compiler: assign and augmented assign 54f3149 compiler: pass, expr statement and assert 4826ccc compile: basic lambda: working d0ea27b compile: implement Dict, Set, attribute lookup 532fd9c compile: implement named constant (True, False, None) 6b7f42a py.Bool eq and ne 5f5112a py.None: eq and ne 54f7fe1 compiler: implement tuple and list 9b2aead compile: implement Bytes b881849 py.Bytes: implement comparisons b8b5f4e compiler: implement comparators 67b9193 compiler: Factor instructions into own file and rename some compile methods 363ce43 compile: Fixup panics to have name of thing they are panicing about 0a8e720 compiler: make stack depth calcuations work 853ec56 Fix 3.4 CLASSDEREF opcode definition 3842c62 compiler: Make names work and detect duplicate constants and names d7653f2 compile: Implement if expression and JUMP_FORWARD 6fa5265 compiler: Fix jump resolver 2ece17f compiler: Bool Ops, Labels, N pass assembly, Jump resolution d84b599 compiler: Unary Ops a9c21a1 compiler: basic infrastructure, constants and binops c49e757 Add test machinery for compile 6f1f9b2 Add auto generated y.go and y.output now the code is done (almost) bd6b992 Move grammar test data to its own file 1f41308 Improve coverage f8f4d5e Fix Ctx bf62f09 decorators 8ed83d0 Class definition 6ae1b00 Function definitions 0079df4 Lambda and varargs bad0904 Assign and augmented assign 8858589 With statememt 034315f try / except statememts 79b119d Fix assert statement a27bc28 Implement For and If b685896 Simple statements b3fe9bd Mark unfinished parts f627870 Make Call with arguments work 133ce36 trailers - call and subscript - call not finished 6305d51 Fix Call to have correct Func name f993dc7 Make nil items return as None 216cff9 BinOp, BoolOp and UnaryOp 058dc76 Fix Mod String 302a07f Get rid of uneccessary stacks and clear out yylval each lex 3078552 Generator, List, Set and Dictionary comprehensions 817f25d Add SetCtx and SetCtxer a08810b Ast dump Comprehension structs properly 69f12ff Implement tuple and list in ast - comprehensions still to go bdbd2d0 Fix parsing of Tuple within Set 13b545c Make simple set and dict literals work debd25b Empty dict 1950ac4 Parse numbers 8c9be74 Parse string literals into AST dc76883 Fix String dump 4ab8fc2 Dump Bytes 1d99034 More grammar f23426a Fix Identifier dumping eeaa6ed Add ellipsis 1455b43 Add str for None 3729af3 Implement True aa058f1 Dump py.Objects with str if possible adafadd Implement bool.str a1a397a Fix ast.Dump to output to be the same as Python dc4ddaa Make grammar tests 12ea25a Make testlist work 33659a5 Fix reduce/reduce conflict 571c05c More grammar to ast implementation 9efc2f4 More grammar to ast implementation 378d65e Fix exec mode - add \n on end if not present 41189eb Fix testparser after API changes 0adc14a Fix grammar for multiple entry points for compile mode c2c5db0 ast.Pos updates, and make initial parse work f76b12f Make parser return AST - some small parts working a112b80 Add []Ast to ast.Dump 5084eeb Python AST for gpython a1f34b2 Move to ast package 0bfa031 Make Go AST 77d414e Python.asdl and generator code straight from Python 3.4 4d6ae14 Tests for Lexer 1e62f18 Coverage of parseNumber and parseString 160b692 Fix ambiguity in try/except statement grammar 52f190f Fix ambiguity in FROM x IMPORT y 8dc6b03 Add backslash continuations and make lexer obey yyDebug so it isn't so noisy 4d27ead Implement implicit line joining * Redo indentation count code - better but still not 100% * Detect errors and return an error on Parse acd7411 Add debug-ability to yacc code 431305f Fix dictorsetmaker and testlist_comp 1da31d7 Fix argumentlist parsing 9ad6324 A test script for parsing and lexing ccfbbf6 go generate commands for building grammar 904ca07 Lexer for python 3.4 41a1540 Python 3.4 parser bcab40c Python Grammar file from Python 3.4 8e1e0b2 Update to use compiler from python3.4 a7d0488 Fix build_class so that it passes its locals properly 9524f0b Fix typo in comment f7c7648 Update marshal to v3 protocol from Python 3.4 85cf1cd Remove debugging c6c0fbd Implement ASCII only str.getitem e57a0df Implement chr() 338ca42 Implement COMPARE_OP IS and NOT_IS 3d702be Fix checking of and init arguments 13dc258 Remove debug d58e96a Add compile time option for debug messages 49bcc8f Rudimentary string % operator b686bb2 Implement sys.exit and stdout/stderr/stdin 5f03d50 Basic file object 9a1bb3e Fix ParseTupleAndKeywords 9a3c5db Fix raising an exception in an except block b30f5fb Implement len() and py.Len bffb0f4 Implement int() 1e659f3 Skeleton sys module 0dedea3 Rich comparison for string 732ebed BUILD_SLICE, slice objects and slice indexing for lists and tuple implemented 287a1df Implement STORE_GLOBAL be4d292 Implement + and * for string, list and tuple 21d01bf Implement UNPACK_SEQUENCE e1f060c Set file when importing a module 7f0ea86 Implement parts of time module 63fe344 Implement ParseTuple and "d" option 47c8d26 Implement IMPORT_FROM e906ee1 Redo import e83891d Note on possible improvement a18babf Execute .py files directly 0b3a137 Implement compile() by cheating and calling python3.3 a74eee3 Implement getattr(), hasattr() and setattr() builtins 96bfd77 Remove importlib as too ambitious right now 45034ef Notes on gpython strings 1827c0c Fix Free and Cell variables to make closures work properly 103d54d Fix Code.Cell2Arg creation bb0b4cd Move iteration stuff into sequence.go 6bd194a Implement classmethod() and staticmethod() d625bd9 Implement bytes() constructor f72f347 Make iterate create the iterator itself 2cb6be9 Implement "s" type in ParseTupleAndKeywords fc906f0 Implement string len and bool 7d197e6 Implement list() factoring common parts out of tuple() into SequenceList, SequenceTuple and Iterate. d60fc6f Implement 4eda964 Implement ord() 8cc57c1 Correct calling of init for new objects 13f5466 Make tracebacks work and show something useful cbcda57 Fix function exception message f9b0894 Implement py.DeleteAttr, py.NewStringDictSized and DELETE_ATTR, BUILD_MAP, STORE_MAP opcodes e387540 Notes on type caching 3aadc0b Attributes for Function object 150601a Implementation of properties 22b9afd Rework GetAttr and SetAttr and related parts 611ef13 Loading of frozen module importlib/ 0f6ac1b Make import statement, import builtin and IMPORT_NAME opcode work (a bit) 5511993 Better error reporting in sequence c1949ed Make modules have attributes and call methods in them 858b973 Implement "i" in ParseTupleAndKeywords c1a8582 Turn marshal into a proper module 3770178 Fix parameter order in checkNumberOfArgs 04017d1 Implement BUILD_SET for set literals eg {1,2,3} dd14ce9 Fill out Set interface - preliminary implementation only 5a8a876 Convert Set and FrozenSet into pointer types e1cecbb Implement LIST_APPEND for list comprehensions and speed up BUILD_TUPLE and BUILD_LIST f7bc949 Make List mutable - type is now *List ced6726 Fix go vet warnings 08eff15 Implement closures and LOAD_CLOSURE, LOAD_DEREF, MAKE_CLOSURE opcodes c85199b Raise internal errors properly using panic(ExceptionNewf(Exception, "msg")) ef89736 Implement generator send() and stub out throw() and close() e1f0bbd Make bound methods for built in types work properly 4dedb41 Implement and py.IsException 84c03fa Implement YIELD_FROM and fix YIELD 9c120e6 Make generator protocol interface and adjust generator.go to use it 4a525b9 Make try/except/else/finally exception handling work ca73609 Update comments now have decided how exceptions get propagated 8234f5b Make ExceptionInfo which is Type, Value, Traceback for panic propagation 778850d Make sure exception subclasses have TPFLAGS_BASE_EXC_SUBCLASS set for ExceptionClassCheck 5aeba6f Work on exceptions * Improve internal interfaces for making and using exceptions * Catch and check exceptions in the vm * raise exceptions in the vm * Unwind blocks (more work to do) in the vm 6980c03 Notes on the differences between cpython and gpython 7c4b61a Make NewBool and use it to simplify code f18c29d Define exception heirachy 317101a Make a subclass of a type and implement Fast subclass flags e90b958 Notes on list implementation 4974b6d Notes on strings bc5ac4a Fix LOAD_NAME and remove incorrect workaround 03f02c0 Set name, doc and package in Module 0de7e76 Fix range object to step correctly ee4f980 Fix name lookup in Function object 89966c1 Implement getitem & setitem for List and getitem for Tuple 9e25827 Generators and YIELD_VALUE aa100dc Put the stack in the Frame like cpython in preparation for generators ac76658 Notes on attributes of built in objects 7619a72 Make py.Iter and make FOR_ITER use it b5c3273 Implement range() and object() 2a65fbd Sort out type Init and New so we can make built in objects too! 35eacd5 Implement STORE_ATTR / py.SetAttr 01e2121 Fix object init fc9465a Fix default arguments 40e3f41 Return bound methods on attribute access 9510b77 Implement LOAD_ATTR/py.GetAttr 058a4e2 Implement py.GetItem/BINARY_SUBSCR and optimise some vm stack operations 6fd60a4 Remove unneeded nil check in STORE_LOCALS now build_class is fixed 984bfd8 Fix locals for class constructor call daf467b Fix method calling for TypeCallX 17013ce Implement STORE_SUBSCR and SetItem and first attempt at attribute lookup 3fd76bb Dump the stack on exceptions in eval 9dc3e65 type() much more nearly working 9022860 Implement ParseTupleAndKeywords c8a6976 Make Tuple.Copy() 11d5c5d More implementation of types. Not fully working yet. edfec36 Start of Object operations 6cbdfef Sequence operations b2aa6e4 Fix problems noted by go vet 46bb245 Ignore test files 44ee1c2 Working towards making classes work c305f37 Implement py.None and NoneType 8ad766a Add missing STORE_LOCALS opcode and remove 3.4 LOAD_CLASSDEREF e85f707 Rework python function calling in preparation for polymorphism 60dd952 Make Iter() and Iterator type and implement GET_ITER, FOR_ITER, BUILD_LIST/TUPLE acc6057 Implement BREAK and CONTINUE opcodes c8a27c6 Implement blocks and make while loop work. Fix args > 255 also 36faf9f Implement remaining JUMP opcodes 64c73d3 If statements and rich comparisons e552306 Fix VM so calling functions works properly 3726302 Remove debug 2008d78 Fix CALL_FUNCTION opcode 7e4713c More builtins abs, round and pow plus more infrastructure 44e760e Implement Neg, Pos, Abs, Invert, MakeBool/Int/Float/Complex and Index 8131a31 Add remaining __ methods 110fc8a Implement divmod and pow and check and fix interfaces for int, float, complex c1b8923 More arithmetic operations c8d406d Fix complex type to complex128 6a21724 Auto generate boiler plate for arithmetic operations 55fd328 Implement add and subtract d30fc55 Factor types into own files and rename some 810fccf Fix VM to use stack frames and not to re-instantiate itself a217e4f Ignore all hello 21cd9f2 Cheap and nasty BINARY_ADD, fix LOAD_GLOBAL and 51c26cc Implement STORE_FAST 3f7c1e2 Implement LOAD_GLOBAL 00d856f Fix integer unmarshal and add set & frozenset adbc338 Log error on function call for the moment 98bb655 Use more native types 6b8c802 Impelement LOAD_FAST 6e4d79a Name those opcodes af9a450 Work around circular import - now calls python functions 9a79b97 Notes on future plans b52ac85 Work on getting the python functions running dcccf9b Catch panics from vm 56baf07 Make builtin print sort of work 427419c Add module objects, method objects and a start at builtins 06dc53f Byte code loaded and partly executing 7a05a3c More work on basic types 1c83e6c Fix types and code object 507f2f9 Add illegal instruction as default 0827e7c More python types f65c2cd Tidy output 1f52454 Main gpython binary - slightly working 8ad5ca3 Read .pyc files 92e6a2d Add comparison opcodes 993788c Remove unused opcodes 4c48b1f First commit - work in progress only

    Automated with GoReleaser Built with go version go1.10.1 linux/amd64

    Source code(tar.gz)
    Source code(zip)
    gpython_0.0.0_checksums.txt(1.31 KB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB) MB)
Bridges between Go and Python
Scriptable interpreter written in golang

Anko Anko is a scriptable interpreter written in Go. (Picture licensed under CC BY-SA 3.0, photo by Ocdp) Usage Example - Embedded package main impor

mattn 1.3k Sep 25, 2022
Grumpy is a Python to Go source code transcompiler and runtime.

Grumpy: Go running Python Overview Grumpy is a Python to Go source code transcompiler and runtime that is intended to be a near drop-in replacement fo

Google 10.5k Sep 24, 2022
Go -> Haxe -> JS Java C# C++ C Python Lua

go2hx Compile: Go -> Haxe -> Js, Lua, C#, C++, Java, C, Python warning: heavily experimental still a ways to go before an alpha. Come give feedback on

go2hx 62 Sep 20, 2022
A JavaScript interpreter in Go (golang)

otto -- import "" Package otto is a JavaScript parser and interpreter written natively in Go.

Robert Krimen 6.9k Sep 24, 2022
wagon, a WebAssembly-based Go interpreter, for Go.

wagon wagon is a WebAssembly-based interpreter in Go, for Go. As of 2020/05/11 Wagon is in read-only mode, and looking for a maintainer. You may want

Go Interpreter 900 Aug 6, 2022
Yaegi is Another Elegant Go Interpreter

Yaegi is Another Elegant Go Interpreter. It powers executable Go scripts and plugins, in embedded interpreters or interactive shells, on top of the Go

Traefik Labs 4.9k Sep 24, 2022
Lisp Interpreter

golisp Lisp Interpreter Usage $ golisp < foo.lisp Installation $ go get Features Call Go functions. Print random in

mattn 121 Sep 20, 2022
A simple interpreter

类型: 基础类型: 整形,浮点,字符串,布尔,空值(nil) 符合类型: 数组,只读数组(元组),字典 支持语句: if, elif, else, for, foreach, break, continue, return 支持类型定义: class, func 语法格式: 赋值语句---> ```

null 19 Aug 10, 2022
A Lua 5.3 VM and compiler written in Go.

DCLua - Go Lua Compiler and VM: This is a Lua 5.3 VM and compiler written in Go. This is intended to allow easy embedding into Go programs, with minim

Milo Christiansen 900 Sep 21, 2022
PHP parser written in Go

PHP Parser written in Go This project uses goyacc and ragel tools to create PHP parser. It parses source code into AST. It can be used to write static

Vadym Slizov 891 Sep 9, 2022
High-performance PHP application server, load-balancer and process manager written in Golang

RoadRunner is an open-source (MIT licensed) high-performance PHP application server, load balancer, and process manager. It supports running as a serv

Spiral Scout 6.7k Sep 25, 2022
An interpreted languages written in Go

Monkey My changes 1. Installation Source Installation go <= 1.11 Source installation go >= 1.12 Binary Releases 1.1 Usage 2 Syntax 2.1 Definitions 2.2

Steve Kemp 179 Sep 26, 2022
A compiler for the ReCT programming language written in Golang

ReCT-Go-Compiler A compiler for the ReCT programming language written in Golang

null 6 Aug 20, 2022
Interpreter - The Official Interpreter for the Infant Lang written in Go

Infant Lang Interpreter Infant Lang Minimalistic Less Esoteric Programming Langu

Infant Lang 2 Jan 10, 2022
Scriptable interpreter written in golang

Anko Anko is a scriptable interpreter written in Go. (Picture licensed under CC BY-SA 3.0, photo by Ocdp) Usage Example - Embedded package main impor

mattn 1.3k Sep 25, 2022
Scriptable interpreter written in golang

Anko Anko is a scriptable interpreter written in Go. (Picture licensed under CC BY-SA 3.0, photo by Ocdp) Usage Example - Embedded package main impor

mattn 1.3k Sep 20, 2022
A POSIX-compliant AWK interpreter written in Go

GoAWK: an AWK interpreter written in Go AWK is a fascinating text-processing language, and somehow after reading the delightfully-terse The AWK Progra

Ben Hoyt 1.6k Sep 23, 2022
A BASIC interpreter written in golang.

05 PRINT "Index" 10 PRINT "GOBASIC!" 20 PRINT "Limitations" Arrays Line Numbers IF Statement DATA / READ Statements Builtin Functions Types 30 PRINT "

Steve Kemp 282 Aug 20, 2022
A simple virtual machine - compiler & interpreter - written in golang

go.vm Installation Build without Go Modules (Go before 1.11) Build with Go Modules (Go 1.11 or higher) Usage Opcodes Notes The compiler The interprete

Steve Kemp 241 Sep 23, 2022
Mini lisp interpreter written in Go.

Mini Go Lisp Mini lisp interpreter written in Go. It is implemented with reference to the d-tsuji/SDLisp repository written in Java. Support System Fu

Tsuji Daishiro 16 Nov 25, 2020