Skip to content

Commit b84d6e2

Browse files
committed
Added doc-comments to all files
1 parent f6a7731 commit b84d6e2

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

Core.scope

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,31 @@
1+
/%
2+
@noalloc: This function does not use string concatenation.
3+
4+
Prints @"s" into `stdout` along with a new-line.
5+
%/
16
func void println(str s) {
2-
print(s + "\n");
7+
print(s);
8+
print("\n");
39
}
410

11+
/%
12+
Converts @"b" into a string.
13+
14+
Returns `"true"` or `"false"`.
15+
%/
516
func str boolToStr(bool b) {
617
if (b) {
718
ret "true";
819
}
920
ret "false";
1021
}
1122

23+
/%
24+
Converts @"num" into a string.
25+
26+
Returns the number in a basic format without any commas.
27+
Prepends a `-` if negative.
28+
%/
1229
func str intToStr(int num) {
1330
// If we don't do this, this will return ""
1431
if (num == 0) {

LowLevel/BitManip.scope

+38
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/%
2+
Converts @"num" into a 64 character binary number.
3+
4+
`3354674` -> `00000000000000000000000000000000000000000001100110011000000110010`
5+
%/
16
func str toBin(int num) {
27
str out = "";
38
for (int i : 0..65) {
@@ -13,6 +18,11 @@ func str toBin(int num) {
1318
ret out;
1419
}
1520

21+
/%
22+
Converts the bits of @"a" into a decimal number.
23+
24+
No type conversion is done. Use casting if you intend on the numerical values matching.
25+
%/
1626
func dec rawCastIntToDec(int a) {
1727
dec o = 0.0;
1828
assembly {
@@ -23,6 +33,11 @@ func dec rawCastIntToDec(int a) {
2333
ret o;
2434
}
2535

36+
/%
37+
Converts the bits of @"a" into a integer.
38+
39+
No type conversion is done. Use casting if you intend on the numerical values matching.
40+
%/
2641
func int rawCastDecToInt(dec a) {
2742
int o = 0;
2843
assembly {
@@ -33,10 +48,16 @@ func int rawCastDecToInt(dec a) {
3348
ret o;
3449
}
3550

51+
/%
52+
Returns the @"n"th bit of @"a".
53+
%/
3654
func int nthBit(int n, int a) {
3755
ret and(shr(a, n), 1);
3856
}
3957

58+
/%
59+
Returns the bitwise and of @"a" and @"b".
60+
%/
4061
func int and(int a, int b) {
4162
int o = 0;
4263
assembly {
@@ -49,6 +70,9 @@ func int and(int a, int b) {
4970
ret o;
5071
}
5172

73+
/%
74+
Returns the bitwise or of @"a" and @"b".
75+
%/
5276
func int or(int a, int b) {
5377
int o = 0;
5478
assembly {
@@ -61,6 +85,9 @@ func int or(int a, int b) {
6185
ret o;
6286
}
6387

88+
/%
89+
Returns the bitwise xor of @"a" and @"b".
90+
%/
6491
func int xor(int a, int b) {
6592
int o = 0;
6693
assembly {
@@ -73,6 +100,9 @@ func int xor(int a, int b) {
73100
ret o;
74101
}
75102

103+
/%
104+
Returns the bitwise not of @"a".
105+
%/
76106
func int not(int a) {
77107
int o = 0;
78108
assembly {
@@ -84,6 +114,10 @@ func int not(int a) {
84114
ret o;
85115
}
86116

117+
/%
118+
Returns @"a" bit-shifted to the left by @"b".
119+
@"b" gets down casted into a 8-bit number (0-255). Upper bits are ignored.
120+
%/
87121
func int shl(int a, int b) {
88122
int o = 0;
89123
assembly {
@@ -96,6 +130,10 @@ func int shl(int a, int b) {
96130
ret o;
97131
}
98132

133+
/%
134+
Returns @"a" bit-shifted to the right by @"b".
135+
@"b" gets down casted into a 8-bit number (0-255). Upper bits are ignored.
136+
%/
99137
func int shr(int a, int b) {
100138
int o = 0;
101139
assembly {

Test.scope

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import "Core";
2-
import "LowLevel/BitManip";
2+
import "LowLevel/Floats";
3+
import "Math/Rounding";
34

45
func void main() {
56
println("println");
@@ -11,4 +12,9 @@ func void main() {
1112
int moreBits = -987181;
1213
println(toBin(moreBits));
1314
println(toBin(and(bits, moreBits)));
15+
16+
println(intToStr(exponentPart(0.01)));
17+
println(intToStr(mantissaPart(0.01)));
18+
19+
println(toBin(rawCastDecToInt(floor(5.3))));
1420
}

0 commit comments

Comments
 (0)