github.com/goplus/gogen@v1.16.0/tutorial/01-Basic/main.go (about) 1 package main 2 3 import ( 4 "go/token" 5 "go/types" 6 "os" 7 8 "github.com/goplus/gogen" 9 ) 10 11 func main() { 12 pkg := gogen.NewPackage("", "main", nil) 13 fmt := pkg.Import("fmt") 14 v := pkg.NewParam(token.NoPos, "v", types.Typ[types.String]) // v string 15 16 pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg). 17 DefineVarStart(token.NoPos, "a", "b").Val("Hi").Val(3).EndInit(2). // a, b := "Hi", 3 18 NewVarStart(nil, "c").VarVal("b").EndInit(1). // var c = b 19 NewVar(gogen.TyEmptyInterface, "x", "y"). // var x, y interface{} 20 Val(fmt.Ref("Println")). 21 /**/ VarVal("a").VarVal("b").VarVal("c"). // fmt.Println(a, b, c) 22 /**/ Call(3).EndStmt(). 23 NewClosure(gogen.NewTuple(v), nil, false).BodyStart(pkg). 24 /**/ Val(fmt.Ref("Println")).Val(v).Call(1).EndStmt(). // fmt.Println(v) 25 /**/ End(). 26 Val("Hello").Call(1).EndStmt(). // func(v string) { ... } ("Hello") 27 End() 28 29 pkg.WriteTo(os.Stdout) 30 }