Closed phillvancejr closed 5 years ago
I was able to successfully run the hello.go file and the hello exe by making changes to the hello.go file generated by grumpc.
The hello.go file generated by grumpc was:
package __main__
import (
πg "grumpy"
)
var Code *πg.Code
func init() {
Code = πg.NewCode("<module>", "/Users/phill.vance/go/src/grumpy/grumpy-runtime-src/build/src/test/hello.py", nil, 0, func(πF *πg.Frame, _ []*πg.Object) (*πg.Object, *πg.BaseException) {
var πR *πg.Object; _ = πR
var πE *πg.BaseException; _ = πE
ß__doc__ := πg.InternStr("__doc__")
var πTemp001 []*πg.Object
_ = πTemp001
for ; πF.State() >= 0; πF.PopCheckpoint() {
switch πF.State() {
case 0:
default: panic("unexpected function state")
}
// line 2: print "hello from Grumpy!"
πF.SetLineno(2)
πTemp001 = make([]*πg.Object, 1)
// line 2: print "hello from Grumpy!"
πF.SetLineno(2)
if πE = πF.Globals().SetItem(πF, ß__doc__.ToObject(), πg.NewStr("hello from Grumpy!").ToObject()); πE != nil {
continue
}
πTemp001[0] = πg.NewStr("hello from Grumpy!").ToObject()
if πE = πg.Print(πF, πTemp001, true); πE != nil {
continue
}
}
return nil, πE
})
πg.RegisterModule("__main__", Code)
}
I changed the package name to main then added a main function with the following code:
func main() {
πg.RunMain(Code)
}
hello.go is now:
package main
import (
πg "grumpy"
)
var Code *πg.Code
func init() {
Code = πg.NewCode("<module>", "/Users/phill.vance/go/src/grumpy/grumpy-runtime-src/build/src/test/hello.py", nil, 0, func(πF *πg.Frame, _ []*πg.Object) (*πg.Object, *πg.BaseException) {
var πR *πg.Object
_ = πR
var πE *πg.BaseException
_ = πE
ß__doc__ := πg.InternStr("__doc__")
var πTemp001 []*πg.Object
_ = πTemp001
for ; πF.State() >= 0; πF.PopCheckpoint() {
switch πF.State() {
case 0:
default:
panic("unexpected function state")
}
// line 2: print "hello from Grumpy!"
πF.SetLineno(2)
πTemp001 = make([]*πg.Object, 1)
// line 2: print "hello from Grumpy!"
πF.SetLineno(2)
if πE = πF.Globals().SetItem(πF, ß__doc__.ToObject(), πg.NewStr("hello from Grumpy!").ToObject()); πE != nil {
continue
}
πTemp001[0] = πg.NewStr("hello from Grumpy!").ToObject()
if πE = πg.Print(πF, πTemp001, true); πE != nil {
continue
}
}
return nil, πE
})
πg.RegisterModule("__main__", Code)
}
func main() {
πg.RunMain(Code)
}
This code now runs both via go run and after building a binary with go build. It seems that this should be the output of grumpc. Is there a flag or option that I am missing that enables code for use as a main file as opposed to what I assume is a module in the default grumpc generation?
I have a simple python file hello.py:
I can run it with python, and with grumpy run. But when I transpile it into a go file using:
I cannot run hello.go with go run. I get the error:
I noticed that the go file has the package main like python. It also has no main function, only an init function, so I guess this only transpiles for modules?
I build it with:
When I try to run hello I get permission denied. If I chmod +x the file and then run, I get the following error:
How can I convert this python code into go code that I can compile into a binary? Thanks for any help
I'm on macOS High Sierra 10.13 My grumpy project is located in my normal gopath src directory -> /Users/phill.vance/go/src/grumpy