Minor refactoring.
h3rald h3rald@h3rald.com
Wed, 26 Nov 2025 15:25:12 +0100
1 files changed,
20 insertions(+),
19 deletions(-)
jump to
M
xywasm.c
→
xywasm.c
@@ -101,9 +101,9 @@ directive_data_length = 0;
directive_data[0] = '\0'; } -//// Parsing functions +//// Processing functions -static int parse_comment(xyw_context *ctx) +static int process_comment(xyw_context *ctx) { char c; char comment_data[COMMENT_CONTENT_MAX_LENGTH];@@ -135,7 +135,7 @@ printf("Comment:\t%s%s\n", token, comment_data);
return 0; } -static int parse_hex_number(xyw_context *ctx) +static int process_hex_number(xyw_context *ctx) { // Token is a hex number starting with $ xyw_short value = 0;@@ -167,7 +167,7 @@ // TODO: Store value
return 0; } -static int parse_binary_number(xyw_context *ctx) +static int process_binary_number(xyw_context *ctx) { // Token is a binary number starting with % xyw_short value = 0;@@ -195,7 +195,7 @@ // TODO: Store value
return 0; } -static int parse_decimal_number(xyw_context *ctx) +static int process_decimal_number(xyw_context *ctx) { // Token is a decimal number (may or may not start with -) xyw_short value = 0;@@ -229,7 +229,7 @@ // TODO: Store value
return 0; } -static int parse_instruction(xyw_context *ctx) +static int process_instruction(xyw_context *ctx) { (void)ctx; xyw_byte opcode = 0;@@ -278,7 +278,7 @@ }
return -1; } -static int parse_string(xyw_context *ctx) +static int process_string(xyw_context *ctx) { (void)ctx; // Token is a string enclosed in double quotes@@ -288,7 +288,7 @@ // TODO: Store string data
return 0; } -static int parse_symbol(xyw_context *ctx) +static int process_symbol(xyw_context *ctx) { if (validate_symbol(ctx, token, token_length) != 0) {@@ -300,7 +300,7 @@ // TODO: Process symbol
return 0; } -static int parse_directive(xyw_context *ctx) +static int process_directive(xyw_context *ctx) { if (validate_symbol(ctx, token + 1, token_length - 1) != 0) {@@ -311,45 +311,47 @@ for (unsigned int i = 0; i < directive_length; i++)
{ directive[i] = token[i]; } + directive[directive_length] = '\0'; // TODO: Remove printf("Directive:\t%s\n", token); // TODO: Process directive return 0; } +// Parse tokens static int parse_token(xyw_context *ctx) { if (token[0] == ';') { - return parse_comment(ctx); + return process_comment(ctx); } else if (token[0] == '.') { - return parse_directive(ctx); + return process_directive(ctx); } else if (token[0] == '$') { - return parse_hex_number(ctx); + return process_hex_number(ctx); } else if (token[0] == '%') { - return parse_binary_number(ctx); + return process_binary_number(ctx); } else if (token[0] == '\"') { - return parse_string(ctx); + return process_string(ctx); } else if ((token[0] >= '0' && token[0] <= '9') || token[0] == '-') { - return parse_decimal_number(ctx); + return process_decimal_number(ctx); } else if ((token[0] >= 'A' && token[0] <= 'Z') || (token[0] >= 'a' && token[0] <= 'z') || token[0] == '_') { - if (parse_instruction(ctx) == 0) + if (process_instruction(ctx) == 0) { return 0; } - return parse_symbol(ctx); + return process_symbol(ctx); } token_error("Unrecognized token"); return -1;@@ -370,13 +372,12 @@ while (fread(&c, 1, 1, ctx->fp) == 1)
{ if (c == '"') { - // Start of string token + // Special handling for string tokens if (token_length < STRING_MAX_LENGTH - 1) { token[token_length++] = (char)c; token[token_length] = '\0'; ctx->column++; - // Read until closing quote while (fread(&c, 1, 1, ctx->fp) == 1) { ctx->column++;