]> git.lizzy.rs Git - uwu-lang.git/blob - api/int.c
Unify value types
[uwu-lang.git] / api / int.c
1 #include <stdlib.h>
2 #include "../src/util.h"
3 #include "int.h"
4
5 UwUVMValue uwuint_create(int value)
6 {
7         UwUVMValue vm_value = {
8                 .type = &uwuint_type,
9                 .data = malloc(sizeof(int))
10         };
11         *(int *) vm_value.data = value;
12
13         return vm_value;
14 }
15
16 void *uwuint_copy(void *data)
17 {
18         int *copy = malloc(sizeof(*copy));
19         *copy = *(int *) data;
20         return copy;
21 }
22
23 char *uwuint_print(void *data)
24 {
25         return asprintf_wrapper("%d", *(int *) data);
26 }
27
28 UwUVMType uwuint_type = {
29         .copy = &uwuint_copy,
30         .delete = &free,
31         .print = &uwuint_print,
32 };