harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

rtmain.ha (655B)


      1 @symbol("main") fn main() void;
      2 
      3 const @symbol("__init_array_start") init_start: [*]*fn() void;
      4 const @symbol("__init_array_end") init_end: [*]*fn() void;
      5 const @symbol("__fini_array_start") fini_start: [*]*fn() void;
      6 const @symbol("__fini_array_end") fini_end: [*]*fn() void;
      7 
      8 export @noreturn fn start_ha(iv: [*]uintptr) void = {
      9 	const ninit = (&init_end: uintptr - &init_start: uintptr): size
     10 		/ size(*fn() void);
     11 	for (let i = 0z; i < ninit; i += 1) {
     12 		init_start[i]();
     13 	};
     14 
     15 	main();
     16 
     17 	const nfini = (&fini_end: uintptr - &fini_start: uintptr): size
     18 		/ size(*fn() void);
     19 	for (let i = 0z; i < nfini; i += 1) {
     20 		fini_start[i]();
     21 	};
     22 
     23 	exit(0);
     24 };