Tested unbalanced quotations.
h3rald h3rald@h3rald.com
Wed, 18 Dec 2024 11:45:46 +0100
3 files changed,
11 insertions(+),
10 deletions(-)
M
src/hex.h
→
src/hex.h
@@ -352,7 +352,7 @@ int hex_symbol_clear(hex_context_t *ctx);
int hex_symbol_pop(hex_context_t *ctx); // VM -int hex_bytecode(hex_context_t *ctx, const char *input, uint8_t **output, size_t *output_size, hex_file_position_t *position, int *open_quotations); +int hex_bytecode(hex_context_t *ctx, const char *input, uint8_t **output, size_t *output_size, hex_file_position_t *position); int hex_generate_quotation_bytecode(hex_context_t *ctx, const char **input, uint8_t **output, size_t *output_size, size_t *n_items, hex_file_position_t *position); int hex_bytecode_quotation(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t *capacity, uint8_t **output, size_t *output_size, size_t *n_items); int hex_bytecode_integer(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t *capacity, int32_t value);
M
src/main.c
→
src/main.c
@@ -380,7 +380,6 @@ hex_file_position_t position;
position.column = 1; position.line = 1 + ctx.hashbang; position.filename = file; - int open_quotations = 0; char *bytecode_file = strdup(file); char *ext = strrchr(bytecode_file, '.'); if (ext != NULL)@@ -391,14 +390,9 @@ else
{ strcat(bytecode_file, ".hbx"); } - if (hex_bytecode(&ctx, fileContent, &bytecode, &bytecode_size, &position, &open_quotations) != 0) + if (hex_bytecode(&ctx, fileContent, &bytecode, &bytecode_size, &position) != 0) { hex_error(&ctx, "Failed to generate bytecode"); - return 1; - } - if (open_quotations != 0) - { - hex_error(&ctx, "File contains unbalanced quotations"); return 1; } if (hex_write_bytecode_file(&ctx, bytecode_file, bytecode, bytecode_size) != 0)
M
src/vm.c
→
src/vm.c
@@ -530,7 +530,7 @@ hex_debug(ctx, "PUSHQT[%d]: (total size: %d) <end>", *n_items, *output_size);
return 0; } -int hex_bytecode(hex_context_t *ctx, const char *input, uint8_t **output, size_t *output_size, hex_file_position_t *position, int *open_quotations) +int hex_bytecode(hex_context_t *ctx, const char *input, uint8_t **output, size_t *output_size, hex_file_position_t *position) { hex_token_t *token; size_t capacity = 128;@@ -571,7 +571,8 @@ hex_bytecode_quotation(ctx, &bytecode, &size, &capacity, "ation_bytecode, "ation_size, &n_items);
} else if (token->type == HEX_TOKEN_QUOTATION_END) { - open_quotations--; + hex_error(ctx, "(%d, %d) Unexpected end of quotation", position->line, position->column); + return 1; } else {@@ -883,18 +884,21 @@ {
case HEX_OP_PUSHIN: if (hex_interpret_bytecode_integer(ctx, &bytecode, &size, item) != 0) { + HEX_FREE(ctx, *item); return 1; } break; case HEX_OP_PUSHST: if (hex_interpret_bytecode_string(ctx, &bytecode, &size, item) != 0) { + HEX_FREE(ctx, *item); return 1; } break; case HEX_OP_LOOKUP: if (hex_interpret_bytecode_user_symbol(ctx, &bytecode, &size, position, item) != 0) { + HEX_FREE(ctx, *item); return 1; } break;@@ -902,18 +906,21 @@ case HEX_OP_PUSHQT:
if (hex_interpret_bytecode_quotation(ctx, &bytecode, &size, position, item) != 0) { + HEX_FREE(ctx, *item); return 1; } break; default: if (hex_interpret_bytecode_native_symbol(ctx, opcode, position, item) != 0) { + HEX_FREE(ctx, *item); return 1; } break; } if (hex_push(ctx, *item) != 0) { + HEX_FREE(ctx, *item); return 1; } }