all repos — hex @ 2eb9feb0b7e19b6c67a6bd15698c8896cf135311

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

Improvements + additional tests.
h3rald h3rald@h3rald.com
Tue, 03 Dec 2024 11:31:32 +0100
commit

2eb9feb0b7e19b6c67a6bd15698c8896cf135311

parent

fe7ab6a66e763b0f2d5c1b97c15566ddeb00b7eb

4 files changed, 21 insertions(+), 7 deletions(-)

jump to
M MakefileMakefile

@@ -6,7 +6,7 @@ hex: hex.c

$(CC) $(CFLAGS) $(LDFLAGS) $< -o hex wasm: hex.c - emcc -sASYNCIFY -sEXPORTED_RUNTIME_METHODS=stringToUTF8 hex.c -o web/assets/hex.js --pre-js web/assets/hex-playground.js + emcc -O2 -sASYNCIFY -sEXPORTED_RUNTIME_METHODS=stringToUTF8 hex.c -o web/assets/hex.js --pre-js web/assets/hex-playground.js ape: hex.c cosmocc $(CFLAGS) $(LDFLAGS) $< -o hex
M hex.chex.c

@@ -1087,7 +1087,7 @@ return 1;

} if (hex_set_symbol(ctx, name.data.str_value, value, 0) != 0) { - hex_error(ctx, "Failed to store variable"); + hex_error(ctx, "Failed to store symbol '%s'", name.data.str_value); FREE(ctx, name); FREE(ctx, value); return 1;

@@ -1107,7 +1107,7 @@ }

if (item.type != HEX_TYPE_STRING) { FREE(ctx, item); - hex_error(ctx, "Variable name must be a string"); + hex_error(ctx, "Symbol name must be a string"); return 1; } if (hex_valid_native_symbol(ctx, item.data.str_value))

@@ -1160,7 +1160,7 @@ return 1;

} if (item.type != HEX_TYPE_QUOTATION) { - hex_error(ctx, "'i' symbol requires a quotation"); + hex_error(ctx, "Symbol 'i' requires a quotation"); FREE(ctx, item); return 1; }

@@ -1187,7 +1187,7 @@ return 1;

} if (item.type != HEX_TYPE_STRING) { - hex_error(ctx, "'eval' symbol requires a string"); + hex_error(ctx, "Symbol 'eval' requires a string"); FREE(ctx, item); return 1; }

@@ -1284,7 +1284,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, "'+' symbol requires two integers"); + hex_error(ctx, "Symbol '+' requires two integers"); FREE(ctx, a); FREE(ctx, b); return 1;

@@ -1310,7 +1310,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, "'-' symbol requires two integers"); + hex_error(ctx, "Symbol '-' requires two integers"); FREE(ctx, a); FREE(ctx, b); return 1;
M test.hextest.hex

@@ -4,6 +4,8 @@ 0x0 "failures" store

() "errors" store () "fails" store +(dup puts) "pp" store + ( "current-test" store test-count 0x1 + "test-count" store

@@ -135,6 +137,18 @@ (0x2 dup stack (0x2 0x2) ==)

(clear stack () ==) (0x1 0x2 swap pop stack (0x2) ==) ;68 + + (("aaa" "puts" store) (error) try "Failed to store symbol 'puts'" ==) + (("puts" free) (error) try "Cannot free native symbol 'puts'" ==) + (("aaa" 0x2 store) (error) try "Symbol name must be a string" ==) + ((0x2 free) (error) try "Symbol name must be a string" ==) + ;72 + + (("puts" i) (error) try "Symbol 'i' requires a quotation" ==) + (((puts) eval) (error) try "Symbol 'eval' requires a string" ==) + (("3" 0x3 +) (error) try "Symbol '+' requires two integers" ==) + (("3" 0x3 -) (error) try "Symbol '-' requires two integers" ==) + ;76 ) "tests" store