\subsubsection{.NET in a Nutshell} \input{dotNet} \subsubsection{Mapping \ootype types to .NET} \label{sect:cli-types} Most of \ootype 's types can be mapped to .NET in a straight-forward way. All the primitive types have a direct correpondent in the CLI type-system, including signed and unsigned integers, floating point numbers, strings and characters. Moreover, as of version 2.0, the CLI supports \emph{generics}, i.e. parametric types. GenCLI exploits generics to implement collection types such as \lstinline{List} and \lstinline{Dict}, which are parametrized by the type of their items, as explained in section \ref{sect:ootype}. By contrast, since JVM does not support generic types, GenJVM needs to simulate them by using type erasure (see section \ref{sect:jvm-generics}). \subsubsection{First-order functions and classes} A significant difference between \ootype and CLI is that the latter does not support first-order functions. .NET \emph{delegates} are exploited to encode them: a new delegate type is created for each different signature of the functions we want to use, then they are wrapped inside \emph{delegate objects} and passed around: finally, to call such a wrapped function we simply call the \emph{Invoke} method of the delegate. Finally, \ootype also supports classes as first-order objects, while CLI does not: to solve the problem we can pass around the instance of \lstinline{System.Type} which corresponds to the class instead of the class itself. Then we can dynamically create an instance of that class by calling the helper method shown below, which is written in C\# and uses reflection to get the default constructor and call it: \begin{lstlisting}[language=Java] public static object RuntimeNew(Type t) { return t.GetConstructor(new Type[0])\ .Invoke(new object[0]); } \end{lstlisting} \subsubsection{Accessing the .NET libraries} One of the major advantages of using a .NET compiler is to be able to use the vast library of existing classes. GenCLI allow the programmer to access the external .NET libraries, though work remains to smooth the rough edges that exist between the two worlds. In particular, the current syntax is less than ideal. For example, the GenCLI does not yet support \emph{indexers} \footnote{In .NET an indexer is a special method that is usually callable through the square bracked notation, as it were an array} or properties, and the only way to call them is to directly call the underlying methods. Overloaded methods are fully supported, even though the concept of overloading does not exist in the Python world. The types inferred by the annotator are used to select the most appropriate overloading for a given method. For example, the following is a valid RPython program that makes use of the native \lstinline{ArrayList} and \lstinline{Console} classes. \begin{lstlisting} Console = CLR.System.Console ArrayList = CLR.System.Collections.ArrayList def main(): mylist = ArrayList() mylist.Add("world") Console.WriteLine( "Hello {0}", mylist.get_Item(0)) Console.WriteLine( "mylist.Count = {0}", mylist.get_Count()) \end{lstlisting} As shown by the example, the items of the \lstinline{ArrayList} instance can be accessed only by calling \lstinline{get\_Item}, as well as the \lstinline{Count} property can be read only by calling \lstinline{get\_Count}.