view paste/paste.15661 @ 12493:885661512b17 draft

<int-e> le//rn schwartzian//In 1987, Yogurt introduced a better way to rank Schwartz users: Rather than holding an annual tournament, users would take a series of standardized tests adminstered by official Schwartz centers, and would then be ranked according to the results. This lead to the Schwartzian transform because it allowed many more users to be ranked.
author HackEso <hackeso@esolangs.org>
date Fri, 12 Jan 2024 07:24:55 +0000
parents 9a4f41db9f00
children
line wrap: on
line source

#!/bin/bash
LANG="$1"

case "$LANG" in
    c)
        HEAD='#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <sys/types.h>\n#include <unistd.h>\nint main(int argc, char **argv) {'
        TAIL='; return 0; }'
        EXT='c'
        GCC='gcc'
        FLAGS='-std=gnu99'
    ;;

    c++)
        HEAD='#include <iostream>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\nusing namespace std;\nint main(int argc, char **argv) {'
        TAIL='; return 0; }'
        EXT='cc'
        GCC='g++'
        FLAGS='-std=gnu++0x'
    ;;

    assembler)
        HEAD='.globl main; main: pushq %rbp; movq %rsp, %rbp;'
        TAIL='movl $0, %eax; leave; ret;'
        EXT='s'
        GCC='gcc'
        FLAGS=''
    ;;

    java)
        HEAD='class Main { public static void main(String[] args) {'
        TAIL='; } }'
        EXT='java'
        GCC='gcj'
        FLAGS='--main=Main'
    ;;
esac

SOURCE="/tmp/source.$$.$EXT"

(
    echo -e "$HEAD"
    cat "$2"
    echo "$TAIL"
) > "$SOURCE"

"$GCC" -x "$LANG" "$SOURCE" $FLAGS -o /tmp/compiled.$$ 2> /dev/null ||
"$GCC" -x "$LANG" "$2" $FLAGS -o /tmp/compiled.$$ 2> /dev/null ||
echo 'Does not compile.'
rm -f "$SOURCE"

ulimit -u 3
if [ -x /tmp/compiled.$$ ] ; then /tmp/compiled.$$; fi 2>&1
rm -f /tmp/compiled.$$