#!/bin/bash
# Try to lower all R47 programs to lesser machine formats, to try
# identifying gaps between what is implemented and what each machine
# actually supports.  It also serves to outline the capabilities of
# each machine by comparison to the others.
if [ -z "$1" ]
then
    for ext in 11c 15c 32sii d32 35s raw ; do "$0" "$ext" ; done
    exit 0
fi

ext=$1
tries=0
fails=0
tmp=/tmp/r47-lower-$$.$ext

for t in tests/r47/*.p47 ../*.p47
do
    tries=$((tries + 1))
    if ! ./rejig "$t" -o "$tmp" > /dev/null 2>&1
    then
        # If we can't lower it, we ipso facto cannot raise it, so mark
        # it as total failure.  Also, adding "LOWER" makes the "RAISE"
        # failures harder to see in the output, being the same length.
        echo -e "\033[31mFAIL ($ext): $t\033[0m"
        fails=$((fails + 1))
    elif ! ./rejig "$tmp" > /dev/null 2>&1
    then
        echo -e "\033[33mRAISE FAIL ($ext): $t\033[0m"
        fails=$((fails + 1))
    #else echo -e "\033[32m  OK ($ext): $t\033[0m"
    fi
done

ok=$((tries - fails))
echo -e "\033[32m$ok of $tries OK\033[0m\n"
