From 316eb1d4298fb1304e3b99e01f273f473f550574 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 25 Feb 2025 07:48:11 +0800 Subject: [PATCH 1/2] cl: remove newRange --- builtin/doc/builtin.gop | 2 -- cl/builtin.go | 8 ++------ cmd/chore/gopbuiltingen/builtingen.gox | 1 - cmd/chore/gopbuiltingen/helper.gop | 3 --- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/builtin/doc/builtin.gop b/builtin/doc/builtin.gop index b64dec045..7177ea476 100755 --- a/builtin/doc/builtin.gop +++ b/builtin/doc/builtin.gop @@ -1,7 +1,6 @@ package builtin import ( - "gop/builtin" "gop/builtin/iox" "io" "os" @@ -17,7 +16,6 @@ func Blines(r io.Reader) iox.BLineReader // Type returns the reflection [Type] that represents the dynamic type of i. // If i is a nil interface value, Type returns nil. func Type(i any) reflect.Type -func NewRange(start, end, step int) *builtin.IntRange // Print formats using the default formats for its operands and writes to standard output. // Spaces are added between operands when neither is a string. diff --git a/cl/builtin.go b/cl/builtin.go index 93445a394..b916d24fb 100644 --- a/cl/builtin.go +++ b/cl/builtin.go @@ -38,7 +38,7 @@ func initBuiltinFns(builtin *types.Package, scope *types.Scope, pkg gogen.PkgRef } } -func initBuiltin(_ *gogen.Package, builtin *types.Package, os, fmt, ng, iox, buil, reflect gogen.PkgRef) { +func initBuiltin(_ *gogen.Package, builtin *types.Package, os, fmt, ng, iox, reflect gogen.PkgRef) { scope := builtin.Scope() if ng.Types != nil { typs := []string{"bigint", "bigrat", "bigfloat"} @@ -71,9 +71,6 @@ func initBuiltin(_ *gogen.Package, builtin *types.Package, os, fmt, ng, iox, bui if reflect.Types != nil { scope.Insert(gogen.NewOverloadFunc(token.NoPos, builtin, "type", reflect.Ref("TypeOf"))) } - if buil.Types != nil { - scope.Insert(gogen.NewOverloadFunc(token.NoPos, builtin, "newRange", buil.Ref("NewRange__0"))) - } scope.Insert(types.NewTypeName(token.NoPos, builtin, "any", gogen.TyEmptyInterface)) } @@ -82,7 +79,6 @@ func newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package { fmt := pkg.TryImport("fmt") os := pkg.TryImport("os") reflect := pkg.TryImport("reflect") - buil := pkg.TryImport("github.com/goplus/gop/builtin") ng := pkg.TryImport("github.com/goplus/gop/builtin/ng") iox := pkg.TryImport("github.com/goplus/gop/builtin/iox") strx := pkg.TryImport("github.com/qiniu/x/stringutil") @@ -92,7 +88,7 @@ func newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package { if ng.Types != nil { initMathBig(pkg, conf, ng) } - initBuiltin(pkg, builtin, os, fmt, ng, iox, buil, reflect) + initBuiltin(pkg, builtin, os, fmt, ng, iox, reflect) gogen.InitBuiltin(pkg, builtin, conf) if strx.Types != nil { ti := pkg.BuiltinTI(types.Typ[types.String]) diff --git a/cmd/chore/gopbuiltingen/builtingen.gox b/cmd/chore/gopbuiltingen/builtingen.gox index 744f86653..681c6cad2 100644 --- a/cmd/chore/gopbuiltingen/builtingen.gox +++ b/cmd/chore/gopbuiltingen/builtingen.gox @@ -25,7 +25,6 @@ func gen() []byte { f.Decls <- &ast.GenDecl{ Tok: token.IMPORT, Specs: []ast.Spec{ - importSpec("gop/builtin"), importSpec("gop/builtin/iox"), importSpec("io"), importSpec("os"), diff --git a/cmd/chore/gopbuiltingen/helper.gop b/cmd/chore/gopbuiltingen/helper.gop index 2af5450de..13bb41c0f 100644 --- a/cmd/chore/gopbuiltingen/helper.gop +++ b/cmd/chore/gopbuiltingen/helper.gop @@ -36,9 +36,6 @@ func toParams(params *ast.FieldList, at string) *ast.FieldList { if params == nil { return nil } - if at == "buil" { - at = "builtin" - } list := make([]*ast.Field, len(params.List)) for i, p <- params.List { typ := p.Type From 8cf05aaab9e7d65b18dcfb1200b96f3110abd976 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Tue, 25 Feb 2025 07:59:20 +0800 Subject: [PATCH 2/2] hide builtin newRange --- cl/builtin.go | 8 ++++++-- cmd/chore/gopbuiltingen/builtingen.gox | 10 ++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cl/builtin.go b/cl/builtin.go index b916d24fb..93445a394 100644 --- a/cl/builtin.go +++ b/cl/builtin.go @@ -38,7 +38,7 @@ func initBuiltinFns(builtin *types.Package, scope *types.Scope, pkg gogen.PkgRef } } -func initBuiltin(_ *gogen.Package, builtin *types.Package, os, fmt, ng, iox, reflect gogen.PkgRef) { +func initBuiltin(_ *gogen.Package, builtin *types.Package, os, fmt, ng, iox, buil, reflect gogen.PkgRef) { scope := builtin.Scope() if ng.Types != nil { typs := []string{"bigint", "bigrat", "bigfloat"} @@ -71,6 +71,9 @@ func initBuiltin(_ *gogen.Package, builtin *types.Package, os, fmt, ng, iox, ref if reflect.Types != nil { scope.Insert(gogen.NewOverloadFunc(token.NoPos, builtin, "type", reflect.Ref("TypeOf"))) } + if buil.Types != nil { + scope.Insert(gogen.NewOverloadFunc(token.NoPos, builtin, "newRange", buil.Ref("NewRange__0"))) + } scope.Insert(types.NewTypeName(token.NoPos, builtin, "any", gogen.TyEmptyInterface)) } @@ -79,6 +82,7 @@ func newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package { fmt := pkg.TryImport("fmt") os := pkg.TryImport("os") reflect := pkg.TryImport("reflect") + buil := pkg.TryImport("github.com/goplus/gop/builtin") ng := pkg.TryImport("github.com/goplus/gop/builtin/ng") iox := pkg.TryImport("github.com/goplus/gop/builtin/iox") strx := pkg.TryImport("github.com/qiniu/x/stringutil") @@ -88,7 +92,7 @@ func newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package { if ng.Types != nil { initMathBig(pkg, conf, ng) } - initBuiltin(pkg, builtin, os, fmt, ng, iox, reflect) + initBuiltin(pkg, builtin, os, fmt, ng, iox, buil, reflect) gogen.InitBuiltin(pkg, builtin, conf) if strx.Types != nil { ti := pkg.BuiltinTI(types.Typ[types.String]) diff --git a/cmd/chore/gopbuiltingen/builtingen.gox b/cmd/chore/gopbuiltingen/builtingen.gox index 681c6cad2..f0d1b7a27 100644 --- a/cmd/chore/gopbuiltingen/builtingen.gox +++ b/cmd/chore/gopbuiltingen/builtingen.gox @@ -104,10 +104,12 @@ func initBuiltin(fn gopq.NodeSet) { item := stmt.callExpr("scope.Insert").arg(0).cache for call <- item.callExpr("gogen.NewOverloadFunc") { built := call.arg(2).unquotedString! - ref := call.arg(3).callExpr.one - pkg := ref.fun.x.ident! - name := ref.arg(0).unquotedString! - Builtins <- builtin{built, {pkg, name, 0}} + if built != "newRange" { // hide builtin `newRange` + ref := call.arg(3).callExpr.one + pkg := ref.fun.x.ident! + name := ref.arg(0).unquotedString! + Builtins <- builtin{built, {pkg, name, 0}} + } } for call <- stmt.callExpr("initBuiltinFns") { pkg := call.arg(2).ident!