cleaned up the set of samples

This commit is contained in:
cozis
2022-03-08 22:20:04 +01:00
parent 542177e46f
commit 94dc01dcaa
12 changed files with 4 additions and 186 deletions
-36
View File
@@ -1,36 +0,0 @@
stack = {count: 0, head: none};
fun push(stack, value)
{
node = {prev: null, item: value};
node.prev = list.head;
stack.head = node;
stack.count += 1;
}
fun pop(stack)
{
if stack.head is none:
return none; # return it; ?
value = stack.head.item;
stack.head = stack.head.prev;
stack.count -= 1;
return value;
}
push(stack, 1);
push(stack, 2);
push(stack, 3);
x = pop(stack);
y = pop(stack);
z = pop(stack);
w = pop(stack);
assert x == 3;
assert y == 2;
assert z == 1;
assert w == none;
-25
View File
@@ -1,25 +0,0 @@
{
fun Apple(Apple, Apple, Apple)
while 13:
return 26.7;
return "Hello, world!";
}
do
while 46.9:
do
fun Apple()
{}
while {67.97: "Hello, world!", 50.36: "Hello, world!", 54.91: 9};
while 26;
[{90: "Hello, world!"}, {14: 56.96, 16.24: 23, []: [20.31, 41.3, 33.49]}, 44.62];
fun Apple(Apple, Apple, Apple) while {[]: 88.42}: do return 57.21; while [];
do if []: if {"Hello, world!": "Hello, world!", 0.65: 13.22, "Hello, world!": 61.3}: fun Apple(Apple, Apple, Apple) {} while 3.15;
return 41;
["Hello, world!", 34.8];
return {34.81: {}};
do return "Hello, world!"; while [[[12.36, "Hello, world!"], 98, [48.22, 29.87, "Hello, world!"]], [{10.78: 32.44}], "Hello, world!"];
do {return 99.31;fun Apple(Apple, Apple) if "Hello, world!": {}} while "Hello, world!";
return 38.57;
return {67: {"Hello, world!": 93, 5: 84.14, 9: [83.73, 65.86, 47.73]}, "Hello, world!": 40};
-12
View File
@@ -1,12 +0,0 @@
fun isalpha(c)
return c <
fun parse(req)
{
i = 0;
while i < count(req) && isalpha(req[i]):
i = i + 1;
}
-23
View File
@@ -1,23 +0,0 @@
a = 'Francesco';
b = 'Gennaro';
print('Are ', a, ' and ', b, ' the same name?\n');
if a == b:
print('Yup!\n');
else
print('Nop!\n');
# Now they are!
a = 'Francesco';
b = 'Francesco';
print('Are ', a, ' and ', b, ' the same name?\n');
if a == b:
print('Yup!\n');
else
print('Nop!\n');
-7
View File
@@ -1,7 +0,0 @@
define = true;
if define:
a = 33;
print(a, '\n');
-26
View File
@@ -1,26 +0,0 @@
# ------------------------------------- #
# -- While loop ----------------------- #
i = 0;
while i < 3:
{
print('Hello from the while loop!\n');
i = i + 1;
}
# ------------------------------------- #
# -- Do-Wile loop --------------------- #
i = 0;
do
{
print('Hello from the do-while loop!\n');
i = i + 1;
}
while i < 3;
# ------------------------------------- #
# ------------------------------------- #
+1
View File
@@ -1,3 +1,4 @@
# This script creates a lot of objects, so it can be used to stress the garbage collector.
print('Start\n'); print('Start\n');
-55
View File
@@ -1,55 +0,0 @@
port = 8080;
backlog = 5;
fd = net.socket(net.AF_INET, net.SOCK_STREAM, 0);
if fd < 0:
{
print('Failed to create socket.\n');
return none;
}
if net.bind(fd, {sin_family: net.AF_INET, sin_port: net.htons(port), sin_addr: {s_addr: net.htonl(net.INADDR_ANY)}}) != 0:
{
print('Failed to bind.\n');
return none;
}
if net.listen(fd, backlog) != 0:
{
print('Failed to listen.\n');
return none;
}
buffer = newBuffer(16);
while true:
{
client_addr = {};
client_fd = net.accept(fd, client_addr);
if client_fd < 0:
print('Warning! Failed to accept!\n');
print('Got a connection!\n');
print('client_fd = ', client_fd, '\n');
print('client_addr = {', client_addr, '}\n');
do
{
n = net.recv(client_fd, buffer, 0);
if n < 0:
print('Warning! Failed to read from socket!\n');
else if n == 0:
{
# Client disconnected.
}
else
{
print('Received ', n, ' bytes: ', buffer, '\n');
}
}
while n > 0;
}
@@ -1,3 +1,4 @@
# Implementation of a stack using a linked list.
stack = {count: 0, head: none}; stack = {count: 0, head: none};
@@ -1,3 +1,4 @@
# Implementation of a basic TCP server that listen for connections and prints received bytes.
fun startServer(callbacks, port, backlog) fun startServer(callbacks, port, backlog)
{ {
@@ -96,7 +97,7 @@ fun on_connect(addr)
fun on_datain(addr, data) fun on_datain(addr, data)
{ {
print('Received ', count(data), ' bytes from ', addr, '\n'); print('Received ', count(data), ' bytes from ', addr, ': ', data, '\n');
} }
fun on_disconnect(addr) fun on_disconnect(addr)
-1
View File
@@ -1 +0,0 @@
'hello' + ' world!';