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
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:
#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 = {
#include "vm.h"
extern UwUVMType uwuint_type;
-UwUVMValue uwuint_create(int value);
+UwUVMValue uwuint_create(long value);
int uwuint_get(UwUVMValue vm_value);
#endif
struct UwUVMExpression *args;
size_t num_args;
} cll_value;
- int int_value;
+ long int_value;
char *str_value;
UwUVMFunction *ref_value;
} value;
// 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
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;
UwUVMExpressionType type;
union
{
- int int_value;
+ long int_value;
char *str_value;
} value;
size_t num_children;
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);
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;
case BOP_GRT: return a > b;
case BOP_EQU: return a == b;
}
+
+ return 0;
}
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);
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;