github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/compiler/testdata/slice.go (about) 1 package main 2 3 import "unsafe" 4 5 func sliceLen(ints []int) int { 6 return len(ints) 7 } 8 9 func sliceCap(ints []int) int { 10 return cap(ints) 11 } 12 13 func sliceElement(ints []int, index int) int { 14 return ints[index] 15 } 16 17 func sliceAppendValues(ints []int) []int { 18 return append(ints, 1, 2, 3) 19 } 20 21 func sliceAppendSlice(ints, added []int) []int { 22 return append(ints, added...) 23 } 24 25 func sliceCopy(dst, src []int) int { 26 return copy(dst, src) 27 } 28 29 // Test bounds checking in *ssa.MakeSlice instruction. 30 31 func makeByteSlice(len int) []byte { 32 return make([]byte, len) 33 } 34 35 func makeInt16Slice(len int) []int16 { 36 return make([]int16, len) 37 } 38 39 func makeArraySlice(len int) [][3]byte { 40 return make([][3]byte, len) // slice with element size of 3 41 } 42 43 func makeInt32Slice(len int) []int32 { 44 return make([]int32, len) 45 } 46 47 func Add32(p unsafe.Pointer, len int) unsafe.Pointer { 48 return unsafe.Add(p, len) 49 } 50 51 func Add64(p unsafe.Pointer, len int64) unsafe.Pointer { 52 return unsafe.Add(p, len) 53 } 54 55 func SliceToArray(s []int) *[4]int { 56 return (*[4]int)(s) 57 } 58 59 func SliceToArrayConst() *[4]int { 60 s := make([]int, 6) 61 return (*[4]int)(s) 62 } 63 64 func SliceInt(ptr *int, len int) []int { 65 return unsafe.Slice(ptr, len) 66 } 67 68 func SliceUint16(ptr *byte, len uint16) []byte { 69 return unsafe.Slice(ptr, len) 70 } 71 72 func SliceUint64(ptr *int, len uint64) []int { 73 return unsafe.Slice(ptr, len) 74 } 75 76 func SliceInt64(ptr *int, len int64) []int { 77 return unsafe.Slice(ptr, len) 78 }