all repos — hex @ 97a32596077981eb4565d6734b2bf14a3151db85

A tiny, minimalist, slightly-esoteric concatenative programming lannguage.

Improving debugging.
h3rald h3rald@h3rald.com
Sun, 24 Nov 2024 14:42:27 +0100
commit

97a32596077981eb4565d6734b2bf14a3151db85

parent

a61f8112579e08339fec448e1a149c1bf42e8e5f

1 files changed, 19 insertions(+), 6 deletions(-)

jump to
M hex.chex.c

@@ -269,6 +269,7 @@ ////////////////////////////////////////

// Stack Implementation // //////////////////////////////////////// +void hex_debug(const char *format, ...); void hex_debug_element(const char *message, HEX_StackElement element); void add_to_stack_trace(HEX_Token *token);

@@ -284,11 +285,10 @@ hex_error("Stack overflow");

return 1; } hex_debug_element("PUSH", element); - // Note: from a parser perspective, there is no way to determine if a symbol is a native symbol or a user symbol + int result = 0; if (element.type == HEX_TYPE_USER_SYMBOL) { HEX_StackElement value; - int result = 0; if (hex_get_symbol(element.symbolName, &value)) { result = hex_push(value);

@@ -299,16 +299,26 @@ hex_error("Undefined user symbol: %s", element.symbolName);

hex_free_element(value); result = 1; } - return result; } else if (element.type == HEX_TYPE_NATIVE_SYMBOL) { hex_debug_element("CALL", element); add_to_stack_trace(element.token); - return element.data.functionPointer(); + result = element.data.functionPointer(); } - HEX_STACK[++HEX_TOP] = element; - return 0; + else + { + HEX_STACK[++HEX_TOP] = element; + } + if (result == 0) + { + hex_debug_element("DONE", element); + } + else + { + hex_debug_element("FAIL", element); + } + return result; } int hex_push_int(int value)

@@ -1342,6 +1352,7 @@ {

if (b.data.intValue == 0) { hex_error("Division by zero"); + return 1; } result = hex_push_int(a.data.intValue / b.data.intValue); }

@@ -3209,11 +3220,13 @@

HEX_ERRORS = 0; for (int i = 0; i < tryBlock.quotationSize; i++) { + /// Remove extra printing. printf("-> "); hex_print_element(stdout, *tryBlock.data.quotationValue[i]); printf("\n"); if (hex_push(*tryBlock.data.quotationValue[i]) != 0) { + printf("Error occurred: %s\n", HEX_ERROR); break; } }