forked from coalton-lang/coalton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem.lisp
49 lines (41 loc) · 1.41 KB
/
system.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(coalton-library/utils:defstdlib-package #:coalton-library/system
(:use
#:coalton
#:coalton-library/builtin
#:coalton-library/classes)
(:export
#:gc
#:time
#:sleep))
(in-package #:coalton-library/system)
(named-readtables:in-readtable coalton:coalton)
#+coalton-release
(cl:declaim #.coalton-impl/settings:*coalton-optimize-library*)
(coalton-toplevel
(declare gc (Unit -> Unit))
(define (gc _)
"Perform a full garbage collection."
(lisp Unit ()
(trivial-garbage:gc :full cl:t)
Unit))
(declare time ((Unit -> :a) -> (Tuple :a Integer)))
(define (time f)
"Run the thunk `f` and return a tuple containing its value along with the run time in microseconds.
While the result will always contain microseconds, some implementations may return a value rounded to less precision (e.g., rounded to the nearest second or millisecond)."
(let start = (lisp Integer () (cl:get-internal-run-time)))
(let value = (f))
(let end = (lisp Integer () (cl:get-internal-run-time)))
(Tuple value
(lisp Integer (start end)
(cl:values
(cl:round
(cl:* 1000000 (cl:- end start))
cl:internal-time-units-per-second)))))
(declare sleep (Integer -> Unit))
(define (sleep n)
"Sleep for `n` seconds."
(lisp Unit (n)
(cl:sleep n)
Unit)))
#+sb-package-locks
(sb-ext:lock-package "COALTON-LIBRARY/SYSTEM")