caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Camlp4 generate more than one (compiled) files?
@ 2008-10-17 11:15 Conglun Yao
  2008-10-17 11:52 ` [Caml-list] " Richard Jones
  0 siblings, 1 reply; 3+ messages in thread
From: Conglun Yao @ 2008-10-17 11:15 UTC (permalink / raw)
  To: caml-list

Dear all,

I'm just wondering is it possible to use camlp4 to generate more than
one compiled files.
Normally, camlp4 preprocesses a file and then pass it directly to
compiler (for *.cmo),  or its pretty-printer (for *.ml or other
'plain' file).

In my case, I want to extend the syntax, and write a file, then
preprocess (camlp4) it to generate two different *.cmo files, each one
could be executed separately.

Is it possible?

Thanks,
Conglun


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

* Re: [Caml-list] Camlp4 generate more than one (compiled) files?
  2008-10-17 11:15 Camlp4 generate more than one (compiled) files? Conglun Yao
@ 2008-10-17 11:52 ` Richard Jones
  2008-10-17 13:00   ` Conglun Yao
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Jones @ 2008-10-17 11:52 UTC (permalink / raw)
  To: Conglun Yao; +Cc: caml-list

On Fri, Oct 17, 2008 at 12:15:08PM +0100, Conglun Yao wrote:
> I'm just wondering is it possible to use camlp4 to generate more than
> one compiled files.
> Normally, camlp4 preprocesses a file and then pass it directly to
> compiler (for *.cmo),  or its pretty-printer (for *.ml or other
> 'plain' file).
> 
> In my case, I want to extend the syntax, and write a file, then
> preprocess (camlp4) it to generate two different *.cmo files, each one
> could be executed separately.
> 
> Is it possible?

Camlp4 extensions can open and write files normally.  However it
doesn't have access to crucial details of the 'OCaml environment' such
as the current search path for libraries, which means that it usually
cannot do anything sensible.

For example, I wanted to load another module/library from a camlp4
extension - but that sort of thing isn't possible as far as I can
tell.

I wrote a bit more about this issue here:

http://camltastic.blogspot.com/2008/05/persistent-matches-in-pabitmatch.html

Rich.

-- 
Richard Jones
Red Hat


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

* Re: [Caml-list] Camlp4 generate more than one (compiled) files?
  2008-10-17 11:52 ` [Caml-list] " Richard Jones
@ 2008-10-17 13:00   ` Conglun Yao
  0 siblings, 0 replies; 3+ messages in thread
From: Conglun Yao @ 2008-10-17 13:00 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list

Rich,

Thanks for your reply.

What you mentioned in your blog:

In fact saving the AST into the cmo file is relatively simple: we just
turn it into a string (using Marshal) and write out the string as a
camlp4 substitution:
let bitmatch ext2sb = { ... }

becomes: let ext2sb = "<string containing marshalled representation of AST>"

If I understand correctly, the translated ext2sb would be kept in the
same cmo file(where the ext2sb is defined in the extended syntax),
rather than an additional (new) cmo file.

Currently I'm facing the problem that write a single file in extended
syntax, then camlp4 it into two different  cmo files.

e.g.   in extendFile.ml, we define a type t

type myextend t =  * type definition in my extended syntax *

then I want to translate it into:

extendFile.cmo:

   type t =  * standard ocaml type definition *

  module T  and some t-related functions

and another file newFile.cmo :

   some functions which doesn't rely on type t,
   like checking the existence of some files (name mentioned in type
t's definition)

I know it's possible to generate the latter functions and pretty-print
them into newFile.ml, but don't know how to get a compiled cmo file
directly.

Conglun




Conglun

On Fri, Oct 17, 2008 at 12:52 PM, Richard Jones <rich@annexia.org> wrote:

> Camlp4 extensions can open and write files normally.  However it
> doesn't have access to crucial details of the 'OCaml environment' such
> as the current search path for libraries, which means that it usually
> cannot do anything sensible.
>
> For example, I wanted to load another module/library from a camlp4
> extension - but that sort of thing isn't possible as far as I can
> tell.
>
> I wrote a bit more about this issue here:
>
> http://camltastic.blogspot.com/2008/05/persistent-matches-in-pabitmatch.html
>
> Rich.
>
> --
> Richard Jones
> Red Hat
>


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

end of thread, other threads:[~2008-10-17 13:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-17 11:15 Camlp4 generate more than one (compiled) files? Conglun Yao
2008-10-17 11:52 ` [Caml-list] " Richard Jones
2008-10-17 13:00   ` Conglun Yao

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