comp.lang.ada
 help / color / mirror / Atom feed
* Java wrappers around Ada?
@ 2006-03-22 13:01 kk_oop
  2006-03-22 13:33 ` Larry Kilgallen
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: kk_oop @ 2006-03-22 13:01 UTC (permalink / raw)


Hi.  My team has a bunch of legacy Ada code.  Our new code is being
written in Java.  However, we still have many complex algorithms
written in thousands of lines of Ada.  Rather than rewriting the
tested/validated Ada code in Java, we'd like to create a Java facade
that would delegate to the Ada code, thereby making the Ada code
available to newer Java client objects.  Is this reasonable (as opposed
to rewriting everything in Java)?  Anyone know what
mechanisms/libraries would support such an approach?

Thanks!

Ken




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

* Re: Java wrappers around Ada?
  2006-03-22 13:01 Java wrappers around Ada? kk_oop
@ 2006-03-22 13:33 ` Larry Kilgallen
  2006-03-23  6:57   ` Anders Wirzenius
  2006-03-22 13:33 ` Georg Bauhaus
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Larry Kilgallen @ 2006-03-22 13:33 UTC (permalink / raw)


In article <1143032491.488772.259820@j33g2000cwa.googlegroups.com>, kk_oop@yahoo.com writes:
> Hi.  My team has a bunch of legacy Ada code.  Our new code is being
> written in Java.  However, we still have many complex algorithms
> written in thousands of lines of Ada.  Rather than rewriting the
> tested/validated Ada code in Java, we'd like to create a Java facade
> that would delegate to the Ada code, thereby making the Ada code
> available to newer Java client objects.  Is this reasonable (as opposed
> to rewriting everything in Java)?  Anyone know what
> mechanisms/libraries would support such an approach?

Rewriting correct code solely for the purpose of getting it into another
language is always fraught with peril.  That includes going to Ada.



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

* Re: Java wrappers around Ada?
  2006-03-22 13:01 Java wrappers around Ada? kk_oop
  2006-03-22 13:33 ` Larry Kilgallen
@ 2006-03-22 13:33 ` Georg Bauhaus
  2006-03-22 23:25 ` Jeffrey R. Carter
  2006-03-23 22:24 ` James Alan Farrell
  3 siblings, 0 replies; 10+ messages in thread
From: Georg Bauhaus @ 2006-03-22 13:33 UTC (permalink / raw)


kk_oop@yahoo.com wrote:
> Hi.  My team has a bunch of legacy Ada code.  Our new code is being
> written in Java.  However, we still have many complex algorithms
> written in thousands of lines of Ada.  Rather than rewriting the
> tested/validated Ada code in Java, we'd like to create a Java facade
> that would delegate to the Ada code, thereby making the Ada code
> available to newer Java client objects.  Is this reasonable (as opposed
> to rewriting everything in Java)?  Anyone know what
> mechanisms/libraries would support such an approach?

FWIW, at least one Ada compiler supports JNI (ObjectAda), another is supposed
to support it in the near future, if it doesn't already (GNAT).
Additionally, there are at least two Ada -> Java bytecode compilers,
AppletMagic and JGnat.


-- Georg 



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

* Re: Java wrappers around Ada?
  2006-03-22 13:01 Java wrappers around Ada? kk_oop
  2006-03-22 13:33 ` Larry Kilgallen
  2006-03-22 13:33 ` Georg Bauhaus
@ 2006-03-22 23:25 ` Jeffrey R. Carter
  2006-03-23 22:24 ` James Alan Farrell
  3 siblings, 0 replies; 10+ messages in thread
From: Jeffrey R. Carter @ 2006-03-22 23:25 UTC (permalink / raw)


kk_oop@yahoo.com wrote:
> Hi.  My team has a bunch of legacy Ada code.  Our new code is being
> written in Java.  However, we still have many complex algorithms
> written in thousands of lines of Ada.  Rather than rewriting the
> tested/validated Ada code in Java, we'd like to create a Java facade
> that would delegate to the Ada code, thereby making the Ada code
> available to newer Java client objects.  Is this reasonable (as opposed
> to rewriting everything in Java)?  Anyone know what
> mechanisms/libraries would support such an approach?

You have a number of options. Some compilers support Ada as a language for JNI. 
There are also compilers that output Jcode from Ada. You might be able to turn 
your Ada into a dynamic library and call that from Java. You could rewrite all 
your Ada in Java, though I don't recommend that.

The best option, of course, is to do all your code in Ada, but you'd have to be 
competent SW engineers to choose that.

-- 
Jeff Carter
"Son of a window-dresser."
Monty Python & the Holy Grail
12



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

* Re: Java wrappers around Ada?
  2006-03-22 13:33 ` Larry Kilgallen
@ 2006-03-23  6:57   ` Anders Wirzenius
  2006-03-23 13:10     ` Larry Kilgallen
  0 siblings, 1 reply; 10+ messages in thread
From: Anders Wirzenius @ 2006-03-23  6:57 UTC (permalink / raw)


Kilgallen@SpamCop.net (Larry Kilgallen) writes:

> 
> Rewriting correct code solely for the purpose of getting it into another
> language is always fraught with peril.  That includes going to Ada.

In a learning situation when the code is not used for other purposes
than training and thus the correctness of the code is not a major issue,
I have found rewriting code in another language quite effective. I have
learned something about both languages, especially the differences
between them.

-- 
Anders



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

* Re: Java wrappers around Ada?
  2006-03-23  6:57   ` Anders Wirzenius
@ 2006-03-23 13:10     ` Larry Kilgallen
  0 siblings, 0 replies; 10+ messages in thread
From: Larry Kilgallen @ 2006-03-23 13:10 UTC (permalink / raw)


In article <u64m57imz.fsf@no.email.thanks.invalid>, Anders Wirzenius <anders@no.email.thanks.invalid> writes:
> Kilgallen@SpamCop.net (Larry Kilgallen) writes:
> 
>> 
>> Rewriting correct code solely for the purpose of getting it into another
>> language is always fraught with peril.  That includes going to Ada.
> 
> In a learning situation when the code is not used for other purposes
> than training and thus the correctness of the code is not a major issue,
> I have found rewriting code in another language quite effective. I have
> learned something about both languages, especially the differences
> between them.

Then I would argue the sole purpose is not to get it into another language.
Certainly rewriting into another language is an excellent learning tool -
just don't let the learning interfere with actual production.



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

* Re: Java wrappers around Ada?
  2006-03-22 13:01 Java wrappers around Ada? kk_oop
                   ` (2 preceding siblings ...)
  2006-03-22 23:25 ` Jeffrey R. Carter
@ 2006-03-23 22:24 ` James Alan Farrell
  2006-03-23 22:59   ` kk_oop
  3 siblings, 1 reply; 10+ messages in thread
From: James Alan Farrell @ 2006-03-23 22:24 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 734 bytes --]

We have a similar problem with C, and found it is pretty straight 
forward to wrap Ada in C calls.  Could you do that, then call the C 
calls from Java?

JAF

kk_oop@yahoo.com wrote:
> Hi.  My team has a bunch of legacy Ada code.  Our new code is being
> written in Java.  However, we still have many complex algorithms
> written in thousands of lines of Ada.  Rather than rewriting the
> tested/validated Ada code in Java, we'd like to create a Java facade
> that would delegate to the Ada code, thereby making the Ada code
> available to newer Java client objects.  Is this reasonable (as opposed
> to rewriting everything in Java)?  Anyone know what
> mechanisms/libraries would support such an approach?
> 
> Thanks!
> 
> Ken
> 


[-- Attachment #2: jfarrell.vcf --]
[-- Type: text/x-vcard, Size: 88 bytes --]

begin:vcard
fn:James Alan Farrell
n:Farrell;James
org:GrammaTech
version:2.1
end:vcard


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

* Re: Java wrappers around Ada?
  2006-03-23 22:24 ` James Alan Farrell
@ 2006-03-23 22:59   ` kk_oop
  2006-03-24 21:40     ` James Alan Farrell
  0 siblings, 1 reply; 10+ messages in thread
From: kk_oop @ 2006-03-23 22:59 UTC (permalink / raw)



James Alan Farrell wrote:
> We have a similar problem with C, and found it is pretty straight
> forward to wrap Ada in C calls.  Could you do that, then call the C
> calls from Java?
>
> JAF

JNI seems to support the Java/C connection.  So this may work.  In your
problem space, did you have bi-directional communication between C and
Ada?  In other words, were you able to have C invoke Ada calls and Ada
invoke C calls?

Thanks!

Ken




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

* Re: Java wrappers around Ada?
  2006-03-23 22:59   ` kk_oop
@ 2006-03-24 21:40     ` James Alan Farrell
  2006-03-25  0:37       ` Jeffrey R. Carter
  0 siblings, 1 reply; 10+ messages in thread
From: James Alan Farrell @ 2006-03-24 21:40 UTC (permalink / raw)


[-- Attachment #1: Type: text/plain, Size: 2532 bytes --]

kk_oop@yahoo.com wrote:
> James Alan Farrell wrote:
> 
>>We have a similar problem with C, and found it is pretty straight
>>forward to wrap Ada in C calls.  Could you do that, then call the C
>>calls from Java?
>>
>>JAF
> 
> 
> JNI seems to support the Java/C connection.  So this may work.  In your
> problem space, did you have bi-directional communication between C and
> Ada?  In other words, were you able to have C invoke Ada calls and Ada
> invoke C calls?
> 
> Thanks!
> 
> Ken
> 
Yes.
Our Ada compiler is the gnat (gcc) compiler, and our main program is in 
C.  The tool runs on linux, so we use gcc all around and the tools work 
very nicely together.

We call ada_init() in the C code (you will probably have to do the 
same).  From there it is mostly a matter of making sure both languages 
have the correct interface and calling in either direction is really 
pretty easy.  In Ada, use pragma(C, ...).

On the C side things are a bit messy.  Out and in/out parameters become 
pointers.  This works rather better than I would've thought (probably 
the pragma forces such parameters to be pointers where they would not 
always be otherwise).  But even so, we have a lot of C functions with 
void * parameters instead of typed pointers and ints instead of Boolean, 
etc.

When an Ada function returns an unsized array (such as Wide_String(<>)) 
we wrap it in an Ada procedure that returns a wchar_t and string size. 
(There is a way to ensure the string is null terminated so C does not 
need the size, but this method is good for any array type.  See ARM B.3.1)

One interesting problem we had was converting Ada access types to C 
pointers.  An Ada access type is a higher level construct than a C 
pointer, which means it may or might not actually "point" to the desired 
location in memory.  What we found in practice is that arrays that are 
sized dynamically have a 64 bit entity in which the first 32 bits do 
point to the object of interest.

I'm not sure I'm happy with our solution and others here probably have 
better ideas than we, so instead of saying what we did, I'll look to see 
if anyone posts any suggestions ;)

For exceptions raised in Ada, we catch them in Ada and call a C function 
   that passes to C information on the raised exception.  (I wouldn't 
want to mess with anything like trying to pass the exception itself to 
C++ then on to Java)

I can't think of any other gotcha's that we experienced.  It really has 
been a lot easier than I thought coming in to the project.

Have fun!
James

[-- Attachment #2: jfarrell.vcf --]
[-- Type: text/x-vcard, Size: 88 bytes --]

begin:vcard
fn:James Alan Farrell
n:Farrell;James
org:GrammaTech
version:2.1
end:vcard


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

* Re: Java wrappers around Ada?
  2006-03-24 21:40     ` James Alan Farrell
@ 2006-03-25  0:37       ` Jeffrey R. Carter
  0 siblings, 0 replies; 10+ messages in thread
From: Jeffrey R. Carter @ 2006-03-25  0:37 UTC (permalink / raw)


James Alan Farrell wrote:
> On the C side things are a bit messy.  Out and in/out parameters become 
> pointers.  This works rather better than I would've thought (probably 
> the pragma forces such parameters to be pointers where they would not 
> always be otherwise).  But even so, we have a lot of C functions with 
> void * parameters instead of typed pointers and ints instead of Boolean, 
> etc.

ARM B.3 defines how parameters should be passed to a convention-C subprogram.

> One interesting problem we had was converting Ada access types to C 
> pointers.  An Ada access type is a higher level construct than a C 
> pointer, which means it may or might not actually "point" to the desired 
> location in memory.  What we found in practice is that arrays that are 
> sized dynamically have a 64 bit entity in which the first 32 bits do 
> point to the object of interest.

You can apply pragma Convention (C, ...); to an Ada access type to ensure that 
it is C compatible.

-- 
Jeff Carter
"Ditto, you provincial putz?"
Blazing Saddles
86



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

end of thread, other threads:[~2006-03-25  0:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-22 13:01 Java wrappers around Ada? kk_oop
2006-03-22 13:33 ` Larry Kilgallen
2006-03-23  6:57   ` Anders Wirzenius
2006-03-23 13:10     ` Larry Kilgallen
2006-03-22 13:33 ` Georg Bauhaus
2006-03-22 23:25 ` Jeffrey R. Carter
2006-03-23 22:24 ` James Alan Farrell
2006-03-23 22:59   ` kk_oop
2006-03-24 21:40     ` James Alan Farrell
2006-03-25  0:37       ` Jeffrey R. Carter

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