blob: 924ad92d31f36bb7cdc5a2ae49464f435c76efc2 (
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
|
#pragma once
#include "ast.h"
#include <stdbool.h>
#include <stdint.h>
#define VARIABLES_MAX 64
#define FUNCTIONS_MAX 32
// the longest thing a single type can say when emitted
#define TEXT_LENGTH_MAX 255
enum TypeKind
{
KIND_VOID,
KIND_INT32,
KIND_BYTE,
KIND_SIZE,
KIND_ARRAY,
KIND_CHAR,
KIND_CHAR_CONSTANT,
KIND_TUPLE,
KIND_VALUE
};
struct Type
{
enum TypeKind kind;
int64_t number;
char text[TEXT_LENGTH_MAX + 1];
};
struct Variable
{
char name[NAME_LENGTH_MAX + 1];
int64_t value;
bool declared;
};
struct Function
{
char name[NAME_LENGTH_MAX + 1];
const struct Node* node;
bool defined;
};
struct Machine
{
struct Variable variables[VARIABLES_MAX];
struct Function functions[FUNCTIONS_MAX];
struct Type returned;
int depth;
};
enum RunStatus
{
RUN_DONE,
RUN_FAILED,
RUN_RETURNED
};
void machine_init(struct Machine* machine);
enum RunStatus execute(struct Machine* machine, const struct Node* statement);
|