Browse thread
Using OCaml's run-time from LLVM-generated native code
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Jon Harrop <jon@f...> |
| Subject: | Using OCaml's run-time from LLVM-generated native code |
I would like to use OCaml's run-time in code that is run-time generated by
LLVM as simply as possible (i.e. with no regard for efficiency yet). There
are two main motivations for this:
1. Write a native-code compiler for MiniML as an educational exercise but
without having to implement a GC.
2. Write a tool that autogenerates bindings to native-code libraries that are
immediately usable from OCaml without having to go via C or use external
tools (just LLVM).
I believe the easiest solution is to autogenerate equivalents of the CAML*
macros from OCaml's C FFI. For example, the LLVM backend can then generate
native code equivalent to (from [1]):
CAMLprim value
create_tuple( value a, value b, value c )
{
CAMLparam3( a, b, c );
CAMLlocal1( abc );
abc = caml_alloc(3, 0);
Store_field( abc, 0, a );
Store_field( abc, 1, b );
Store_field( abc, 2, c );
CAMLreturn( abc );
}
This raises several questions for me:
. Is this even possible?
. Has anyone written any self-contained toy C programs that use OCaml's
run-time for garbage collection?
. Do I need to worry about what the C program puts on the stack or will this
take care of itself?
. Has anyone already done this?
For anyone who hasn't already used LLVM and its excellent OCaml bindings, I
cannot recommend it highly enough: it is a tremendous achievement.
[1] - http://www.linux-nantes.org/~fmonnier/OCaml/ocaml-wrapping-c.php
Many thanks,
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/products/?e