From 8b8ed7282a0fa5e17b83f0eaae404aa5f231b66a Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 16 Jan 2025 11:27:23 +0200 Subject: start adding exported defs --- include/ek/compiler.h | 2 +- include/ek/scope.h | 26 ++++++++++++-------------- include/ek/sptree.h | 3 +++ 3 files changed, 16 insertions(+), 15 deletions(-) (limited to 'include') diff --git a/include/ek/compiler.h b/include/ek/compiler.h index cbe34e2..4afddb6 100644 --- a/include/ek/compiler.h +++ b/include/ek/compiler.h @@ -31,6 +31,6 @@ int compile(const char *input); * @param file File to process. * @return \c 0 if compilation was succesful, otherwise some non-zero value. */ -int process_file(struct scope **parent, int public, const char *file); +struct scope *process_file(const char *file); #endif /* EK_COMPILER_H */ diff --git a/include/ek/scope.h b/include/ek/scope.h index ab27cc6..d8a5974 100644 --- a/include/ek/scope.h +++ b/include/ek/scope.h @@ -55,6 +55,11 @@ static inline int expanded_key_cmp(struct expanded_key a, struct expanded_key b) #define MAP_NAME expanded #include "map.h" +#define SPTREE_TYPE struct ast * +#define SPTREE_CMP(a, b) ((uintptr_t)(a) - (uintptr_t)(b)) +#define SPTREE_NAME exported +#include "sptree.h" + /** * Scope. * Responsible for keeping track of visibilities and @@ -87,6 +92,10 @@ struct scope { struct visible symbols; struct visible macros; struct visible types; + + struct exported exported_symbols; + struct exported exported_macros; + struct exported exported_types; }; /** @@ -104,15 +113,6 @@ struct scope *create_scope(); */ void destroy_scope(struct scope *scope); -/** - * Add a scratch AST node. - * - * @param scope Scope to add scratch AST node to. - * @param scratch Scratch node to add to \p scope. - * @return \c 0 when successful, non-zero otherwise. - */ -int scope_add_scratch(struct scope *scope, struct ast *scratch); - /** * Set scope flags. * @@ -336,10 +336,8 @@ struct ast *file_scope_find_trait(struct scope *scope, char *id); struct ast *file_scope_find_expd_struct(struct scope *scope, struct ast *def, struct type *types); -#define foreach_visible(iter, init) \ - for (struct visible *iter = init; iter; iter = iter->next) - -#define foreach_expanded(iter, init) \ - for (struct expanded *iter = init; iter; iter = iter->next) +bool is_exported_type(struct scope *scope, struct ast *def); +bool is_exported_symbol(struct scope *scope, struct ast *def); +bool is_exported_macro(struct scope *scope, struct ast *def); #endif /* SCOPE_H */ diff --git a/include/ek/sptree.h b/include/ek/sptree.h index 8dfdfbf..8ba6d6c 100644 --- a/include/ek/sptree.h +++ b/include/ek/sptree.h @@ -73,6 +73,9 @@ static inline struct SPNODE *SPTREE(last)(struct SPNODE *n) static inline SPTREE_TYPE *SPTREE(begin)(struct SPROOT *s) { + if (SPTREE(len)(s) == 0) + return NULL; + return &SPTREE(first)(s->root)->data; } -- cgit v1.3