]> git.lizzy.rs Git - uwu-lang.git/blob - api/int.c
Update capitalization of Turing in the README (#1)
[uwu-lang.git] / api / int.c
1 #include <stdlib.h>
2 #include "common/str.h"
3 #include "int.h"
4
5 UwUVMValue uwuint_create(long value)
6 {
7         UwUVMValue vm_value = {
8                 .type = &uwuint_type,
9                 .data = malloc(sizeof(long))
10         };
11         *(long *) vm_value.data = value;
12
13         return vm_value;
14 }
15
16 int uwuint_get(UwUVMValue vm_value)
17 {
18         return *(long *) vm_value.data;
19 }
20
21 void *uwuint_clone(void *data)
22 {
23         long *copy = malloc(sizeof(*copy));
24         *copy = *(long *) data;
25         return copy;
26 }
27
28 char *uwuint_print(void *data)
29 {
30         return asprintf_wrapper("%ld", *(long *) data);
31 }
32
33 UwUVMType uwuint_type = {
34         .clone = &uwuint_clone,
35         .delet = &free,
36         .print = &uwuint_print,
37 };