2
0

builtin.odin 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. // This is purely for documentation
  2. package builtin
  3. import "base:runtime"
  4. nil :: nil
  5. false :: 0!=0
  6. true :: 0==0
  7. // The following constants are added in `checker.cpp`'s `init_universal` procedure.
  8. /*
  9. An `enum` value indicating the target's CPU architecture.
  10. Possible values are: `.amd64`, `.i386`, `.arm32`, `.arm64`, `.wasm32`, `.wasm64p32`, and `.riscv64`.
  11. */
  12. ODIN_ARCH :: ODIN_ARCH
  13. /*
  14. A `string` indicating the target's CPU architecture.
  15. Possible values are: "amd64", "i386", "arm32", "arm64", "wasm32", "wasm64p32", "riscv64".
  16. */
  17. ODIN_ARCH_STRING :: ODIN_ARCH_STRING
  18. /*
  19. An `enum` value indicating the type of compiled output, chosen using `-build-mode`.
  20. Possible values are: `.Executable`, `.Dynamic`, `.Static`, `.Object`, `.Assembly`, and `.LLVM_IR`.
  21. */
  22. ODIN_BUILD_MODE :: ODIN_BUILD_MODE
  23. /*
  24. A `string` containing the name of the folder that contains the entry point,
  25. e.g. for `%ODIN_ROOT%/examples/demo`, this would contain `demo`.
  26. */
  27. ODIN_BUILD_PROJECT_NAME :: ODIN_BUILD_PROJECT_NAME
  28. /*
  29. An `i64` containing the time at which the executable was compiled, in nanoseconds.
  30. This is compatible with the `time.Time` type, i.e. `time.Time{_nsec=ODIN_COMPILE_TIMESTAMP}`
  31. */
  32. ODIN_COMPILE_TIMESTAMP :: ODIN_COMPILE_TIMESTAMP
  33. /*
  34. `true` if the `-debug` command line switch is passed, which enables debug info generation.
  35. */
  36. ODIN_DEBUG :: ODIN_DEBUG
  37. /*
  38. `true` if the `-default-to-nil-allocator` command line switch is passed,
  39. which sets the initial `context.allocator` to an allocator that does nothing.
  40. */
  41. ODIN_DEFAULT_TO_NIL_ALLOCATOR :: ODIN_DEFAULT_TO_NIL_ALLOCATOR
  42. /*
  43. `true` if the `-default-to-panic-allocator` command line switch is passed,
  44. which sets the initial `context.allocator` to an allocator that panics if allocated from.
  45. */
  46. ODIN_DEFAULT_TO_PANIC_ALLOCATOR :: ODIN_DEFAULT_TO_PANIC_ALLOCATOR
  47. /*
  48. `true` if the `-disable-assert` command line switch is passed,
  49. which removes all calls to `assert` from the program.
  50. */
  51. ODIN_DISABLE_ASSERT :: ODIN_DISABLE_ASSERT
  52. /*
  53. An `enum` value indicating the endianness of the target.
  54. Possible values are: `.Little` and `.Big`.
  55. */
  56. ODIN_ENDIAN :: ODIN_ENDIAN
  57. /*
  58. An `string` indicating the endianness of the target.
  59. Possible values are: "little" and "big".
  60. */
  61. ODIN_ENDIAN_STRING :: ODIN_ENDIAN_STRING
  62. /*
  63. An `enum` value set using the `-error-pos-style` switch, indicating the source location style used for compile errors and warnings.
  64. Possible values are: `.Default` (Odin-style) and `.Unix`.
  65. */
  66. ODIN_ERROR_POS_STYLE :: ODIN_ERROR_POS_STYLE
  67. /*
  68. `true` if the `-foreign-error-procedures` command line switch is passed,
  69. which inhibits generation of runtime error procedures, so that they can be in a separate compilation unit.
  70. */
  71. ODIN_FOREIGN_ERROR_PROCEDURES :: ODIN_FOREIGN_ERROR_PROCEDURES
  72. /*
  73. A `string` describing the microarchitecture used for code generation.
  74. If not set using the `-microarch` command line switch, the compiler will pick a default.
  75. Possible values include, but are not limited to: "sandybridge", "x86-64-v2".
  76. */
  77. ODIN_MICROARCH_STRING :: ODIN_MICROARCH_STRING
  78. /*
  79. An `int` value representing the minimum OS version given to the linker, calculated as `major * 10_000 + minor * 100 + revision`.
  80. If not set using the `-minimum-os-version` command line switch, it defaults to `0`, except on Darwin, where it's `11_00_00`.
  81. */
  82. ODIN_MINIMUM_OS_VERSION :: ODIN_MINIMUM_OS_VERSION
  83. /*
  84. `true` if the `-no-bounds-check` command line switch is passed, which disables bounds checking at runtime.
  85. */
  86. ODIN_NO_BOUNDS_CHECK :: ODIN_NO_BOUNDS_CHECK
  87. /*
  88. `true` if the `-no-crt` command line switch is passed, which inhibits linking with the C Runtime Library, a.k.a. LibC.
  89. */
  90. ODIN_NO_CRT :: ODIN_NO_CRT
  91. /*
  92. `true` if the `-no-entry-point` command line switch is passed, which makes the declaration of a `main` procedure optional.
  93. */
  94. ODIN_NO_ENTRY_POINT :: ODIN_NO_ENTRY_POINT
  95. /*
  96. `true` if the `-no-rtti` command line switch is passed, which inhibits generation of full Runtime Type Information.
  97. */
  98. ODIN_NO_RTTI :: ODIN_NO_RTTI
  99. /*
  100. `true` if the `-no-type-assert` command line switch is passed, which disables type assertion checking program wide.
  101. */
  102. ODIN_NO_TYPE_ASSERT :: ODIN_NO_TYPE_ASSERT
  103. /*
  104. An `enum` value indicating the optimization level selected using the `-o` command line switch.
  105. Possible values are: `.None`, `.Minimal`, `.Size`, `.Speed`, and `.Aggressive`.
  106. If `ODIN_OPTIMIZATION_MODE` is anything other than `.None` or `.Minimal`, the compiler will also perform a unity build,
  107. and `ODIN_USE_SEPARATE_MODULES` will be set to `false` as a result.
  108. */
  109. ODIN_OPTIMIZATION_MODE :: ODIN_OPTIMIZATION_MODE
  110. /*
  111. An `enum` value indicating what the target operating system is.
  112. */
  113. ODIN_OS :: ODIN_OS
  114. /*
  115. A `string` indicating what the target operating system is.
  116. */
  117. ODIN_OS_STRING :: ODIN_OS_STRING
  118. /*
  119. An `enum` value indicating the platform subtarget, chosen using the `-subtarget` switch.
  120. Possible values are: `.Default` `.iPhone`, .iPhoneSimulator, and `.Android`.
  121. */
  122. ODIN_PLATFORM_SUBTARGET :: ODIN_PLATFORM_SUBTARGET
  123. /*
  124. A `string` representing the path of the folder containing the Odin compiler,
  125. relative to which we expect to find the `base` and `core` package collections.
  126. */
  127. ODIN_ROOT :: ODIN_ROOT
  128. /*
  129. A `bit_set` indicating the sanitizer flags set using the `-sanitize` command line switch.
  130. Supported flags are `.Address`, `.Memory`, and `.Thread`.
  131. */
  132. ODIN_SANITIZER_FLAGS :: ODIN_SANITIZER_FLAGS
  133. /*
  134. `true` if the code is being compiled via an invocation of `odin test`.
  135. */
  136. ODIN_TEST :: ODIN_TEST
  137. /*
  138. `true` if built using the experimental Tilde backend.
  139. */
  140. ODIN_TILDE :: ODIN_TILDE
  141. /*
  142. `true` by default, meaning each each package is built into its own object file, and then linked together.
  143. `false` if the `-use-single-module` command line switch to force a unity build is provided.
  144. If `ODIN_OPTIMIZATION_MODE` is anything other than `.None` or `.Minimal`, the compiler will also perform a unity build,
  145. and this constant will also be set to `false`.
  146. */
  147. ODIN_USE_SEPARATE_MODULES :: ODIN_USE_SEPARATE_MODULES
  148. /*
  149. `true` if Valgrind integration is supported on the target.
  150. */
  151. ODIN_VALGRIND_SUPPORT :: ODIN_VALGRIND_SUPPORT
  152. /*
  153. A `string` which identifies the compiler being used. The official compiler sets this to `"odin"`.
  154. */
  155. ODIN_VENDOR :: ODIN_VENDOR
  156. /*
  157. A `string` containing the version of the Odin compiler, typically in the format `dev-YYYY-MM`.
  158. */
  159. ODIN_VERSION :: ODIN_VERSION
  160. /*
  161. A `string` containing the Git hash part of the Odin version.
  162. Empty if `.git` could not be detected at the time the compiler was built.
  163. */
  164. ODIN_VERSION_HASH :: ODIN_VERSION_HASH
  165. /*
  166. An `enum` set by the `-subsystem` flag, specifying which Windows subsystem the PE file was created for.
  167. Possible values are:
  168. `.Unknown` - Default and only value on non-Windows platforms
  169. `.Console` - Default on Windows
  170. `.Windows` - Can be used by graphical applications so Windows doesn't open an empty console
  171. There are some other possible values for e.g. EFI applications, but only Console and Windows are supported.
  172. See also: https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_optional_header64
  173. */
  174. ODIN_WINDOWS_SUBSYSTEM :: ODIN_WINDOWS_SUBSYSTEM
  175. /*
  176. An `string` set by the `-subsystem` flag, specifying which Windows subsystem the PE file was created for.
  177. Possible values are:
  178. "UNKNOWN" - Default and only value on non-Windows platforms
  179. "CONSOLE" - Default on Windows
  180. "WINDOWS" - Can be used by graphical applications so Windows doesn't open an empty console
  181. There are some other possible values for e.g. EFI applications, but only Console and Windows are supported.
  182. See also: https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-image_optional_header64
  183. */
  184. ODIN_WINDOWS_SUBSYSTEM_STRING :: ODIN_WINDOWS_SUBSYSTEM_STRING
  185. /*
  186. `true` if LLVM supports the f16 type.
  187. */
  188. __ODIN_LLVM_F16_SUPPORTED :: __ODIN_LLVM_F16_SUPPORTED
  189. byte :: u8 // alias
  190. bool :: bool
  191. b8 :: b8
  192. b16 :: b16
  193. b32 :: b32
  194. b64 :: b64
  195. i8 :: i8
  196. u8 :: u8
  197. i16 :: i16
  198. u16 :: u16
  199. i32 :: i32
  200. u32 :: u32
  201. i64 :: i64
  202. u64 :: u64
  203. i128 :: i128
  204. u128 :: u128
  205. rune :: rune
  206. f16 :: f16
  207. f32 :: f32
  208. f64 :: f64
  209. complex32 :: complex32
  210. complex64 :: complex64
  211. complex128 :: complex128
  212. quaternion64 :: quaternion64
  213. quaternion128 :: quaternion128
  214. quaternion256 :: quaternion256
  215. int :: int
  216. uint :: uint
  217. uintptr :: uintptr
  218. rawptr :: rawptr
  219. string :: string
  220. cstring :: cstring
  221. any :: any
  222. typeid :: typeid
  223. // Endian Specific Types
  224. i16le :: i16le
  225. u16le :: u16le
  226. i32le :: i32le
  227. u32le :: u32le
  228. i64le :: i64le
  229. u64le :: u64le
  230. i128le :: i128le
  231. u128le :: u128le
  232. i16be :: i16be
  233. u16be :: u16be
  234. i32be :: i32be
  235. u32be :: u32be
  236. i64be :: i64be
  237. u64be :: u64be
  238. i128be :: i128be
  239. u128be :: u128be
  240. f16le :: f16le
  241. f32le :: f32le
  242. f64le :: f64le
  243. f16be :: f16be
  244. f32be :: f32be
  245. f64be :: f64be
  246. // Procedures
  247. len :: proc(array: Array_Type) -> int ---
  248. cap :: proc(array: Array_Type) -> int ---
  249. size_of :: proc($T: typeid) -> int ---
  250. align_of :: proc($T: typeid) -> int ---
  251. // e.g. offset_of(t.f), where t is an instance of the type T
  252. offset_of_selector :: proc(selector: $T) -> uintptr ---
  253. // e.g. offset_of(T, f), where T can be the type instead of a variable
  254. offset_of_member :: proc($T: typeid, member: $M) -> uintptr ---
  255. offset_of :: proc{offset_of_selector, offset_of_member}
  256. // e.g. offset_of(T, "f"), where T can be the type instead of a variable
  257. offset_of_by_string :: proc($T: typeid, member: string) -> uintptr ---
  258. type_of :: proc(x: expr) -> type ---
  259. type_info_of :: proc($T: typeid) -> ^runtime.Type_Info ---
  260. typeid_of :: proc($T: typeid) -> typeid ---
  261. swizzle :: proc(x: [N]T, indices: ..int) -> [len(indices)]T ---
  262. complex :: proc(real, imag: Float) -> Complex_Type ---
  263. quaternion :: proc(imag, jmag, kmag, real: Float) -> Quaternion_Type --- // fields must be named
  264. real :: proc(value: Complex_Or_Quaternion) -> Float ---
  265. imag :: proc(value: Complex_Or_Quaternion) -> Float ---
  266. jmag :: proc(value: Quaternion) -> Float ---
  267. kmag :: proc(value: Quaternion) -> Float ---
  268. conj :: proc(value: Complex_Or_Quaternion) -> Complex_Or_Quaternion ---
  269. expand_values :: proc(value: Struct_Or_Array) -> (A, B, C, ...) ---
  270. compress_values :: proc(values: ...) -> Struct_Or_Array_Like_Type ---
  271. min :: proc(values: ..T) -> T ---
  272. max :: proc(values: ..T) -> T ---
  273. abs :: proc(value: T) -> T ---
  274. clamp :: proc(value, minimum, maximum: T) -> T ---
  275. soa_zip :: proc(slices: ...) -> #soa[]Struct ---
  276. soa_unzip :: proc(value: $S/#soa[]$E) -> (slices: ...) ---
  277. unreachable :: proc() -> ! ---
  278. // Where T is a string, slice, dynamic array, or pointer to an array type
  279. raw_data :: proc(t: $T) -> rawptr