From dd4be0f7bf6e11b89d122eb05019c4d555398284 Mon Sep 17 00:00:00 2001 From: TitouanT Date: Sun, 7 Feb 2021 22:31:06 +0100 Subject: [PATCH 1/2] 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/2] 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