diff options
author | dec05eba <dec05eba@protonmail.com> | 2019-02-24 02:10:58 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-07-25 14:36:40 +0200 |
commit | 11dc4b81935e3dfee997c421d8d6fa166edd7a05 (patch) | |
tree | ccb08be54209a4900c740c9ed58e8f9c2910811d /include/ast.h |
Initial commit, Function declaration work somewhat
Diffstat (limited to 'include/ast.h')
-rw-r--r-- | include/ast.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/include/ast.h b/include/ast.h new file mode 100644 index 0000000..edbe70f --- /dev/null +++ b/include/ast.h @@ -0,0 +1,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); +WARN_UNUSED_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 |