caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* weird behavior with camlp4o
@ 2008-04-09  2:45 Andrew I. Schein
  2008-04-09  7:29 ` [Caml-list] " forum
  0 siblings, 1 reply; 7+ messages in thread
From: Andrew I. Schein @ 2008-04-09  2:45 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 348 bytes --]

Greetings list -

I was playing around with OCaml 3.10.2 camlp4o like this:

camlp4o pa_breakcont.cmo sample1.ml

with my macro pa_breakcont.cmo and got the expected macro translation
printed to my terminal.  However, when I type:

camlp4o pa_breakcont.cmo sample1.ml > out.ml

out.ml contains binary output.  Am I misusing camlp4o?

Thanks,

Andy

[-- Attachment #2: Type: text/html, Size: 530 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] weird behavior with camlp4o
  2008-04-09  2:45 weird behavior with camlp4o Andrew I. Schein
@ 2008-04-09  7:29 ` forum
  2008-04-09  7:36   ` Olivier Andrieu
  0 siblings, 1 reply; 7+ messages in thread
From: forum @ 2008-04-09  7:29 UTC (permalink / raw)
  To: caml-list

Selon "Andrew I. Schein" <andrew@andrewschein.com>:

> Greetings list -
>
> I was playing around with OCaml 3.10.2 camlp4o like this:
>
> camlp4o pa_breakcont.cmo sample1.ml
>
> with my macro pa_breakcont.cmo and got the expected macro translation
> printed to my terminal.  However, when I type:
>
> camlp4o pa_breakcont.cmo sample1.ml > out.ml
>
> out.ml contains binary output.  Am I misusing camlp4o?

I have encountered the same problem a few days ago while working on
Ocaml-Java to make it camlp4-compatible.

The fact is that the kind of output (binary dump of abstract tree or
source code in textual form) is chosen according to the nature of the
output file descriptor. If the output file descriptor denotes a tty
then the textual form is chosen, otherwise the binary form is chosen.

That being said, I don't know what is the rationale of this choice,
as I have not come up with a use case for the binary form.


Hope this helps,

Xavier Clerc


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] weird behavior with camlp4o
  2008-04-09  7:29 ` [Caml-list] " forum
@ 2008-04-09  7:36   ` Olivier Andrieu
  2008-04-09  7:48     ` forum
  2008-04-09  7:50     ` Nicolas Pouillard
  0 siblings, 2 replies; 7+ messages in thread
From: Olivier Andrieu @ 2008-04-09  7:36 UTC (permalink / raw)
  To: forum; +Cc: caml-list

On Wed, Apr 9, 2008 at 9:29 AM,  <forum@x9c.fr> wrote:
> Selon "Andrew I. Schein" <andrew@andrewschein.com>:
>  > Greetings list -
>  >
>  > I was playing around with OCaml 3.10.2 camlp4o like this:
>  >
>  > camlp4o pa_breakcont.cmo sample1.ml
>  >
>  > with my macro pa_breakcont.cmo and got the expected macro translation
>  > printed to my terminal.  However, when I type:
>  >
>  > camlp4o pa_breakcont.cmo sample1.ml > out.ml
>  >
>  > out.ml contains binary output.  Am I misusing camlp4o?
>
>  I have encountered the same problem a few days ago while working on
>  Ocaml-Java to make it camlp4-compatible.
>
>  The fact is that the kind of output (binary dump of abstract tree or
>  source code in textual form) is chosen according to the nature of the
>  output file descriptor. If the output file descriptor denotes a tty
>  then the textual form is chosen, otherwise the binary form is chosen.
>
>  That being said, I don't know what is the rationale of this choice,
>  as I have not come up with a use case for the binary form.

It's simply more efficient for ocamlc or ocamlopt when camlp4 is
called via the -pp option: no need to pretty-print and then reparse
the source.

-- 
  Olivier


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] weird behavior with camlp4o
  2008-04-09  7:36   ` Olivier Andrieu
@ 2008-04-09  7:48     ` forum
  2008-04-09  7:52       ` Nicolas Pouillard
  2008-04-09  7:50     ` Nicolas Pouillard
  1 sibling, 1 reply; 7+ messages in thread
From: forum @ 2008-04-09  7:48 UTC (permalink / raw)
  To: caml-list

Selon Olivier Andrieu <oandrieu@gmail.com>:

> On Wed, Apr 9, 2008 at 9:29 AM,  <forum@x9c.fr> wrote:
> > Selon "Andrew I. Schein" <andrew@andrewschein.com>:
> >  > Greetings list -
> >  >
> >  > I was playing around with OCaml 3.10.2 camlp4o like this:
> >  >
> >  > camlp4o pa_breakcont.cmo sample1.ml
> >  >
> >  > with my macro pa_breakcont.cmo and got the expected macro translation
> >  > printed to my terminal.  However, when I type:
> >  >
> >  > camlp4o pa_breakcont.cmo sample1.ml > out.ml
> >  >
> >  > out.ml contains binary output.  Am I misusing camlp4o?
> >
> >  I have encountered the same problem a few days ago while working on
> >  Ocaml-Java to make it camlp4-compatible.
> >
> >  The fact is that the kind of output (binary dump of abstract tree or
> >  source code in textual form) is chosen according to the nature of the
> >  output file descriptor. If the output file descriptor denotes a tty
> >  then the textual form is chosen, otherwise the binary form is chosen.
> >
> >  That being said, I don't know what is the rationale of this choice,
> >  as I have not come up with a use case for the binary form.
>
> It's simply more efficient for ocamlc or ocamlopt when camlp4 is
> called via the -pp option: no need to pretty-print and then reparse
> the source.

Well, this is what I thought at first but, if I am not mistaken, when
you use the '-pp' option of a compiler, a command of the following form
is executed: "camlp4XXX source-file.ml > tmp-file.ml".
Then the "tmp-file.ml" is actually compiled instead of the "source-file.ml".

So, it seems that compilers go through the textual form.


Xavier Clerc


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] weird behavior with camlp4o
  2008-04-09  7:36   ` Olivier Andrieu
  2008-04-09  7:48     ` forum
@ 2008-04-09  7:50     ` Nicolas Pouillard
  1 sibling, 0 replies; 7+ messages in thread
From: Nicolas Pouillard @ 2008-04-09  7:50 UTC (permalink / raw)
  To: Olivier Andrieu; +Cc: xclerc, Caml_mailing list

[-- Attachment #1: Type: text/plain, Size: 1962 bytes --]

It's  more  about  locations  that  efficiency,  if camlp4o was printing OCaml
source code, then the locations will be those of the translated code.

Camlp4  used  to always print by default the binary output. I found this quite
annoying  when  developing Camlp4 extensions because I always forget to give a
proper pretty printer and the binary output just screwed up my terminal.

So Camlp4 now automatically use the pretty-printer when stdout is a tty [1].

However this does not prevent you from reading the little docs about camlp4 :)

Cheers,

[1]: http://brion.inria.fr/gallium/index.php/Using_Camlp4

Excerpts from Olivier Andrieu's message of Wed Apr 09 09:36:40 +0200 2008:
> On Wed, Apr 9, 2008 at 9:29 AM,  <forum@x9c.fr> wrote:
> > Selon "Andrew I. Schein" <andrew@andrewschein.com>:
> >  > Greetings list -
> >  >
> >  > I was playing around with OCaml 3.10.2 camlp4o like this:
> >  >
> >  > camlp4o pa_breakcont.cmo sample1.ml
> >  >
> >  > with my macro pa_breakcont.cmo and got the expected macro translation
> >  > printed to my terminal.  However, when I type:
> >  >
> >  > camlp4o pa_breakcont.cmo sample1.ml > out.ml
> >  >
> >  > out.ml contains binary output.  Am I misusing camlp4o?
> >
> >  I have encountered the same problem a few days ago while working on
> >  Ocaml-Java to make it camlp4-compatible.
> >
> >  The fact is that the kind of output (binary dump of abstract tree or
> >  source code in textual form) is chosen according to the nature of the
> >  output file descriptor. If the output file descriptor denotes a tty
> >  then the textual form is chosen, otherwise the binary form is chosen.
> >
> >  That being said, I don't know what is the rationale of this choice,
> >  as I have not come up with a use case for the binary form.
> 
> It's simply more efficient for ocamlc or ocamlopt when camlp4 is
> called via the -pp option: no need to pretty-print and then reparse
> the source.
> 

-- 
Nicolas Pouillard aka Ertai

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] weird behavior with camlp4o
  2008-04-09  7:48     ` forum
@ 2008-04-09  7:52       ` Nicolas Pouillard
  2008-04-09  8:07         ` forum
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Pouillard @ 2008-04-09  7:52 UTC (permalink / raw)
  To: xclerc; +Cc: Caml_mailing list

[-- Attachment #1: Type: text/plain, Size: 1853 bytes --]

Excerpts from xclerc's message of Wed Apr 09 09:48:22 +0200 2008:
> Selon Olivier Andrieu <oandrieu@gmail.com>:
> 
> > On Wed, Apr 9, 2008 at 9:29 AM,  <forum@x9c.fr> wrote:
> > > Selon "Andrew I. Schein" <andrew@andrewschein.com>:
> > >  > Greetings list -
> > >  >
> > >  > I was playing around with OCaml 3.10.2 camlp4o like this:
> > >  >
> > >  > camlp4o pa_breakcont.cmo sample1.ml
> > >  >
> > >  > with my macro pa_breakcont.cmo and got the expected macro translation
> > >  > printed to my terminal.  However, when I type:
> > >  >
> > >  > camlp4o pa_breakcont.cmo sample1.ml > out.ml
> > >  >
> > >  > out.ml contains binary output.  Am I misusing camlp4o?
> > >
> > >  I have encountered the same problem a few days ago while working on
> > >  Ocaml-Java to make it camlp4-compatible.
> > >
> > >  The fact is that the kind of output (binary dump of abstract tree or
> > >  source code in textual form) is chosen according to the nature of the
> > >  output file descriptor. If the output file descriptor denotes a tty
> > >  then the textual form is chosen, otherwise the binary form is chosen.
> > >
> > >  That being said, I don't know what is the rationale of this choice,
> > >  as I have not come up with a use case for the binary form.
> >
> > It's simply more efficient for ocamlc or ocamlopt when camlp4 is
> > called via the -pp option: no need to pretty-print and then reparse
> > the source.
> 
> Well, this is what I thought at first but, if I am not mistaken, when
> you use the '-pp' option of a compiler, a command of the following form
> is executed: "camlp4XXX source-file.ml > tmp-file.ml".
> Then the "tmp-file.ml" is actually compiled instead of the "source-file.ml".
> 
> So, it seems that compilers go through the textual form.

Nop, the compiler knows both binary and textual formats.

-- 
Nicolas Pouillard aka Ertai

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] weird behavior with camlp4o
  2008-04-09  7:52       ` Nicolas Pouillard
@ 2008-04-09  8:07         ` forum
  0 siblings, 0 replies; 7+ messages in thread
From: forum @ 2008-04-09  8:07 UTC (permalink / raw)
  To: Caml_mailing list

Selon Nicolas Pouillard <nicolas.pouillard@gmail.com>:

> Excerpts from xclerc's message of Wed Apr 09 09:48:22 +0200 2008:
> > Selon Olivier Andrieu <oandrieu@gmail.com>:
> >
> > > On Wed, Apr 9, 2008 at 9:29 AM,  <forum@x9c.fr> wrote:
> > > > Selon "Andrew I. Schein" <andrew@andrewschein.com>:
> > > >  > Greetings list -
> > > >  >
> > > >  > I was playing around with OCaml 3.10.2 camlp4o like this:
> > > >  >
> > > >  > camlp4o pa_breakcont.cmo sample1.ml
> > > >  >
> > > >  > with my macro pa_breakcont.cmo and got the expected macro
> translation
> > > >  > printed to my terminal.  However, when I type:
> > > >  >
> > > >  > camlp4o pa_breakcont.cmo sample1.ml > out.ml
> > > >  >
> > > >  > out.ml contains binary output.  Am I misusing camlp4o?
> > > >
> > > >  I have encountered the same problem a few days ago while working on
> > > >  Ocaml-Java to make it camlp4-compatible.
> > > >
> > > >  The fact is that the kind of output (binary dump of abstract tree or
> > > >  source code in textual form) is chosen according to the nature of the
> > > >  output file descriptor. If the output file descriptor denotes a tty
> > > >  then the textual form is chosen, otherwise the binary form is chosen.
> > > >
> > > >  That being said, I don't know what is the rationale of this choice,
> > > >  as I have not come up with a use case for the binary form.
> > >
> > > It's simply more efficient for ocamlc or ocamlopt when camlp4 is
> > > called via the -pp option: no need to pretty-print and then reparse
> > > the source.
> >
> > Well, this is what I thought at first but, if I am not mistaken, when
> > you use the '-pp' option of a compiler, a command of the following form
> > is executed: "camlp4XXX source-file.ml > tmp-file.ml".
> > Then the "tmp-file.ml" is actually compiled instead of the
> "source-file.ml".
> >
> > So, it seems that compilers go through the textual form.
>
> Nop, the compiler knows both binary and textual formats.

My mistake. Sorry for the noise.
In fact, I mixed up the actual behaviour of camlp4 with the awful
hack I set up to make OCaml-Java camlp4-aware. As I don't know any
pure-Java way to know if a file descriptor denotes a tty, I just
pretend that descriptor "1" is always a tty. As a consequence, camlp4
(when run by OCaml-Java) always outputs the textual form. This in turn
implies that compilers using the '-pp' option will go through the
textual form.

This seemed to work like a charm but I totally missed the location problem
you point out. This should make me craft another hack ...
Thanks for the information.


Xavier Clerc

PS: the 'camlp4' patches for OCaml-Java are not currently applied to the
released version
PPS: if anyone knows a reliable pure-Java way to determine if a Java output
stream is related to a tty, I would just avoid a terrible hack ...


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2008-04-09  8:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-09  2:45 weird behavior with camlp4o Andrew I. Schein
2008-04-09  7:29 ` [Caml-list] " forum
2008-04-09  7:36   ` Olivier Andrieu
2008-04-09  7:48     ` forum
2008-04-09  7:52       ` Nicolas Pouillard
2008-04-09  8:07         ` forum
2008-04-09  7:50     ` Nicolas Pouillard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).