From 6a035a71ebe031b2f3727b805ac1aa505d880473 Mon Sep 17 00:00:00 2001 From: samsonium Date: Mon, 2 Nov 2026 19:24:09 +0300 Subject: [PATCH] wip: working on extern - Ref: move extern header into common scope - Feat: add extern symbols descriptors - Feat: add `is_out` flag in declaration node --- include/common/fzl_extern.h | 72 +++++++++++++++++++++++++++++ include/compiler/fzl_parser.h | 2 + include/compiler/utils/fzl_extern.h | 16 ------- 3 files changed, 74 insertions(+), 16 deletions(-) create mode 100644 include/common/fzl_extern.h delete mode 100644 include/compiler/utils/fzl_extern.h diff --git a/include/common/fzl_extern.h b/include/common/fzl_extern.h new file mode 100644 index 0000000..59971f6 --- /dev/null +++ b/include/common/fzl_extern.h @@ -0,0 +1,72 @@ +#ifndef FZL_EXTERN_H +#define FZL_EXTERN_H + +#include +#include + +// External library entry types +typedef enum +{ + FZL_EXTERN_KIND_PRIMITIVE, + FZL_EXTERN_KIND_HANDLE, + FZL_EXTERN_KIND_STRUCT, + FZL_EXTERN_KIND_REF, + FZL_EXTERN_KIND_ALIAS, +} fzl_extern_kind_t; + +// External library structure field descriptor +typedef struct +{ + char *name; + fzl_type_t type; +} fzl_extern_struct_field_t; + +// Extern symbol type descriptor +typedef struct fzl_extern_type +{ + size_t lib_slot; + fzl_extern_kind_t kind; + char *symbol_name; + char *used_name; + + union + { + // Structure data + struct + { + fzl_extern_struct_field_t **fields; + size_t fields_count; + } structure; + + // Reference + struct fzl_extern_type *ref_of; + + // Aliasing type + fzl_type_t alias; + + // Primitive type + // NOTE: same type as `.alias` just for readable format + fzl_type_t primitive; + }; +} fzl_extern_type_t; + +// Extern symbol function descriptor +typedef struct +{ + size_t lib_slot; + char *symbol_name; + char *used_name; + + fzl_extern_type_t *ret_type; + + fzl_extern_type_t **args; + size_t args_count; +} fzl_extern_fn_t; + +// External library descriptor +typedef struct +{ + char *name; +} fzl_extern_lib_t; + +#endif // FZL_EXTERN_H diff --git a/include/compiler/fzl_parser.h b/include/compiler/fzl_parser.h index c91dde9..2b40a78 100644 --- a/include/compiler/fzl_parser.h +++ b/include/compiler/fzl_parser.h @@ -3,6 +3,7 @@ #include #include +#include #include // AST node type @@ -106,6 +107,7 @@ typedef struct fzl_node { fzl_token_t *type; struct fzl_node *identifier; + bool is_out; } var; // Conditional blocks diff --git a/include/compiler/utils/fzl_extern.h b/include/compiler/utils/fzl_extern.h deleted file mode 100644 index 2fe0815..0000000 --- a/include/compiler/utils/fzl_extern.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef FZL_EXTERN_H -#define FZL_EXTERN_H - -// Library symbol descriptor -typedef struct -{ - // -} fzl_extern_item_t; - -// External library descriptor -typedef struct -{ - // -} fzl_extern_lib_t; - -#endif // FZL_EXTERN_H