using tuple comparison when checking for nim version instead of template

This commit is contained in:
andri lim 2019-08-07 21:28:33 +07:00
parent 173699583b
commit e084bb7d9d
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
1 changed files with 4 additions and 7 deletions

View File

@ -81,18 +81,15 @@ template createShr(name, operator: untyped) =
result.lo = convert[LoType](name(x.hi, (y - halfSize)))
result.hi = name(x.hi, halfSize-1)
template nimVersionIs(comparator: untyped, major, minor, patch: int): bool =
comparator(NimMajor * 100 + NimMinor * 10 + NimPatch, major * 100 + minor * 10 + patch)
when nimVersionIs(`>=`, 0, 20, 0):
when (NimMajor, NimMinor, NimPatch) >= (0, 20, 0):
createShr(shrOfShr, `shr`)
elif nimVersionIs(`<`, 0, 20, 0) and defined(nimAshr):
elif (NimMajor, NimMinor, NimPatch) < (0, 20, 0) and defined(nimAshr):
createShr(shrOfAshr, ashr)
else:
{.error: "arithmetic right shift is not defined for this Nim version".}
template `shr`*(a, b: typed): untyped =
when nimVersionIs(`>=`, 0, 20, 0):
when (NimMajor, NimMinor, NimPatch) >= (0, 20, 0):
shrOfShr(a, b)
elif nimVersionIs(`<`, 0, 20, 0) and defined(nimAshr):
elif (NimMajor, NimMinor, NimPatch) < (0, 20, 0) and defined(nimAshr):
shrOfAShr(a, b)