Created
June 2, 2019 20:17
-
-
Save porky11/d07d39598460656c2b78d9f8e22eebdc to your computer and use it in GitHub Desktop.
Slice test
This file contains hidden or 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
using import struct | |
inline Slice (T) | |
struct ("[" .. (tostring T) .. "]") | |
first : (mutable pointer T) | |
size : usize | |
inline __countof (self) | |
self.size | |
fn slice (array start end) | |
let start = | |
static-if (none? start) 0 | |
else start | |
let end = | |
static-if (none? end) | |
countof array | |
else | |
end | |
assert (start <= end) "Negative slice sizes are not allowed" | |
print (countof array) ">=" end "?" | |
assert ((countof array) >= end) "Array slice has to be smaller" | |
first := array @ start | |
(Slice (typeof first)) | |
view first | |
end - start | |
locals; |
This file contains hidden or 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
using import struct | |
using import ..Slice | |
struct Number | |
element : i32 | |
local number-array = | |
arrayof Number | |
va-map Number 1 2 3 4 5 | |
let array-slice = | |
slice number-array 1 4 | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment