caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Dynamic linking in CSL?
@ 1995-12-22 19:09 Mark C. Chu-Carroll
  1995-12-28 15:08 ` Francois Rouaix
  1995-12-28 16:13 ` Xavier Leroy
  0 siblings, 2 replies; 5+ messages in thread
From: Mark C. Chu-Carroll @ 1995-12-22 19:09 UTC (permalink / raw)
  To: caml-list



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

(I'm writing an editor, which provides mechanisms for user implemented
enhancements.  Most enhancements work as external programs that communicate
with the editor through sockets. But I'd like users to be able to write
enhancements that use the TK binding to alter window behavior. The
only way for them to do such a thing without recompiling the editor
would be to have some sort of dynamic loading. I can handle type safety
by forcing extension packages to comform to a particular signature. But
I really need to have dynamic linking/loading.)

	<MC>






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

* Re: Dynamic linking in CSL?
  1995-12-22 19:09 Dynamic linking in CSL? Mark C. Chu-Carroll
@ 1995-12-28 15:08 ` Francois Rouaix
  1995-12-29 14:06   ` Mark C. Chu-Carroll
  1995-12-28 16:13 ` Xavier Leroy
  1 sibling, 1 reply; 5+ messages in thread
From: Francois Rouaix @ 1995-12-28 15:08 UTC (permalink / raw)
  To: Mark C. Chu-Carroll; +Cc: caml-list


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

Dynamic linking is available for CSL (bytecode compiler only !)
as a library, in csl/otherlibs/dynlink.
Type safety is handled exactly as for static linking, except that you
can restrict arbitrarily the modules "exported" to dynamically linked
bytecode.
I have used this feature extensively in my MMM browser, written in CSL with
CamlTk4.
The difficulty is to invoke code from dynamically loaded modules. I believe
the easiest way is to provide "registration functions" that the extension
will call during loading.
E.G. in MMM
let _ = Applets.register the_function "some name"

and other similar "hooks" mechanisms.

--
Francois.Rouaix@inria.fr                   Projet Cristal - INRIA Rocquencourt
WWW Home Page: http://pauillac.inria.fr/~rouaix/






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

* Re: Dynamic linking in CSL?
  1995-12-22 19:09 Dynamic linking in CSL? Mark C. Chu-Carroll
  1995-12-28 15:08 ` Francois Rouaix
@ 1995-12-28 16:13 ` Xavier Leroy
  1 sibling, 0 replies; 5+ messages in thread
From: Xavier Leroy @ 1995-12-28 16:13 UTC (permalink / raw)
  To: Mark C. Chu-Carroll; +Cc: caml-list


> 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




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

* Re: Dynamic linking in CSL?
  1995-12-28 15:08 ` Francois Rouaix
@ 1995-12-29 14:06   ` Mark C. Chu-Carroll
  1995-12-30 10:45     ` Francois Rouaix
  0 siblings, 1 reply; 5+ messages in thread
From: Mark C. Chu-Carroll @ 1995-12-29 14:06 UTC (permalink / raw)
  To: Francois.Rouaix; +Cc: Mark C. Chu-Carroll, caml-list


Thanks. That's exactly what I was looking for!

BTW, what version of Tcl/TK are you using over there for camltk4?
(I'm still trying to figure out why highlighting and underlining
in my code works for you, but not for me!)

	<MC>





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

* Re: Dynamic linking in CSL?
  1995-12-29 14:06   ` Mark C. Chu-Carroll
@ 1995-12-30 10:45     ` Francois Rouaix
  0 siblings, 0 replies; 5+ messages in thread
From: Francois Rouaix @ 1995-12-30 10:45 UTC (permalink / raw)
  To: Mark C. Chu-Carroll; +Cc: caml-list


> BTW, what version of Tcl/TK are you using over there for camltk4?
Well, we use Tcl 7.4pl2 and Tk 4.0pl2. I know that camltk4 works with
plain Tcl7.4 and Tk4.0, but I have never tested it with beta versions
of Tk4.0, or Tk4.1.

--
Francois.Rouaix@inria.fr                   Projet Cristal - INRIA Rocquencourt
WWW Home Page: http://pauillac.inria.fr/~rouaix/






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

end of thread, other threads:[~1996-01-04 10:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1995-12-22 19:09 Dynamic linking in CSL? 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 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).