tsignaturehash.nim 533 B

123456789101112131415161718192021
  1. # test sym digest is computable at compile time
  2. import macros, algorithm
  3. import md5
  4. macro testmacro(s: typed{nkSym}): string =
  5. let s = getMD5(signaturehash(s) & " - " & symBodyHash(s))
  6. result = newStrLitNode(s)
  7. macro testmacro(s: typed{nkOpenSymChoice|nkClosedSymChoice}): string =
  8. var str = ""
  9. for sym in s:
  10. str &= symBodyHash(sym)
  11. result = newStrLitNode(getMD5(str))
  12. # something recursive and/or generic
  13. discard testmacro(testmacro)
  14. discard testmacro(`[]`)
  15. discard testmacro(binarySearch)
  16. discard testmacro(sort)