From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=AWL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id AF19EBC6C for ; Fri, 1 Feb 2008 22:29:59 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAK4do0fAXQInh2dsb2JhbACCNo13AQEBCAopnhE X-IronPort-AV: E=Sophos;i="4.25,292,1199660400"; d="scan'208";a="22069878" Received: from concorde.inria.fr ([192.93.2.39]) by mail4-smtp-sop.national.inria.fr with ESMTP; 01 Feb 2008 22:29:59 +0100 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m11LTvLU018566 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Fri, 1 Feb 2008 22:29:59 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Ah4FAGceo0fUnw6Elmdsb2JhbACCNo13AQEBAQcEBgcKEQeeCA X-IronPort-AV: E=Sophos;i="4.25,292,1199660400"; d="scan'208";a="7530542" Received: from pih-relay05.plus.net ([212.159.14.132]) by mail1-smtp-roc.national.inria.fr with ESMTP; 01 Feb 2008 22:29:56 +0100 Received: from [80.229.56.224] (helo=beast.local) by pih-relay05.plus.net with esmtp (Exim) id 1JL3SN-00070w-B0 for caml-list@inria.fr; Fri, 01 Feb 2008 21:29:55 +0000 From: Jon Harrop Organization: Flying Frog Consultancy Ltd. 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 User-Agent: KMail/1.9.7 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200802012124.56835.jon@ffconsultancy.com> X-Plusnet-Relay: f2205535e565fdd1abbe533f90165b81 X-Miltered: at concorde with ID 47A38F55.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocaml's:01 run-time:01 ocaml's:01 run-time:01 native-code:01 compiler:01 bindings:01 native-code:01 ocaml:01 ffi:01 camlprim:01 camlparam:01 alloc:01 camlreturn:01 ocaml:01 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