core_builtin.odin 16 KB

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