]> git.lizzy.rs Git - uwu-nolambda.git/commitdiff
Update to new uwu syntax
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 17:03:36 +0000 (18:03 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 17:03:36 +0000 (18:03 +0100)
README.md
exit.uwu
flow.c
fs.c
io.c
os.c
random.c
test.uwu

index 4c13ce70a2e3fbeafa7dbcacd0d798f69a8917ec..5a1b5c773004b152527137e95cd424d10a82cedf 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# nolambda
+e# nolambda
 nolambda is a collection of native [uwu](https://github.com/EliasFleckenstein03/uwulang) modules that break the lambda paradigm, such as linear execution, I/O, globals etc.
 
 ## Building
@@ -21,39 +21,39 @@ Note: The module `global` is not implemented yet.
 
 ### `flow`
 
-- `flow:linear`: Accepts an arbitrary number of arguments of arbitrary type, but at least one and evaulates all of them in order. Returns the last argument.
-- `flow:error`: Accepts an arbitrary type as $0, prints it to stderr appending a newline and exits the program with failure. Returns `:nil:nil` in theory.
+- `flow.linear`: Accepts an arbitrary number of arguments of arbitrary type, but at least one and evaulates all of them in order. Returns the last argument.
+- `flow.error`: Accepts an arbitrary type as $0, prints it to stderr appending a newline and exits the program with failure. Returns `nil.nil` in theory.
 
 ### `io`
 
-- `io:print`: Accepts an arbitrary type as $0 and prints it to stdout, followed by a newline. Returns $0.
-- `io:scan`: Reads a line from stdin and returns it as a string, without the newline character at the end. If $0 is given, it is used as a prompt (after converting to string).
+- `io.print`: Accepts an arbitrary type as $0 and prints it to stdout, followed by a newline. Returns $0.
+- `io.scan`: Reads a line from stdin and returns it as a string, without the newline character at the end. If $0 is given, it is used as a prompt (after converting to string).
 
 ### `fs`
 
 Note: all file paths are relative to the _directory the program was started from_.
 
-- `fs:read`: Accepts a file name (arbirary value, converted to string) as $0 and returns it's contents as a string. Causes an error if the file does not exist.
-- `fs:write`: Accepts a file name (arbirary value, converted to string) as $0 and overwrites it with the contents in $1 (arbirary value, converted to string). Causes an error if the file could not be written. Returns `:nil:nil`.
-- `fs:remove`: Accepts an arbitrary number of file names (arbirary type, converted to string), but at least one and unlinks them from the file system (the files can also be a directories). Causes an error if one of the file could not be removed, or if some or all of the files did not exist in the first place. Returns `:nil:nil`.
-- `fs:exists`: Accepts an arbitrary number of file names (arbirary type, converted to string), but at least one and returns `:bool:true` if all of them exist, `:bool:fase` else.
+- `fs.read`: Accepts a file name (arbirary value, converted to string) as $0 and returns it's contents as a string. Causes an error if the file does not exist.
+- `fs.write`: Accepts a file name (arbirary value, converted to string) as $0 and overwrites it with the contents in $1 (arbirary value, converted to string). Causes an error if the file could not be written. Returns `nil.nil`.
+- `fs.remove`: Accepts an arbitrary number of file names (arbirary type, converted to string), but at least one and unlinks them from the file system (the files can also be a directories). Causes an error if one of the file could not be removed, or if some or all of the files did not exist in the first place. Returns `nil.nil`.
+- `fs.exists`: Accepts an arbitrary number of file names (arbirary type, converted to string), but at least one and returns `bool.true` if all of them exist, `bool.false` else.
 
 ### `os`
 
-- `os:exit`: Optionally takes an exit code (integer) as $0 and exits the program with the given exit code, or 0 if no exit code was given. Returns `:nil:nil` in theory.
-- `os:sleep`: Takes an integer as $0 and pauses the execution of the program for $1 milliseconds. Returns `:nil:nil`.
-- `os:execute`: Takes a command (arbirary value, converted to string) as $0 and executes it as a shell command. Returns the exit code of the command as an integer.
-- `os:time`: Returns the current unix millis as an integer.
+- `os.exit`: Optionally takes an exit code (integer) as $0 and exits the program with the given exit code, or 0 if no exit code was given. Returns `nil.nil` in theory.
+- `os.sleep`: Takes an integer as $0 and pauses the execution of the program for $1 milliseconds. Returns `nil.nil`.
+- `os.execute`: Takes a command (arbirary value, converted to string) as $0 and executes it as a shell command. Returns the exit code of the command as an integer.
+- `os.time`: Returns the current unix millis as an integer.
 
 ### `global`
 
-- `global:set`: Creates or overwrites a global variable named $0 (arbirary value, converted to string) and puts the contents of $1 (arbitrary type) into it. Returns `:bool:false` if the variable existed previously and was updated, `:bool:true` if it was created.
-- `global:get`: Returns the global variable named $0 (arbirary value, converted to string). Causes an error if the variable does not exist.
-- `global:exists`: Returns `:bool:true` if the global variable named $0 (arbirary value, converted to string) exists, `:bool:false` else.
-- `global:delete`: Deletes the global variable named $0 (arbirary value, converted to string). Returns `:bool:true` if the variable existed previously, `:bool:false` else.
+- `global.set`: Creates or overwrites a global variable named $0 (arbirary value, converted to string) and puts the contents of $1 (arbitrary type) into it. Returns `bool.false` if the variable existed previously and was updated, `bool.true` if it was created.
+- `global.get`: Returns the global variable named $0 (arbirary value, converted to string). Causes an error if the variable does not exist.
+- `global.exists`: Returns `bool.true` if the global variable named $0 (arbirary value, converted to string) exists, `bool.false` else.
+- `global.delete`: Deletes the global variable named $0 (arbirary value, converted to string). Returns `bool.true` if the variable existed previously, `bool.false` else.
 
 ### `random`
 
-- `random:random`: Returns a pseudorandom integer between $0 (integer) and $1 (integer). The range is inclusive on both boundse. Causes an error if the range is bigger than `random:max` or empty.
-- `random:max`: Returns RAND_MAX.
-- `random:seed`: Sets the random seed to $0 (integer) and returns `:nil:nil`.
+- `random.random`: Returns a pseudorandom integer between $0 (integer) and $1 (integer). The range is inclusive on both boundse. Causes an error if the range is bigger than `random.max` or empty.
+- `random.max`: Returns RAND_MAX.
+- `random.seed`: Sets the random seed to $0 (integer) and returns `nil.nil`.
index f5e4ca1006a42b957974706754e92e752809a1c1..6438ca8bcfbfcf3ca399f16cad78c7bb25d70b7e 100644 (file)
--- a/exit.uwu
+++ b/exit.uwu
@@ -1 +1,9 @@
-main os:exit(1)
+main .flow.linear(
+       .random.seed(.os.time),
+       .os.exit(
+               bool.if(int.equal(.random.random(1, 2), 1),
+                       69,
+                       int.sub(0, 8)
+               )
+       )
+)
diff --git a/flow.c b/flow.c
index d17b49259e146973c1062de7349118357bc90ba7..23cd5f8fa1a9b978d274f7b0a35302488c90825e 100644 (file)
--- a/flow.c
+++ b/flow.c
@@ -8,7 +8,7 @@
 
 UwUVMValue uwu_linear(UwUVMArgs *args)
 {
-       uwuutil_require_min("flow:linear", args, 1);
+       uwuutil_require_min("flow.linear", args, 1);
 
        size_t return_arg = args->num - 1;
 
@@ -20,7 +20,7 @@ UwUVMValue uwu_linear(UwUVMArgs *args)
 
 UwUVMValue uwu_error(UwUVMArgs *args)
 {
-       uwuutil_require_exact("flow:error", args, 1);
+       uwuutil_require_exact("flow.error", args, 1);
 
        char *err = uwustr_get(uwuvm_get_arg(args, 0));
        fprintf(stderr, "%s\n", err);
diff --git a/fs.c b/fs.c
index 953c0625ae07fc8b3b8372b24ac6a5deb94aa34d..7b18289ba377892c819655848dc9d01aeae35ad3 100644 (file)
--- a/fs.c
+++ b/fs.c
@@ -11,7 +11,7 @@
 
 UwUVMValue uwu_read(UwUVMArgs *args)
 {
-       uwuutil_require_exact("fs:read", args, 1);
+       uwuutil_require_exact("fs.read", args, 1);
 
        char *filename = uwustr_get(uwuvm_get_arg(args, 0));
 
@@ -36,7 +36,7 @@ UwUVMValue uwu_read(UwUVMArgs *args)
 
 UwUVMValue uwu_write(UwUVMArgs *args)
 {
-       uwuutil_require_exact("fs:write", args, 2);
+       uwuutil_require_exact("fs.write", args, 2);
        
        char *filename = uwustr_get(uwuvm_get_arg(args, 0));
        char *contents = uwustr_get(uwuvm_get_arg(args, 1));
@@ -56,7 +56,7 @@ UwUVMValue uwu_write(UwUVMArgs *args)
 
 UwUVMValue uwu_remove(UwUVMArgs *args)
 {
-       uwuutil_require_min("fs:remove", args, 1);
+       uwuutil_require_min("fs.remove", args, 1);
 
        for (size_t i = 0; i < args->num; i++) {
                char *filename = uwustr_get(uwuvm_get_arg(args, i));
@@ -71,7 +71,7 @@ UwUVMValue uwu_remove(UwUVMArgs *args)
 
 UwUVMValue uwu_exists(UwUVMArgs *args)
 {
-       uwuutil_require_min("fs:exists", args, 1);
+       uwuutil_require_min("fs.exists", args, 1);
 
        for (size_t i = 0; i < args->num; i++) {
                char *filename = uwustr_get(uwuvm_get_arg(args, i));
diff --git a/io.c b/io.c
index a54acc7a099fda70bf8ca4143ca3a1b605ba8678..249eefe996dbeff5039efe9c72b708b064e605a4 100644 (file)
--- a/io.c
+++ b/io.c
@@ -9,7 +9,7 @@
 
 UwUVMValue uwu_print(UwUVMArgs *args)
 {
-       uwuutil_require_exact("io:print", args, 1);
+       uwuutil_require_exact("io.print", args, 1);
 
        UwUVMValue value = uwuvm_get_arg(args, 0);
 
@@ -22,7 +22,7 @@ UwUVMValue uwu_print(UwUVMArgs *args)
 
 UwUVMValue uwu_scan(UwUVMArgs *args)
 {
-       uwuutil_require_max("io:scan", args, 1);
+       uwuutil_require_max("io.scan", args, 1);
 
        char *prompt = NULL;
 
diff --git a/os.c b/os.c
index fe004927e0b762d935381d2e465c23828d67a8c7..9f6ff3bb334b7e0492ae1bcd3a8cb3d7d44b701e 100644 (file)
--- a/os.c
+++ b/os.c
@@ -10,7 +10,7 @@
 
 UwUVMValue uwu_exit(UwUVMArgs *args)
 {
-       uwuutil_require_max("os:exit", args, 1);
+       uwuutil_require_max("os.exit", args, 1);
 
        long exit_code = 0;
 
@@ -23,17 +23,17 @@ UwUVMValue uwu_exit(UwUVMArgs *args)
 
 UwUVMValue uwu_sleep(UwUVMArgs *args)
 {
-       uwuutil_require_exact("os:sleep", args, 1);
+       uwuutil_require_exact("os.sleep", args, 1);
 
        UwUVMValue value = uwuvm_get_arg(args, 0);
 
        if (value.type != &uwuint_type)
-               error("type error: nolamda:os:sleep requires an integer as $0\n");
+               error("type error: os.sleep requires an integer as $1\n");
 
        long millis = uwuint_get(value);
 
        if (millis < 0)
-               error("type error: nolamda:os:sleep requires a positive value as $0\n");
+               error("type error: os.sleep requires a positive value as $2\n");
 
        struct timespec ts = {
                .tv_sec = millis / 1000,
@@ -49,7 +49,7 @@ UwUVMValue uwu_sleep(UwUVMArgs *args)
 
 UwUVMValue uwu_execute(UwUVMArgs *args)
 {
-       uwuutil_require_exact("os:execute", args, 1);
+       uwuutil_require_exact("os.execute", args, 1);
 
        char *command = uwustr_get(uwuvm_get_arg(args, 0));
        int ret = system(command);
@@ -60,7 +60,7 @@ UwUVMValue uwu_execute(UwUVMArgs *args)
 
 UwUVMValue uwu_time(UwUVMArgs *args)
 {
-       uwuutil_require_exact("os:time", args, 0);
+       uwuutil_require_exact("os.time", args, 0);
 
        struct timespec ts;
        clock_gettime(CLOCK_REALTIME, &ts);
index c28e139921e958c7ed405383e9e0e153f5c74933..94c8fb9a2c3fe09914a482935c8ae5ce431ba410 100644 (file)
--- a/random.c
+++ b/random.c
@@ -7,17 +7,17 @@
 
 UwUVMValue uwu_random(UwUVMArgs *args)
 {
-       uwuutil_require_exact("random:random", args, 2);
+       uwuutil_require_exact("random.random", args, 2);
 
        UwUVMValue value0 = uwuvm_get_arg(args, 0);
 
        if (value0.type != &uwuint_type)
-               error("type error: random:random requires an integer as $0\n");
+               error("type error: random.random requires an integer as $1\n");
 
        UwUVMValue value1 = uwuvm_get_arg(args, 1);
 
        if (value1.type != &uwuint_type)
-               error("type error: random:random requires an integer as $1\n");
+               error("type error: random.random requires an integer as $2\n");
 
        long min = uwuint_get(value0);
        long max = uwuint_get(value1) + 1;
@@ -25,28 +25,28 @@ UwUVMValue uwu_random(UwUVMArgs *args)
        long range = max - min;
 
        if (range < 0)
-               error("type error: range passed to random:random is empty\n");
+               error("type error: range passed to random.random is empty\n");
 
        if (range > RAND_MAX)
-               error("type error: range passed to random:random is bigger than random:max");
+               error("type error: range passed to random.random is bigger than random.max");
 
        return uwuint_create(min + rand() % range);
 }
 
 UwUVMValue uwu_max(UwUVMArgs *args)
 {
-       uwuutil_require_exact("random:max", args, 0);
+       uwuutil_require_exact("random.max", args, 0);
        return uwuint_create(RAND_MAX);
 }
 
 UwUVMValue uwu_seed(UwUVMArgs *args)
 {
-       uwuutil_require_exact("random:seed", args, 1);
+       uwuutil_require_exact("random.seed", args, 1);
 
        UwUVMValue value = uwuvm_get_arg(args, 0);
 
        if (value.type != &uwuint_type)
-               error("type error: random:seed requires an integer as $0\n");
+               error("type error: random.seed requires an integer as $1\n");
 
        srand(uwuint_get(value) % RAND_MAX);
        return uwunil_create();
index 6182a05cc3c75bb1878f905c0c5727c7f9e50117..e543bb4f4374766d9dfd3470c939cd84251d0525 100644 (file)
--- a/test.uwu
+++ b/test.uwu
@@ -1,52 +1,52 @@
-main flow:linear(
-       io:print("please enter something:"),
-       io:print(io:scan),
+main .flow.linear(
+       .io.print("please enter something:"),
+       .io.print(.io.scan),
 
-       io:print(:str:cat(
-               "your input: ",
-               io:scan("please enter something else: ")
+       .io.print(str.cat(
+               "your input. ",
+               .io.scan("please enter something else: ")
        )),
 
-       io:print(:nil:nil),
-       fs:write("test", "hello world"),
-       :bool:if(fs:exists("test"),
-               io:print("successfully wrote file"),
-               flow:error("failed to write file")
+       .io.print(nil.nil),
+       .fs.write("test", "hello world"),
+       bool.if(.fs.exists("test"),
+               .io.print("successfully wrote file"),
+               .flow.error("failed to write file")
        ),
 
-       io:print(fs:read("test")),
+       .io.print(.fs.read("test")),
 
-       fs:remove("test"),
-       :bool:if(fs:exists("test"),
-               flow:error("failed to remove file"),
-               io:print("successfully removed file")
+       .fs.remove("test"),
+       bool.if(.fs.exists("test"),
+               .flow.error("failed to remove file"),
+               .io.print("successfully removed file")
        ),
 
-       io:print(:nil:nil),
-       io:print(os:time),
-       os:sleep(500),
-       io:print(os:time),
+       .io.print(nil.nil),
+       .io.print(.os.time),
+       .os.sleep(500),
+       .io.print(.os.time),
 
-       io:print(:nil:nil),
-       os:execute("echo hello world"),
+       .io.print(nil.nil),
+       .os.execute("echo hello world"),
 
-       io:print(:nil:nil),
-       io:print(:str:cat(
+       .io.print(nil.nil),
+       .io.print(str.cat(
                "Unseeded dice: ",
-               random:random(1, 6)
+               .random.random(1, 6)
        )),
 
-       random:seed(os:time),
-       io:print(:str:cat(
+       .random.seed(.os.time),
+       .io.print(str.cat(
                "Seeded dice: ",
-               random:random(1, 6)
+               .random.random(1, 6)
        )),
 
-       io:print(:str:cat(
+       .io.print(str.cat(
                "RAND_MAX = ",
-               random:max
+               .random.max
        )),
 
-       io:print(:nil:nil),
+       .io.print(nil.nil),
        "success"
 )