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.5 required=5.0 tests=DNS_FROM_RFC_ABUSE autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 156B0BC69 for ; Sun, 16 Dec 2007 13:52:29 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAMetZEfZkrEKn2dsb2JhbACQAwEBAQEHBAYRGJdM X-IronPort-AV: E=Sophos;i="4.24,172,1196636400"; d="scan'208,217";a="5251478" Received: from web27010.mail.ukl.yahoo.com ([217.146.177.10]) by mail2-smtp-roc.national.inria.fr with SMTP; 16 Dec 2007 13:52:28 +0100 Received: (qmail 4611 invoked by uid 60001); 16 Dec 2007 12:52:28 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.fr; h=X-YMail-OSG:Received:X-Mailer:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-ID; b=zr+yLLv8MJF4StmhXKZMNO7HB08XEKh31LJBFi7sdVGE2f6SbR0faJtG+ymaD5hmLIcM7T0LZMsmUqjI0SwRKl8/lpd1g0KSn9EoobnUAqCy0leLFEa0L5m463jLfKwBOYS3RnVXsld/WwscMY8+o0WYIm9TtIEgOMmyJmPx73Y=; X-YMail-OSG: SEFb4u0VM1k1jTeV.Eye5ahLKCf3ij8hO14RHIExoD37RopwrogIjaprLeuTVnGF5rhRmop9ljj7aVV__g7VL49tLCySyPwF7hHp9SA_UiQLF3k7d76bnD9pIKU- Received: from [82.242.132.106] by web27010.mail.ukl.yahoo.com via HTTP; Sun, 16 Dec 2007 12:52:28 GMT X-Mailer: YahooMailRC/818.31 YahooMailWebService/0.7.158.1 Date: Sun, 16 Dec 2007 12:52:28 +0000 (GMT) From: Matthieu Wipliez Subject: Re : [Caml-list] Ask for a more efficient way to deallocate memory (full version) To: caml-list@yquem.inria.fr MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Message-ID: <273947.94856.qm@web27010.mail.ukl.yahoo.com> X-Spam: no; 0.00; matthieu:01 bandel:01 in-berlin:01 compiler:01 ocaml:01 -pp:01 syntax:01 parses:01 syntax:01 compiler:01 ocaml:01 expr:01 expr:01 camlp:01 parses:01 Oliver Bandel :=0A> =0A> =0A > So, is it just a = kind of pre-compilation?=0A> The core-OCaml compiler will be the same?=0A..= .=0A> I have not looked at the OCaml-compiler in detail,=0A> but from what = you wrote I would assume, there=0A> are at least two parts.=0A=0AYes. The O= Caml compilers accept a -pp option to pre-process the source code. This is = how one can create a syntax extension without changing anything to the comp= ilers. Traditionally, the pre-processor parses the code in the extended syn= tax, transforms it back to original syntax (where each extended construct b= ecomes a chunk of code for example), and gives it to the compiler, as an AS= T.=0A=0A> =0A> Is the TryFinally-code slight enough, so that=0A> it's behav= ing like handwritten OCaml? Did you look=0A> at the TryFinally in detail?= =0A=0ALooking at http://martin.jambon.free.fr/pa_tryfinally.ml.html=0A=0ATh= e effect of the EXTEND ... END construct is to extend a syntax entry with r= ules. Here we extend "expr" (the entry for expressions) with a new [ "try";= expr; "finally"; expr ] rule. When Camlp4 parses code using this rule, it = calls the "expand" function.=0A=0AThis function returns <:expr< code writte= n in the revised syntax >>. This is a quotation. Even if you're not familia= r with the revised syntax, I assume you can see the point there: try finall= y will be transformed to=0A"let result =3D try with ... i= n=0Alet () =3D in=0Amatch result with ...".=0A=0AThis= syntax extension must be compiled with something like camlp4orf (original = syntax in the language, revised syntax inside the quotations). camlp4 will = replace each quotation by its equivalent AST representation. Note that the = identifiers between $ are called antiquotations, and insert AST nodes where= used.=0A=0AFor example, "let result =3D try ... in expr" is represented by= something like:=0AExLet (_loc, false, BiEq(_loc, PaId(_loc, IdLid(_loc, re= sult)), ExTry(...)), expr)=0A=0AYou can pre-process code that uses a syntax= extension and pretty-print it in original syntax: "camlp4o -parser TryFina= lly.cmo" file.ml=0AAnd you would see that it is exactly as if you wrote "le= t result =3D ..." everywhere instead of "try finally". The only additional = cost is, as already mentioned, that the parsing is not as fast as using Yac= c. Yet Yacc can hardly dynamically accept new syntaxes, so...=0ACompiling t= he code is done just by using the -pp option: ocamlc -pp "camlp4o -parser T= ryFinally.cmo" file.ml=0A=0A > Oh, well.... that's new to me.=0A> =0A> I ha= d not needed camlp4 so far. And I don't know if it makes sense to=0A> look = at it now, because there will be (or already is?) a replacement=0A> (from 3= .10 on?).=0A=0ACamlp4 has been "partially reimplemented" by Nicolas Pouilla= rd for 3.10 version (as said on caml.inria.fr). Most of these changes requi= red the authors of syntax extensions to update their code so that it would = compile with the new Camlp4. Daniel De Rauglaudre, the author of the origin= al (pre 3.10) Camlp4, thus proposes Camlp5, which can be installed in a tra= nsitional mode to ensure backward compatibility.=0A=0A> =0A> I hope the cam= lp4-tutorial will be updated to the camlp4-replacement.=0A> Possibly later = I might use it. Then it would be good to have=0A> introductional material.= =0A=0ACamlp4 3.10: http://brion.inria.fr/gallium/index.php/Camlp4=0ACamlp5:= http://pauillac.inria.fr/~ddr/camlp5/doc/html/index.html=0A=0A> Ciao,=0A> = Oliver=0A=0A=0AMatthieu=0A=0A=0A=0A _______________________________= ______________________________________________ =0ANe gardez plus qu'une seu= le adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr