aboutsummaryrefslogtreecommitdiff
path: root/include/ast.h
blob: b14c26de0a58d28c26e765d8cf07311679bc3bd4 (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
#ifndef AMALGAM_AST_H
#define AMALGAM_AST_H

#include "buffer_view.h"
#include "buffer.h"
#include "misc.h"

typedef struct FunctionDecl FunctionDecl;
typedef struct FunctionCall FunctionCall;
typedef struct LhsExpr LhsExpr;

typedef union {
    FunctionDecl *func_decl;
    FunctionCall *func_call;
    LhsExpr *lhs_expr;
} AstValue;

typedef enum {
    AST_NONE,
    AST_FUNCTION_DECL,
    AST_FUNCTION_CALL,
    AST_LHS
} AstType;

typedef struct {
    AstValue value;
    AstType type;
} Ast;

struct FunctionDecl {
    BufferView name;
    Buffer body;
};

struct FunctionCall {
    BufferView name;
};

struct LhsExpr {
    int isConst;
    BufferView var_name;
    Ast rhs_expr;
};

Ast ast_none();
void ast_deinit(Ast *ast);

void funcdecl_init(FunctionDecl *self);
void funcdecl_deinit(FunctionDecl *self);
CHECK_RESULT int funcdecl_add_to_body(FunctionDecl *self, Ast ast);

void funccall_init(FunctionCall *self, BufferView name);

void lhsexpr_init(LhsExpr *self, int isConst, BufferView var_name);
void lhsexpr_deinit(LhsExpr *self);

#endif