]> git.lizzy.rs Git - uwu-lang.git/blob - api/vm.h
Add :ref module and refactor type handling
[uwu-lang.git] / api / vm.h
1 #ifndef _API_VM_H_
2 #define _API_VM_H_
3
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include "../src/expression.h"
7
8 typedef enum
9 {
10         MODULE_PLAIN,
11         MODULE_NATIVE,
12 } UwUVMModuleType;
13
14 typedef struct
15 {
16         void *(*clone)(void *data);
17         void  (*delet)(void *data);
18         char *(*print)(void *data);
19 } UwUVMType;
20
21 typedef struct
22 {
23         void *data;
24         UwUVMType *type;
25 } UwUVMValue;
26
27 typedef struct UwUVMArgs
28 {
29         size_t num;
30         UwUVMValue              **evaluated;
31         struct UwUVMExpression *unevaluated;
32         struct UwUVMArgs *super;
33 } UwUVMArgs;
34
35 typedef UwUVMValue (*UwUVMNativeFunction)(UwUVMArgs *args);
36
37 typedef struct
38 {
39         UwUVMModuleType type;
40         union
41         {
42                 struct UwUVMExpression *plain;
43                 UwUVMNativeFunction native;
44         } value;
45 } UwUVMFunction;
46
47 typedef struct UwUVMExpression
48 {
49         ExpressionType type;
50         union
51         {
52                 struct
53                 {
54                         UwUVMFunction *function;
55                         struct UwUVMExpression *args;
56                         size_t           num_args;
57                 }           cll_value;
58                 int         int_value;
59                 char       *str_value;
60                 UwUVMFunction *ref_value;
61         } value;
62 } UwUVMExpression;
63
64 typedef struct
65 {
66         void *api_library;
67         UwUVMFunction *main_function;
68         UwUVMFunction     **functions;
69         size_t          num_functions;
70         void     **libraries;
71         size_t num_libraries;
72 } UwUVMProgram;
73
74 UwUVMValue uwuvm_clone_value(UwUVMValue value);
75 void       uwuvm_delet_value(UwUVMValue value);
76 char      *uwuvm_print_value(UwUVMValue value);
77 UwUVMValue uwuvm_get_arg(UwUVMArgs *args, size_t i);
78 UwUVMValue uwuvm_evaluate_expression(UwUVMExpression *expression, UwUVMArgs *args);
79 UwUVMValue uwuvm_call_function(UwUVMFunction *function, size_t num_args, UwUVMExpression *unevaluated_args, UwUVMArgs *super_args);
80
81 #endif