mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 19:17:47 +00:00
compiler: add support for the append builtin
This commit is contained in:
Vendored
+24
@@ -8,8 +8,32 @@ func main() {
|
||||
printslice("bar", bar)
|
||||
printslice("foo[1:2]", foo[1:2])
|
||||
println("sum foo:", sum(foo))
|
||||
|
||||
// copy
|
||||
println("copy foo -> bar:", copy(bar, foo))
|
||||
printslice("bar", bar)
|
||||
|
||||
// append
|
||||
var grow []int
|
||||
printslice("grow", grow)
|
||||
grow = append(grow, 42)
|
||||
printslice("grow", grow)
|
||||
grow = append(grow, -1, -2)
|
||||
printslice("grow", grow)
|
||||
grow = append(grow, foo...)
|
||||
printslice("grow", grow)
|
||||
grow = append(grow)
|
||||
printslice("grow", grow)
|
||||
grow = append(grow, grow...)
|
||||
printslice("grow", grow)
|
||||
|
||||
// append string to []bytes
|
||||
bytes := append([]byte{1, 2, 3}, "foo"...)
|
||||
print("bytes: len=", len(bytes), " cap=", cap(bytes), " data:")
|
||||
for _, n := range bytes {
|
||||
print(" ", n)
|
||||
}
|
||||
println()
|
||||
}
|
||||
|
||||
func printslice(name string, s []int) {
|
||||
|
||||
Vendored
+7
@@ -4,3 +4,10 @@ foo[1:2]: len=1 cap=3 data: 2
|
||||
sum foo: 12
|
||||
copy foo -> bar: 3
|
||||
bar: len=3 cap=5 data: 1 2 4
|
||||
grow: len=0 cap=0 data:
|
||||
grow: len=1 cap=1 data: 42
|
||||
grow: len=3 cap=4 data: 42 -1 -2
|
||||
grow: len=7 cap=8 data: 42 -1 -2 1 2 4 5
|
||||
grow: len=7 cap=8 data: 42 -1 -2 1 2 4 5
|
||||
grow: len=14 cap=16 data: 42 -1 -2 1 2 4 5 42 -1 -2 1 2 4 5
|
||||
bytes: len=6 cap=6 data: 1 2 3 102 111 111
|
||||
|
||||
Reference in New Issue
Block a user