diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-12-30 20:01:13 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-12-30 20:01:13 +0100 |
commit | 34b269f811896fd033ce72fcfea63bfe541038b0 (patch) | |
tree | 3d544a5394894543d1c82482cdcd52611fd2d4ae | |
parent | 31a42c7b3b65e7c00c4303914d03e0745be3b49f (diff) | |
download | uwu-nolambda-34b269f811896fd033ce72fcfea63bfe541038b0.tar.xz |
Implement nolambda:flow
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | README.md | 22 | ||||
-rw-r--r-- | flow.c | 33 |
3 files changed, 53 insertions, 11 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e64b357 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +all: flow.so + +uwu_include_path=../uwulang/ + +%.so: %.c + gcc -g -I${uwu_include_path} -shared -fpic $< -o $@ -D_GNU_SOURCE + +clean: + rm -rf *.so @@ -6,35 +6,35 @@ nolambda is a collection of native [uwu](https://github.com/EliasFleckenstein03/ ### `nolambda:flow` - `nolambda: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. -- `nolambda:flow:error`: Accepts a string as $0, prints the string to stderr and exits the program with failure. Returns `:nil:nil` in theory. +- `nolambda:flow:error`: Accepts an arbitrary value as $0, prints it to stderr appending a newline and exits the program with failure. Returns `:nil:nil` in theory. ### `nolambda:io` -- `nolambda:io:print`: Accepts a string as $0 and prints it to stdout, followed by a newline. Returns $0. +- `nolambda:io:print`: Accepts an arbitrary value as $0 and prints it to stdout, followed by a newline. Returns $0. - `nolambda:io:scan`: Reads a line from stdin and returns it as a string, without the newline character at the end. This is interally using readline. ### `nolambda:fs` Note: all file paths are relative to the _directory the program was started from_. -- `nolambda:fs:read`: Accepts a file name (string) as $0 and returns it's contents as a string. Causes an error if the file does not exist. -- `nolambda:fs:write`: Accepts a file name (string) as $0 and overwrites it with the contents in $1 (string). Causes an error if the file could not be written. Returns `:bool:true` if the file was freshly created, `:bool:false` if it was overwritten. -- `nolambda:fs:remove`: Accepts a file name (string) as $0 and removes it from the file system. Causes an error if the file could not be removed, but does not cause an error if the file does not exist. Returns `:bool:true` if the file existed and was removed, `:bool:false` otherwise. -- `nolambda:fs:exists`: Accepts a file name (string) as $0 and returns `:bool:true` if it exists, `:bool:fase` else. +- `nolambda:fs:read`: Accepts a file name (arbirary value, used as string) as $0 and returns it's contents as a string. Causes an error if the file does not exist. +- `nolambda:fs:write`: Accepts a file name (arbirary value, used as string) as $0 and overwrites it with the contents in $1 (arbirary value, used as string). Causes an error if the file could not be written. Returns `:bool:true` if the file was freshly created, `:bool:false` if it was overwritten. +- `nolambda:fs:remove`: Accepts a file name (arbirary value, used as string) as $0 and removes it from the file system. Causes an error if the file could not be removed, but does not cause an error if the file does not exist. Returns `:bool:true` if the file existed and was removed, `:bool:false` otherwise. +- `nolambda:fs:exists`: Accepts a file name (arbirary value, used as string) as $0 and returns `:bool:true` if it exists, `:bool:fase` else. ### `nolambda:os` - `nolambda: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. - `nolambda:os:sleep`: Takes an integer as $0 and pauses the execution of the program for $1 milliseconds. Returns `:nil:nil`. -- `nolambda:os:execute`: Takes a command (string) as $0 and executes it as a shell command. Returns the exit code of the command as an integer. +- `nolambda:os:execute`: Takes a command (arbirary value, used as string) as $0 and executes it as a shell command. Returns the exit code of the command as an integer. - `nolambda:os:time`: Returns the current unix time as an integer. ### `nolambda:global` -- `nolambda:global:set`: Creates or overwrites a global variable named $0 (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. -- `nolambda:global:get`: Returns the global variable named $0 (string). Causes an error if the variable does not exist. -- `nolambda:global:exists`: Returns `:bool:true` if the global variable named $0 (string) exists, `:bool:false` else. -- `nolambda:global:delete`: Deletes the global variable named $0 (string). Returns `:bool:true` if the variable existed previously, `:bool:false` else. +- `nolambda:global:set`: Creates or overwrites a global variable named $0 (arbirary value, used as 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. +- `nolambda:global:get`: Returns the global variable named $0 (arbirary value, used as string). Causes an error if the variable does not exist. +- `nolambda:global:exists`: Returns `:bool:true` if the global variable named $0 (arbirary value, used as string) exists, `:bool:false` else. +- `nolambda:global:delete`: Deletes the global variable named $0 (arbirary value, used as string). Returns `:bool:true` if the variable existed previously, `:bool:false` else. ### `nolambda:random` @@ -0,0 +1,33 @@ +#include <stdlib.h> +#include <stdio.h> +#include "common/err.h" +#include "api/vm.h" +#include "api/nil.h" +#include "api/str.h" + +UwUVMValue uwu_linear(UwUVMArgs *args) +{ + if (args->num < 1) + error("error: nolambda:flow:linear requires at least one argument"); + + size_t return_arg = args->num - 1; + + for (size_t i = 0; i < return_arg; i++) + uwuvm_get_arg(args, i); + + return uwuvm_clone_value(uwuvm_get_arg(args, return_arg)); +} + +UwUVMValue uwu_error(UwUVMArgs *args) +{ + if (args->num != 1) + error("error: nolambda:flow:error exactly one argument"); + + char *err = uwustr_get(uwuvm_get_arg(args, 0)); + fprintf(stderr, "%s\n", err); + free(err); + + exit(1); + + return uwunil_create(); +} |