diff --git a/samples/func.noja b/samples/args.noja similarity index 100% rename from samples/func.noja rename to samples/args.noja diff --git a/samples/gang.noja b/samples/gang.noja deleted file mode 100644 index c71b917..0000000 --- a/samples/gang.noja +++ /dev/null @@ -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; \ No newline at end of file diff --git a/samples/generated_000.noja b/samples/generated_000.noja deleted file mode 100644 index 76433f6..0000000 --- a/samples/generated_000.noja +++ /dev/null @@ -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}; diff --git a/samples/http.noja b/samples/http.noja deleted file mode 100644 index ba88473..0000000 --- a/samples/http.noja +++ /dev/null @@ -1,12 +0,0 @@ - -fun isalpha(c) - return c < - -fun parse(req) -{ - i = 0; - while i < count(req) && isalpha(req[i]): - i = i + 1; - - -} \ No newline at end of file diff --git a/samples/if-else.noja b/samples/if-else.noja deleted file mode 100644 index 5a6a7b4..0000000 --- a/samples/if-else.noja +++ /dev/null @@ -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'); \ No newline at end of file diff --git a/samples/if-else2.noja b/samples/if-else2.noja deleted file mode 100644 index 888e0d8..0000000 --- a/samples/if-else2.noja +++ /dev/null @@ -1,7 +0,0 @@ - -define = true; - -if define: - a = 33; - -print(a, '\n'); \ No newline at end of file diff --git a/samples/loop.noja b/samples/loop.noja deleted file mode 100644 index 892d435..0000000 --- a/samples/loop.noja +++ /dev/null @@ -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; - -# ------------------------------------- # -# ------------------------------------- # \ No newline at end of file diff --git a/samples/makegarbage.noja b/samples/makegarbage.noja index 0b43759..27019fe 100644 --- a/samples/makegarbage.noja +++ b/samples/makegarbage.noja @@ -1,3 +1,4 @@ +# This script creates a lot of objects, so it can be used to stress the garbage collector. print('Start\n'); diff --git a/samples/server.noja b/samples/server.noja deleted file mode 100644 index 7670ea8..0000000 --- a/samples/server.noja +++ /dev/null @@ -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; - } \ No newline at end of file diff --git a/samples/gang2.noja b/samples/stack.noja similarity index 88% rename from samples/gang2.noja rename to samples/stack.noja index 6deb60e..ae2666d 100644 --- a/samples/gang2.noja +++ b/samples/stack.noja @@ -1,3 +1,4 @@ +# Implementation of a stack using a linked list. stack = {count: 0, head: none}; diff --git a/samples/server2.noja b/samples/tcp-server.noja similarity index 89% rename from samples/server2.noja rename to samples/tcp-server.noja index f3b2d78..1f2731c 100644 --- a/samples/server2.noja +++ b/samples/tcp-server.noja @@ -1,3 +1,4 @@ +# Implementation of a basic TCP server that listen for connections and prints received bytes. fun startServer(callbacks, port, backlog) { @@ -96,7 +97,7 @@ fun on_connect(addr) 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) diff --git a/samples/test.noja b/samples/test.noja deleted file mode 100644 index 4b3ec3a..0000000 --- a/samples/test.noja +++ /dev/null @@ -1 +0,0 @@ -'hello' + ' world!';