wip: working on extern
- Feat: stabilize extern header - Feat: add externs to walker - Feat: add extern node walking logic
This commit is contained in:
+36
-22
@@ -2,68 +2,82 @@
|
|||||||
#define FZL_EXTERN_H
|
#define FZL_EXTERN_H
|
||||||
|
|
||||||
#include <common/fzl_types.h>
|
#include <common/fzl_types.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
// External library entry types
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
FZL_EXTERN_KIND_PRIMITIVE,
|
|
||||||
FZL_EXTERN_KIND_HANDLE,
|
FZL_EXTERN_KIND_HANDLE,
|
||||||
FZL_EXTERN_KIND_STRUCT,
|
FZL_EXTERN_KIND_STRUCT,
|
||||||
FZL_EXTERN_KIND_REF,
|
FZL_EXTERN_KIND_REF,
|
||||||
FZL_EXTERN_KIND_ALIAS,
|
FZL_EXTERN_KIND_ALIAS,
|
||||||
} fzl_extern_kind_t;
|
} fzl_extern_kind_t;
|
||||||
|
|
||||||
// External library structure field descriptor
|
// Type reference descriptor
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
bool is_primitive;
|
||||||
|
union
|
||||||
|
{
|
||||||
|
fzl_type_t primitive;
|
||||||
|
size_t type_slot;
|
||||||
|
};
|
||||||
|
} fzl_extern_type_ref_t;
|
||||||
|
|
||||||
|
// Structure field descriptor
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
fzl_type_t type;
|
fzl_extern_type_ref_t type;
|
||||||
} fzl_extern_struct_field_t;
|
} fzl_extern_struct_field_t;
|
||||||
|
|
||||||
// Extern symbol type descriptor
|
// Type descriptor
|
||||||
typedef struct fzl_extern_type
|
typedef struct
|
||||||
{
|
{
|
||||||
size_t lib_slot;
|
size_t lib_slot;
|
||||||
|
char *name;
|
||||||
fzl_extern_kind_t kind;
|
fzl_extern_kind_t kind;
|
||||||
char *symbol_name;
|
|
||||||
char *used_name;
|
|
||||||
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
// Structure data
|
// Structure
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
fzl_extern_struct_field_t **fields;
|
fzl_extern_struct_field_t *fields;
|
||||||
size_t fields_count;
|
size_t fields_count;
|
||||||
} structure;
|
} structure;
|
||||||
|
|
||||||
// Reference
|
// Pointer (ref)
|
||||||
struct fzl_extern_type *ref_of;
|
fzl_extern_type_ref_t ref_target;
|
||||||
|
|
||||||
// Aliasing type
|
// Alias
|
||||||
fzl_type_t alias;
|
fzl_extern_type_ref_t alias_target;
|
||||||
|
|
||||||
// Primitive type
|
|
||||||
// NOTE: same type as `.alias` just for readable format
|
|
||||||
fzl_type_t primitive;
|
|
||||||
};
|
};
|
||||||
} fzl_extern_type_t;
|
} fzl_extern_type_t;
|
||||||
|
|
||||||
// Extern symbol function descriptor
|
// Function argument descriptor
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
char *name;
|
||||||
|
fzl_extern_type_ref_t type;
|
||||||
|
bool is_out;
|
||||||
|
} fzl_extern_arg_t;
|
||||||
|
|
||||||
|
// Function descriptor
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
size_t lib_slot;
|
size_t lib_slot;
|
||||||
char *symbol_name;
|
char *symbol_name;
|
||||||
char *used_name;
|
char *used_name;
|
||||||
|
|
||||||
fzl_extern_type_t *ret_type;
|
bool has_return;
|
||||||
|
fzl_extern_type_ref_t ret_type;
|
||||||
|
|
||||||
fzl_extern_type_t **args;
|
fzl_extern_arg_t *args;
|
||||||
size_t args_count;
|
size_t args_count;
|
||||||
} fzl_extern_fn_t;
|
} fzl_extern_fn_t;
|
||||||
|
|
||||||
// External library descriptor
|
// Library descriptor
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef FZL_WALKER_H
|
#ifndef FZL_WALKER_H
|
||||||
#define FZL_WALKER_H
|
#define FZL_WALKER_H
|
||||||
|
|
||||||
|
#include <common/fzl_extern.h>
|
||||||
#include <common/fzl_opcodes.h>
|
#include <common/fzl_opcodes.h>
|
||||||
#include <common/fzl_types.h>
|
#include <common/fzl_types.h>
|
||||||
#include <compiler/fzl_parser.h>
|
#include <compiler/fzl_parser.h>
|
||||||
@@ -73,6 +74,15 @@ typedef struct
|
|||||||
|
|
||||||
fzl_ctable_t *classes[64];
|
fzl_ctable_t *classes[64];
|
||||||
size_t classes_count;
|
size_t classes_count;
|
||||||
|
|
||||||
|
fzl_extern_lib_t extern_libs[64];
|
||||||
|
size_t extern_libs_count;
|
||||||
|
|
||||||
|
fzl_extern_type_t extern_types[256];
|
||||||
|
size_t extern_types_count;
|
||||||
|
|
||||||
|
fzl_extern_fn_t extern_fns[256];
|
||||||
|
size_t extern_fns_count;
|
||||||
} fzl_walker_t;
|
} fzl_walker_t;
|
||||||
|
|
||||||
// Allocate new walker
|
// Allocate new walker
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "common/fzl_extern.h"
|
||||||
#include <common/fzl_builtins.h>
|
#include <common/fzl_builtins.h>
|
||||||
#include <common/fzl_opcodes.h>
|
#include <common/fzl_opcodes.h>
|
||||||
#include <common/fzl_types.h>
|
#include <common/fzl_types.h>
|
||||||
@@ -61,6 +62,14 @@ fzl_walker_t *fzl_mkwalker(fzl_node_t *root)
|
|||||||
walker->classes_count = 0;
|
walker->classes_count = 0;
|
||||||
memset(walker->classes, 0, sizeof(walker->classes));
|
memset(walker->classes, 0, sizeof(walker->classes));
|
||||||
|
|
||||||
|
walker->extern_libs_count = 0;
|
||||||
|
walker->extern_types_count = 0;
|
||||||
|
walker->extern_fns_count = 0;
|
||||||
|
|
||||||
|
memset(walker->extern_libs, 0, sizeof(walker->extern_libs));
|
||||||
|
memset(walker->extern_types, 0, sizeof(walker->extern_types));
|
||||||
|
memset(walker->extern_fns, 0, sizeof(walker->extern_fns));
|
||||||
|
|
||||||
return walker;
|
return walker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +212,28 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
|
|||||||
{
|
{
|
||||||
switch (node->type)
|
switch (node->type)
|
||||||
{
|
{
|
||||||
case FZL_NODETYPE_EXTERN: // TODO: create meta
|
case FZL_NODETYPE_EXTERN:
|
||||||
|
walker->extern_libs[walker->extern_libs_count++] =
|
||||||
|
(fzl_extern_lib_t){.name = node->ext.libname};
|
||||||
|
|
||||||
|
for (size_t i = 0; i < node->ext.typedefs_count; i++)
|
||||||
|
{
|
||||||
|
fzl_walk_res_t res = walk(walker, node->ext.typedefs[i]);
|
||||||
|
if (res.error)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < node->ext.fns_count; i++)
|
||||||
|
{
|
||||||
|
fzl_walk_res_t res = walk(walker, node->ext.fns[i]);
|
||||||
|
if (res.error)
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
current_res = (fzl_walk_res_t){
|
||||||
|
.error = false, .type = FZL_TYPE_NULL, .classname = NULL};
|
||||||
|
break;
|
||||||
|
|
||||||
case FZL_NODETYPE_EXTERN_FN: // TODO: write to meta
|
case FZL_NODETYPE_EXTERN_FN: // TODO: write to meta
|
||||||
case FZL_NODETYPE_REFERENCE: // TODO: write to meta
|
case FZL_NODETYPE_REFERENCE: // TODO: write to meta
|
||||||
case FZL_NODETYPE_STRUCT: // TODO: write to meta
|
case FZL_NODETYPE_STRUCT: // TODO: write to meta
|
||||||
|
|||||||
Reference in New Issue
Block a user