system.nim: cleanup the formatting
This commit is contained in:
parent
c7298561c1
commit
a9e96888d0
1 changed files with 189 additions and 189 deletions
378
lib/system.nim
378
lib/system.nim
|
|
@ -59,13 +59,13 @@ const
|
||||||
{.push warning[GcMem]: off, warning[Uninit]: off.}
|
{.push warning[GcMem]: off, warning[Uninit]: off.}
|
||||||
{.push hints: off.}
|
{.push hints: off.}
|
||||||
|
|
||||||
proc `or` *(a, b: typedesc): typedesc {.magic: "TypeTrait", noSideEffect.}
|
proc `or`*(a, b: typedesc): typedesc {.magic: "TypeTrait", noSideEffect.}
|
||||||
## Constructs an `or` meta class
|
## Constructs an `or` meta class
|
||||||
|
|
||||||
proc `and` *(a, b: typedesc): typedesc {.magic: "TypeTrait", noSideEffect.}
|
proc `and`*(a, b: typedesc): typedesc {.magic: "TypeTrait", noSideEffect.}
|
||||||
## Constructs an `and` meta class
|
## Constructs an `and` meta class
|
||||||
|
|
||||||
proc `not` *(a: typedesc): typedesc {.magic: "TypeTrait", noSideEffect.}
|
proc `not`*(a: typedesc): typedesc {.magic: "TypeTrait", noSideEffect.}
|
||||||
## Constructs an `not` meta class
|
## Constructs an `not` meta class
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -178,7 +178,7 @@ else:
|
||||||
## Cannot be overloaded.
|
## Cannot be overloaded.
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc `not` *(x: bool): bool {.magic: "Not", noSideEffect.}
|
proc `not`*(x: bool): bool {.magic: "Not", noSideEffect.}
|
||||||
## Boolean not; returns true iff ``x == false``.
|
## Boolean not; returns true iff ``x == false``.
|
||||||
|
|
||||||
proc `and`*(x, y: bool): bool {.magic: "And", noSideEffect.}
|
proc `and`*(x, y: bool): bool {.magic: "And", noSideEffect.}
|
||||||
|
|
@ -331,7 +331,7 @@ when not defined(nimunion):
|
||||||
{.pragma: unchecked.}
|
{.pragma: unchecked.}
|
||||||
|
|
||||||
# comparison operators:
|
# comparison operators:
|
||||||
proc `==` *[Enum: enum](x, y: Enum): bool {.magic: "EqEnum", noSideEffect.}
|
proc `==`*[Enum: enum](x, y: Enum): bool {.magic: "EqEnum", noSideEffect.}
|
||||||
## Checks whether values within the *same enum* have the same underlying value
|
## Checks whether values within the *same enum* have the same underlying value
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
|
|
@ -345,59 +345,59 @@ proc `==` *[Enum: enum](x, y: Enum): bool {.magic: "EqEnum", noSideEffect.}
|
||||||
## e2 = Enum1(Place2)
|
## e2 = Enum1(Place2)
|
||||||
## echo (e1 == e2) # true
|
## echo (e1 == e2) # true
|
||||||
## echo (e1 == Place2) # raises error
|
## echo (e1 == Place2) # raises error
|
||||||
proc `==` *(x, y: pointer): bool {.magic: "EqRef", noSideEffect.}
|
proc `==`*(x, y: pointer): bool {.magic: "EqRef", noSideEffect.}
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## var # this is a wildly dangerous example
|
## var # this is a wildly dangerous example
|
||||||
## a = cast[pointer](0)
|
## a = cast[pointer](0)
|
||||||
## b = cast[pointer](nil)
|
## b = cast[pointer](nil)
|
||||||
## echo (a == b) # true due to the special meaning of `nil`/0 as a pointer
|
## echo (a == b) # true due to the special meaning of `nil`/0 as a pointer
|
||||||
proc `==` *(x, y: string): bool {.magic: "EqStr", noSideEffect.}
|
proc `==`*(x, y: string): bool {.magic: "EqStr", noSideEffect.}
|
||||||
## Checks for equality between two `string` variables
|
## Checks for equality between two `string` variables
|
||||||
|
|
||||||
proc `==` *(x, y: char): bool {.magic: "EqCh", noSideEffect.}
|
proc `==`*(x, y: char): bool {.magic: "EqCh", noSideEffect.}
|
||||||
## Checks for equality between two `char` variables
|
## Checks for equality between two `char` variables
|
||||||
proc `==` *(x, y: bool): bool {.magic: "EqB", noSideEffect.}
|
proc `==`*(x, y: bool): bool {.magic: "EqB", noSideEffect.}
|
||||||
## Checks for equality between two `bool` variables
|
## Checks for equality between two `bool` variables
|
||||||
proc `==` *[T](x, y: set[T]): bool {.magic: "EqSet", noSideEffect.}
|
proc `==`*[T](x, y: set[T]): bool {.magic: "EqSet", noSideEffect.}
|
||||||
## Checks for equality between two variables of type `set`
|
## Checks for equality between two variables of type `set`
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
## var a = {1, 2, 2, 3} # duplication in sets is ignored
|
## var a = {1, 2, 2, 3} # duplication in sets is ignored
|
||||||
## var b = {1, 2, 3}
|
## var b = {1, 2, 3}
|
||||||
## echo (a == b) # true
|
## echo (a == b) # true
|
||||||
proc `==` *[T](x, y: ref T): bool {.magic: "EqRef", noSideEffect.}
|
proc `==`*[T](x, y: ref T): bool {.magic: "EqRef", noSideEffect.}
|
||||||
## Checks that two `ref` variables refer to the same item
|
## Checks that two `ref` variables refer to the same item
|
||||||
proc `==` *[T](x, y: ptr T): bool {.magic: "EqRef", noSideEffect.}
|
proc `==`*[T](x, y: ptr T): bool {.magic: "EqRef", noSideEffect.}
|
||||||
## Checks that two `ptr` variables refer to the same item
|
## Checks that two `ptr` variables refer to the same item
|
||||||
proc `==` *[T: proc](x, y: T): bool {.magic: "EqProc", noSideEffect.}
|
proc `==`*[T: proc](x, y: T): bool {.magic: "EqProc", noSideEffect.}
|
||||||
## Checks that two `proc` variables refer to the same procedure
|
## Checks that two `proc` variables refer to the same procedure
|
||||||
|
|
||||||
proc `<=` *[Enum: enum](x, y: Enum): bool {.magic: "LeEnum", noSideEffect.}
|
proc `<=`*[Enum: enum](x, y: Enum): bool {.magic: "LeEnum", noSideEffect.}
|
||||||
proc `<=` *(x, y: string): bool {.magic: "LeStr", noSideEffect.}
|
proc `<=`*(x, y: string): bool {.magic: "LeStr", noSideEffect.}
|
||||||
proc `<=` *(x, y: char): bool {.magic: "LeCh", noSideEffect.}
|
proc `<=`*(x, y: char): bool {.magic: "LeCh", noSideEffect.}
|
||||||
proc `<=` *[T](x, y: set[T]): bool {.magic: "LeSet", noSideEffect.}
|
proc `<=`*[T](x, y: set[T]): bool {.magic: "LeSet", noSideEffect.}
|
||||||
proc `<=` *(x, y: bool): bool {.magic: "LeB", noSideEffect.}
|
proc `<=`*(x, y: bool): bool {.magic: "LeB", noSideEffect.}
|
||||||
proc `<=` *[T](x, y: ref T): bool {.magic: "LePtr", noSideEffect.}
|
proc `<=`*[T](x, y: ref T): bool {.magic: "LePtr", noSideEffect.}
|
||||||
proc `<=` *(x, y: pointer): bool {.magic: "LePtr", noSideEffect.}
|
proc `<=`*(x, y: pointer): bool {.magic: "LePtr", noSideEffect.}
|
||||||
|
|
||||||
proc `<` *[Enum: enum](x, y: Enum): bool {.magic: "LtEnum", noSideEffect.}
|
proc `<`*[Enum: enum](x, y: Enum): bool {.magic: "LtEnum", noSideEffect.}
|
||||||
proc `<` *(x, y: string): bool {.magic: "LtStr", noSideEffect.}
|
proc `<`*(x, y: string): bool {.magic: "LtStr", noSideEffect.}
|
||||||
proc `<` *(x, y: char): bool {.magic: "LtCh", noSideEffect.}
|
proc `<`*(x, y: char): bool {.magic: "LtCh", noSideEffect.}
|
||||||
proc `<` *[T](x, y: set[T]): bool {.magic: "LtSet", noSideEffect.}
|
proc `<`*[T](x, y: set[T]): bool {.magic: "LtSet", noSideEffect.}
|
||||||
proc `<` *(x, y: bool): bool {.magic: "LtB", noSideEffect.}
|
proc `<`*(x, y: bool): bool {.magic: "LtB", noSideEffect.}
|
||||||
proc `<` *[T](x, y: ref T): bool {.magic: "LtPtr", noSideEffect.}
|
proc `<`*[T](x, y: ref T): bool {.magic: "LtPtr", noSideEffect.}
|
||||||
proc `<` *[T](x, y: ptr T): bool {.magic: "LtPtr", noSideEffect.}
|
proc `<`*[T](x, y: ptr T): bool {.magic: "LtPtr", noSideEffect.}
|
||||||
proc `<` *(x, y: pointer): bool {.magic: "LtPtr", noSideEffect.}
|
proc `<`*(x, y: pointer): bool {.magic: "LtPtr", noSideEffect.}
|
||||||
|
|
||||||
template `!=` * (x, y: untyped): untyped =
|
template `!=`*(x, y: untyped): untyped =
|
||||||
## unequals operator. This is a shorthand for ``not (x == y)``.
|
## unequals operator. This is a shorthand for ``not (x == y)``.
|
||||||
not (x == y)
|
not (x == y)
|
||||||
|
|
||||||
template `>=` * (x, y: untyped): untyped =
|
template `>=`*(x, y: untyped): untyped =
|
||||||
## "is greater or equals" operator. This is the same as ``y <= x``.
|
## "is greater or equals" operator. This is the same as ``y <= x``.
|
||||||
y <= x
|
y <= x
|
||||||
|
|
||||||
template `>` * (x, y: untyped): untyped =
|
template `>`*(x, y: untyped): untyped =
|
||||||
## "is greater" operator. This is the same as ``y < x``.
|
## "is greater" operator. This is the same as ``y < x``.
|
||||||
y < x
|
y < x
|
||||||
|
|
||||||
|
|
@ -839,68 +839,68 @@ when not defined(JS):
|
||||||
## last 32 bits from `x`.
|
## last 32 bits from `x`.
|
||||||
|
|
||||||
# integer calculations:
|
# integer calculations:
|
||||||
proc `+` *(x: int): int {.magic: "UnaryPlusI", noSideEffect.}
|
proc `+`*(x: int): int {.magic: "UnaryPlusI", noSideEffect.}
|
||||||
proc `+` *(x: int8): int8 {.magic: "UnaryPlusI", noSideEffect.}
|
proc `+`*(x: int8): int8 {.magic: "UnaryPlusI", noSideEffect.}
|
||||||
proc `+` *(x: int16): int16 {.magic: "UnaryPlusI", noSideEffect.}
|
proc `+`*(x: int16): int16 {.magic: "UnaryPlusI", noSideEffect.}
|
||||||
proc `+` *(x: int32): int32 {.magic: "UnaryPlusI", noSideEffect.}
|
proc `+`*(x: int32): int32 {.magic: "UnaryPlusI", noSideEffect.}
|
||||||
proc `+` *(x: int64): int64 {.magic: "UnaryPlusI", noSideEffect.}
|
proc `+`*(x: int64): int64 {.magic: "UnaryPlusI", noSideEffect.}
|
||||||
## Unary `+` operator for an integer. Has no effect.
|
## Unary `+` operator for an integer. Has no effect.
|
||||||
|
|
||||||
proc `-` *(x: int): int {.magic: "UnaryMinusI", noSideEffect.}
|
proc `-`*(x: int): int {.magic: "UnaryMinusI", noSideEffect.}
|
||||||
proc `-` *(x: int8): int8 {.magic: "UnaryMinusI", noSideEffect.}
|
proc `-`*(x: int8): int8 {.magic: "UnaryMinusI", noSideEffect.}
|
||||||
proc `-` *(x: int16): int16 {.magic: "UnaryMinusI", noSideEffect.}
|
proc `-`*(x: int16): int16 {.magic: "UnaryMinusI", noSideEffect.}
|
||||||
proc `-` *(x: int32): int32 {.magic: "UnaryMinusI", noSideEffect.}
|
proc `-`*(x: int32): int32 {.magic: "UnaryMinusI", noSideEffect.}
|
||||||
proc `-` *(x: int64): int64 {.magic: "UnaryMinusI64", noSideEffect.}
|
proc `-`*(x: int64): int64 {.magic: "UnaryMinusI64", noSideEffect.}
|
||||||
## Unary `-` operator for an integer. Negates `x`.
|
## Unary `-` operator for an integer. Negates `x`.
|
||||||
|
|
||||||
proc `not` *(x: int): int {.magic: "BitnotI", noSideEffect.}
|
proc `not`*(x: int): int {.magic: "BitnotI", noSideEffect.}
|
||||||
proc `not` *(x: int8): int8 {.magic: "BitnotI", noSideEffect.}
|
proc `not`*(x: int8): int8 {.magic: "BitnotI", noSideEffect.}
|
||||||
proc `not` *(x: int16): int16 {.magic: "BitnotI", noSideEffect.}
|
proc `not`*(x: int16): int16 {.magic: "BitnotI", noSideEffect.}
|
||||||
proc `not` *(x: int32): int32 {.magic: "BitnotI", noSideEffect.}
|
proc `not`*(x: int32): int32 {.magic: "BitnotI", noSideEffect.}
|
||||||
## computes the `bitwise complement` of the integer `x`.
|
## computes the `bitwise complement` of the integer `x`.
|
||||||
|
|
||||||
when defined(nimnomagic64):
|
when defined(nimnomagic64):
|
||||||
proc `not` *(x: int64): int64 {.magic: "BitnotI", noSideEffect.}
|
proc `not`*(x: int64): int64 {.magic: "BitnotI", noSideEffect.}
|
||||||
else:
|
else:
|
||||||
proc `not` *(x: int64): int64 {.magic: "BitnotI64", noSideEffect.}
|
proc `not`*(x: int64): int64 {.magic: "BitnotI64", noSideEffect.}
|
||||||
|
|
||||||
proc `+` *(x, y: int): int {.magic: "AddI", noSideEffect.}
|
proc `+`*(x, y: int): int {.magic: "AddI", noSideEffect.}
|
||||||
proc `+` *(x, y: int8): int8 {.magic: "AddI", noSideEffect.}
|
proc `+`*(x, y: int8): int8 {.magic: "AddI", noSideEffect.}
|
||||||
proc `+` *(x, y: int16): int16 {.magic: "AddI", noSideEffect.}
|
proc `+`*(x, y: int16): int16 {.magic: "AddI", noSideEffect.}
|
||||||
proc `+` *(x, y: int32): int32 {.magic: "AddI", noSideEffect.}
|
proc `+`*(x, y: int32): int32 {.magic: "AddI", noSideEffect.}
|
||||||
## Binary `+` operator for an integer.
|
## Binary `+` operator for an integer.
|
||||||
|
|
||||||
when defined(nimnomagic64):
|
when defined(nimnomagic64):
|
||||||
proc `+` *(x, y: int64): int64 {.magic: "AddI", noSideEffect.}
|
proc `+`*(x, y: int64): int64 {.magic: "AddI", noSideEffect.}
|
||||||
else:
|
else:
|
||||||
proc `+` *(x, y: int64): int64 {.magic: "AddI64", noSideEffect.}
|
proc `+`*(x, y: int64): int64 {.magic: "AddI64", noSideEffect.}
|
||||||
|
|
||||||
proc `-` *(x, y: int): int {.magic: "SubI", noSideEffect.}
|
proc `-`*(x, y: int): int {.magic: "SubI", noSideEffect.}
|
||||||
proc `-` *(x, y: int8): int8 {.magic: "SubI", noSideEffect.}
|
proc `-`*(x, y: int8): int8 {.magic: "SubI", noSideEffect.}
|
||||||
proc `-` *(x, y: int16): int16 {.magic: "SubI", noSideEffect.}
|
proc `-`*(x, y: int16): int16 {.magic: "SubI", noSideEffect.}
|
||||||
proc `-` *(x, y: int32): int32 {.magic: "SubI", noSideEffect.}
|
proc `-`*(x, y: int32): int32 {.magic: "SubI", noSideEffect.}
|
||||||
## Binary `-` operator for an integer.
|
## Binary `-` operator for an integer.
|
||||||
|
|
||||||
when defined(nimnomagic64):
|
when defined(nimnomagic64):
|
||||||
proc `-` *(x, y: int64): int64 {.magic: "SubI", noSideEffect.}
|
proc `-`*(x, y: int64): int64 {.magic: "SubI", noSideEffect.}
|
||||||
else:
|
else:
|
||||||
proc `-` *(x, y: int64): int64 {.magic: "SubI64", noSideEffect.}
|
proc `-`*(x, y: int64): int64 {.magic: "SubI64", noSideEffect.}
|
||||||
|
|
||||||
proc `*` *(x, y: int): int {.magic: "MulI", noSideEffect.}
|
proc `*`*(x, y: int): int {.magic: "MulI", noSideEffect.}
|
||||||
proc `*` *(x, y: int8): int8 {.magic: "MulI", noSideEffect.}
|
proc `*`*(x, y: int8): int8 {.magic: "MulI", noSideEffect.}
|
||||||
proc `*` *(x, y: int16): int16 {.magic: "MulI", noSideEffect.}
|
proc `*`*(x, y: int16): int16 {.magic: "MulI", noSideEffect.}
|
||||||
proc `*` *(x, y: int32): int32 {.magic: "MulI", noSideEffect.}
|
proc `*`*(x, y: int32): int32 {.magic: "MulI", noSideEffect.}
|
||||||
## Binary `*` operator for an integer.
|
## Binary `*` operator for an integer.
|
||||||
|
|
||||||
when defined(nimnomagic64):
|
when defined(nimnomagic64):
|
||||||
proc `*` *(x, y: int64): int64 {.magic: "MulI", noSideEffect.}
|
proc `*`*(x, y: int64): int64 {.magic: "MulI", noSideEffect.}
|
||||||
else:
|
else:
|
||||||
proc `*` *(x, y: int64): int64 {.magic: "MulI64", noSideEffect.}
|
proc `*`*(x, y: int64): int64 {.magic: "MulI64", noSideEffect.}
|
||||||
|
|
||||||
proc `div` *(x, y: int): int {.magic: "DivI", noSideEffect.}
|
proc `div`*(x, y: int): int {.magic: "DivI", noSideEffect.}
|
||||||
proc `div` *(x, y: int8): int8 {.magic: "DivI", noSideEffect.}
|
proc `div`*(x, y: int8): int8 {.magic: "DivI", noSideEffect.}
|
||||||
proc `div` *(x, y: int16): int16 {.magic: "DivI", noSideEffect.}
|
proc `div`*(x, y: int16): int16 {.magic: "DivI", noSideEffect.}
|
||||||
proc `div` *(x, y: int32): int32 {.magic: "DivI", noSideEffect.}
|
proc `div`*(x, y: int32): int32 {.magic: "DivI", noSideEffect.}
|
||||||
## computes the integer division. This is roughly the same as
|
## computes the integer division. This is roughly the same as
|
||||||
## ``trunc(x/y)``.
|
## ``trunc(x/y)``.
|
||||||
##
|
##
|
||||||
|
|
@ -911,14 +911,14 @@ proc `div` *(x, y: int32): int32 {.magic: "DivI", noSideEffect.}
|
||||||
## 7 div 5 == 1
|
## 7 div 5 == 1
|
||||||
|
|
||||||
when defined(nimnomagic64):
|
when defined(nimnomagic64):
|
||||||
proc `div` *(x, y: int64): int64 {.magic: "DivI", noSideEffect.}
|
proc `div`*(x, y: int64): int64 {.magic: "DivI", noSideEffect.}
|
||||||
else:
|
else:
|
||||||
proc `div` *(x, y: int64): int64 {.magic: "DivI64", noSideEffect.}
|
proc `div`*(x, y: int64): int64 {.magic: "DivI64", noSideEffect.}
|
||||||
|
|
||||||
proc `mod` *(x, y: int): int {.magic: "ModI", noSideEffect.}
|
proc `mod`*(x, y: int): int {.magic: "ModI", noSideEffect.}
|
||||||
proc `mod` *(x, y: int8): int8 {.magic: "ModI", noSideEffect.}
|
proc `mod`*(x, y: int8): int8 {.magic: "ModI", noSideEffect.}
|
||||||
proc `mod` *(x, y: int16): int16 {.magic: "ModI", noSideEffect.}
|
proc `mod`*(x, y: int16): int16 {.magic: "ModI", noSideEffect.}
|
||||||
proc `mod` *(x, y: int32): int32 {.magic: "ModI", noSideEffect.}
|
proc `mod`*(x, y: int32): int32 {.magic: "ModI", noSideEffect.}
|
||||||
## computes the integer modulo operation (remainder).
|
## computes the integer modulo operation (remainder).
|
||||||
## This is the same as
|
## This is the same as
|
||||||
## ``x - (x div y) * y``.
|
## ``x - (x div y) * y``.
|
||||||
|
|
@ -927,16 +927,16 @@ proc `mod` *(x, y: int32): int32 {.magic: "ModI", noSideEffect.}
|
||||||
## (7 mod 5) == 2
|
## (7 mod 5) == 2
|
||||||
|
|
||||||
when defined(nimnomagic64):
|
when defined(nimnomagic64):
|
||||||
proc `mod` *(x, y: int64): int64 {.magic: "ModI", noSideEffect.}
|
proc `mod`*(x, y: int64): int64 {.magic: "ModI", noSideEffect.}
|
||||||
else:
|
else:
|
||||||
proc `mod` *(x, y: int64): int64 {.magic: "ModI64", noSideEffect.}
|
proc `mod`*(x, y: int64): int64 {.magic: "ModI64", noSideEffect.}
|
||||||
|
|
||||||
when defined(nimNewShiftOps):
|
when defined(nimNewShiftOps):
|
||||||
proc `shr` *(x: int, y: SomeInteger): int {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x: int, y: SomeInteger): int {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x: int8, y: SomeInteger): int8 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x: int8, y: SomeInteger): int8 {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x: int16, y: SomeInteger): int16 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x: int16, y: SomeInteger): int16 {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x: int32, y: SomeInteger): int32 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x: int32, y: SomeInteger): int32 {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x: int64, y: SomeInteger): int64 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x: int64, y: SomeInteger): int64 {.magic: "ShrI", noSideEffect.}
|
||||||
## computes the `shift right` operation of `x` and `y`, filling
|
## computes the `shift right` operation of `x` and `y`, filling
|
||||||
## vacant bit positions with zeros.
|
## vacant bit positions with zeros.
|
||||||
##
|
##
|
||||||
|
|
@ -946,121 +946,121 @@ when defined(nimNewShiftOps):
|
||||||
## 0b0000_0001'i8 shr 1 == 0b0000_0000'i8
|
## 0b0000_0001'i8 shr 1 == 0b0000_0000'i8
|
||||||
|
|
||||||
|
|
||||||
proc `shl` *(x: int, y: SomeInteger): int {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x: int, y: SomeInteger): int {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x: int8, y: SomeInteger): int8 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x: int8, y: SomeInteger): int8 {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x: int16, y: SomeInteger): int16 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x: int16, y: SomeInteger): int16 {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x: int32, y: SomeInteger): int32 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x: int32, y: SomeInteger): int32 {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x: int64, y: SomeInteger): int64 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x: int64, y: SomeInteger): int64 {.magic: "ShlI", noSideEffect.}
|
||||||
## computes the `shift left` operation of `x` and `y`.
|
## computes the `shift left` operation of `x` and `y`.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## 1'i32 shl 4 == 0x0000_0010
|
## 1'i32 shl 4 == 0x0000_0010
|
||||||
## 1'i64 shl 4 == 0x0000_0000_0000_0010
|
## 1'i64 shl 4 == 0x0000_0000_0000_0010
|
||||||
else:
|
else:
|
||||||
proc `shr` *(x, y: int): int {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x, y: int): int {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x, y: int8): int8 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x, y: int8): int8 {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x, y: int16): int16 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x, y: int16): int16 {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x, y: int32): int32 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x, y: int32): int32 {.magic: "ShrI", noSideEffect.}
|
||||||
proc `shr` *(x, y: int64): int64 {.magic: "ShrI", noSideEffect.}
|
proc `shr`*(x, y: int64): int64 {.magic: "ShrI", noSideEffect.}
|
||||||
|
|
||||||
proc `shl` *(x, y: int): int {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x, y: int): int {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x, y: int8): int8 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x, y: int8): int8 {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x, y: int16): int16 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x, y: int16): int16 {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x, y: int32): int32 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x, y: int32): int32 {.magic: "ShlI", noSideEffect.}
|
||||||
proc `shl` *(x, y: int64): int64 {.magic: "ShlI", noSideEffect.}
|
proc `shl`*(x, y: int64): int64 {.magic: "ShlI", noSideEffect.}
|
||||||
|
|
||||||
proc `and` *(x, y: int): int {.magic: "BitandI", noSideEffect.}
|
proc `and`*(x, y: int): int {.magic: "BitandI", noSideEffect.}
|
||||||
proc `and` *(x, y: int8): int8 {.magic: "BitandI", noSideEffect.}
|
proc `and`*(x, y: int8): int8 {.magic: "BitandI", noSideEffect.}
|
||||||
proc `and` *(x, y: int16): int16 {.magic: "BitandI", noSideEffect.}
|
proc `and`*(x, y: int16): int16 {.magic: "BitandI", noSideEffect.}
|
||||||
proc `and` *(x, y: int32): int32 {.magic: "BitandI", noSideEffect.}
|
proc `and`*(x, y: int32): int32 {.magic: "BitandI", noSideEffect.}
|
||||||
proc `and` *(x, y: int64): int64 {.magic: "BitandI", noSideEffect.}
|
proc `and`*(x, y: int64): int64 {.magic: "BitandI", noSideEffect.}
|
||||||
## computes the `bitwise and` of numbers `x` and `y`.
|
## computes the `bitwise and` of numbers `x` and `y`.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## (0xffff'i16 and 0x0010'i16) == 0x0010
|
## (0xffff'i16 and 0x0010'i16) == 0x0010
|
||||||
|
|
||||||
proc `or` *(x, y: int): int {.magic: "BitorI", noSideEffect.}
|
proc `or`*(x, y: int): int {.magic: "BitorI", noSideEffect.}
|
||||||
proc `or` *(x, y: int8): int8 {.magic: "BitorI", noSideEffect.}
|
proc `or`*(x, y: int8): int8 {.magic: "BitorI", noSideEffect.}
|
||||||
proc `or` *(x, y: int16): int16 {.magic: "BitorI", noSideEffect.}
|
proc `or`*(x, y: int16): int16 {.magic: "BitorI", noSideEffect.}
|
||||||
proc `or` *(x, y: int32): int32 {.magic: "BitorI", noSideEffect.}
|
proc `or`*(x, y: int32): int32 {.magic: "BitorI", noSideEffect.}
|
||||||
proc `or` *(x, y: int64): int64 {.magic: "BitorI", noSideEffect.}
|
proc `or`*(x, y: int64): int64 {.magic: "BitorI", noSideEffect.}
|
||||||
## computes the `bitwise or` of numbers `x` and `y`.
|
## computes the `bitwise or` of numbers `x` and `y`.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## (0x0005'i16 or 0x0010'i16) == 0x0015
|
## (0x0005'i16 or 0x0010'i16) == 0x0015
|
||||||
|
|
||||||
proc `xor` *(x, y: int): int {.magic: "BitxorI", noSideEffect.}
|
proc `xor`*(x, y: int): int {.magic: "BitxorI", noSideEffect.}
|
||||||
proc `xor` *(x, y: int8): int8 {.magic: "BitxorI", noSideEffect.}
|
proc `xor`*(x, y: int8): int8 {.magic: "BitxorI", noSideEffect.}
|
||||||
proc `xor` *(x, y: int16): int16 {.magic: "BitxorI", noSideEffect.}
|
proc `xor`*(x, y: int16): int16 {.magic: "BitxorI", noSideEffect.}
|
||||||
proc `xor` *(x, y: int32): int32 {.magic: "BitxorI", noSideEffect.}
|
proc `xor`*(x, y: int32): int32 {.magic: "BitxorI", noSideEffect.}
|
||||||
proc `xor` *(x, y: int64): int64 {.magic: "BitxorI", noSideEffect.}
|
proc `xor`*(x, y: int64): int64 {.magic: "BitxorI", noSideEffect.}
|
||||||
## computes the `bitwise xor` of numbers `x` and `y`.
|
## computes the `bitwise xor` of numbers `x` and `y`.
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## (0x1011'i16 xor 0x0101'i16) == 0x1110
|
## (0x1011'i16 xor 0x0101'i16) == 0x1110
|
||||||
|
|
||||||
proc `==` *(x, y: int): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: int): bool {.magic: "EqI", noSideEffect.}
|
||||||
proc `==` *(x, y: int8): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: int8): bool {.magic: "EqI", noSideEffect.}
|
||||||
proc `==` *(x, y: int16): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: int16): bool {.magic: "EqI", noSideEffect.}
|
||||||
proc `==` *(x, y: int32): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: int32): bool {.magic: "EqI", noSideEffect.}
|
||||||
proc `==` *(x, y: int64): bool {.magic: "EqI", noSideEffect.}
|
proc `==`*(x, y: int64): bool {.magic: "EqI", noSideEffect.}
|
||||||
## Compares two integers for equality.
|
## Compares two integers for equality.
|
||||||
|
|
||||||
proc `<=` *(x, y: int): bool {.magic: "LeI", noSideEffect.}
|
proc `<=`*(x, y: int): bool {.magic: "LeI", noSideEffect.}
|
||||||
proc `<=` *(x, y: int8): bool {.magic: "LeI", noSideEffect.}
|
proc `<=`*(x, y: int8): bool {.magic: "LeI", noSideEffect.}
|
||||||
proc `<=` *(x, y: int16): bool {.magic: "LeI", noSideEffect.}
|
proc `<=`*(x, y: int16): bool {.magic: "LeI", noSideEffect.}
|
||||||
proc `<=` *(x, y: int32): bool {.magic: "LeI", noSideEffect.}
|
proc `<=`*(x, y: int32): bool {.magic: "LeI", noSideEffect.}
|
||||||
proc `<=` *(x, y: int64): bool {.magic: "LeI", noSideEffect.}
|
proc `<=`*(x, y: int64): bool {.magic: "LeI", noSideEffect.}
|
||||||
## Returns true iff `x` is less than or equal to `y`.
|
## Returns true iff `x` is less than or equal to `y`.
|
||||||
|
|
||||||
proc `<` *(x, y: int): bool {.magic: "LtI", noSideEffect.}
|
proc `<`*(x, y: int): bool {.magic: "LtI", noSideEffect.}
|
||||||
proc `<` *(x, y: int8): bool {.magic: "LtI", noSideEffect.}
|
proc `<`*(x, y: int8): bool {.magic: "LtI", noSideEffect.}
|
||||||
proc `<` *(x, y: int16): bool {.magic: "LtI", noSideEffect.}
|
proc `<`*(x, y: int16): bool {.magic: "LtI", noSideEffect.}
|
||||||
proc `<` *(x, y: int32): bool {.magic: "LtI", noSideEffect.}
|
proc `<`*(x, y: int32): bool {.magic: "LtI", noSideEffect.}
|
||||||
proc `<` *(x, y: int64): bool {.magic: "LtI", noSideEffect.}
|
proc `<`*(x, y: int64): bool {.magic: "LtI", noSideEffect.}
|
||||||
## Returns true iff `x` is less than `y`.
|
## Returns true iff `x` is less than `y`.
|
||||||
|
|
||||||
type
|
type
|
||||||
IntMax32 = int|int8|int16|int32
|
IntMax32 = int|int8|int16|int32
|
||||||
|
|
||||||
proc `+%` *(x, y: IntMax32): IntMax32 {.magic: "AddU", noSideEffect.}
|
proc `+%`*(x, y: IntMax32): IntMax32 {.magic: "AddU", noSideEffect.}
|
||||||
proc `+%` *(x, y: int64): int64 {.magic: "AddU", noSideEffect.}
|
proc `+%`*(x, y: int64): int64 {.magic: "AddU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and adds them. The result is truncated to
|
## treats `x` and `y` as unsigned and adds them. The result is truncated to
|
||||||
## fit into the result. This implements modulo arithmetic. No overflow
|
## fit into the result. This implements modulo arithmetic. No overflow
|
||||||
## errors are possible.
|
## errors are possible.
|
||||||
|
|
||||||
proc `-%` *(x, y: IntMax32): IntMax32 {.magic: "SubU", noSideEffect.}
|
proc `-%`*(x, y: IntMax32): IntMax32 {.magic: "SubU", noSideEffect.}
|
||||||
proc `-%` *(x, y: int64): int64 {.magic: "SubU", noSideEffect.}
|
proc `-%`*(x, y: int64): int64 {.magic: "SubU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and subtracts them. The result is
|
## treats `x` and `y` as unsigned and subtracts them. The result is
|
||||||
## truncated to fit into the result. This implements modulo arithmetic.
|
## truncated to fit into the result. This implements modulo arithmetic.
|
||||||
## No overflow errors are possible.
|
## No overflow errors are possible.
|
||||||
|
|
||||||
proc `*%` *(x, y: IntMax32): IntMax32 {.magic: "MulU", noSideEffect.}
|
proc `*%`*(x, y: IntMax32): IntMax32 {.magic: "MulU", noSideEffect.}
|
||||||
proc `*%` *(x, y: int64): int64 {.magic: "MulU", noSideEffect.}
|
proc `*%`*(x, y: int64): int64 {.magic: "MulU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and multiplies them. The result is
|
## treats `x` and `y` as unsigned and multiplies them. The result is
|
||||||
## truncated to fit into the result. This implements modulo arithmetic.
|
## truncated to fit into the result. This implements modulo arithmetic.
|
||||||
## No overflow errors are possible.
|
## No overflow errors are possible.
|
||||||
|
|
||||||
proc `/%` *(x, y: IntMax32): IntMax32 {.magic: "DivU", noSideEffect.}
|
proc `/%`*(x, y: IntMax32): IntMax32 {.magic: "DivU", noSideEffect.}
|
||||||
proc `/%` *(x, y: int64): int64 {.magic: "DivU", noSideEffect.}
|
proc `/%`*(x, y: int64): int64 {.magic: "DivU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and divides them. The result is
|
## treats `x` and `y` as unsigned and divides them. The result is
|
||||||
## truncated to fit into the result. This implements modulo arithmetic.
|
## truncated to fit into the result. This implements modulo arithmetic.
|
||||||
## No overflow errors are possible.
|
## No overflow errors are possible.
|
||||||
|
|
||||||
proc `%%` *(x, y: IntMax32): IntMax32 {.magic: "ModU", noSideEffect.}
|
proc `%%`*(x, y: IntMax32): IntMax32 {.magic: "ModU", noSideEffect.}
|
||||||
proc `%%` *(x, y: int64): int64 {.magic: "ModU", noSideEffect.}
|
proc `%%`*(x, y: int64): int64 {.magic: "ModU", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
|
## treats `x` and `y` as unsigned and compute the modulo of `x` and `y`.
|
||||||
## The result is truncated to fit into the result.
|
## The result is truncated to fit into the result.
|
||||||
## This implements modulo arithmetic.
|
## This implements modulo arithmetic.
|
||||||
## No overflow errors are possible.
|
## No overflow errors are possible.
|
||||||
|
|
||||||
proc `<=%` *(x, y: IntMax32): bool {.magic: "LeU", noSideEffect.}
|
proc `<=%`*(x, y: IntMax32): bool {.magic: "LeU", noSideEffect.}
|
||||||
proc `<=%` *(x, y: int64): bool {.magic: "LeU64", noSideEffect.}
|
proc `<=%`*(x, y: int64): bool {.magic: "LeU64", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and compares them.
|
## treats `x` and `y` as unsigned and compares them.
|
||||||
## Returns true iff ``unsigned(x) <= unsigned(y)``.
|
## Returns true iff ``unsigned(x) <= unsigned(y)``.
|
||||||
|
|
||||||
proc `<%` *(x, y: IntMax32): bool {.magic: "LtU", noSideEffect.}
|
proc `<%`*(x, y: IntMax32): bool {.magic: "LtU", noSideEffect.}
|
||||||
proc `<%` *(x, y: int64): bool {.magic: "LtU64", noSideEffect.}
|
proc `<%`*(x, y: int64): bool {.magic: "LtU64", noSideEffect.}
|
||||||
## treats `x` and `y` as unsigned and compares them.
|
## treats `x` and `y` as unsigned and compares them.
|
||||||
## Returns true iff ``unsigned(x) < unsigned(y)``.
|
## Returns true iff ``unsigned(x) < unsigned(y)``.
|
||||||
|
|
||||||
|
|
@ -1124,35 +1124,35 @@ proc `<`*[T: SomeUnsignedInt](x, y: T): bool {.magic: "LtU", noSideEffect.}
|
||||||
## Returns true iff ``unsigned(x) < unsigned(y)``.
|
## Returns true iff ``unsigned(x) < unsigned(y)``.
|
||||||
|
|
||||||
# floating point operations:
|
# floating point operations:
|
||||||
proc `+` *(x: float32): float32 {.magic: "UnaryPlusF64", noSideEffect.}
|
proc `+`*(x: float32): float32 {.magic: "UnaryPlusF64", noSideEffect.}
|
||||||
proc `-` *(x: float32): float32 {.magic: "UnaryMinusF64", noSideEffect.}
|
proc `-`*(x: float32): float32 {.magic: "UnaryMinusF64", noSideEffect.}
|
||||||
proc `+` *(x, y: float32): float32 {.magic: "AddF64", noSideEffect.}
|
proc `+`*(x, y: float32): float32 {.magic: "AddF64", noSideEffect.}
|
||||||
proc `-` *(x, y: float32): float32 {.magic: "SubF64", noSideEffect.}
|
proc `-`*(x, y: float32): float32 {.magic: "SubF64", noSideEffect.}
|
||||||
proc `*` *(x, y: float32): float32 {.magic: "MulF64", noSideEffect.}
|
proc `*`*(x, y: float32): float32 {.magic: "MulF64", noSideEffect.}
|
||||||
proc `/` *(x, y: float32): float32 {.magic: "DivF64", noSideEffect.}
|
proc `/`*(x, y: float32): float32 {.magic: "DivF64", noSideEffect.}
|
||||||
|
|
||||||
proc `+` *(x: float): float {.magic: "UnaryPlusF64", noSideEffect.}
|
proc `+`*(x: float): float {.magic: "UnaryPlusF64", noSideEffect.}
|
||||||
proc `-` *(x: float): float {.magic: "UnaryMinusF64", noSideEffect.}
|
proc `-`*(x: float): float {.magic: "UnaryMinusF64", noSideEffect.}
|
||||||
proc `+` *(x, y: float): float {.magic: "AddF64", noSideEffect.}
|
proc `+`*(x, y: float): float {.magic: "AddF64", noSideEffect.}
|
||||||
proc `-` *(x, y: float): float {.magic: "SubF64", noSideEffect.}
|
proc `-`*(x, y: float): float {.magic: "SubF64", noSideEffect.}
|
||||||
proc `*` *(x, y: float): float {.magic: "MulF64", noSideEffect.}
|
proc `*`*(x, y: float): float {.magic: "MulF64", noSideEffect.}
|
||||||
proc `/` *(x, y: float): float {.magic: "DivF64", noSideEffect.}
|
proc `/`*(x, y: float): float {.magic: "DivF64", noSideEffect.}
|
||||||
## computes the floating point division
|
## computes the floating point division
|
||||||
|
|
||||||
proc `==` *(x, y: float32): bool {.magic: "EqF64", noSideEffect.}
|
proc `==`*(x, y: float32): bool {.magic: "EqF64", noSideEffect.}
|
||||||
proc `<=` *(x, y: float32): bool {.magic: "LeF64", noSideEffect.}
|
proc `<=`*(x, y: float32): bool {.magic: "LeF64", noSideEffect.}
|
||||||
proc `<` *(x, y: float32): bool {.magic: "LtF64", noSideEffect.}
|
proc `<` *(x, y: float32): bool {.magic: "LtF64", noSideEffect.}
|
||||||
|
|
||||||
proc `==` *(x, y: float): bool {.magic: "EqF64", noSideEffect.}
|
proc `==`*(x, y: float): bool {.magic: "EqF64", noSideEffect.}
|
||||||
proc `<=` *(x, y: float): bool {.magic: "LeF64", noSideEffect.}
|
proc `<=`*(x, y: float): bool {.magic: "LeF64", noSideEffect.}
|
||||||
proc `<` *(x, y: float): bool {.magic: "LtF64", noSideEffect.}
|
proc `<`*(x, y: float): bool {.magic: "LtF64", noSideEffect.}
|
||||||
|
|
||||||
# set operators
|
# set operators
|
||||||
proc `*` *[T](x, y: set[T]): set[T] {.magic: "MulSet", noSideEffect.}
|
proc `*`*[T](x, y: set[T]): set[T] {.magic: "MulSet", noSideEffect.}
|
||||||
## This operator computes the intersection of two sets.
|
## This operator computes the intersection of two sets.
|
||||||
proc `+` *[T](x, y: set[T]): set[T] {.magic: "PlusSet", noSideEffect.}
|
proc `+`*[T](x, y: set[T]): set[T] {.magic: "PlusSet", noSideEffect.}
|
||||||
## This operator computes the union of two sets.
|
## This operator computes the union of two sets.
|
||||||
proc `-` *[T](x, y: set[T]): set[T] {.magic: "MinusSet", noSideEffect.}
|
proc `-`*[T](x, y: set[T]): set[T] {.magic: "MinusSet", noSideEffect.}
|
||||||
## This operator computes the difference of two sets.
|
## This operator computes the difference of two sets.
|
||||||
|
|
||||||
proc contains*[T](x: set[T], y: T): bool {.magic: "InSet", noSideEffect.}
|
proc contains*[T](x: set[T], y: T): bool {.magic: "InSet", noSideEffect.}
|
||||||
|
|
@ -1184,20 +1184,20 @@ proc contains*[U, V, W](s: HSlice[U, V], value: W): bool {.noSideEffect, inline.
|
||||||
## assert((1..3).contains(4) == false)
|
## assert((1..3).contains(4) == false)
|
||||||
result = s.a <= value and value <= s.b
|
result = s.a <= value and value <= s.b
|
||||||
|
|
||||||
template `in` * (x, y: untyped): untyped {.dirty.} = contains(y, x)
|
template `in`*(x, y: untyped): untyped {.dirty.} = contains(y, x)
|
||||||
## Sugar for contains
|
## Sugar for contains
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## assert(1 in (1..3) == true)
|
## assert(1 in (1..3) == true)
|
||||||
## assert(5 in (1..3) == false)
|
## assert(5 in (1..3) == false)
|
||||||
template `notin` * (x, y: untyped): untyped {.dirty.} = not contains(y, x)
|
template `notin`*(x, y: untyped): untyped {.dirty.} = not contains(y, x)
|
||||||
## Sugar for not containing
|
## Sugar for not containing
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## assert(1 notin (1..3) == false)
|
## assert(1 notin (1..3) == false)
|
||||||
## assert(5 notin (1..3) == true)
|
## assert(5 notin (1..3) == true)
|
||||||
|
|
||||||
proc `is` *[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
|
proc `is`*[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
|
||||||
## Checks if T is of the same type as S
|
## Checks if T is of the same type as S
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -1209,12 +1209,12 @@ proc `is` *[T, S](x: T, y: S): bool {.magic: "Is", noSideEffect.}
|
||||||
##
|
##
|
||||||
## assert(test[int](3) == 3)
|
## assert(test[int](3) == 3)
|
||||||
## assert(test[string]("xyz") == 0)
|
## assert(test[string]("xyz") == 0)
|
||||||
template `isnot` *(x, y: untyped): untyped = not (x is y)
|
template `isnot`*(x, y: untyped): untyped = not (x is y)
|
||||||
## Negated version of `is`. Equivalent to ``not(x is y)``.
|
## Negated version of `is`. Equivalent to ``not(x is y)``.
|
||||||
|
|
||||||
proc `of` *[T, S](x: typeDesc[T], y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
proc `of`*[T, S](x: typeDesc[T], y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
||||||
proc `of` *[T, S](x: T, y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
proc `of`*[T, S](x: T, y: typeDesc[S]): bool {.magic: "Of", noSideEffect.}
|
||||||
proc `of` *[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.}
|
proc `of`*[T, S](x: T, y: S): bool {.magic: "Of", noSideEffect.}
|
||||||
## Checks if `x` has a type of `y`
|
## Checks if `x` has a type of `y`
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
|
|
@ -1237,7 +1237,7 @@ proc cmp*[T](x, y: T): int {.procvar.} =
|
||||||
proc cmp*(x, y: string): int {.noSideEffect, procvar.}
|
proc cmp*(x, y: string): int {.noSideEffect, procvar.}
|
||||||
## Compare proc for strings. More efficient than the generic version.
|
## Compare proc for strings. More efficient than the generic version.
|
||||||
|
|
||||||
proc `@` * [IDX, T](a: array[IDX, T]): seq[T] {.
|
proc `@`* [IDX, T](a: array[IDX, T]): seq[T] {.
|
||||||
magic: "ArrToSeq", nosideeffect.}
|
magic: "ArrToSeq", nosideeffect.}
|
||||||
## turns an array into a sequence. This most often useful for constructing
|
## turns an array into a sequence. This most often useful for constructing
|
||||||
## sequences with the array constructor: ``@[1, 2, 3]`` has the type
|
## sequences with the array constructor: ``@[1, 2, 3]`` has the type
|
||||||
|
|
@ -1275,25 +1275,25 @@ proc newStringOfCap*(cap: Natural): string {.
|
||||||
## procedure exists only for optimization purposes; the same effect can
|
## procedure exists only for optimization purposes; the same effect can
|
||||||
## be achieved with the ``&`` operator or with ``add``.
|
## be achieved with the ``&`` operator or with ``add``.
|
||||||
|
|
||||||
proc `&` * (x: string, y: char): string {.
|
proc `&`*(x: string, y: char): string {.
|
||||||
magic: "ConStrStr", noSideEffect, merge.}
|
magic: "ConStrStr", noSideEffect, merge.}
|
||||||
## Concatenates `x` with `y`
|
## Concatenates `x` with `y`
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## assert("ab" & 'c' == "abc")
|
## assert("ab" & 'c' == "abc")
|
||||||
proc `&` * (x, y: char): string {.
|
proc `&`*(x, y: char): string {.
|
||||||
magic: "ConStrStr", noSideEffect, merge.}
|
magic: "ConStrStr", noSideEffect, merge.}
|
||||||
## Concatenates `x` and `y` into a string
|
## Concatenates `x` and `y` into a string
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## assert('a' & 'b' == "ab")
|
## assert('a' & 'b' == "ab")
|
||||||
proc `&` * (x, y: string): string {.
|
proc `&`*(x, y: string): string {.
|
||||||
magic: "ConStrStr", noSideEffect, merge.}
|
magic: "ConStrStr", noSideEffect, merge.}
|
||||||
## Concatenates `x` and `y`
|
## Concatenates `x` and `y`
|
||||||
##
|
##
|
||||||
## .. code-block:: Nim
|
## .. code-block:: Nim
|
||||||
## assert("ab" & "cd" == "abcd")
|
## assert("ab" & "cd" == "abcd")
|
||||||
proc `&` * (x: char, y: string): string {.
|
proc `&`*(x: char, y: string): string {.
|
||||||
magic: "ConStrStr", noSideEffect, merge.}
|
magic: "ConStrStr", noSideEffect, merge.}
|
||||||
## Concatenates `x` with `y`
|
## Concatenates `x` with `y`
|
||||||
##
|
##
|
||||||
|
|
@ -1863,11 +1863,11 @@ when not defined(js) and not defined(booting) and defined(nimTrMacros):
|
||||||
# unnecessary slow down in this case.
|
# unnecessary slow down in this case.
|
||||||
swap(cast[ptr pointer](addr arr[a])[], cast[ptr pointer](addr arr[b])[])
|
swap(cast[ptr pointer](addr arr[a])[], cast[ptr pointer](addr arr[b])[])
|
||||||
|
|
||||||
template `>=%` *(x, y: untyped): untyped = y <=% x
|
template `>=%`*(x, y: untyped): untyped = y <=% x
|
||||||
## treats `x` and `y` as unsigned and compares them.
|
## treats `x` and `y` as unsigned and compares them.
|
||||||
## Returns true iff ``unsigned(x) >= unsigned(y)``.
|
## Returns true iff ``unsigned(x) >= unsigned(y)``.
|
||||||
|
|
||||||
template `>%` *(x, y: untyped): untyped = y <% x
|
template `>%`*(x, y: untyped): untyped = y <% x
|
||||||
## treats `x` and `y` as unsigned and compares them.
|
## treats `x` and `y` as unsigned and compares them.
|
||||||
## Returns true iff ``unsigned(x) > unsigned(y)``.
|
## Returns true iff ``unsigned(x) > unsigned(y)``.
|
||||||
|
|
||||||
|
|
@ -1882,32 +1882,32 @@ proc `$`*(x: int64): string {.magic: "Int64ToStr", noSideEffect.}
|
||||||
|
|
||||||
when not defined(nimscript):
|
when not defined(nimscript):
|
||||||
when not defined(JS) and hasAlloc:
|
when not defined(JS) and hasAlloc:
|
||||||
proc `$` *(x: uint64): string {.noSideEffect.}
|
proc `$`*(x: uint64): string {.noSideEffect.}
|
||||||
## The stringify operator for an unsigned integer argument. Returns `x`
|
## The stringify operator for an unsigned integer argument. Returns `x`
|
||||||
## converted to a decimal string.
|
## converted to a decimal string.
|
||||||
|
|
||||||
proc `$` *(x: float): string {.magic: "FloatToStr", noSideEffect.}
|
proc `$`*(x: float): string {.magic: "FloatToStr", noSideEffect.}
|
||||||
## The stringify operator for a float argument. Returns `x`
|
## The stringify operator for a float argument. Returns `x`
|
||||||
## converted to a decimal string.
|
## converted to a decimal string.
|
||||||
|
|
||||||
proc `$` *(x: bool): string {.magic: "BoolToStr", noSideEffect.}
|
proc `$`*(x: bool): string {.magic: "BoolToStr", noSideEffect.}
|
||||||
## The stringify operator for a boolean argument. Returns `x`
|
## The stringify operator for a boolean argument. Returns `x`
|
||||||
## converted to the string "false" or "true".
|
## converted to the string "false" or "true".
|
||||||
|
|
||||||
proc `$` *(x: char): string {.magic: "CharToStr", noSideEffect.}
|
proc `$`*(x: char): string {.magic: "CharToStr", noSideEffect.}
|
||||||
## The stringify operator for a character argument. Returns `x`
|
## The stringify operator for a character argument. Returns `x`
|
||||||
## converted to a string.
|
## converted to a string.
|
||||||
|
|
||||||
proc `$` *(x: cstring): string {.magic: "CStrToStr", noSideEffect.}
|
proc `$`*(x: cstring): string {.magic: "CStrToStr", noSideEffect.}
|
||||||
## The stringify operator for a CString argument. Returns `x`
|
## The stringify operator for a CString argument. Returns `x`
|
||||||
## converted to a string.
|
## converted to a string.
|
||||||
|
|
||||||
proc `$` *(x: string): string {.magic: "StrToStr", noSideEffect.}
|
proc `$`*(x: string): string {.magic: "StrToStr", noSideEffect.}
|
||||||
## The stringify operator for a string argument. Returns `x`
|
## The stringify operator for a string argument. Returns `x`
|
||||||
## as it is. This operator is useful for generic code, so
|
## as it is. This operator is useful for generic code, so
|
||||||
## that ``$expr`` also works if ``expr`` is already a string.
|
## that ``$expr`` also works if ``expr`` is already a string.
|
||||||
|
|
||||||
proc `$` *[Enum: enum](x: Enum): string {.magic: "EnumToStr", noSideEffect.}
|
proc `$`*[Enum: enum](x: Enum): string {.magic: "EnumToStr", noSideEffect.}
|
||||||
## The stringify operator for an enumeration argument. This works for
|
## The stringify operator for an enumeration argument. This works for
|
||||||
## any enumeration type thanks to compiler magic. If
|
## any enumeration type thanks to compiler magic. If
|
||||||
## a ``$`` operator for a concrete enumeration is provided, this is
|
## a ``$`` operator for a concrete enumeration is provided, this is
|
||||||
|
|
@ -2312,7 +2312,7 @@ proc isNil*[T: proc](x: T): bool {.noSideEffect, magic: "IsNil".}
|
||||||
## Fast check whether `x` is nil. This is sometimes more efficient than
|
## Fast check whether `x` is nil. This is sometimes more efficient than
|
||||||
## ``== nil``.
|
## ``== nil``.
|
||||||
|
|
||||||
proc `==` *[I, T](x, y: array[I, T]): bool =
|
proc `==`*[I, T](x, y: array[I, T]): bool =
|
||||||
for f in low(x)..high(x):
|
for f in low(x)..high(x):
|
||||||
if x[f] != y[f]:
|
if x[f] != y[f]:
|
||||||
return
|
return
|
||||||
|
|
@ -2325,7 +2325,7 @@ proc `@`*[T](a: openArray[T]): seq[T] =
|
||||||
newSeq(result, a.len)
|
newSeq(result, a.len)
|
||||||
for i in 0..a.len-1: result[i] = a[i]
|
for i in 0..a.len-1: result[i] = a[i]
|
||||||
|
|
||||||
proc `&` *[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
|
proc `&`*[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
|
||||||
## Concatenates two sequences.
|
## Concatenates two sequences.
|
||||||
## Requires copying of the sequences.
|
## Requires copying of the sequences.
|
||||||
##
|
##
|
||||||
|
|
@ -2337,7 +2337,7 @@ proc `&` *[T](x, y: seq[T]): seq[T] {.noSideEffect.} =
|
||||||
for i in 0..y.len-1:
|
for i in 0..y.len-1:
|
||||||
result[i+x.len] = y[i]
|
result[i+x.len] = y[i]
|
||||||
|
|
||||||
proc `&` *[T](x: seq[T], y: T): seq[T] {.noSideEffect.} =
|
proc `&`*[T](x: seq[T], y: T): seq[T] {.noSideEffect.} =
|
||||||
## Appends element y to the end of the sequence.
|
## Appends element y to the end of the sequence.
|
||||||
## Requires copying of the sequence
|
## Requires copying of the sequence
|
||||||
##
|
##
|
||||||
|
|
@ -2348,7 +2348,7 @@ proc `&` *[T](x: seq[T], y: T): seq[T] {.noSideEffect.} =
|
||||||
result[i] = x[i]
|
result[i] = x[i]
|
||||||
result[x.len] = y
|
result[x.len] = y
|
||||||
|
|
||||||
proc `&` *[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
|
proc `&`*[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
|
||||||
## Prepends the element x to the beginning of the sequence.
|
## Prepends the element x to the beginning of the sequence.
|
||||||
## Requires copying of the sequence
|
## Requires copying of the sequence
|
||||||
##
|
##
|
||||||
|
|
@ -2359,7 +2359,7 @@ proc `&` *[T](x: T, y: seq[T]): seq[T] {.noSideEffect.} =
|
||||||
for i in 0..y.len-1:
|
for i in 0..y.len-1:
|
||||||
result[i+1] = y[i]
|
result[i+1] = y[i]
|
||||||
|
|
||||||
proc `==` *[T](x, y: seq[T]): bool {.noSideEffect.} =
|
proc `==`*[T](x, y: seq[T]): bool {.noSideEffect.} =
|
||||||
## Generic equals operator for sequences: relies on a equals operator for
|
## Generic equals operator for sequences: relies on a equals operator for
|
||||||
## the element type `T`.
|
## the element type `T`.
|
||||||
when nimvm:
|
when nimvm:
|
||||||
|
|
@ -3690,7 +3690,7 @@ proc `/=`*[T: float|float32](x: var T, y: T) {.inline, noSideEffect.} =
|
||||||
## Divides in place a floating point number
|
## Divides in place a floating point number
|
||||||
x = x / y
|
x = x / y
|
||||||
|
|
||||||
proc `&=`* (x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
|
proc `&=`*(x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
|
||||||
template `&=`*(x, y: typed) =
|
template `&=`*(x, y: typed) =
|
||||||
## generic 'sink' operator for Nim. For files an alias for ``write``.
|
## generic 'sink' operator for Nim. For files an alias for ``write``.
|
||||||
## If not specialized further an alias for ``add``.
|
## If not specialized further an alias for ``add``.
|
||||||
|
|
@ -4041,7 +4041,7 @@ proc xlen*[T](x: seq[T]): int {.magic: "XLenSeq", noSideEffect.} =
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
||||||
proc `==` *(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
|
proc `==`*(x, y: cstring): bool {.magic: "EqCString", noSideEffect,
|
||||||
inline.} =
|
inline.} =
|
||||||
## Checks for equality between two `cstring` variables.
|
## Checks for equality between two `cstring` variables.
|
||||||
proc strcmp(a, b: cstring): cint {.noSideEffect,
|
proc strcmp(a, b: cstring): cint {.noSideEffect,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue