Skip to content

Instantly share code, notes, and snippets.

@saml
Created April 12, 2011 11:48
Show Gist options
  • Save saml/915371 to your computer and use it in GitHub Desktop.
Save saml/915371 to your computer and use it in GitHub Desktop.
poor man's repl
#!/bin/bash
ATSCC="$ATSHOME/bin/atscc"
TMP_DIR="$(mktemp -d --suffix='.ats-rcepl')"
TMP_DATS="$TMP_DIR/tmp.dats"
TMP_EXE="$TMP_DIR/tmp.exe"
function prompt() {
echo -n "> "
}
function codegen() {
expression="$1"
output="$2"
cat <<HEREDOC > "$output"
staload _ = "libc/SATS/stdio.sats"
staload _ = "prelude/DATS/array.dats"
staload _ = "prelude/DATS/array0.dats"
staload _ = "prelude/DATS/list.dats"
staload _ = "prelude/DATS/list0.dats"
staload _ = "prelude/DATS/list_vt.dats"
staload _ = "prelude/DATS/matrix.dats"
staload _ = "prelude/DATS/matrix0.dats"
staload _ = "prelude/DATS/option.dats"
staload _ = "prelude/DATS/option0.dats"
staload _ = "prelude/DATS/pointer.dats"
staload _ = "prelude/DATS/reference.dats"
implement main() = begin
print($expression);
end
HEREDOC
}
function compile() {
line="$1"
codegen "$line" "$TMP_DATS"
"$ATSCC" "$TMP_DATS" -o "$TMP_EXE" > /dev/null 2>&1 || return 1
}
function execute() {
"$TMP_EXE"
echo
}
trap "rm -rf $TMP_DIR" EXIT
echo "ATS Read Compile Execute Print Loop"
echo "ctrl-d (EOF) to quit"
prompt
while read line
do
if [[ "" != "$line" ]]
then
compile "$line"
execute
fi
prompt
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment