use otmp
use http
use http.server {Req :: Request, Res :: Response, route}
+use json
#inject runtime.vars {
Enable_Heap_Debug :: true
@route.{.GET, "/news"}
(req: &Req, res: &Res) {
- articles := make([..] str);
+ Article :: struct { name, description, path, date: str }
+ articles := make([..] Article);
+
+ article_file := os.get_contents("www/news-articles/index.json");
+ article_index, json_err := json.decode_with_error(article_file);
+ if json_err->has_error() {
+ res->status(500);
+ return;
+ }
- for os.list_directory("www/news-articles") {
- name := it->name();
- if string.ends_with(name, ".html") {
- articles << string.temp_copy(name[0 .. name.length-5]);
- }
+ for article_index.root->as_array() {
+ name := it["name"]->as_str();
+ desc := it["description"]->as_str();
+ path := it["path"]->as_str();
+ date := it["date"]->as_str();
+ articles << .{ name, desc, path, date };
}
res->render("pages/news", &.{
--- /dev/null
+[
+ {
+ "name": "Onyx's Custom Runtime",
+ "path": "ovmwasm",
+ "date": "5th April 2023",
+ "description": "Something about a brief introduction to the OVM-Wasm system."
+ }
+]
-<div class="container">
- <h1>Onyx's Custom Runtime</h1>
+<h1>Onyx's Custom Runtime</h1>
- <p>
- As Onyx targets WebAssembly (WASM) exclusively, running code outside of the browser requires a <a href="https://webassembly.github.io/spec/core/appendix/embedding.html">WASM embedder</a>.
- The job of the embedder is to translate the WASM Virtual Instruction Set Architecture into a "real" architecture that can be executed on the host system.
- There are many great WASM embedders that exist for running WASM outside the browser. Here's a small, non-comprehensive list:
- </p>
- <ul>
- <li><a href="https://wasmer.io">Wasmer</a></li>
- <li><a href="https://wasmtime.dev">Wasmtime</a></li>
- <li><a href="https://github.com/wasm3/wasm3">Wasm3</a></li>
- <li><a href="https://wasmedge.org">WasmEdge</a></li>
- </ul>
+<p>
+ As Onyx targets WebAssembly (WASM) exclusively, running code outside of the browser requires a <a href="https://webassembly.github.io/spec/core/appendix/embedding.html">WASM embedder</a>.
+ The job of the embedder is to translate the WASM Virtual Instruction Set Architecture into a "real" architecture that can be executed on the host system.
+ There are many great WASM embedders that exist for running WASM outside the browser. Here's a small, non-comprehensive list:
+</p>
+<ul>
+ <li><a href="https://wasmer.io">Wasmer</a></li>
+ <li><a href="https://wasmtime.dev">Wasmtime</a></li>
+ <li><a href="https://github.com/wasm3/wasm3">Wasm3</a></li>
+ <li><a href="https://wasmedge.org">WasmEdge</a></li>
+</ul>
- <p>
- All of these embedders are great in their own way, but the one thing they are not <em>great</em> at is providing a great developer experience for Onyx. For this reason, Onyx maintains support for two WASM embedders: <em>Wasmer</em> and <em>OVM-Wasm</em>. Wasmer is used as the faster, production-ready embedder, while OVM-Wasm is used as the development embedder.
- </p>
+<p>
+All of these embedders are great in their own way, but the one thing they are not <em>great</em> at is providing a great developer experience for Onyx. For this reason, Onyx maintains support for two WASM embedders: <em>Wasmer</em> and <em>OVM-Wasm</em>. Wasmer is used as the faster, production-ready embedder, while OVM-Wasm is used as the development embedder.
+</p>
- <p>
- OVM-Wasm stands for <em>Onyx Virtual Machine for WASM</em>. The Onyx Virtual Machine (OVM) started as a separate project with the goal of providing a separate compile-target for Onyx; however, to reduce complexity, OVM-Wasm was created as a wrapper around OVM, that provides a <a href="https://github.com/WebAssembly/wasm-c-api">wasm-c-api</a> compatible interface, making it a WASM embedder.
- Since OVM-Wasm is entirely specific to Onyx and can be easily modified to suit the needs of developing Onyx.
- It has more features compared to a normal WASM embedder, such a <em>debugging interface</em> that is compatible with the Debug Adapter Protocol.
- </p>
-
- <p>
- Currently, it does not run as fast as it could.
- This is due to several reason, but largely because it simply compiles WebAssembly down to an <em>interpreted</em> instruction stream, not machine-native instructions.
- This was done to make OVM-Wasm more portable, but does come at a significant performance cost.
- To compound onto this fact, the instruction stream itself is not optimized <em>at all</em>.
- It is the most literal, WASM to OVM conversion possible.
- This helps make the initial startup time faster, but does incur wasted performance.
- It is on the (rather large) list of to-dos to add simple optimizations to the embedding process to make OVM-Wasm not <em>horribly</em> slow.
- </p>
-</div>
+<p>
+OVM-Wasm stands for <em>Onyx Virtual Machine for WASM</em>. The Onyx Virtual Machine (OVM) started as a separate project with the goal of providing a separate compile-target for Onyx; however, to reduce complexity, OVM-Wasm was created as a wrapper around OVM, that provides a <a href="https://github.com/WebAssembly/wasm-c-api">wasm-c-api</a> compatible interface, making it a WASM embedder.
+Since OVM-Wasm is entirely specific to Onyx and can be easily modified to suit the needs of developing Onyx.
+It has more features compared to a normal WASM embedder, such a <em>debugging interface</em> that is compatible with the Debug Adapter Protocol.
+</p>
+
+<p>
+Currently, it does not run as fast as it could.
+This is due to several reasons, but largely because it compiles WebAssembly down to an <em>interpreted</em> instruction stream, not machine-native instructions.
+This was done to make OVM-Wasm more portable, but does come at a significant performance cost.
+To compound onto this fact, the instruction stream itself is not optimized <em>at all</em>.
+It is the most literal, WASM to OVM conversion possible.
+This helps the initial startup time be faster, but does incur wasted performance.
+It is on the (rather large) list of to-dos to add simple optimizations to the embedding process to make OVM-Wasm not <em>as</em> slow.
+</p>
--dark-background-color: #111;
--active-color: #555;
--link-color: #bbf;
+ --visited-link-color: #bfbfff;
--foreground-color: #fff;
}
}
--light-background-color: #e0e0e0;
--dark-background-color: #c0c0c0;
--active-color: #cccccc;
- --link-color: #224;
+ --link-color: #448;
+ --visited-link-color: #669;
--foreground-color: #000000;
}
}
a {
color: var(--link-color);
+ text-decoration: none;
+}
+
+a.link-button {
+ padding: 8px;
+ text-decoration: none;
+ background-color: var(--light-background-color);
+ transition: all 300ms;
+}
+
+a.link-button:hover {
+ background-color: var(--active-color);
+ cursor: pointer;
}
a:visited {
- color: #88f;
+ color: var(--visited-link-color);
}
.container {
- padding: 56px 12px;
+ padding: 48px 12px;
}
.container > .container.merge {
margin-top: 20px;
}
-.container ul {
+.container ul, .container ol {
padding-left: 20px;
}
h1 {
min-width: 100px;
font-size: 36pt;
- font-weight: lighter;
+}
+
+h1, h2, h3, h4, h5, h6 {
+ font-weight: 200;
}
.container h3 {
grid-template-rows: auto 1fr auto;
}
+main pre {
+ border: 1px solid var(--terminal-background-color);
+ box-shadow: 0px 1px 10px 1px rgba(0, 0, 0, 0.2);
+ padding: 8px;
+ display: block;
+}
+
+main li {
+ margin-top: 8px;
+}
-/*
- * Visual Studio 2015 dark style
- * Author: Nicolas LLOBERA <nllobera@gmail.com>
- */
-
-.hljs {
- background: #1E1E1E;
- color: #DCDCDC;
-}
-
-.hljs-keyword,
-.hljs-literal,
-.hljs-symbol,
-.hljs-name {
- color: #569CD6;
-}
-.hljs-link {
- color: #569CD6;
- text-decoration: underline;
-}
-
-.hljs-built_in,
-.hljs-type {
- color: #4EC9B0;
-}
-
-.hljs-number,
-.hljs-class {
- color: #B8D7A3;
-}
-
-.hljs-string,
-.hljs-meta .hljs-string {
- color: #D69D85;
-}
-
-.hljs-regexp,
-.hljs-template-tag {
- color: #9A5334;
-}
-
-.hljs-subst,
-.hljs-function,
-.hljs-title,
-.hljs-params,
-.hljs-formula {
- color: #DCDCDC;
-}
-
-.hljs-comment,
-.hljs-quote {
- color: #57A64A;
- font-style: italic;
-}
-
-.hljs-doctag {
- color: #608B4E;
-}
-
-.hljs-meta,
-.hljs-meta .hljs-keyword,
-
-.hljs-tag {
- color: #9B9B9B;
-}
-
-.hljs-variable,
-.hljs-template-variable {
- color: #BD63C5;
-}
-
-.hljs-attr,
-.hljs-attribute {
- color: #9CDCFE;
-}
-
-.hljs-section {
- color: gold;
-}
-
-.hljs-emphasis {
- font-style: italic;
-}
-
-.hljs-strong {
- font-weight: bold;
-}
-
-/*.hljs-code {
- font-family:'Monospace';
-}*/
-
-.hljs-bullet,
-.hljs-selector-tag,
-.hljs-selector-id,
-.hljs-selector-class,
-.hljs-selector-attr,
-.hljs-selector-pseudo {
- color: #D7BA7D;
-}
-
-.hljs-addition {
- background-color: #144212;
- display: inline-block;
- width: 100%;
-}
-
-.hljs-deletion {
- background-color: #600;
- display: inline-block;
- width: 100%;
+@media (prefers-color-scheme: light) {
+ /*
+ Visual Studio-like style based on original C# coloring by Jason Diamond <jason@diamond.name>
+ */
+ .hljs {
+ background: white;
+ color: black;
+ }
+
+ .hljs-comment,
+ .hljs-quote,
+ .hljs-variable {
+ color: #008000;
+ }
+
+ .hljs-keyword,
+ .hljs-selector-tag,
+ .hljs-built_in,
+ .hljs-name,
+ .hljs-tag {
+ color: #00f;
+ }
+
+ .hljs-string,
+ .hljs-title,
+ .hljs-section,
+ .hljs-attribute,
+ .hljs-literal,
+ .hljs-template-tag,
+ .hljs-template-variable,
+ .hljs-type,
+ .hljs-addition {
+ color: #a31515;
+ }
+
+ .hljs-deletion,
+ .hljs-selector-attr,
+ .hljs-selector-pseudo,
+ .hljs-meta {
+ color: #2b91af;
+ }
+
+ .hljs-doctag {
+ color: #808080;
+ }
+
+ .hljs-attr {
+ color: #f00;
+ }
+
+ .hljs-symbol,
+ .hljs-bullet,
+ .hljs-link {
+ color: #00b0e8;
+ }
+
+
+ .hljs-emphasis {
+ font-style: italic;
+ }
+
+ .hljs-strong {
+ font-weight: bold;
+ }
+}
+
+@media (prefers-color-scheme: dark) {
+ /*
+ * Visual Studio 2015 dark style
+ * Author: Nicolas LLOBERA <nllobera@gmail.com>
+ */
+
+ .hljs {
+ background: #1E1E1E;
+ color: #DCDCDC;
+ }
+
+ .hljs-keyword,
+ .hljs-literal,
+ .hljs-symbol,
+ .hljs-name {
+ color: #569CD6;
+ }
+ .hljs-link {
+ color: #569CD6;
+ text-decoration: underline;
+ }
+
+ .hljs-built_in,
+ .hljs-type {
+ color: #4EC9B0;
+ }
+
+ .hljs-number,
+ .hljs-class {
+ color: #B8D7A3;
+ }
+
+ .hljs-string,
+ .hljs-meta .hljs-string {
+ color: #D69D85;
+ }
+
+ .hljs-regexp,
+ .hljs-template-tag {
+ color: #9A5334;
+ }
+
+ .hljs-subst,
+ .hljs-function,
+ .hljs-title,
+ .hljs-params,
+ .hljs-formula {
+ color: #DCDCDC;
+ }
+
+ .hljs-comment,
+ .hljs-quote {
+ color: #57A64A;
+ font-style: italic;
+ }
+
+ .hljs-doctag {
+ color: #608B4E;
+ }
+
+ .hljs-meta,
+ .hljs-meta .hljs-keyword,
+
+ .hljs-tag {
+ color: #9B9B9B;
+ }
+
+ .hljs-variable,
+ .hljs-template-variable {
+ color: #BD63C5;
+ }
+
+ .hljs-attr,
+ .hljs-attribute {
+ color: #9CDCFE;
+ }
+
+ .hljs-section {
+ color: gold;
+ }
+
+ .hljs-emphasis {
+ font-style: italic;
+ }
+
+ .hljs-strong {
+ font-weight: bold;
+ }
+
+ /*.hljs-code {
+ font-family:'Monospace';
+ }*/
+
+ .hljs-bullet,
+ .hljs-selector-tag,
+ .hljs-selector-id,
+ .hljs-selector-class,
+ .hljs-selector-attr,
+ .hljs-selector-pseudo {
+ color: #D7BA7D;
+ }
+
+ .hljs-addition {
+ background-color: #144212;
+ display: inline-block;
+ width: 100%;
+ }
+
+ .hljs-deletion {
+ background-color: #600;
+ display: inline-block;
+ width: 100%;
+ }
}
<div class="container">
<h1>Onyx Docs</h1>
+</div>
+
+<div class="container">
+ <h2>Getting Started</h2>
+ <p>
+ Install Onyx locally on your system, or use it in your browser.
+ </p>
+ <p>
+ <a class="link-button"href="/docs/install">Install</a>
+ <a class="link-button" href="/playground/">Playground</a>
+ </p>
+</div>
- <ul>
- <li><a href="/docs/install">Installation</a></li>
- <li>Getting Started</li>
- <li>Language Reference Book</li>
- <li>Packages</li>
- <ul>
- <li><a href="https://docs.onyxlang.io/packages/core">Core packages</a></li>
- </ul>
- </ul>
-
+<div class="container">
+ <h2>Language Reference</h2>
+ <p>
+ Read about the features of Onyx.
+ </p>
+ <p>
+ <a class="link-button" href="https://docs.onyxlang.io/book">Language Book</a>
+ </p>
+</div>
+
+<div class="container">
+ <h2>Package Reference</h2>
+ <p>
+ Reference material for all packages shipped with the Onyx toolchain.
+ </p>
+ <p>
+ <a class="link-button" href="https://docs.onyxlang.io/packages/core">Core packages</a>
+ </p>
</div>
{{endblock}}
<div class="container">
<h1>Installing Onyx</h1>
<p>
- <a href="#online">Online</a>
- <a href="#linux">Linux</a>
- <a href="#windows">Windows</a>
- <a href="#macos">MacOS</a>
+ <a class="link-button" href="#online">Online</a>
+ <a class="link-button" href="#linux">Linux</a>
+ <a class="link-button" href="#windows">Windows</a>
+ <a class="link-button" href="#macos">MacOS</a>
</p>
</div>
<div class="container" id="linux">
<h2>Linux</h2>
- <p>
- </p>
+ <div>
+ <h3>From Source</h3>
+ <p>
+ The easiest way to install Onyx on a Linux system is to clone the repository from GitHub, and then compile from source.
+ This is relatively simple, since Onyx does not use any fancy things in its source tree. Only C code and shell scripts.
+
+ <ol>
+ <li>
+ Clone the respository at <a href="https://github.com/onyx-lang/onyx">onyx-lang/onyx</a>.
+ <pre class="hljs"><code class="language-sh">git clone https://github.com/onyx-lang/onyx --depth 1</code></pre>
+ </li>
+ <li>
+ Navigate into the new "onyx" directory.
+ <pre class="hljs"><code class="language-sh">cd onyx</code></pre>
+ </li>
+ <li>
+ Configure the <code>settings.sh</code> file to suit your system needs.
+ If everything looks good, (or if you don't know what you are looking at), you should be good to go.
+ </li>
+ <li>
+ Run <code>./build.sh</code>.
+ This will compile and install Onyx onto your system.
+ By default, the "onyx" binary will be placed in "/usr/bin", and the necessary libraries/core packages/tooling will be installed at "/usr/share/onyx".
+ </li>
+ <li>
+ Try running the "onyx help" command. You should see something like this.
+ <pre class="hljs"><code class="language-sh">$ onyx help
+Onyx toolchain version v0.1.0
+
+The toolchain for the Onyx programming language, created by Brendan Hansen.
+
+Usage:
+ onyx <subcommand>
+
+Subcommands:
+ help Shows this help message. Use "onyx help <subcommand>".
+ build Compiles an Onyx program into an executable.
+ run Compiles and runs an Onyx program, all at once.
+ check Checks syntax and types of an Onyx program.
+ package Package manager</code></pre>
+ </li>
+ </ol>
+ </p>
+
+ <h3>Future Plans</h3>
+ <p>
+ In the future, Onyx may ship a ".deb" file for Debian-based distros to easily install.
+ While this is planned, it is not a priority at the moment.
+ </p>
+ </div>
</div>
-<div class="container" id="windows">
+<div class="container light" id="windows">
<h2>Windows</h2>
<p>
+ <ol>
+ <li>Download the latest Windows release folder from the <a>Releases</a> on GitHub.</li>
+ <li>Extract the zip file to a permanent location.</li>
+ <li>Modify system environment variables.</li>
+ <ul>
+ <li>Add the extracted folder to your system or user's PATH variable.</li>
+ <li>Make a new variable called "ONYX_PATH", and set it equal to the extracted folder path.</li>
+ </ul>
+ <li>Log out and log back in to let system environment variable update.</li>
+ <li>Open a Command Prompt or Powershell instance, and try running "onyx help".</li>
+ </ol>
</p>
</div>
</ul>
</div>
- <pre class="hljs" style="overflow-y: scroll; width: 40%; border: 2px solid black; padding: 8px; display: block"><code class="language-onyx">use core {println}
+ <pre class="hljs" style="overflow-y: scroll; width: 40%;"><code class="language-onyx">use core {println}
main :: () {
f := factorial(10);
<div class="container">
<h1>News</h1>
+</div>
- <ul>
- {{ foreach $article in $articles }}
- <li>
- <a href="/news/{% $article %}">{% $article %}</a>
- </li>
- {{ endforeach }}
- </ul>
+{{ foreach $article in $articles }}
+<div class="container">
+ <h2><a href="/news/{% $article.path %}">{% $article.name %}</a></h2>
+ <p><em>{% $article.date %}</em></p>
+ <p>
+ {% $article.description %}
+ </p>
</div>
+{{ endforeach }}
{{endblock}}