]> git.lizzy.rs Git - uwu-lang.git/commitdiff
uwuint: use long instead of int to prevent YEAR2038 problem in nolambda time library
authorElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 13:23:34 +0000 (14:23 +0100)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Sat, 1 Jan 2022 13:23:34 +0000 (14:23 +0100)
Makefile
api/int.c
api/int.h
api/vm.h
src/load.c
src/parse.c
src/parse.h
std/int.c

index da9c509b7cb9c6f0b63fb2086c69d9b285f5c967..4eb1f9ee41301e0b1c9cc92690d80e425518aba9 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
 all: uwu std api
 
 uwu: src/*.c src/*.h
-       gcc -g -I.               src/*.c   -o uwu        -D_GNU_SOURCE -ldl
+       gcc -g -I.               src/*.c   -o uwu        -D_GNU_SOURCE -Wall -Wextra -ldl
 
 .PHONY: std api
 
@@ -9,11 +9,10 @@ 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
+       gcc -g -I. -shared -fpic $< -o $@ -D_GNU_SOURCE -Wall -Wextra
 
 api/api.so: api/*.c api/*.h
-       gcc -g -I. -shared -fpic api/*.c   -o api/api.so -D_GNU_SOURCE
-
+       gcc -g -I. -shared -fpic api/*.c   -o api/api.so -D_GNU_SOURCE -Wall -Wextra
 .PHONY: clean
 
 clean:
index b1e0c69a98305294661e756b43a7a6cf8be1527f..dc7d8ceb937ce0cdf54d5c0a371e7fa67676d5b4 100644 (file)
--- a/api/int.c
+++ b/api/int.c
@@ -2,32 +2,32 @@
 #include "common/str.h"
 #include "int.h"
 
-UwUVMValue uwuint_create(int value)
+UwUVMValue uwuint_create(long value)
 {
        UwUVMValue vm_value = {
                .type = &uwuint_type,
-               .data = malloc(sizeof(int))
+               .data = malloc(sizeof(long))
        };
-       *(int *) vm_value.data = value;
+       *(long *) vm_value.data = value;
 
        return vm_value;
 }
 
 int uwuint_get(UwUVMValue vm_value)
 {
-       return *(int *) vm_value.data;
+       return *(long *) vm_value.data;
 }
 
 void *uwuint_clone(void *data)
 {
-       int *copy = malloc(sizeof(*copy));
-       *copy = *(int *) data;
+       long *copy = malloc(sizeof(*copy));
+       *copy = *(long *) data;
        return copy;
 }
 
 char *uwuint_print(void *data)
 {
-       return asprintf_wrapper("%d", *(int *) data);
+       return asprintf_wrapper("%l", *(long *) data);
 }
 
 UwUVMType uwuint_type = {
index 6b5361dfc2608a361dd63dc5f8e660b59516c585..a8ed03c1adb89f9c6ab339327575939e0b2d4c8f 100644 (file)
--- a/api/int.h
+++ b/api/int.h
@@ -4,7 +4,7 @@
 #include "vm.h"
 
 extern UwUVMType uwuint_type;
-UwUVMValue       uwuint_create(int value);
+UwUVMValue       uwuint_create(long value);
 int              uwuint_get(UwUVMValue vm_value);
 
 #endif
index fc761d3e3f9815eef779082e682337cb4fad029b..8434d98833c7a929ac862640007f53eb1bd85f97 100644 (file)
--- a/api/vm.h
+++ b/api/vm.h
@@ -64,7 +64,7 @@ typedef struct UwUVMExpression
                        struct UwUVMExpression *args;
                        size_t           num_args;
                }           cll_value;
-               int         int_value;
+               long        int_value;
                char       *str_value;
                UwUVMFunction *ref_value;
        } value;
index f6386d6341a5feeb9737ddf271d2fc39a11de93f..e5f683646a6a80da44b2926caa47aadca6813c4f 100644 (file)
 
 // helper functions
 
-static char *wrap_name_func(const char *name, char *(*fn)(char *))
+static char *dirname_wrapper(const char *name)
 {
        char *copy = strdup(name);
-       char *result = fn(copy);
+       char *result = dirname(copy);
        char *result_copy = strdup(result);
 
        free(copy);
        return result_copy;
 }
 
-static char *basename_wrapper(const char *name)
-{
-       return wrap_name_func(name, &basename);
-}
-
-static char *dirname_wrapper(const char *name)
-{
-       return wrap_name_func(name, &dirname);
-}
-
 // type definitions
 
 typedef struct
index e8f1d381ee92ac7f2fb0ac9b4be224b8fe99ecb6..66a90a3bad4881b022998d32ef49f7b3b7209e81 100644 (file)
@@ -156,7 +156,7 @@ static bool parse_expression_finish(ParseState *state, char c)
        char *buffer_read = buffer_terminate(state);
 
        if (state->expression->type == EX_INTLIT || state->expression->type == EX_ARGNUM) {
-               state->expression->value.int_value = atoi(buffer_read);
+               state->expression->value.int_value = atol(buffer_read);
                free(buffer_read);
        } else {
                state->expression->value.str_value = buffer_read;
index 46f454282e8f8bceb30eef4cb8c71c67746eeb57..7c13dd73757c13244887fc7a3e44a56216e8d019 100644 (file)
@@ -10,7 +10,7 @@ typedef struct ParseExpression
        UwUVMExpressionType type;
        union
        {
-               int   int_value;
+               long  int_value;
                char *str_value;
        } value;
        size_t num_children;
index 300737b84b6207b61538156454e644b788ac99ea..be314dc98cddd69153ecedabc86df3086c596908 100644 (file)
--- a/std/int.c
+++ b/std/int.c
@@ -16,7 +16,7 @@ typedef enum
        BOP_EQU,
 } BinaryOP;
 
-static int binary(const char *fnname, UwUVMArgs *args, BinaryOP op)
+static long binary(const char *fnname, UwUVMArgs *args, BinaryOP op)
 {
        uwuutil_require_exact(fnname, args, 2);
 
@@ -30,8 +30,8 @@ static int binary(const char *fnname, UwUVMArgs *args, BinaryOP op)
        if (value1.type != &uwuint_type)
                error("type error: %s requires an integer as $1\n", fnname);
 
-       int a = uwuint_get(value0);
-       int b = uwuint_get(value1);
+       long a = uwuint_get(value0);
+       long b = uwuint_get(value1);
 
        switch (op) {
                case BOP_SUB: return a - b;
@@ -41,6 +41,8 @@ static int binary(const char *fnname, UwUVMArgs *args, BinaryOP op)
                case BOP_GRT: return a > b;
                case BOP_EQU: return a == b;
        }
+
+       return 0;
 }
 
 typedef enum
@@ -50,9 +52,9 @@ typedef enum
        ROP_EQU,
 } ReduceOP;
 
-static int reduce(const char *fnname, UwUVMArgs *args, ReduceOP op, int result)
+static long reduce(const char *fnname, UwUVMArgs *args, ReduceOP op, long result)
 {
-       int first;
+       long first;
 
        for (size_t i = 0; i < args->num; i++) {
                UwUVMValue value = uwuvm_get_arg(args, i);
@@ -60,7 +62,7 @@ static int reduce(const char *fnname, UwUVMArgs *args, ReduceOP op, int result)
                if (value.type != &uwuint_type)
                        error("type error: %s only accepts integers as arguments (invalid argument: $%lu)\n", fnname, i);
 
-               int this = uwuint_get(value);
+               long this = uwuint_get(value);
 
                switch (op) {
                        case ROP_ADD: result += this; break;