Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke OCaml compiler to just produce .cmi

maybe I'm just failing in a really simple thing but I'm developing an intepreter written in OCaml with standard tools as ocamllex and ocamlyacc and I have this situation:

  • iparser.mly contains parser spec
  • ilexer.mll contains lexer spec
  • impossible.ml contains the vm that executes the code and all the types needed

The instruction type that defines various instructions is in impossible.ml and it is needed by the parser but impossible.ml uses the parser defined in iparser.mly so they both need each other to compile correctly.

Is there a way to produce just the .cmi file for my impossible.ml? In this way the parser would know about types defined in impossible.ml and it will allow me to compile impossible.cmo/.cmi and later compile also impossible.cmo. Then I can link all of them together.

So far my compiling script is:

ocamlyacc iparser.mly
ocamlc -c iparser.mli
ocamllex ilexer.mll
ocamlc -c ilexer.ml
ocamlc -c iparser.ml
ocamlc -c impossible.ml
ocamlc -o imp.exe ilexer.cmo iparser.cmo impossible.cmo

but this doesn't work because ocamlc -c iparser.ml needs at least impossible.cmi to know the types.

Any suggestions? Thanks in advance..

like image 888
Jack Avatar asked Jun 30 '10 15:06

Jack


2 Answers

You need to create an impossible.mli and compile that. That will produce the impossible.cmi and only the .cmi.

Alternatively:

ocamlc -i impossible.ml

will print the mli to stdout. You could do something like this:

ocamlc -i impossible.ml > impossible.mli
ocamlc -c impossible.mli
like image 125
Niki Yoshiuchi Avatar answered Sep 27 '22 19:09

Niki Yoshiuchi


IMHO, you cannot legitimately compile recursively-dependant modules this way. Either factor out the interdependencies in the third module (usually easy), or pass them as parameters (or mutable initialization references - ugly), or use recursive modules.

like image 24
ygrek Avatar answered Sep 27 '22 18:09

ygrek