pragma for sfCallsite instead of name check + better semantics, test (#20464)
* pragma for sfCallsite instead of name check at every template definition Not documented because it seems to be for internal use? Should also make it possible to make comparisons and setops imports, but this doesn't have to be done. I can reuse a name like `cursor` for the pragma as well, added a new name just to be safe. * make sfCallsite recursive, add tests
This commit is contained in:
parent
81e7811e01
commit
2cca38d33c
13 changed files with 73 additions and 25 deletions
|
|
@ -731,13 +731,16 @@ proc contains*[U, V, W](s: HSlice[U, V], value: W): bool {.noSideEffect, inline.
|
|||
## ```
|
||||
result = s.a <= value and value <= s.b
|
||||
|
||||
template `in`*(x, y: untyped): untyped {.dirty.} = contains(y, x)
|
||||
when not defined(nimHasCallsitePragma):
|
||||
{.pragma: callsite.}
|
||||
|
||||
template `in`*(x, y: untyped): untyped {.dirty, callsite.} = contains(y, x)
|
||||
## Sugar for `contains`.
|
||||
## ```
|
||||
## assert(1 in (1..3) == true)
|
||||
## assert(5 in (1..3) == false)
|
||||
## ```
|
||||
template `notin`*(x, y: untyped): untyped {.dirty.} = not contains(y, x)
|
||||
template `notin`*(x, y: untyped): untyped {.dirty, callsite.} = not contains(y, x)
|
||||
## Sugar for `not contains`.
|
||||
## ```
|
||||
## assert(1 notin (1..3) == false)
|
||||
|
|
@ -762,7 +765,7 @@ proc `is`*[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
|
|||
## assert(test[int](3) == 3)
|
||||
## assert(test[string]("xyz") == 0)
|
||||
## ```
|
||||
template `isnot`*(x, y: untyped): untyped = not (x is y)
|
||||
template `isnot`*(x, y: untyped): untyped {.callsite.} = not (x is y)
|
||||
## Negated version of `is <#is,T,S>`_. Equivalent to `not(x is y)`.
|
||||
## ```
|
||||
## assert 42 isnot float
|
||||
|
|
|
|||
|
|
@ -125,15 +125,18 @@ proc `<`*[T](x, y: ref T): bool {.magic: "LtPtr", noSideEffect.}
|
|||
proc `<`*[T](x, y: ptr T): bool {.magic: "LtPtr", noSideEffect.}
|
||||
proc `<`*(x, y: pointer): bool {.magic: "LtPtr", noSideEffect.}
|
||||
|
||||
template `!=`*(x, y: untyped): untyped =
|
||||
when not defined(nimHasCallsitePragma):
|
||||
{.pragma: callsite.}
|
||||
|
||||
template `!=`*(x, y: untyped): untyped {.callsite.} =
|
||||
## Unequals operator. This is a shorthand for `not (x == y)`.
|
||||
not (x == y)
|
||||
|
||||
template `>=`*(x, y: untyped): untyped =
|
||||
template `>=`*(x, y: untyped): untyped {.callsite.} =
|
||||
## "is greater or equals" operator. This is the same as `y <= x`.
|
||||
y <= x
|
||||
|
||||
template `>`*(x, y: untyped): untyped =
|
||||
template `>`*(x, y: untyped): untyped {.callsite.} =
|
||||
## "is greater" operator. This is the same as `y < x`.
|
||||
y < x
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ func incl*[T](x: var set[T], y: T) {.magic: "Incl".} =
|
|||
a.incl(4)
|
||||
assert a == {1, 2, 3, 4, 5}
|
||||
|
||||
template incl*[T](x: var set[T], y: set[T]) =
|
||||
when not defined(nimHasCallsitePragma):
|
||||
{.pragma: callsite.}
|
||||
|
||||
template incl*[T](x: var set[T], y: set[T]) {.callsite.} =
|
||||
## Includes the set `y` in the set `x`.
|
||||
runnableExamples:
|
||||
var a = {1, 3, 5, 7}
|
||||
|
|
@ -27,7 +30,7 @@ func excl*[T](x: var set[T], y: T) {.magic: "Excl".} =
|
|||
b.excl(5)
|
||||
assert b == {2, 3, 6, 12, 545}
|
||||
|
||||
template excl*[T](x: var set[T], y: set[T]) =
|
||||
template excl*[T](x: var set[T], y: set[T]) {.callsite.} =
|
||||
## Excludes the set `y` from the set `x`.
|
||||
runnableExamples:
|
||||
var a = {1, 3, 5, 7}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue