diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2020-10-06 16:47:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-06 16:47:15 +0200 |
commit | 92163fa3304e5b6768a50d36a5243639ce4a2f69 (patch) | |
tree | b7aa2705a4772e8f82d61e765ff9158f7b21b441 /lib/std/effecttraits.nim | |
parent | acd71dd6bb745eb08f81ab489d635951f8edfcfa (diff) | |
download | Nim-92163fa3304e5b6768a50d36a5243639ce4a2f69.tar.gz |
implements https://github.com/nim-lang/RFCs/issues/258 (#15503)
* implements https://github.com/nim-lang/RFCs/issues/258 * don't be too strict with custom pragma blocks * cast pragmas: documentation * added most missing inference query procs to effecttraits.nim
Diffstat (limited to 'lib/std/effecttraits.nim')
-rw-r--r-- | lib/std/effecttraits.nim | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/lib/std/effecttraits.nim b/lib/std/effecttraits.nim index a5d799786..0f0a24492 100644 --- a/lib/std/effecttraits.nim +++ b/lib/std/effecttraits.nim @@ -1,7 +1,7 @@ # # # Nim's Runtime Library -# (c) Copyright 2018 Nim contributors +# (c) Copyright 2020 Nim contributors # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -9,11 +9,46 @@ ## 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*(call: NimNode): NimNode = - expectKind call, nnkCallKinds - result = getRaisesListImpl(call[0]) +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) |