~fd/cane-lang

7dca962578ce5288cb58624b521f881e0c1faf8c — Ersei Saggi 10 months ago cbacbd4
Web-ready!
3 files changed, 54 insertions(+), 5 deletions(-)

M README.md
M cane-wasm/index.html
M shell.nix
M README.md => README.md +10 -1
@@ 6,6 6,7 @@ A funky programming language made in 24(ish) hours
- [Mailing List](https://lists.sr.ht/~fd/public-inbox)
- [Source](https://git.sr.ht/~fd/cane-lang)
- [Blog Post](https://ersei.net/blog/diy-programming-language)
- [Web Playground](https://fd.srht.site)

## Examples!



@@ 86,7 87,15 @@ $ cargo build --release
$ target/release/cane FILE
```

Requires Windows 8.1 or higher if compiling there (because of the sole library requiring a recent version of MSVC).
### WASM Version

Go into the `cane-wasm` directory and run:

```
wasm-pack build --target web
```

Open the `index.html` file in your favourite browser.

## Spec


M cane-wasm/index.html => cane-wasm/index.html +43 -3
@@ 2,12 2,49 @@
<html lang="en-US">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Cane Lang Web Playground</title>
    <style>
      pre {
        background: black;
        color: white;
        padding: 10px;
        overflow: scroll;
      }
      #code_input,
      #args_input {
        width: 100%;
        -webkit-box-sizing: border-box;
        -moz-box-sizing: border-box;
        box-sizing: border-box;
      }
      textarea {
        font-family: monospace;
      }
      button {
        padding-left: 10px;
        padding-top: 5px;
        padding-right: 10px;
        padding-bottom: 5px;
      }
      body {
        font-family: sans-serif;
      }
    </style>
  </head>
  <body>
    <textarea placeholder="Code" id="code_input" rows="5">
([(`hello, world!\n' print)] 5 repeat)

(args `-' join print)</textarea
    >
    <textarea id="args_input" placeholder="Space-separated arguments" rows="1">
arg1 arg2 arg3 (space separated)</textarea
    >
    <button id="run">Run</button>
    <textarea id="code_input">([(`hello, world!\n' print)] 5 repeat)</textarea>
    <pre id="output"></pre>
    <a href="https://sr.ht/~fd/cane-lang">Homepage</a>
    <a href="https://git.sr.ht/~fd/cane-lang/tree/main/item/demos">Demos</a>
    <pre id="output">Output</pre>
    <script type="module">
      import init, { interpreter } from './pkg/cane_wasm.js'
      window.writeOut = function writeOut(text) {


@@ 17,7 54,10 @@
      document.getElementById('run').onclick = function () {
        document.getElementById('output').innerText = ''
        init().then(() => {
          interpreter(document.getElementById('code_input').value, '')
          interpreter(
            document.getElementById('code_input').value,
            document.getElementById('args_input').value
          )
        })
      }
    </script>

M shell.nix => shell.nix +1 -1
@@ 1,5 1,5 @@
let
  pkgs = import (fetchTarball("channel:nixpkgs-unstable")) {};
in pkgs.mkShell {
  buildInputs = [ pkgs.rustfmt pkgs.rust-analyzer pkgs.wasm-pack pkgs.rustup pkgs.pkg-config pkgs.openssl ];
  buildInputs = [ pkgs.rustfmt pkgs.rust-analyzer pkgs.wasm-pack pkgs.rustup pkgs.pkg-config pkgs.openssl pkgs.binaryen ];
}