comp.lang.ada
 help / color / mirror / Atom feed
* Dynamic Plug-in Loading with Ada
@ 2005-06-25  7:35 Preben Randhol
  2005-06-28 18:30 ` Mark Lorenzen
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Preben Randhol @ 2005-06-25  7:35 UTC (permalink / raw)
  To: comp.lang.ada

I don't know if you have seen this paper: 

   http://www.gnat.com/pressroom_20.php#

   Maintenance of high-availability systems (e.g., servers) requires the
   ability to modify, enhance, or correct parts of the application
   without needing to shut down and re-link the entire system. This is
   relatively straightforward in an interpreted or virtual-machine based
   language such as Java, in which new code is loaded upon demand. In a
   language with static executable images this capability can be
   realized though dynamically loaded / linked libraries ("DLLs").
   However, in practice this causes problems, because the protocol for
   invoking subprograms in a DLL is very low-level and sacrifices type
   safety.

   Object-oriented programming makes this approach practical by using
   dynamic dispatching to invoke dynamically loaded functions with a
   more robust, high-level protocol. In an OO paradigm, a �plug-in�
   contains new classes that enrich the class set of the original
   application. Calls to subprograms in the shared library (plug-in) are
   done implicitly through dynamic dispatching which is much simpler,
   more transparent to the programmer, more type-safe, and thus much
   safer.A paper by Cyrille Comar and Pat Rogers shows how Ada � a
   statically-typed, statically-built, object-oriented language� can
   fully implement dynamic plug-ins as in Java, but without needing to
   rely on a comparatively inefficient virtual machine. This paper,
   which will be available on the AdaCore website, shows how to use GNAT
   Pro to build an extensible application and illustrates adding new
   functionality at run time through plug-ins, without needing to shut
   down the program.

The paper explains the procedure for doing this in Windows. Does anybody
know if one could do the same in Linux with shared libraries?

Thanks in advance

Preben
-- 
Preben Randhol -------------- http://www.pvv.org/~randhol/Ada95 --
                 �For me, Ada95 puts back the joy in programming.�



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

* Re: Dynamic Plug-in Loading with Ada
  2005-06-25  7:35 Dynamic Plug-in Loading with Ada Preben Randhol
@ 2005-06-28 18:30 ` Mark Lorenzen
  2005-06-28 20:43 ` Dr. Adrian Wrigley
  2005-07-01  6:09 ` Michael Erdmann
  2 siblings, 0 replies; 7+ messages in thread
From: Mark Lorenzen @ 2005-06-28 18:30 UTC (permalink / raw)


Preben Randhol <randhol+cla@pvv.org> writes:

> I don't know if you have seen this paper: 
> 
>    http://www.gnat.com/pressroom_20.php#
> 

Yep - I have read it.

> The paper explains the procedure for doing this in Windows. Does anybody
> know if one could do the same in Linux with shared libraries?

It should not be hard to port the example given in the paper to
Linux. Take a look at the man page for dlopen(). It describes how to
open (load), close (unload) a shared object in Linux. The function
similiar to Win32.Winbase.GetProcAddress on line 23 in the example, is
called dlsym() in Linux.

The technique using dlopen() and friends is used by fx. the web
browser Firefox to load plugins.

> 
> Thanks in advance
> 
> Preben

- Mark Lorenzen



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

* Re: Dynamic Plug-in Loading with Ada
  2005-06-25  7:35 Dynamic Plug-in Loading with Ada Preben Randhol
  2005-06-28 18:30 ` Mark Lorenzen
@ 2005-06-28 20:43 ` Dr. Adrian Wrigley
  2005-06-28 20:53   ` Alex R. Mosteo
  2005-06-28 21:30   ` Preben Randhol
  2005-07-01  6:09 ` Michael Erdmann
  2 siblings, 2 replies; 7+ messages in thread
From: Dr. Adrian Wrigley @ 2005-06-28 20:43 UTC (permalink / raw)


On Sat, 25 Jun 2005 09:35:16 +0200, Preben Randhol wrote:

> I don't know if you have seen this paper: 
> 
>    http://www.gnat.com/pressroom_20.php#
...
> The paper explains the procedure for doing this in Windows. Does anybody
> know if one could do the same in Linux with shared libraries?

Hi!

I put together a little package last year to do "Live Coding" in
Ada under GNAT/Linux.

The package (LiveCoding) implemented procedures to run statements, to
compile subprograms and to compile packages.  The arguments would
be strings and context clauses.  I implemented context clauses as
a separate data type which could be passed in to the code generator,

The LiveCoding package wrote out new packages into files and called
out to gnatgcc (or whatever) to compile the code fragments using dlopen
and dlsym to access the new program symbols.

I think this goes a bit beyond implementing plug-ins because the
new code was written out and compiled by the running program.
And it could run new statements and function calls dynamically
generated.

Overall, it was just an experimental system, to investigate the
viability of the technique.  While it was not perfect, it seemed
very promising. It took about 150ms to compile, link and run
basic statements and packages (2xAMD 1400XP).  OK for implementing
a command parser with a human interface.  The run-time performance
of the code, of course, is excellent.

What was it all for?

One use I was looking into was for interactive digital music
synthesis.  Users want to be able to type in music fragments
as code segments, joining them together in real time.
The most popular way of doing this (live) is with a LISP
system, but some people use FORTH derivitives (AMPLE).

It also shows promise for efficient emplementation of
genetic algorithms, where expressions are generated and
tested for fitness in problem solving.  Compiling the
code is often 20x the speed of interpreting the
function more directly in the code.

Another use was in a new kind of software development system
I was messing around with.  Basically, I wanted to make the
programming experience much more interactive, allowing
changes to code to be made "on the fly".  Ada is particularly
unsuited to Live Coding, but it *can* be made to work.

In curious to know if anyone else has tried "Live Coding"
in Ada, and what the outcome was.

Good luck!
-- 
Dr. Adrian Wrigley, Cambridge, UK.




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

* Re: Dynamic Plug-in Loading with Ada
  2005-06-28 20:43 ` Dr. Adrian Wrigley
@ 2005-06-28 20:53   ` Alex R. Mosteo
  2005-06-28 21:30   ` Preben Randhol
  1 sibling, 0 replies; 7+ messages in thread
From: Alex R. Mosteo @ 2005-06-28 20:53 UTC (permalink / raw)


Dr. Adrian Wrigley wrote:
> On Sat, 25 Jun 2005 09:35:16 +0200, Preben Randhol wrote:
> 
> 
>>I don't know if you have seen this paper: 
>>
>>   http://www.gnat.com/pressroom_20.php#
> 
> ...
> 
>>The paper explains the procedure for doing this in Windows. Does anybody
>>know if one could do the same in Linux with shared libraries?
> 
> 
> Hi!
> 
> I put together a little package last year to do "Live Coding" in
> Ada under GNAT/Linux.
> 
> (...)
> 
> I think this goes a bit beyond implementing plug-ins because the
> new code was written out and compiled by the running program.
> And it could run new statements and function calls dynamically
> generated.

It's somewhat creepy... :) Skynet anyone?

> In curious to know if anyone else has tried "Live Coding"
> in Ada, and what the outcome was.

Not this exactly, but when you do some coding in Java within Eclipse you 
really get a taste for compilation on the fly...



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

* Re: Dynamic Plug-in Loading with Ada
  2005-06-28 20:43 ` Dr. Adrian Wrigley
  2005-06-28 20:53   ` Alex R. Mosteo
@ 2005-06-28 21:30   ` Preben Randhol
  2005-06-28 23:22     ` Dr. Adrian Wrigley
  1 sibling, 1 reply; 7+ messages in thread
From: Preben Randhol @ 2005-06-28 21:30 UTC (permalink / raw)
  To: comp.lang.ada

On Tue, Jun 28, 2005 at 08:43:20PM +0000, Dr. Adrian Wrigley wrote:
> 
> I put together a little package last year to do "Live Coding" in
> Ada under GNAT/Linux.
> 
> The package (LiveCoding) implemented procedures to run statements, to
> compile subprograms and to compile packages.  The arguments would
> be strings and context clauses.  I implemented context clauses as
> a separate data type which could be passed in to the code generator,
> 
> The LiveCoding package wrote out new packages into files and called
> out to gnatgcc (or whatever) to compile the code fragments using dlopen
> and dlsym to access the new program symbols.

Sounds interesting? Is this package by any chance available online?

-- 
Preben Randhol -------------- http://www.pvv.org/~randhol/Ada95 --
                 �For me, Ada95 puts back the joy in programming.�



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

* Re: Dynamic Plug-in Loading with Ada
  2005-06-28 21:30   ` Preben Randhol
@ 2005-06-28 23:22     ` Dr. Adrian Wrigley
  0 siblings, 0 replies; 7+ messages in thread
From: Dr. Adrian Wrigley @ 2005-06-28 23:22 UTC (permalink / raw)


On Tue, 28 Jun 2005 23:30:13 +0200, Preben Randhol wrote:

> On Tue, Jun 28, 2005 at 08:43:20PM +0000, Dr. Adrian Wrigley wrote:
>> 
>> I put together a little package last year to do "Live Coding" in
>> Ada under GNAT/Linux.
>> 
>> The package (LiveCoding) implemented procedures to run statements, to
>> compile subprograms and to compile packages.  The arguments would
>> be strings and context clauses.  I implemented context clauses as
>> a separate data type which could be passed in to the code generator,
>> 
>> The LiveCoding package wrote out new packages into files and called
>> out to gnatgcc (or whatever) to compile the code fragments using dlopen
>> and dlsym to access the new program symbols.
> 
> Sounds interesting? Is this package by any chance available online?

I had thought it might be useful to other people at some point.
The functionality is very general, and can be a substitute for
an embedded command interpreter.  But it is little more than
a heap of code I threw together as a proof of concept.  I don't
have the time to publish it right now.  Maybe I could send you
some code to look at (next week).
-- 
Dr. Adrian Wrigley, Cambridge, UK.




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

* Re: Dynamic Plug-in Loading with Ada
  2005-06-25  7:35 Dynamic Plug-in Loading with Ada Preben Randhol
  2005-06-28 18:30 ` Mark Lorenzen
  2005-06-28 20:43 ` Dr. Adrian Wrigley
@ 2005-07-01  6:09 ` Michael Erdmann
  2 siblings, 0 replies; 7+ messages in thread
From: Michael Erdmann @ 2005-07-01  6:09 UTC (permalink / raw)


Preben Randhol wrote:
> I don't know if you have seen this paper: 
> 
>    http://www.gnat.com/pressroom_20.php#
> 
I have read the paper. i think the paper misses out some of the
nasty details how to initialize the loaded plugin. At least
from my experience i have made with my own implementation 
(http://sourceforge.net/projects/ascl) this is a small nightmare
since you got very strange effect regarding access types
if you dont do it.

Michael


>    Maintenance of high-availability systems (e.g., servers) requires the
>    ability to modify, enhance, or correct parts of the application
>    without needing to shut down and re-link the entire system. This is
>    relatively straightforward in an interpreted or virtual-machine based
>    language such as Java, in which new code is loaded upon demand. In a
>    language with static executable images this capability can be
>    realized though dynamically loaded / linked libraries ("DLLs").
>    However, in practice this causes problems, because the protocol for
>    invoking subprograms in a DLL is very low-level and sacrifices type
>    safety.
> 
>    Object-oriented programming makes this approach practical by using
>    dynamic dispatching to invoke dynamically loaded functions with a
>    more robust, high-level protocol. In an OO paradigm, a �plug-in�
>    contains new classes that enrich the class set of the original
>    application. Calls to subprograms in the shared library (plug-in) are
>    done implicitly through dynamic dispatching which is much simpler,
>    more transparent to the programmer, more type-safe, and thus much
>    safer.A paper by Cyrille Comar and Pat Rogers shows how Ada � a
>    statically-typed, statically-built, object-oriented language� can
>    fully implement dynamic plug-ins as in Java, but without needing to
>    rely on a comparatively inefficient virtual machine. This paper,
>    which will be available on the AdaCore website, shows how to use GNAT
>    Pro to build an extensible application and illustrates adding new
>    functionality at run time through plug-ins, without needing to shut
>    down the program.
> 
> The paper explains the procedure for doing this in Windows. Does anybody
> know if one could do the same in Linux with shared libraries?
> 
> Thanks in advance
> 
> Preben



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

end of thread, other threads:[~2005-07-01  6:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-25  7:35 Dynamic Plug-in Loading with Ada Preben Randhol
2005-06-28 18:30 ` Mark Lorenzen
2005-06-28 20:43 ` Dr. Adrian Wrigley
2005-06-28 20:53   ` Alex R. Mosteo
2005-06-28 21:30   ` Preben Randhol
2005-06-28 23:22     ` Dr. Adrian Wrigley
2005-07-01  6:09 ` Michael Erdmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox