This is the 13th article of a series (table of contents) about compiler development with LLVM using OCaml. We intend to develop a compiler for a subset of OCaml large enough to allow our compiler to compile itself.
This article is more a status update than anything else. It only brings some library updates and code clean-up.
It has been a long time since my last Photon-related post. I had few time for Photon development last months, overwhelmed by professional work, NGO activities and my other hobbies.
I also felt back into my old sin of experimenting too much in too many directions, without keeping straight on path. I multiplied branches in my Photon own Git repository, and experimented again with various language design issues. I even hesitated to pretend this whole series never existed and start from scratch again, possibly towards another goal language.
To prevent this from occurring again and again, I will try to be more regular with updates. In the process, I'll switch to smaller, less formal posts. Feel free to ask questions in the comments!
Photon now links with version 2.9 of the LLVM library. Required changes were a path change in
myocamlbuild.ml and a small adaptation to an API change for module creation in the
Our interpreter and compiler were sharing much state. It was not easy to enforce this internal state being used in a consistent manner in both modules. I finally decided to remove the
Interpreter module, moving its functionality directly into
Negate operators for integer and floating-point numbers (respectively
F_neg in our AST) were compiled using the same
build_neg LLVM function.
I don't know whether this bug was already present or if it is due to a change in LLVM API, but this does not work with floating-point numbers. One has to use
build_fneg for these.
The code has been fixed accordingly.
We encountered some bugs in LLVM OCaml bindings previously. We had to use workarounds to circumvent these bugs.
As these bugs have been fixed in version 2.9 of LLVM bindings, the corresponding workaround code has been removed.
Tests have been modified to run more quickly. When we will bring optimization on the table, we will consider longer test to obtain more meaningful comparisons.
mainhas been split into smaller functions.
In the next installment, we will improve
unit type handling.
The code accompanying this article is available in archive photon-tut-13.tar.xz or through the git repository:
git clone http://git.legiasoft.com/photon.git cd photon git checkout 13-cleanup.2