compiler: implement make([]T, ...)

This commit is contained in:
Ayke van Laethem
2018-09-06 09:46:58 +02:00
parent ef2c406127
commit 094c5561b6
3 changed files with 54 additions and 1 deletions
+3
View File
@@ -35,8 +35,11 @@ func main() {
readMap(testmap, "data")
// slice
l := 5
foo := []int{1, 2, 4, 5}
bar := make([]byte, l-2, l)
println("len/cap foo:", len(foo), cap(foo))
println("len/cap bar:", len(bar), cap(bar))
println("foo[3]:", foo[3])
println("sum foo:", sum(foo))
+9 -1
View File
@@ -99,10 +99,18 @@ func lookupBoundsCheck(length, index int) {
}
}
// Check for bounds in *ssa.Slice
// Check for bounds in *ssa.Slice.
func sliceBoundsCheck(length, low, high uint) {
if !(0 <= low && low <= high && high <= length) {
printstring("panic: runtime error: slice out of range\n")
abort()
}
}
// Check for bounds in *ssa.MakeSlice.
func sliceBoundsCheckMake(length, capacity uint) {
if !(0 <= length && length <= capacity) {
printstring("panic: runtime error: slice size out of range\n")
abort()
}
}