github.com/goplus/gox@v1.14.13-0.20240308130321-6ff7f61cfae8/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/gox"
     9  )
    10  
    11  func main() {
    12  	pkg := gox.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(gox.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(gox.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  }