effecttraits.nim 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #
  2. #
  3. # Nim's Runtime Library
  4. # (c) Copyright 2020 Nim contributors
  5. #
  6. # See the file "copying.txt", included in this
  7. # distribution, for details about the copyright.
  8. #
  9. ## This module provides access to the inferred .raises effects
  10. ## for Nim's macro system.
  11. ## **Since**: Version 1.4.
  12. ##
  13. ## One can test for the existance of this standard module
  14. ## via ``defined(nimHasEffectTraitsModule)``.
  15. import macros
  16. proc getRaisesListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
  17. proc getTagsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
  18. proc isGcSafeImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
  19. proc hasNoSideEffectsImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
  20. proc getRaisesList*(fn: NimNode): NimNode =
  21. ## Extracts the ``.raises`` list of the func/proc/etc ``fn``.
  22. ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  23. ## implies that the macro that calls this proc should accept ``typed``
  24. ## arguments and not ``untyped`` arguments.
  25. expectKind fn, nnkSym
  26. result = getRaisesListImpl(fn)
  27. proc getTagsList*(fn: NimNode): NimNode =
  28. ## Extracts the ``.tags`` list of the func/proc/etc ``fn``.
  29. ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  30. ## implies that the macro that calls this proc should accept ``typed``
  31. ## arguments and not ``untyped`` arguments.
  32. expectKind fn, nnkSym
  33. result = getTagsListImpl(fn)
  34. proc isGcSafe*(fn: NimNode): bool =
  35. ## Return true if the func/proc/etc ``fn`` is `gcsafe`.
  36. ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  37. ## implies that the macro that calls this proc should accept ``typed``
  38. ## arguments and not ``untyped`` arguments.
  39. expectKind fn, nnkSym
  40. result = isGcSafeImpl(fn)
  41. proc hasNoSideEffects*(fn: NimNode): bool =
  42. ## Return true if the func/proc/etc ``fn`` has `noSideEffect`.
  43. ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  44. ## implies that the macro that calls this proc should accept ``typed``
  45. ## arguments and not ``untyped`` arguments.
  46. expectKind fn, nnkSym
  47. result = hasNoSideEffectsImpl(fn)