From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 02923BC58 for ; Wed, 15 Sep 2010 14:58:41 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvkAAHtfkEzAbHMMmWdsb2JhbACDG55YFQEBAQEBCAsKBxEisDGSEoRNdASNKg X-IronPort-AV: E=Sophos;i="4.56,371,1280700000"; d="vcf'?scan'208";a="69568164" Received: from coliposte.enst-bretagne.fr ([192.108.115.12]) by mail4-smtp-sop.national.inria.fr with ESMTP; 15 Sep 2010 14:58:41 +0200 Received: from localhost (localhost.localdomain [127.0.0.1]) by coliposte.enst-bretagne.fr (8.13.7/8.13.7/2009.11.10) with ESMTP id o8FCwhg7015617; Wed, 15 Sep 2010 14:58:43 +0200 Received: from courrier.enst-bretagne.fr (smtps.enst-bretagne.fr [10.29.90.4]) by coliposte.enst-bretagne.fr (8.13.7/8.13.7/2009.11.10) with ESMTP id o8FCwRJg015572; Wed, 15 Sep 2010 14:58:30 +0200 Received: from [10.66.144.72] (pc-salsa-elec-072.ext.enst-bretagne.fr [10.66.144.72]) (user=vgripon mech=PLAIN bits=0) by courrier.enst-bretagne.fr (8.13.8/8.13.8/2010.02.22) with ESMTP id o8FCwOGe002164 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Wed, 15 Sep 2010 14:58:24 +0200 Message-ID: <4C90C33A.8060800@telecom-bretagne.eu> Date: Wed, 15 Sep 2010 14:59:38 +0200 From: Vincent Gripon User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.10pre) Gecko/20100914 Shredder/3.1.5pre MIME-Version: 1.0 To: Basile Starynkevitch Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Compiling Ocaml sources to c sources References: <4C8F660B.4060901@telecom-bretagne.eu> <20100914124341.GA11500@hector.lesours> In-Reply-To: <20100914124341.GA11500@hector.lesours> Content-Type: multipart/mixed; boundary="------------000709070008050202070802" X-Virus-Scanned: amavisd-new at enst-bretagne.fr X-Spam: no; 0.00; ocaml:01 basile:01 0200,:01 planing:01 ocaml:01 gcc:01 compilable:01 runtime:01 runtime:01 non-trivial:01 recursion:01 bytecode:01 translating:01 byte:01 compiler:01 X-Attachments: cset="utf-8" name="vincent_gripon.vcf" name="vincent_gripon.vcf" This is a multi-part message in MIME format. --------------000709070008050202070802 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Thanks for your answer, On 09/14/2010 02:43 PM, Basile Starynkevitch wrote: > On Tue, Sep 14, 2010 at 02:09:47PM +0200, Vincent Gripon wrote: >> Hello, >> >> We are currently planing to participate to a programming contest. > It would be interesting for us to know more about that contest. We are entering the IEEEXtreme programming competition ( http://www.ieee.org/membership_services/membership/students/competitions/xtreme/index.html ). >> This contest allows the use of four languages (C/C#/C++/java) but >> not OCaml. > That does not mean much. What about libraries you are calling from C? > > In particular: > > * can you use any library? This seems strange (because the > organizers very probably won't have the same libraries or versions > as you have). > > * do you have any restrictions on the libraries you are using? > > * at the extreme case, the competition might require you to provide > all the sources of every non standard (in the sense of ISO C > standard) libraries you are using, and a verified mean to build > them. What about POSIX system calls? There is very little information on these aspects, it looks like only the basic gcc compilers are available. The proposed exercises will probably not require any library or complicated system call, as it is more an algorithmic contest than system one. > >> We would like to use Ocaml as it is to us the language that fits the >> most the kind of exercises proposed. The organizers don't mind if we >> use OCaml as long as we provide an easily compilable C source to >> them, even if it is not readable. >> >> Is there any platform independent way to compile OCaml sources to C >> sources? > I don't see any easy way to do that. There are several issues > > * the Ocaml runtime environment, which not only includes its garbage > collector but also all the ocaml runtime library. > > * Hacking a C generator inside Ocaml is non-trivial, because of the > garbage collector, currified function calls, and tail recursion > etc. > > * If you really insist on coding in Ocaml and if you don't care much > about performance, you could take my bit-rotten Ocamljit work (I > forgot where you can find it, and I don't have it anymore, but > google should help finding it) and make something which transform > the entire bytecode of an Ocaml program into a gigantic single C > function (translating straightforwardly every byte code into a > small chunk of C code). This is not easy to do, and it might not > be fun neither. Very probably, a C compiler would have pain to > optimize such a big function (by personal experience, the GCC > compiler usually take O(n^2) time to optimize with -O2 a > sufficiently large function of size n, and may also need O(n^2) > memory). And such an approach might not produce portable code > (perhaps there are some issues w.r.t. 32 vs 64 bits > systems). Actually, portable C is a fiction: only ported C > programs can exist. We downloaded your software and it works perfectly well (with ocaml 3.09). It seems perfectly suited for the contest rules and we are planing to use it in this regard if it does not bother you. > > Did you also consider using Scheme, it has several implementations > generating C code (Chicken & Stalin come to mind). > > But still, programming in C does not mean much! What about > portability? building? external libraries? linking other stuff? target > system? > > If you have complete freedom on what you link with your program, you > could hack a libocamlrun to be linkable, and link the bytecode as an > array, as suggested previously. > > I would imagine that preparing stuff to make you code in Ocaml and fit > into the contest rules is a big lot of work. Thanks to your software, it should not be =) Cheers. --------------000709070008050202070802 Content-Type: text/x-vcard; charset=utf-8; name="vincent_gripon.vcf" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="vincent_gripon.vcf" begin:vcard fn:Vincent Gripon n:Gripon;Vincent org:Telecom Bretagne;Computer Science and Telecommunications adr:;;Telecom Bretagne - Technopole Brest Iroise;Brest Cedex 3;;29238;France email;internet:vincent.gripon@ens-cachan.org title:PhD Student tel;work:+0033 2 29 00 1586 url:http://perso.eleves.bretagne.ens-cachan.fr/~gripon version:2.1 end:vcard --------------000709070008050202070802--