[Caml-list] embedding ocaml into a windows app: need gcc?

2008-09-27 Thread Joel Reymont
Can I do without gcc if I want to embed the OCaml compiler into a  
commercial Windows app?


Do I need to become part of the OCaml consortium to do this?

Ideally, I would like to generate OCaml code at runtime and compile it  
into something that can be loaded by a runtime of some sort.


Compiling into a DLL would be ideal, is it possible?

Are there are other options?

Thanks in advance, Joel

--
wagerlabs.com





___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] embedding ocaml into a windows app: need gcc?

2008-09-27 Thread Richard Jones
On Sat, Sep 27, 2008 at 08:27:18PM +0100, Joel Reymont wrote:
 Can I do without gcc if I want to embed the OCaml compiler into a  
 commercial Windows app?

The OCaml compiler uses gcc in various stages (linking IIRC).  Also
needs an assembler.

 Do I need to become part of the OCaml consortium to do this?

You certainly need to read the license very carefully.

However is it necessary to embed the compiler?  Can you not just call
out to the compiler as a separate process?  It's surely easier to do
Sys.command, rather than working out the licensing and technical
issues involved in linking your program to the compiler.

 Ideally, I would like to generate OCaml code at runtime and compile it  
 into something that can be loaded by a runtime of some sort.
 
 Compiling into a DLL would be ideal, is it possible?

ocamlopt -fPIC ... should be able to do it.

Or compile the code with ocamlc and use Dynlink.

Or wait for OCaml 3.11 which can use Dynlink on native code.

Rich.

-- 
Richard Jones
Red Hat

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] embedding ocaml into a windows app: need gcc?

2008-09-27 Thread David Teller
I don't know if this answers your question, but OCaml 3 now has Dynlink,
i.e. a manner of dynamically loading OCaml modules from OCaml. So if you
manage to get your code compiled at run-time, it shouldn't be too hard
to load it.

Cheers,
 David

On Sat, 2008-09-27 at 20:27 +0100, Joel Reymont wrote:
 Ideally, I would like to generate OCaml code at runtime and compile it  
 into something that can be loaded by a runtime of some sort.
 
 Compiling into a DLL would be ideal, is it possible?
 
 Are there are other options?

-- 
David Teller-Rajchenbach
 Security of Distributed Systems
  http://www.univ-orleans.fr/lifo/Members/David.Teller
 Angry researcher: French Universities need reforms, but the LRU act
brings liquidations. 

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


Re: [Caml-list] embedding ocaml into a windows app: need gcc?

2008-09-27 Thread Mikkel Fahnøe Jørgensen
2008/9/27 Joel Reymont [EMAIL PROTECTED]:
 Can I do without gcc if I want to embed the OCaml compiler into a commercial
 Windows app?

I assume you mean native compilation.

As mentioned, you should consider using a standalone ocaml compiler to
avoid licensing issues, but either way:

The ocamlopt compiler generates assembly source code and doesn't need
a C compiler.
It needs a runtime library, a linker and an assembler.

On Windows you need to install masm - or find a compatible
alternative. (On Unix I think gcc works as assembler).

Masm can be downloaded without too much trouble - but if you start
deploying it to other users, you may have a problem. Likewise, you
must consider if your users have a linker installed and how you can
distribute it legally.

So assuming you have an assembler, ocaml compiler, linker and ocaml libraries:

If you want to attach the generated code to a live process, you need
to create a dll or a new process. If you want to attach to existing
code then start a process, you can use static linking.

So lets assume you want to create a dll.

On Windows you don't need to compile position independent code, last
time I looked, so -fPIC is not relevant.

You compile an ocaml library and link it with other code as a dll.
With the next ocaml version you might even be able to create a dll and
use it not from OCaml but from any other program. Then the problem is
solved - except for installing all the compile tools.

Without the above solution, I have created such dll's some years back.
More specifically to embed an ocamlyacc compiler in other Windows
programs.

You need to get the compile flags right, but it definitely is possible.

You can also create a COM dll if you want - and call it from .Net.
The benefit of a COM dll is that you get a clear calling interface and
can interface with .NET easily. The downside is that COM projects are
ugly.

If you create a simple dll, you need a way to manage your call backs.
I have an old ocamldll library for this purpose. It lets you register
multiple ocaml function names in a dll and call them from the
application by name.

The new windows dll solution scheduled for next OCaml version has a
more elegant solution where you don't have to register callbacks:

http://alain.frisch.fr/natdynlink.html

You can probably use this even with current OCaml version since it is
Windows specific, not OCaml specific.

Let me know if I should publish my ocamldll thing which will work, but
is not cutting edge.

All that being said:

I have considered the same thing, and it is messy because of the compiler tools.

I would like an OCaml support library that can compile and execute
similar to JaveScript engines, but we don't have that in any practical
form.

So I would recommend looking into embedding a javascript compiler
instead if performance is not absolutely critical - you could still
drive fast ocaml library routines.

In the past few months performance has exploded both in WebKit and
Mozilla. Google has also released a fast engine named V8. WebKit has
LGPL licensing issues, but Mozilla and V8 should be very embeddable.
All compilers have JIT compilation, Mozilla also 64-bit.

Or look at Haxe or Lua.

Regards,
Mikkel

___
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs