So I'm taking a class where the project is to create a new embedded language. We are using OCaml for the compiler, so I was looking for a way to interface with AVR or its C library in such a way as I can write programs in my language, then compile and somehow get it on the arduino I have. I was curious if there's a library for OCaml or some sort of white paper for interfacing with the board at a high level or even at a low level where I can get this to work.
I have no experience with OCaml or with writing compilers, but I would suggest that you first learn how to program the Arduino, then teach your compiler to do so.
You may start by using the Arduino IDE and a couple basic tutorials. There is an option in the IDE for displaying all the commands it runs to get your program compiled and linked. Take note of these commands, then throw the IDE away. Alternatively, you can download one of the few Arduino Makefiles that float around the Web.
You will see that the basic toolset you need is the following:
- The AVR flavor of GNU GCC and the binutils. This allows you to program the AVR in assembly, C and C++. Calling these tools from your own compiler should be as easy as calling them from the command-line.
- The avr-libc, which is a port of the libc for the AVR, together with some AVR-specific stuff, and the C runtime. It does not provide a hardware abstraction layer.
- The Arduino core library, a beginner-oriented C++ library built on top of avr-libc. It does provide a hardware abstraction layer and is source-level compatible with non-AVR based Arduinos.
In terms of language and API, your main choices are: AVR assembly, C + avr-libc, C++ + avr-libc, C++ + Arduino core + avr-libc. There are others, of course, these are just the better known. Pick your favorite, learn how to use it, then teach your compiler.
The OCAML compiler can emit C code and the Arduino IDE takes C code, so in theory it is possible.
You would need to get the OCAML runtime code ported over to the Arduino IDE. At very least, I think this would be a lot of work. At worst, the Arduino might not have enough memory to support it.