mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-09 21:43:40 +00:00
all: drop support for Go 1.16 and Go 1.17
This commit is contained in:
committed by
Ron Evans
parent
f094e895c5
commit
4695da83b7
Vendored
+26
@@ -1,5 +1,7 @@
|
||||
package main
|
||||
|
||||
import "unsafe"
|
||||
|
||||
type MySlice [32]byte
|
||||
|
||||
type myUint8 uint8
|
||||
@@ -130,6 +132,26 @@ func main() {
|
||||
}
|
||||
println()
|
||||
|
||||
// Test conversion from array to slice.
|
||||
slice1 := []int{1, 2, 3, 4}
|
||||
arr1 := (*[4]int)(slice1)
|
||||
arr1[1] = -2
|
||||
arr1[2] = 20
|
||||
println("slice to array pointer:", arr1[0], arr1[1], arr1[2], arr1[3])
|
||||
|
||||
// Test unsafe.Add.
|
||||
arr2 := [...]int{1, 2, 3, 4}
|
||||
*(*int)(unsafe.Add(unsafe.Pointer(&arr2[0]), unsafe.Sizeof(int(1))*1)) = 5
|
||||
*addInt(&arr2[0], 2) = 8
|
||||
println("unsafe.Add array:", arr2[0], arr2[1], arr2[2], arr2[3])
|
||||
|
||||
// Test unsafe.Slice.
|
||||
arr3 := [...]int{1, 2, 3, 4}
|
||||
slice3 := unsafe.Slice(&arr3[1], 3)
|
||||
slice3[0] = 9
|
||||
slice3[1] = 15
|
||||
println("unsafe.Slice array:", len(slice3), cap(slice3), slice3[0], slice3[1], slice3[2])
|
||||
|
||||
// Verify the fix in https://github.com/tinygo-org/tinygo/pull/119
|
||||
var unnamed [32]byte
|
||||
var named MySlice
|
||||
@@ -177,3 +199,7 @@ func makeUint32(x uint32) uint32 { return x }
|
||||
func makeUint64(x uint64) uint64 { return x }
|
||||
func makeUintptr(x uintptr) uintptr { return x }
|
||||
func makeMyUint8(x myUint8) myUint8 { return x }
|
||||
|
||||
func addInt(ptr *int, index uintptr) *int {
|
||||
return (*int)(unsafe.Add(unsafe.Pointer(ptr), unsafe.Sizeof(int(1))*index))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user