File: effecttraits.nim

package info (click to toggle)
nim 1.4.6%2Breally1.4.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 936,800 kB
  • sloc: sh: 17,201; ansic: 4,767; makefile: 856; python: 407; sql: 298; asm: 141; xml: 13
file content (54 lines) | stat: -rw-r--r-- 2,116 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#
#
#            Nim's Runtime Library
#        (c) Copyright 2020 Nim contributors
#
#    See the file "copying.txt", included in this
#    distribution, for details about the copyright.
#

## This module provides access to the inferred .raises effects
## for Nim's macro system.
## **Since**: Version 1.4.
##
## One can test for the existance of this standard module
## via ``defined(nimHasEffectTraitsModule)``.

import macros

proc getRaisesListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
proc getTagsListImpl(n: NimNode): NimNode = discard "see compiler/vmops.nim"
proc isGcSafeImpl(n: NimNode): bool = discard "see compiler/vmops.nim"
proc hasNoSideEffectsImpl(n: NimNode): bool = discard "see compiler/vmops.nim"

proc getRaisesList*(fn: NimNode): NimNode =
  ## Extracts the ``.raises`` list of the func/proc/etc ``fn``.
  ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  ## implies that the macro that calls this proc should accept ``typed``
  ## arguments and not ``untyped`` arguments.
  expectKind fn, nnkSym
  result = getRaisesListImpl(fn)

proc getTagsList*(fn: NimNode): NimNode =
  ## Extracts the ``.tags`` list of the func/proc/etc ``fn``.
  ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  ## implies that the macro that calls this proc should accept ``typed``
  ## arguments and not ``untyped`` arguments.
  expectKind fn, nnkSym
  result = getTagsListImpl(fn)

proc isGcSafe*(fn: NimNode): bool =
  ## Return true if the func/proc/etc ``fn`` is `gcsafe`.
  ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  ## implies that the macro that calls this proc should accept ``typed``
  ## arguments and not ``untyped`` arguments.
  expectKind fn, nnkSym
  result = isGcSafeImpl(fn)

proc hasNoSideEffects*(fn: NimNode): bool =
  ## Return true if the func/proc/etc ``fn`` has `noSideEffect`.
  ## ``fn`` has to be a resolved symbol of kind ``nnkSym``. This
  ## implies that the macro that calls this proc should accept ``typed``
  ## arguments and not ``untyped`` arguments.
  expectKind fn, nnkSym
  result = hasNoSideEffectsImpl(fn)