At StrangeLoop (well, really, PWLconf) 2017, James Long introduced me to Abdulaziz Ghuloum's An Incremental Approach to Compiler Construction, an academic-whitepaper-formatted compiler-writing tutorial.
At the same time, I was refreshing my ML knowledge, picking up OCaml — and I thought it'd be fun, perhaps, to take a stab at following the IACC, but in ML instead of Scheme.
So, someday (probably not-so-soon), this repository may contain a (shitty) (slow) (pointless) (partial) implementation of Scheme in OCaml. (As if there aren't enough of those already. 🙄)
(Note: The tests
were originally written by Professor Ghuloum, retreived from Wayback Machine for
this URL: http://www.cs.indiana.edu/~aghuloum/compilers-tutorial-tests-2006-10-11.tgz. I do not
have any copyright over, or claim on, them.)
This is useless. But hey.
brew install opam && \
opam init && \
eval `opam config env`
opam install core jbuilder
npm run-script prepare
./_build/install/default/bin/ocameel --help
./_build/install/default/bin/ocameel -o - -S - <<<"42"
./_build/install/default/bin/ocameel -o answer.s -S - <<<"42"
gcc -c src/runtime.c
gcc -o answer ./omg.o ./runtime.o
./answer
(Yes. It literally only compiles the number ‘42.’ Told you it was useless.)
Of note, I've only tested this on macOS — there's some system
calls that almost certainly need to
be re-written for a Linux. Should only be a minor effort.