#include "../include/ast.h" #include "../include/std/log.h" #include static void ast_resolve(Ast *self); 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 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; } int scope_init(Scope *self, ScopedAllocator *allocator) { return buffer_init(&self->ast_objects, allocator); } void scope_resolve(Scope *self) { Ast *ast; Ast *ast_end; ast = buffer_start(&self->ast_objects); ast_end = buffer_end(&self->ast_objects); for(; ast != ast_end; ++ast) { ast_resolve(ast); } } static void lhs_resolve(LhsExpr *self) { amal_log_debug("Lhs resolve var name: %.*s", self->var_name.size, self->var_name.data); } void ast_resolve(Ast *self) { switch(self->type) { case AST_LHS: lhs_resolve(self->value.lhs_expr); break; default: assert(bool_false && "ast_resolve not implemented for type"); break; } }