]> git.lizzy.rs Git - uwu-lang.git/commitdiff
Turn std into a submodule
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 18:44:35 +0000 (19:44 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 18:44:35 +0000 (19:44 +0100)
.gitmodules
Makefile
README.md
std [new submodule]
std/bool.c [deleted file]
std/int.c [deleted file]
std/nil.c [deleted file]
std/ref.c [deleted file]
std/str.c [deleted file]

index 64d2f3724102b267e2e6e7f840255cbb17adbbc3..ef80cf6ecf3fb32b2fad0377639da46fcc2466c2 100644 (file)
@@ -1,3 +1,6 @@
 [submodule "common"]
        path = common
        url = git@github.com:EliasFleckenstein03/uwu-common
+[submodule "std"]
+       path = std
+       url = git@github.com:EliasFleckenstein03/uwu-std
index ea736fa0ca053f37caef78607d301942be7726e0..5a240bafefe7a6e34cca9f2436e5384d72d0c1c6 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,10 @@
-all: uwu api
+all: uwu api/api.so
 
-uwu: src/*.c src/*.h
+uwu: src/*.c src/*.h api/*.h common/*.h
        gcc -g -I.               src/*.c   -o uwu        -D_GNU_SOURCE -Wall -Wextra -ldl
 
-.PHONY: std api
-
-std: std/bool.so std/int.so std/str.so std/nil.so std/ref.so
-api: api/api.so
-
-std/%.so: std/%.c
-       gcc -g -I. -shared -fpic $< -o $@ -D_GNU_SOURCE -Wall -Wextra
-
-api/api.so: api/*.c api/*.h
+api/api.so: api/*.c api/*.h common/*.h
        gcc -g -I. -shared -fpic api/*.c   -o api/api.so -D_GNU_SOURCE -Wall -Wextra
-.PHONY: clean
 
 clean:
-       rm -rf std/*.so api/api.so uwu
+       rm -rf api/api.so uwu
index 6d21e4fc3abb739a9a5e535d621279b1c6eebb06..ebea2357ef9873656c4cb5b2b108e6b0d49a25ee 100644 (file)
--- a/README.md
+++ b/README.md
@@ -34,7 +34,8 @@ git submodule update --init
 To build:
 
 ```
-make all std
+make
+make -C std
 ```
 
 To run:
diff --git a/std b/std
new file mode 160000 (submodule)
index 0000000..7b37593
--- /dev/null
+++ b/std
@@ -0,0 +1 @@
+Subproject commit 7b375939be901cf2114916193da9f4b9864f0504
diff --git a/std/bool.c b/std/bool.c
deleted file mode 100644 (file)
index 72a52d3..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "common/err.h"
-#include "api/vm.h"
-#include "api/util.h"
-#include "api/bool.h"
-
-static inline bool get_bool_arg(UwUVMArgs *args, size_t i)
-{
-       return uwubool_get(uwuvm_get_arg(args, i));
-}
-
-UwUVMValue uwu_if(UwUVMArgs *args)
-{
-       uwuutil_require_exact("bool.if", args, 3);
-
-       return uwuvm_clone_value(get_bool_arg(args, 0)
-               ? uwuvm_get_arg(args, 1)
-               : uwuvm_get_arg(args, 2)
-       );
-}
-
-UwUVMValue uwu_and(UwUVMArgs *args)
-{
-       uwuutil_require_min("bool.and", args, 1);
-
-       for (size_t i = 0; i < args->num; i++)
-               if (! get_bool_arg(args, i))
-                       return uwubool_create(false);
-
-       return uwubool_create(true);
-}
-
-UwUVMValue uwu_or(UwUVMArgs *args)
-{
-       uwuutil_require_min("bool.or", args, 1);
-
-       for (size_t i = 0; i < args->num; i++)
-               if (get_bool_arg(args, i))
-                       return uwubool_create(true);
-
-       return uwubool_create(false);
-}
-
-UwUVMValue uwu_equal(UwUVMArgs *args)
-{
-       uwuutil_require_min("bool.equal", args, 2);
-
-       bool value = get_bool_arg(args, 0);
-
-       for (size_t i = 1; i < args->num; i++)
-               if (get_bool_arg(args, i) != value)
-                       return uwubool_create(false);
-
-       return uwubool_create(true);
-}
-
-UwUVMValue uwu_not(UwUVMArgs *args)
-{
-       uwuutil_require_exact("bool.not", args, 1);
-       return uwubool_create(! get_bool_arg(args, 0));
-}
-
-UwUVMValue uwu_true(UwUVMArgs *args)
-{
-       uwuutil_require_exact("bool.true", args, 0);
-       return uwubool_create(true);
-}
-
-UwUVMValue uwu_false(UwUVMArgs *args)
-{
-       uwuutil_require_exact("bool.false", args, 0);
-       return uwubool_create(false);
-}
-
-UwUVMValue uwu_is(UwUVMArgs *args)
-{
-       return uwuutil_is_type("bool.is", args, &uwubool_type);
-}
diff --git a/std/int.c b/std/int.c
deleted file mode 100644 (file)
index 625595d..0000000
--- a/std/int.c
+++ /dev/null
@@ -1,127 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include "common/err.h"
-#include "api/vm.h"
-#include "api/int.h"
-#include "api/bool.h"
-#include "api/util.h"
-
-typedef enum
-{
-       BOP_SUB,
-       BOP_DIV,
-       BOP_MOD,
-       BOP_SML,
-       BOP_GRT,
-       BOP_EQU,
-} BinaryOP;
-
-static long binary(const char *fnname, UwUVMArgs *args, BinaryOP op)
-{
-       uwuutil_require_exact(fnname, args, 2);
-
-       UwUVMValue value0 = uwuvm_get_arg(args, 0);
-
-       if (value0.type != &uwuint_type)
-               error("type error: %s requires an integer as $1\n", fnname);
-
-       UwUVMValue value1 = uwuvm_get_arg(args, 1);
-
-       if (value1.type != &uwuint_type)
-               error("type error: %s requires an integer as $2\n", fnname);
-
-       long a = uwuint_get(value0);
-       long b = uwuint_get(value1);
-
-       switch (op) {
-               case BOP_SUB: return a - b;
-               case BOP_DIV: return a / b;
-               case BOP_MOD: return a % b;
-               case BOP_SML: return a < b;
-               case BOP_GRT: return a > b;
-               case BOP_EQU: return a == b;
-       }
-
-       return 0;
-}
-
-typedef enum
-{
-       ROP_ADD,
-       ROP_MUL,
-       ROP_EQU,
-} ReduceOP;
-
-static long reduce(const char *fnname, UwUVMArgs *args, ReduceOP op, long result)
-{
-       long first;
-
-       for (size_t i = 0; i < args->num; i++) {
-               UwUVMValue value = uwuvm_get_arg(args, i);
-
-               if (value.type != &uwuint_type)
-                       error("type error: %s only accepts integers as arguments (invalid argument: $%lu)\n", fnname, i + 1);
-
-               long this = uwuint_get(value);
-
-               switch (op) {
-                       case ROP_ADD: result += this; break;
-                       case ROP_MUL: result *= this; break;
-                       case ROP_EQU:
-                               if (i == 0)
-                                       first = this;
-                               else if (this != first)
-                                       return 0;
-
-                               break;
-               }
-       }
-
-       return result;
-}
-
-UwUVMValue uwu_add(UwUVMArgs *args)
-{
-       return uwuint_create(reduce("int.add", args, ROP_ADD, 0));
-}
-
-UwUVMValue uwu_sub(UwUVMArgs *args)
-{
-       return uwuint_create(binary("int.sub", args, BOP_SUB));
-}
-
-UwUVMValue uwu_mul(UwUVMArgs *args)
-{
-       return uwuint_create(reduce("int.mul", args, ROP_MUL, 1));
-}
-
-UwUVMValue uwu_div(UwUVMArgs *args)
-{
-       return uwuint_create(binary("int.div", args, BOP_DIV));
-}
-
-UwUVMValue uwu_mod(UwUVMArgs *args)
-{
-       return uwuint_create(binary("int.mod", args, BOP_MOD));
-}
-
-UwUVMValue uwu_smaller(UwUVMArgs *args)
-{
-       return uwubool_create(binary("int.smaller", args, BOP_SML) == 1);
-}
-
-UwUVMValue uwu_greater(UwUVMArgs *args)
-{
-       return uwubool_create(binary("int.greater", args, BOP_GRT) == 1);
-}
-
-UwUVMValue uwu_equal(UwUVMArgs *args)
-{
-       uwuutil_require_min("int.equal", args, 2);
-       return uwubool_create(reduce("int.equal", args, ROP_EQU, 1) == 1);
-}
-
-UwUVMValue uwu_is(UwUVMArgs *args)
-{
-       return uwuutil_is_type("int.is", args, &uwuint_type);
-}
diff --git a/std/nil.c b/std/nil.c
deleted file mode 100644 (file)
index cb27dbb..0000000
--- a/std/nil.c
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "common/err.h"
-#include "api/nil.h"
-#include "api/util.h"
-
-UwUVMValue uwu_nil(UwUVMArgs *args)
-{
-       uwuutil_require_exact("nil.nil", args, 0);
-       return uwunil_create();
-}
-
-UwUVMValue uwu_is(UwUVMArgs *args)
-{
-       return uwuutil_is_type("nil.is", args, &uwunil_type);
-}
diff --git a/std/ref.c b/std/ref.c
deleted file mode 100644 (file)
index 0147160..0000000
--- a/std/ref.c
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "common/err.h"
-#include "api/ref.h"
-#include "api/util.h"
-
-UwUVMValue uwu_call(UwUVMArgs *args)
-{
-       uwuutil_require_min("ref.call", args, 1);
-
-       UwUVMValue value = uwuvm_get_arg(args, 0);
-
-       if (value.type != &uwuref_type)
-               error("ref.call requires a function reference as $1\n");
-
-       return uwuvm_call_function(value.data, args->num - 1, &args->unevaluated[1], args->super);
-}
-
-UwUVMValue uwu_is(UwUVMArgs *args)
-{
-       return uwuutil_is_type("ref.is", args, &uwuref_type);
-}
diff --git a/std/str.c b/std/str.c
deleted file mode 100644 (file)
index 29b94db..0000000
--- a/std/str.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <string.h>
-#include <stdlib.h>
-#include "api/vm.h"
-#include "api/str.h"
-#include "api/util.h"
-
-UwUVMValue uwu_cat(UwUVMArgs *args)
-{
-       size_t total_len = 0;
-       size_t lengths[args->num];
-       char  *substrs[args->num];
-
-       for (size_t i = 0; i < args->num; i++) {
-               substrs[i] = uwustr_get(uwuvm_get_arg(args, i));
-               lengths[i] = strlen(substrs[i]);
-               total_len += lengths[i];
-       }
-
-       char result[total_len + 1];
-       char *result_ptr = result;
-
-       for (size_t i = 0; i < args->num; i++) {
-               strcpy(result_ptr, substrs[i]);
-               free(substrs[i]);
-               result_ptr += lengths[i];
-       }
-
-       *result_ptr = 0;
-
-       return uwustr_create(result);
-}
-
-UwUVMValue uwu_is(UwUVMArgs *args)
-{
-       return uwuutil_is_type("str.is", args, &uwustr_type);
-}