OcaPic: Programming PIC microcontrollers in OCaml

Most embedded systems development is done in C. It's rare to see a functional programming language target any kind of microcontroller, let alone an 8-bit microcontroller with only a few kB of RAM. But the team behind the OcaPic project has somehow managed to get OCaml running on a PIC18 microcontroller. To do so, they created an efficient OCaml virtual machine in PIC assembler (~4kB of program memory), and utilized some clever techniques to postprocess the compiled bytecode to reduce heap usage, eliminate unused closures, reduce indirections, and compress the bytecode representation. Even if you're not interested in embedded systems, you may find some interesting ideas there for reducing overheads or dealing with constrained resource budgets.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


For some unknown reason I cannot access the link in your post. The link to the implementation is:


(It seems there was a recent (PADL'15) publication, but I cannot find a PDF online.)

The author of OCaPIC is Benoît Vaugon (supervised by Philippe Wang and Emmanual Chailloux), who is a bit of an expert in interesting compilation projects related to OCaml. OCamlClean (a whole-program dead code removal tool for OCaml bytecodes) is part of OCaPIC, but there is also OCamlCC, a compiler from OCaml bytecode to C that does interesting analyses and optimizations -- such as a transformation from the stack-based bytecode instructions to a register-like format allowing to utilize C local variables for some slots.

I fixed the link and

I fixed the link and promoted to home page. (Allan, why didn't you post directly to the home page?)

Lack of paper

In the absence of a non-paywalled paper I wasn't comfortable putting it on the front page. But the project seemed interesting enough to at least let other LtUers know about it.

Personally, I find project

Personally, I find project websites just as interesting as research papers (often actually more interesting...)

Fair enough

Noted for future reference :)

source as docs

There's the additional possibility of reproducing key details of a paper by analysing the source code and included demos. There's plenty of both in this project's web site plus a 2011 paper and pieces of a 2015 paper in Google books. Plenty of potential value despite the paywall.


For the record, after I personally insisted to get the paper online, the authors added the following mention on their webpage:

Posting the paper online is forbidden by Springer, but we have the right to share the chapter by email with research colleagues for their professional non-commercial research. To send us a mail, see the Contact page.

I am convinced that posting a preprint online would be perfectly reasonable, but they appear to take a legalist take on the issue and do things which in practice imply that nobody will read the paper. Meh.

It is confusing while the

It is confusing while the publishers/committees are pragmatic only in the winky way. The system is clearly broken, and the loopholes that keep it going are difficult to understand.

Another link

Does anybody have a non-paywall link to the PADL paper?

I spent a bit of time

I spent a bit of time looking for one, but wasn't able to find it, which was a little disappointing. The "References" section of the project website includes a slide presentation that provides some details.

Email (meta)

I think the right move in this case is to email the authors and ask them to put the paper online. (They should feel that it is their duty to do so, editor policies notwithstanding.) I sent an email to the authors.

here's the link

Applied my Google Fu to see if I can bypass yet another paywall on good research. Many times they're posted elsewhere under a different name. So, search for part of name, author, and use "pdf" in search to sometimes get a result like this:


French version

The original French document is not beyond a paywall, but it only help those of us that can read it.


Hard data point

Had a read through the paywalled copy at work. This is a really interesting data-point: it is already surprising that a VM for a symbolic language with memory management can fit into 5.5Kib/4Kib of memory. It does not seem reasonable to expect it could be squeezed into anything smaller. The instruction set on the PIC is not particularly dense. This seems like a reasonable lower bound for the "cost" of those language features in interesting units: a fairly standard 8-bit instruction set.


I gave another commenter the link to the paper. Maybe put it in your post somewhere? Here it is again:



I believe this is a link to slides of a presentation given in 2011, not a paper written in 2014 -- which should have more details. Interesting complementary information, though -- some people prefer to look at slides for first approach.

good catch

Good catch: I didn't realize there were two. So, looking for the 2015 version led to bad news: it wasn't a regular paywall. It's a book chapter by Springer and they can't publish anywhere else.

Did find something, though. A paper on Google books with some pages removed below. There's significant details in the remaining pages.


Further, they'll email you the full paper for free if you can justify it's part of your research:

"Posting the paper online is forbidden by Springer, but we have the right to share the chapter by email with research colleagues for their professional non-commercial research. To send us a mail, see the Contact page."