WASM: Add few helper array library functions from Slava's changes

This commit is contained in:
Igor Laevsky
2021-06-25 18:59:39 +03:00
committed by teamcityserver
parent dc8186cb83
commit 74a87e2b79
3 changed files with 235 additions and 33 deletions
@@ -920,7 +920,24 @@ object ArrayOps : TemplateGroupBase() {
}
}
on(Backend.Wasm) {
body { """TODO("Wasm stdlib: $signature")""" }
body {
"""
AbstractList.checkRangeIndexes(startIndex, endIndex, this.size)
val rangeSize = endIndex - startIndex
AbstractList.checkRangeIndexes(destinationOffset, destinationOffset + rangeSize, destination.size)
if (this !== destination || destinationOffset <= startIndex) {
for (index in 0 until rangeSize) {
destination[destinationOffset + index] = this[startIndex + index]
}
} else {
for (index in rangeSize - 1 downTo 0) {
destination[destinationOffset + index] = this[startIndex + index]
}
}
return destination
"""
}
}
}
}
@@ -1049,9 +1066,6 @@ object ArrayOps : TemplateGroupBase() {
return result
"""
}
on(Backend.Wasm) {
body { """TODO("Wasm stdlib: $signature")""" }
}
}
val f_copyOf = fn("copyOf()") {
@@ -1646,7 +1660,13 @@ object ArrayOps : TemplateGroupBase() {
"arrayFill(this, fromIndex, toIndex, element)"
}
on(Backend.Wasm) {
body { """TODO("Wasm stdlib: $signature")""" }
body {
"""
for (index in fromIndex..toIndex) {
this[index] = element
}
"""
}
}
}
on(Platform.Common) {