caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* building executables with camlp4
@ 2007-06-13 10:47 Jeremy Yallop
  2007-06-13 12:23 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremy Yallop @ 2007-06-13 10:47 UTC (permalink / raw)
  To: caml-list

With the 3.09 version of camlp4 I could build an executable for my 
extension by linking against various .cmx files.  Is it possible to do 
something similar with the new camlp4 in 3.10?  I've tried linking with

    camlp4lib.cmxa
    Camlp4Parsers/Camlp4OCamlRevisedParser.cmx
    Camlp4Parsers/Camlp4OCamlParser.cmx
    Camlp4Printers/Camlp4OCamlRevisedPrinter.cmx
    Camlp4Printers/Camlp4OCamlPrinter.cmx

which results in an executable that fails with Not_found when run, 
apparently due to a failure to delete a rule from the grammar.  Building 
a set of bytecode (.cmo) files and loading them with camlp4o works as 
expected.

In case it makes things simpler I'm using OCamlMakefile,

Jeremy.


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

* Re: [Caml-list] building executables with camlp4
  2007-06-13 10:47 building executables with camlp4 Jeremy Yallop
@ 2007-06-13 12:23 ` Nicolas Pouillard
  2007-06-13 13:12   ` Jeremy Yallop
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Pouillard @ 2007-06-13 12:23 UTC (permalink / raw)
  To: Jeremy Yallop; +Cc: caml-list

On 6/13/07, Jeremy Yallop <jeremy.yallop@ed.ac.uk> wrote:
> With the 3.09 version of camlp4 I could build an executable for my
> extension by linking against various .cmx files.  Is it possible to do
> something similar with the new camlp4 in 3.10?  I've tried linking with

Yes

>
>     camlp4lib.cmxa

A good starting point

>     Camlp4Parsers/Camlp4OCamlRevisedParser.cmx
>     Camlp4Parsers/Camlp4OCamlParser.cmx
>     Camlp4Printers/Camlp4OCamlRevisedPrinter.cmx

Why not

>     Camlp4Printers/Camlp4OCamlPrinter.cmx

This is indeed useless, the real printer is in the Camlp4 package, and
Camlp4Printers/Camlp4OCamlPrinter is a dummy module to enable it.

It really depends on what you want to do, if you want to build your
own camlp4 (using Camlp4Bin) then you are in the good path (don't miss
unix, and -linkall).
If you want use camlp4 as a library and then certainly don't rely on
the Camlp4.Register module you can try camlp4fullib.cmxa.

[...]

> In case it makes things simpler I'm using OCamlMakefile,

Not specially.

-- 
Nicolas Pouillard


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

* Re: [Caml-list] building executables with camlp4
  2007-06-13 12:23 ` [Caml-list] " Nicolas Pouillard
@ 2007-06-13 13:12   ` Jeremy Yallop
  2007-06-13 13:27     ` Nicolas Pouillard
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremy Yallop @ 2007-06-13 13:12 UTC (permalink / raw)
  To: caml-list

Thanks for the help, Nicolas.  I think I'm getting somewhere.  I no
longer get Not_found, but now my grammar extension doesn't seem to be
activated.

Here's a fairly minimal example:

File minimal.ml:

     open Camlp4.PreCast.Syntax

     DELETE_RULE Gram str_item: "type"; type_declaration END

     EXTEND Gram
     str_item:
     [[ "type"; types = type_declaration ->
           <:str_item< type $types$ >>
      | "type"; types = type_declaration;
        "premiums" ; "(" ; "squigglier" ; ")" ->
           prerr_endline "squigglier!";
           <:str_item< type $types$ >>  ]];
     END

File input.ml:

     type x = int premiums ( squigglier )

This works:

      $ ocamlc -c -pp camlp4of  \
        -I /usr/local/ocaml/lib/ocaml/camlp4 minimal.ml
      $ camlp4o minimal.cmo input.ml
      squigglier!
      type x = int

But this doesn't:

      $ ocamlc -g -linkall -I /usr/local/ocaml/lib/ocaml/camlp4  \
        -o minimal \
        camlp4lib.cma \
        unix.cma \
        Camlp4Parsers/Camlp4OCamlRevisedParser.cmo \
        Camlp4Parsers/Camlp4OCamlParser.cmo \
        Camlp4Printers/Camlp4OCamlPrinter.cmo \
        Camlp4Bin.cmo \
        minimal.cmo
      $ ./minimal input.ml
      File "input.ml", line 1, characters 35-36:
      Parse error: ident_of_ctyp: this type is not an identifier

What should my linking command be for this to work?

Jeremy.


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

* Re: [Caml-list] building executables with camlp4
  2007-06-13 13:12   ` Jeremy Yallop
@ 2007-06-13 13:27     ` Nicolas Pouillard
  2007-06-13 13:27       ` Jeremy Yallop
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Pouillard @ 2007-06-13 13:27 UTC (permalink / raw)
  To: Jeremy Yallop; +Cc: caml-list

> But this doesn't:
>
>       $ ocamlc -g -linkall -I /usr/local/ocaml/lib/ocaml/camlp4  \
>         -o minimal \
>         camlp4lib.cma \
>         unix.cma \
>         Camlp4Parsers/Camlp4OCamlRevisedParser.cmo \
>         Camlp4Parsers/Camlp4OCamlParser.cmo \
>         Camlp4Printers/Camlp4OCamlPrinter.cmo \
>         Camlp4Bin.cmo \
>         minimal.cmo
>       $ ./minimal input.ml
>       File "input.ml", line 1, characters 35-36:
>       Parse error: ident_of_ctyp: this type is not an identifier
>

Try to put Camlp4Bin before minimal, since it's the main so the init
section of this module is the starting point.

-- 
Nicolas Pouillard


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

* Re: [Caml-list] building executables with camlp4
  2007-06-13 13:27     ` Nicolas Pouillard
@ 2007-06-13 13:27       ` Jeremy Yallop
  2007-06-13 13:45         ` Nicolas Pouillard
  0 siblings, 1 reply; 7+ messages in thread
From: Jeremy Yallop @ 2007-06-13 13:27 UTC (permalink / raw)
  To: caml-list

Nicolas Pouillard wrote:
>> But this doesn't:
>>
>>       $ ocamlc -g -linkall -I /usr/local/ocaml/lib/ocaml/camlp4  \
>>         -o minimal \
>>         camlp4lib.cma \
>>         unix.cma \
>>         Camlp4Parsers/Camlp4OCamlRevisedParser.cmo \
>>         Camlp4Parsers/Camlp4OCamlParser.cmo \
>>         Camlp4Printers/Camlp4OCamlPrinter.cmo \
>>         Camlp4Bin.cmo \
>>         minimal.cmo
>>       $ ./minimal input.ml
>>       File "input.ml", line 1, characters 35-36:
>>       Parse error: ident_of_ctyp: this type is not an identifier
> 
> Try to put Camlp4Bin before minimal, since it's the main so the init
> section of this module is the starting point.

Sorry, I don't follow.  Camlp4Bin is before minimal above, right?  If I 
reverse the order of Camlp4Bin.cmo and minimal.cmo I get Not_found 
errors again when I run the program.

Jeremy.


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

* Re: [Caml-list] building executables with camlp4
  2007-06-13 13:27       ` Jeremy Yallop
@ 2007-06-13 13:45         ` Nicolas Pouillard
  2007-06-13 14:07           ` Jeremy Yallop
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Pouillard @ 2007-06-13 13:45 UTC (permalink / raw)
  To: Jeremy Yallop; +Cc: caml-list

On 6/13/07, Jeremy Yallop <jeremy.yallop@ed.ac.uk> wrote:
> Nicolas Pouillard wrote:
> >> But this doesn't:
> >>
> >>       $ ocamlc -g -linkall -I /usr/local/ocaml/lib/ocaml/camlp4  \
> >>         -o minimal \
> >>         camlp4lib.cma \
> >>         unix.cma \
> >>         Camlp4Parsers/Camlp4OCamlRevisedParser.cmo \
> >>         Camlp4Parsers/Camlp4OCamlParser.cmo \
> >>         Camlp4Printers/Camlp4OCamlPrinter.cmo \
> >>         Camlp4Bin.cmo \
> >>         minimal.cmo
> >>       $ ./minimal input.ml
> >>       File "input.ml", line 1, characters 35-36:
> >>       Parse error: ident_of_ctyp: this type is not an identifier
> >
> > Try to put Camlp4Bin before minimal, since it's the main so the init
> > section of this module is the starting point.
>
> Sorry, I don't follow.  Camlp4Bin is before minimal above, right?  If I
> reverse the order of Camlp4Bin.cmo and minimal.cmo I get Not_found
> errors again when I run the program.
>

Hum, sorry for my very confusing previous answer. I thought "Camlp4Bin
*after* minimal". But you've tried that.

After thinking a little more, I can explain what's happening there is
two modes to get into Camlp4 pipeline. The first one is through
registration and the second one is through dyn-linking of cmo files on
the command line.

Here your Minimal module is neither on the command line nor registered.

To register it make a functor around your grammar extension and call
Camlp4.Register.OCamlSyntaxExtension.

-- 
Nicolas Pouillard


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

* Re: [Caml-list] building executables with camlp4
  2007-06-13 13:45         ` Nicolas Pouillard
@ 2007-06-13 14:07           ` Jeremy Yallop
  0 siblings, 0 replies; 7+ messages in thread
From: Jeremy Yallop @ 2007-06-13 14:07 UTC (permalink / raw)
  To: caml-list

Nicolas Pouillard wrote:
> After thinking a little more, I can explain what's happening there is
> two modes to get into Camlp4 pipeline. The first one is through
> registration and the second one is through dyn-linking of cmo files on
> the command line.
> 
> Here your Minimal module is neither on the command line nor registered.
> 
> To register it make a functor around your grammar extension and call
> Camlp4.Register.OCamlSyntaxExtension.

Thanks, Nicolas!  Everything's working now.  In case anyone else wants
to do something similar, here's the fully working example:

minimal.ml:
    open Camlp4.PreCast

    module Id : Camlp4.Sig.Id =
    struct
      let name = "minimal"
      let version = "1.0"
    end

    module Extension (Syntax : Camlp4.Sig.Camlp4Syntax) =
    struct
      include Syntax

      DELETE_RULE Gram str_item: "type"; type_declaration END

        EXTEND Gram
        str_item:
        [[ "type"; types = type_declaration ->
             <:str_item< type $types$ >>
         | "type"; types = type_declaration;
           "premiums" ; "(" ; "squigglier" ; ")" ->
             prerr_endline "squigglier!";
           <:str_item< type $types$ >>
        ]];
      END
    end

    module M = Camlp4.Register.OCamlSyntaxExtension(Id)(Extension)

File input.ml:

     type x = int premiums ( squigglier )

Building:

     $ ocamlc -c -pp camlp4of  -I /usr/local/ocaml/lib/ocaml/camlp4 
minimal.ml
     $ ocamlc -g -linkall -I /usr/local/ocaml/lib/ocaml/camlp4 \
        -o minimal                                             \
        camlp4lib.cma                                          \
        unix.cma                                               \
        Camlp4Parsers/Camlp4OCamlRevisedParser.cmo             \
        Camlp4Parsers/Camlp4OCamlParser.cmo                    \
        Camlp4Printers/Camlp4OCamlPrinter.cmo                  \
        minimal.cmo                                            \
        Camlp4Bin.cmo

Running:

     $ ./minimal input.ml
     squigglier!
     type x = int

Jeremy.


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

end of thread, other threads:[~2007-06-13 14:14 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-13 10:47 building executables with camlp4 Jeremy Yallop
2007-06-13 12:23 ` [Caml-list] " Nicolas Pouillard
2007-06-13 13:12   ` Jeremy Yallop
2007-06-13 13:27     ` Nicolas Pouillard
2007-06-13 13:27       ` Jeremy Yallop
2007-06-13 13:45         ` Nicolas Pouillard
2007-06-13 14:07           ` Jeremy Yallop

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