Skip to content

Commit

Permalink
Merge pull request #402 from xushiwei/gogen
Browse files Browse the repository at this point in the history
gox => gogen
  • Loading branch information
xushiwei authored Mar 8, 2024
2 parents 6ff7f61 + 7f2b2da commit 010bb4b
Show file tree
Hide file tree
Showing 31 changed files with 509 additions and 509 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
gox - Code generator for the Go language
gogen - Code generator for the Go language
========

[![Build Status](https://github.com/goplus/gox/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/gox/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/goplus/gox)](https://goreportcard.com/report/github.com/goplus/gox)
[![GitHub release](https://img.shields.io/github/v/tag/goplus/gox.svg?label=release)](https://github.com/goplus/gox/releases)
[![Coverage Status](https://codecov.io/gh/goplus/gox/branch/main/graph/badge.svg)](https://codecov.io/gh/goplus/gox)
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/gox.svg)](https://pkg.go.dev/github.com/goplus/gox)
[![Build Status](https://github.com/goplus/gogen/actions/workflows/go.yml/badge.svg)](https://github.com/goplus/gogen/actions/workflows/go.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/goplus/gogen)](https://goreportcard.com/report/github.com/goplus/gogen)
[![GitHub release](https://img.shields.io/github/v/tag/goplus/gogen.svg?label=release)](https://github.com/goplus/gogen/releases)
[![Coverage Status](https://codecov.io/gh/goplus/gogen/branch/main/graph/badge.svg)](https://codecov.io/gh/goplus/gogen)
[![GoDoc](https://pkg.go.dev/badge/github.com/goplus/gogen.svg)](https://pkg.go.dev/github.com/goplus/gogen)

## Quick start

Expand All @@ -19,22 +19,22 @@ import (
"go/types"
"os"

"github.com/goplus/gox"
"github.com/goplus/gogen"
)

func main() {
pkg := gox.NewPackage("", "main", nil)
pkg := gogen.NewPackage("", "main", nil)
fmt := pkg.Import("fmt")
v := pkg.NewParam(token.NoPos, "v", types.Typ[types.String]) // v string

pkg.NewFunc(nil, "main", nil, nil, false).BodyStart(pkg).
DefineVarStart(token.NoPos, "a", "b").Val("Hi").Val(3).EndInit(2). // a, b := "Hi", 3
NewVarStart(nil, "c").VarVal("b").EndInit(1). // var c = b
NewVar(gox.TyEmptyInterface, "x", "y"). // var x, y interface{}
NewVar(gogen.TyEmptyInterface, "x", "y"). // var x, y interface{}
Val(fmt.Ref("Println")).
/**/ VarVal("a").VarVal("b").VarVal("c"). // fmt.Println(a, b, c)
/**/ Call(3).EndStmt().
NewClosure(gox.NewTuple(v), nil, false).BodyStart(pkg).
NewClosure(gogen.NewTuple(v), nil, false).BodyStart(pkg).
/**/ Val(fmt.Ref("Println")).Val(v).Call(1).EndStmt(). // fmt.Println(v)
/**/ End().
Val("Hello").Call(1).EndStmt(). // func(v string) { ... } ("Hello")
Expand Down
4 changes: 2 additions & 2 deletions ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package gox
package gogen

import (
"errors"
Expand All @@ -26,7 +26,7 @@ import (
"strconv"
"strings"

"github.com/goplus/gox/internal"
"github.com/goplus/gogen/internal"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package gox
package gogen

import (
"fmt"
Expand Down Expand Up @@ -1312,7 +1312,7 @@ func initBuiltinTIs(pkg *Package) {
{
ioxPkg := pkg.conf.PkgPathIox
if debugImportIox && ioxPkg == "" {
ioxPkg = "github.com/goplus/gox/internal/iox"
ioxPkg = "github.com/goplus/gogen/internal/iox"
}
if ioxPkg != "" {
if os := pkg.TryImport("os"); os.isValid() {
Expand Down
14 changes: 7 additions & 7 deletions builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package gox
package gogen

import (
"bytes"
Expand All @@ -25,9 +25,9 @@ import (
"testing"
"unsafe"

"github.com/goplus/gox/internal"
"github.com/goplus/gox/internal/go/format"
"github.com/goplus/gox/packages"
"github.com/goplus/gogen/internal"
"github.com/goplus/gogen/internal/go/format"
"github.com/goplus/gogen/packages"
)

var (
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestContractName(t *testing.T) {
func TestContract(t *testing.T) {
pkg := NewPackage("", "foo", nil)
at := types.NewPackage("foo", "foo")
foo := pkg.Import("github.com/goplus/gox/internal/foo")
foo := pkg.Import("github.com/goplus/gogen/internal/foo")
tfoo := foo.Ref("Foo").Type()
tarr := types.NewArray(tyInt, 10)
testcases := []struct {
Expand Down Expand Up @@ -546,7 +546,7 @@ func TestAssignableTo(t *testing.T) {
}
}
if Default(pkg, types.Typ[types.UntypedInt]) != types.Typ[types.Int] {
t.Fatal("gox.Default failed")
t.Fatal("gogen.Default failed")
}
}

Expand Down Expand Up @@ -1142,7 +1142,7 @@ func TestTryImport(t *testing.T) {

func TestUntypeBig(t *testing.T) {
pkg := NewPackage("foo", "foo", gblConf)
big := pkg.Import("github.com/goplus/gox/internal/builtin")
big := pkg.Import("github.com/goplus/gogen/internal/builtin")
big.EnsureImported()
pkg.utBigInt = big.Ref("Gop_untyped_bigint").Type().(*types.Named)
pkg.utBigRat = big.Ref("Gop_untyped_bigrat").Type().(*types.Named)
Expand Down
4 changes: 2 additions & 2 deletions c.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
limitations under the License.
*/

package gox
package gogen

import (
"go/ast"
"go/token"
"go/types"
"strconv"

"github.com/goplus/gox/internal"
"github.com/goplus/gogen/internal"
)

// ----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions c_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
limitations under the License.
*/

package gox_test
package gogen_test

import (
"go/token"
"go/types"
"testing"

"github.com/goplus/gox"
"github.com/goplus/gogen"
)

// ----------------------------------------------------------------------------
Expand All @@ -30,7 +30,7 @@ func TestBitFields(t *testing.T) {
types.NewField(token.NoPos, pkg.Types, "y", types.Typ[types.Uint], false),
}
tyT := pkg.NewType("T").InitType(pkg, types.NewStruct(fields, nil))
pkg.SetVFields(tyT, gox.NewBitFields([]*gox.BitField{
pkg.SetVFields(tyT, gogen.NewBitFields([]*gogen.BitField{
{Name: "z1", FldName: "x", Off: 0, Bits: 1},
{Name: "z2", FldName: "x", Off: 1, Bits: 3},
{Name: "u1", FldName: "y", Off: 0, Bits: 1},
Expand Down Expand Up @@ -97,7 +97,7 @@ func TestUnionFields(t *testing.T) {
}
tyT := pkg.NewType("T").InitType(pkg, types.NewStruct(fields, nil))
tyFlt := types.Typ[types.Float32]
pkg.SetVFields(tyT, gox.NewUnionFields([]*gox.UnionField{
pkg.SetVFields(tyT, gogen.NewUnionFields([]*gogen.UnionField{
{Name: "z", Type: tyFlt},
{Name: "val", Type: tyFlt, Off: 4},
}))
Expand Down Expand Up @@ -162,7 +162,7 @@ func test() {

func TestCFunc(t *testing.T) {
pkg := newMainPackage()
cfn := gox.NewCSignature(nil, nil, false)
cfn := gogen.NewCSignature(nil, nil, false)
pkg.NewFunc(nil, "test", nil, nil, false).BodyStart(pkg).
NewVar(cfn, "f").
VarVal("f").Call(0).EndStmt().
Expand Down
2 changes: 1 addition & 1 deletion chore/gobyeff/by_effect.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"log"
"os"

"github.com/goplus/gox/packages"
"github.com/goplus/gogen/packages"
)

type none = struct{}
Expand Down
6 changes: 3 additions & 3 deletions codebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package gox
package gogen

import (
"errors"
Expand All @@ -27,8 +27,8 @@ import (
"strings"
"syscall"

"github.com/goplus/gox/internal"
xtoken "github.com/goplus/gox/token"
"github.com/goplus/gogen/internal"
xtoken "github.com/goplus/gogen/token"
"golang.org/x/tools/go/types/typeutil"
)

Expand Down
14 changes: 7 additions & 7 deletions cpackages/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,45 +16,45 @@ package cpackages
import (
"go/types"

"github.com/goplus/gox"
"github.com/goplus/gogen"
)

// ----------------------------------------------------------------------------

type PkgRef struct {
pkg gox.PkgRef
pkg gogen.PkgRef
public map[string]string
}

func (p *PkgRef) Pkg() gox.PkgRef {
func (p *PkgRef) Pkg() gogen.PkgRef {
return p.pkg
}

func (p *PkgRef) Lookup(name string) types.Object {
if goName, ok := p.public[name]; ok {
if goName == "" {
goName = gox.CPubName(name)
goName = gogen.CPubName(name)
}
return p.pkg.TryRef(goName)
}
return nil
}

func PubName(name string) string {
return gox.CPubName(name)
return gogen.CPubName(name)
}

// ----------------------------------------------------------------------------

type Config struct {
Pkg *gox.Package
Pkg *gogen.Package
LookupPub func(pkgPath string) (pubfile string, err error)
}

type Importer struct {
loaded map[string]PkgRef
lookupPub func(pkgPath string) (pubfile string, err error)
pkg *gox.Package
pkg *gogen.Package
}

func NewImporter(conf *Config) *Importer {
Expand Down
Loading

0 comments on commit 010bb4b

Please sign in to comment.