Skip to content

Commit

Permalink
Added doc-comments to all files
Browse files Browse the repository at this point in the history
  • Loading branch information
EliteAsian123 committed Sep 27, 2022
1 parent f6a7731 commit b84d6e2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
19 changes: 18 additions & 1 deletion Core.scope
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
/%
@noalloc: This function does not use string concatenation.

Prints @"s" into `stdout` along with a new-line.
%/
func void println(str s) {
print(s + "\n");
print(s);
print("\n");
}

/%
Converts @"b" into a string.

Returns `"true"` or `"false"`.
%/
func str boolToStr(bool b) {
if (b) {
ret "true";
}
ret "false";
}

/%
Converts @"num" into a string.

Returns the number in a basic format without any commas.
Prepends a `-` if negative.
%/
func str intToStr(int num) {
// If we don't do this, this will return ""
if (num == 0) {
Expand Down
38 changes: 38 additions & 0 deletions LowLevel/BitManip.scope
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/%
Converts @"num" into a 64 character binary number.

`3354674` -> `00000000000000000000000000000000000000000001100110011000000110010`
%/
func str toBin(int num) {
str out = "";
for (int i : 0..65) {
Expand All @@ -13,6 +18,11 @@ func str toBin(int num) {
ret out;
}

/%
Converts the bits of @"a" into a decimal number.

No type conversion is done. Use casting if you intend on the numerical values matching.
%/
func dec rawCastIntToDec(int a) {
dec o = 0.0;
assembly {
Expand All @@ -23,6 +33,11 @@ func dec rawCastIntToDec(int a) {
ret o;
}

/%
Converts the bits of @"a" into a integer.

No type conversion is done. Use casting if you intend on the numerical values matching.
%/
func int rawCastDecToInt(dec a) {
int o = 0;
assembly {
Expand All @@ -33,10 +48,16 @@ func int rawCastDecToInt(dec a) {
ret o;
}

/%
Returns the @"n"th bit of @"a".
%/
func int nthBit(int n, int a) {
ret and(shr(a, n), 1);
}

/%
Returns the bitwise and of @"a" and @"b".
%/
func int and(int a, int b) {
int o = 0;
assembly {
Expand All @@ -49,6 +70,9 @@ func int and(int a, int b) {
ret o;
}

/%
Returns the bitwise or of @"a" and @"b".
%/
func int or(int a, int b) {
int o = 0;
assembly {
Expand All @@ -61,6 +85,9 @@ func int or(int a, int b) {
ret o;
}

/%
Returns the bitwise xor of @"a" and @"b".
%/
func int xor(int a, int b) {
int o = 0;
assembly {
Expand All @@ -73,6 +100,9 @@ func int xor(int a, int b) {
ret o;
}

/%
Returns the bitwise not of @"a".
%/
func int not(int a) {
int o = 0;
assembly {
Expand All @@ -84,6 +114,10 @@ func int not(int a) {
ret o;
}

/%
Returns @"a" bit-shifted to the left by @"b".
@"b" gets down casted into a 8-bit number (0-255). Upper bits are ignored.
%/
func int shl(int a, int b) {
int o = 0;
assembly {
Expand All @@ -96,6 +130,10 @@ func int shl(int a, int b) {
ret o;
}

/%
Returns @"a" bit-shifted to the right by @"b".
@"b" gets down casted into a 8-bit number (0-255). Upper bits are ignored.
%/
func int shr(int a, int b) {
int o = 0;
assembly {
Expand Down
8 changes: 7 additions & 1 deletion Test.scope
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "Core";
import "LowLevel/BitManip";
import "LowLevel/Floats";
import "Math/Rounding";

func void main() {
println("println");
Expand All @@ -11,4 +12,9 @@ func void main() {
int moreBits = -987181;
println(toBin(moreBits));
println(toBin(and(bits, moreBits)));

println(intToStr(exponentPart(0.01)));
println(intToStr(mantissaPart(0.01)));

println(toBin(rawCastDecToInt(floor(5.3))));
}

0 comments on commit b84d6e2

Please sign in to comment.