compiler: add support for the append builtin

This commit is contained in:
Ayke van Laethem
2018-10-19 14:40:19 +02:00
parent b81aecf753
commit 963ba16d7b
5 changed files with 112 additions and 11 deletions
+24
View File
@@ -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) {