From ac39b15e169cd1582d1a4d8e2de23b6efcb070fc Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sat, 9 Jan 2021 15:36:14 -0800 Subject: [PATCH] Make more languages work --- backend/sandbox.bash | 40 ++++++++++++++++++++------ docker/packaging/install.bash | 2 ++ langs/beatnik.yaml | 18 ++++++------ langs/befunge.yaml | 52 +++++++++++++++++----------------- langs/blc.yaml | 25 ++++++++++++++++ langs/boo.yaml | 13 +++++++++ langs/brainf.yaml | 34 ++++++++++++++++++++-- langs/cat.yaml | 31 ++++++++++++++++++-- tools/generate-build-script.js | 39 +++++++++++++++++++++++-- 9 files changed, 204 insertions(+), 50 deletions(-) diff --git a/backend/sandbox.bash b/backend/sandbox.bash index 31f96ff..b80caef 100644 --- a/backend/sandbox.bash +++ b/backend/sandbox.bash @@ -20,15 +20,24 @@ function riju-exec { } function daemon { - has daemon && riju-exec "$(get daemon)" + if has daemon; then + echo "$(get daemon)" + riju-exec "$(get daemon)" + fi } function setup { - has setup && riju-exec "$(get setup)" + if has setup; then + echo "$(get setup)" + riju-exec "$(get setup)" + fi } function repl { - has repl && riju-exec "$(get repl)" + if has repl; then + echo "$(get repl)" + riju-exec "$(get repl)" + fi } function main { @@ -39,11 +48,17 @@ function main { } function compile { - has compile && echo "$(get compile)" && riju-exec "$(get compile)" + if has compile; then + echo "$(get compile)" + riju-exec "$(get compile)" + fi } function run-only { - has run && echo "$(get run)" && riju-exec "$(get run)" + if has run; then + echo "$(get run)" + riju-exec "$(get run)" + fi } function run { @@ -51,12 +66,21 @@ function run { } function format { - has format && echo "$(get format.run)" && riju-exec "( $(get format.run) ) < $(get main)" + if has format; then + echo "$(get format.run)" + riju-exec "( $(get format.run) ) < $(get main)" + fi } function lsp { - has lsp.setup && echo "$(get lsp.setup)" && riju-exec "$(get lsp.setup)" - has lsp && echo "$(get lsp.start)" && riju-exec "$(get lsp.start)" + if has lsp.setup; then + echo "$(get lsp.setup)" + riju-exec "$(get lsp.setup)" + fi + if has lsp; then + echo "$(get lsp.start)" + riju-exec "$(get lsp.start)" + fi } if [[ -z "$NS" ]]; then diff --git a/docker/packaging/install.bash b/docker/packaging/install.bash index 13d1357..f4130f2 100755 --- a/docker/packaging/install.bash +++ b/docker/packaging/install.bash @@ -30,9 +30,11 @@ less make man nodejs +python3-pip ripgrep sudo tmux +tree unzip vim wget diff --git a/langs/beatnik.yaml b/langs/beatnik.yaml index 3daa2f8..f25cac5 100644 --- a/langs/beatnik.yaml +++ b/langs/beatnik.yaml @@ -1,15 +1,6 @@ id: "beatnik" name: "Beatnik" -install: - apt: - - python2 - manual: | - install -d "${pkg}/usr/local/bin" - git clone https://github.com/catseye/Beatnik.git - sed -i 's#env python#env python2#' Beatnik/script/beatnik.py - cp Beatnik/script/beatnik.py "${pkg}/usr/local/bin/beatnik" - info: impl: "Cat's Eye Beatnik" year: 2001 @@ -28,6 +19,15 @@ info: paradigm: stack usage: [] +install: + apt: + - python2 + manual: | + install -d "${pkg}/usr/local/bin" + git clone https://github.com/catseye/Beatnik.git + sed -i 's#env python#env python2#' Beatnik/script/beatnik.py + cp Beatnik/script/beatnik.py "${pkg}/usr/local/bin/beatnik" + main: "main.beatnik" template: | Soars, larkspurs, rains. diff --git a/langs/befunge.yaml b/langs/befunge.yaml index 1a980b9..9f071c6 100644 --- a/langs/befunge.yaml +++ b/langs/befunge.yaml @@ -3,6 +3,32 @@ aliases: - "be" name: "Befunge" +info: + impl: "amicloud Befunge-93" + version: "Befunge-93" + year: 1993 + desc: "Two-dimensional esoteric programming language invented in 1993 by Chris Pressey with the goal of being as difficult to compile as possible" + ext: + - be + - bf + - b93 + - b98 + - befunge + web: + wiki: "https://en.wikipedia.org/wiki/Befunge" + esolang: "https://esolangs.org/wiki/Befunge" + home: "https://catseye.tc/article/Languages.md#befunge-93" + source: "https://github.com/amicloud/befunge93" + category: esoteric + mode: interpreted + platform: [] + syntax: + - golf + - 2d + typing: integer + paradigm: stack + usage: [] + install: npm: - befunge93 @@ -36,32 +62,6 @@ install: process.exit(1); }); -info: - impl: "amicloud Befunge-93" - version: "Befunge-93" - year: 1993 - desc: "Two-dimensional esoteric programming language invented in 1993 by Chris Pressey with the goal of being as difficult to compile as possible" - ext: - - be - - bf - - b93 - - b98 - - befunge - web: - wiki: "https://en.wikipedia.org/wiki/Befunge" - esolang: "https://esolangs.org/wiki/Befunge" - home: "https://catseye.tc/article/Languages.md#befunge-93" - source: "https://github.com/amicloud/befunge93" - category: esoteric - mode: interpreted - platform: [] - syntax: - - golf - - 2d - typing: integer - paradigm: stack - usage: [] - main: "main.be" template: | 64+"!dlrow ,olleH">:#,_@ diff --git a/langs/blc.yaml b/langs/blc.yaml index 78e387a..5818e78 100644 --- a/langs/blc.yaml +++ b/langs/blc.yaml @@ -25,6 +25,31 @@ info: paradigm: functional usage: [] +install: + prepare: + apt: + - clang + apt: + - python3 + scripts: + binary-to-text: | + #!/usr/bin/env python3 + + import re + import sys + + text = re.sub(r"[^01]", "", sys.stdin.read()) + out = [] + + for m in re.finditer(r"([01]{8})", text): + out += chr(int(m.group(0), 2)) + + print("".join(out), end="") + manual: | + install -d "${pkg}/usr/local/bin" + wget https://www.ioccc.org/2012/tromp/tromp.c + clang tromp.c -Wno-everything -DInt=long -DX=8 -DA=500000 -o "${pkg}/usr/local/bin/tromp" + main: "main.blc" template: | 001010100100100001100101011011000110110001101111001011000010 diff --git a/langs/boo.yaml b/langs/boo.yaml index dc79c53..3176da8 100644 --- a/langs/boo.yaml +++ b/langs/boo.yaml @@ -26,6 +26,19 @@ info: - oo usage: [] +install: + apt: + - mono-runtime + - mono-devel + manual: | + install -d "${pkg}/usr/local/lib" + install -d "${pkg}/usr/local/bin" + wget https://github.com/boo-lang/boo/releases/download/unstable/boo-latest.zip + unzip boo-latest.zip + mv -T boo-latest "${pkg}/usr/local/lib/boo" + chmod +x "${pkg}/usr/local/lib/boo/booc" "${pkg}/usr/local/lib/boo/booish" + ln -s /usr/local/lib/boo/booc /usr/local/lib/boo/booish "${pkg}/usr/local/bin/" + setup: | mkdir -p "$HOME/.local/share" && touch "$HOME/.local/share/booish_history" diff --git a/langs/brainf.yaml b/langs/brainf.yaml index 7142210..4f4bd40 100644 --- a/langs/brainf.yaml +++ b/langs/brainf.yaml @@ -27,9 +27,39 @@ info: install: apt: - beef + - python3 + scripts: + brainf: | + #!/usr/bin/env python3 + import argparse + import readline + import subprocess + import tempfile + + parser = argparse.ArgumentParser() + parser.add_argument("file", nargs="?") + args = parser.parse_args() + + if args.file: + subprocess.run(["beef", args.file]) + while True: + try: + code = input("bf> ") + except KeyboardInterrupt: + print("^C") + continue + except EOFError: + print("^D") + break + if not code: + continue + with tempfile.NamedTemporaryFile(mode="w") as f: + f.write(code) + f.flush() + subprocess.run(["beef", f.name]) repl: | - brainf-repl + brainf input: | >++>+[>++++[-<++++>]<<]> [>>+>+<<<-]>>>[<<<+>>>-]<<+>[<->[>++++++++++<[->-[>+>>]>[+[-<+>]>+>>]<<<<<]>[-]++++++++[<++++++>-]>[<<+>>-]>[<<+>>-]<<]>]<[->>++++++++[<++++++>-]]<[.[-]<]< output: | @@ -67,6 +97,6 @@ template: | >++. run: | - brainf-repl main.bf + brainf main.bf hello: | Hello World diff --git a/langs/cat.yaml b/langs/cat.yaml index b6c1998..0a6185c 100644 --- a/langs/cat.yaml +++ b/langs/cat.yaml @@ -17,8 +17,35 @@ info: paradigm: stack usage: [] +install: + scripts: + cat-lang: | + #!/usr/bin/env -S NODE_PATH=/opt/cat node + const fs = require("fs"); + const repl = require("repl"); + + const args = process.argv.slice(2); + if (args.length > 1) { + console.error("usage: repl.js [FILE]"); + process.exit(1); + } + + const program = args.length === 1 ? fs.readFileSync(args[0], "utf-8") : null; + + const cat = require("cat"); + const ce = new cat.CatLanguage.CatEvaluator(); + + if (program !== null) { + ce.eval(program); + } + + repl.start({prompt: "cat> ", eval: (cmd, context, filename, callback) => callback(null, ce.eval(cmd))}); + manual: + - | + git clone https://github.com/cdiggins/cat-language "${pkg}/opt/cat" + repl: | - NODE_PATH=/opt/cat node /opt/cat/repl.js + cat-lang input: | 123 234 mul @@ -27,6 +54,6 @@ template: | 72 101 108 108 111 44 32 119 111 114 108 100 33 10 run: | - NODE_PATH=/opt/cat node /opt/cat/repl.js main.cat + cat-lang main.cat hello: | 72,101,108,108,111,44,32,119,111,114,108,100,33,10 diff --git a/tools/generate-build-script.js b/tools/generate-build-script.js index 3399343..b044999 100644 --- a/tools/generate-build-script.js +++ b/tools/generate-build-script.js @@ -38,18 +38,51 @@ sudo apt-get install -y ${apt.join(" ")}`); } } if (npm) { - for (const fullname of npm) { - const basename = fullname.replace(/^[^\/]+\//g, ""); + for (let fullname of npm) { + let arg; + if (typeof fullname === "string") { + arg = fullname; + } else { + arg = fullname.arg; + fullname = fullname.name; + } + let basename = fullname.replace(/^[^\/]+\//g, ""); parts.push(`\ install -d "\${pkg}/usr/local/bin" install -d "\${pkg}/opt/${basename}/lib" -npm install ${fullname} -g --prefix "\${pkg}/opt/${basename}" +npm install ${arg} -g --prefix "\${pkg}/opt/${basename}" if [[ -d "$\{pkg}/opt/${basename}/bin" ]]; then ls "$\{pkg}/opt/${basename}/bin" | while read name; do if readlink "\${pkg}/opt/${basename}/bin/\${name}" | grep -q '/${fullname}/'; then ln -s "/opt/${basename}/bin/\${name}" "\${pkg}/usr/local/bin/\${name}" fi done +fi`); + } + } + if (pip) { + for (const basename of pip) { + parts.push(`\ +install -d "\${pkg}/usr/local/bin" +pip3 install "${basename}" --prefix "\${pkg}/opt/${basename}" +if [[ -d "\${pkg}/opt/${basename}/bin" ]]; then + ls "\${pkg}/opt/${basename}/bin" | while read name; do + version="$(ls "\${pkg}/opt/${basename}/lib" | head -n1)" + cat < "\${pkg}/usr/local/bin/\${name}" +#!/usr/bin/env bash +exec env PYTHONPATH="/opt/${basename}/lib/\${version}/site-packages" "/opt/${basename}/bin/\${name}" "\\\$@" +EOF + chmod +x "\${pkg}/usr/local/bin/\${name}" + done +fi + +if [[ -d "\${pkg}/opt/${basename}/man" ]]; then + ls "\${pkg}/opt/${basename}/man" | while read dir; do + install -d "\${pkg}/usr/local/man/\${dir}" + ls "\${pkg}/opt/${basename}/man/\${dir}" | while read name; do + ln -s "/opt/${basename}/man/\${dir}/\${name}" "\${pkg}/usr/local/man/\${dir}/\${name}" + done + done fi`); } }