all repos — hex @ 45d653d92de03defcf410c34574553e14cf5945b

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

Fixes.
h3rald h3rald@h3rald.com
Sun, 24 Nov 2024 22:05:28 +0100
commit

45d653d92de03defcf410c34574553e14cf5945b

parent

9f2c8d5e89f3455cb25c90e9eb4b10dd224f1a38

1 files changed, 37 insertions(+), 62 deletions(-)

jump to
M hex.chex.c

@@ -1703,21 +1703,16 @@ hex_free_element(a);

hex_free_element(b); return 1; } - int result = 0; if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER) { - result = hex_push_int(a.data.intValue < b.data.intValue); + return hex_push_int(a.data.intValue < b.data.intValue); } - else if (a.type == HEX_TYPE_STRING && b.type == HEX_TYPE_STRING) + if (a.type == HEX_TYPE_STRING && b.type == HEX_TYPE_STRING) { - result = hex_push_int(strcmp(a.data.strValue, b.data.strValue) < 0); + return hex_push_int(strcmp(a.data.strValue, b.data.strValue) < 0); } - else - { - hex_error("'<' symbol requires two integers or two strings"); - result = 1; - } - return result; + hex_error("'<' symbol requires two integers or two strings"); + return 1; } int hex_symbol_greaterequal()

@@ -1735,21 +1730,16 @@ hex_free_element(a);

hex_free_element(b); return 1; } - int result = 0; if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER) { - result = hex_push_int(a.data.intValue >= b.data.intValue); - } - else if (a.type == HEX_TYPE_STRING && b.type == HEX_TYPE_STRING) - { - result = hex_push_int(strcmp(a.data.strValue, b.data.strValue) >= 0); + return hex_push_int(a.data.intValue >= b.data.intValue); } - else + if (a.type == HEX_TYPE_STRING && b.type == HEX_TYPE_STRING) { - hex_error("'>=' symbol requires two integers or two strings"); - result = 1; + return hex_push_int(strcmp(a.data.strValue, b.data.strValue) >= 0); } - return result; + hex_error("'>=' symbol requires two integers or two strings"); + return 1; } int hex_symbol_lessequal()

@@ -1767,21 +1757,16 @@ hex_free_element(a);

hex_free_element(b); return 1; } - int result = 0; if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER) { - result = hex_push_int(a.data.intValue <= b.data.intValue); + return hex_push_int(a.data.intValue <= b.data.intValue); } - else if (a.type == HEX_TYPE_STRING && b.type == HEX_TYPE_STRING) + if (a.type == HEX_TYPE_STRING && b.type == HEX_TYPE_STRING) { - result = hex_push_int(strcmp(a.data.strValue, b.data.strValue) <= 0); + return hex_push_int(strcmp(a.data.strValue, b.data.strValue) <= 0); } - else - { - hex_error("'<=' symbol requires two integers or two strings"); - result = 1; - } - return result; + hex_error("'<=' symbol requires two integers or two strings"); + return 1; } // Boolean symbols

@@ -1801,17 +1786,12 @@ hex_free_element(a);

hex_free_element(b); return 1; } - int result = 0; if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER) { - result = hex_push_int(a.data.intValue && b.data.intValue); + return hex_push_int(a.data.intValue && b.data.intValue); } - else - { - hex_error("'and' symbol requires two integers"); - result = 1; - } - return result; + hex_error("'and' symbol requires two integers"); + return 1; } int hex_symbol_or()

@@ -1829,17 +1809,12 @@ hex_free_element(a);

hex_free_element(b); return 1; } - int result = 0; if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER) { - result = hex_push_int(a.data.intValue || b.data.intValue); - } - else - { - hex_error("'or' symbol requires two integers"); - result = 1; + return hex_push_int(a.data.intValue || b.data.intValue); } - return result; + hex_error("'or' symbol requires two integers"); + return 1; } int hex_symbol_not()

@@ -1850,18 +1825,13 @@ {

hex_free_element(a); return 1; } - int result = 0; if (a.type == HEX_TYPE_INTEGER) { - result = hex_push_int(!a.data.intValue); + return hex_push_int(!a.data.intValue); } - else - { - hex_error("'not' symbol requires an integer"); - result = 1; - } + hex_error("'not' symbol requires an integer"); hex_free_element(a); - return result; + return 1; } int hex_symbol_xor()

@@ -1879,17 +1849,12 @@ hex_free_element(a);

hex_free_element(b); return 1; } - int result = 0; if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER) { - result = hex_push_int(a.data.intValue ^ b.data.intValue); + return hex_push_int(a.data.intValue ^ b.data.intValue); } - else - { - hex_error("'xor' symbol requires two integers"); - result = 1; - } - return result; + hex_error("'xor' symbol requires two integers"); + return 1; } ////////////////////////////////////////

@@ -2062,6 +2027,12 @@ {

hex_error("Symbol 'slice' requires a quotation or a string"); result = 1; } + if (result != 0) + { + hex_free_element(list); + hex_free_element(start); + hex_free_element(end); + } return result; }

@@ -2086,6 +2057,10 @@ else

{ hex_error("Symbol 'len' requires a quotation or a string"); result = 1; + } + if (result != 0) + { + hex_free_element(element); } return result; }