diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-12-30 16:02:10 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2021-12-30 16:02:10 +0100 |
commit | 058d954e80f83c26deb209008f11d87a5b59418e (patch) | |
tree | ef7b5a95cfd1dbdba71041e1f0608d551adfa360 /api/int.c | |
parent | 3ba311b0afdf9cc62d630687d171bee0b6435e4a (diff) | |
download | uwu-lang-058d954e80f83c26deb209008f11d87a5b59418e.tar.xz |
Unify value types
Diffstat (limited to 'api/int.c')
-rw-r--r-- | api/int.c | 31 |
1 files changed, 26 insertions, 5 deletions
@@ -1,11 +1,32 @@ +#include <stdlib.h> +#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, +}; |