basic_types.nim 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 # we need to start a new type section here, so that ``0`` can have a type
  14. bool* {.magic: "Bool".} = enum ## Built-in boolean type.
  15. false = 0, true = 1
  16. const
  17. on* = true ## Alias for ``true``.
  18. off* = false ## Alias for ``false``.
  19. type
  20. SomeSignedInt* = int|int8|int16|int32|int64
  21. ## Type class matching all signed integer types.
  22. SomeUnsignedInt* = uint|uint8|uint16|uint32|uint64
  23. ## Type class matching all unsigned integer types.
  24. SomeInteger* = SomeSignedInt|SomeUnsignedInt
  25. ## Type class matching all integer types.
  26. SomeOrdinal* = int|int8|int16|int32|int64|bool|enum|uint|uint8|uint16|uint32|uint64
  27. ## Type class matching all ordinal types; however this includes enums with
  28. ## holes. See also `Ordinal`
  29. BiggestInt* = int64
  30. ## is an alias for the biggest signed integer type the Nim compiler
  31. ## supports. Currently this is ``int64``, but it is platform-dependent
  32. ## in general.
  33. {.push warning[GcMem]: off, warning[Uninit]: off.}
  34. {.push hints: off.}
  35. proc `not`*(x: bool): bool {.magic: "Not", noSideEffect.}
  36. ## Boolean not; returns true if ``x == false``.
  37. proc `and`*(x, y: bool): bool {.magic: "And", noSideEffect.}
  38. ## Boolean ``and``; returns true if ``x == y == true`` (if both arguments
  39. ## are true).
  40. ##
  41. ## Evaluation is lazy: if ``x`` is false, ``y`` will not even be evaluated.
  42. proc `or`*(x, y: bool): bool {.magic: "Or", noSideEffect.}
  43. ## Boolean ``or``; returns true if ``not (not x and not y)`` (if any of
  44. ## the arguments is true).
  45. ##
  46. ## Evaluation is lazy: if ``x`` is true, ``y`` will not even be evaluated.
  47. proc `xor`*(x, y: bool): bool {.magic: "Xor", noSideEffect.}
  48. ## Boolean `exclusive or`; returns true if ``x != y`` (if either argument
  49. ## is true while the other is false).
  50. {.pop.}
  51. {.pop.}