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.3 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 mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id 35D89BBCA for ; Mon, 17 Mar 2008 21:34:02 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEAGpy3kfAXQIm/2dsb2JhbACoSQ X-IronPort-AV: E=Sophos;i="4.25,514,1199660400"; d="scan'208";a="9584010" Received: from discorde.inria.fr ([192.93.2.38]) by mail1-smtp-roc.national.inria.fr with ESMTP; 17 Mar 2008 21:34:01 +0100 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id m2HKXxlt028469 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Mon, 17 Mar 2008 21:34:01 +0100 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AtsBAGpy3kdQW+UCh2dsb2JhbACQfgEBAQgKKZcN X-IronPort-AV: E=Sophos;i="4.25,514,1199660400"; d="scan'208";a="8497090" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail2-smtp-roc.national.inria.fr with ESMTP; 17 Mar 2008 21:33:57 +0100 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1JbM1p-0004fD-Ne for caml-list@inria.fr; Mon, 17 Mar 2008 20:33:53 +0000 Received: from ks300734.kimsufi.com ([91.121.65.225]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 17 Mar 2008 20:33:53 +0000 Received: from sylvain by ks300734.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 17 Mar 2008 20:33:53 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Subject: Re: A C to OCaml helper ? Date: Mon, 17 Mar 2008 20:33:43 +0000 (UTC) Message-ID: References: <20080312204217.3f5087e3@orange.fr> <20080312220938.236ba3d5@orange.fr> <47D8CCA1.9020502@starynkevitch.net> <200803171507.10069.ober.14@osu.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ks300734.kimsufi.com User-Agent: slrn/0.9.8.1pl2 (Debian) Sender: news X-Miltered: at discorde with ID 47DED5B7.001 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; le-gall:01 ocaml:01 basile:01 basile:01 ocaml:01 higher-level:01 ocaml's:01 pointer:01 translating:01 translated:01 pointer:01 translated:01 stdlib:01 stub:01 utilize:98 On 17-03-2008, Kuba Ober wrote: > On Thursday 13 March 2008, Basile STARYNKEVITCH wrote: >> Fabrice Marchant wrote: >> > On Wed, 12 Mar 2008 22:03:51 +0100 >> > >> > Basile STARYNKEVITCH wrote: >> >> Fabrice Marchant wrote: >> >>> Please does it exist some tool that could do at least the very >> >>> mechanical first parts of the translation of a C source to OCaml ? >> >> >> >> Why do you want to do that? >> > > I disagree somewhat. A good starting point is to have mechanically-translated > code that works, and then work on refactoring it to utilize what OCaml has to > offer. > > In fact, C++ may provide much better translation results than C, since, if > properly written, the C++ sources will utilize higher-level primitives that > look better in OCaml. C is a really primitive language, by OCaml's > standards ;) > In my former work i have been able to see (and to participate) to some kind of langage rewrite (PLI -> C++ for example). This is interesting, because it "mechanically work" but it is far from being "humand readable". Just to give you a couple of example: * integer arithmetic are most of the time not what you think (i.e. COBOL/PLI doesn't have the same integer representation, C play with bit arithmetic, a lot of people like i++ on pointer...) * float arithmetic is a nightmare (less than integer because you cannot do a lot of tricky stuff with it) * with 99% of the tools you will find, you will loose your comments * you will get a lot more lines than the initial program (because most of the tools do a local rewrite translating one token in langage SRC to many token in langage DST) Results: You will get a BIG program without any comments, containing tricky behavior in one langage translated to buggy source code in OCaml (i let you think about the pointer/pointer arithmetic problem). BUT i am not saying this is not possible... It is always possible, you will just get a pile of junk that works more or less... But don't think you will be able to dig into a huge amount of code autogenerated without comments and anything like that. (just for fun: imagine all C macro expanded everywhere in your program and then translated to ocaml -- take a look at stdlib.h to see how many macros it uses ;-) Conclusion of my former work: it works, but soure need to be near destination language (e.g. COBOL MVS -> COBOL MicroFocus -- which is already a nightmare). IMHO, the real good way: define piece of code that will stay in C, translate other parts, by hand, into OCaml, link both. When you feel this or that part can be rewritten, remove the C stub and replace it. And use the former C part for regression testing against the new OCaml code. Regards, Sylvain Le Gall