diff --git a/include/common/fzl_opcodes.h b/include/common/fzl_opcodes.h index 8603d3f..fb6fc2d 100644 --- a/include/common/fzl_opcodes.h +++ b/include/common/fzl_opcodes.h @@ -20,8 +20,9 @@ typedef enum FZL_OPCODE_JMP = 0xF20001, // Jump to specified IP address FZL_OPCODE_JZ = 0xF20002, // Jump if top value in dstack is zero - FZL_OPCODE_CALL = 0xF30001, // Call function - FZL_OPCODE_RET = 0xF30002, // Return from function + FZL_OPCODE_CALL = 0xF30001, // Call 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_GET_FIELD = 0xFA0002, // Get field N of an object at dstack diff --git a/include/compiler/utils/fzl_extern.h b/include/compiler/utils/fzl_extern.h new file mode 100644 index 0000000..2fe0815 --- /dev/null +++ b/include/compiler/utils/fzl_extern.h @@ -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 diff --git a/src/compiler/analyzer/utility.c b/src/compiler/analyzer/utility.c index d6a7401..6ba3c99 100644 --- a/src/compiler/analyzer/utility.c +++ b/src/compiler/analyzer/utility.c @@ -1,6 +1,8 @@ #include #include +#include #include +#include #include #include #include @@ -101,7 +103,21 @@ fzl_type_t an_toktotype(fzl_analyzer_t *analyzer, fzl_token_t *tok, if (sym_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) diff --git a/src/compiler/fzl_walker.c b/src/compiler/fzl_walker.c index d7f34d6..b392576 100644 --- a/src/compiler/fzl_walker.c +++ b/src/compiler/fzl_walker.c @@ -203,6 +203,9 @@ fzl_walk_res_t walk(fzl_walker_t *walker, fzl_node_t *node) { switch (node->type) { + case FZL_NODETYPE_TYPEDEF: + break; + case FZL_NODETYPE_FMT_STRING: { for (size_t i = 0; i < node->list.entry_count; i++) diff --git a/src/compiler/main.c b/src/compiler/main.c index 5c7e64c..49f1adc 100644 --- a/src/compiler/main.c +++ b/src/compiler/main.c @@ -123,7 +123,7 @@ int main(int argc, char **argv) printf("%sok%s!\n", FZL_COK, FZL_CRST); fzl_debug_print_ast(parser->root); 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);