mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-09 11:45:42 +00:00
remove workaround for unsupported Nim 0.19 and earlier (#200)
* remove workaround for unsupported Nim 0.19 and earlier * replace some proc with func
This commit is contained in:
parent
65ce2203f0
commit
9958aac68a
@ -52,10 +52,10 @@ when defined(windows):
|
|||||||
else:
|
else:
|
||||||
proc alloca(n: int): pointer {.importc, header: "<alloca.h>".}
|
proc alloca(n: int): pointer {.importc, header: "<alloca.h>".}
|
||||||
|
|
||||||
proc raiseRangeError(s: string) =
|
func raiseRangeError(s: string) =
|
||||||
raise newException(RangeDefect, s)
|
raise newException(RangeDefect, s)
|
||||||
|
|
||||||
proc raiseOutOfRange =
|
func raiseOutOfRange =
|
||||||
raiseRangeError "index out of range"
|
raiseRangeError "index out of range"
|
||||||
|
|
||||||
template len*(a: StackArray): int =
|
template len*(a: StackArray): int =
|
||||||
@ -71,7 +71,7 @@ template `[]`*(a: StackArray, i: int): auto =
|
|||||||
if i < 0 or i >= a.len: raiseOutOfRange()
|
if i < 0 or i >= a.len: raiseOutOfRange()
|
||||||
a.buffer[i]
|
a.buffer[i]
|
||||||
|
|
||||||
proc `[]=`*(a: StackArray, i: int, val: a.T) {.inline.} =
|
func `[]=`*(a: StackArray, i: int, val: a.T) {.inline.} =
|
||||||
if i < 0 or i >= a.len: raiseOutOfRange()
|
if i < 0 or i >= a.len: raiseOutOfRange()
|
||||||
a.buffer[i] = val
|
a.buffer[i] = val
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ template `[]`*(a: StackArray, i: BackwardsIndex): auto =
|
|||||||
if int(i) < 1 or int(i) > a.len: raiseOutOfRange()
|
if int(i) < 1 or int(i) > a.len: raiseOutOfRange()
|
||||||
a.buffer[a.len - int(i)]
|
a.buffer[a.len - int(i)]
|
||||||
|
|
||||||
proc `[]=`*(a: StackArray, i: BackwardsIndex, val: a.T) =
|
func `[]=`*(a: StackArray, i: BackwardsIndex, val: a.T) =
|
||||||
if int(i) < 1 or int(i) > a.len: raiseOutOfRange()
|
if int(i) < 1 or int(i) > a.len: raiseOutOfRange()
|
||||||
a.buffer[a.len - int(i)] = val
|
a.buffer[a.len - int(i)] = val
|
||||||
|
|
||||||
@ -121,10 +121,7 @@ template allocStackArrayNoInit*(T: typedesc, size: int): StackArray[T] =
|
|||||||
allocStackArrayAux(T, size, false)
|
allocStackArrayAux(T, size, false)
|
||||||
|
|
||||||
template getBuffer*(a: StackArray): untyped =
|
template getBuffer*(a: StackArray): untyped =
|
||||||
when (NimMajor,NimMinor,NimPatch)>=(0,19,9):
|
a.buffer
|
||||||
a.buffer
|
|
||||||
else:
|
|
||||||
a.buffer[]
|
|
||||||
|
|
||||||
template toOpenArray*(a: StackArray): auto =
|
template toOpenArray*(a: StackArray): auto =
|
||||||
toOpenArray(a.getBuffer, 0, a.high)
|
toOpenArray(a.getBuffer, 0, a.high)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user