basic_types.nim 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. type
  2. int* {.magic: Int.} ## Default integer type; bitwidth depends on
  3. ## architecture, but is always the same as a pointer.
  4. int8* {.magic: Int8.} ## Signed 8 bit integer type.
  5. int16* {.magic: Int16.} ## Signed 16 bit integer type.
  6. int32* {.magic: Int32.} ## Signed 32 bit integer type.
  7. int64* {.magic: Int64.} ## Signed 64 bit integer type.
  8. uint* {.magic: UInt.} ## Unsigned default integer type.
  9. uint8* {.magic: UInt8.} ## Unsigned 8 bit integer type.
  10. uint16* {.magic: UInt16.} ## Unsigned 16 bit integer type.
  11. uint32* {.magic: UInt32.} ## Unsigned 32 bit integer type.
  12. uint64* {.magic: UInt64.} ## Unsigned 64 bit integer type.
  13. type
  14. float* {.magic: Float.} ## Default floating point type.
  15. float32* {.magic: Float32.} ## 32 bit floating point type.
  16. float64* {.magic: Float.} ## 64 bit floating point type.
  17. # 'float64' is now an alias to 'float'; this solves many problems
  18. type
  19. char* {.magic: Char.} ## Built-in 8 bit character type (unsigned).
  20. string* {.magic: String.} ## Built-in string type.
  21. cstring* {.magic: Cstring.} ## Built-in cstring (*compatible string*) type.
  22. pointer* {.magic: Pointer.} ## Built-in pointer type, use the `addr`
  23. ## operator to get a pointer to a variable.
  24. typedesc* {.magic: TypeDesc.} ## Meta type to denote a type description.
  25. type
  26. `ptr`*[T] {.magic: Pointer.} ## Built-in generic untraced pointer type.
  27. `ref`*[T] {.magic: Pointer.} ## Built-in generic traced pointer type.
  28. `nil` {.magic: "Nil".}
  29. void* {.magic: "VoidType".} ## Meta type to denote the absence of any type.
  30. auto* {.magic: Expr.} ## Meta type for automatic type determination.
  31. any* {.deprecated: "Deprecated since v1.5; Use auto instead.".} = distinct auto ## Deprecated; Use `auto` instead. See https://github.com/nim-lang/RFCs/issues/281
  32. untyped* {.magic: Expr.} ## Meta type to denote an expression that
  33. ## is not resolved (for templates).
  34. typed* {.magic: Stmt.} ## Meta type to denote an expression that
  35. ## is resolved (for templates).
  36. type # we need to start a new type section here, so that ``0`` can have a type
  37. bool* {.magic: "Bool".} = enum ## Built-in boolean type.
  38. false = 0, true = 1
  39. const
  40. on* = true ## Alias for `true`.
  41. off* = false ## Alias for `false`.
  42. type
  43. SomeSignedInt* = int|int8|int16|int32|int64
  44. ## Type class matching all signed integer types.
  45. SomeUnsignedInt* = uint|uint8|uint16|uint32|uint64
  46. ## Type class matching all unsigned integer types.
  47. SomeInteger* = SomeSignedInt|SomeUnsignedInt
  48. ## Type class matching all integer types.
  49. SomeFloat* = float|float32|float64
  50. ## Type class matching all floating point number types.
  51. SomeNumber* = SomeInteger|SomeFloat
  52. ## Type class matching all number types.
  53. SomeOrdinal* = int|int8|int16|int32|int64|bool|enum|uint|uint8|uint16|uint32|uint64
  54. ## Type class matching all ordinal types; however this includes enums with
  55. ## holes. See also `Ordinal`
  56. {.push warning[GcMem]: off, warning[Uninit]: off.}
  57. {.push hints: off.}
  58. proc `not`*(x: bool): bool {.magic: "Not", noSideEffect.}
  59. ## Boolean not; returns true if `x == false`.
  60. proc `and`*(x, y: bool): bool {.magic: "And", noSideEffect.}
  61. ## Boolean `and`; returns true if `x == y == true` (if both arguments
  62. ## are true).
  63. ##
  64. ## Evaluation is lazy: if `x` is false, `y` will not even be evaluated.
  65. proc `or`*(x, y: bool): bool {.magic: "Or", noSideEffect.}
  66. ## Boolean `or`; returns true if `not (not x and not y)` (if any of
  67. ## the arguments is true).
  68. ##
  69. ## Evaluation is lazy: if `x` is true, `y` will not even be evaluated.
  70. proc `xor`*(x, y: bool): bool {.magic: "Xor", noSideEffect.}
  71. ## Boolean `exclusive or`; returns true if `x != y` (if either argument
  72. ## is true while the other is false).
  73. {.pop.}
  74. {.pop.}