Fix core:slice.rotate_left

This commit includes two fixes:
- a temporary cast to make the function compile
- a fix to a logic error that caused the function to hang or return
  incorrect results
This commit is contained in:
Andrea Piseri
2022-12-21 21:09:22 +01:00
parent 0829ac30f7
commit 385d2a143c
2 changed files with 10 additions and 16 deletions
+5 -3
View File
@@ -218,8 +218,10 @@ rotate_left :: proc(array: $T/[]$E, mid: int) {
n := len(array)
m := mid %% n
k := n - m
p := raw_data(array)
ptr_rotate(mid, ptr_add(p, mid), k)
// FIXME: (ap29600) this cast is a temporary fix for the compiler not matching
// [^T] with $P/^$T
p := cast(^int)raw_data(array)
ptr_rotate(m, ptr_add(p, m), k)
}
rotate_right :: proc(array: $T/[]$E, k: int) {
rotate_left(array, -k)
@@ -515,4 +517,4 @@ dot_product :: proc(a, b: $S/[]$T) -> (r: T, ok: bool)
enumerated_array :: proc(ptr: ^$T) -> []intrinsics.type_elem_type(T)
where intrinsics.type_is_enumerated_array(T) {
return ([^]intrinsics.type_elem_type(T))(ptr)[:len(T)]
}
}