aboutsummaryrefslogtreecommitdiff
path: root/src/ast.c
blob: 993cf953b7b80ec39448133c8da172d950d22648 (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
#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;
}

int funccall_init(FunctionCall *self, BufferView name, ScopedAllocator *allocator) {
    self->name = name;
    return buffer_init(&self->args, allocator);
}

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

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

int string_init(String *self, BufferView str) {
    /* TODO: Convert special characters. For example \n should be converted to binary newline etc */
    self->str = str;
    return 0;
}

void number_init(Number *self, i64 value, bool is_integer) {
    self->value.integer = value;
    self->is_integer = is_integer;
}

void binop_init(Binop *self) {
    self->lhs = ast_none();
    self->rhs = ast_none();
    self->type = BINOP_ADD;
    self->grouped = bool_false;
}