caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] OCamlMakefile mly/mll interdependency
@ 2003-08-26  0:40 Jeff Henrikson
  2003-08-27 10:01 ` Markus Mottl
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Henrikson @ 2003-08-26  0:40 UTC (permalink / raw)
  To: caml-list


To help me with the aforementioned release, anybody want to help me 
figure out why my OCamlMakefile isn't doing well on compling frontc?  
No ordering of the source files seems to work:


> ocamlc -c cabs.mli
> ocamlc -c cabs.ml
> ocamlc -c cparser.mli
> ocamlc -c clexer.ml
> File "clexer.mll", line 378, characters 1-16:
> Warning: this expression should have type unit.
> ocamlc -c cparser.ml
> ocamlc -c frontc.mli
> ocamlc -c frontc.ml
> ocamlc -c cprint.mli
> ocamlc -c cprint.ml
> ocamlc -a             \
>                           -o frontc.cma  cabs.cmo cparser.cmo 
> clexer.cmo frontc.cmo cprint.cmo


However, when I run a toplevel


> bash on ttyp4, ~/src/forklift/frontc$ ocaml
>         Objective Caml version 3.06
>
> # #load "frontc.cma";;
> Reference to undefined global `Clexer'
> #


I can work around by shelling this:


> ocamlc -a                                       -o frontc.cma  
> cabs.cmo clexer.cmo cparser.cmo frontc.cmo cprint.cmo


But if I try to correct this in the Makefile:


> OCAMLMAKEFILE = OCamlMakefile
>
> SOURCES =  cabs.ml clexer.mll cparser.mly frontc.ml cprint.ml cabs.mli 
> cprint.m\
> li frontc.mli
> RESULT = frontc
> all: byte-code-library
>
> -include $(OCAMLMAKEFILE)


Then it causes the build to break:


> bash on ttyp4, ~/src/forklift/frontc$ make
> ocamllex clexer.mll
> 125 states, 1674 transitions, table size 7446 bytes
> ocamlyacc  cparser.mly
> making ._bcdi/cparser.di from cparser.mli
> making ._bcdi/frontc.di from frontc.mli
> making ._bcdi/cprint.di from cprint.mli
> making ._bcdi/cabs.di from cabs.mli
> making ._d/cparser.d from cparser.ml
> making ._d/clexer.d from clexer.ml
> making ._d/cprint.d from cprint.ml
> making ._d/frontc.d from frontc.ml
> making ._d/cabs.d from cabs.ml
> ocamlc -c cabs.mli
> ocamlc -c cabs.ml
> ocamlc -c clexer.ml
> File "clexer.mll", line 22, characters 0-12:
> Unbound module Cparser
> make[1]: *** [clexer.cmi] Error 2
> make: *** [byte-code-library] Error 2


Thanks for any help,


Jeff Henrikson

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] OCamlMakefile mly/mll interdependency
  2003-08-26  0:40 [Caml-list] OCamlMakefile mly/mll interdependency Jeff Henrikson
@ 2003-08-27 10:01 ` Markus Mottl
  2003-08-27 18:27   ` [Caml-list] Re: cyclic modules (was: OCamlMakefile mly/mll interdependency) Michal Moskal
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Mottl @ 2003-08-27 10:01 UTC (permalink / raw)
  To: Jeff Henrikson; +Cc: caml-list

On Mon, 25 Aug 2003, Jeff Henrikson wrote:
> To help me with the aforementioned release, anybody want to help me 
> figure out why my OCamlMakefile isn't doing well on compling frontc?  
> No ordering of the source files seems to work:

This is not really surprising: module Clexer references module Cparser
and vice versa! You cannot have recursion between modules.

Since the lexer always depends on the parser, because the latter declares
tokens that the lexer returns, the parser must always be compiled before
the lexer.

Therefore, you'll have to factor out all code from the lexer that is
referenced by the parser and put it into a separate module, which you
have to compile before the parser (and by transitivity before the lexer).

Regards,
Markus Mottl

-- 
Markus Mottl          http://www.oefai.at/~markus          markus@oefai.at

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* [Caml-list] Re: cyclic modules (was: OCamlMakefile mly/mll interdependency)
  2003-08-27 10:01 ` Markus Mottl
@ 2003-08-27 18:27   ` Michal Moskal
  2003-08-27 18:53     ` Ville-Pertti Keinonen
  0 siblings, 1 reply; 5+ messages in thread
From: Michal Moskal @ 2003-08-27 18:27 UTC (permalink / raw)
  To: caml-list; +Cc: Jeff Henrikson

On Wed, Aug 27, 2003 at 12:01:25PM +0200, Markus Mottl wrote:
> On Mon, 25 Aug 2003, Jeff Henrikson wrote:
> > To help me with the aforementioned release, anybody want to help me 
> > figure out why my OCamlMakefile isn't doing well on compling frontc?  
> > No ordering of the source files seems to work:
> 
> This is not really surprising: module Clexer references module Cparser
> and vice versa! You cannot have recursion between modules.
> 
> Since the lexer always depends on the parser, because the latter declares
> tokens that the lexer returns, the parser must always be compiled before
> the lexer.
> 
> Therefore, you'll have to factor out all code from the lexer that is
> referenced by the parser and put it into a separate module, which you
> have to compile before the parser (and by transitivity before the lexer).

Well, I don't know if it's intensional, but OCaml allows one to have
cyclic modules if you only use *types*, not values. For example:

[malekith@roke t]$ cat a.mli
type t = C
val f : unit -> bool
[malekith@roke t]$ cat a.ml 
type t = C
let f () = B.v
[malekith@roke t]$ cat b.mli
val v : bool
[malekith@roke t]$ cat b.ml 
let v = (A.C == A.C)
[malekith@roke t]$ ocamlc -c a.mli
[malekith@roke t]$ ocamlc -c b.mli
[malekith@roke t]$ ocamlc -c a.ml 
[malekith@roke t]$ ocamlc -c b.ml
[malekith@roke t]$ ocamlc b.cmo a.cmo
[malekith@roke t]$ 

-- 
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Re: cyclic modules (was: OCamlMakefile mly/mll interdependency)
  2003-08-27 18:27   ` [Caml-list] Re: cyclic modules (was: OCamlMakefile mly/mll interdependency) Michal Moskal
@ 2003-08-27 18:53     ` Ville-Pertti Keinonen
  2003-08-27 19:03       ` Ville-Pertti Keinonen
  0 siblings, 1 reply; 5+ messages in thread
From: Ville-Pertti Keinonen @ 2003-08-27 18:53 UTC (permalink / raw)
  To: caml-list, Jeff Henrikson

> Well, I don't know if it's intensional, but OCaml allows one to have
> cyclic modules if you only use *types*, not values. For example:

 ...

> [malekith@roke t]$ ocamlc -c a.mli
> [malekith@roke t]$ ocamlc -c b.mli
> [malekith@roke t]$ ocamlc -c a.ml 
> [malekith@roke t]$ ocamlc -c b.ml
> [malekith@roke t]$ ocamlc b.cmo a.cmo

This works because a.ml depends on b.mli (b.cmi), which was compiled
before a.ml, but not b.ml (b.cmo).

You still can't have cyclic dependencies between a.mli and b.mli or
a.ml and b.ml.

It doesn't limit the dependency problem because the same effect could
always be achieved by defining the types in a separate module.

For types, it might be easier to actually allow cyclic dependencies,
at least the side-effects ordering problem doesn't apply.  However I
don't think it would fit well with the current compilation model.  As
far as I understand, the compiler never reads source files other than
the one being compiled, all external information is from
.cmi/.cmo/.cmx files.

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

* Re: [Caml-list] Re: cyclic modules (was: OCamlMakefile mly/mll interdependency)
  2003-08-27 18:53     ` Ville-Pertti Keinonen
@ 2003-08-27 19:03       ` Ville-Pertti Keinonen
  0 siblings, 0 replies; 5+ messages in thread
From: Ville-Pertti Keinonen @ 2003-08-27 19:03 UTC (permalink / raw)
  To: caml-list

> This works because a.ml depends on b.mli (b.cmi), which was compiled
> before a.ml, but not b.ml (b.cmo).

Correcting myself - swap a and b and that makes more sense...

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2003-08-27 19:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-26  0:40 [Caml-list] OCamlMakefile mly/mll interdependency Jeff Henrikson
2003-08-27 10:01 ` Markus Mottl
2003-08-27 18:27   ` [Caml-list] Re: cyclic modules (was: OCamlMakefile mly/mll interdependency) Michal Moskal
2003-08-27 18:53     ` Ville-Pertti Keinonen
2003-08-27 19:03       ` Ville-Pertti Keinonen

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