Skip to content

Instantly share code, notes, and snippets.

@bbengfort

bbengfort/fibpy.go

Last active Mar 22, 2017
Embed
What would you like to do?
Transpiled implementation of a fib.py file.
package main
import (
π___python__Γsys "__python__/sys"
πg "grumpy"
π_os "os"
)
func initModule(πF *πg.Frame, _ []*πg.Object) (*πg.Object, *πg.BaseException) {
ßIndexError := πg.InternStr("IndexError")
ßValueError := πg.InternStr("ValueError")
ß__main__ := πg.InternStr("__main__")
ß__name__ := πg.InternStr("__name__")
ßargv := πg.InternStr("argv")
ßfib := πg.InternStr("fib")
ßidx := πg.InternStr("idx")
ßint := πg.InternStr("int")
ßsys := πg.InternStr("sys")
var πTemp001 *πg.Object
_ = πTemp001
var πTemp002 []*πg.Object
_ = πTemp002
var πTemp003 []πg.Param
_ = πTemp003
var πTemp004 *πg.Object
_ = πTemp004
var πTemp005 *πg.Object
_ = πTemp005
var πTemp006 bool
_ = πTemp006
var πTemp007 *πg.Object
_ = πTemp007
var πTemp008 *πg.Object
_ = πTemp008
var πTemp009 []*πg.Object
_ = πTemp009
var πTemp010 []*πg.Object
_ = πTemp010
var πTemp011 *πg.BaseException
_ = πTemp011
var πTemp012 *πg.Traceback
_ = πTemp012
var πE *πg.BaseException; _ = πE
for ; πF.State() >= 0; πF.PopCheckpoint() {
switch πF.State() {
case 0:
case 4: goto Label4
default: panic("unexpected function state")
}
// line 3: import sys
πF.SetLineno(3)
if πTemp002, πE = πg.ImportModule(πF, "sys", []*πg.Code{π___python__Γsys.Code}); πE != nil {
continue
}
πTemp001 = πTemp002[0]
if πE = πF.Globals().SetItem(πF, ßsys.ToObject(), πTemp001); πE != nil {
continue
}
// line 5: def fib(i):
πF.SetLineno(5)
πTemp003 = make([]πg.Param, 1)
πTemp003[0] = πg.Param{Name: "i", Def: nil}
πTemp001 = πg.NewFunction(πg.NewCode("fib", "fib.py", πTemp003, 0, func(πF *πg.Frame, πArgs []*πg.Object) (*πg.Object, *πg.BaseException) {
var µi *πg.Object = πArgs[0]; _ = µi
var πTemp001 *πg.Object
_ = πTemp001
var πTemp002 bool
_ = πTemp002
var πTemp003 []*πg.Object
_ = πTemp003
var πTemp004 *πg.Object
_ = πTemp004
var πTemp005 *πg.Object
_ = πTemp005
var πTemp006 *πg.Object
_ = πTemp006
var πE *πg.BaseException; _ = πE
for ; πF.State() >= 0; πF.PopCheckpoint() {
switch πF.State() {
case 0:
default: panic("unexpected function state")
}
if πE = πg.CheckLocal(πF, µi, "i"); πE != nil {
continue
}
if πTemp001, πE = πg.LT(πF, µi, πg.NewInt(2).ToObject()); πE != nil {
continue
}
if πTemp002, πE = πg.IsTrue(πF, πTemp001); πE != nil {
continue
}
if πTemp002 {
goto Label1
}
goto Label2
// line 6: if i < 2:
πF.SetLineno(6)
Label1:
// line 7: return 1
πF.SetLineno(7)
return πg.NewInt(1).ToObject(), nil
goto Label2
Label2:
// line 8: return fib(i-1) + fib(i-2)
πF.SetLineno(8)
πTemp003 = πF.MakeArgs(1)
if πE = πg.CheckLocal(πF, µi, "i"); πE != nil {
continue
}
if πTemp004, πE = πg.Sub(πF, µi, πg.NewInt(1).ToObject()); πE != nil {
continue
}
πTemp003[0] = πTemp004
if πTemp004, πE = πg.ResolveGlobal(πF, ßfib); πE != nil {
continue
}
if πTemp005, πE = πTemp004.Call(πF, πTemp003, nil); πE != nil {
continue
}
πF.FreeArgs(πTemp003)
πTemp003 = πF.MakeArgs(1)
if πE = πg.CheckLocal(πF, µi, "i"); πE != nil {
continue
}
if πTemp004, πE = πg.Sub(πF, µi, πg.NewInt(2).ToObject()); πE != nil {
continue
}
πTemp003[0] = πTemp004
if πTemp004, πE = πg.ResolveGlobal(πF, ßfib); πE != nil {
continue
}
if πTemp006, πE = πTemp004.Call(πF, πTemp003, nil); πE != nil {
continue
}
πF.FreeArgs(πTemp003)
if πTemp001, πE = πg.Add(πF, πTemp005, πTemp006); πE != nil {
continue
}
return πTemp001, nil
return nil, nil
}
return nil, πE
}), πF.Globals()).ToObject()
if πE = πF.Globals().SetItem(πF, ßfib.ToObject(), πTemp001); πE != nil {
continue
}
if πTemp005, πE = πg.ResolveGlobal(πF, ß__name__); πE != nil {
continue
}
if πTemp004, πE = πg.Eq(πF, πTemp005, ß__main__.ToObject()); πE != nil {
continue
}
if πTemp006, πE = πg.IsTrue(πF, πTemp004); πE != nil {
continue
}
if πTemp006 {
goto Label1
}
goto Label2
// line 10: if __name__ == '__main__':
πF.SetLineno(10)
Label1:
// line 11: try:
πF.SetLineno(11)
πF.PushCheckpoint(4)
// line 12: idx = sys.argv[1]
πF.SetLineno(12)
πTemp004 = πg.NewInt(1).ToObject()
if πTemp007, πE = πg.ResolveGlobal(πF, ßsys); πE != nil {
continue
}
if πTemp008, πE = πg.GetAttr(πF, πTemp007, ßargv, nil); πE != nil {
continue
}
if πTemp005, πE = πg.GetItem(πF, πTemp008, πTemp004); πE != nil {
continue
}
if πE = πF.Globals().SetItem(πF, ßidx.ToObject(), πTemp005); πE != nil {
continue
}
// line 13: print fib(int(idx))
πF.SetLineno(13)
πTemp002 = make([]*πg.Object, 1)
πTemp009 = πF.MakeArgs(1)
πTemp010 = πF.MakeArgs(1)
if πTemp004, πE = πg.ResolveGlobal(πF, ßidx); πE != nil {
continue
}
πTemp010[0] = πTemp004
if πTemp004, πE = πg.ResolveGlobal(πF, ßint); πE != nil {
continue
}
if πTemp005, πE = πTemp004.Call(πF, πTemp010, nil); πE != nil {
continue
}
πF.FreeArgs(πTemp010)
πTemp009[0] = πTemp005
if πTemp004, πE = πg.ResolveGlobal(πF, ßfib); πE != nil {
continue
}
if πTemp005, πE = πTemp004.Call(πF, πTemp009, nil); πE != nil {
continue
}
πF.FreeArgs(πTemp009)
πTemp002[0] = πTemp005
if πE = πg.Print(πF, πTemp002, true); πE != nil {
continue
}
πF.PopCheckpoint()
goto Label3
Label4:
πTemp011, πTemp012 = πF.ExcInfo()
if πTemp004, πE = πg.ResolveGlobal(πF, ßIndexError); πE != nil {
continue
}
if πTemp006, πE = πg.IsInstance(πF, πTemp011.ToObject(), πTemp004); πE != nil {
continue
}
if πTemp006 {
goto Label5
}
if πTemp004, πE = πg.ResolveGlobal(πF, ßValueError); πE != nil {
continue
}
if πTemp006, πE = πg.IsInstance(πF, πTemp011.ToObject(), πTemp004); πE != nil {
continue
}
if πTemp006 {
goto Label6
}
πE = πF.Raise(πTemp011.ToObject(), nil, πTemp012.ToObject())
continue
// line 14: except IndexError:
πF.SetLineno(14)
Label5:
// line 15: print "please specify a fibonacci index"
πF.SetLineno(15)
πTemp002 = make([]*πg.Object, 1)
πTemp002[0] = πg.NewStr("please specify a fibonacci index").ToObject()
if πE = πg.Print(πF, πTemp002, true); πE != nil {
continue
}
πE = nil
πF.RestoreExc(nil, nil)
goto Label3
// line 16: except ValueError:
πF.SetLineno(16)
Label6:
// line 17: print "please specify an integer"
πF.SetLineno(17)
πTemp002 = make([]*πg.Object, 1)
πTemp002[0] = πg.NewStr("please specify an integer").ToObject()
if πE = πg.Print(πF, πTemp002, true); πE != nil {
continue
}
πE = nil
πF.RestoreExc(nil, nil)
goto Label3
Label3:
goto Label2
Label2:
return nil, nil
}
return nil, πE
}
var Code *πg.Code
func main() {
Code = πg.NewCode("<module>", "fib.py", nil, 0, initModule)
π_os.Exit(πg.RunMain(Code))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment