File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
Expand file tree Collapse file tree 2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 11import "LowLevel/Floats";
2+ import "LowLevel/Limits";
23import "Math/Rounding";
34import "Math/Core";
45
@@ -32,6 +33,38 @@ func str input() {
3233 ret o;
3334}
3435
36+ /%
37+ @asm
38+
39+ Stops the program for @"time" seconds.
40+ @"time" will be clamped between 0 and @"INT_MAX".
41+ %/
42+ func void sleep(dec time) {
43+ // Special cases
44+
45+ if (time <= 0.0) {
46+ ret;
47+ }
48+
49+ if (time > INT_MAX -> dec) {
50+ time = INT_MAX -> dec;
51+ }
52+
53+ // Convert input to seconds and nanoseconds
54+
55+ dec rounded = floor(time);
56+ int seconds = rounded -> int;
57+ int nano = ((time - rounded) * 1'000'000'000.0) -> int;
58+
59+ // Call syscall
60+
61+ assembly {
62+ vlist_get rdi, $seconds$
63+ vlist_get rsi, $nano$
64+ call sleep
65+ }
66+ }
67+
3568/%
3669Converts @"b" into a string.
3770
Original file line number Diff line number Diff line change 1+ namespace LowLevel;
2+
3+ /%
4+ The minimum value for a variable with the type of `int`.
5+ %/
6+ const int INT_MIN = -9'223'372'036'854'775'808;
7+ /%
8+ The maximum value for a variable with the type of `int`.
9+ %/
10+ const int INT_MAX = 9'223'372'036'854'775'807;
You can’t perform that action at this time.
0 commit comments