简体   繁体   中英

binary file of the helloworld.go generated by Grumpy does not get generated

I wrote a HelloWorld.py and using grumpy I compiled the HelloWorld.py to a Go source code. but after running go build , the binary file does not get generated, the go build command was executed successfully without any error but there was no binary file found in the folder.

here is the code inside HelloWorld.py:

def hello():
        print("hello, world")

here is the generated code in hello.go:

package __main__

import πg "grumpy/build/src/grumpy"

var Code *πg.Code

func init() {
    Code = πg.NewCode("<module>", "hello.py", nil, 0, func(πF *πg.Frame, _ []*πg.Object) (*πg.Object, *πg.BaseException) {
        var πR *πg.Object; _ = πR
        var πE *πg.BaseException; _ = πE
        ßhello := πg.InternStr("hello")
        var πTemp001 *πg.Object
        _ = πTemp001
        var πTemp002 []πg.Param
        _ = πTemp002
        for ; πF.State() >= 0; πF.PopCheckpoint() {
            switch πF.State() {
            case 0:
            default: panic("unexpected function state")
            }
            // line 1: def hello(): print "hello, world"
            πF.SetLineno(1)
            πTemp002 = make([]πg.Param, 0)
            πTemp001 = πg.NewFunction(πg.NewCode("hello", "hello.py", πTemp002, 0, func(πF *πg.Frame, πArgs []*πg.Object) (*πg.Object, *πg.BaseException) {
                var πTemp001 []*πg.Object
                _ = πTemp001
                var πR *πg.Object; _ = πR
                var πE *πg.BaseException; _ = πE
                for ; πF.State() >= 0; πF.PopCheckpoint() {
                    switch πF.State() {
                    case 0:
                    default: panic("unexpected function state")
                    }
                    // line 1: def hello(): print "hello, world"
                    πF.SetLineno(1)
                    πTemp001 = make([]*πg.Object, 1)
                    πTemp001[0] = πg.NewStr("hello, world").ToObject()
                    if πE = πg.Print(πF, πTemp001, true); πE != nil {
                        continue
                    }
                }
                if πE != nil {
                    πR = nil
                } else if πR == nil {
                    πR = πg.None
                }
                return πR, πE
            }), πF.Globals()).ToObject()
            if πE = πF.Globals().SetItem(πF, ßhello.ToObject(), πTemp001); πE != nil {
                continue
            }
        }
        return nil, πE
    })
    πg.RegisterModule("__main__", Code)
}

when i try to add the main function to the end of the hello.go and call init() like this :

func main() {
    init()
}

i get this error when i run go build

can't load package: package .:  main.go:1:2: expected 'package', found 'EOF'

I know it is an old post but following code in python file may work:

def hello():
        print("hello, world")
if __name__ == "__main__": 
    hello()

Now go will create its own main function and is likely to work. (disclaimer: I have not yet tried this myself).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM