From dd4be0f7bf6e11b89d122eb05019c4d555398284 Mon Sep 17 00:00:00 2001 From: TitouanT Date: Sun, 7 Feb 2021 22:31:06 +0100 Subject: [PATCH 1/4] transpiles bf into C code --- lxc/executors/brainfuck | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/lxc/executors/brainfuck b/lxc/executors/brainfuck index eb9725d..7a82aa5 100755 --- a/lxc/executors/brainfuck +++ b/lxc/executors/brainfuck @@ -1,4 +1,33 @@ #!/bin/bash cd /tmp/$1 -timeout -s KILL 3 xargs -a args.args -d '\n' brainfuck code.code < stdin.stdin +sedarg="\ +s/+/P/g;\ +s/-/M/g;\ +s/>/++p;/g;\ +s/ code.c +#include + +char mem[1<<$MEMSIZE]; +char *p = mem + (1<<$((MEMSIZE - 1))); +int c; + +int main() { + $(timeout -s KILL 3 sed 's/[^][<>.,+-]//g' code.code | timeout -s KILL 3 sed $sedarg) +} +EOF +timeout -s KILL 3 gcc -std=c11 -o binary code.c + +# execution +timeout -s KILL 3 ./binary < args.args < stdin.stdin From f8391e9aaf41a7c79d0d2f7076a219a6e8029182 Mon Sep 17 00:00:00 2001 From: Eleanor Bartle Date: Wed, 10 Feb 2021 17:41:14 +1100 Subject: [PATCH 2/4] Don't attempt to run executable if compilation fails It was just ugly. --- lxc/executors/zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lxc/executors/zig b/lxc/executors/zig index b046672..bc2a971 100644 --- a/lxc/executors/zig +++ b/lxc/executors/zig @@ -2,5 +2,5 @@ cd /tmp/$1 cp code.code main.zig -timeout -s KILL 10 zig build-exe main.zig +timeout -s KILL 10 zig build-exe main.zig && \ timeout -s KILL 3 xargs -a args.args -d '\n' ./main From 0e2131eb1d23aa4a876b03ae9e1bbdd1121bccc6 Mon Sep 17 00:00:00 2001 From: Titouan Teyssier Date: Sun, 14 Feb 2021 17:59:33 +0100 Subject: [PATCH 3/4] add prolog language support (#82) * add prolog language support --- config/languages.json | 7 +++++++ container/install_script.sh | 16 ++++++++++++++++ lxc/executors/prolog | 9 +++++++++ lxc/tests/_run | 2 ++ lxc/tests/prolog.pl | 1 + lxc/util/versions | 4 ++++ 6 files changed, 39 insertions(+) create mode 100755 lxc/executors/prolog create mode 100644 lxc/tests/prolog.pl diff --git a/config/languages.json b/config/languages.json index 2fd5b1e..f62ea5c 100644 --- a/config/languages.json +++ b/config/languages.json @@ -199,6 +199,13 @@ "php5" ] }, + { + "name": "prolog", + "aliases": [ + "prolog", + "plg" + ] + }, { "name": "python3", "aliases": [ diff --git a/container/install_script.sh b/container/install_script.sh index 65e72c1..bb7264f 100644 --- a/container/install_script.sh +++ b/container/install_script.sh @@ -283,6 +283,22 @@ MIX_ENV=prod mix escript.build --force echo 'export PATH=$PATH:/opt/05AB1E/05AB1E' >> /opt/.profile source /opt/.profile + +# install prolog +# final binary: /opt/swipl/swipl-/build/src/swipl +cd /opt && mkdir swipl && cd swipl +SUB_DIR=swipl-8.2.4 +wget https://www.swi-prolog.org/download/stable/src/$SUB_DIR.tar.gz +tar -xf $SUB_DIR.tar.gz +rm $SUB_DIR.tar.gz +cd $SUB_DIR +mkdir build +cd build +cmake -DSWIPL_PACKAGES_JAVA=OFF -DSWIPL_PACKAGES_X=OFF -DMULTI_THREADED=OFF -G Ninja .. +ninja +echo "export PATH=\$PATH:/opt/swipl/$SUB_DIR/build/src" >> /opt/.profile +source /opt/.profile + # create runnable users and apply limits for i in {1..150}; do useradd -M runner$i diff --git a/lxc/executors/prolog b/lxc/executors/prolog new file mode 100755 index 0000000..e5bb3ec --- /dev/null +++ b/lxc/executors/prolog @@ -0,0 +1,9 @@ +#!/bin/bash + +cd /tmp/$1 + +sed 's/^.*$/:- forall((Goal = (\0), call(Goal)), (write(Goal), nl))./' input.input | + cat code.code - > code.pl + +timeout -s KILL 3 swipl -g true -t halt code.pl + diff --git a/lxc/tests/_run b/lxc/tests/_run index e063d4f..b166802 100755 --- a/lxc/tests/_run +++ b/lxc/tests/_run @@ -52,6 +52,8 @@ echo -n 'testing perl = ' ../../cli/execute perl perl.pl echo -n 'testing php = ' ../../cli/execute php php.php +echo -n 'testing prolog = ' +../../cli/execute prolog prolog.pl echo -n 'testing python2 = ' ../../cli/execute python2 python2.py echo -n 'testing python3 = ' diff --git a/lxc/tests/prolog.pl b/lxc/tests/prolog.pl new file mode 100644 index 0000000..2521fb1 --- /dev/null +++ b/lxc/tests/prolog.pl @@ -0,0 +1 @@ +:- write('good'), nl. diff --git a/lxc/util/versions b/lxc/util/versions index f280210..f86b563 100755 --- a/lxc/util/versions +++ b/lxc/util/versions @@ -105,6 +105,10 @@ echo 'php' lxc-attach --clear-env -n piston -- /bin/bash -l -c "php -v" echo '---' +echo 'prolog' +lxc-attach --clear-env -n piston -- /bin/bash -l -c "swipl --version" +echo '---' + echo 'python2' lxc-attach --clear-env -n piston -- /bin/bash -l -c "python -V" echo '---' From f20c8bafd194be49c86cb87fd762371256cbf0ab Mon Sep 17 00:00:00 2001 From: ThreshMain Date: Mon, 15 Feb 2021 17:59:33 +0100 Subject: [PATCH 4/4] Fixed brainfuck transpiler to accept args --- lxc/executors/brainfuck | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lxc/executors/brainfuck b/lxc/executors/brainfuck index 7a82aa5..f03b43f 100755 --- a/lxc/executors/brainfuck +++ b/lxc/executors/brainfuck @@ -29,5 +29,8 @@ int main() { EOF timeout -s KILL 3 gcc -std=c11 -o binary code.c +# Merging args.args and stdin.stdin for emkc challenges +cat stdin.stdin >> args.args + # execution -timeout -s KILL 3 ./binary < args.args < stdin.stdin +timeout -s KILL 3 ./binary < args.args