#ifndef AMALGAM_AST_H #define AMALGAM_AST_H #include "std/buffer_view.h" #include "std/buffer.h" #include "std/misc.h" #include "std/scoped_allocator.h" #include "binop_type.h" typedef struct FunctionDecl FunctionDecl; typedef struct FunctionCall FunctionCall; typedef struct LhsExpr LhsExpr; typedef struct Import Import; typedef struct String String; typedef struct Variable Variable; typedef struct Number Number; typedef struct Binop Binop; typedef union { FunctionDecl *func_decl; FunctionCall *func_call; LhsExpr *lhs_expr; Import *import; String *string; Number *number; Variable *variable; Binop *binop; } AstValue; typedef enum { AST_NONE, AST_FUNCTION_DECL, AST_FUNCTION_CALL, AST_LHS, AST_IMPORT, AST_STRING, AST_NUMBER, AST_VARIABLE, AST_BINOP } AstType; typedef struct { AstValue value; AstType type; } Ast; struct FunctionDecl { BufferView name; Buffer body; }; struct FunctionCall { BufferView name; Buffer args; }; struct LhsExpr { int isConst; BufferView type_name; BufferView var_name; Ast rhs_expr; }; struct Import { BufferView path; }; struct String { BufferView str; }; struct Number { union { i64 integer; f64 floating; } value; bool is_integer; }; struct Variable { BufferView name; }; struct Binop { Ast lhs; Ast rhs; BinopType type; /* Is the binop already ordered - no need to reorder it */ bool grouped; }; Ast ast_none(); CHECK_RESULT int funcdecl_init(FunctionDecl *self, ScopedAllocator *allocator); CHECK_RESULT int funcdecl_add_to_body(FunctionDecl *self, Ast ast); CHECK_RESULT int funccall_init(FunctionCall *self, BufferView name, ScopedAllocator *allocator); void lhsexpr_init(LhsExpr *self, int isConst, BufferView var_name); void import_init(Import *self, BufferView path); CHECK_RESULT int string_init(String *self, BufferView str); void number_init(Number *self, i64 value, bool is_integer); void binop_init(Binop *self); #endif