220 likes | 358 Views
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.
E N D
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 Martin 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. Weaving Ada into the .NET Framework Martin 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# Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin Carlisle
Starting Point • Largely derived from JGNAT, a GNAT port to the JVM Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin Carlisle
MSIL2Ada Process • Disassemble .NET DLL using ILDASM (from .NET Framework SDK) • Run MSIL2Ada on resultant text file • MSIL2Ada based on AdaGOOP Weaving Ada into the .NET Framework Martin Carlisle
MSIL2Ada process Weaving Ada into the .NET Framework Martin 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); Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin 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; Weaving Ada into the .NET Framework Martin 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) Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin Carlisle
Object.Method syntax C#: Window1.ResetSecurityTip(true); Ada: MSSyst.Windows.Forms.ResetSecurityTip( This => Window1, modalOnly => True); A#: Window1.ResetSecurityTip(modalOnly => True); Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin 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”); Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin 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# Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin 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 Weaving Ada into the .NET Framework Martin Carlisle