From dc90305a767feaacc3430aaee0928b745a8e5b0f Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 23 Mar 2019 16:16:59 +0100 Subject: Use ast pointers to fix resolving, remove try/throwing macros --- include/ast.h | 24 +++++++++++++----------- include/std/misc.h | 30 +++++++++++++++++++----------- 2 files changed, 32 insertions(+), 22 deletions(-) (limited to 'include') diff --git a/include/ast.h b/include/ast.h index 25d9034..56795cd 100644 --- a/include/ast.h +++ b/include/ast.h @@ -43,7 +43,6 @@ typedef union { } AstValue; typedef enum { - AST_NONE, AST_FUNCTION_DECL, AST_FUNCTION_CALL, AST_STRUCT_DECL, @@ -62,16 +61,20 @@ typedef enum { AST_RESOLVED } AstResolveStatus; +typedef struct { + LhsExpr *type; + AstResolveStatus status; +} AstResolveData; + typedef struct { AstValue value; AstType type; - AstResolveStatus resolve_status; - LhsExpr *resolved_type; + AstResolveData resolve_data; } Ast; struct Scope { - Buffer ast_objects; - HashMap/*(key=BufferView, value=Ast)*/ named_objects; + Buffer/**/ ast_objects; + HashMap/*(key=BufferView, value=Ast*)*/ named_objects; Scope *parent; }; @@ -91,7 +94,7 @@ struct FunctionDecl { struct FunctionCall { Variable func; - Buffer/*Ast*/ args; + Buffer/**/ args; }; struct StructDecl { @@ -108,7 +111,7 @@ struct LhsExpr { bool is_const; BufferView var_name; Variable type; - Ast rhs_expr; + Ast *rhs_expr; /* A mutex is only available if the LhsExpr is public, because other threads (files) can access it. It's used to prevent usage of unresolved data and also to decide which @@ -136,8 +139,8 @@ struct Number { }; struct Binop { - Ast lhs; - Ast rhs; + Ast *lhs; + Ast *rhs; BinopType type; /* Is the binop already ordered - no need to reorder it */ bool grouped; @@ -149,8 +152,7 @@ typedef struct { Scope *scope; } AstCompilerContext; -Ast ast_none(); -void ast_init(Ast *self, void *value, AstType type); +CHECK_RESULT int ast_create(ScopedAllocator *allocator, void *value, AstType type, Ast **result); BufferView ast_get_name(Ast *self); CHECK_RESULT int funcdecl_init(FunctionDecl *self, Scope *parent, ScopedAllocator *allocator); diff --git a/include/std/misc.h b/include/std/misc.h index e28ed48..2549c22 100644 --- a/include/std/misc.h +++ b/include/std/misc.h @@ -1,25 +1,33 @@ #ifndef AMALGAM_MISC_H #define AMALGAM_MISC_H -#include +#ifndef AMAL_PEDANTIC +#include "log.h" +#endif + +#ifdef AMAL_PEDANTIC + #define throw_debug_msg do {} while(0) +#else + #define throw_debug_msg do { amal_log_error("Throwing from %s:%d", __FUNCTION__, __LINE__); } while(0) +#endif #ifdef AMAL_PEDANTIC #define return_if_debug_msg do {} while(0) #define cleanup_if_debug_msg do {} while(0) #else - #define return_if_debug_msg do { fprintf(stderr, "Return from %s:%d\n", __FUNCTION__, __LINE__); } while(0) - #define cleanup_if_debug_msg do { fprintf(stderr, "cleanup from %s:%d\n", __FUNCTION__, __LINE__); } while(0) + #define return_if_debug_msg do { amal_log_error("Return from %s:%d", __FUNCTION__, __LINE__); } while(0) + #define cleanup_if_debug_msg do { amal_log_error("cleanup from %s:%d", __FUNCTION__, __LINE__); } while(0) #endif #define return_if_error(result) \ -do { \ - int return_if_result; \ - return_if_result = (result); \ - if((return_if_result) != 0) { \ - return_if_debug_msg; \ - return return_if_result; \ - } \ -} while(0) + do { \ + int return_if_result; \ + return_if_result = (result); \ + if((return_if_result) != 0) { \ + return_if_debug_msg; \ + return return_if_result; \ + } \ + } while(0) #define cleanup_if_error(result) do { if((result) != 0) { cleanup_if_debug_msg; goto cleanup; } } while(0) -- cgit v1.2.3