diff --git a/libs/macro/computer.c b/libs/macro/computer.c index 06bdcd83c..d345b9d73 100644 --- a/libs/macro/computer.c +++ b/libs/macro/computer.c @@ -305,9 +305,9 @@ static inline int computer_const_number(computer *const comp, const item_t pos, */ -computer computer_create(location *const loc, universal_io *const io) +computer computer_create(location *const loc, universal_io *const io, const char *const directive) { - return (computer) { .loc = loc_copy(loc), .io = io + return (computer) { .loc = loc_copy(loc), .io = io, .directive = directive , .numbers = stack_create(MAX_EXPRESSION_DAPTH) , .operators = stack_create(MAX_EXPRESSION_DAPTH) , .was_number = false }; @@ -396,6 +396,12 @@ item_t computer_pop_result(computer *const comp) return 0; } + if (stack_size(&comp->numbers) == 0) + { + computer_error(comp, ITEM_MAX, DIRECTIVE_NO_EXPRESSION, comp->directive); + return 0; + } + if (!comp->was_number) { char token[3]; diff --git a/libs/macro/computer.h b/libs/macro/computer.h index 1dc1bfcb2..32b38db94 100644 --- a/libs/macro/computer.h +++ b/libs/macro/computer.h @@ -74,6 +74,7 @@ typedef struct computer location loc; /**< Directive location */ universal_io *io; /**< IO for location assembly */ + const char *directive; /**< Directive name for error emitting */ bool was_number; /**< Set, if last push is number */ } computer; @@ -83,10 +84,12 @@ typedef struct computer * Create computer structure * * @param loc Default location + * @param io Location IO + * @param directive Directive name * * @return Computer structure */ -computer computer_create(location *const loc, universal_io *const io); +computer computer_create(location *const loc, universal_io *const io, const char *const directive); /** diff --git a/libs/macro/parser.c b/libs/macro/parser.c index 40a11ec68..49dec77d6 100644 --- a/libs/macro/parser.c +++ b/libs/macro/parser.c @@ -439,13 +439,17 @@ static inline char32_t skip_macro(parser *const prs, const keyword_t keyword) if (utf8_is_letter(character)) { const char *value = storage_get_by_index(prs->stg, storage_search(prs->stg, prs->io)); - if (value != NULL) + if (value == NULL) { - uni_printf(prs->io, MASK_ARGUMENT "%s", value); + uni_printf(prs->io, "%s", storage_last_read(prs->stg)); + } + else if (keyword == KW_IFDEF || keyword == KW_IFNDEF) + { + uni_printf(prs->io, MASK_TOKEN_PASTE "%s", value); } else { - uni_printf(prs->io, "%s", storage_last_read(prs->stg)); + uni_printf(prs->io, MASK_ARGUMENT "%s", value); } } else if (character == '\'' || character == '"' || (character == '<' && keyword == KW_INCLUDE)) @@ -1460,10 +1464,13 @@ static inline bool parse_token(parser *const prs, computer *const comp, const si static item_t parse_expression(parser *const prs) { location loc = parse_location(prs); + char directive[MAX_KEYWORD_SIZE]; + sprintf(directive, "%s", storage_last_read(prs->stg)); + char32_t character = skip_until(prs, false); if (character == '\n' || character == (char32_t)EOF) { - parser_error(prs, &loc, DIRECTIVE_NO_EXPRESSION, storage_last_read(prs->stg)); + parser_error(prs, &loc, DIRECTIVE_NO_EXPRESSION, directive); return 0; } @@ -1471,7 +1478,8 @@ static item_t parse_expression(parser *const prs) location *origin_loc = prs->loc; location *origin_prev = prs->prev; - computer comp = prs->prev == NULL ? computer_create(&loc, prs->io) : computer_create(prs->prev, NULL); + computer comp = prs->prev == NULL ? computer_create(&loc, prs->io, directive) + : computer_create(prs->prev, NULL, directive); size_t position = in_get_position(prs->io); universal_io out = io_create(); char *buffer = NULL;