compiler: implement clear builtin for slices

This commit is contained in:
Ayke van Laethem
2023-07-07 15:15:49 +02:00
committed by Ron Evans
parent f791c821ff
commit a2f886a67a
6 changed files with 95 additions and 21 deletions
+6
View File
@@ -1,6 +1,7 @@
package main
func main() {
// The new min/max builtins.
ia := 1
ib := 5
ic := -3
@@ -9,4 +10,9 @@ func main() {
fc := -3.0
println("min/max:", min(ia, ib, ic), max(ia, ib, ic))
println("min/max:", min(fa, fb, fc), max(fa, fb, fc))
// The clear builtin, for slices.
s := []int{1, 2, 3, 4, 5}
clear(s[:3])
println("cleared s[:3]:", s[0], s[1], s[2], s[3], s[4])
}
+1
View File
@@ -1,2 +1,3 @@
min/max: -3 5
min/max: -3.000000e+000 +5.000000e+000
cleared s[:3]: 0 0 0 4 5