Introduction to CLR (1), Introduction to CLR (

Source: Internet
Author: User
Tags perl interpreter windows x86

Introduction to CLR (1), Introduction to CLR (

What is the universal language runtime (CLR)? To put it simply:

CLR is a complete advanced virtual machine that supports multi-programming languages and multi-language interoperability.

It is a bit confusing and not very enlightening, but the above text is the first step to classify large and complex CLR functions for easy understanding. It helps us understand the design goals of CLR from a height of 10 thousand feet. From this perspective, we can go deep into the various components of CLR.

CLR: A (rare) complete programming platform

Each program has an astonishing number of runtime dependencies. Although the program is clearly written by a specific programming language, it is only one of the basis for programmers to write programs. Every useful program requires someRuntime function librarySo that it can interact with other computer resources (such as user input devices, disk files, and network communication. The program also needs to be converted into a format that can be directly executed by computer hardware. The number and scope of these dependencies are so large that Programming Language designers usually reference other standards to regulate them. For example, the C ++ programming language does not specify the format of the C ++ program. Each C ++ compiler is associated with a specific hardware architecture (such as the x86 architecture, associated with a specific operating system environment (such as Windows, Linux, or Mac OS). These architectures and environments define the file format and Loading Method of executable files. Therefore, programmers are not writing a "C ++ executable program", but "Windows X86 executable program" or "Power PC Mac OS executable program ".

Reusing existing hardware or operating system standards is usually a good thing, but it makes it difficult to abstract new specifications above existing standards. For example, today's operating system does not support garbage collection. Therefore, existing standards cannot be used to support the garbage collection interface (for example, to transmit strings, you do not need to delete them ). Similarly, a typical executable file format only provides enough information to run the program, but not enough for the compiler to bind other executable files to run together. For example, C ++ programs generally use a standard library that contains frequently-used functions (such as printf) (msvcrt. dll in Windows), but this library is not enough. Without corresponding header files (such as stdio. h), programmers cannot use these function libraries. Therefore, the existing executable file format standards cannot describe the executable file format at the same time, and add other information.

CLR defines a [very complete specification] ecma-spec to describe all information about a program from compilation to dependency binding during deployment to the entire life cycle of running. Therefore, apart from other details, CLR defines

  • A set of virtual machines that support GC and contain their own instruction sets (Common intermediate language-CLI) that execute basic program operations, which means that CLR does not need to rely on the specified type of CPU;
  • A set of metadata that describes elements declared in a program (such as types, values, variables, and so on, so that the compiler has enough information to call functions in the program from the "external" when generating other executable files;
  • A file format that accurately describes how bytes should be distributed in files. In this way, we will discuss clr exe without binding to a specific operating system or computer hardware;
  • The lifecycle semantics of a process. That is, a clr exe references other clr exe mechanisms, and the CLR finds the rules for the process dependent files at runtime;
  • Using a class library with built-in CLR functions (such as garbage collection, exceptions, and generics), in addition to providing basic functions such as integer, String, array, list, and dictionary, it also provides operating system services such as file, network, and UI interaction.
Multi-Programming Language Support

Defining, standardizing, and implementing these details are a daunting task, which is why CLR-like full abstraction is rare. In fact, most abstractions are designed for a single programming language. For example, the Perl interpreter or Early Visual Basic runtime provides similar complete abstraction during Java runtime. But CLR differs from these pioneers in that it supports multiple programming languages. In addition to Visual Basic (because it uses the COM Object Model), the experience of using only one programming language is very good, but the experience is a little poor for interoperability with other programming languages. The difficulty of interoperation between programming languages is that these programming languages can only communicate with the "foreign" programming language through the primitives provided by the operating system. However, the abstract level of the operating system is too low (for example, the operating system does not provide memory garbage collection), so it has to adopt some complicated technologies. By providingGeneral Language Runtime, CLR allows high-order structure (for example, GC Data Structure) communication between programming languages, greatly reducing the trouble of interoperability.

BecauseManyLanguage sharing means that more resources are supported. A good debugger and performance analysis tool for a programming language requires a lot of work. Therefore, only some very important programming languages can have complete tool chain support. However, the programming languages implemented on CLR can share these infrastructures, greatly reducing the workload for implementing new programming languages. Perhaps more importantly, all programming languages implemented on CLR can accessAllClass Library implemented on CLR. The huge and increasing (strict debugging and Support) feature is an important reason for CLR's success.

In short, CLR is a complete specification for saving bytes to files to create and run programs. Virtual machines can run these programs using class libraries written in different programming languages. This virtual machine, as well as the ever-increasing class libraries running on it, is what we call the universal language runtime (CLR ).

From collection:. NET Framework source code parsing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.