feat: Add OCaml code generation
Some checks failed
continuous-integration/drone/push Build is failing

Also start using nailgun to speed up code generation.

  Resolves #6.
This commit is contained in:
Glen Whitney 2021-02-28 22:21:56 -08:00
parent 380177b274
commit f789ed94fd
10 changed files with 128 additions and 4 deletions

View file

@ -5,6 +5,7 @@ erro() { printf "%s\n" "$*" >&2; }
##### Set defaults:
SUPPRESS_ERR=YES
USE_NAILGUN=YES
LANGUAGE=Python
##### Extract command line options:
@ -14,18 +15,23 @@ do
-h|--help)
echo
echo "Usage:"
echo " fosgen [-d] [-l LANGUAGE] FILE"
echo " fosgen [-d] [-j] [-l LANGUAGE] FILE"
echo
echo "Writes to standard output the code generated from the fostr"
echo "program in FILE, targeting the specified LANGUAGE (which"
echo "defaults to Python)."
echo
echo "The -d option writes diagnostic output to standard error."
echo "The -j option uses the Spoofax Sunshine JAR directly, rather"
echo "than via nailgun."
exit
;;
-d)
SUPPRESS_ERR=''
;;
-j)
USE_NAILGUN=''
;;
-l)
shift
LANGUAGE="$1"
@ -67,5 +73,12 @@ then
exec 2>/dev/null
fi
if [[ $USE_NAILGUN ]]
then
$BINDIR/let_sun_shine
$BINDIR/ng sunshine transform -p $PROJDIR -n $LANGUAGE -i $PROGRAM
exit $?
fi
java -jar $SUNJAR transform -p $PROJDIR -l $PROJDIR -l $MVN_REPO -n $LANGUAGE -i $PROGRAM
exit $?

View file

@ -4,7 +4,7 @@ failed=0
for dir in tests/extracted/*; do
for file in $dir/*.fos; do
for language in Python Javascript Haskell; do
for language in Python Javascript Haskell OCaml; do
echo bin/fosgen -l ${language%.*} $file ...
bin/fosgen -l $language $file
if [[ $? -ne 0 ]]; then

26
bin/let_sun_shine Executable file
View file

@ -0,0 +1,26 @@
#!/bin/bash
BINDIR=$(dirname $BASH_SOURCE)
if $BINDIR/ng sunshine --help
then
# echo "sun already shining."
else
# echo "disperse the clouds."
SUNJAR="$BINDIR/../lib/sunshine.jar"
PROJDIR="$BINDIR/.."
if [[ ! $MVN_REPO ]]; then
MVN_REPO="$HOME/.m2/repository"
fi
if [[ ! -d $MVN_REPO ]]; then
MVN_REPO="/root/.m2/repository"
fi
if [[ ! -d $MVN_REPO ]]; then
echo "Cannot find your Maven repository. Please set environment variable"
echo "MVN_REPO to its full path and re-run."
exit 1
fi
java -jar $SUNJAR server >/dev/null 2>&1 &
sleep 5
$BINDIR/ng sunshine load -l $PROJDIR -l $MVN_REPO
fi