all repos — hex @ 874ad63adc314a21055baf0d4faf7c9aaabef08d

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

Added extra argument to !
Fabio Cevasco h3rald@h3rald.com
Sun, 06 Apr 2025 13:10:13 +0200
commit

874ad63adc314a21055baf0d4faf7c9aaabef08d

parent

feaa3f8a2763baf164b3d7323bd705d6e654fce9

4 files changed, 23 insertions(+), 9 deletions(-)

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

@@ -48,7 +48,7 @@ ("aaa" type "string" == 0x1 type "integer" == () type "quotation" == and and)

((0x1 0x2 +) . 0x3 ==) ;4 - ("0x2 0x2 -" ! 0x0 ==) + ("0x2 0x2 -" "test.hex" ! 0x0 ==) (0x4 0x5 + 0x9 ==) (0x5 0x3 - 0x2 ==) (0x5 0x2 * 0xa ==)

@@ -152,7 +152,7 @@ ((0x2 #) (error) try "[symbol #] Symbol name must be a string" ==)

;72 (("puts" .) (error) try "[symbol .] Quotation required" ==) - (((puts) !) (error) try "[symbol !] Quotation must contain only integers" ==) + (((puts) "test.hex" !) (error) try "[symbol !] Quotation must contain only integers" ==) (("3" 0x3 +) (error) try "[symbol +] Two integers required" ==) (("3" 0x3 -) (error) try "[symbol -] Two integers required" ==) ;76
M src/doc.csrc/doc.c

@@ -57,7 +57,7 @@ hex_set_doc(docs, "stack", "", "q", "Returns the contents of the stack.");

// Evaluation hex_set_doc(docs, ".", "q", "*", "Pushes each item of 'q' on the stack."); - hex_set_doc(docs, "!", "(s|q)", "*", "Evaluates 's' as a hex program or 'q' as hex bytecode."); + hex_set_doc(docs, "!", "(s1|q) s2", "*", "Evaluates 's1' as a hex program or 'q' as hex bytecode (using s2 as file name)."); hex_set_doc(docs, "'", "a", "q", "Wraps 'a' in a quotation."); hex_set_doc(docs, "debug", "q", "*", "Enables debug mode and pushes each item of 'q' on the stack.");
M src/symbols.csrc/symbols.c

@@ -241,16 +241,28 @@

// evaluate a string or bytecode array int hex_symbol_eval(hex_context_t *ctx) { + HEX_POP(ctx, file); HEX_POP(ctx, item); - ; + if (file->type == HEX_TYPE_INVALID) + { + HEX_FREE(ctx, file); + return 1; + } + if (file->type != HEX_TYPE_STRING) + { + hex_error(ctx, "[symbol !] File name or scope identifier required"); + HEX_FREE(ctx, file); + return 1; + } if (item->type == HEX_TYPE_INVALID) { HEX_FREE(ctx, item); + HEX_FREE(ctx, file); return 1; } if (item->type == HEX_TYPE_STRING) { - int result = hex_interpret(ctx, item->data.str_value, "<!>", 1, 1); + int result = hex_interpret(ctx, item->data.str_value, file->data.str_value, 1, 1); // HEX_FREE(ctx, item); return result; }

@@ -270,6 +282,7 @@ if (!bytecode)

{ hex_error(ctx, "[symbol !] Memory allocation failed"); HEX_FREE(ctx, item); + HEX_FREE(ctx, file); return 1; } for (size_t i = 0; i < item->quotation_size; i++)

@@ -278,7 +291,7 @@ bytecode[i] = (uint8_t)item->data.quotation_value[i]->data.int_value;

} // Copy the current symbol table before evaluating the bytecode hex_symbol_table_t *symbol_table_copy = hex_symboltable_copy(ctx); - int result = hex_interpret_bytecode(ctx, bytecode, item->quotation_size, "<eval>"); + int result = hex_interpret_bytecode(ctx, bytecode, item->quotation_size, file->data.str_value); // Restore the original symbol table ctx->symbol_table = symbol_table_copy; return result;

@@ -287,6 +300,7 @@ else

{ hex_error(ctx, "[symbol !] String or a quotation of integers required"); HEX_FREE(ctx, item); + HEX_FREE(ctx, file); return 1; } }
M web/contents/spec.htmlweb/contents/spec.html

@@ -599,11 +599,11 @@ <p><mark>q &rarr; *</mark></p>

<aside>OPCODE: <code>1d</code></aside> <p>Dequotes quotation <code>q</code>.</p> <h5 id="eval-symbol"><code>$:!$$</code> Symbol<a href="#top"></a></h5> - <p><mark>(s|q) &rarr; *</mark></p> + <p><mark>(s1|q) s2 &rarr; *</mark></p> <aside>OPCODE: <code>1e</code></aside> - <p>Evaluates the string <code>s</code> as an hex program, or the array of integers to be interpreted as hex + <p>Evaluates the string <code>s1</code> as an hex program, or the array of integers to be interpreted as hex bytecode - (HBX format).</p> + (HBX format). <code>s2</code> will be used as the file name to display in stack traces.</p> <h5 id="quote-symbol"><code>$:&#39;$$</code> Symbol<a href="#top"></a></h5> <p><mark>a &rarr; q</mark></p> <aside>OPCODE: <code>1f</code></aside>