From 058d954e80f83c26deb209008f11d87a5b59418e Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Thu, 30 Dec 2021 16:02:10 +0100 Subject: Unify value types --- api/int.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'api/int.c') diff --git a/api/int.c b/api/int.c index 49463cf..0b9329d 100644 --- a/api/int.c +++ b/api/int.c @@ -1,11 +1,32 @@ +#include +#include "../src/util.h" #include "int.h" UwUVMValue uwuint_create(int value) { - return (UwUVMValue) { - .type = VT_INT, - .value = { - .int_value = value, - }, + UwUVMValue vm_value = { + .type = &uwuint_type, + .data = malloc(sizeof(int)) }; + *(int *) vm_value.data = value; + + return vm_value; +} + +void *uwuint_copy(void *data) +{ + int *copy = malloc(sizeof(*copy)); + *copy = *(int *) data; + return copy; } + +char *uwuint_print(void *data) +{ + return asprintf_wrapper("%d", *(int *) data); +} + +UwUVMType uwuint_type = { + .copy = &uwuint_copy, + .delete = &free, + .print = &uwuint_print, +}; -- cgit v1.2.3