all repos — hex @ 77191c38902b63d51b0d43541f09a2efc56d11e3

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

Improvements.
h3rald h3rald@h3rald.com
Tue, 03 Dec 2024 08:03:10 +0100
commit

77191c38902b63d51b0d43541f09a2efc56d11e3

parent

fc8380255e0235f05740a273586f49fa3cae3268

4 files changed, 14 insertions(+), 12 deletions(-)

jump to
M MakefileMakefile

@@ -1,15 +1,15 @@

-CC ?= gcc -CFLAGS ?= -Wall -Wextra -g -LDFLAGS ?= +CC = gcc +CFLAGS = -Wall -Wextra -g +LDFLAGS = hex: hex.c - $(CC) $(CFLAGS) $(LDFLAGS) $< -o $@ + $(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 ape: hex.c - cosmocc $(CFLAGS) $(LDFLAGS) $< -o $@ + cosmocc $(CFLAGS) $(LDFLAGS) $< -o hex .PHONY: clean clean:
D build.cmd

@@ -1,3 +0,0 @@

-gcc -Wall -Wextra -g hex.c -o hex.exe -emcc -sASYNCIFY -sEXPORTED_RUNTIME_METHODS=stringToUTF8 hex.c -o web/assets/hex.js --pre-js web/assets/hex-playground.js -cosmocc -o hex hex.c
M hex.chex.c

@@ -77,7 +77,7 @@ if (strcmp(ctx->registry.entries[i].key, key) == 0)

{ if (ctx->registry.entries[i].value.type == HEX_TYPE_NATIVE_SYMBOL) { - hex_error(ctx, "Cannot overwrite native symbol %s", key); + hex_error(ctx, "Cannot overwrite native symbol '%s'", key); return 1; } free(ctx->registry.entries[i].key);

@@ -1108,6 +1108,12 @@ if (item.type != HEX_TYPE_STRING)

{ FREE(ctx, item); hex_error(ctx, "Variable name must be a string"); + return 1; + } + if (hex_valid_native_symbol(ctx, item.data.str_value)) + { + hex_error(ctx, "Cannot free native symbol '%s'", item.data.str_value); + FREE(ctx, item); return 1; } for (int i = 0; i < ctx->registry.size; i++)

@@ -2956,7 +2962,6 @@ CloseHandle(pi.hProcess);

CloseHandle(pi.hThread); CloseHandle(hOutputRead); CloseHandle(hErrorRead); - #else // POSIX implementation (Linux/macOS) int stdout_pipe[2];
M web/contents/home.htmlweb/contents/home.html

@@ -34,14 +34,14 @@ inside a quotation that is then printed:</p>

<pre><code>"ls" run 0x1 get "&bsol;n" split puts</code></pre> <p>Note that <strong>no variable is used in the code above</strong>! Let's break it down:</p> <ul> - <li>The string <code>ls</code> is pushed on the stack.</li> + <li>The string <code>"ls"</code> is pushed on the stack.</li> <li>The <code>run</code> symbol is executed, which runs the command <code>ls</code> and pushes quotation on the stack containing three elements: the return code of the program, its standard output, and its standard error.</li> <li>The integer <code>0x1</code> is pushed on the stack.</li> <li>The <code>get</code> symbol is executed, which retrieves the second element of the quotation (the standard output).</li> - <li>The string <code>&bsol;n</code> is pushed on the stack.</li> + <li>The string <code>"&bsol;n"</code> is pushed on the stack.</li> <li>The <code>split</code> symbol is executed, which splits the string using the newline character as a separator.</li> <li>The <code>puts</code> symbol is executed, which prints the quotation on the stack.</li>