Chapter 1.3. IL Intermediate Language

I l @ ve RuBoard

IN THIS CHAPTER

  • Language Inter-Op

  • Hello IL

  • Functions

  • Classes

  • ILDASM

  • Metadata

  • Reflection API

In the current day and age of software development, developers use high-level languages such as C++, Visual Basic, or Java to implement applications and components . I personally don't know any working binary developers and few assembly language programmers.

So why is IL, Intermediate Language, so important to .NET? To answer this question requires a brief tour of compiler theory 101. The basic task of a compiler is to transform readable source code into native executable code for a given platform. The compilation process includes several phases, which include but are not limited to lexical scanning, parsing, abstract syntax tree creation, intermediate code creation, code emission, assembler, and linking. Figure 1.3.1 shows a basic diagram of this process.

Figure 1.3.1. The basic compilation process.

graphics/0103fig01.gif

The intermediate code creation poses an interesting question: What if it's possible to translate a given set of languages into some standard intermediate code? This is where IL fits into the scheme of things. The ability to translate high-level language constructs into a standardized format, such as IL, allows for a single underlying compiler or just-in-time (JIT) compiler. This is the approach taken by .NET.

With the introduction of Visual Studio .NET, Microsoft is providing Managed C++, C#, Visual Basic, and ASP.NET, each of which produce IL from their respective source code. There are also several third-party language vendors providing .NET versions of their respective languages. Figure 1.3.2 shows the basic .NET compilation process.

Figure 1.3.2. .NET compilation.

graphics/0103fig02.gif

It is important to note that IL is not interpreted. Rather, the .NET platform makes use of various types of just-in-time compilers to produce native code from the IL code. Native code runs directly on the hardware and does not require a virtual machine, as is the case with Java and early versions of Visual Basic. By compiling IL to native code, the runtime performance is increased compared to interpreted languages that run on top of a virtual machine. We will be covering the various types of just-in-time compilers later on. (From here on out I will refer to the just-in-time compiler(s) as the jitter ).

IL is a full, stack-based language that you can use to implement .NET components. Although it is definitely not suggested for the sake of productivity, you can use IL to do things that you can't do with C#. For example, in IL, you can create global functions and call them from within IL.

I l @ ve RuBoard


C# and the .NET Framework. The C++ Perspective
C# and the .NET Framework
ISBN: 067232153X
EAN: 2147483647
Year: 2001
Pages: 204

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net