Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Matthieu Wipliez <mwipliez@yahoo.fr>
To: caml-list@yquem.inria.fr
Subject: Re : [Caml-list] Ask for a more efficient way to deallocate memory (full version)
Date: Sun, 16 Dec 2007 12:52:28 +0000 (GMT)	[thread overview]
Message-ID: <273947.94856.qm@web27010.mail.ukl.yahoo.com> (raw)

Oliver Bandel <oliver@first.in-berlin.de>:
> 
> 
 > So, is it just a kind of pre-compilation?
> The core-OCaml compiler will be the same?
...
> I have not looked at the OCaml-compiler in detail,
> but from what you wrote I would assume, there
> are at least two parts.

Yes. The OCaml 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 compilers. Traditionally, the pre-processor parses the code in the extended syntax, transforms it back to original syntax (where each extended construct becomes a chunk of code for example), and gives it to the compiler, as an AST.

> 
> Is the TryFinally-code slight enough, so that
> it's behaving like handwritten OCaml? Did you look
> at the TryFinally in detail?

Looking at http://martin.jambon.free.fr/pa_tryfinally.ml.html

The effect of the EXTEND ... END construct is to extend a syntax entry with rules. 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.

This function returns <:expr< code written in the revised syntax >>. This is a quotation. Even if you're not familiar with the revised syntax, I assume you can see the point there: try finally will be transformed to
"let result = try <body of the try> with ... in
let () = <body of the finally> in
match result with ...".

This 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.

For example, "let result = try ... in expr" is represented by something like:
ExLet (_loc, false, BiEq(_loc, PaId(_loc, IdLid(_loc, result)), ExTry(...)), expr)

You can pre-process code that uses a syntax extension and pretty-print it in original syntax: "camlp4o -parser TryFinally.cmo" file.ml
And you would see that it is exactly as if you wrote "let result = ..." everywhere instead of "try finally". The only additional cost is, as already mentioned, that the parsing is not as fast as using Yacc. Yet Yacc can hardly dynamically accept new syntaxes, so...
Compiling the code is done just by using the -pp option: ocamlc -pp "camlp4o -parser TryFinally.cmo" file.ml

 > Oh, well.... that's new to me.
> 
> I had not needed camlp4 so far. And I don't know if it makes sense to
> look at it now, because there will be (or already is?) a replacement
> (from 3.10 on?).

Camlp4 has been "partially reimplemented" by Nicolas Pouillard for 3.10 version (as said on caml.inria.fr). Most of these changes required 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 original (pre 3.10) Camlp4, thus proposes Camlp5, which can be installed in a transitional mode to ensure backward compatibility.

> 
> I hope the camlp4-tutorial will be updated to the camlp4-replacement.
> Possibly later I might use it. Then it would be good to have
> introductional material.

Camlp4 3.10: http://brion.inria.fr/gallium/index.php/Camlp4
Camlp5: http://pauillac.inria.fr/~ddr/camlp5/doc/html/index.html

> Ciao,
>    Oliver


Matthieu



      _____________________________________________________________________________ 
Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail http://mail.yahoo.fr


             reply	other threads:[~2007-12-16 12:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-16 12:52 Matthieu Wipliez [this message]
  -- strict thread matches above, loose matches on Subject: below --
2007-12-11  9:56 Matthieu Wipliez

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=273947.94856.qm@web27010.mail.ukl.yahoo.com \
    --to=mwipliez@yahoo.fr \
    --cc=caml-list@yquem.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