aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
blob: 0acc69c7b5368d06602896bc6203893553760ec7 (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
#include "../include/ast.h"

Ast ast_none() {
    Ast ast;
    ast.value.func_decl = NULL;
    ast.type = AST_NONE;
    return ast;
}

int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator) {
    self->name = create_buffer_view_null();
    return buffer_init(&self->body, allocator);
}

int funcdecl_add_to_body(FunctionDecl *self, Ast ast) {
    return_if_error(buffer_append(&self->body, &ast, sizeof(ast)));
    return BUFFER_OK;
}

void funccall_init(FunctionCall *self, BufferView name) {
    self->name = name;
}

void lhsexpr_init(LhsExpr *self, int isConst, BufferView var_name) {
    self->isConst = isConst;
    self->var_name = var_name;
    self->rhs_expr = ast_none();
}

void import_init(Import *self, BufferView path) {
    self->path = path;
}