vile / scheme / system.c.v
39 lines · 33 sloc · 979 bytes · 76646891b77a3d5c6af4a1e42b122cd61dc1654b
Raw
1module scheme
2
3$if !freestanding || (macos && arm64) {
4 #include "@VMODROOT/scheme/system.h"
5
6 fn C.vile_system_tai_seconds(result &f64) bool
7 fn C.vile_system_terminate(status i64, emergency bool)
8}
9
10$if freestanding && macos && amd64 {
11 @[noreturn]
12 fn C._Exit(i32)
13}
14
15fn system_tai_seconds() ?f64 {
16 $if freestanding {
17 seconds, nanoseconds, code := bf_tai_now()
18 if code != 0 { return none }
19 return f64(seconds) + f64(nanoseconds) / 1_000_000_000.0
20 } $else {
21 mut seconds := 0.0
22 if C.vile_system_tai_seconds(&seconds) { return seconds }
23 return none
24 }
25}
26
27fn system_terminate(status i64, emergency bool) {
28 $if freestanding && (!macos || amd64) {
29 // Scheme cleanup is performed before the host hook. The AMD64 Mac
30 // runtime also distinguishes native finalizers from emergency termination.
31 $if macos && amd64 {
32 if emergency { C._Exit(i32(u64(status) & 255)) }
33 }
34 exit(int(u64(status) & 255))
35 } $else {
36 C.vile_system_terminate(status, emergency)
37 }
38}
39
40