caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xleroy@pauillac.inria.fr>
To: carroll@louie.udel.edu (Mark C. Chu-Carroll)
Cc: caml-list@pauillac.inria.fr
Subject: Re: Dynamic linking in CSL?
Date: Thu, 28 Dec 1995 17:13:29 +0100 (MET)	[thread overview]
Message-ID: <199512281613.RAA03255@pauillac.inria.fr> (raw)
In-Reply-To: <9512221909.aa01551@auriga.cis.udel.edu> from "Mark C. Chu-Carroll" at Dec 22, 95 02:09:29 pm


> Is it possible, in CSL, to dynamically load and link a CSL module
> which matches a static signature?

Yes. The current distribution of Caml Special Light includes a dynamic
linking library (in otherlibs/dynlink), originally developed for
implementing applets in the MMM browser, but general enough (I think)
for your needs.

There is some documentation in otherlibs/dynlink/dynlink.mli. I'll try
to summarize the main points below.

First of all, the library provides no mechanism for accessing values
defined by a dynamically-linked module. (That would be hard to do in a
type-safe way.) So, the dynamically-linked module must register
explicitly the functions it exports with the application, e.g. by
storing these functions in mutable data structures. For instance:

        let f x = ...
        let g y = ...
        let _ =
          App.extension_functions :=
            ["f", f; "g", g] @ !App1.extension_functions

Here, "App" is assumed to be a module from the application, that defines

        let extension_functions = ref ([] : (string * (int -> int)) list)

Calling an extension function given its name is a simple "assoc" in
that list.

For this reason, the signature of the dynamically-linked module does
not matter. What matters, for type safety, is the signatures of the
modules from the application that the dynamically-linked module references.
The dynlink library checks that the dynamically-linked module has been
compiled against the same interfaces for these application modules as
the application modules themselves. This ensures type safety.

Say your application is composed of three modules, App App2 App3.
You would initialize the dynamic linker as follows:

        Dynlink.init();
        Dynlink.add_interfaces
          ["Pervasives";"Array";"String";"Char";"App";"App2";"App3"]
          ["/the/sources/of/my/application";
           "/usr/local/lib/caml-special-light"]

The add_interfaces function sets the list of modules that
dynamically-linked code can reference. Here, we allow access to the
three application modules, plus a number of standard library modules.
The second argument is a list of directories where the .cmi files (the
compiled signatures) for these modules are found.

Then, linking a file foo.cmo is as easy as

        Dynlink.loadfile "foo.cmo"

There are some extra features in the library, but I hope you get the
general idea. Write caml-light@pauillac.inria.fr for more info.

Regards,

- Xavier Leroy




      parent reply	other threads:[~1995-12-28 17:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1995-12-22 19:09 Mark C. Chu-Carroll
1995-12-28 15:08 ` Francois Rouaix
1995-12-29 14:06   ` Mark C. Chu-Carroll
1995-12-30 10:45     ` Francois Rouaix
1995-12-28 16:13 ` Xavier Leroy [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=199512281613.RAA03255@pauillac.inria.fr \
    --to=xleroy@pauillac.inria.fr \
    --cc=caml-list@pauillac.inria.fr \
    --cc=carroll@louie.udel.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).