New language: Unison

This commit is contained in:
Radon Rosborough 2020-08-23 17:49:47 -06:00
parent d5b1459410
commit d93d4382ef
4 changed files with 51 additions and 9 deletions

View File

@ -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",

View File

@ -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 () => {

View File

@ -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"

View File

@ -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