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

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

Community

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.

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.

Owner
go-python
Bridges between Go and Python
go-python
Comments
  • 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/utils.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 os.test.py, a file which you can run with gpython to check if the OS module is working properly.

    Thanks!

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

  • 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/

  • 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!

  • 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:

    • https://docs.python.org/3/library/functions.html#all
    • https://docs.python.org/3/library/functions.html#any

    Fixes: https://github.com/go-python/gpython/issues/14

  • 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/test.py":

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

    Before:

    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'
    

    After

    Exception 
      File "/Users/jpoole/gpython/test.py", line 10, offset 0
        
    
    SyntaxError: 'unexpected EOF while parsing'
    -- No traceback available --
    
    
  • 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
    
  • 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
    {1}
    >>> a ^ b
    {1, 4, 5}
    >>>
    
  • SyntaxError of global declaration don't stop program

    SyntaxError of global declaration don't stop program

    a = 3
    global a
    print(a)
    
    b = 2 + 5
    print(b)
    

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

    Expected Result

    Hyeockz:bin hyeockjinkim$ python3 g.py 
      File "g.py", 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
    3
    7
    

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

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

  • How would i go about writing a new module?

    How would i go about writing a new module?

    Hi

    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!

  • How to get `globals()` inside Go bounded method?

    How to get `globals()` inside Go bounded method?

    Simple description

    I cannot find a way to access globals() within a bounded method in GoLang.

    I expose a type into module, like moduleImpl.Globals["Foo"] = FooType, and add methods to FooType by FooType.Globals["bar"] = MustNewMethod(..., someGoMethod, ...).

    I cannot access module's global variables inside someGoMethod.

    Why I need this feature

    I just attach different zap.Logger to multiple py.Contexts. I attach logger as a module's global variable, by using

    ctx.GetModule("name").Globals["logger"] = &pyLoggerObject{logger}
    

    but I cannot find a way to use this logger inside bounded methods.


    I found I can create a py.Type and attach the type to module global dynamically. I can somehow read module globals by this trick. But Is there a elegant way to archive that?

    m = ctx.GetModule("module")
    m.Globals["Foo"] = NewFooType(m)
    
  • Compiling long operations crashes gpython

    Compiling long operations crashes gpython

    Taking long operations as argument of compiler() leads that pointer gets access to unused region crashing gpython

    test.py compile('1'+'<2'*100000000,'','exec')

    Output on go/wasm(https://gpython.org/?wasm):

    Gpython 3.4.0 running in your browser with go/wasm
    >>> compile('1'+'<2'*100000000,'','exec')
    runtime: pointer 0x1e8b0000 to unused region of span span.base()=0xc538000 span.limit=0x183f4200 span.state=1
    fatal error: found bad pointer in Go heap (incorrect use of unsafe or cgo?)
    runtime stack:
    runtime.throw(0x71c31, 0x3e)
        /opt/go/go1.11/src/runtime/panic.go:608 +0x6 fp=0x36a280 sp=0x36a258 pc=0x11c60006
    runtime.findObject(0x1e8b0000, 0x0, 0x0, 0x0, 0x0, 0x0)
        /opt/go/go1.11/src/runtime/mbitmap.go:399 +0x42 fp=0x36a2c8 sp=0x36a280 pc=0x10f50042
    runtime.wbBufFlush1(0xc010000)
        /opt/go/go1.11/src/runtime/mwbbuf.go:252 +0x16 fp=0x36a348 sp=0x36a2c8 pc=0x11a90016
    runtime.gcMarkDone.func1.1(0xc010000)
        /opt/go/go1.11/src/runtime/mgc.go:1449 +0x2 fp=0x36a358 sp=0x36a348 pc=0x13290002
    runtime.forEachP(0x7aa20)
        /opt/go/go1.11/src/runtime/proc.go:1452 +0x25 fp=0x36a3c0 sp=0x36a358 pc=0x12090025
    runtime.gcMarkDone.func1()
        /opt/go/go1.11/src/runtime/mgc.go:1448 +0x2 fp=0x36a3d0 sp=0x36a3c0 pc=0x132a0002
    runtime.systemstack(0x36a410)
        /opt/go/go1.11/src/runtime/asm_wasm.s:171 +0x2 fp=0x36a3d8 sp=0x36a3d0 pc=0x13590002
    runtime.mstart()
        /opt/go/go1.11/src/runtime/proc.go:1229 fp=0x36a3e0 sp=0x36a3d8 pc=0x12050000
    goroutine 5 [running]:
    runtime.systemstack_switch()
        /opt/go/go1.11/src/runtime/asm_wasm.s:182 fp=0xc07b6e8 sp=0xc07b6e0 pc=0x135a0000
    runtime.gcMarkDone()
        /opt/go/go1.11/src/runtime/mgc.go:1442 +0xc fp=0xc07b710 sp=0xc07b6e8 pc=0x1127000c
    runtime.gcAssistAlloc(0xc000780)
        /opt/go/go1.11/src/runtime/mgcmark.go:476 +0x23 fp=0xc07b770 sp=0xc07b710 pc=0x11410023
    runtime.mallocgc(0xbebc201, 0x0, 0x2c979d00, 0x13380002)
        /opt/go/go1.11/src/runtime/malloc.go:807 +0x9b fp=0xc07b818 sp=0xc07b770 pc=0x10b2009b
    runtime.rawstring(0xbebc201, 0x0, 0x0, 0x0, 0x0, 0x0)
        /opt/go/go1.11/src/runtime/string.go:258 +0x2 fp=0xc07b840 sp=0xc07b818 pc=0x129e0002
    runtime.rawstringtmp(0x0, 0xbebc201, 0x19a30001, 0x328040, 0x130f0002, 0x5a020, 0xde40)
        /opt/go/go1.11/src/runtime/string.go:123 +0x7 fp=0xc07b878 sp=0xc07b840 pc=0x12990007
    runtime.concatstrings(0x0, 0xc07b950, 0x2, 0x2, 0x20de3, 0x3d120)
        /opt/go/go1.11/src/runtime/string.go:49 +0x11 fp=0xc07b910 sp=0xc07b878 pc=0x12930011
    runtime.concatstring2(0x0, 0x3262d1, 0x1, 0xc538000, 0xbebc200, 0x366168, 0x0)
        /opt/go/go1.11/src/runtime/string.go:58 +0x2 fp=0xc07b948 sp=0xc07b910 pc=0x12940002
    github.com/go-python/gpython/py.String.M__add__(0x3262d1, 0x1, 0x9d740, 0xc00e010, 0x3d120, 0x5a020, 0x1, 0x2c9345a0)
        /home/ncw/go/src/github.com/go-python/gpython/py/string.go:135 +0x5 fp=0xc07b998 sp=0xc07b948 pc=0x1d160005
    github.com/go-python/gpython/py.(*String).M__add__(0xc00f960, 0x9d740, 0xc00e010, 0x2c9345a0, 0xc00f960, 0x1, 0x0)
        <autogenerated>:1 +0x3 fp=0xc07b9e0 sp=0xc07b998 pc=0x1e8b0003
    github.com/go-python/gpython/py.Add(0x9d740, 0xc00f960, 0x9d740, 0xc00e010, 0x9d740, 0xc00e010, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/py/arithmetic.go:174 +0x1d fp=0xc07ba70 sp=0xc07b9e0 pc=0x1b3e001d
    github.com/go-python/gpython/vm.do_BINARY_ADD(0xc074930, 0x2, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:277 +0xc fp=0xc07bac0 sp=0xc07ba70 pc=0x214e000c
    github.com/go-python/gpython/vm.RunFrame(0xc0de0b0, 0x0, 0xc07bd18, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:1785 +0x3f fp=0xc07bba0 sp=0xc07bac0 pc=0x21ad003f
    github.com/go-python/gpython/vm.EvalCodeEx(0xc04c200, 0xc062db0, 0xc062db0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:2162 +0xa3 fp=0xc07bd80 sp=0xc07bba0 pc=0x21b100a3
    github.com/go-python/gpython/vm.Run(0xc062db0, 0xc062db0, 0xc04c200, 0x0, 0x0, 0x0, 0x0, 0x1, 0x9d240, 0xc04c200)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:2182 +0x2 fp=0xc07be18 sp=0xc07bd80 pc=0x21b30002
    github.com/go-python/gpython/repl.(*REPL).Run(0xc09a6c0, 0xc038330, 0x25)
        /home/ncw/go/src/github.com/go-python/gpython/repl/repl.go:99 +0x20 fp=0xc07bf28 sp=0xc07be18 pc=0x229f0020
    main.main.func1(0xc01e3f0, 0x2, 0x2)
        /home/ncw/go/src/github.com/go-python/gpython/repl/web/main.go:82 +0x4 fp=0xc07bf50 sp=0xc07bf28 pc=0x22db0004
    syscall/js.callbackLoop()
        /opt/go/go1.11/src/syscall/js/callback.go:116 +0x7 fp=0xc07bfe0 sp=0xc07bf50 pc=0x14dd0007
    runtime.goexit()
        /opt/go/go1.11/src/runtime/asm_wasm.s:425 +0x1 fp=0xc07bfe8 sp=0xc07bfe0 pc=0x13800001
    created by syscall/js.NewCallback.func1
        /opt/go/go1.11/src/syscall/js/callback.go:40 +0x2
    goroutine 1 [select (no cases)]:
    runtime.gopark(0x0, 0x0, 0x6100a, 0x1)
        /opt/go/go1.11/src/runtime/proc.go:302 +0x18 fp=0xc05ae98 sp=0xc05ae70 pc=0x11e30018
    runtime.block()
        /opt/go/go1.11/src/runtime/select.go:102 +0x2 fp=0xc05aec0 sp=0xc05ae98 pc=0x126a0002
    main.main()
        /home/ncw/go/src/github.com/go-python/gpython/repl/web/main.go:100 +0x34 fp=0xc05afa0 sp=0xc05aec0 pc=0x22da0034
    runtime.main()
        /opt/go/go1.11/src/runtime/proc.go:201 +0x1f fp=0xc05afe0 sp=0xc05afa0 pc=0x11de001f
    runtime.goexit()
        /opt/go/go1.11/src/runtime/asm_wasm.s:425 +0x1 fp=0xc05afe8 sp=0xc05afe0 pc=0x13800001
    goroutine 2 [force gc (idle)]:
    runtime.gopark(0x7ab30, 0x34ac00, 0x1410, 0x1)
        /opt/go/go1.11/src/runtime/proc.go:302 +0x18 fp=0xc024f90 sp=0xc024f68 pc=0x11e30018
    runtime.goparkunlock(0x34ac00, 0x1410, 0x1)
        /opt/go/go1.11/src/runtime/proc.go:308 +0x2 fp=0xc024fb8 sp=0xc024f90 pc=0x11e40002
    runtime.forcegchelper()
        /opt/go/go1.11/src/runtime/proc.go:251 +0xb fp=0xc024fe0 sp=0xc024fb8 pc=0x11e1000b
    runtime.goexit()
        /opt/go/go1.11/src/runtime/asm_wasm.s:425 +0x1 fp=0xc024fe8 sp=0xc024fe0 pc=0x13800001
    created by runtime.init.3
        /opt/go/go1.11/src/runtime/proc.go:240 +0x2
    goroutine 3 [runnable]:
    runtime.Gosched()
        /opt/go/go1.11/src/runtime/proc.go:267 +0x3 fp=0xc0257b8 sp=0xc0257a8 pc=0x11e20003
    runtime.bgsweep(0xc02c000)
        /opt/go/go1.11/src/runtime/mgcsweep.go:57 +0x8 fp=0xc0257d8 sp=0xc0257b8 pc=0x11540008
    runtime.goexit()
        /opt/go/go1.11/src/runtime/asm_wasm.s:425 +0x1 fp=0xc0257e0 sp=0xc0257d8 pc=0x13800001
    created by runtime.gcenable
        /opt/go/go1.11/src/runtime/mgc.go:216 +0x3
    goroutine 4 [finalizer wait]:
    runtime.gopark(0x7ab30, 0x366158, 0x140f, 0x1)
        /opt/go/go1.11/src/runtime/proc.go:302 +0x18 fp=0xc025f30 sp=0xc025f08 pc=0x11e30018
    runtime.goparkunlock(0x366158, 0x140f, 0x1)
        /opt/go/go1.11/src/runtime/proc.go:308 +0x2 fp=0xc025f58 sp=0xc025f30 pc=0x11e40002
    runtime.runfinq()
        /opt/go/go1.11/src/runtime/mfinal.go:175 +0x7 fp=0xc025fe0 sp=0xc025f58 pc=0x11140007
    runtime.goexit()
        /opt/go/go1.11/src/runtime/asm_wasm.s:425 +0x1 fp=0xc025fe8 sp=0xc025fe0 pc=0x13800001
    created by runtime.createfing
        /opt/go/go1.11/src/runtime/mfinal.go:156 +0x8
    goroutine 6 [GC worker (idle)]:
    runtime.gopark(0x7aa10, 0xc01e500, 0xffff1417, 0x0)
        /opt/go/go1.11/src/runtime/proc.go:302 +0x18 fp=0xc024760 sp=0xc024738 pc=0x11e30018
    runtime.gcBgMarkWorker(0xc010000)
        /opt/go/go1.11/src/runtime/mgc.go:1772 +0x12 fp=0xc0247d8 sp=0xc024760 pc=0x112a0012
    runtime.goexit()
        /opt/go/go1.11/src/runtime/asm_wasm.s:425 +0x1 fp=0xc0247e0 sp=0xc0247d8 pc=0x13800001
    created by runtime.gcBgMarkStartWorkers
        /opt/go/go1.11/src/runtime/mgc.go:1720 +0xc
    
  • Taking large arguments in functions crashes gpython

    Taking large arguments in functions crashes gpython

    The following example takes large arguments and then crashes gpython.

    test.py

    def f(*args, **kwargs):
        return (len(args), len(kwargs))
    f(*[0] * (2 ** 32 + 1))
    

    Output on go/wasm(https://gpython.org/?wasm):

    Gpython 3.4.0 running in your browser with gopherjs
    >>> def f(*args, **kwargs):
    ...     return (len(args), len(kwargs))
    ... 
    >>> f(*[0] * (2 ** 32 + 1))
    [USER]: https://gpython.org/gpython.js: runtime error: invalid memory address or nil pointer dereference
    $callDeferred@https://gpython.org/gpython.js:4:22511
    $panic@https://gpython.org/gpython.js:4:22957
    AK@https://gpython.org/gpython.js:10:2429
    $throwNilPointerError@https://gpython.org/gpython.js:4:504
    get@https://gpython.org/gpython.js:4:4514
    BL.ptr.prototype.Exp@https://gpython.org/gpython.js:38:95685
    BH.ptr.prototype.pow@https://gpython.org/gpython.js:41:102703
    BH.ptr.prototype.M__pow__@https://gpython.org/gpython.js:41:103772
    EQ.prototype.M__pow__@https://gpython.org/gpython.js:41:236439
    AZ@https://gpython.org/gpython.js:41:73603
    V@https://gpython.org/gpython.js:44:18787
    DO@https://gpython.org/gpython.js:44:91592
    DU@https://gpython.org/gpython.js:44:107450
    DW@https://gpython.org/gpython.js:44:109015
    G.ptr.prototype.Run@https://gpython.org/gpython.js:56:3575
    $b@https://gpython.org/gpython.js:60:3908
    $b@https://gpython.org/gpython.js:59:2625
    r@https://gpython.org/gpython.js:4:23443
    $runScheduled@https://gpython.org/gpython.js:4:24007
    $schedule@https://gpython.org/gpython.js:4:24184
    $go@https://gpython.org/gpython.js:4:23907
    I/$packages["github.com/gopherjs/gopherwasm/js"]<@https://gpython.org/gpython.js:59:2240
    $externalizeFunction/e.$externalizeWrapper@https://gpython.org/gpython.js:4:28925
    a@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:82615
    k@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:83463
    ENTER@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:14915
    $e@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:28362
    dispatch@https://code.jquery.com/jquery-latest.js:4641:9
    add/elemData.handle@https://code.jquery.com/jquery-latest.js:4309:28
    

    output with gopherjs(https://gpython.org/):

    Gpython 3.4.0 running in your browser with go/wasm
    >>> def f(*args, **kwargs): return (len(args), len(kwargs))
    >>> f(*[0] * (2 ** 32 + 1))
    panic: runtime error: makeslice: len out of range
    goroutine 5 [running]:
    github.com/go-python/gpython/py.NewListSized(...)
        /home/ncw/go/src/github.com/go-python/gpython/py/list.go:52
    github.com/go-python/gpython/py.(*List).M__mul__(0xc05eba0, 0x9d6e0, 0xc01e568, 0x2c931ef0, 0xc05eba0, 0x1, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/py/list.go:239 +0x13
    github.com/go-python/gpython/py.Mul(0x9d340, 0xc05eba0, 0x9d6e0, 0xc01e568, 0x9d6e0, 0xc01e568, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/py/arithmetic.go:262 +0x1d
    github.com/go-python/gpython/vm.do_BINARY_MULTIPLY(0xc074930, 0x3, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:248 +0xc
    github.com/go-python/gpython/vm.RunFrame(0xc0a4370, 0x0, 0xc07bd18, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:1785 +0x3f
    github.com/go-python/gpython/vm.EvalCodeEx(0xc04c400, 0xc062db0, 0xc062db0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:2162 +0xa3
    github.com/go-python/gpython/vm.Run(0xc062db0, 0xc062db0, 0xc04c400, 0x0, 0x0, 0x0, 0x0, 0x1, 0x9d240, 0xc04c400)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:2182 +0x2
    github.com/go-python/gpython/repl.(*REPL).Run(0xc09a6c0, 0xc04a660, 0x17)
        /home/ncw/go/src/github.com/go-python/gpython/repl/repl.go:99 +0x20
    main.main.func1(0xc01e450, 0x2, 0x2)
        /home/ncw/go/src/github.com/go-python/gpython/repl/web/main.go:82 +0x4
    syscall/js.callbackLoop()
        /opt/go/go1.11/src/syscall/js/callback.go:116 +0x7
    created by syscall/js.NewCallback.func1
        /opt/go/go1.11/src/syscall/js/callback.go:40 +0x2
    
  • transforming generators into list trigger crashing

    transforming generators into list trigger crashing

    In the following example, we initialize a 'population' with a list then we define a generator 'gen'. When we transform the generator into list, it crashes gpython with message "panic: runtime error: makeslice: len out of range".

    test.py

    population = list(range(10))
    gen = (-1 * population for w in range(10))
    list(gen)
    

    Output on go/wasm(https://gpython.org/?wasm):

    Gpython 3.4.0 running in your browser with go/wasm
    >>> population = list(range(10))
    >>> gen = (-1 * population for w in range(10))
    >>> list(gen)
    panic: runtime error: makeslice: len out of range
    goroutine 5 [running]:
    github.com/go-python/gpython/py.NewListSized(...)
        /home/ncw/go/src/github.com/go-python/gpython/py/list.go:52
    github.com/go-python/gpython/py.(*List).M__mul__(0xc05ea40, 0x9d6e0, 0xc01e660, 0x3eca0, 0x59a80, 0xffffffffffffff01, 0x2c932218)
        /home/ncw/go/src/github.com/go-python/gpython/py/list.go:239 +0x13
    github.com/go-python/gpython/py.(*List).M__rmul__(0xc05ea40, 0x9d6e0, 0xc01e660, 0x2c932218, 0xc05ea40, 0x1, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/py/list.go:249 +0x2
    github.com/go-python/gpython/py.Mul(0x9d6e0, 0xc01e660, 0x9d340, 0xc05ea40, 0xc0de420, 0xc01e660, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/py/arithmetic.go:274 +0x14
    github.com/go-python/gpython/vm.do_BINARY_MULTIPLY(0xc074a10, 0x0, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:248 +0xc
    github.com/go-python/gpython/vm.RunFrame(0xc0de420, 0x4a408, 0x4a3f8, 0x10860032, 0x366168)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:1785 +0x3f
    github.com/go-python/gpython/py.(*Generator).Send(0xc0632f0, 0x9d720, 0x3661e8, 0x3e720, 0x4a3c0, 0x1, 0x2c9321b8)
        /home/ncw/go/src/github.com/go-python/gpython/py/generator.go:100 +0xb
    github.com/go-python/gpython/py.(*Generator).M__next__(0xc0632f0, 0x9d300, 0xc0632f0, 0x2c9321b8, 0xc0632f0)
        /home/ncw/go/src/github.com/go-python/gpython/py/generator.go:71 +0x2
    

    output with gopherjs(https://gpython.org/):

    [USER]: https://gpython.org/gpython.js: runtime error: makeslice: len out of range
    $callDeferred@https://gpython.org/gpython.js:4:22511
    $panic@https://gpython.org/gpython.js:4:22957
    AK@https://gpython.org/gpython.js:10:2429
    $makeSlice@https://gpython.org/gpython.js:4:20053
    GF@https://gpython.org/gpython.js:41:276509
    GB.ptr.prototype.M__mul__@https://gpython.org/gpython.js:41:286563
    GB.ptr.prototype.M__rmul__@https://gpython.org/gpython.js:41:286854
    AG@https://gpython.org/gpython.js:41:47063
    W@https://gpython.org/gpython.js:44:19407
    DO@https://gpython.org/gpython.js:44:91592
    EJ.ptr.prototype.Send@https://gpython.org/gpython.js:41:212721
    EJ.ptr.prototype.M__next__@https://gpython.org/gpython.js:41:211418
    LD@https://gpython.org/gpython.js:41:316574
    LE@https://gpython.org/gpython.js:41:319732
    GB.ptr.prototype.ExtendSequence@https://gpython.org/gpython.js:41:277441
    LC@https://gpython.org/gpython.js:41:315768
    GC@https://gpython.org/gpython.js:41:276033
    MH.ptr.prototype.M__call__@https://gpython.org/gpython.js:41:366934
    FK@https://gpython.org/gpython.js:41:255589
    DN@https://gpython.org/gpython.js:44:82459
    EE.ptr.prototype.Call@https://gpython.org/gpython.js:44:87109
    DC@https://gpython.org/gpython.js:44:77098
    DO@https://gpython.org/gpython.js:44:91592
    DU@https://gpython.org/gpython.js:44:107450
    DW@https://gpython.org/gpython.js:44:109015
    G.ptr.prototype.Run@https://gpython.org/gpython.js:56:3575
    $b@https://gpython.org/gpython.js:60:3908
    $b@https://gpython.org/gpython.js:59:2625
    r@https://gpython.org/gpython.js:4:23443
    $runScheduled@https://gpython.org/gpython.js:4:24007
    $schedule@https://gpython.org/gpython.js:4:24184
    $go@https://gpython.org/gpython.js:4:23907
    I/$packages["github.com/gopherjs/gopherwasm/js"]<@https://gpython.org/gpython.js:59:2240
    $externalizeFunction/e.$externalizeWrapper@https://gpython.org/gpython.js:4:28925
    a@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:82615
    k@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:83463
    ENTER@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:14915
    $e@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:28362
    dispatch@https://code.jquery.com/jquery-latest.js:4641:9
    add/elemData.handle@https://code.jquery.com/jquery-latest.js:4309:28
    
  • Defining Nested set crashes gpython

    Defining Nested set crashes gpython

    In gpython, if we define a nested set, it will lead to crashing. s = {('string', 1), ('string', 2), ('string', 3)}

    Output on go/wasm(https://gpython.org/?wasm):

    Gpython 3.4.0 running in your browser with go/wasm
    >>> s = {('string', 1), ('string', 2), ('string', 3)}
    panic: runtime error: hash of unhashable type py.Tuple
    goroutine 5 [running]:
    github.com/go-python/gpython/py.NewSetFromItems(0xc09a880, 0x3, 0x4, 0x2)
        /home/ncw/go/src/github.com/go-python/gpython/py/set.go:42 +0xc
    github.com/go-python/gpython/vm.do_BUILD_SET(0xc074770, 0x3, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:996 +0x5
    github.com/go-python/gpython/vm.RunFrame(0xc0de0b0, 0x0, 0xc07bd18, 0x0, 0x0)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:1785 +0x3f
    github.com/go-python/gpython/vm.EvalCodeEx(0xc04c200, 0xc062db0, 0xc062db0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:2162 +0xa3
    github.com/go-python/gpython/vm.Run(0xc062db0, 0xc062db0, 0xc04c200, 0x0, 0x0, 0x0, 0x0, 0x1, 0x9d240, 0xc04c200)
        /home/ncw/go/src/github.com/go-python/gpython/vm/eval.go:2182 +0x2
    github.com/go-python/gpython/repl.(*REPL).Run(0xc09a6c0, 0xc09c080, 0x31)
        /home/ncw/go/src/github.com/go-python/gpython/repl/repl.go:99 +0x20
    main.main.func1(0xc01e3f0, 0x2, 0x2)
        /home/ncw/go/src/github.com/go-python/gpython/repl/web/main.go:82 +0x4
    syscall/js.callbackLoop()
        /opt/go/go1.11/src/syscall/js/callback.go:116 +0x7
    created by syscall/js.NewCallback.func1
        /opt/go/go1.11/src/syscall/js/callback.go:40 +0x2
    

    output with gopherjs(https://gpython.org/):

    Gpython 3.4.0 running in your browser with gopherjs
    >>> s = {('string', 1), ('string', 2), ('string', 3)}
    [USER]: https://gpython.org/gpython.js: n.keyFor is not a function
    $ifaceKeyFor@https://gpython.org/gpython.js:4:9630
    LL@https://gpython.org/gpython.js:41:324569
    BY@https://gpython.org/gpython.js:44:56407
    DO@https://gpython.org/gpython.js:44:91592
    DU@https://gpython.org/gpython.js:44:107450
    DW@https://gpython.org/gpython.js:44:109015
    G.ptr.prototype.Run@https://gpython.org/gpython.js:56:3575
    $b@https://gpython.org/gpython.js:60:3908
    $b@https://gpython.org/gpython.js:59:2625
    r@https://gpython.org/gpython.js:4:23443
    $runScheduled@https://gpython.org/gpython.js:4:24007
    $schedule@https://gpython.org/gpython.js:4:24184
    $go@https://gpython.org/gpython.js:4:23907
    I/$packages["github.com/gopherjs/gopherwasm/js"]<@https://gpython.org/gpython.js:59:2240
    $externalizeFunction/e.$externalizeWrapper@https://gpython.org/gpython.js:4:28925
    a@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:82615
    k@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:83463
    ENTER@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:14915
    $e@https://cdnjs.cloudflare.com/ajax/libs/jquery.terminal/1.23.2/js/jquery.terminal.min.js:40:28362
    dispatch@https://code.jquery.com/jquery-latest.js:4641:9
    add/elemData.handle@https://code.jquery.com/jquery-latest.js:4309:28
    
Scriptable interpreter written in golang
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

Dec 23, 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

Jan 7, 2023
Go -> Haxe -> JS Java C# C++ C Python Lua
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

Dec 14, 2022
A JavaScript interpreter in Go (golang)

otto -- import "github.com/robertkrimen/otto" Package otto is a JavaScript parser and interpreter written natively in Go. http://godoc.org/github.com/

Jan 2, 2023
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

Dec 6, 2022
Yaegi is Another Elegant Go Interpreter
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

Jan 5, 2023
Lisp Interpreter

golisp Lisp Interpreter Usage $ golisp < foo.lisp Installation $ go get github.com/mattn/golisp/cmd/golisp Features Call Go functions. Print random in

Dec 15, 2022
A simple interpreter

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

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

Dec 12, 2022
PHP parser written in Go
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

Dec 25, 2022
High-performance PHP application server, load-balancer and process manager written in Golang
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

Dec 30, 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

Jan 8, 2023
A compiler for the ReCT programming language written in Golang

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

Nov 30, 2022
Interpreter - The Official Interpreter for the Infant Lang written in Go

Infant Lang Interpreter Infant Lang Minimalistic Less Esoteric Programming Langu

Jan 10, 2022
Scriptable interpreter written in golang
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

Jan 1, 2023
Scriptable interpreter written in golang
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

Dec 23, 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

Dec 31, 2022
A BASIC interpreter written in golang.
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 "

Dec 24, 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

Dec 17, 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

Nov 25, 2022