-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:slothlang/sloth
- Loading branch information
Showing
13 changed files
with
154 additions
and
39 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
cargo build --features=llvm-sys/prefer-dynamic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn merge_sort(list: List<Int>) { | ||
print(list); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
|
||
char* readln() { | ||
char* str = malloc(128); | ||
scanf("%127s", str); | ||
return str; | ||
} | ||
|
||
void print(char *str) { | ||
fputs(str, stdout); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
foreign fn print(str: String) Void; | ||
foreign fn readln() String; | ||
|
||
fn println(str: String) Void { | ||
print(str); | ||
print("\n"); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <unistd.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
void wait(long long x) { | ||
sleep(x); | ||
} | ||
|
||
long long slen(char *str) { | ||
return (long long) strlen(str); | ||
} | ||
|
||
char charAt(char *str, long long x) { | ||
return str[x]; | ||
} | ||
|
||
long long parse_int(char *str) { | ||
return (long long) atoi(str); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
foreign fn wait(x: Int) Void; | ||
foreign fn print(str: String) Void; | ||
foreign fn slen(str: String) Int; | ||
foreign fn charAt(str: String) Char; | ||
foreign fn parse_int(str: String) Int; | ||
|
||
fn termpos(x: int, y: int) Void { | ||
print("\x1b["); | ||
print(x); | ||
print(";"); | ||
print(y); | ||
print("H"); | ||
} | ||
|
||
fn termclear() Void { | ||
print("\x1b[2J\x1b[H"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <time.h> | ||
|
||
|
||
long long randGen(long long min, long long max) { | ||
srandom((unsigned) time(NULL)); | ||
return random() % (max - min + 1) + min; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
foreign fn randGen(min: Int, max: Int) Int; | ||
|
||
fn abs(x: Int) Int { | ||
if x < 0 { | ||
return -x; | ||
} | ||
return x; | ||
} | ||
|
||
fn fabs(x: Float) Float { | ||
if x < 0.0 { | ||
return -x; | ||
} | ||
return x; | ||
} | ||
|
||
fn max(x: Int, y: Int) Int { | ||
if x > y { | ||
return x; | ||
} | ||
return y; | ||
} | ||
|
||
fn min(x: Int, y: Int) Int { | ||
if x < y { | ||
return x; | ||
} | ||
return y; | ||
} | ||
|
||
fn fmax(x: Float, y: Float) Float { | ||
if x > y { | ||
return x; | ||
} | ||
return y; | ||
} | ||
|
||
fn fmin(x: Float, y: Float) Float { | ||
if x < y { | ||
return x; | ||
} | ||
return y; | ||
} | ||
|
||
fn pow(x: Int, y: Int) Int { | ||
while y > 1 { | ||
x = x*x; | ||
y = y-1; | ||
} | ||
return x; | ||
} | ||
|
||
fn floor(x: Float) Float { | ||
return x - fabs(x % 1.0); | ||
} | ||
|
||
fn ceil(x: Float) Float { | ||
if x < 0.0 { | ||
return floor(x) - 1.0; | ||
} | ||
return floor(x) + 1.0; | ||
} | ||
|
||
fn round(x: Float) Float { | ||
if fabs(x % 1.0) >= 0.5 { | ||
return ceil(x); | ||
} | ||
return floor(x); | ||
} |