# 通用语言基础设施

**通用语言基础设施**（Common Language Infrastructure，CLI）是一项开放技术标准，以 ECMA-335 和 ISO/IEC 23271 发布，它规定可执行代码及其运行所在的执行环境（虚拟执行系统），从而使以多种高级语言编写的应用程序能够在不同的系统环境中执行，而无需为每一种环境重写。<sup>[1](https://ecma-international.org/publications-and-standards/standards/ecma-335/)</sup><sup> • </sup><sup>[2](https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf)</sup> 微软的 .NET 运行时和跨平台的 [Mono](https://www.edgepedia.org/zh/mono-software) 运行时即构建于该标准之上。<sup>[3](https://learn.microsoft.com/dotnet/standard/clr)</sup><sup> • </sup><sup>[4](https://www.mono-project.com/docs/advanced/runtime/)</sup>

| 关键事实 | 详情 |
|---|---|
| 标准编号 | ECMA-335（第 6 版，2012 年 6 月）；ISO/IEC 23271:2012，第 3 版，2012 年 2 月发布，546 页<sup>[1](https://ecma-international.org/publications-and-standards/standards/ecma-335/)</sup><sup> • </sup><sup>[5](https://committee.iso.org/standard/58046.html)</sup> |
| 结构 | 六个分区：概念与架构；元数据定义与语义；CIL 指令集；配置与库；调试交换格式；附录<sup>[5](https://committee.iso.org/standard/58046.html)</sup> |
| 核心组件 | 通用类型系统（CTS）、元数据、通用语言规范（CLS）和虚拟执行系统（VES）<sup>[2](https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf)</sup> |
| 起源 | 微软于 2000 年 10 月向 ECMA 提交 C# 和 CLI 规范；ECMA 于 2001 年 12 月 13 日批准<sup>[6](https://news.microsoft.com/source/2001/12/13/ecma-standardizes-key-net-technologies/)</sup> |
| 版本历史 | 第 1 版 2001 年 12 月，第 2 版 2002 年 12 月，第 3 版 2005 年 6 月，第 4 版 2006 年 6 月，第 5 版 2010 年 12 月，第 6 版 2012 年 6 月<sup>[1](https://ecma-international.org/publications-and-standards/standards/ecma-335/)</sup> |
| 实现 | .NET（Core）、.NET Framework 和 Mono；Mono 运行时以 JIT 和提前编译实现 ECMA CLI<sup>[7](https://learn.microsoft.com/et-ee/dotnet/fundamentals/implementations?view=netstandard-1.0)</sup><sup> • </sup><sup>[4](https://www.mono-project.com/docs/advanced/runtime/)</sup> |
| 专利 | 微软针对 ECMA-335 第 4 版（2006 年 6 月）发布了专利声明<sup>[1](https://ecma-international.org/publications-and-standards/standards/ecma-335/)</sup> |

## 目的与架构

该标准定义了一种体系：不同语言的编译器以通用格式生成代码，运行时则依照一套共享的类型规则加载并执行这些代码。可执行代码以模块的形式呈现给虚拟执行系统，其中模块是单个文件，包含符合第 II 分区所规定格式的可执行内容。<sup>[2](https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf)</sup>

设计的核心由四个组件构成：<sup>[2](https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf)</sup>

- **通用类型系统（CTS）** 提供一个丰富的类型系统，支持众多编程语言中常见的类型和操作，旨在支撑广泛语言的完整实现。它定义 CLI 在声明、使用和管理类型时遵循的规则，并促成跨语言集成、类型安全和高性能的代码执行。
- **元数据** 描述并引用 CTS 所定义的类型。其存储方式独立于任何特定编程语言，为编译器、调试器和 VES 提供通用的交换机制。
- **通用语言规范（CLS）** 是语言设计者与类库设计者之间的约定：CTS 的一个子集加上一组使用惯例。凡公开导出的部分仅使用 CLS 类型的框架，均可由任何至少实现了 CTS 中 CLS 部分的语言访问。CLS 规则定义于 ECMA-335 第 I 分区第 7 至第 11 条。<sup>[8](https://learn.microsoft.com/en-us/dotnet/standard/language-independence)</sup>
- **虚拟执行系统（VES）**，亦称执行引擎，实现并强制执行 CTS 模型。它加载并运行面向 CLI 编写的程序，并利用元数据在运行时将分别生成的模块连接起来（后期绑定）。<sup>[2](https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf)</sup>

这些组件共同构成了标准所称的、用于设计、开发、部署和执行分布式组件与应用程序的统一基础设施。<sup>[2](https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf)</sup>

## 六个分区

该标准分为六个分区。<sup>[5](https://committee.iso.org/standard/58046.html)</sup>

1. **第 I 分区，概念与架构**，给出 CTS、VES 和 CLS 的规范性描述，以及元数据的信息性描述。
2. **第 II 分区，元数据定义与语义**，从物理文件格式、逻辑表集合及其关系、以及假设性汇编器 ilasm 的语义三个角度规定元数据。
3. **第 III 分区** 描述通用中间语言（CIL）指令集，即面向 CLI 的编译器所生成的代码的可移植指令格式。
4. **第 IV 分区，配置与库**，概述 CLI 库及其划分为配置与库的方式，并附有一个 XML 文件详述每个类、值类型和接口。
5. **第 V 分区** 定义 CLI 生产者和消费者之间交换调试信息的标准方式。
6. **第 VI 分区，附录**，包含 CIL 汇编语言的示例程序、CIL 指令集的机器可读描述、库设计指南以及可移植性考量。

## 类型安全与验证

该标准规定了一种验证算法，结合各条 CIL 指令的信息和元数据校验，可保证内存完整性：经过验证的代码无法访问程序逻辑地址空间之外的内存。<sup>[9](https://dev.ecma-international.org/wp-content/uploads/ECMA-335_2nd_edition_december_2002.pdf)</sup> 该算法为合规实现设定了一个最低标准，即凡被其判定为可验证的程序，必须在所有合规的 CLI 实现上都被视为可验证并正确运行。实现可以接受额外的程序，例如通过正确跟踪方法指针上的完整签名并允许 `calli` 指令——标准自身的算法并不允许该指令。<sup>[9](https://dev.ecma-international.org/wp-content/uploads/ECMA-335_2nd_edition_december_2002.pdf)</sup>

这一保证以元数据校验为支撑：一旦元数据被验证为正确，后续步骤——验证 CIL 指令流的类型安全、构造方法表、将 CIL 编译为本机代码、以及封送数据——便可在不致使 CLI 崩溃或出现不安全行为的情况下进行。<sup>[10](https://github.com/stakx/ecma-335/blob/master/docs/ii.22.1-metadata-validation-rules.md)</sup>

## 历史与标准化

微软于 2000 年 10 月向 ECMA 提交了 C# 和 CLI 的规范，并与[惠普](https://www.edgepedia.org/zh/hewlett-packard)、IBM、英特尔和网景通信等行业参与者合作，在完成最终规范的技术工作组中协同工作；ECMA 于 2001 年 12 月 13 日批准了 C# 和 CLI 规范。<sup>[6](https://news.microsoft.com/source/2001/12/13/ecma-standardizes-key-net-technologies/)</sup> 这项工作在 Ecma 第 39 技术委员会（后更名为 TC49）中进行，其中第 3 任务组（TC49-TG3）受命标准化一套通用语言基础设施，以支持 C#、ECMAScript 及其他现代语言；其工作纲领涵盖通用类型系统、执行引擎架构、元数据语法与语义、带校验规则的文件格式、确保类型安全的程序验证规则、通用中间语言格式以及一小组基类。<sup>[11](https://ecma-international.org/task-groups/tc49-tg3/)</sup>

该标准历经六个 ECMA 版本修订，从 2001 年 12 月的第 1 版到 2012 年 6 月的第 6 版，后者仍是当前的 ECMA 版本。<sup>[1](https://ecma-international.org/publications-and-standards/standards/ecma-335/)</sup> 相同内容以快速程序提交至 ISO/IEC，编号为 23271；2012 年版（第 3 版）由 [ISO/IEC JTC 1](https://www.edgepedia.org/zh/iso-iec-jtc-1)/SC 22 编制，根据 ISO 记录，该版本于 2026 年经最后评审并确认，因此该版本仍然现行有效。<sup>[5](https://committee.iso.org/standard/58046.html)</sup> 一份配套技术报告 ECMA TR/89 规定了 CLI 的通用泛型。<sup>[1](https://ecma-international.org/publications-and-standards/standards/ecma-335/)</sup>

微软还发布了覆盖 ECMA-335 第 4 版（2006 年 6 月）的专利声明，并于 2001 年与 Corel 共同宣布了 C# 和 CLI 规范的共享源代码实现，可在 FreeBSD 和 Windows 上运行，用于学术、研究、调试和学习目的。<sup>[1](https://ecma-international.org/publications-and-standards/standards/ecma-335/)</sup><sup> • </sup><sup>[12](https://news.microsoft.com/source/2001/06/27/microsoft-expands-commitment-to-open-standards-and-interoperability/)</sup>

## 实现

编译器和工具能够生成符合规范的运行时可以使用的输出，因为类型系统、元数据格式和运行时环境均由公开的 ECMA 规范定义；微软的通用语言运行时（CLR）是最广为人知的 VES 实现。<sup>[3](https://learn.microsoft.com/dotnet/standard/clr)</sup> 微软文档记载了三种主要的 .NET 实现：.NET（Core）、始于 2002 年的原始 .NET Framework，以及 Mono。<sup>[7](https://learn.microsoft.com/et-ee/dotnet/fundamentals/implementations?view=netstandard-1.0)</sup>

Mono 是现以 MIT 许可证分发的开源实现，在其运行时中实现了 ECMA CLI，提供即时编译器、部分和完整的提前编译、库加载器、垃圾回收（精确的 SGen 收集器或保守的 Boehm 收集器）、线程系统、异常处理以及互操作功能。<sup>[4](https://www.mono-project.com/docs/advanced/runtime/)</sup><sup> • </sup><sup>[13](https://www.mono-project.com/docs/about-mono/)</sup> 它可在 Linux、macOS、BSD、微软 Windows 及其他系统上运行，并支持以 C#、VB、Java、Python、[Ruby](https://www.edgepedia.org/zh/ruby-programming-language)、Eiffel、F#、Oxygene 等语言进行开发。<sup>[13](https://www.mono-project.com/docs/about-mono/)</sup>

## References

1. [ECMA-335, Common Language Infrastructure (CLI), Ecma International](https://ecma-international.org/publications-and-standards/standards/ecma-335/)
2. [ECMA-335, 6th edition, June 2012 (PDF), Ecma International](https://www.ecma-international.org/wp-content/uploads/ECMA-335_6th_edition_june_2012.pdf)
3. [Common Language Runtime (CLR) overview, Microsoft Learn](https://learn.microsoft.com/dotnet/standard/clr)
4. [The Mono Runtime, Mono Project](https://www.mono-project.com/docs/advanced/runtime/)
5. [ISO/IEC 23271:2012, Information technology — Common Language Infrastructure (CLI), ISO](https://committee.iso.org/standard/58046.html)
6. [ECMA Standardizes Key .NET Technologies, Microsoft (December 13, 2001)](https://news.microsoft.com/source/2001/12/13/ecma-standardizes-key-net-technologies/)
7. [.NET implementations, Microsoft Learn](https://learn.microsoft.com/et-ee/dotnet/fundamentals/implementations?view=netstandard-1.0)
8. [Language independence and language-independent components, Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/standard/language-independence)
9. [ECMA-335, 2nd edition, December 2002 (PDF), Ecma International](https://dev.ecma-international.org/wp-content/uploads/ECMA-335_2nd_edition_december_2002.pdf)
10. [ECMA-335 Partition II, Metadata Validation Rules (stakx/ecma-335 transcription), GitHub](https://github.com/stakx/ecma-335/blob/master/docs/ii.22.1-metadata-validation-rules.md)
11. [TC49-TG3, Common Language Infrastructure, Ecma International](https://ecma-international.org/task-groups/tc49-tg3/)
12. [Microsoft Expands Commitment to Open Standards and Interoperability, Microsoft (June 27, 2001)](https://news.microsoft.com/source/2001/06/27/microsoft-expands-commitment-to-open-standards-and-interoperability/)
13. [About Mono, Mono Project](https://www.mono-project.com/docs/about-mono/)

---
*Initially written Sep 17, 2026 · Reviewed: Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Compilers, interpreters, and toolchains

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/common-language-infrastructure

English original: https://www.edgepedia.org/common-language-infrastructure
