caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jon Harrop <jon@ffconsultancy.com>
To: caml-list@inria.fr
Subject: Using OCaml's run-time from LLVM-generated native code
Date: Fri, 1 Feb 2008 21:24:56 +0000	[thread overview]
Message-ID: <200802012124.56835.jon@ffconsultancy.com> (raw)


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


             reply	other threads:[~2008-02-01 21:29 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-01 21:24 Jon Harrop [this message]
2008-02-03 21:24 ` [Caml-list] " Alain Frisch
2008-02-03 23:19   ` Jon Harrop
2008-02-04  7:03     ` Alain Frisch
2008-02-04 10:32       ` Jon Harrop
2008-02-04 11:11         ` Alain Frisch
2008-02-04 13:36           ` Jon Harrop
2008-02-04 15:20             ` Alain Frisch
2008-02-05 23:08             ` Florent Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802012124.56835.jon@ffconsultancy.com \
    --to=jon@ffconsultancy.com \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).