-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathAST.h
55 lines (50 loc) · 1.43 KB
/
AST.h
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
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
// The AST node structure. This contains a node type and two values that can
// be used to represent children. There are three kinds of AST elements,
// identified by the low two bits in a pointer. If the low bit is 0, then it
// is a pointer to one of these structures. If it is 1, then the value is
// either an integer literal or a register.
struct ASTNode {
enum {
NTNeighbours,
NTRangeMap,
NTOperatorAdd,
NTOperatorSub,
NTOperatorMul,
NTOperatorDiv,
NTOperatorAssign,
NTOperatorMin,
NTOperatorMax
} type;
uintptr_t val[2];
};
// A complete program. This is an array of AST nodes representing single
// statements.
struct statements
{
uintptr_t count;
struct ASTNode *list[0];
};
// An entry in a range map. This
struct RangeMapEntry {
intptr_t min;
intptr_t max;
intptr_t val;
};
// Range expressions use this structure in one of the val pointers. It
// contains an array of RangeMapEntries
struct RangeMap {
intptr_t value;
intptr_t count;
struct RangeMapEntry entries[0];
};
void printAST(struct ASTNode *ast);
void runOneStep(int16_t *oldgrid, int16_t *newgrid, int16_t width, int16_t height, struct ASTNode **ast, uintptr_t count);
typedef void(*automaton)(int16_t *oldgrid, int16_t *newgrid, int16_t width, int16_t height);
automaton compile(struct ASTNode **ast, uintptr_t count, int optimiseLevel);
#ifdef __cplusplus
}
#endif