Repository: goplus/gop
Pull request #2047 (2024-12-26 06:38:00)

mini spec ebnf: Array, Pointer, Slice, Map types


Patch:
diff --git a/.goreleaser.yaml b/.goreleaser.yaml
index 2553aacc..d96b74a3 100644
--- a/.goreleaser.yaml
+++ b/.goreleaser.yaml
@@ -51,7 +51,6 @@ dockers:
     build_flag_templates:
       - --platform=linux/386
       - --build-arg=USE_GORELEASER_ARTIFACTS=1
-      - --build-arg=GORELEASER_ARTIFACTS_TARBALL=./.dist/{{.ProjectName}}{{.Version}}.linux-386.tar.gz
     extra_files:
       - ./
   - goarch: amd64
@@ -61,7 +60,6 @@ dockers:
     build_flag_templates:
       - --platform=linux/amd64
       - --build-arg=USE_GORELEASER_ARTIFACTS=1
-      - --build-arg=GORELEASER_ARTIFACTS_TARBALL=./.dist/{{.ProjectName}}{{.Version}}.linux-amd64.tar.gz
     extra_files:
       - ./
   - goarch: arm64
@@ -71,7 +69,6 @@ dockers:
     build_flag_templates:
       - --platform=linux/arm64
       - --build-arg=USE_GORELEASER_ARTIFACTS=1
-      - --build-arg=GORELEASER_ARTIFACTS_TARBALL=./.dist/{{.ProjectName}}{{.Version}}.linux-arm64.tar.gz
     extra_files:
       - ./
 
diff --git a/Dockerfile b/Dockerfile
index 8b214ce7..bbca70c3 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,18 +2,21 @@ ARG BASE_IMAGE=golang:1.22-bookworm
 
 FROM $BASE_IMAGE AS build
 ARG USE_GORELEASER_ARTIFACTS=0
-ARG GORELEASER_ARTIFACTS_TARBALL
 WORKDIR /usr/local/src/gop
 COPY . .
 ENV GOPROOT=/usr/local/gop
 RUN set -eux; \
-	mkdir $GOPROOT; \
+	mkdir -p $GOPROOT/bin; \
+	git ls-tree --full-tree --name-only -r HEAD | grep -vE "^\." | xargs -I {} cp --parents {} $GOPROOT/; \
 	if [ $USE_GORELEASER_ARTIFACTS -eq 1 ]; then \
-		tar -xzf "${GORELEASER_ARTIFACTS_TARBALL}" -C $GOPROOT; \
+		GOARCH=$(go env GOARCH); \
+		BIN_DIR_SUFFIX=linux_$GOARCH; \
+		[ $GOARCH = "amd64" ] && BIN_DIR_SUFFIX=${BIN_DIR_SUFFIX}_v1; \
+		[ $GOARCH = "arm" ] && BIN_DIR_SUFFIX=${BIN_DIR_SUFFIX}_$(go env GOARM | cut -d , -f 1); \
+		cp .dist/gop_$BIN_DIR_SUFFIX/bin/gop $GOPROOT/bin/; \
 	else \
-		git ls-tree --full-tree --name-only -r HEAD | grep -vE "^\." | xargs -I {} cp --parents {} $GOPROOT/; \
 		./all.bash; \
-		mv bin $GOPROOT/; \
+		cp bin/gop $GOPROOT/bin/; \
 	fi
 
 FROM $BASE_IMAGE
diff --git a/doc/spec-mini.md b/doc/spec-mini.md
index 5eb9dbdc..5d88e25c 100644
--- a/doc/spec-mini.md
+++ b/doc/spec-mini.md
@@ -518,28 +518,49 @@ The length of a string `s` can be discovered using the built-in function [len]()
 An array is a numbered sequence of elements of a single type, called the element type. The number of elements is called the length of the array and is never negative.
 
 ```go
-[N]T
+ArrayType   = "[" ArrayLength "]" ElementType .
+ArrayLength = Expression .
+ElementType = Type .
 ```
 
-The length is part of the array's type; it must evaluate to a non-negative [constant]() [representable]() by a value of type int. The length of array `a` can be discovered using the built-in function [len](). The elements can be addressed by integer [indices]() `0` through `len(a)-1`. Array types are always one-dimensional but may be composed to form multi-dimensional types.
+The length is part of the array's type; it must evaluate to a non-negative [constant](#constants) [representable]() by a value of type int. The length of array `a` can be discovered using the built-in function [len](). The elements can be addressed by integer [indices]() `0` through `len(a)-1`. Array types are always one-dimensional but may be composed to form multi-dimensional types.
 
 ```go
 [32]byte
+[2*N] struct { x, y int32 }
 [1000]*float64
 [3][5]int
 [2][2][2]float64  // same as [2]([2]([2]float64))
 ```
 
+An array type T may not have an element of type T, or of a type containing T as a component, directly or indirectly, if those containing types are only array or struct types.
+
+```go
+// invalid array types
+type (
+	T1 [10]T1                 // element type of T1 is T1
+	T2 [10]struct{ f T2 }     // T2 contains T2 as component of a struct
+	T3 [10]T4                 // T3 contains T3 as component of a struct in T4
+	T4 struct{ f T3 }         // T4 contains T4 as component of array T3 in a struct
+)
+
+// valid array types
+type (
+	T5 [10]*T5                // T5 contains T5 as component of a pointer
+	T6 [10]func() T6          // T6 contains T6 as component of a function type
+	T7 [10]struct{ f []T7 }   // T7 contains T7 as component of a slice in a struct
+)
+```
+
 ### Pointer types
 
-A _pointer_ type denotes the set of all pointers to [variables]() of a given type, called the base type of the pointer. The value of an uninitialized pointer is `nil`.
+A _pointer_ type denotes the set of all pointers to [variables](#variables) of a given type, called the base type of the pointer. The value of an uninitialized pointer is `nil`.
 
 ```go
-*T
+PointerType = "*" BaseType .
+BaseType    = Type .
 ```
 
-For example:
-
 ```go
 *Point
 *[4]int
@@ -547,10 +568,10 @@ For example:
 
 ### Slice types
 
-A _slice_ is a descriptor for a contiguous segment of an underlying array and provides access to a numbered sequence of elements from that array. A slice type denotes the set of all slices of arrays of its element type. The number of elements is called the length of the slice and is never negative. The value of an uninitialized slice is `nil`.
+A _slice_ is a descriptor for a contiguous segment of an _underlying array_ and provides access to a numbered sequence of elements from that array. A slice type denotes the set of all slices of arrays of its element type. The number of elements is called the length of the slice and is never negative. The value of an uninitialized slice is `nil`.
 
 ```go
-[]T
+SliceType = "[" "]" ElementType .
 ```
 
 The length of a slice `s` can be discovered by the built-in function [len](); unlike with arrays it may change during execution. The elements can be addressed by integer [indices]() `0` through `len(s)-1`. The slice index of a given element may be less than the index of the same element in the underlying array.
@@ -576,17 +597,18 @@ Like arrays, slices are always one-dimensional but may be composed to construct
 
 ### Map types
 
-A _map_ is an unordered group of elements of one type, called the element type, indexed by a set of unique keys of another type, called the key type. The value of an uninitialized map is `nil`.
+A _map_ is an unordered group of elements of one type, called the element type, indexed by a set of unique _keys_ of another type, called the key type. The value of an uninitialized map is `nil`.
 
 ```go
-map[KeyT]ElemT
+MapType     = "map" "[" KeyType "]" ElementType .
+KeyType     = Type .
 ```
 
 The comparison operators `==` and `!=` must be fully defined for operands of the key type; thus the key type must not be a function, map, or slice. If the key type is an interface type, these comparison operators must be defined for the dynamic key values; failure will cause a run-time panic.
 
 ```go
 map[string]int
-map[*T]string
+map[*T]struct{ x, y float64 }
 map[string]any
 ```
 
diff --git a/go.mod b/go.mod
index 10b3a11e..cbe3b4a8 100644
--- a/go.mod
+++ b/go.mod
@@ -4,7 +4,7 @@ go 1.18
 
 require (
 	github.com/fsnotify/fsnotify v1.8.0
-	github.com/goplus/gogen v1.16.4-0.20241205134824-ac870e207d8f
+	github.com/goplus/gogen v1.16.3
 	github.com/goplus/llgo v0.9.8
 	github.com/goplus/mod v0.13.12
 	github.com/qiniu/x v1.13.10
diff --git a/go.sum b/go.sum
index cead13c2..e1e847ac 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,7 @@
 github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/8M=
 github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
-github.com/goplus/gogen v1.16.4-0.20241205134824-ac870e207d8f h1:+CwzStluc1MGjEQbR5CQOXWOqlBLYnaeECKcSXrHYKg=
-github.com/goplus/gogen v1.16.4-0.20241205134824-ac870e207d8f/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
+github.com/goplus/gogen v1.16.3 h1:nNkV1b6zd89d/UhMb4bZHcEfdAHtPaadrJFXNcoUITI=
+github.com/goplus/gogen v1.16.3/go.mod h1:6TQYbabXDF9LCdDkOOzHmfg1R4ENfXQ3XpHa9RhTSD8=
 github.com/goplus/llgo v0.9.8 h1:9qFO5sEYzTXYixNL9m9qDNfI2kjtnU3bPMf5hOwQlME=
 github.com/goplus/llgo v0.9.8/go.mod h1:1phqPJEgr/uw59PRz/NB7s54OoP+NGjC6pz0HovT5JY=
 github.com/goplus/mod v0.13.12 h1:Trwk6j3i9VvBuW6/9ZxmkoFlEL2v3HKQu0Na1c6DAdw=


Test patch:
diff --git a/cl/compile_gop_test.go b/cl/compile_gop_test.go
index 90bbdd66..04742bf2 100644
--- a/cl/compile_gop_test.go
+++ b/cl/compile_gop_test.go
@@ -1630,37 +1630,3 @@ func main() {
 }
 `)
 }
-
-func TestOverloadUntyped(t *testing.T) {
-	gopMixedClTest(t, "main", `
-package main
-
-type specialObj int
-type SpriteName string
-
-type SpriteImpl struct {
-}
-
-func (p *SpriteImpl) turn(v any) {
-}
-func (p *SpriteImpl) TurnTo__0(sprite *SpriteImpl) {
-}
-func (p *SpriteImpl) TurnTo__1(sprite SpriteName) {
-}
-func (p *SpriteImpl) TurnTo__2(obj specialObj) {
-}
-func (p *SpriteImpl) TurnTo__3(degree float64) {
-}
-`, `
-p := &SpriteImpl{}
-p.turnTo 180.0
-p.turnTo 180.1
-`, `package main
-
-func main() {
-	p := &SpriteImpl{}
-	p.TurnTo__2(180.0)
-	p.TurnTo__3(180.1)
-}
-`)
-}