muninstantiatedgenericcalls.nim 494 B

123456789101112131415161718192021222324252627
  1. import std/bitops
  2. const
  3. lengths = block:
  4. var v: array[64, int8]
  5. for i in 0..<64:
  6. v[i] = int8((i + 7) div 7)
  7. v
  8. type
  9. Leb128* = object
  10. {.push checks: off.}
  11. func len(T: type Leb128, x: SomeUnsignedInt): int8 =
  12. if x == 0: 1
  13. else: lengths[fastLog2(x)]
  14. {.pop.}
  15. # note private to test scoping issue:
  16. func maxLen(T: type Leb128, I: type): int8 =
  17. Leb128.len(I.high)
  18. type
  19. Leb128Buf*[T: SomeUnsignedInt] = object
  20. data*: array[maxLen(Leb128, T), byte]
  21. len*: int8