doc.odin 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. Declarations which are required by the compiler
  3. ## Descriptions of files
  4. There are a lot of files in this package and below is described roughly what
  5. kind of functionality is placed in different files:
  6. | File pattern | Description
  7. |----------------------|------------------------------------------------------|
  8. | `core.odin` | Contains the declarations that compiler will require to be present. Contains context-related declarations, `Type_Info` declarations and some other types used to implement the runtime and other packages. |
  9. | `core_builtin*.odin` | Contain `@(builtin)` declarations that can be used without importing the package. Most of them aren't required by the compiler |
  10. | `default_*.odin` | Contain default implementations for context allocators |
  11. | `entry_*.odin` | Contain OS-specific entry points |
  12. | `os_specific_*.odin` | Contain OS-specific utility procedures |
  13. | `*internal*.odin` | Contain implementations for internal procedures that can be called by the compiler |
  14. ## Implementing custom runtime
  15. For embedded and kernel development it might be required to re-implement parts
  16. of the `base:runtime` package. This can include changing the default printing
  17. procedures that handle console output when the program panics, custom
  18. entry-points, tailored for a specific platform or execution environment, or
  19. simply switching up implementations of some procedures.
  20. In case this is required, the following is suggested:
  21. 1. Define `$ODIN_ROOT` environment variable to point to a directory within your
  22. project that contains the following directories: `base/`, `core/` and `vendor/`.
  23. 2. Inside the `$ODIN_ROOT/base` subdirectory, implement the *necessary
  24. declarations*.
  25. What constitutes the necessary definitions is described below.
  26. ### Context-related
  27. The compiler will require these declarations as they concern the `context`
  28. variable.
  29. * `Maybe`
  30. * `Source_Code_Location`
  31. * `Context`
  32. * `Allocator`
  33. * `Random_Generator`
  34. * `Logger`
  35. * `__init_context`
  36. ### Runtime initialization/cleanup
  37. These are not strictly required for compilation, but if global variables or
  38. `@(init)`/`@(fini)` blocks are used, these procedures need to be called inside
  39. the entry point.
  40. * `_startup_runtime`
  41. * `_cleanup_runtime`
  42. ### Type assertion check
  43. These procedures are called every time `.(Type)` expressions are used in order
  44. to check the union tag or the underlying type of `any` before returning the
  45. value of the underlying type. These are not required if `-no-type-assert` is
  46. specified.
  47. * `type_assertion_check`
  48. * `type_assertion_check2` (takes in typeid)
  49. ### Bounds checking procedures
  50. These procedures are called every time index or slicing expression are used in
  51. order to perform bounds-checking before the actual operation. These are not
  52. required if the `-no-bounds-check` option is specified.
  53. * `bounds_check_error`
  54. * `matrix_bounds_check_error`
  55. * `slice_expr_error_hi`
  56. * `slice_expr_error_lo_hi`
  57. * `multi_pointer_slice_expr_error`
  58. ### cstring calls
  59. If `cstring` or `cstring16` types are used, these procedures are required.
  60. * `cstring_to_string`
  61. * `cstring_len`
  62. * `cstring16_to_string16`
  63. * `cstring16_len`
  64. ### Comparison
  65. These procedures are required for comparison operators between strings and other
  66. compound types to function properly. If strings, structs nor unions are compared,
  67. only `string_eq` procedure is required.
  68. * `memory_equal`
  69. * `memory_compare`
  70. * `memory_compare_zero`
  71. * `cstring_eq`
  72. * `cstring16_eq`
  73. * `cstring_ne`
  74. * `cstring16_ne`
  75. * `cstring_lt`
  76. * `cstring16_lt`
  77. * `cstring_gt`
  78. * `cstring16_gt`
  79. * `cstring_le`
  80. * `cstring16_le`
  81. * `cstring_ge`
  82. * `cstring16_ge`
  83. * `string_eq`
  84. * `string16_eq`
  85. * `string_ne`
  86. * `string16_ne`
  87. * `string_lt`
  88. * `string16_lt`
  89. * `string_gt`
  90. * `string16_gt`
  91. * `string_le`
  92. * `string16_le`
  93. * `string_ge`
  94. * `string16_ge`
  95. * `complex32_eq`
  96. * `complex32_ne`
  97. * `complex64_eq`
  98. * `complex64_ne`
  99. * `complex128_eq`
  100. * `complex128_ne`
  101. * `quaternion64_eq`
  102. * `quaternion64_ne`
  103. * `quaternion128_eq`
  104. * `quaternion128_ne`
  105. * `quaternion256_eq`
  106. * `quaternion256_ne`
  107. ### for-in `string` type
  108. These procedures are required to iterate strings using `for ... in` loop. If this
  109. kind of loop isn't used, these procedures aren't required.
  110. * `string_decode_rune`
  111. * `string_decode_last_rune` (for `#reverse for`)
  112. ### Required when RTTI is enabled (the vast majority of targets)
  113. These declarations are required unless the `-no-rtti` compiler option is
  114. specified. Note that in order to be useful, some other procedures need to be
  115. implemented. Those procedures aren't mentioned here as the compiler won't
  116. complain if they're missing.
  117. * `Type_Info`
  118. * `type_table`
  119. * `__type_info_of`
  120. ### Hashing
  121. Required if maps are used
  122. * `default_hasher`
  123. * `default_hasher_cstring`
  124. * `default_hasher_string`
  125. ### Pseudo-CRT required procedured due to LLVM but useful in general
  126. * `memset`
  127. * `memcpy`
  128. * `memove`
  129. ### Procedures required by the LLVM backend if u128/i128 is used
  130. * `umodti3`
  131. * `udivti3`
  132. * `modti3`
  133. * `divti3`
  134. * `fixdfti`
  135. * `fixunsdfti`
  136. * `fixunsdfdi`
  137. * `floattidf`
  138. * `floattidf_unsigned`
  139. * `truncsfhf2`
  140. * `truncdfhf2`
  141. * `gnu_h2f_ieee`
  142. * `gnu_f2h_ieee`
  143. * `extendhfsf2`
  144. ### Procedures required by the LLVM backend if f16 is used (WASM only)
  145. * `__ashlti3`
  146. * `__multi3`
  147. ### When -no-crt is defined (windows only)
  148. * `_tls_index`
  149. * `_fltused`
  150. ### Arithmetic
  151. * `quo_complex32`
  152. * `quo_complex64`
  153. * `quo_complex128`
  154. * `mul_quaternion64`
  155. * `mul_quaternion128`
  156. * `mul_quaternion256`
  157. * `quo_quaternion64`
  158. * `quo_quaternion128`
  159. * `quo_quaternion256`
  160. * `abs_complex32`
  161. * `abs_complex64`
  162. * `abs_complex128`
  163. * `abs_quaternion64`
  164. * `abs_quaternion128`
  165. * `abs_quaternion256`
  166. ## Map specific calls
  167. * `map_seed_from_map_data`
  168. * `__dynamic_map_check_grow` (for static map calls)
  169. * `map_insert_hash_dynamic` (for static map calls)
  170. * `__dynamic_map_get` (for dynamic map calls)
  171. * `__dynamic_map_set` (for dynamic map calls)
  172. ## Dynamic literals (`[dynamic]T` and `map[K]V`) (can be disabled with `-no-dynamic-literals`)
  173. * `__dynamic_array_reserve`
  174. * `__dynamic_array_append`
  175. * `__dynamic_map_reserve`
  176. ### Objective-C specific
  177. * `objc_lookUpClass`
  178. * `sel_registerName`
  179. * `objc_allocateClassPair`
  180. ### Other required declarations
  181. This is required without conditions.
  182. * `Load_Directory_File`
  183. */
  184. package runtime