Archive for January, 2008

Business web site - CHAPTER 15 UNDERSTANDING CIL AND THE 496

Monday, January 21st, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE 496 THE ROLE OF DYNAMIC ASSEMBLIES To provide some insight to the world of member implementation via CIL, Table 15-5 defines some of the more useful opcodes that are directly related to member implementation logic, grouped by related functionality. Table 15-5. Various Implementation-Specific CIL Opcodes Opcodes Meaning in Life add, sub, mul, div, rem These CIL opcodes allow you to add, subtract, multiply, and divide two values (rem returns the remainder of a division operation). and, or, not, xor These CIL opcodes allow you to perform binary operations on two values. ceq, cgt, clt These CIL opcodes allow you to compare two values on the stack in various manners, for example: ceq: Compare for equality cgt: Compare for greater than clt: Compare for less than box, unbox These CIL opcodes are used to convert between reference types and value types. ret This CIL opcode is used to exit a method and return a value to the caller (if necessary). beq, bgt, ble, blt, switch These CIL opcodes (in addition to many other related opcodes) are used to control branching logic within a method, for example: beq: Break to code label if equal bgt: Break to code label if greater than ble: Break to code label if less than or equal to blt: Break to code label if less than All of the branch-centric opcodes require that you specify a CIL code label to jump to if the result of the test is true. call This CIL opcode is used to call a member on a given type. newarr, newobj These CIL opcodes allow you to allocate a new array or new object type into memory (respectively). The next broad category of CIL opcodes (a subset of which is shown in Table 15-6) are used to load (push) arguments onto the virtual execution stack. Note how these load-specific opcodes take an ld (load) prefix. Table 15-6. The Primary Stack-Centric Opcodes of CIL Opcode Meaning in Life ldarg (with numerous variations) Loads a method s argument onto the stack. In addition to the generic ldarg (which works in conjunction with a given index that identifies the argument), there are numerous other variations. For example, ldarg opcodes that have a numerical suffix (ldarg_0) hard-code which argument to load. As well, variations of the ldarg opcode allow you to hardcode the data type using the CIL constant notation shown in Table 15-4 (ldarg_I4, for an int32) as well as the data type and value (ldarg_I4_5, to load an int32 with the value of 5). ldc (with numerous variations) Loads a constant value onto the stack. ldfld (with numerous variations) Loads the value of an instance-level field onto the stack. ldloc (with numerous variations) Loads the value of a local variable onto the stack.
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

CHAPTER 15 (Domain and web hosting) UNDERSTANDING CIL AND THE ROLE

Sunday, January 20th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES 495 Recall that in terms of CIL, a property maps to a pair of methods that take get_ and set_ prefixes. The .property directive makes use of the related .get and .set directives to map property syntax to the correct specially named methods. Note The previous property definitions will fail to compile, given that you have not yet implemented the mutator logic. Defining Member Parameters Now assume that you wish to define methods that take some number of arguments. In a nutshell, specifying arguments in CIL is (more or less) identical to doing so in C#. For example, each argument is defined by specifying its data type followed by the parameter name. Furthermore, like C#, CIL provides a way to define input, output, and pass-by-reference parameters. As well, CIL allows you to define a parameter array argument (aka the C# params keyword) as well as optional parameters (which are not supported in C#, but are used in VB .NET). To illustrate the process of defining parameters in raw CIL, assume you wish to build a method that takes an int32 (by value), int32 (by reference), a [mscorlib]System.Collection.ArrayList, and a single output parameter (of type int32). In terms of C#, this method would look something like the following: public static void MyMethod(int inputInt, ref int refInt, ArrayList ar, out int outputInt) { outputInt = 0; // Just to satisfy the C# compiler… } If you were to map this method into CIL terms, you would find that C# reference parameters are marked with an ampersand (&) suffixed to the parameter s underlying data type (int32&). Output parameters also make use of the & suffix, but they are further qualified using the CIL [out] token. Also notice that if the parameter is a reference type (in this case, the [mscorlib]System.Collections. ArrayList type), the class token is prefixed to the data type (not to be confused with the .class directive!): .method public hidebysig static void MyMethod(int32 inputInt, int32& refInt, class [mscorlib]System.Collections.ArrayList ar, [out] int32& outputInt) cil managed { … } Examining CIL Opcodes The final aspect of CIL code you ll examine in this chapter has to do with the role of various operational codes (opcodes). Recall that an opcode is simply a CIL token used to build the implementation logic for a given member. The complete set of CIL opcodes (which is fairly large) can be grouped into the following broad categories: Opcodes that control program flow Opcodes that evaluate expressions Opcodes that access values in memory (via parameters, local variables, etc.)
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

CHAPTER 15 UNDERSTANDING CIL AND THE 494 (Web server application)

Saturday, January 19th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE 494 THE ROLE OF DYNAMIC ASSEMBLIES Defining Type Constructors in CIL The CTS supports both instance-level and class-level (static) constructors. In terms of CIL, instancelevel constructors are represented using the .ctor token, while a static-level constructor is expressed via .cctor (class constructor). Both of these CIL tokens must be qualified using the rtspecialname (return type special name) and specialname attributes. Simply put, these attributes are used to identify a specific CIL token that can be treated in unique ways by a given .NET language. For example, in C#, constructors do not define a return type; however, in terms of CIL, the return value of a constructor is indeed void: .class public MyBaseClass { .field private string stringField .field private int32 intField .method public hidebysig specialname rtspecialname instance void .ctor(string s, int32 i) cil managed { // TODO: Add implementation code… } } Note that the .ctor directive has been qualified with the instance attribute (as it is not a static constructor). The cil managed attributes denote that the scope of this method contains CIL code, rather than unmanaged code, which may be used during platform invocation requests. Defining Properties in CIL Properties and methods also have specific CIL representations. By way of an example, if MyBaseClass were updated to support a public property named TheString, you would author the following CIL (note again the use of the specialname attribute): .class public MyBaseClass { … .method public hidebysig specialname instance string get_TheString() cil managed { // TODO: Add implementation code… } .method public hidebysig specialname instance void set_TheString(string ‘value’) cil managed { // TODO: Add implementation code… } .property instance string TheString() { .get instance string MyNamespace.MyBaseClass::get_TheString() .set instance void MyNamespace. MyBaseClass::set_TheString(string) } }
Check Tomcat Web Hosting services for best quality webspace to host your web application.

CHAPTER 15 UNDERSTANDING CIL AND THE (Web server extensions) ROLE

Saturday, January 19th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES 493 .NET Base Class Type C# Keyword CIL Representation CIL Constant Notation System.Boolean bool bool BOOLEAN System.String string string N/A System.Object object object N/A System.Void void void VOID Defining Type Members in CIL As you are already aware, .NET types may support various members. Enumerations have some set of name/value pairs. Structures and classes may have constructors, fields, methods, properties, static members, and so on. Over the course of this book s first 14 chapters, you have already seen partial CIL definitions for the items previously mentioned, but nevertheless, here is a quick recap of how various members map to CIL primitives. Defining Field Data in CIL Enumerations, structures, and classes can all support field data. In each case, the .field directive will be used. For example, let s breathe some life into the skeleton MyEnum enumeration and define three name/value pairs (note the values are specified using a parentheses syntax): .class public auto ansi sealed MyEnum extends [mscorlib]System.Enum { .field public static literal valuetype MyNamespace.MyEnum NameOne = int32(0) .field public static literal valuetype MyNamespace.MyEnum NameTwo = int32(1) .field public static literal valuetype MyNamespace.MyEnum NameThree = int32(2) } Fields that reside within the scope of a .NET System.Enum-derived type are qualified using the static and literal attributes. As you would guess, these attributes set up the field data to be a fixed value accessible from the type itself (e.g., MyEnum.NameOne). Note The values assigned to an enum value may also be in hexadecimal. Of course, when you wish to define a point of field data within a class or structure, you are not limited to a point of public static literal data. For example, you could update MyBaseClass to support two points of private, instance-level field data: .class public MyBaseClass { .field private string stringField .field private int32 intField } As in C#, class field data will automatically be assigned to the correct default value. If you wish to allow the object user to supply custom values at the time of creation for each of these points of private field data, you (of course) need to create custom constructors.
Note: In case you are looking for affordable and reliable webhost to host and run your j2ee application check Vision J2ee Web Hosting services.

Web hosting colocation - CHAPTER 15 UNDERSTANDING CIL AND THE 492

Friday, January 18th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE 492 THE ROLE OF DYNAMIC ASSEMBLIES Figure 15-4. The CILTypes.dll assembly Once you have confirmed the contents of your assembly, run peverify.exe against it. Notice that you are issued a number of errors, given that all your types are completely empty. To understand how to populate a type with content, you first need to examine the fundamental data types of CIL. Source Code The CilTypes.il file is included under the Chapter 15 subdirectory. .NET Base Class Library, C#, and CIL Data Type Mappings Table 15-4 illustrates how a .NET base class type maps to the corresponding C# keyword, and how each C# keyword maps into raw CIL. As well, Table 15-4 documents the shorthand constant notations used for each CIL type. As you will see in just a moment, these constants are often referenced by numerous CIL opcodes. Table 15-4. Mapping .NET Base Class Types to C# Keywords, and C# Keywords to CIL .NET Base Class Type C# Keyword CIL Representation CIL Constant Notation System.SByte sbyte int8 I1 System.Byte byte unsigned int8 U1 System.Int16 short int16 I2 System.UInt16 ushort unsigned int16 U2 System.Int32 int int32 I4 System.UInt32 uint unsigned int32 U4 System.Int64 long int64 I8 System.UInt64 ulong unsigned int64 U8 System.Char char char CHAR System.Single float float32 R4 System.Double double float64 R8
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

CHAPTER 15 UNDERSTANDING CIL (Most popular web site) AND THE ROLE

Thursday, January 17th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES 491 // Extending interfaces in terms of CIL. .class public interface IMyInterface {} .class public interface IMyOtherInterface implements MyNamespace.IMyInterface {} Defining Structures in CIL The .class directive can be used to define a CTS structure if the type extends System.ValueType. As well, the .class directive is qualified with the sealed attribute (given that structures can never be a base structure to other value types). If you attempt to do otherwise, ilasm.exe will issue a compiler error. // A structure definition is always sealed. .class public sealed MyStruct extends [mscorlib]System.ValueType{} Do be aware that CIL provides a shorthand notation to define a structure type. If you use the value attribute, the new type will derive the type from [mscorlib]System.ValueType and be marked as sealed automatically. Therefore, you could define MyStruct as so: // Shorthand notation for declaring a structure. .class public value MyStruct{} Defining Enums in CIL .NET enumerations (as you recall) derive from System.Enum, which is a System.ValueType (and therefore must also be sealed). When you wish to define an enum in terms of CIL, simply extend [mscorlib]System.Enum: // An enum. .class public sealed MyEnum extends [mscorlib]System.Enum{} Like a structure definition, enumerations can be defined with a shorthand notation using the enum attribute: // Enum shorthand. .class public enum MyEnum{} Note The other fundamental .NET type, the delegate, also has a specific CIL representation. See Chapter 8 for full details. Compiling the CILTypes.il file Even though you have not yet added any members or implementation code to the types you have defined, you are able to compile this *.il file into a .NET DLL assembly (which you must do, as you have not specified a Main() method). Open up a command prompt and enter the following command to ilasm.exe: ilasm /dll CilTypes.il Once you have done so, you are able to open your binary into ildasm.exe (see Figure 15-4).
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

CHAPTER 15 UNDERSTANDING (Web server application) CIL AND THE 490

Wednesday, January 16th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE 490 THE ROLE OF DYNAMIC ASSEMBLIES To correctly define the parent class of MyDerivedClass, you must specify the full name of MyBaseClass as so: // Better! .namespace MyNamespace { .class public MyBaseClass {} .class public MyDerivedClass extends MyNamespace.MyBaseClass {} } In addition to the public and extends attributes, a CIL class definition may take numerous additional qualifiers that control the type s visibility, field layout, and so on. Table 15-3 illustrates some (but not all) of the attributes that may be used in conjunction with the .class directive. Table 15-3. Various Attributes Used in Conjunction with the .class Directive Attributes Meaning in Life public, private, nested assembly, CIL defines various attributes that are used to specify the nested famandassem, nested family, visibility of a given type. As you can see, raw CIL offers nested famorassem, nested public, numerous possibilities other than those offered by C#. nested private abstract These two attributes may be tacked onto a .class directive sealed to define an abstract class or sealed class, respectively. auto These attributes are used to instruct the CLR how to lay sequential out field data in memory. For class types, the default layout explicit flag (auto) is appropriate. extends These attributes allow you to define the base class of a type implements (via extends) or implement an interface on a type (via implements). Defining and Implementing Interfaces in CIL As odd as it may seem, interface types are defined in CIL using the .class directive. However, when the .class directive is adorned with the interface attribute, the type is realized as a CTS interface type. Once an interface has been defined, it may be bound to a class or structure type using the CIL implements attribute: .namespace MyNamespace { // An interface definition. .class public interface IMyInterface {} .class public MyBaseClass {} // DerivedTestClass now implements IAmAnInterface. .class public MyDerivedClass extends MyNamespace.MyBaseClass implements MyNamespace.IMyInterface {} } As you recall from Chapter 7, interfaces can function as the base interface to other interface types in order to build interface hierarchies. However, contrary to what you might be thinking, the extends attribute cannot be used to derive interface A from interface B. The extends attribute is used only to qualify a type s base class. When you wish to extend an interface, you will make use of the implements attribute yet again:
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

CHAPTER 15 (Space web hosting) UNDERSTANDING CIL AND THE ROLE

Tuesday, January 15th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES 489 Table 15-2. Additional Assembly-Centric Directives Directive Meaning in Life .mresources If your assembly makes use of internal resource (such as bitmaps or string tables), this directive is used to identify the name of the file that contains the resources to be embedded. Chapter 20 examines .NET resources in detail. .subsystem This CIL directive is used to establish the preferred UI that the assembly wishes to execute within. For example, a value of 2 signifies that the assembly should run within a Forms-based GUI, whereas a value of 3 denotes a console application. Defining Namespaces in CIL Now that you have defined the look and feel of your assembly (and the required external references), you can create a .NET namespace (MyNamespace) using the .namespace directive: // Our assembly has a single namespace. .namespace MyNamespace {} Like C#, CIL namespace definitions can be nested within an outer namespace. For the sake of argument, assume you wish to create a root namespace named IntertechTraining: .namespace IntertechTraining { .namespace MyNamespace {} } Like C#, CIL allows you to define a nested namespace as so: // Defining a nested namespace. .namespace IntertechTraining.MyNamespace{} Defining Class Types in CIL Empty namespaces are not very interesting, so let s now check out the process of defining a class type using CIL. Not surprisingly, the .class directive is used to define a new class type. However, this simple directive can be adorned with numerous additional attributes, to further qualify the nature of the type. To illustrate, add a simple public class named MyBaseClass. As in C#, if you do not specify an explicit base class, your type will automatically be derived from System.Object: .namespace MyNamespace { // System.Object base class assumed. .class public MyBaseClass {} } When you are building a class type that derives from any class other than System.Object, you make use of the extends attribute. Whenever you need to reference a type defined within the same assembly, CIL demands that you also make use of the fully qualified name (however, if the base type is within the same assembly, you can omit the assembly s friendly name prefix). Therefore, the following attempt to extend MyBaseClass results in a compiler error: // This will not compile! .namespace MyNamespace { .class public MyBaseClass {} .class public MyDerivedClass extends MyBaseClass {} }
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

Web hosting rating - CHAPTER 15 UNDERSTANDING CIL AND THE 488

Monday, January 14th, 2008

CHAPTER 15 UNDERSTANDING CIL AND THE 488 THE ROLE OF DYNAMIC ASSEMBLIES Specifying Externally Referenced Assemblies in CIL Create a new file named CilTypes.il using your editor of choice. First, you need to list the set of external assemblies used by the current assembly. For this example, you will only make use of types found within mscorlib.dll. To do so, the .assembly directive will be qualified using the external attribute. When you are referencing a strongly named assembly, such as mscorlib.dll, you ll want to specify the .publickeytoken and .ver directives as well: .assembly extern mscorlib { .publickeytoken = (B7 7A 5C 56 19 34 E0 89 ) .ver 2:0:0:0 } Note Strictly speaking, you are not required to explicitly reference mscorlib.dll as an external reference, as ilasm.exe will do so automatically. Defining the Current Assembly in CIL The next order of business is to define the assembly you are interested in building using the .assembly directive. At the simplest level, an assembly can be defined by specifying the friendly name of the binary: // Our assembly. .assembly CILTypes { } While this indeed defines a new .NET assembly, you will typically place additional directives within the scope of the assembly declaration. For this example, update your assembly definition to include a version number of 1.0.0.0 using the .ver directive (note that each numerical identifier is separated by colons, not the C#-centric dot notation): // Our assembly. .assembly CILTypes { .ver 1:0:0:0 } Given that the CILTypes assembly is a single-file assembly, you will finish up the assembly definition using a single .module directive, which marks the official name of your .NET binary, CILTypes.dll: .assembly CILTypes { .ver 1:0:0:0 } // The module of our single-file assembly. .module CILTypes.dll In addition to .assembly and .module are CIL directives that further qualify the overall structure of the .NET binary you are composing. Table 15-2 lists a few of the more common assembly-level directives.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Web design online - Figure 15-3. ILIDE# is a free CIL IDE.

Sunday, January 13th, 2008

Figure 15-3. ILIDE# is a free CIL IDE. CHAPTER 15 UNDERSTANDING CIL AND THE ROLE OF DYNAMIC ASSEMBLIES 487 The Role of peverify.exe When you are building or modifying assemblies using CIL code, it is always advisable to verify that the compiled binary image is a well-formed .NET image using the peverify.exe command-line tool: peverify HelloProgram.exe This tool will examine all opcodes within the specified assembly for valid CIL code. For example, in terms of CIL code, the evaluation stack must always be empty before exiting a function. If you forget to pop off any remaining values, the ilasm.exe compiler will still generate a valid assembly (given that compilers are concerned only with syntax). peverify.exe, on the other hand, is concerned with semantics. If you did forget to clear the stack before exiting a given function, peverify.exe will let you know. Source Code The HelloProgram.il file is included under the Chapter 15 subdirectory. Understanding CIL Directives and Attributes Now that you have seen how ildasm.exe and ilasm.exe can be used to perform a round-trip, we can get down to the business of checking out the syntax and semantics of CIL itself. The next sections will walk you through the process of authoring a custom namespace containing a set of types. However, to keep things simple, these types will not contain any implementation logic for their members. Once you understand how to create empty types, you can then turn your attention to the process of providing real members using CIL opcodes.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.