21
11 December 2002 Weaving Ada into the .NET Framework Martin Carlisle Weaving Ada into the .NET Framework Martin C. Carlisle, Ricky E. Sward Jeffrey W. Humphries United States Air Force Academy Department of Computer Science

Weaving Ada into the .NET Framework

Embed Size (px)

DESCRIPTION

Weaving Ada into the .NET Framework. Martin C. Carlisle, Ricky E. Sward Jeffrey W. Humphries United States Air Force Academy Department of Computer Science. DISCLAIMER. - PowerPoint PPT Presentation

Citation preview

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Weaving Ada into the .NET Framework

Martin C. Carlisle, Ricky E. Sward

Jeffrey W. HumphriesUnited States Air Force Academy

Department of Computer Science

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

DISCLAIMER

• Opinions in this talk are those of the speaker and not necessarily those of the US Air Force Academy, US Air Force, US Department of Defense, or US Government.

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

What is .NET?

• Microsoft’s answer to Java– Language independent runtime – Microsoft Intermediate Language (MSIL)

• JIT compiled

– Large collection of classes (CoreEE)– Flagship language is C#

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Our Objectives

• Be able to write Ada code that compiles to a .NET executable

• Be able to use .NET classes from within Ada

• Be able to use Ada components in other .NET languages

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Starting Point

• Largely derived from JGNAT, a GNAT port to the JVM

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Provided Tools

• MSIL2Ada– Extract Ada specifications from .NET DLLs

• MGNAT– Compiles Ada to MSIL

• RAPID– Ported to A# (Ada for .NET)

• AdaGIDE allows targeting .NET• http://www.usafa.af.mil/dfcs/bios/mcc_html/

a_sharp.html

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

MSIL2Ada Process

• Disassemble .NET DLL using ILDASM (from .NET Framework SDK)

• Run MSIL2Ada on resultant text file– MSIL2Ada based on AdaGOOP

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

MSIL2Ada process

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

MSIL2Ada Output

package TimeLibrary.Time3 is type Typ is new MSSyst.Object.Typ with null record; type Ref is access all Typ'Class; … function new_Time3 ( This : Ref := null; hour : Integer; minute : Integer) return Ref; -- constructor for Time3 function get_Hour (This : access Typ) return Integer; procedure set_Hour ( This : access Typ; value : Integer);

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

MSIL2Ada Output - Interfaces

type Typ(

I_IContainerControl : IContainerControl.Ref;

I_ISynchronizeInvoke : ISynchronizeInvoke.Ref)

is new ContainerControl.Typ(

I_IContainerControl => I_IContainerControl) with null record;

-- Use X.I_IContainerControl to cast X as the IContainerControl interface

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

MSIL2Ada Output - Constructor

pragma MSIL_Constructor(new_MenuItem);

function New_MenuItem(This : Ref := null) return Ref is Super : MenuItem.Ref := MenuItem.New_MenuItem(MenuItem.Ref(This)); begin return This; -- note Super is never used! (compiler magic) end New_MenuItem;

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

MSIL2Ada Output - ValueType

• Unlike Java, .NET has ValueTypes, which are passed by copy

• Introduce ValueType reserved word – types with this name follow this calling convention

• Example: Point record (X,Y)

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

MSIL2Ada Output - Enumerations

• .NET also provides enumerations (children of ValueType)

• Mapped to Ada enumerations, although they are not true enumerations! (Bold+Italic)

• Add function “+” to Ada spec to allow combination

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Compiling to MSIL

• Goal to simplify use of .NET classes and provide a stronger OO feel to Ada

• Result: added object.method calling syntax to MGNAT

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Object.Method syntax

C#:

Window1.ResetSecurityTip(true);

Ada:

MSSyst.Windows.Forms.ResetSecurityTip(

This => Window1,

modalOnly => True);

A#:

Window1.ResetSecurityTip(modalOnly => True);

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Object.Method syntax

• Also incorporated into GNAT 3.15 for Windows (local version only)

• 127 non-blank, non-comment lines of Ada code to make this change.

• Recommend allowing as an option in Ada 0X.

• Support traditional Ada syntax also

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Implicit string conversions

• To simplify calling .NET libraries, implicitly convert from Ada string to MSSyst.String.Ref

• Only if “use MSSyst.String”

• E.g. Console.Writeline(“Hello Ada”);

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

RAPID

• Ported RAPID to .NET platform

• In general easier than JGNAT port, but– No bell– Can’t group radio buttons without GroupBox– Can only attach menubar to window

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

New since paper

• Ada projects for Visual Studio .NET

• Compiled Ada libraries using MGNAT– No dependence on J#– Demonstrates interoperability of C# and A#

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Possible future work

• Continue development for Ada for Visual Studio .NET

• Rewrite MSIL2Ada using Reflection– Eliminates need for .NET Framework SDK

• Change .NET enumerations to named constants

11 December 2002 Weaving Ada into the .NET FrameworkMartin Carlisle

Conclusions

• A# project provides a clean interface to allow interoperability between Ada and other .NET languages

• Huge .NET libraries now available to Ada programmers