all repos — hex @ e789e8e6d03cf2991713c71771d2f29ea061b8d2

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

Added more test, fixed double entries and hashbang shift in stack trace.
h3rald h3rald@h3rald.com
Wed, 11 Dec 2024 07:34:49 +0100
commit

e789e8e6d03cf2991713c71771d2f29ea061b8d2

parent

55b0654160b7b4f7dca7b3bfa6d6f04241238c0b

3 files changed, 33 insertions(+), 10 deletions(-)

jump to
M scripts/test.hexscripts/test.hex

@@ -189,13 +189,31 @@ ((0x3 "aaa") ("aaa" 0x5) > 0x0 ==)

(("aaa" 0x5) ("aaa" 0x5 0x4) >= 0x0 ==) ;100 - ((test "aaa") (test "aaa" 0x5) < 0x1 ==) + ((test "aaa") (test "aaa" 0x5) < 0x1 ==) (("aaa" 0x5) ("" "aaa" 0x5) <= 0x0 ==) + (("a" "b" and) (error) try "Symbol 'and' requires two integers" ==) + ((0x1 "a" or) (error) try "Symbol 'or' requires two integers" ==) + ;104 + + ((() not) (error) try "Symbol 'not' requires an integer" ==) + ((() 0x1 xor) (error) try "Symbol 'xor' requires two integers" ==) + (("" () cat) (error) try "Symbol 'cat' requires two quotations or two strings" ==) + (("abcde" 0x1 "2" slice ) (error) try "Slice indices must be integers" ==) + ;108 + + (("abcde" 0xffffffff 0x2 slice ) (error) try "Slice indices out of range" ==) + (("abcde" 0x2 0xf slice ) (error) try "Slice indices out of range" ==) + (((0x4 0x5) 0xffffffff 0x2 slice ) (error) try "Slice indices out of range" ==) + (((0x3 0x4 0x5 0x6) 0x2 0xf slice ) (error) try "Slice indices out of range" ==) + ;112 + + ((0x4 0x5 0x6 slice) (error) try "Symbol 'slice' requires a quotation or a string" ==) + ((0x4 len) (error) try "Symbol 'len' requires a quotation or a string" ==) + (("abc" "b" get) (error) try "Index must be an integer" ==) + (((0x4 "aa" test) "b" get) (error) try "Index must be an integer" ==) + ;116 ) "tests" : - -; Cleanup -clear ; --- Run tests
M src/hex.csrc/hex.c

@@ -160,7 +160,6 @@ }

else if (item.type == HEX_TYPE_NATIVE_SYMBOL) { hex_debug_item(ctx, "CALL", item); - add_to_stack_trace(ctx, item.token); result = item.data.fn_value(ctx); } else

@@ -1979,7 +1978,7 @@ if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER)

{ return hex_push_integer(ctx, a.data.int_value && b.data.int_value); } - hex_error(ctx, "'and' symbol requires two integers"); + hex_error(ctx, "Symbol 'and' requires two integers"); FREE(ctx, a); FREE(ctx, b); return 1;

@@ -2005,7 +2004,7 @@ if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER)

{ return hex_push_integer(ctx, a.data.int_value || b.data.int_value); } - hex_error(ctx, "'or' symbol requires two integers"); + hex_error(ctx, "Symbol 'or' requires two integers"); FREE(ctx, a); FREE(ctx, b); return 1;

@@ -2024,7 +2023,7 @@ if (a.type == HEX_TYPE_INTEGER)

{ return hex_push_integer(ctx, !a.data.int_value); } - hex_error(ctx, "'not' symbol requires an integer"); + hex_error(ctx, "Symbol 'not' requires an integer"); FREE(ctx, a); return 1; }

@@ -2049,7 +2048,7 @@ if (a.type == HEX_TYPE_INTEGER && b.type == HEX_TYPE_INTEGER)

{ return hex_push_integer(ctx, a.data.int_value ^ b.data.int_value); } - hex_error(ctx, "'xor' symbol requires two integers"); + hex_error(ctx, "Symbol 'xor' requires two integers"); FREE(ctx, a); FREE(ctx, b); return 1;

@@ -3953,6 +3952,11 @@ if (strncmp(hashbangLine, "#!", 2) != 0)

{ // Not a hashbang line, reset file pointer to the beginning fseek(file, 0, SEEK_SET); + ctx->hashbang = 0; + } + else + { + ctx->hashbang = 1; } }

@@ -4241,7 +4245,7 @@ if (!fileContent)

{ return 1; } - hex_interpret(&ctx, fileContent, arg, 1, 1); + hex_interpret(&ctx, fileContent, arg, 1 + ctx.hashbang, 1); return 0; } }
M src/hex.hsrc/hex.h

@@ -132,6 +132,7 @@ hex_registry_t registry;

hex_stack_trace_t stack_trace; hex_settings_t settings; hex_doc_dictionary_t docs; + int hashbang; char error[256]; int argc; char **argv;