Fixed assembler to process token end at comments
h3rald h3rald@h3rald.com
Wed, 07 Jan 2026 11:06:19 +0100
1 files changed,
27 insertions(+),
9 deletions(-)
jump to
M
xywasm.c
→
xywasm.c
@@ -58,6 +58,7 @@ {
TOKEN_END_EOF = 0, TOKEN_END_EOL, TOKEN_END_SPACE, + TOKEN_END_COMMENT, TOKEN_END_INVALID } xyw_token_terminator;@@ -219,7 +220,7 @@ if (r == TOKEN_END_INVALID)
{ return -1; } - if (r == TOKEN_END_EOL || r == TOKEN_END_EOF) + if (r == TOKEN_END_EOL || r == TOKEN_END_EOF || r == TOKEN_END_COMMENT) { break; }@@ -345,7 +346,8 @@ return -1;
} } xyw_dbg("Hex number:\t%s\t(%04X)\n", token, value); - } else if (token[0] == '%') + } + else if (token[0] == '%') { for (i = 1; i < token_length; i++) {@@ -362,10 +364,11 @@ return -1;
} } xyw_dbg("Binary number:\t%s\t(%04X)\n", token, value); - } else + } + else { - token_error("Invalid number."); - return -1; + token_error("Invalid number."); + return -1; } token_type = TOKEN_TYPE_NUMBER; token_value = value;@@ -559,6 +562,10 @@ if (r == TOKEN_END_INVALID)
{ return -1; } + if (r == TOKEN_END_EOL || r == TOKEN_END_EOF || r == TOKEN_END_COMMENT) + { + break; + } if (process_number(ctx) != 0) { return -1;@@ -568,10 +575,6 @@ {
token_error("Byte value out of range (0-255)"); return -1; } - if (r == TOKEN_END_EOL || r == TOKEN_END_EOF) - { - break; - } data[ptr++] = (xyw_byte)token_value; } return 0;@@ -848,6 +851,21 @@ token[token_length] = '\0';
} else if (c == ';' && !in_string && !in_comment) { + if (token_length > 0) + { + // put back character for next call, so that comment is processed separately + if (ctx->src == SRC_FILE) + { + fseek(ctx->fp, -1, SEEK_CUR); + } + else + { + ctx->sp--; + } + // Return current token before starting comment + token[token_length] = '\0'; + return TOKEN_END_COMMENT; + } in_comment = 1; ctx->column++; // Start of comment token