-
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.
- Loading branch information
1 parent
ee2133a
commit 52d6bc8
Showing
13 changed files
with
147 additions
and
131 deletions.
There are no files selected for viewing
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 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 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 |
---|---|---|
@@ -1,36 +1,39 @@ | ||
#foreign fn print(str: String); | ||
#foreign fn printint(i: Int); | ||
#foreign fn as_int(x: Float) Int; | ||
fn main() Int{ | ||
# Configure | ||
var size: Float = 1000.0; | ||
var maxVal: Float = 4.0; | ||
var maxIter: Float = 50.0; | ||
var plane: Float = 4.0; | ||
|
||
#foreign fn termpos(x: Int, y: Int) Void; | ||
# loop over coordinates | ||
var x: Float = 0.0; | ||
while x < size { | ||
var y: Float = 0.0; | ||
while y < size { | ||
# Initialize | ||
var cReal: Float = (x * plane / size) - 2.0; | ||
var cImg: Float = (y * plane / size) - 2.0; | ||
var zReal: Float = 0.0; | ||
var zImg: Float = 0.0; | ||
var count: Float = 0.0; | ||
|
||
fn main() Int{ | ||
var size: Float = 1000.0; | ||
var maxVal: Float = 4.0; | ||
var maxIter: Float = 50.0; | ||
var plane: Float = 4.0; | ||
var x: Float = 0.0; | ||
while x < size { | ||
var y: Float = 0.0; | ||
while y < size { | ||
var cReal: Float = (x * plane / size) - 2.0; | ||
var cImg: Float = (y * plane / size) - 2.0; | ||
var zReal: Float = 0.0; | ||
var zImg: Float = 0.0; | ||
var count: Float = 0.0; | ||
while (zReal * zReal + zImg * zImg) <= maxVal && count < maxIter { | ||
var temp: Float = (zReal * zReal) - (zImg * zImg) + cReal; | ||
zImg = 2.0 * zReal * zImg + cImg; | ||
zReal = temp; | ||
count = count + 1.0; | ||
} | ||
if as_int(count) == as_int(maxIter) { | ||
termpos(as_int(x), as_int(y)); | ||
print("*"); | ||
} | ||
y = y + 1.0; | ||
} | ||
x = x + 1.0; | ||
# Calculate | ||
while (zReal * zReal + zImg * zImg) <= maxVal && count < maxIter { | ||
var temp: Float = (zReal * zReal) - (zImg * zImg) + cReal; | ||
zImg = 2.0 * zReal * zImg + cImg; | ||
zReal = temp; | ||
count = count + 1.0; | ||
} | ||
|
||
# Check | ||
if as_int(count) == as_int(maxIter) { | ||
termpos(as_int(x), as_int(y)); | ||
print("█"); | ||
} | ||
|
||
y = y + 1.0; | ||
} | ||
return 0; | ||
x = x + 1.0; | ||
} | ||
return 0; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
fn main() Int { | ||
print(filer("examples/read.txt")); | ||
print(filer("examples/server.sloth")); | ||
return 0; | ||
} |
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,28 @@ | ||
# stdio | ||
foreign fn print(str: String) Void; | ||
foreign fn readln() String; | ||
foreign fn filer(path: String) String; | ||
foreign fn curshide(); | ||
foreign fn cursshow(); | ||
|
||
# stdlib | ||
foreign fn wait(x: Int) Int; | ||
foreign fn slen(str: String) Int; | ||
# foreign fn charAt(str: String) Char; | ||
foreign fn parse_int(str: String) Int; | ||
foreign fn termpos(x: Int, y: Int); | ||
foreign fn as_int(x: Float) Int; | ||
foreign fn istr(x: Int) String; | ||
foreign fn system(cmd: String) Int; | ||
foreign fn sequals(a: String, b: String) Bool; | ||
foreign fn termclear() Void; | ||
|
||
#stdmath | ||
foreign fn randGen(min: Int, max: Int) Int; | ||
|
||
#stdsocket | ||
foreign fn serversock(port: Int, addr: String, backlog: Int) Int; | ||
foreign fn clientsock(port: Int, addr: String) Int; | ||
foreign fn closesock(soc: Int, server:Bool); | ||
foreign fn sendsock(msg: String, soc: Int); | ||
foreign fn recvsock(soc: Int) String; |
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
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 |
---|---|---|
@@ -1,76 +1,76 @@ | ||
#include "stdlib.c" | ||
#include <netinet/in.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/socket.h> | ||
#include <unistd.h> | ||
#include <stdbool.h> | ||
|
||
int serversock(int PORT, char* addr, int backlog) { | ||
int opt = 1; | ||
int sock, new_sock; | ||
struct sockaddr_in address; | ||
int addrlen = sizeof(address); | ||
int serversock(int PORT, char *addr, int backlog) { | ||
int opt = 1; | ||
int sock, new_sock; | ||
struct sockaddr_in address; | ||
int addrlen = sizeof(address); | ||
|
||
if((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { | ||
perror("socket failed"); | ||
exit(EXIT_FAILURE); | ||
} | ||
if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) { | ||
perror("socket failed"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, sizeof(opt)) < 0 ) { | ||
perror("setsockopt"); | ||
exit(EXIT_FAILURE); | ||
} | ||
if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, &opt, | ||
sizeof(opt)) < 0) { | ||
perror("setsockopt"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
address.sin_family = AF_INET; | ||
if (sequals(addr, "auto")) { | ||
address.sin_addr.s_addr = INADDR_ANY; | ||
} else { | ||
inet_aton(addr, &address.sin_addr.s_addr); | ||
} | ||
address.sin_port = htons(PORT); | ||
address.sin_family = AF_INET; | ||
if (sequals(addr, "auto")) { | ||
address.sin_addr.s_addr = INADDR_ANY; | ||
} else { | ||
inet_aton(addr, &address.sin_addr.s_addr); | ||
} | ||
address.sin_port = htons(PORT); | ||
|
||
if (bind(sock, (struct sockaddr*)&address, sizeof(address)) < 0) { | ||
perror("bind"); | ||
exit(EXIT_FAILURE); | ||
} | ||
if (listen(sock, backlog) < 0) { | ||
perror("listen"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
if ((new_sock = accept(sock, (struct sockaddr*)&address, (socklen_t*)&addrlen)) < 0) { | ||
perror("accept"); | ||
exit(EXIT_FAILURE); | ||
} | ||
return new_sock; | ||
if (bind(sock, (struct sockaddr *)&address, sizeof(address)) < 0) { | ||
perror("bind"); | ||
exit(EXIT_FAILURE); | ||
} | ||
if (listen(sock, backlog) < 0) { | ||
perror("listen"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
if ((new_sock = accept(sock, (struct sockaddr *)&address, | ||
(socklen_t *)&addrlen)) < 0) { | ||
perror("accept"); | ||
exit(EXIT_FAILURE); | ||
} | ||
return new_sock; | ||
} | ||
|
||
int clientsock(int PORT, char *server_ip) { | ||
struct sockaddr_in serv_addr; | ||
int sock = socket(PF_INET, SOCK_STREAM, 0); | ||
serv_addr.sin_family = AF_INET; | ||
serv_addr.sin_port = htons(PORT); | ||
|
||
int clientsock(int PORT, char* server_ip) { | ||
struct sockaddr_in serv_addr; | ||
int sock = socket(PF_INET, SOCK_STREAM, 0); | ||
serv_addr.sin_family = AF_INET; | ||
serv_addr.sin_port = htons(PORT); | ||
|
||
inet_pton(AF_INET, server_ip, &serv_addr.sin_addr); | ||
int status = connect(sock, (struct sockaddr*)&serv_addr, sizeof(serv_addr)); | ||
return sock; | ||
inet_pton(AF_INET, server_ip, &serv_addr.sin_addr); | ||
int status = connect(sock, (struct sockaddr *)&serv_addr, sizeof(serv_addr)); | ||
return sock; | ||
} | ||
|
||
char* recvsock(int soc) { | ||
char* buf = malloc(1024); | ||
int valread = read(soc, buf, 1024); | ||
return buf; | ||
char *recvsock(int soc) { | ||
char *buf = malloc(1024); | ||
int valread = read(soc, buf, 1024); | ||
return buf; | ||
} | ||
|
||
void sendsock(char* msg, int soc) { | ||
send(soc, msg, strlen(msg), 0); | ||
} | ||
void sendsock(char *msg, int soc) { send(soc, msg, strlen(msg), 0); } | ||
|
||
void closesock(int soc, bool server) { | ||
close(soc); | ||
if (server) { | ||
shutdown(soc, SHUT_RDWR); | ||
} | ||
close(soc); | ||
if (server) { | ||
shutdown(soc, SHUT_RDWR); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.