Repository: goplus/gop
Pull request #1145 (2022-04-21 08:20:20)

gop/builtin/big


Patch:
diff --git a/builtin/_big.gop b/builtin/big/_big.gop
similarity index 100%
rename from builtin/_big.gop
rename to builtin/big/_big.gop
diff --git a/builtin/big.go b/builtin/big/big.go
similarity index 99%
rename from builtin/big.go
rename to builtin/big/big.go
index 6e83bbac..dea99008 100644
--- a/builtin/big.go
+++ b/builtin/big/big.go
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package builtin
+package big
 
 import (
 	"math/big"
diff --git a/builtin/range.go b/builtin/range.go
index 5bd98c60..259104a1 100644
--- a/builtin/range.go
+++ b/builtin/range.go
@@ -16,6 +16,10 @@
 
 package builtin
 
+const (
+	GopPackage = true // to indicate this is a Go+ package
+)
+
 // -----------------------------------------------------------------------------
 
 type IntRange struct {
diff --git a/cl/builtin.go b/cl/builtin.go
index 119fe9bd..b9af78d1 100644
--- a/cl/builtin.go
+++ b/cl/builtin.go
@@ -32,7 +32,7 @@ func initMathBig(pkg gox.PkgImporter, conf *gox.Config, big *gox.PkgRef) {
 	conf.UntypedBigFloat = big.Ref("Gop_untyped_bigfloat").Type().(*types.Named)
 }
 
-func initBuiltin(pkg gox.PkgImporter, builtin *types.Package, fmt, big *gox.PkgRef) {
+func initBuiltin(pkg gox.PkgImporter, builtin *types.Package, fmt, big, buil *gox.PkgRef) {
 	scope := builtin.Scope()
 	typs := []string{"bigint", "bigrat", "bigfloat"}
 	for _, typ := range typs {
@@ -47,18 +47,19 @@ func initBuiltin(pkg gox.PkgImporter, builtin *types.Package, fmt, big *gox.PkgR
 		fnTitle := string(fn[0]-'a'+'A') + fn[1:]
 		scope.Insert(gox.NewOverloadFunc(token.NoPos, builtin, fn, fmt.Ref(fnTitle)))
 	}
-	scope.Insert(gox.NewOverloadFunc(token.NoPos, builtin, "newRange", big.Ref("NewRange__0")))
+	scope.Insert(gox.NewOverloadFunc(token.NoPos, builtin, "newRange", buil.Ref("NewRange__0")))
 	scope.Insert(types.NewTypeName(token.NoPos, builtin, "any", gox.TyEmptyInterface))
 }
 
 func newBuiltinDefault(pkg gox.PkgImporter, conf *gox.Config) *types.Package {
 	builtin := types.NewPackage("", "")
 	fmt := pkg.Import("fmt")
-	big := pkg.Import("github.com/goplus/gop/builtin")
+	buil := pkg.Import("github.com/goplus/gop/builtin")
+	big := pkg.Import("github.com/goplus/gop/builtin/big")
 	pkg.Import("strconv")
 	pkg.Import("strings")
 	initMathBig(pkg, conf, big)
-	initBuiltin(pkg, builtin, fmt, big)
+	initBuiltin(pkg, builtin, fmt, big, buil)
 	gox.InitBuiltin(pkg, builtin, conf)
 	return builtin
 }


Test patch:
diff --git a/cl/compile_test.go b/cl/compile_test.go
index 030ae61e..7b2d9f7b 100644
--- a/cl/compile_test.go
+++ b/cl/compile_test.go
@@ -1198,10 +1198,10 @@ var x, y bigint
 var z bigint = x + y
 `, `package main
 
-import builtin "github.com/goplus/gop/builtin"
+import big "github.com/goplus/gop/builtin/big"
 
-var x, y builtin.Gop_bigint
-var z builtin.Gop_bigint = x.Gop_Add(y)
+var x, y big.Gop_bigint
+var z big.Gop_bigint = x.Gop_Add(y)
 `)
 }
 
@@ -1211,11 +1211,11 @@ var x = 1r
 `, `package main
 
 import (
-	builtin "github.com/goplus/gop/builtin"
-	big "math/big"
+	big "github.com/goplus/gop/builtin/big"
+	big1 "math/big"
 )
 
-var x = builtin.Gop_bigint_Init__1(big.NewInt(1))
+var x = big.Gop_bigint_Init__1(big1.NewInt(1))
 `)
 }
 
@@ -1225,11 +1225,11 @@ var x = 1/2r
 `, `package main
 
 import (
-	builtin "github.com/goplus/gop/builtin"
-	big "math/big"
+	big "github.com/goplus/gop/builtin/big"
+	big1 "math/big"
 )
 
-var x = builtin.Gop_bigrat_Init__2(big.NewRat(1, 2))
+var x = big.Gop_bigrat_Init__2(big1.NewRat(1, 2))
 `)
 }
 
@@ -1239,11 +1239,11 @@ var x = 3 + 1/2r
 `, `package main
 
 import (
-	builtin "github.com/goplus/gop/builtin"
-	big "math/big"
+	big "github.com/goplus/gop/builtin/big"
+	big1 "math/big"
 )
 
-var x = builtin.Gop_bigrat_Init__2(big.NewRat(7, 2))
+var x = big.Gop_bigrat_Init__2(big1.NewRat(7, 2))
 `)
 }
 
@@ -1256,13 +1256,13 @@ var z = 100 + y
 `, `package main
 
 import (
-	builtin "github.com/goplus/gop/builtin"
-	big "math/big"
+	big "github.com/goplus/gop/builtin/big"
+	big1 "math/big"
 )
 
-var x = builtin.Gop_bigrat_Init__2(big.NewRat(7, 2))
-var y = x.Gop_Add(builtin.Gop_bigrat_Init__0(100))
-var z = builtin.Gop_bigrat_Init__0(100) + y
+var x = big.Gop_bigrat_Init__2(big1.NewRat(7, 2))
+var y = x.Gop_Add(big.Gop_bigrat_Init__0(100))
+var z = big.Gop_bigrat_Init__0(100) + y
 `)
 }
 
@@ -1344,12 +1344,12 @@ var x bigint
 x += 3
 `, `package main
 
-import builtin "github.com/goplus/gop/builtin"
+import big "github.com/goplus/gop/builtin/big"
 
-var x builtin.Gop_bigint
+var x big.Gop_bigint
 
 func main() {
-	x.Gop_AddAssign(builtin.Gop_bigint_Init__0(3))
+	x.Gop_AddAssign(big.Gop_bigint_Init__0(3))
 }
 `)
 }
@@ -1361,13 +1361,13 @@ x *= 2
 `, `package main
 
 import (
-	builtin "github.com/goplus/gop/builtin"
-	big "math/big"
+	big "github.com/goplus/gop/builtin/big"
+	big1 "math/big"
 )
 
 func main() {
-	x := builtin.Gop_bigint_Init__1(big.NewInt(3))
-	x.Gop_MulAssign(builtin.Gop_bigint_Init__0(2))
+	x := big.Gop_bigint_Init__1(big1.NewInt(3))
+	x.Gop_MulAssign(big.Gop_bigint_Init__0(2))
 }
 `)
 }
@@ -1379,13 +1379,13 @@ x *= 2r
 `, `package main
 
 import (
-	builtin "github.com/goplus/gop/builtin"
-	big "math/big"
+	big "github.com/goplus/gop/builtin/big"
+	big1 "math/big"
 )
 
 func main() {
-	x := builtin.Gop_bigint_Init__1(big.NewInt(3))
-	x.Gop_MulAssign(builtin.Gop_bigint_Init__1(big.NewInt(2)))
+	x := big.Gop_bigint_Init__1(big1.NewInt(3))
+	x.Gop_MulAssign(big.Gop_bigint_Init__1(big1.NewInt(2)))
 }
 `)
 }