I have this code (playground) which I want to build compile-time consts. I've eliminated unrelated operations to hone in on my problem. The error is that toMask expects a Slice, but got an HSlice because the types of foo and baz differ; foo is becoming an int for a reason I do not understand.
import std/bitops
func mask(foo: static uint32, bar: static uint32): uint32 =
const baz: uint32 = bar - 1
const bim = toMask(foo .. baz)
result = bim
const m = mask(0, 1)
My attempts to work around:
I've read in docs that nim generally prefers signed int to unsigned types. I'm using uint32 here because I'm working in 32-bit microcontroller-land and want to avoid implicit sign extensions if I shift-right the value. If this is a C habit I need to purge, please help me understand.
Oh, here it is. I looked at the declaration of toMask:
func toMask*[T: SomeInteger](slice: Slice[int]): T {.inline, since: (1, 3).}
Previously, I speed-read the SomeInteger and thought I was safe to use unsigned. But now I see the Slice is constrained to use signed values.