all repos — hex @ bf132c89d800c4ad4a435aeaef5656e72f6a6971

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

Improvements.
h3rald h3rald@h3rald.com
Mon, 02 Dec 2024 15:01:30 +0100
commit

bf132c89d800c4ad4a435aeaef5656e72f6a6971

parent

571ea9b94d25f00f9204b79acf69ebb59b9f90e4

M MakefileMakefile

@@ -1,4 +1,3 @@

-# Default Compiler and Flags CC ?= gcc CFLAGS ?= -Wall -Wextra -g LDFLAGS ?=

@@ -13,6 +12,7 @@

.PHONY: clean clean: rm hex + rm -r web/out/ .PHONY: test test:
M web.hexweb.hex

@@ -36,6 +36,9 @@ assets

( "fn_asset" store (d_out "assets" fn_asset) () map "/" join "dst_file" store + (fn_asset "robots.txt" ==) + ((d_out fn_asset) () map "/" join "dst_file" store) + when (d_assets fn_asset) () map "/" join "src_file" store " - Writing: " dst_file cat puts ("cp" src_file dst_file) () map " " join exec
A web/assets/robots.txt

@@ -0,0 +1,2 @@

+User-agent: * +Disallow:
M web/assets/styles.cssweb/assets/styles.css

@@ -31,7 +31,12 @@ header h1 {

display: inline; font-size: 100%; font-weight: 400; + text-decoration: none; margin: 0; +} + +header h1 a { + text-decoration: none; } footer {

@@ -66,18 +71,17 @@ margin: 0.5rem 0;

} .prompt-wrapper { - whitespace: nowrap; - color: lime; + white-space: nowrap; + color: lime; } - -article > section { +article>section { display: flex; flex-direction: column; border: 1px solid lime; } -article > section > section { +article>section>section { height: 30vh; white-space: pre-wrap; overflow-y: scroll;

@@ -105,3 +109,13 @@

article input:focus { outline: none; } + +pre { + margin: 1rem; +} + +code { + color: gold; +} + +pre code {}
M web/contents/home.htmlweb/contents/home.html

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

<article> - <h2>Welcome</h2> - <p>Welcome to the <strong>hex</strong> programming language.</p> - <p><strong>hex</strong> is a tiny minimalist, concatenative, stack-based and slightly-esoteric programming language + <h2>Welcome to the <em>hex</em> programming language</h2> + <p><strong>hex</strong> is a tiny, minimalist, concatenative, stack-based and slightly-esoteric programming language that can run on many platforms (including <a href="/play">the browser</a>) and can be used as an embedded language, to create shell scripts, or simply to learn more about concatenative programming.</p> - <p>Its syntax is heavily inspired by the <a href="https://min-lang.org">min</a> programming language, and features + <p>Its syntax is heavily inspired by the <a href="https://min-lang.org" target="_blank">min</a> programming + language, and features space-separated tokens, no unnecessary punctuation characters, and round brackets to delimit lists.</p> <h2>Features</h2> <ul> <li>Support <strong>32bit integers</strong>, <em>written only in hexadecimal format</em>, both positive and - negative (represented via <a href="https://en.wikipedia.org/wiki/Two%27s_complement">two's complement</a>), + negative (represented via <a href="https://en.wikipedia.org/wiki/Two%27s_complement" target="_blank">two's + complement</a>), <strong>strings</strong>, and <strong>quotations</strong> (lists). </li> <li><strong>64 native symbols</strong> implementing simple arithmetic, boolean logic, bitwise operations,

@@ -19,9 +20,30 @@ manipulate the stack.</li>

<li>Fully <strong>homoiconic</strong> (everything is data).</li> <li>Includes a simple <strong>REPL</strong>.</li> <li>Includes an integrated <strong>help system</strong>.</li> - <li>Implemented as <strong>a single <a href="https://github.com/h3rald/hex/blob/master/hex.c">.c file</a> and a - single <a href="https://github.com/h3rald/hex/blob/master/hex.h">.h file</a></strong>, making it easier + <li>Implemented as <strong>a single <a href="https://github.com/h3rald/hex/blob/master/hex.c" target="_blank">.c + file</a> and a + single <a href="https://github.com/h3rald/hex/blob/master/hex.h" target="_blank">.h file</a></strong>, + making it easier to embed in other programs and port to different platforms.</li> + </ul> + <h2>Example</h2> + <p> The following code executes the <em>ls</em> command, retrieves the files returned in standard output, and stores + them + 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 <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 <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> </ul> </article>
M web/contents/play.htmlweb/contents/play.html

@@ -1,12 +1,16 @@

<article> - <h2>Playground</h2> - <p>You can use the REPL below to try out hex directly in your browser. This is the <em>actual</em> hex REPL, compiled to <a href="https://webassembly.org">WebAssembly</a>.</p> - <section> - <section></section> - <aside> - <span>&gt;&nbsp;</span> - <input type="text" autofocus /> - </aside> - </section> + <h2>Playground</h2> + <p>You can use the REPL below to try out hex directly in your browser. This is the <em>actual</em> hex REPL, compiled + to <a href="https://webassembly.org">WebAssembly</a>.</p> + <p>For example, try entering the following code, which pushes the quotation <code>(0x1 0x8 0x1b)</code> on the stack: + </p> + <pre><code>(0x1 0x2 0x3) (dup dup * *) map</code></pre> + <section> + <section></section> + <aside> + <span>&gt;&nbsp;</span> + <input type="text" autofocus /> + </aside> + </section> </article> <script src="/assets/hex.js"></script>
M web/templates/page.htmlweb/templates/page.html

@@ -1,33 +1,37 @@

<!DOCTYPE html> <html lang="en"> - <head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0"> - <title>hex programming language</title> - <link rel="stylesheet" href="/assets/styles.css"> - </head> +<head> + <title>hex programming language</title> + <meta charset="UTF-8"> + <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1,user-scalable=0"> + <meta name="author" content="Fabio Cevasco"> + <meta name="description" content="A tiny, minimalist, concatenative, stack-based and slightly-esoteric programming language + that can run on many platforms."> + <link rel="stylesheet" href="/assets/styles.css"> + <link rel="icon" type="image/png" href="/assets/favicon.png"> +</head> - <body> - <header> +<body> + <header> <pre> _*_ _ / \<h1><a href="/">hex</a></h1>\* programming language *\_/_/_/ * </pre> - </header> - <nav> - <a href="/get-started">Get Started</a> | + </header> + <nav> + <a href="/get">Get Started</a> | <a href="/manual">Manual</a> | <a href="/play">Play</a> | <a href="/changelog">Changelog</a> | <a href="/about">About</a> - </nav> - {{content}} - <footer> + </nav> + {{content}} + <footer> &copy; 2024 Fabio Cevasco - </footer> - </body> + </footer> +</body> </html>