blob: af105738c734aeff3077940de4bc9f70ab61a76c (
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
|
#ifndef BDL_NODES_H
#define BDL_NODES_H
typedef enum NodeType {
NODE_BUILTIN,
NODE_NUMBER,
NODE_BOOL,
NODE_STRING,
NODE_SYMBOL,
NODE_TYPE,
NODE_DEF,
NODE_SET,
NODE_FUN,
NODE_BLOCK,
NODE_IF,
NODE_FUNCALL,
} NodeType;
typedef struct Node {
size_t id;
NodeType type;
size_t line;
size_t col;
struct Type *expr_type;
union {
// Numbers.
struct {
bool negative;
size_t integral;
size_t fractional;
} number;
// String/symbol/type.
StringView string;
// Boolean.
bool boolean;
// Builtin primitive.
struct {
TokenType type;
struct Node **args;
} builtin;
// Function call.
struct {
struct Node *name;
struct Node **args;
} funcall;
// Variable definition.
struct {
struct Node *symbol;
struct Node *value;
struct Node *type;
} def;
// Variable assignment.
struct {
struct Node *symbol;
struct Node *value;
} set;
// Function definition.
struct {
struct Node *name;
struct Node **param_names;
struct Node **param_types;
struct Node *return_type;
struct Node *body;
} fun;
// Block statements.
struct {
struct Node **expr;
} block;
// If statement.
struct {
struct Node *cond;
struct Node *expr_true;
struct Node *expr_false;
} ifexpr;
};
} Node;
#endif // BDL_NODES_H
|