Skip to content

Commit 1495321

Browse files
authored
Merge pull request #2361 from goplus/main
v1.4.6
2 parents 7a6c5d1 + f91bd7f commit 1495321

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1009
-282
lines changed

.github/codecov.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ coverage:
2020
- "cl/internal/spx3"
2121
- "cl/internal/test"
2222
- "cl/internal/unit"
23+
- "cl/internal/typesalias"
2324
- "parser/fsx"
2425
- "parser/parsertest"
2526
- "x/jsonrpc2"

.github/workflows/release-build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- name: Set up Go
5858
uses: actions/setup-go@v5
5959
with:
60-
go-version: 1.21.x
60+
go-version: 1.24.x
6161

6262
- name: Set up QEMU
6363
uses: docker/setup-qemu-action@v3

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ Code style is just the first step. We have made many efforts to make the code mo
7676
| package main<br><br>import "fmt"<br><br>func main() {<br>&nbsp;&nbsp;&nbsp;&nbsp;fmt.Println("Hi")<br>} | import "fmt"<br><br>fmt.Println("Hi")<br> | Program structure: Go+ allows omitting `package main` and `func main` |
7777
| fmt.Println("Hi") | echo("Hi") | More builtin functions: It simplifies the expression of the most common tasks |
7878
| fmt.Println("Hi") | echo "Hi" | Command-line style code: It reduces the number of parentheses in the code as much as possible, making it closer to natural language |
79+
| name := "Ken"<br>fmt.Printf(<br>&nbsp;&nbsp;"Hi %s\n", name) | name := "Ken"<br>echo "Hi ${name}" | [Goodbye printf](doc/goodbye-printf.md), use `${expr}` in string literals |
7980
| a := []int{1, 2, 3} | a := [1, 2, 3] | List literals |
8081
| a = append(a, 4)<br>a = append(a, 5, 6, 7) | a <- 4<br>a <- 5, 6, 7 | Append values to a list |
8182
| a := map[string]int{<br>&nbsp;&nbsp;&nbsp;&nbsp;"Monday": 1,<br>&nbsp;&nbsp;&nbsp;&nbsp;"Tuesday": 2,<br>} | a := {<br>&nbsp;&nbsp;&nbsp;&nbsp;"Monday": 1,<br>&nbsp;&nbsp;&nbsp;&nbsp;"Tuesday": 2,<br>} | Mapping literals |

ast/ast.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,18 @@ func (x *ChanType) Pos() token.Pos { return x.Begin }
427427
func (x *BadExpr) End() token.Pos { return x.To }
428428

429429
// End returns position of first character immediately after the node.
430-
func (x *Ident) End() token.Pos { return token.Pos(int(x.NamePos) + len(x.Name)) }
430+
func (x *Ident) End() token.Pos {
431+
if x.Implicit() { // implicitly declared
432+
return x.NamePos
433+
}
434+
return x.NamePos + token.Pos(len(x.Name))
435+
}
436+
437+
// Implicit reports whether the identifier was implicitly declared
438+
func (x *Ident) Implicit() bool {
439+
o := x.Obj
440+
return o != nil && o.Kind >= implicitBase
441+
}
431442

432443
// End returns position of first character immediately after the node.
433444
func (x *Ellipsis) End() token.Pos {
@@ -542,6 +553,11 @@ func (*ChanType) exprNode() {}
542553
// Useful for ASTs generated by code other than the Go+ parser.
543554
func NewIdent(name string) *Ident { return &Ident{token.NoPos, name, nil} }
544555

556+
// NewIdentEx creates a new Ident with position and with the given kind.
557+
func NewIdentEx(pos token.Pos, name string, kind ObjKind) *Ident {
558+
return &Ident{pos, name, NewObj(kind, name)}
559+
}
560+
545561
// IsExported reports whether name starts with an upper-case letter.
546562
func IsExported(name string) bool { return token.IsExported(name) }
547563

@@ -1084,7 +1100,6 @@ func (*FuncDecl) declNode() {}
10841100
// collectively building a Go+ package.
10851101
type Package struct {
10861102
Name string // package name
1087-
Scope *Scope // package scope across all files
10881103
Imports map[string]*Object // map of package id -> package object
10891104
Files map[string]*File // Go+ source files by filename
10901105
GoFiles map[string]*ast.File // Go source files by filename

ast/ast_gop.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,7 @@ type File struct {
471471
Name *Ident // package name
472472
Decls []Decl // top-level declarations; or nil
473473

474-
Scope *Scope // package scope (this file only)
475474
Imports []*ImportSpec // imports in this file
476-
Unresolved []*Ident // unresolved identifiers in this file
477475
Comments []*CommentGroup // list of all comments in the source file
478476
Code []byte
479477
ShadowEntry *FuncDecl // indicate the module entry point.

ast/filter.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ func MergePackageFiles(pkg *Package, mode MergeMode) *File {
499499

500500
// TODO(gri) need to compute unresolved identifiers!
501501
return &File{
502-
doc, pos, NewIdent(pkg.Name), decls, pkg.Scope,
503-
imports, nil, comments, nil, nil, false, false, false, false,
502+
doc, pos, NewIdent(pkg.Name), decls,
503+
imports, comments, nil, nil, false, false, false, false,
504504
}
505505
}

ast/resolve.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
package ast
2020

21+
/* TODO(xsw): remove
2122
import (
2223
"fmt"
2324
"strconv"
@@ -184,3 +185,4 @@ func NewPackage(fset *token.FileSet, files map[string]*File, importer Importer,
184185
p.errors.Sort()
185186
return &Package{pkgName, pkgScope, imports, files, nil}, p.errors.Err()
186187
}
188+
*/

ast/scope.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,10 @@ const (
154154
Var // variable
155155
Fun // function or method
156156
Lbl // label
157+
implicitBase
158+
159+
ImplicitPkg = ObjKind(implicitBase)
160+
ImplicitFun = ObjKind(implicitBase + 1)
157161
)
158162

159163
var objKindStrings = [...]string{
@@ -164,6 +168,9 @@ var objKindStrings = [...]string{
164168
Var: "var",
165169
Fun: "func",
166170
Lbl: "label",
171+
172+
ImplicitPkg: "package",
173+
ImplicitFun: "func",
167174
}
168175

169176
func (kind ObjKind) String() string { return objKindStrings[kind] }

cl/builtin.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"go/types"
2222

2323
"github.com/goplus/gogen"
24+
"github.com/goplus/gop/cl/internal/typesalias"
2425
)
2526

2627
// -----------------------------------------------------------------------------
@@ -81,7 +82,7 @@ const (
8182
osxPkgPath = "github.com/qiniu/x/gop/osx"
8283
)
8384

84-
func newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package {
85+
func (ctx *pkgCtx) newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package {
8586
builtin := types.NewPackage("", "")
8687
fmt := pkg.TryImport("fmt")
8788
os := pkg.TryImport("os")
@@ -95,9 +96,12 @@ func newBuiltinDefault(pkg *gogen.Package, conf *gogen.Config) *types.Package {
9596
pkg.TryImport("strings")
9697
if ng.Types != nil {
9798
initMathBig(pkg, conf, ng)
98-
if obj := ng.Types.Scope().Lookup("Gop_ninteger"); obj != nil {
99-
if _, ok := obj.Type().(*types.Basic); !ok {
100-
conf.EnableTypesalias = true
99+
if typesalias.Support {
100+
if obj := ng.Types.Scope().Lookup("Gop_ninteger"); obj != nil {
101+
if _, ok := obj.Type().(*types.Basic); !ok {
102+
conf.EnableTypesalias = true
103+
ctx.featTypesAlias = true
104+
}
101105
}
102106
}
103107
}

cl/classfile.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,12 @@ func gmxProjMain(pkg *gogen.Package, parent *pkgCtx, proj *gmxProject) {
516516
mainFn := stk.Pop()
517517
sigParams := mainFn.Type.(*types.Signature).Params()
518518
callMain := func() {
519+
src := parent.lookupClassNode(proj.gameClass_)
519520
stk.Push(mainFn)
520521
if _, isPtr := sigParams.At(0).Type().(*types.Pointer); isPtr {
521-
cb.Val(recv).MemberRef(base.Name()).UnaryOp(gotoken.AND)
522+
cb.Val(recv, src).MemberRef(base.Name()).UnaryOp(gotoken.AND)
522523
} else {
523-
cb.Val(recv) // template recv method
524+
cb.Val(recv, src) // template recv method
524525
}
525526
}
526527

@@ -531,15 +532,15 @@ func gmxProjMain(pkg *gogen.Package, parent *pkgCtx, proj *gmxProject) {
531532
if len(sprites) == 1 && sprites[0].proto == "" { // no work class prototype
532533
sp := sprites[0]
533534
narg = 1 + len(sp.types)
534-
genWorkClasses(pkg, cb, recv, sp, iobj, -1, callMain)
535+
genWorkClasses(pkg, parent, cb, recv, sp, iobj, -1, callMain)
535536
} else {
536537
lstNames := make([]string, narg)
537538
for i := 1; i < narg; i++ {
538539
tslice := sigParams.At(i).Type()
539540
tn := tslice.(*types.Slice).Elem().(*types.Named)
540541
sp := spriteByProto(sprites, tn.Obj().Name()) // work class
541542
if n := len(sp.types); n > 0 {
542-
lstNames[i] = genWorkClasses(pkg, cb, recv, sp, iobj, i, nil)
543+
lstNames[i] = genWorkClasses(pkg, parent, cb, recv, sp, iobj, i, nil)
543544
cb.SliceLitEx(tslice, n, false).EndInit(1)
544545
iobj += n
545546
}
@@ -563,7 +564,7 @@ func gmxProjMain(pkg *gogen.Package, parent *pkgCtx, proj *gmxProject) {
563564
}
564565

565566
func genWorkClasses(
566-
pkg *gogen.Package, cb *gogen.CodeBuilder, recv *types.Var,
567+
pkg *gogen.Package, parent *pkgCtx, cb *gogen.CodeBuilder, recv *types.Var,
567568
sp *spxObj, iobj, ilst int, callMain func()) (lstName string) {
568569
const (
569570
indexGame = 1
@@ -588,9 +589,10 @@ func genWorkClasses(
588589
} else {
589590
callMain()
590591
}
591-
for i := range sptypes {
592+
for i, spt := range sptypes {
593+
src := parent.lookupClassNode(spt)
592594
objName := objNamePrefix + strconv.Itoa(iobj+i)
593-
cb.VarVal(objName)
595+
cb.VarVal(objName, src)
594596
}
595597
return
596598
}

0 commit comments

Comments
 (0)