https://github.com/akkartik/mu/blob/master/402time.mu
 1 type timespec {
 2   tv_sec: int
 3   tv_nsec: int
 4 }
 5 
 6 # TODO: y2038
 7 fn time -> secs/eax: int {
 8   var t: timespec
 9   var clock/ebx: int <- copy 0  # CLOCK_MONOTONIC
10   var t-addr/ecx: (addr timespec) <- address t
11   syscall_clock_gettime
12   var t-secs-addr/ecx: (addr int) <- get t-addr, tv_sec
13   secs <- copy *t-secs-addr
14 }
15 
16 fn ntime -> nsecs/eax: int {
17   var t: timespec
18   var clock/ebx: int <- copy 0  # CLOCK_MONOTONIC
19   var t-addr/ecx: (addr timespec) <- address t
20   syscall_clock_gettime
21   var t-nsecs-addr/ecx: (addr int) <- get t-addr, tv_nsec
22   nsecs <- copy *t-nsecs-addr
23 }
24 
25 # nsecs must be less than 999999999 or 0x3b9ac9ff nanoseconds
26 fn sleep secs: int, nsecs: int {
27   var t: timespec
28   # initialize t
29   var tmp/eax: (addr int) <- get t, tv_sec
30   var tmp2/ecx: int <- copy secs
31   copy-to *tmp, tmp2
32   tmp <- get t, tv_nsec
33   tmp2 <- copy nsecs
34   copy-to *tmp, tmp2
35   # perform the syscall
36   var t-addr/ebx: (addr timespec) <- address t
37   var rem-addr/ecx: (addr timespec) <- copy 0
38   syscall_nanosleep
39 }