blob: c2365cc76958af27e4a8af74f0a9d705bfb76986 (
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
|
#pragma once
#include "ast.h"
#include <stdbool.h>
#include <stdint.h>
#define VARIABLES_MAX 64
// 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
};
// a tuple keeps what it will say, already said, so nothing inside it can go out of scope
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 Machine
{
struct Variable variables[VARIABLES_MAX];
};
enum RunStatus
{
RUN_DONE,
RUN_FAILED
};
void machine_init(struct Machine* machine);
enum RunStatus execute(struct Machine* machine, const struct Node* statement);
|