blob: 2857f0b76c68a7788f4a1f70d791da84f05c9d56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bool.h"
#include "nil.h"
UwUVMValue uwubool_create(bool value)
{
UwUVMValue vm_value = {
.type = VT_NAT,
.value = {
.nat_value = {
.type = &uwubool_type,
.data = malloc(sizeof(bool))
},
},
};
*(bool *) vm_value.value.nat_value.data = value;
return vm_value;
}
bool uwubool_get(UwUVMValue vm_value)
{
if (vm_value.type != VT_NAT)
return true;
else if (vm_value.value.nat_value.type == &uwunil_type)
return false;
else if (vm_value.value.nat_value.type == &uwubool_type)
return *(bool *) vm_value.value.nat_value.data;
else
return true;
}
static void *uwubool_copy(void *data)
{
bool *copy = malloc(sizeof(*copy));
*copy = *(bool *) data;
return copy;
}
static char *uwubool_print(void *data)
{
return strdup(((bool *) data) ? "true" : "false");
}
UwUVMNativeType uwubool_type = {
.copy = &uwubool_copy,
.delete = &free,
.print = &uwubool_print,
};
|