Skip to content

Instantly share code, notes, and snippets.

@porky11
Created June 2, 2019 20:17
Show Gist options
  • Save porky11/d07d39598460656c2b78d9f8e22eebdc to your computer and use it in GitHub Desktop.
Save porky11/d07d39598460656c2b78d9f8e22eebdc to your computer and use it in GitHub Desktop.
Slice test
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;
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