File tree 2 files changed +43
-0
lines changed
2 files changed +43
-0
lines changed Original file line number Diff line number Diff line change 1
1
import "LowLevel/Floats";
2
+ import "LowLevel/Limits";
2
3
import "Math/Rounding";
3
4
import "Math/Core";
4
5
@@ -32,6 +33,38 @@ func str input() {
32
33
ret o;
33
34
}
34
35
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
+
35
68
/%
36
69
Converts @"b" into a string.
37
70
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