all repos — hex @ 04cc717deed6c3078e2035d92b7225d0718d5037

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

Merge branch 'master' of github.com:h3rald/hex
h3rald h3rald@h3rald.com
Thu, 05 Dec 2024 14:02:02 +0000
commit

04cc717deed6c3078e2035d92b7225d0718d5037

parent

0f8cdd87fa98b10f6b45f5d3b5c5a66a4e117a6d

7 files changed, 231 insertions(+), 17 deletions(-)

jump to
A .github/workflows/release.yml

@@ -0,0 +1,129 @@

+name: Release + +# Controls when the action will run. +on: + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + release: + name: "Build and upload artifacts" + runs-on: ${{ matrix.os }} + permissions: + contents: write + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + - macos-13 + steps: + # Cancel other actions of the same type that might be already running + - name: "Cancel similar actions in progress" + uses: styfle/cancel-workflow-action@0.9.1 + with: + access_token: ${{ github.token }} + + # Detects OS and provide Nim-friendly OS identifiers + - name: Detect current OS + id: os + run: echo "os=${{matrix.os == 'ubuntu-latest' && 'linux' || matrix.os == 'macos-latest' && 'macos' || matrix.os == 'macos-13' && 'macos' || matrix.os == 'windows-latest' && 'windows'}}" >> $GITHUB_OUTPUT + + # Checks out the repository + - uses: actions/checkout@v2 + + # Install cosmocc + - name: Install cosmocc + run: | + mkdir -p $HOME/cosmocc + cd $HOME/cosmocc + wget -q https://cosmo.zip/pub/cosmocc/cosmocc.zip + unzip -q cosmocc.zip + pwd + ls -l + if: matrix.os == 'ubuntu-latest' + + # Setup emsdk + - name: Setup emsdk + uses: mymindstorm/setup-emsdk@v14 + if: matrix.os == 'ubuntu-latest' + + # Retrieve ID and Name of the current (draft) release + - name: "Get current release" + id: current-release + uses: InsonusK/get-latest-release@v1.0.1 + with: + myToken: ${{ github.token }} + exclude_types: "release" + view_top: 1 + + # Build (non-Windows) + - name: Build + run: make + if: matrix.os != 'windows-latest' + + # Package the resulting Linux/macOS binary + - name: Create artifact (Linux, macOS) + run: zip hex_${{steps.current-release.outputs.tag_name}}_${{steps.os.outputs.os}}_x86_64.zip hex + if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-13' + + # Package the resulting macOs latest binary + - name: Create artifact (Linux, macOS) + run: zip hex_${{steps.current-release.outputs.tag_name}}_${{steps.os.outputs.os}}_arm64.zip hex + if: matrix.os == 'macos-latest' + + # Generate WASM binary + - name: Generate WASM binary + run: emcc -O2 -sASYNCIFY -sEXPORTED_RUNTIME_METHODS=stringToUTF8 hex.c -o hex.js + if: matrix.os == 'ubuntu-latest' + + # Package the resulting WASM binary + - name: Create artifact (Linux - WASM) + run: zip hex_${{steps.current-release.outputs.tag_name}}_wasm.zip hex.wasm hex.js + if: matrix.os == 'ubuntu-latest' + + # Add cosmocc to PATH + see https://redbean.dev/#install + - name: Add cosmocc to PATH + run: | + echo $HOME/cosmocc/bin >> $GITHUB_PATH + sudo wget -O /usr/bin/ape https://cosmo.zip/pub/cosmos/bin/ape-$(uname -m).elf + sudo chmod +x /usr/bin/ape + sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" + sudo sh -c "echo ':APE-jart:M::jartsr::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" + if: matrix.os == 'ubuntu-latest' + + # Generate APE binary + - name: Generate APE binary + run: | + mv hex hex.native + make ape + if: matrix.os == 'ubuntu-latest' + + # Package the resulting APE binary + - name: Create artifact (Linux - APE) + run: zip hex_${{steps.current-release.outputs.tag_name}}_ape.zip hex + if: matrix.os == 'ubuntu-latest' + + # Build (Windows) + - name: Build + run: make + shell: bash + if: matrix.os == 'windows-latest' + + # Package the resulting Windows binary + - name: Create artifact (Windows) + run: Compress-Archive -Path hex.exe -DestinationPath hex_${{steps.current-release.outputs.tag_name}}_windows_x86_64.zip + if: matrix.os == 'windows-latest' + + # Upload artifacts to current draft release + - name: "Upload to current release" + uses: xresloader/upload-to-github-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + file: "hex_v*.zip" + overwrite: true + tag_name: ${{steps.current-release.outputs.tag_name}} + release_id: ${{steps.current-release.outputs.id }} + verbose: true
M .gitignore.gitignore

@@ -59,3 +59,5 @@ web/out/

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

@@ -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 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:

@@ -27,9 +33,9 @@ dtest:

./hex -d test.hex .PHONY: web -web: wasm +web: playground ./hex web.hex .PHONY: dweb -dweb: wasm +dweb: playground ./hex -d web.hex
M hex.chex.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.hexweb.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.cssweb/assets/styles.css

@@ -20,6 +20,7 @@ h3 {

margin: 1rem 0 0.5rem 0; font-size: 1rem; font-weight: 700; + color: gold; } header {

@@ -113,6 +114,7 @@ }

pre { margin: 1rem; + white-space: pre-wrap; } code {
M web/contents/get.htmlweb/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. + </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>