all repos — hex @ d0bab75f02a8c195bcc42886dafd41739d197552

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

Merge branch 'master' of github.com:h3rald/hex
h3rald h3rald@h3rald.com
Mon, 02 Dec 2024 15:47:54 +0000
commit

d0bab75f02a8c195bcc42886dafd41739d197552

parent

99f8504ec63be697aeff669530c80f5bd7de5e01

5 files changed, 57 insertions(+), 49 deletions(-)

jump to
M .gitignore.gitignore

@@ -58,3 +58,4 @@ example.hex

web/out/ web/assets/hex.js web/assets/hex.wasm +*.com.dbg
M MakefileMakefile

@@ -8,6 +8,8 @@

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 $@ .PHONY: clean clean:
M build.cmdbuild.cmd

@@ -1,2 +1,3 @@

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

@@ -3,27 +3,31 @@

#ifdef EMSCRIPTEN #include <emscripten.h> -EM_ASYNC_JS(char *, em_fgets, (const char* buf, size_t bufsize), { - return await new Promise((resolve, reject) => { - if (Module.pending_lines.length > 0) { - resolve(Module.pending_lines.shift()); - } else { - Module.pending_fgets.push(resolve); - } - }).then((s) => { - // convert JS string to WASM string - let l = s.length + 1; - if (l >= bufsize) { - // truncate - l = bufsize - 1; - } - Module.stringToUTF8(s.slice(0, l), buf, l); - return buf; - }); +EM_ASYNC_JS(char *, em_fgets, (const char *buf, size_t bufsize), { + return await new Promise((resolve, reject) = > { + if (Module.pending_lines.length > 0) + { + resolve(Module.pending_lines.shift()); + } + else + { + Module.pending_fgets.push(resolve); + } + }) + .then((s) = > { + // convert JS string to WASM string + let l = s.length + 1; + if (l >= bufsize) + { + // truncate + l = bufsize - 1; + } + Module.stringToUTF8(s.slice(0, l), buf, l); + return buf; + }); }); #endif - // Common operations #define POP(ctx, x) hex_item_t x = hex_pop(ctx)

@@ -3846,40 +3850,39 @@ fclose(file);

return content; } -static void do_repl(void *v_ctx) +static void do_repl(void *v_ctx) { - hex_context_t *ctx = (hex_context_t *)v_ctx; - char line[1024]; + hex_context_t *ctx = (hex_context_t *)v_ctx; + char line[1024]; #ifdef EMSCRIPTEN - char *p = line; - p = em_fgets(line, 1024); - if (!p) - { - printf("Error reading output"); - } + char *p = line; + p = em_fgets(line, 1024); + if (!p) + { + printf("Error reading output"); + } #else - printf("> "); // Prompt - if (fgets(line, sizeof(line), stdin) == NULL) - { - printf("\n"); // Handle EOF (Ctrl+D) - return; - } + printf("> "); // Prompt + fflush(stdout); + if (fgets(line, sizeof(line), stdin) == NULL) + { + printf("\n"); // Handle EOF (Ctrl+D) + return; + } #endif - // Normalize line endings (remove trailing \r\n or \n) - line[strcspn(line, "\r\n")] = '\0'; + // Normalize line endings (remove trailing \r\n or \n) + line[strcspn(line, "\r\n")] = '\0'; - // Tokenize and process the input - hex_interpret(ctx, line, "<repl>", 1, 1); - // Print the top item of the stack - if (ctx->stack.top >= 0) - { - hex_print_item(stdout, ctx->stack.entries[ctx->stack.top]); - // hex_print_item(stdout, HEX_STACK[HEX_TOP]); - printf("\n"); - } - return; - - + // Tokenize and process the input + hex_interpret(ctx, line, "<repl>", 1, 1); + // Print the top item of the stack + if (ctx->stack.top >= 0) + { + hex_print_item(stdout, ctx->stack.entries[ctx->stack.top]); + // hex_print_item(stdout, HEX_STACK[HEX_TOP]); + printf("\n"); + } + return; } // REPL implementation

@@ -3903,7 +3906,7 @@ printf(" *\n");

while (1) { - do_repl(ctx); + do_repl(ctx); } #endif }
M web/assets/styles.cssweb/assets/styles.css

@@ -55,7 +55,8 @@ color: limegreen;

} a[href^=http] { - text-decoration-style: dashed; + text-decoration-style: dotted; + text-decoration-thickness: from-font; } strong {