aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-23 16:16:59 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitdc90305a767feaacc3430aaee0928b745a8e5b0f (patch)
tree6d85df4245a84820dfdf6425f0aa095a563cabbe /include
parent4f308829ad0e81a59971e172284c018cf2bdca3d (diff)
Use ast pointers to fix resolving, remove try/throwing macros
Diffstat (limited to 'include')
-rw-r--r--include/ast.h24
-rw-r--r--include/std/misc.h30
2 files changed, 32 insertions, 22 deletions
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,
@@ -63,15 +62,19 @@ typedef enum {
} 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<LhsExpr>)*/ named_objects;
+ Buffer/*<Ast*>*/ ast_objects;
+ HashMap/*(key=BufferView, value=Ast<LhsExpr>*)*/ named_objects;
Scope *parent;
};
@@ -91,7 +94,7 @@ struct FunctionDecl {
struct FunctionCall {
Variable func;
- Buffer/*Ast*/ args;
+ Buffer/*<Ast*>*/ 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 <stdio.h>
+#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)