caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Compiling a native code OCaml library into an .so?
@ 2003-11-19 23:49 Aleksey Nogin
  2003-11-20  3:33 ` Kamil Shakirov
  0 siblings, 1 reply; 9+ messages in thread
From: Aleksey Nogin @ 2003-11-19 23:49 UTC (permalink / raw)
  To: caml-list

Hello all,

I am wondering - is it possible to compile a native code OCaml library 
into an dynamic library (.so) and then link an OCaml program against it, 
or dynamically load it from an OCaml program?

My (very shallow) understanding of how this is supposed to work suggests 
that it should not be too hard to implement (at least if we do not 
insist on detecting version mismatches at runtime). We would need:

1) A flag to ocamlopt that would tell it to compile to ".cmxa + .so" 
instead of ".cmxa + .a". Given such a flag, ocamlopt would
   a) Create an assembly file defining _init function that would call 
the initialization functions of all the modules and add that file to the 
list of things to be compiled in.
   b) Add -shared flag to the ld call.

2) When compiling a program with ocamlopt, if one of the arguments is a 
.cmxa, then look for both .a and .so and pass the right one to ld.

3) Have a function somewhere (Dynlink module?) that's a wrapper for the 
C's dlopen function.

4) Ideally - have a function somewhere (Dynlink module?) that would try 
loading a .cma when running in bytecode and would try loading an .so 
when running in native code.

Am I missing any serious difficulties here? Are there any plans to add 
something like this to OCaml?

-- 
Aleksey Nogin

Home Page: http://nogin.org/
E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal)
Office: Jorgensen 70, tel: (626) 395-2907

-------------------
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] 9+ messages in thread

* Re: [Caml-list] Compiling a native code OCaml library into an .so?
  2003-11-19 23:49 [Caml-list] Compiling a native code OCaml library into an .so? Aleksey Nogin
@ 2003-11-20  3:33 ` Kamil Shakirov
  2003-11-20  4:57   ` Aleksey Nogin
  2003-11-20 11:13   ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
  0 siblings, 2 replies; 9+ messages in thread
From: Kamil Shakirov @ 2003-11-20  3:33 UTC (permalink / raw)
  To: caml-list, onlynews

Hello,

> I am wondering - is it possible to compile a native code OCaml library 
> into an dynamic library (.so) and then link an OCaml program against it, 
> or dynamically load it from an OCaml program?
> 
> My (very shallow) understanding of how this is supposed to work suggests 
> that it should not be too hard to implement (at least if we do not 
> insist on detecting version mismatches at runtime). We would need:
> 
> 1) A flag to ocamlopt that would tell it to compile to ".cmxa + .so" 
> instead of ".cmxa + .a". Given such a flag, ocamlopt would
>    a) Create an assembly file defining _init function that would call 
> the initialization functions of all the modules and add that file to the 
> list of things to be compiled in.
>    b) Add -shared flag to the ld call.
> 
> 2) When compiling a program with ocamlopt, if one of the arguments is a 
> .cmxa, then look for both .a and .so and pass the right one to ld.
> 
> 3) Have a function somewhere (Dynlink module?) that's a wrapper for the 
> C's dlopen function.
> 
> 4) Ideally - have a function somewhere (Dynlink module?) that would try 
> loading a .cma when running in bytecode and would try loading an .so 
> when running in native code.
> 
> Am I missing any serious difficulties here? Are there any plans to add 
> something like this to OCaml?

Look at the http://www.boblycat.org/~malc/scaml/

--
 Kamil.

-------------------
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] 9+ messages in thread

* Re: [Caml-list] Compiling a native code OCaml library into an .so?
  2003-11-20  3:33 ` Kamil Shakirov
@ 2003-11-20  4:57   ` Aleksey Nogin
  2003-11-20 11:13   ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
  1 sibling, 0 replies; 9+ messages in thread
From: Aleksey Nogin @ 2003-11-20  4:57 UTC (permalink / raw)
  To: caml-list, onlynews

On 19.11.2003 19:33, Kamil Shakirov wrote:

> Look at the http://www.boblycat.org/~malc/scaml/

Thanks, it looks very promising. I would love to see something like that 
in the standard OCaml distribution. Is there some particular reason it 
is not in there (yet)?

-- 
Aleksey Nogin

Home Page: http://nogin.org/
E-Mail: nogin@cs.caltech.edu (office), aleksey@nogin.org (personal)
Office: Jorgensen 70, tel: (626) 395-2907

-------------------
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] 9+ messages in thread

* [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)
  2003-11-20  3:33 ` Kamil Shakirov
  2003-11-20  4:57   ` Aleksey Nogin
@ 2003-11-20 11:13   ` Oleg Trott
  2003-11-20 11:30     ` Ville-Pertti Keinonen
  2003-11-20 11:46     ` Christian Lindig
  1 sibling, 2 replies; 9+ messages in thread
From: Oleg Trott @ 2003-11-20 11:13 UTC (permalink / raw)
  To: caml-list

On Wednesday 19 November 2003 10:33 pm, Kamil Shakirov wrote:
> > Am I missing any serious difficulties here? Are there any plans to add
> > something like this to OCaml?
>
> Look at the http://www.boblycat.org/~malc/scaml/

Things like this make me wonder how people outside of INRIA understand the 
inner workings of Caml compiler (enough to modify it). Just  guessing by 
looking at the rather sparcely commented source? Or is there anything else?

In particular, I'm curious if parts of Caml compiler, such as "asmcomp", could 
be used as a sort of C--, i.e. a weakly typed backend for another language, 
especially if the language itself is written in Caml.

TIA
-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
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] 9+ messages in thread

* Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)
  2003-11-20 11:13   ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
@ 2003-11-20 11:30     ` Ville-Pertti Keinonen
  2003-11-20 17:07       ` Oleg Trott
  2003-11-20 11:46     ` Christian Lindig
  1 sibling, 1 reply; 9+ messages in thread
From: Ville-Pertti Keinonen @ 2003-11-20 11:30 UTC (permalink / raw)
  To: Oleg Trott; +Cc: caml-list

On Thu, Nov 20, 2003 at 06:13:09AM -0500, Oleg Trott wrote:

> Things like this make me wonder how people outside of INRIA understand the 
> inner workings of Caml compiler (enough to modify it). Just  guessing by 
> looking at the rather sparcely commented source? Or is there anything else?

I find most of it fairly easy to understand (although I haven't tried to
modify it).  Just looking at the definitions of the types for the various
representations is very enlightening.

> In particular, I'm curious if parts of Caml compiler, such as "asmcomp", could 
> be used as a sort of C--, i.e. a weakly typed backend for another language, 
> especially if the language itself is written in Caml.

It's actually called C--...did you know that already?

Look in the asmcomp and testasmcomp directories if you didn't already...

The license might be an issue in actually using the code in a compiler
for another language, though.

-------------------
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] 9+ messages in thread

* Re: [Caml-list] Caml as C--
  2003-11-20 11:46     ` Christian Lindig
@ 2003-11-20 11:45       ` ZHAO Wei
  2003-11-20 16:37       ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
  1 sibling, 0 replies; 9+ messages in thread
From: ZHAO Wei @ 2003-11-20 11:45 UTC (permalink / raw)
  To: Caml Mailing List

Christian Lindig wrote:
> On Thu, Nov 20, 2003 at 06:13:09AM -0500, Oleg Trott wrote:
> 
>>Things like this make me wonder how people outside of INRIA understand the 
>>inner workings of Caml compiler (enough to modify it). Just  guessing by 
>>looking at the rather sparcely commented source? Or is there anything else?
> 
> 
> I once looked at the data structures in the ocamlopt back end. I'm not
> sure my slides are useful without the talk, but here they are:
> 
>     http://www.st.cs.uni-sb.de/~lindig/talks/ocaml-02/slides.ps.gz

Thanks!

-- 
zhaoway@public1.ptt.js.cn http://iloveqhq.blog@bbs.nju.edu.cn
http://c2.com/cgi/wiki?ZhaoWay http://advogato.org/person/zhaoway

-------------------
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] 9+ messages in thread

* Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)
  2003-11-20 11:13   ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
  2003-11-20 11:30     ` Ville-Pertti Keinonen
@ 2003-11-20 11:46     ` Christian Lindig
  2003-11-20 11:45       ` [Caml-list] Caml as C-- ZHAO Wei
  2003-11-20 16:37       ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
  1 sibling, 2 replies; 9+ messages in thread
From: Christian Lindig @ 2003-11-20 11:46 UTC (permalink / raw)
  To: Oleg Trott; +Cc: Caml Mailing List

On Thu, Nov 20, 2003 at 06:13:09AM -0500, Oleg Trott wrote:
> Things like this make me wonder how people outside of INRIA understand the 
> inner workings of Caml compiler (enough to modify it). Just  guessing by 
> looking at the rather sparcely commented source? Or is there anything else?

I once looked at the data structures in the ocamlopt back end. I'm not
sure my slides are useful without the talk, but here they are:

    http://www.st.cs.uni-sb.de/~lindig/talks/ocaml-02/slides.ps.gz
    

-- Christian

-------------------
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] 9+ messages in thread

* Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)
  2003-11-20 11:46     ` Christian Lindig
  2003-11-20 11:45       ` [Caml-list] Caml as C-- ZHAO Wei
@ 2003-11-20 16:37       ` Oleg Trott
  1 sibling, 0 replies; 9+ messages in thread
From: Oleg Trott @ 2003-11-20 16:37 UTC (permalink / raw)
  To: Christian Lindig; +Cc: Caml Mailing List

On Thursday 20 November 2003 06:46 am, Christian Lindig wrote:
> On Thu, Nov 20, 2003 at 06:13:09AM -0500, Oleg Trott wrote:
> > Things like this make me wonder how people outside of INRIA understand
> > the inner workings of Caml compiler (enough to modify it). Just  guessing
> > by looking at the rather sparcely commented source? Or is there anything
> > else?
>
> I once looked at the data structures in the ocamlopt back end. I'm not
> sure my slides are useful without the talk, but here they are:
>
>     http://www.st.cs.uni-sb.de/~lindig/talks/ocaml-02/slides.ps.gz

Yes! That's the kind of thing I'm looking for, but in a 160-page book form :-)

-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
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] 9+ messages in thread

* Re: [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?)
  2003-11-20 11:30     ` Ville-Pertti Keinonen
@ 2003-11-20 17:07       ` Oleg Trott
  0 siblings, 0 replies; 9+ messages in thread
From: Oleg Trott @ 2003-11-20 17:07 UTC (permalink / raw)
  To: Ville-Pertti Keinonen; +Cc: caml-list

On Thursday 20 November 2003 06:30 am, Ville-Pertti Keinonen wrote:
>
> It's actually called C--...did you know that already?

C-- is a separate project AFAIK (although one of the files in "asmcomp" 
mentions it). C-- is in its infancy, as I understand.

> Look in the asmcomp and testasmcomp directories if you didn't already...
>
> The license might be an issue in actually using the code in a compiler
> for another language, though.

I just read QPL. It does not define the concept of "language" or "other 
language". IANAL, but I think QPL is fairly reasonable. It's like GPL, but 
modifications have to be "patches" and the "original developer" gets to 
distribute your "patches" under other licenses as well.
-- 
Oleg Trott <oleg_trott@columbia.edu>

-------------------
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] 9+ messages in thread

end of thread, other threads:[~2003-11-20 17:07 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-19 23:49 [Caml-list] Compiling a native code OCaml library into an .so? Aleksey Nogin
2003-11-20  3:33 ` Kamil Shakirov
2003-11-20  4:57   ` Aleksey Nogin
2003-11-20 11:13   ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott
2003-11-20 11:30     ` Ville-Pertti Keinonen
2003-11-20 17:07       ` Oleg Trott
2003-11-20 11:46     ` Christian Lindig
2003-11-20 11:45       ` [Caml-list] Caml as C-- ZHAO Wei
2003-11-20 16:37       ` [Caml-list] Caml as C-- (was: Compiling a native code OCaml library into an .so?) Oleg Trott

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