hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

initfini.ha (526B)


      1 // SPDX-License-Identifier: MPL-2.0
      2 // (c) Hare authors <https://harelang.org>
      3 
      4 // Run all global initialization functions.
      5 export fn init() void = {
      6 	const ninit = (&init_end: uintptr - &init_start: uintptr): size
      7 		/ size(*fn() void);
      8 	for (let i = 0z; i < ninit; i += 1) {
      9 		init_start[i]();
     10 	};
     11 };
     12 
     13 // Run all global finalization functions.
     14 export fn fini() void = {
     15 	const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
     16 		/ size(*fn() void);
     17 	for (let i = nfini; i > 0; i -= 1) {
     18 		fini_start[i - 1]();
     19 	};
     20 };