interp: implement runtime.sliceCopy

This implements the copy() built-in function. It may not work in all
cases, but should work in most cases.

This commit gets the following 3 packages to compile, according to
tinygo-site/imports/main.go:

  * encoding/base32
  * encoding/base64
  * encoding/pem (was blocked by encoding/base64)
This commit is contained in:
Ayke van Laethem
2019-09-22 00:16:26 +02:00
committed by Ayke
parent 4ea1559d46
commit 582457b81e
8 changed files with 201 additions and 7 deletions
+18
View File
@@ -13,6 +13,11 @@ func main() {
println("v5:", len(v5), v5 == nil)
println("v6:", v6)
println("v7:", cap(v7), string(v7))
println(uint8SliceSrc[0])
println(uint8SliceDst[0])
println(intSliceSrc[0])
println(intSliceDst[0])
}
type (
@@ -30,4 +35,17 @@ var (
v5 = map[string]int{}
v6 = float64(v1) < 2.6
v7 = []byte("foo")
uint8SliceSrc = []uint8{3, 100}
uint8SliceDst []uint8
intSliceSrc = []int16{5, 123, 1024}
intSliceDst []int16
)
func init() {
uint8SliceDst = make([]uint8, len(uint8SliceSrc))
copy(uint8SliceDst, uint8SliceSrc)
intSliceDst = make([]int16, len(intSliceSrc))
copy(intSliceDst, intSliceSrc)
}
+4
View File
@@ -7,3 +7,7 @@ v4: 0 true
v5: 0 false
v6: false
v7: 3 foo
3
3
5
5