From: Elias Fleckenstein Date: Sat, 1 Jan 2022 13:23:34 +0000 (+0100) Subject: uwuint: use long instead of int to prevent YEAR2038 problem in nolambda time library X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=8a3ed3c5996e8a88d94c24daa091dcd11fd81fac;p=uwu-lang.git uwuint: use long instead of int to prevent YEAR2038 problem in nolambda time library --- diff --git a/Makefile b/Makefile index da9c509..4eb1f9e 100644 --- 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: diff --git a/api/int.c b/api/int.c index b1e0c69..dc7d8ce 100644 --- 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 = { diff --git a/api/int.h b/api/int.h index 6b5361d..a8ed03c 100644 --- 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 diff --git a/api/vm.h b/api/vm.h index fc761d3..8434d98 100644 --- 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; diff --git a/src/load.c b/src/load.c index f6386d6..e5f6836 100644 --- a/src/load.c +++ b/src/load.c @@ -15,26 +15,16 @@ // 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 diff --git a/src/parse.c b/src/parse.c index e8f1d38..66a90a3 100644 --- a/src/parse.c +++ b/src/parse.c @@ -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; diff --git a/src/parse.h b/src/parse.h index 46f4542..7c13dd7 100644 --- a/src/parse.h +++ b/src/parse.h @@ -10,7 +10,7 @@ typedef struct ParseExpression UwUVMExpressionType type; union { - int int_value; + long int_value; char *str_value; } value; size_t num_children; diff --git a/std/int.c b/std/int.c index 300737b..be314dc 100644 --- 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;