wip: working on walker (externs)

Begin working on extern walking (libs metadata collet + opcode gen)
This commit is contained in:
samsonium
2026-10-31 18:45:33 +03:00
parent a4aa220cfa
commit 4d9c4ddd21
5 changed files with 40 additions and 4 deletions
+1
View File
@@ -22,6 +22,7 @@ typedef enum
FZL_OPCODE_CALL = 0xF30001, // Call function FZL_OPCODE_CALL = 0xF30001, // Call function
FZL_OPCODE_RET = 0xF30002, // Return from function FZL_OPCODE_RET = 0xF30002, // Return from function
FZL_OPCODE_CALL_EXTERN = 0xF30003, // Call external function
FZL_OPCODE_ALLOC_OBJECT = 0xFA0001, // Allocate N slots FZL_OPCODE_ALLOC_OBJECT = 0xFA0001, // Allocate N slots
FZL_OPCODE_GET_FIELD = 0xFA0002, // Get field N of an object at dstack FZL_OPCODE_GET_FIELD = 0xFA0002, // Get field N of an object at dstack
+16
View File
@@ -0,0 +1,16 @@
#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
+17 -1
View File
@@ -1,6 +1,8 @@
#include <common/fzl_types.h> #include <common/fzl_types.h>
#include <compiler/fzl_analyzer.h> #include <compiler/fzl_analyzer.h>
#include <compiler/fzl_parser.h>
#include <compiler/fzl_token.h> #include <compiler/fzl_token.h>
#include <compiler/internals/analyzer.h>
#include <compiler/utils/fzl_symtable.h> #include <compiler/utils/fzl_symtable.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdio.h> #include <stdio.h>
@@ -101,7 +103,21 @@ fzl_type_t an_toktotype(fzl_analyzer_t *analyzer, fzl_token_t *tok,
if (sym_found) if (sym_found)
*sym_found = found; *sym_found = found;
return found ? sym.type : FZL_TYPE_NULL; if (found && sym.node->type == FZL_NODETYPE_CLASS)
return FZL_TYPE_OBJECT;
if (found && sym.node->type != FZL_NODETYPE_CLASS &&
sym.node->type != FZL_NODETYPE_TYPEDEF)
{
snprintf(an_problem, sizeof(an_problem), "cannot use '%s' as type",
sym.name);
an_push_error(analyzer, sym.node->token, an_problem);
return FZL_TYPE_NULL;
}
return (found || (tok->value && strcmp(tok->value, "null") == 0))
? sym.type
: FZL_TYPE_NULL;
} }
if (sym_found) if (sym_found)
+3
View File
@@ -203,6 +203,9 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node)
{ {
switch (node->type) switch (node->type)
{ {
case FZL_NODETYPE_TYPEDEF:
break;
case FZL_NODETYPE_FMT_STRING: case FZL_NODETYPE_FMT_STRING:
{ {
for (size_t i = 0; i < node->list.entry_count; i++) for (size_t i = 0; i < node->list.entry_count; i++)
+1 -1
View File
@@ -123,7 +123,7 @@ int main(int argc, char **argv)
printf("%sok%s!\n", FZL_COK, FZL_CRST); printf("%sok%s!\n", FZL_COK, FZL_CRST);
fzl_debug_print_ast(parser->root); fzl_debug_print_ast(parser->root);
printf("%s> building%s\n", FZL_CDEBUG, FZL_CRST); printf("%s> building%s\n", FZL_CDEBUG, FZL_CRST);
printf("%s-> analyzing AST...%s\n", FZL_CDEBUG, FZL_CRST); printf("%s-> analyzing AST...%s", FZL_CDEBUG, FZL_CRST);
} }
fzl_analyzer_t *analyzer = fzl_mkanalyzer(parser->root); fzl_analyzer_t *analyzer = fzl_mkanalyzer(parser->root);