Fixes.
@@ -108,10 +108,9 @@
typedef struct hex_registry_t { hex_registry_entry_t **buckets; // Array of bucket pointers - size_t bucket_count; // Number of buckets - size_t size; // Number of stored entries + size_t bucket_count; // Number of buckets + size_t size; // Number of stored entries } hex_registry_t; - typedef struct hex_doc_entry_t {@@ -309,7 +308,7 @@ char *hex_bytes_to_string(const uint8_t *bytes, size_t size);
char *hex_process_string(const char *value); size_t hex_min_bytes_to_encode_integer(int32_t value); char *hex_unescape_string(const char *input); -char* hex_normalize_newlines(const char* input); +char *hex_normalize_newlines(const char *input); // Native symbols int hex_symbol_store(hex_context_t *ctx);@@ -389,10 +388,10 @@ int hex_bytecode_string(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t *capacity, const char *value);
int hex_bytecode_symbol(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t *capacity, const char *value); int hex_interpret_bytecode_integer(hex_context_t *ctx, uint8_t **bytecode, size_t *size, hex_item_t *result); int hex_interpret_bytecode_string(hex_context_t *ctx, uint8_t **bytecode, size_t *size, hex_item_t *result); -int hex_interpret_bytecode_native_symbol(hex_context_t *ctx, uint8_t opcode, size_t position, hex_item_t *result); -int hex_interpret_bytecode_user_symbol(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, hex_item_t *result); -int hex_interpret_bytecode_quotation(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, hex_item_t *result); -int hex_interpret_bytecode(hex_context_t *ctx, uint8_t *bytecode, size_t size); +int hex_interpret_bytecode_native_symbol(hex_context_t *ctx, uint8_t opcode, size_t position, const char *filename, hex_item_t *result); +int hex_interpret_bytecode_user_symbol(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, const char *filename, hex_item_t *result); +int hex_interpret_bytecode_quotation(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, const char *filename, hex_item_t *result); +int hex_interpret_bytecode(hex_context_t *ctx, uint8_t *bytecode, size_t size, const char *filename); void hex_header(hex_context_t *ctx, uint8_t header[8]); int hex_validate_header(uint8_t header[8]);
@@ -376,7 +376,7 @@ return 1;
} fread(bytecode, 1, bytecode_size, bytecode_file); fclose(bytecode_file); - hex_interpret_bytecode(ctx, bytecode, bytecode_size); + hex_interpret_bytecode(ctx, bytecode, bytecode_size, file); free(bytecode); } else
@@ -63,7 +63,7 @@ }
} else if (item->type == HEX_TYPE_NATIVE_SYMBOL) { - hex_item_t *value = malloc(sizeof(hex_item_t)); + HEX_ALLOC(value); if (value == NULL) { hex_error(ctx, "[push] Failed to allocate memory for value");@@ -299,7 +299,14 @@ }
// Copy basic fields copy->type = token->type; - copy->quotation_size = token->quotation_size; + if (token->type == HEX_TOKEN_QUOTATION_START || token->type == HEX_TOKEN_QUOTATION_END) + { + copy->quotation_size = token->quotation_size; + } + else + { + copy->quotation_size = 0; + } // Copy the token's value if (token->value)@@ -347,8 +354,22 @@ {
copy->position->filename = NULL; } - copy->position->line = token->position->line; - copy->position->column = token->position->column; + if (token->position->line) + { + copy->position->line = token->position->line; + } + else + { + copy->position->line = 0; + } + if (token->position->column) + { + copy->position->column = token->position->column; + } + else + { + copy->position->column = 0; + } } else {
@@ -146,7 +146,7 @@ // Free already allocated items
for (size_t j = 0; j < quotation_size; j++) { free(quotation[j]->data.str_value); // Free string value - free(quotation[j]); // Free hex_item_t + free(quotation[j]); // Free hex_item_t } free(quotation); return 1;@@ -231,7 +231,7 @@ for (size_t i = 0; i < item->quotation_size; i++)
{ if (hex_push(ctx, item->data.quotation_value[i]) != 0) { - //HEX_FREE(ctx, item); + // HEX_FREE(ctx, item); return 1; } }@@ -276,7 +276,7 @@ for (size_t i = 0; i < item->quotation_size; i++)
{ bytecode[i] = (uint8_t)item->data.quotation_value[i]->data.int_value; } - int result = hex_interpret_bytecode(ctx, bytecode, item->quotation_size); + int result = hex_interpret_bytecode(ctx, bytecode, item->quotation_size, "<eval>"); return result; } else@@ -306,7 +306,7 @@ for (size_t i = 0; i < item->quotation_size; i++)
{ if (hex_push(ctx, item->data.quotation_value[i]) != 0) { - //HEX_FREE(ctx, item); + // HEX_FREE(ctx, item); ctx->settings->debugging_enabled = 0; return 1; }@@ -1508,7 +1508,7 @@
// String symbols int hex_symbol_join(hex_context_t *ctx) -{ +{ HEX_POP(ctx, separator); if (separator->type == HEX_TYPE_INVALID) {
@@ -392,7 +392,7 @@ hex_debug(ctx, ">> PUSHST[02]: \"%s\"", str);
return 0; } -int hex_interpret_bytecode_native_symbol(hex_context_t *ctx, uint8_t opcode, size_t position, hex_item_t *result) +int hex_interpret_bytecode_native_symbol(hex_context_t *ctx, uint8_t opcode, size_t position, const char *filename, hex_item_t *result) { const char *symbol = hex_opcode_to_symbol(opcode);@@ -408,6 +408,7 @@ HEX_ALLOC(value);
hex_token_t *token = (hex_token_t *)malloc(sizeof(hex_token_t)); token->value = strdup(symbol); token->position = (hex_file_position_t *)malloc(sizeof(hex_file_position_t)); + token->position->filename = strdup(filename); token->position->line = 0; token->position->column = position; if (hex_get_symbol(ctx, token->value, value))@@ -427,7 +428,7 @@ *result = *item;
return 0; } -int hex_interpret_bytecode_user_symbol(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, hex_item_t *result) +int hex_interpret_bytecode_user_symbol(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, const char *filename, hex_item_t *result) { // Get the index of the symbol (one byte) if (*size == 0)@@ -461,6 +462,7 @@
token->value = (char *)malloc(length + 1); strncpy(token->value, value, length + 1); token->position = (hex_file_position_t *)malloc(sizeof(hex_file_position_t)); + token->position->filename = strdup(filename); token->position->line = 0; token->position->column = position;@@ -473,7 +475,7 @@ *result = item;
return 0; } -int hex_interpret_bytecode_quotation(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, hex_item_t *result) +int hex_interpret_bytecode_quotation(hex_context_t *ctx, uint8_t **bytecode, size_t *size, size_t position, const char *filename, hex_item_t *result) { size_t n_items = 0; int shift = 0;@@ -525,21 +527,21 @@ return 1;
} break; case HEX_OP_LOOKUP: - if (hex_interpret_bytecode_user_symbol(ctx, bytecode, size, position, item) != 0) + if (hex_interpret_bytecode_user_symbol(ctx, bytecode, size, position, filename, item) != 0) { hex_free_list(ctx, items, n_items); return 1; } break; case HEX_OP_PUSHQT: - if (hex_interpret_bytecode_quotation(ctx, bytecode, size, position, item) != 0) + if (hex_interpret_bytecode_quotation(ctx, bytecode, size, position, filename, item) != 0) { hex_free_list(ctx, items, n_items); return 1; } break; default: - if (hex_interpret_bytecode_native_symbol(ctx, opcode, *size, item) != 0) + if (hex_interpret_bytecode_native_symbol(ctx, opcode, *size, filename, item) != 0) { hex_free_list(ctx, items, n_items); return 1;@@ -556,7 +558,7 @@ hex_debug(ctx, ">> PUSHQT[03]: <end> (items: %zu)", n_items);
return 0; } -int hex_interpret_bytecode(hex_context_t *ctx, uint8_t *bytecode, size_t size) +int hex_interpret_bytecode(hex_context_t *ctx, uint8_t *bytecode, size_t size, const char *filename) { size_t bytecode_size = size; size_t position = bytecode_size;@@ -618,7 +620,7 @@ return 1;
} break; case HEX_OP_LOOKUP: - if (hex_interpret_bytecode_user_symbol(ctx, &bytecode, &size, position, item) != 0) + if (hex_interpret_bytecode_user_symbol(ctx, &bytecode, &size, position, filename, item) != 0) { HEX_FREE(ctx, item); return 1;@@ -626,14 +628,14 @@ }
break; case HEX_OP_PUSHQT: - if (hex_interpret_bytecode_quotation(ctx, &bytecode, &size, position, item) != 0) + if (hex_interpret_bytecode_quotation(ctx, &bytecode, &size, position, filename, item) != 0) { HEX_FREE(ctx, item); return 1; } break; default: - if (hex_interpret_bytecode_native_symbol(ctx, opcode, position, item) != 0) + if (hex_interpret_bytecode_native_symbol(ctx, opcode, position, filename, item) != 0) { HEX_FREE(ctx, item); return 1;