blob: 768ae2fc14e99792148ce5221dc1c9e8307a66ae (
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
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bool.h"
#include "nil.h"
UwUVMValue uwubool_create(bool value)
{
UwUVMValue vm_value = {
.type = &uwubool_type,
.data = malloc(sizeof(bool)),
};
*(bool *) vm_value.data = value;
return vm_value;
}
bool uwubool_get(UwUVMValue vm_value)
{
if (vm_value.type == &uwunil_type)
return false;
else if (vm_value.type == &uwubool_type)
return *(bool *) vm_value.data;
else
return true;
}
static void *uwubool_clone(void *data)
{
bool *copy = malloc(sizeof(*copy));
*copy = *(bool *) data;
return copy;
}
static char *uwubool_print(void *data)
{
return strdup(((bool *) data) ? "true" : "false");
}
UwUVMType uwubool_type = {
.clone = &uwubool_clone,
.delet = &free,
.print = &uwubool_print,
};
|