Compare commits

...

4 Commits

Author SHA1 Message Date
Brian Seymour 0c4c6e7ad5
Merge pull request #77 from TitouanT/bf_new_executor
Fixes the brainfuck executor
2021-02-10 13:40:49 -06:00
Brian Seymour 95d8b853db
Merge pull request #80 from EleanorNB/patch-1
Don't attempt to run executable if compilation fails
2021-02-10 13:38:50 -06:00
Eleanor Bartle f8391e9aaf
Don't attempt to run executable if compilation fails
It was just ugly.
2021-02-10 17:41:14 +11:00
TitouanT dd4be0f7bf transpiles bf into C code 2021-02-07 22:31:06 +01:00
2 changed files with 31 additions and 2 deletions

View File

@ -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/</--p;/g;\
s/P/++*p;/g;\
s/M/--*p;/g;\
s/\\./putchar(*p);/g;\
s/,/*p=(c=getchar())==EOF?0:c;/g;\
s/\\[/while(*p){/g;\
s/]/}/g\
"
# compilation
MEMSIZE=15
cat <<EOF > code.c
#include <stdio.h>
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

View File

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