From d93d4382ef06173e97fc960aed02b0b32fd0c3b9 Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Sun, 23 Aug 2020 17:49:47 -0600 Subject: [PATCH] New language: Unison --- backend/src/langs.ts | 24 ++++++++++++++++++++++++ backend/src/test-runner.ts | 25 ++++++++++++++++--------- scripts/docker-install-phase4.bash | 4 ++++ scripts/docker-install-phase7.bash | 7 +++++++ 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/backend/src/langs.ts b/backend/src/langs.ts index b64d98f..8a77480 100644 --- a/backend/src/langs.ts +++ b/backend/src/langs.ts @@ -2500,6 +2500,30 @@ a `, timeout: 15, }, + unison: { + aliases: ["ucm"], + name: "Unison", + setup: "shopt -s dotglob && cp -R /opt/unison/project-template/* ./", + repl: "unison -codebase .", + input: "find : [a] -> [a]", + output: "base.List.reverse", + main: "main.u", + run: `echo "Type 'run main' to run the code." && unison -codebase .`, + helloInput: "run main", + scope: { + code: `x = 123 * 234`, + input: `DELAY: 1 +add x +DELAY: 0.5 +display x`, + }, + template: `use io + +main : '{IO} () +main = 'let + printLine "Hello, world!" +`, + }, unlambda: { aliases: ["unl"], name: "Unlambda", diff --git a/backend/src/test-runner.ts b/backend/src/test-runner.ts index 025667a..fad3ba9 100644 --- a/backend/src/test-runner.ts +++ b/backend/src/test-runner.ts @@ -26,8 +26,18 @@ function findPosition(str: string, idx: number) { return { line, character }; } -function forTTY(input: string) { - return input.replace(/\n/g, "\r") + "\r"; +async function sendInput(send: (msg: any) => any, input: string) { + for (const line of input.split("\n")) { + if (line.startsWith("DELAY:")) { + const delay = parseFloat(line.replace(/DELAY: */, "")); + if (Number.isNaN(delay)) continue; + await new Promise((resolve) => + setTimeout(resolve, delay * 1000 * TIMEOUT_FACTOR) + ); + } else { + send({ event: "terminalInput", input: line + "\r" }); + } + } } class Test { @@ -196,24 +206,21 @@ class Test { const pattern = this.config.hello || "Hello, world!"; this.send({ event: "runCode", code: this.config.template }); if (this.config.helloInput !== undefined) { - this.send({ - event: "terminalInput", - input: forTTY(this.config.helloInput), - }); + sendInput(this.send, this.config.helloInput); } await this.waitForOutput(pattern, this.config.helloMaxLength); }; testRepl = async () => { const input = this.config.input || "123 * 234"; const output = this.config.output || "28782"; - this.send({ event: "terminalInput", input: forTTY(input) }); + sendInput(this.send, input); await this.waitForOutput(output); }; testRunRepl = async () => { const input = this.config.runReplInput || this.config.input || "123 * 234"; const output = this.config.runReplOutput || this.config.output || "28782"; this.send({ event: "runCode", code: this.config.template }); - this.send({ event: "terminalInput", input: forTTY(input) }); + sendInput(this.send, input); await this.waitForOutput(output); }; testScope = async () => { @@ -231,7 +238,7 @@ class Test { allCode = allCode + code + "\n"; } this.send({ event: "runCode", code: allCode }); - this.send({ event: "terminalInput", input: forTTY(input) }); + sendInput(this.send, input); await this.waitForOutput(output); }; testFormat = async () => { diff --git a/scripts/docker-install-phase4.bash b/scripts/docker-install-phase4.bash index 57d73f0..74f1cf1 100755 --- a/scripts/docker-install-phase4.bash +++ b/scripts/docker-install-phase4.bash @@ -284,5 +284,9 @@ ln -s /opt/swift/bin/swiftc /usr/local/bin/swiftc ln -s /opt/swift/bin/sourcekit-lsp /usr/local/bin/sourcekit-lsp rm swift.tar.gz +# Unison +wget -nv https://github.com/raxod502/riju-cdn/releases/download/unison-M1l-232-519cbeb58704c1b9410c9386e492be59fd5a5334/unison -O /usr/local/bin/unison +chmod +x /usr/local/bin/unison + popd >/dev/null rm "$0" diff --git a/scripts/docker-install-phase7.bash b/scripts/docker-install-phase7.bash index 5482ddb..3067935 100755 --- a/scripts/docker-install-phase7.bash +++ b/scripts/docker-install-phase7.bash @@ -71,6 +71,13 @@ cat bsconfig.json | jq '.name = "riju-project"' | sponge bsconfig.json yarn install popd >/dev/null +# Unison +mkdir -p /opt/unison/project-template +pushd /opt/unison/project-template >/dev/null +unison -codebase . init +LESS="+q" unison -codebase . <<< 'pull https://github.com/unisonweb/base:.trunk .base' +popd >/dev/null + # Befunge tee /usr/local/bin/befunge-repl >/dev/null <<"EOF" #!/usr/bin/env -S NODE_PATH=/usr/lib/node_modules node