https://github.com/akkartik/mu/blob/main/402time.mu
1 type timespec {
2 tv_sec: int
3 tv_nsec: int
4 }
5
6
7
8 fn time -> _/eax: int {
9 var t: timespec
10 var clock/ebx: int <- copy 0
11 var t-addr/ecx: (addr timespec) <- address t
12 syscall_clock_gettime
13 var t-secs-addr/ecx: (addr int) <- get t-addr, tv_sec
14 var secs/eax: int <- copy *t-secs-addr
15 return secs
16 }
17
18
19 fn ntime -> _/eax: int {
20 var t: timespec
21 var clock/ebx: int <- copy 0
22 var t-addr/ecx: (addr timespec) <- address t
23 syscall_clock_gettime
24 var t-nsecs-addr/ecx: (addr int) <- get t-addr, tv_nsec
25 var nsecs/eax: int <- copy *t-nsecs-addr
26 return nsecs
27 }
28
29
30 fn sleep secs: int, nsecs: int {
31 var t: timespec
32
33 var tmp/eax: (addr int) <- get t, tv_sec
34 var tmp2/ecx: int <- copy secs
35 copy-to *tmp, tmp2
36 tmp <- get t, tv_nsec
37 tmp2 <- copy nsecs
38 copy-to *tmp, tmp2
39
40 var t-addr/ebx: (addr timespec) <- address t
41 var rem-addr/ecx: (addr timespec) <- copy 0
42 syscall_nanosleep
43 }