-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented
mSlice
on the VM allowing toOpenArray
to work at comp…
…ile time. (#20586) * Implemented opcSlice to make 'toOpenArray' work on the VM * Added nkOpenArray for VM to reduce bodgeness * Fixed range issues and erraneous comments * Range check correctly for openArrays in opcLdArr * Inverted logic for ldArr checking * vm now supports slicing strings * Added string tests * Removed usage of 'nkOpenArray' and redundant operations * Refactored vmSlice implementation, removing redundant and incorrect code * Made tuples go throw opcWrObj for field assignment * All strkinds should be considered for openarrays (cherry picked from commit 4aa67ad)
- Loading branch information
Showing
4 changed files
with
204 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
proc mutate(a: var openarray[int]) = | ||
var i = 0 | ||
for x in a.mitems: | ||
x = i | ||
inc i | ||
|
||
proc mutate(a: var openarray[char]) = | ||
var i = 1 | ||
for ch in a.mitems: | ||
ch = 'a' | ||
|
||
|
||
static: | ||
var a = [10, 20, 30] | ||
assert a.toOpenArray(1, 2).len == 2 | ||
|
||
mutate(a) | ||
assert a.toOpenArray(0, 2) == [0, 1, 2] | ||
assert a.toOpenArray(0, 0) == [0] | ||
assert a.toOpenArray(1, 2) == [1, 2] | ||
assert "Hello".toOpenArray(1, 4) == "ello" | ||
var str = "Hello" | ||
str.toOpenArray(2, 4).mutate() | ||
assert str.toOpenArray(0, 4).len == 5 | ||
assert str.toOpenArray(0, 0).len == 1 | ||
assert str.toOpenArray(0, 0).high == 0 | ||
assert str == "Heaaa" | ||
assert str.toOpenArray(0, 4) == "Heaaa" | ||
|
||
var arr: array[3..4, int] = [1, 2] | ||
assert arr.toOpenArray(3, 4) == [1, 2] | ||
assert arr.toOpenArray(3, 4).len == 2 | ||
assert arr.toOpenArray(3, 3).high == 0 | ||
|
||
assert arr.toOpenArray(3, 4).toOpenArray(0, 0) == [1] | ||
|
||
|
||
|