#!/bin/sh

# Compile an ALF program (if necessary) and execute it:

COMPILE=no
PPERROR=XYZalfpreproerrorXYZ

if test ! -f $1.alf
then
   echo "Main module '$1.alf' not found."
   exit
fi
if test -f $1.byt
then
   if [ `ls -t $1.alf $1.byt | head -1` = $1.alf ]
   then
      COMPILE=yes
   fi
else
   COMPILE=yes
fi

if [ $COMPILE = yes ]
then
   echo " -------------------------------------- "
   echo "| Compiling ALF program into bytecode: |"
   echo " -------------------------------------- "
   echo

   alfcheck $1
   echo
   if test ! -f $PPERROR
   then
      flatalfcompile $1
      rm $1.fal
   fi
fi

if test -f $PPERROR
then
   rm $PPERROR
else
   echo " --------------------------------- "
   echo "| Executing compiled ALF program: |"
   echo " --------------------------------- "
   echo
   awam $1
fi
