Created get page; improved file reading, updated web generator.
h3rald h3rald@h3rald.com
Thu, 05 Dec 2024 14:45:09 +0100
6 files changed,
101 insertions(+),
17 deletions(-)
M
.gitignore
→
.gitignore
@@ -59,3 +59,5 @@ web/out/
web/assets/hex.js web/assets/hex.wasm *.com.dbg +hex.js +hex.wasm
M
Makefile
→
Makefile
@@ -6,13 +6,19 @@ hex: hex.c
$(CC) $(CFLAGS) $(LDFLAGS) $< -o hex web/assets/hex.wasm: hex.c - emcc -O2 -sASYNCIFY -sEXPORTED_RUNTIME_METHODS=stringToUTF8 hex.c -o web/assets/hex.js --pre-js web/assets/hex-playground.js + emcc -O2 -sASYNCIFY -DBROWSER -sEXPORTED_RUNTIME_METHODS=stringToUTF8 hex.c -o web/assets/hex.js --pre-js web/assets/hex-playground.js + +hex.wasm: hex.c + emcc -O2 -sASYNCIFY -sEXPORTED_RUNTIME_METHODS=stringToUTF8 hex.c -o hex.js ape: hex.c cosmocc $(CFLAGS) $(LDFLAGS) $< -o hex .PHONY: wasm -wasm: web/assets/hex.wasm +wasm: hex.wasm + +.PHONY: playground +playground: web/assets/hex.wasm .PHONY: clean clean:@@ -28,9 +34,9 @@ dtest:
./hex -d test.hex .PHONY: web -web: wasm +web: playground ./hex web.hex .PHONY: dweb -dweb: +dweb: playground ./hex -d web.hex
M
hex.c
→
hex.c
@@ -1,6 +1,6 @@
#include "hex.h" -#ifdef EMSCRIPTEN +#if defined(EMSCRIPTEN) && defined(BROWSER) #include <emscripten.h> EM_ASYNC_JS(char *, em_fgets, (const char *buf, size_t bufsize), {@@ -1243,7 +1243,7 @@ {
char input[HEX_STDIN_BUFFER_SIZE]; // Buffer to store the input (adjust size if needed) char *p = input; -#ifdef EMSCRIPTEN +#if defined(EMSCRIPTEN) && defined(BROWSER) p = em_fgets(input, 1024); #else p = fgets(input, sizeof(input), stdin);@@ -2675,8 +2675,8 @@ result = 1;
} else { - fread(buffer, 1, length, file); - buffer[length] = '\0'; + size_t bytesRead = fread(buffer, 1, length, file); + buffer[bytesRead] = '\0'; result = hex_push_string(ctx, buffer); free(buffer); }@@ -3794,7 +3794,7 @@ {
FILE *file = fopen(filename, "r"); if (file == NULL) { - hex_error(ctx, "Failed to open file"); + hex_error(ctx, "Failed to open file: %s", filename); return NULL; }@@ -3859,7 +3859,7 @@ static void do_repl(void *v_ctx)
{ hex_context_t *ctx = (hex_context_t *)v_ctx; char line[1024]; -#ifdef EMSCRIPTEN +#if defined(EMSCRIPTEN) && defined(BROWSER) char *p = line; p = em_fgets(line, 1024); if (!p)@@ -3893,7 +3893,7 @@
// REPL implementation void hex_repl(hex_context_t *ctx) { -#ifdef __EMSCRIPTEN__ +#if defined(EMSCRIPTEN) && defined(BROWSER) printf(" _*_ _\n"); printf(" / \\hex\\*\n"); printf(" *\\_/_/_/ v%s - WASM Build\n", HEX_VERSION);@@ -4059,7 +4059,7 @@ return 0;
} } } -#ifndef EMSCRIPTEN +#if !(EMSCRIPTEN) && !(BROWSER) if (!isatty(fileno(stdin))) { ctx.settings.stack_trace_enabled = 0;
M
web.hex
→
web.hex
@@ -1,3 +1,5 @@
+"2024" "meta_year" store +"0.1.0" "meta_release" store "web/assets" "d_assets" store "web/templates" "d_templates" store "web/contents" "d_contents" store@@ -11,6 +13,25 @@ d_contents ls i "contents" store
d_assets ls i "assets" store d_templates "/page.html" cat "t_page" store +; Convenience symbol for debugging +(dup puts) "_" store + +; Generate tag placeholder +( + "{{" swap "}}" cat cat +) "tag" store + +; Replace tag +( + "pt_repl" store + "pt_tag" store + "pt_content" store + (pt_content pt_tag tag i index 0x0 >) + (pt_content pt_tag tag i pt_repl replace "pt_content" store) + while + pt_content +) "process-tag" store + "*** Generating hex web site..." puts ; Write contents contents@@ -18,8 +39,12 @@ (
"fn_content" store fn_content ".html" "" replace "id_content" store d_contents "/" fn_content cat cat read "content" store - t_page read "{{content}}" content replace - "{{title}}" id_content replace + t_page read + ; Replace tags + "content" content process-tag i + "title" id_content process-tag i + "release" meta_release process-tag i + "year" meta_year process-tag i "new_content" store (fn_content "home.html" ==) (d_out "/index.html" cat "dst_file" store)
M
web/assets/styles.css
→
web/assets/styles.css
@@ -113,6 +113,7 @@ }
pre { margin: 1rem; + white-space: pre-wrap; } code {
M
web/contents/get.html
→
web/contents/get.html
@@ -1,7 +1,57 @@
<article> <h2>Get Started</h2> - <blockquote> - Under construction. - </blockquote> + <p>At present there are no pre-build binaries available for download, because hex has not been officially released + yet. However, when it is, the following pre-built binaries will be available from download:</p> + <ul> + <li>hex v{{release}} for Windows (x86_64)</li> + <li>hex v{{release}} for Linux (x86_64)</li> + <li>hex v{{release}} for MacOS (ARM64)</li> + <li>hex v{{release}} (<a href="https://justine.lol/ape.html" target="_blank">αcτµαlly pδrταblε εxεcµταblε</a>) + </li> + <li>hex v{{release}} (<a href="https://webassembly.org" target="_blank">WebAssembly</a>)</li> + </ul> + + <h3>Building from Source</h3> + + <p>Building from source is easy: just run <code>make</code> after cloning the repo to build the hex executable for + your platform.</p> + <p>This assumes that you have a C compiler like GCC and the make command installed. On Windows, you may want to look + into <a href="https://www.msys2.org" target="_blank">MSYS2</a>.</p> + <p>You can also:</p> + <ul> + <li>Run <code>make test</code> to run the test suite.</li> + <li>Run <code>make ape</code> to generate an αcτµαlly pδrταblε εxεcµταblε (requires <a + href="https://github.com/jart/cosmopolitan" target="_blank">Cosmopolitan</a>). </li> + <li>Run <code>make wasm</code> to generate a <code>hex.js</code> and a <code>hex.wasm</code> (WebAssembly) file + (you can run it using NodeJS via <code>node hex.js</code>) </li> + </ul> + + <h3>Command line options</h3> + + <p>Running <code>hex -h</code> will print the following list of all the available command line options for the hex + executable:</p> + + <pre> + _*_ _ + / \hex\* + *\_/_/_/ v{{release}} - A minimalist, concatenative programming language. + * (c) {{year}} Fabio Cevasco + + USAGE + hex [options] [file] + + ARGUMENTS + file A .hex file to interpret + + OPTIONS + -d, --debug Enable debug mode. + -h, --help Display this help message. + -m --manual Display the manual. + -v, --version Display hex version. + </pre> + + <p>If you do not specify any option or argument, a simple <abbr title="Read-Eval-Print-Loop">REPL</abbr> will be + started.</p> + </article>