core_builtin.odin 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. package runtime
  2. import "core:intrinsics"
  3. @builtin
  4. Maybe :: union($T: typeid) {T}
  5. @builtin
  6. container_of :: #force_inline proc "contextless" (ptr: $P/^$Field_Type, $T: typeid, $field_name: string) -> ^T
  7. where intrinsics.type_has_field(T, field_name),
  8. intrinsics.type_field_type(T, field_name) == Field_Type {
  9. offset :: offset_of_by_string(T, field_name)
  10. return (^T)(uintptr(ptr) - offset) if ptr != nil else nil
  11. }
  12. @thread_local global_default_temp_allocator_data: Default_Temp_Allocator
  13. @builtin
  14. init_global_temporary_allocator :: proc(size: int, backup_allocator := context.allocator) {
  15. default_temp_allocator_init(&global_default_temp_allocator_data, size, backup_allocator)
  16. }
  17. @builtin
  18. copy_slice :: proc "contextless" (dst, src: $T/[]$E) -> int {
  19. n := max(0, min(len(dst), len(src)))
  20. if n > 0 {
  21. intrinsics.mem_copy(raw_data(dst), raw_data(src), n*size_of(E))
  22. }
  23. return n
  24. }
  25. @builtin
  26. copy_from_string :: proc "contextless" (dst: $T/[]$E/u8, src: $S/string) -> int {
  27. n := max(0, min(len(dst), len(src)))
  28. if n > 0 {
  29. intrinsics.mem_copy(raw_data(dst), raw_data(src), n)
  30. }
  31. return n
  32. }
  33. @builtin
  34. copy :: proc{copy_slice, copy_from_string}
  35. @builtin
  36. unordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) #no_bounds_check {
  37. bounds_check_error_loc(loc, index, len(array))
  38. n := len(array)-1
  39. if index != n {
  40. array[index] = array[n]
  41. }
  42. (^Raw_Dynamic_Array)(array).len -= 1
  43. }
  44. @builtin
  45. ordered_remove :: proc(array: ^$D/[dynamic]$T, index: int, loc := #caller_location) #no_bounds_check {
  46. bounds_check_error_loc(loc, index, len(array))
  47. if index+1 < len(array) {
  48. copy(array[index:], array[index+1:])
  49. }
  50. (^Raw_Dynamic_Array)(array).len -= 1
  51. }
  52. @builtin
  53. remove_range :: proc(array: ^$D/[dynamic]$T, lo, hi: int, loc := #caller_location) #no_bounds_check {
  54. slice_expr_error_lo_hi_loc(loc, lo, hi, len(array))
  55. n := max(hi-lo, 0)
  56. if n > 0 {
  57. if hi != len(array) {
  58. copy(array[lo:], array[hi:])
  59. }
  60. (^Raw_Dynamic_Array)(array).len -= n
  61. }
  62. }
  63. @builtin
  64. pop :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: E) #no_bounds_check {
  65. assert(len(array) > 0, "", loc)
  66. res = array[len(array)-1]
  67. (^Raw_Dynamic_Array)(array).len -= 1
  68. return res
  69. }
  70. @builtin
  71. pop_safe :: proc(array: ^$T/[dynamic]$E) -> (res: E, ok: bool) #no_bounds_check {
  72. if len(array) == 0 {
  73. return
  74. }
  75. res, ok = array[len(array)-1], true
  76. (^Raw_Dynamic_Array)(array).len -= 1
  77. return
  78. }
  79. @builtin
  80. pop_front :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) -> (res: E) #no_bounds_check {
  81. assert(len(array) > 0, "", loc)
  82. res = array[0]
  83. if len(array) > 1 {
  84. copy(array[0:], array[1:])
  85. }
  86. (^Raw_Dynamic_Array)(array).len -= 1
  87. return res
  88. }
  89. @builtin
  90. pop_front_safe :: proc(array: ^$T/[dynamic]$E) -> (res: E, ok: bool) #no_bounds_check {
  91. if len(array) == 0 {
  92. return
  93. }
  94. res, ok = array[0], true
  95. if len(array) > 1 {
  96. copy(array[0:], array[1:])
  97. }
  98. (^Raw_Dynamic_Array)(array).len -= 1
  99. return
  100. }
  101. @builtin
  102. clear :: proc{clear_dynamic_array, clear_map}
  103. @builtin
  104. reserve :: proc{reserve_dynamic_array, reserve_map}
  105. @builtin
  106. resize :: proc{resize_dynamic_array}
  107. @builtin
  108. free :: proc{mem_free}
  109. @builtin
  110. free_all :: proc{mem_free_all}
  111. @builtin
  112. delete_string :: proc(str: string, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
  113. return mem_free(raw_data(str), allocator, loc)
  114. }
  115. @builtin
  116. delete_cstring :: proc(str: cstring, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
  117. return mem_free((^byte)(str), allocator, loc)
  118. }
  119. @builtin
  120. delete_dynamic_array :: proc(array: $T/[dynamic]$E, loc := #caller_location) -> Allocator_Error {
  121. return mem_free(raw_data(array), array.allocator, loc)
  122. }
  123. @builtin
  124. delete_slice :: proc(array: $T/[]$E, allocator := context.allocator, loc := #caller_location) -> Allocator_Error {
  125. return mem_free(raw_data(array), allocator, loc)
  126. }
  127. @builtin
  128. delete_map :: proc(m: $T/map[$K]$V, loc := #caller_location) -> Allocator_Error {
  129. raw := transmute(Raw_Map)m
  130. err := delete_slice(raw.hashes, raw.entries.allocator, loc)
  131. err1 := mem_free(raw.entries.data, raw.entries.allocator, loc)
  132. if err == nil {
  133. err = err1
  134. }
  135. return err
  136. }
  137. @builtin
  138. delete :: proc{
  139. delete_string,
  140. delete_cstring,
  141. delete_dynamic_array,
  142. delete_slice,
  143. delete_map,
  144. }
  145. // The new built-in procedure allocates memory. The first argument is a type, not a value, and the value
  146. // return is a pointer to a newly allocated value of that type using the specified allocator, default is context.allocator
  147. @builtin
  148. new :: proc($T: typeid, allocator := context.allocator, loc := #caller_location) -> (^T, Allocator_Error) #optional_second {
  149. return new_aligned(T, align_of(T), allocator, loc)
  150. }
  151. new_aligned :: proc($T: typeid, alignment: int, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) {
  152. data := mem_alloc_bytes(size_of(T), alignment, allocator, loc) or_return
  153. t = (^T)(raw_data(data))
  154. return
  155. }
  156. @builtin
  157. new_clone :: proc(data: $T, allocator := context.allocator, loc := #caller_location) -> (t: ^T, err: Allocator_Error) #optional_second {
  158. t_data := mem_alloc_bytes(size_of(T), align_of(T), allocator, loc) or_return
  159. t = (^T)(raw_data(t_data))
  160. if t != nil {
  161. t^ = data
  162. }
  163. return
  164. }
  165. DEFAULT_RESERVE_CAPACITY :: 16
  166. make_aligned :: proc($T: typeid/[]$E, #any_int len: int, alignment: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
  167. make_slice_error_loc(loc, len)
  168. data, err := mem_alloc_bytes(size_of(E)*len, alignment, allocator, loc)
  169. if data == nil && size_of(E) != 0 {
  170. return nil, err
  171. }
  172. s := Raw_Slice{raw_data(data), len}
  173. return transmute(T)s, err
  174. }
  175. @(builtin)
  176. make_slice :: proc($T: typeid/[]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
  177. return make_aligned(T, len, align_of(E), allocator, loc)
  178. }
  179. @(builtin)
  180. make_dynamic_array :: proc($T: typeid/[dynamic]$E, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
  181. return make_dynamic_array_len_cap(T, 0, DEFAULT_RESERVE_CAPACITY, allocator, loc)
  182. }
  183. @(builtin)
  184. make_dynamic_array_len :: proc($T: typeid/[dynamic]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (T, Allocator_Error) #optional_second {
  185. return make_dynamic_array_len_cap(T, len, len, allocator, loc)
  186. }
  187. @(builtin)
  188. make_dynamic_array_len_cap :: proc($T: typeid/[dynamic]$E, #any_int len: int, #any_int cap: int, allocator := context.allocator, loc := #caller_location) -> (array: T, err: Allocator_Error) #optional_second {
  189. make_dynamic_array_error_loc(loc, len, cap)
  190. data := mem_alloc_bytes(size_of(E)*cap, align_of(E), allocator, loc) or_return
  191. s := Raw_Dynamic_Array{raw_data(data), len, cap, allocator}
  192. if data == nil && size_of(E) != 0 {
  193. s.len, s.cap = 0, 0
  194. }
  195. array = transmute(T)s
  196. return
  197. }
  198. @(builtin)
  199. make_map :: proc($T: typeid/map[$K]$E, #any_int cap: int = DEFAULT_RESERVE_CAPACITY, allocator := context.allocator, loc := #caller_location) -> T {
  200. make_map_expr_error_loc(loc, cap)
  201. context.allocator = allocator
  202. m: T
  203. reserve_map(&m, cap)
  204. return m
  205. }
  206. @(builtin)
  207. make_multi_pointer :: proc($T: typeid/[^]$E, #any_int len: int, allocator := context.allocator, loc := #caller_location) -> (mp: T, err: Allocator_Error) #optional_second {
  208. make_slice_error_loc(loc, len)
  209. data := mem_alloc_bytes(size_of(E)*len, align_of(E), allocator, loc) or_return
  210. if data == nil && size_of(E) != 0 {
  211. return
  212. }
  213. mp = cast(T)raw_data(data)
  214. return
  215. }
  216. // The make built-in procedure allocates and initializes a value of type slice, dynamic array, or map (only)
  217. // Similar to new, the first argument is a type, not a value. Unlike new, make's return type is the same as the
  218. // type of its argument, not a pointer to it.
  219. // Make uses the specified allocator, default is context.allocator, default is context.allocator
  220. @builtin
  221. make :: proc{
  222. make_slice,
  223. make_dynamic_array,
  224. make_dynamic_array_len,
  225. make_dynamic_array_len_cap,
  226. make_map,
  227. make_multi_pointer,
  228. }
  229. @builtin
  230. clear_map :: proc "contextless" (m: ^$T/map[$K]$V) {
  231. if m == nil {
  232. return
  233. }
  234. raw_map := (^Raw_Map)(m)
  235. entries := (^Raw_Dynamic_Array)(&raw_map.entries)
  236. entries.len = 0
  237. for _, i in raw_map.hashes {
  238. raw_map.hashes[i] = -1
  239. }
  240. }
  241. @builtin
  242. reserve_map :: proc(m: ^$T/map[$K]$V, capacity: int) {
  243. if m != nil {
  244. __dynamic_map_reserve(__get_map_header(m), capacity)
  245. }
  246. }
  247. // The delete_key built-in procedure deletes the element with the specified key (m[key]) from the map.
  248. // If m is nil, or there is no such element, this procedure is a no-op
  249. @builtin
  250. delete_key :: proc(m: ^$T/map[$K]$V, key: K) -> (deleted_key: K, deleted_value: V) {
  251. if m != nil {
  252. key := key
  253. h := __get_map_header(m)
  254. hash := __get_map_hash(&key)
  255. fr := __dynamic_map_find(h, hash)
  256. if fr.entry_index >= 0 {
  257. entry := __dynamic_map_get_entry(h, fr.entry_index)
  258. deleted_key = (^K)(uintptr(entry)+h.key_offset)^
  259. deleted_value = (^V)(uintptr(entry)+h.value_offset)^
  260. __dynamic_map_erase(h, fr)
  261. }
  262. }
  263. return
  264. }
  265. @builtin
  266. append_elem :: proc(array: ^$T/[dynamic]$E, arg: E, loc := #caller_location) {
  267. if array == nil {
  268. return
  269. }
  270. if cap(array) < len(array)+1 {
  271. cap := 2 * cap(array) + max(8, 1)
  272. _ = reserve(array, cap, loc)
  273. }
  274. if cap(array)-len(array) > 0 {
  275. a := (^Raw_Dynamic_Array)(array)
  276. when size_of(E) != 0 {
  277. data := ([^]E)(a.data)
  278. assert(condition=data != nil, loc=loc)
  279. data[a.len] = arg
  280. }
  281. a.len += 1
  282. }
  283. }
  284. @builtin
  285. append_elems :: proc(array: ^$T/[dynamic]$E, args: ..E, loc := #caller_location) {
  286. if array == nil {
  287. return
  288. }
  289. arg_len := len(args)
  290. if arg_len <= 0 {
  291. return
  292. }
  293. if cap(array) < len(array)+arg_len {
  294. cap := 2 * cap(array) + max(8, arg_len)
  295. _ = reserve(array, cap, loc)
  296. }
  297. arg_len = min(cap(array)-len(array), arg_len)
  298. if arg_len > 0 {
  299. a := (^Raw_Dynamic_Array)(array)
  300. when size_of(E) != 0 {
  301. data := ([^]E)(a.data)
  302. assert(condition=data != nil, loc=loc)
  303. intrinsics.mem_copy(&data[a.len], raw_data(args), size_of(E) * arg_len)
  304. }
  305. a.len += arg_len
  306. }
  307. }
  308. // The append_string built-in procedure appends a string to the end of a [dynamic]u8 like type
  309. @builtin
  310. append_elem_string :: proc(array: ^$T/[dynamic]$E/u8, arg: $A/string, loc := #caller_location) {
  311. args := transmute([]E)arg
  312. append_elems(array=array, args=args, loc=loc)
  313. }
  314. // The append_string built-in procedure appends multiple strings to the end of a [dynamic]u8 like type
  315. @builtin
  316. append_string :: proc(array: ^$T/[dynamic]$E/u8, args: ..string, loc := #caller_location) {
  317. for arg in args {
  318. append(array = array, args = transmute([]E)(arg), loc = loc)
  319. }
  320. }
  321. // The append built-in procedure appends elements to the end of a dynamic array
  322. @builtin append :: proc{append_elem, append_elems, append_elem_string}
  323. @builtin
  324. append_nothing :: proc(array: ^$T/[dynamic]$E, loc := #caller_location) {
  325. if array == nil {
  326. return
  327. }
  328. resize(array, len(array)+1)
  329. }
  330. @builtin
  331. insert_at_elem :: proc(array: ^$T/[dynamic]$E, index: int, arg: E, loc := #caller_location) -> (ok: bool) #no_bounds_check {
  332. if array == nil {
  333. return
  334. }
  335. n := max(len(array), index)
  336. m :: 1
  337. new_size := n + m
  338. if resize(array, new_size, loc) {
  339. when size_of(E) != 0 {
  340. copy(array[index + m:], array[index:])
  341. array[index] = arg
  342. }
  343. ok = true
  344. }
  345. return
  346. }
  347. @builtin
  348. insert_at_elems :: proc(array: ^$T/[dynamic]$E, index: int, args: ..E, loc := #caller_location) -> (ok: bool) #no_bounds_check {
  349. if array == nil {
  350. return
  351. }
  352. if len(args) == 0 {
  353. ok = true
  354. return
  355. }
  356. n := max(len(array), index)
  357. m := len(args)
  358. new_size := n + m
  359. if resize(array, new_size, loc) {
  360. when size_of(E) != 0 {
  361. copy(array[index + m:], array[index:])
  362. copy(array[index:], args)
  363. }
  364. ok = true
  365. }
  366. return
  367. }
  368. @builtin
  369. insert_at_elem_string :: proc(array: ^$T/[dynamic]$E/u8, index: int, arg: string, loc := #caller_location) -> (ok: bool) #no_bounds_check {
  370. if array == nil {
  371. return
  372. }
  373. if len(arg) == 0 {
  374. ok = true
  375. return
  376. }
  377. n := max(len(array), index)
  378. m := len(arg)
  379. new_size := n + m
  380. if resize(array, new_size, loc) {
  381. copy(array[index+m:], array[index:])
  382. copy(array[index:], arg)
  383. ok = true
  384. }
  385. return
  386. }
  387. @builtin insert_at :: proc{insert_at_elem, insert_at_elems, insert_at_elem_string}
  388. @builtin
  389. clear_dynamic_array :: proc "contextless" (array: ^$T/[dynamic]$E) {
  390. if array != nil {
  391. (^Raw_Dynamic_Array)(array).len = 0
  392. }
  393. }
  394. @builtin
  395. reserve_dynamic_array :: proc(array: ^$T/[dynamic]$E, capacity: int, loc := #caller_location) -> bool {
  396. if array == nil {
  397. return false
  398. }
  399. a := (^Raw_Dynamic_Array)(array)
  400. if capacity <= a.cap {
  401. return true
  402. }
  403. if a.allocator.procedure == nil {
  404. a.allocator = context.allocator
  405. }
  406. assert(a.allocator.procedure != nil)
  407. old_size := a.cap * size_of(E)
  408. new_size := capacity * size_of(E)
  409. allocator := a.allocator
  410. new_data, err := allocator.procedure(
  411. allocator.data, .Resize, new_size, align_of(E),
  412. a.data, old_size, loc,
  413. )
  414. if new_data == nil || err != nil {
  415. return false
  416. }
  417. a.data = raw_data(new_data)
  418. a.cap = capacity
  419. return true
  420. }
  421. @builtin
  422. resize_dynamic_array :: proc(array: ^$T/[dynamic]$E, length: int, loc := #caller_location) -> bool {
  423. if array == nil {
  424. return false
  425. }
  426. a := (^Raw_Dynamic_Array)(array)
  427. if length <= a.cap {
  428. a.len = max(length, 0)
  429. return true
  430. }
  431. if a.allocator.procedure == nil {
  432. a.allocator = context.allocator
  433. }
  434. assert(a.allocator.procedure != nil)
  435. old_size := a.cap * size_of(E)
  436. new_size := length * size_of(E)
  437. allocator := a.allocator
  438. new_data, err := allocator.procedure(
  439. allocator.data, .Resize, new_size, align_of(E),
  440. a.data, old_size, loc,
  441. )
  442. if new_data == nil || err != nil {
  443. return false
  444. }
  445. a.data = raw_data(new_data)
  446. a.len = length
  447. a.cap = length
  448. return true
  449. }
  450. @builtin
  451. map_insert :: proc(m: ^$T/map[$K]$V, key: K, value: V, loc := #caller_location) -> (ptr: ^V) {
  452. key, value := key, value
  453. h := __get_map_header(m)
  454. hash := __get_map_hash(&key)
  455. data := uintptr(__dynamic_map_set(h, hash, &value, loc))
  456. return (^V)(data + h.value_offset)
  457. }
  458. @builtin
  459. incl_elem :: proc(s: ^$S/bit_set[$E; $U], elem: E) {
  460. s^ |= {elem}
  461. }
  462. @builtin
  463. incl_elems :: proc(s: ^$S/bit_set[$E; $U], elems: ..E) {
  464. for elem in elems {
  465. s^ |= {elem}
  466. }
  467. }
  468. @builtin
  469. incl_bit_set :: proc(s: ^$S/bit_set[$E; $U], other: S) {
  470. s^ |= other
  471. }
  472. @builtin
  473. excl_elem :: proc(s: ^$S/bit_set[$E; $U], elem: E) {
  474. s^ &~= {elem}
  475. }
  476. @builtin
  477. excl_elems :: proc(s: ^$S/bit_set[$E; $U], elems: ..E) {
  478. for elem in elems {
  479. s^ &~= {elem}
  480. }
  481. }
  482. @builtin
  483. excl_bit_set :: proc(s: ^$S/bit_set[$E; $U], other: S) {
  484. s^ &~= other
  485. }
  486. @builtin incl :: proc{incl_elem, incl_elems, incl_bit_set}
  487. @builtin excl :: proc{excl_elem, excl_elems, excl_bit_set}
  488. @builtin
  489. card :: proc(s: $S/bit_set[$E; $U]) -> int {
  490. when size_of(S) == 1 {
  491. return int(intrinsics.count_ones(transmute(u8)s))
  492. } else when size_of(S) == 2 {
  493. return int(intrinsics.count_ones(transmute(u16)s))
  494. } else when size_of(S) == 4 {
  495. return int(intrinsics.count_ones(transmute(u32)s))
  496. } else when size_of(S) == 8 {
  497. return int(intrinsics.count_ones(transmute(u64)s))
  498. } else when size_of(S) == 16 {
  499. return int(intrinsics.count_ones(transmute(u128)s))
  500. } else {
  501. #panic("Unhandled card bit_set size")
  502. }
  503. }
  504. @builtin
  505. raw_array_data :: proc "contextless" (a: $P/^($T/[$N]$E)) -> [^]E {
  506. return ([^]E)(a)
  507. }
  508. @builtin
  509. raw_simd_data :: proc "contextless" (a: $P/^($T/#simd[$N]$E)) -> [^]E {
  510. return ([^]E)(a)
  511. }
  512. @builtin
  513. raw_slice_data :: proc "contextless" (s: $S/[]$E) -> [^]E {
  514. ptr := (transmute(Raw_Slice)s).data
  515. return ([^]E)(ptr)
  516. }
  517. @builtin
  518. raw_dynamic_array_data :: proc "contextless" (s: $S/[dynamic]$E) -> [^]E {
  519. ptr := (transmute(Raw_Dynamic_Array)s).data
  520. return ([^]E)(ptr)
  521. }
  522. @builtin
  523. raw_string_data :: proc "contextless" (s: $S/string) -> [^]u8 {
  524. return (transmute(Raw_String)s).data
  525. }
  526. @builtin
  527. raw_data :: proc{raw_array_data, raw_slice_data, raw_dynamic_array_data, raw_string_data, raw_simd_data}
  528. @builtin
  529. @(disabled=ODIN_DISABLE_ASSERT)
  530. assert :: proc(condition: bool, message := "", loc := #caller_location) {
  531. if !condition {
  532. // NOTE(bill): This is wrapped in a procedure call
  533. // to improve performance to make the CPU not
  534. // execute speculatively, making it about an order of
  535. // magnitude faster
  536. @(cold)
  537. internal :: proc(message: string, loc: Source_Code_Location) {
  538. p := context.assertion_failure_proc
  539. if p == nil {
  540. p = default_assertion_failure_proc
  541. }
  542. p("runtime assertion", message, loc)
  543. }
  544. internal(message, loc)
  545. }
  546. }
  547. @builtin
  548. @(disabled=ODIN_DISABLE_ASSERT)
  549. panic :: proc(message: string, loc := #caller_location) -> ! {
  550. p := context.assertion_failure_proc
  551. if p == nil {
  552. p = default_assertion_failure_proc
  553. }
  554. p("panic", message, loc)
  555. }
  556. @builtin
  557. @(disabled=ODIN_DISABLE_ASSERT)
  558. unimplemented :: proc(message := "", loc := #caller_location) -> ! {
  559. p := context.assertion_failure_proc
  560. if p == nil {
  561. p = default_assertion_failure_proc
  562. }
  563. p("not yet implemented", message, loc)
  564. }
  565. @builtin
  566. @(disabled=ODIN_DISABLE_ASSERT)
  567. unreachable :: proc(message := "", loc := #caller_location) -> ! {
  568. p := context.assertion_failure_proc
  569. if p == nil {
  570. p = default_assertion_failure_proc
  571. }
  572. if message != "" {
  573. p("internal error", message, loc)
  574. } else {
  575. p("internal error", "entered unreachable code", loc)
  576. }
  577. }