aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbuild.sh6
-rw-r--r--examples/cgol.sloth50
-rw-r--r--sloth/src/codegen/mod.rs2
-rw-r--r--sloth/src/main.rs2
-rw-r--r--std/stdio.c60
-rw-r--r--test.sloth10
6 files changed, 69 insertions, 61 deletions
diff --git a/build.sh b/build.sh
index 2bdd204..a53fb29 100755
--- a/build.sh
+++ b/build.sh
@@ -1,11 +1,11 @@
# Build Sloth
-cargo build
+#cargo build
FILENAME="$1"
# Compile standard library
-./target/debug/sloth std/extern.sloth std/stdmath.sloth std/stdio.sloth $FILENAME
+./target/release/sloth std/extern.sloth std/stdmath.sloth std/stdio.sloth $FILENAME
# Generate binary
-clang -lm output.o std/stdio.c std/stdlib.c std/stdmath.c -o "${FILENAME%.sloth}"
+clang -lm output.o std/stdsocket.c std/stdio.c std/stdlib.c std/stdmath.c -o "${FILENAME%.sloth}"
# Move file
mv "${FILENAME%.sloth}" out/
diff --git a/examples/cgol.sloth b/examples/cgol.sloth
index a0e1878..fafe440 100644
--- a/examples/cgol.sloth
+++ b/examples/cgol.sloth
@@ -1,7 +1,7 @@
fn populate() [Int]
{
# Initialize life vector
- var life: [Int] = [0];
+ var life: [Int] = [1];
vpopi(life);
# Fill the vector with random values
@@ -28,26 +28,28 @@ fn coord(x: Int, y: Int) Int
return res;
}
-fn cval(x: Int, y: Int, life: [Int]) Int
+fn cval(x: Int, y: Int, life: [Int]) Int
{
# Check to make sure index exists before returning
var res: Int = 0;
var c: Int = coord(x, y);
- if c >= 0 {
+ if c >= 0
+ {
res = vgeti(life, c);
}
return res;
}
-fn gol(total: Int, alive: Bool) Int
-{
+#fn gol(total: Int, alive: Bool) Int
+#{
- if !alive && total == 3 {
- return 1;
- }
- if alive && ()
- return 0;
-}
+ #if !alive && total == 3
+ #{
+ #return 1;
+ #}
+ #if alive && ()
+ #return 0;
+ #}
fn update(life: [Int], new: [Int])
{
@@ -97,32 +99,40 @@ fn update(life: [Int], new: [Int])
}
}
-fn display(life: [Int]) {
+fn display(life: [Int])
+{
# Iterate through life
- for x in 3..62 {
- for y in 0..240 {
+ for x in 3..62
+ {
+ for y in 0..240
+ {
termpos(x-3, y);
- if cval(x-3, y, life) == 1 {
+ if cval(x-3, y, life) == 1
+ {
print("█");
- } else {
+ }
+ else
+ {
print(" ");
}
}
}
}
-fn main() Int {
+fn main() Int
+{
# Populate
var life: [Int] = populate();
display(life);
- curshide();
+ curshide();
# Play forever
- while true {
+ while true
+ {
var new: [Int] = populate();
update(life, new);
display(new);
life = new;
- wait(100);
+ # wait(100);
}
return 0;
}
diff --git a/sloth/src/codegen/mod.rs b/sloth/src/codegen/mod.rs
index e2c8082..7ac1011 100644
--- a/sloth/src/codegen/mod.rs
+++ b/sloth/src/codegen/mod.rs
@@ -71,6 +71,7 @@ impl<'ctx> Codegen<'ctx> {
for stmt in stmts {
self.codegen_stmt(stmt);
+ self.current_func.unwrap().print_to_stderr();
}
}
@@ -555,7 +556,6 @@ impl<'ctx> Codegen<'ctx> {
"",
)
};
-
self.builder.build_store(value_ptr, value);
}
diff --git a/sloth/src/main.rs b/sloth/src/main.rs
index f66a1be..c0a76ad 100644
--- a/sloth/src/main.rs
+++ b/sloth/src/main.rs
@@ -50,7 +50,7 @@ fn main() {
// Parsing
let tokens = Lexer::new(&source).collect_vec();
- println!("{tokens:#?}");
+ //println!("{tokens:#?}");
let global_symtable = mk_symtable();
let mut ast = match AstParser::parse(tokens, global_symtable) {
diff --git a/std/stdio.c b/std/stdio.c
index b5f1dd0..e9cefd0 100644
--- a/std/stdio.c
+++ b/std/stdio.c
@@ -1,48 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
-char* readln() {
- char* str = malloc(128);
- scanf("%127s", str);
- return str;
+char *readln() {
+ char *str = malloc(128);
+ fgets(str, 127, stdin);
+ return str;
}
-void print(char *str) {
- fputs(str, stdout);
-}
+void print(char *str) { fputs(str, stdout); }
-void termpos(int x, int y) {
- printf("\x1b[%d;%dH", x, y);
-}
+void termpos(int x, int y) { printf("\x1b[%d;%dH", x, y); }
-void termclear() {
- printf("\x1b[2J\x1b[H");
-}
+void termclear() { printf("\x1b[2J\x1b[H"); }
-void curshide() {
- print("\x1b[?25l");
-}
+void curshide() { print("\x1b[?25l"); }
-void cursshow() {
- print("\x1b[?25h");
-}
+void cursshow() { print("\x1b[?25h"); }
-char* filer(char* path) {
- FILE *fptr = fopen(path, "rb");
- char *contents = 0;
-
- if(fptr == NULL) {
- return "File not found";
- }
- fseek(fptr, 0, SEEK_END);
- long size = ftell(fptr);
- fseek(fptr, 0, SEEK_SET);
-
- contents = malloc(size);
- fread(contents, 1, size, fptr);
- fclose(fptr);
-
- return contents;
-}
+char *filer(char *path) {
+ FILE *fptr = fopen(path, "rb");
+ char *contents = 0;
+ if (fptr == NULL) {
+ return "File not found";
+ }
+ fseek(fptr, 0, SEEK_END);
+ long size = ftell(fptr);
+ fseek(fptr, 0, SEEK_SET);
+ contents = malloc(size);
+ fread(contents, 1, size, fptr);
+ fclose(fptr);
+
+ return contents;
+}
diff --git a/test.sloth b/test.sloth
new file mode 100644
index 0000000..be3b1de
--- /dev/null
+++ b/test.sloth
@@ -0,0 +1,10 @@
+
+fn getStr() Bool
+{
+ return true;
+}
+
+fn main() Int {
+ val poggers: Int = getStr();
+ return 0;
+}