blob: 94103d5c5a610c908d6a4ceddabd312865d1bbb9 (
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
#ifndef _API_VM_H_
#define _API_VM_H_
#include <stddef.h>
#include <stdbool.h>
#include "../src/expression.h"
typedef enum
{
MODULE_PLAIN,
MODULE_NATIVE,
} UwUVMModuleType;
typedef struct
{
void *(*copy )(void *data);
void (*delete)(void *data);
char *(*print )(void *data);
} UwUVMNativeType;
typedef struct
{
void *data;
UwUVMNativeType *type;
} UwUVMNativeValue;
typedef struct UwUVMArgs
{
size_t num;
struct UwUVMValue **evaluated;
struct UwUVMExpression *unevaluated;
struct UwUVMArgs *super;
} UwUVMArgs;
typedef struct UwUVMValue (*UwUVMNativeFunction)(UwUVMArgs *args);
typedef struct
{
UwUVMModuleType type;
union
{
struct UwUVMExpression *plain;
UwUVMNativeFunction native;
} value;
} UwUVMFunction;
typedef struct UwUVMValue
{
enum
{
VT_INT,
VT_STR,
VT_REF,
VT_NAT,
} type;
union
{
int int_value;
char *str_value;
UwUVMFunction *ref_value;
UwUVMNativeValue nat_value;
} value;
} UwUVMValue;
typedef struct UwUVMExpression
{
ExpressionType type;
union
{
struct
{
UwUVMFunction *function;
struct UwUVMExpression *args;
size_t num_args;
} cll_value;
int int_value;
char *str_value;
UwUVMFunction *ref_value;
} value;
} UwUVMExpression;
typedef struct
{
void *api_library;
UwUVMFunction *main_function;
UwUVMFunction **functions;
size_t num_functions;
void **libraries;
size_t num_libraries;
} UwUVMProgram;
void uwuvm_free_value(UwUVMValue value);
void uwuvm_free_args(UwUVMArgs *args);
UwUVMValue uwuvm_copy_value(UwUVMValue value);
UwUVMValue uwuvm_get_arg(UwUVMArgs *args, size_t i);
UwUVMValue uwuvm_evaluate_expression(UwUVMExpression *expression, UwUVMArgs *args);
UwUVMValue uwuvm_run_function(UwUVMFunction *function, UwUVMArgs args);
#endif
|