]> git.lizzy.rs Git - uwu-lang.git/blob - api/int.c
Add :ref module and refactor type handling
[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 int uwuint_get(UwUVMValue vm_value)
17 {
18         return *(int *) vm_value.data;
19 }
20
21 void *uwuint_clone(void *data)
22 {
23         int *copy = malloc(sizeof(*copy));
24         *copy = *(int *) data;
25         return copy;
26 }
27
28 char *uwuint_print(void *data)
29 {
30         return asprintf_wrapper("%d", *(int *) data);
31 }
32
33 UwUVMType uwuint_type = {
34         .clone = &uwuint_clone,
35         .delet = &free,
36         .print = &uwuint_print,
37 };