日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

ECMA-335 (CLI) 标准 读书笔记——总结CLI类型系统(上)

發(fā)布時間:2023/12/19 windows 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ECMA-335 (CLI) 标准 读书笔记——总结CLI类型系统(上) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
??? 看到類型系統(tǒng)的概述時,就忍不住按圖索驥,想搞清楚CLI如何定義的整個類型系統(tǒng)。于是翻遍了整個標(biāo)準(zhǔn),將類型系統(tǒng)中最核心的、與運行平臺密切相關(guān)的類型定義與說明整理了出來,以供理清思路。

?

??? 標(biāo)準(zhǔn)的第四部指出,CLI的核心是Kernel Profile,而Kernel ProfileRuntime infrastructure libraryBase Class Library (BCL) 組成。

?

?

·???????? Runtime infrastructure library CLI提供了編譯器需要的服務(wù)和從特定格式的文件流中動態(tài)調(diào)用類型的能力,CLI規(guī)范的第二部中指定了這些特定的文件格式。

·???????? BCL是現(xiàn)代編程語言的一個簡單的運行時庫,它作為C#語言運行時庫的標(biāo)準(zhǔn),同時也作為CLI標(biāo)準(zhǔn)庫的一部分。它提供了類型來描述CLI的內(nèi)建數(shù)據(jù)類型,簡單的文件存取,定制屬性,安全屬性,字符串處理,格式化,流,集合等等。

??

這里我們可以看出支持CLI核心特征的Runtime infrastructure library主要由指令系統(tǒng)構(gòu)成,而BCL則主要由類型系統(tǒng)構(gòu)成。所以我們研究CLI的核心就要從它的指令系統(tǒng)和類型系統(tǒng)入手。

?

我們先來總結(jié)一下CLI的類型系統(tǒng)。

通用類型系統(tǒng)的概述請參考:ECMA- 335(CLI)標(biāo)準(zhǔn) 讀書筆記(第一部:概念和架構(gòu) 8~8.2

類型分為值類型和引用類型。

值類型分為內(nèi)建值類型和用戶定義類型。

引用類型分為自描述、接口、指針和內(nèi)建引用類型。

?

類型系統(tǒng)里最核心的是內(nèi)建類型,包括內(nèi)建值類型和引用類型。其它的特征則可以根據(jù)不同的系統(tǒng)平臺要求在實現(xiàn)時進(jìn)行裁減。

?

第二部 7 類型和簽名

元數(shù)據(jù)提供了定義和引用類型的機制。第10章描述了與類型定義相關(guān)的元數(shù)據(jù),這里不區(qū)分類型是類,接口還是值類型。

用于引用類型的機制分為以下兩部分:

·???????? 用戶定義類型的邏輯描述,該類型被引用但沒定義在當(dāng)前模塊中,它們被存儲于元數(shù)據(jù)的表中(22.38章)。

·???????? 編碼一個或更多類型引用的簽名,除了多種修飾語外。語法非終結(jié)符的Type描述了簽名中的獨特入口。簽名的編碼在23.1.16章詳述。

7.1 內(nèi)建類型

下面的表詳細(xì)列出了CLI中所有的內(nèi)建類型(包括指針類型):

Type ::=

Description

Clause

‘!’ Int32

Generic parameter in a type definition, accessed by index from 0

9.1

| ‘!!’ Int32

Generic parameter in a method definition, accessed by index from 0

9.2

| bool

Boolean

7.2

| char

16-bit Unicode code point

7.2

| class TypeReference

User defined reference type

7.3

| float32

32-bit floating-point number

7.2

| float64

64-bit floating-point number

7.2

| int8

Signed 8-bit integer

7.2

| int16

Signed 16-bit integer

7.2

| int32

Signed 32-bit integer

7.2

| int64

Signed 64-bit integer

7.2

| method CallConv Type ‘*’

‘(’ Parameters ‘)’

Method pointer

14.5

| native int

32- or 64-bit signed integer whose size is platform-specific

7.2

| native unsigned int

32- or 64-bit unsigned integer whose size is platform-specific

7.2

| object

See System. Object in Partition IV

?

| string

See System.String in Partition IV

?

| Type ‘&’

Managed pointer to Type. Type shall not be a managed pointer type or typedref

14.4

| Type ‘*’

Unmanaged pointer to Type

14.4

| Type ‘<’ GenArgs ‘>’

Instantiation of generic type

9.4

| Type ‘[’ [ Bound [ ‘,’ Bound ]*] ‘]’

Array of Type with optional rank (number of dimensions) and bounds.

14.1and 14.2

| Type modopt ‘(’ TypeReference ‘)’

Custom modifier that can be ignored by the caller.

7.1.1

| Type modreq ‘(’ TypeReference ‘)’

Custom modifier that the caller shall understand.

7.1.1

| Type pinned

For local variables only. The garbage collector shall not move the referenced value.

7.1.2

| typedref

Typed reference (i.e., a value of type System.TypedReference), created by mkrefany and used by refanytype or refanyval.

7.2

| valuetype TypeReference

(Unboxed) user defined value type

13

| unsigned int8

Unsigned 8-bit integer

7.2

| ?unsigned intl6

Unsigned l6-bit integer

7.2

| ?unsigned int32

Unsigned 32-bit integer

7.2?

| ?unsigned int64

Unsigned 64-bit integer

7.2?

| ?void

No type. Only allowed as a return type or as part of void *

7.2

?

7.4 本地數(shù)據(jù)類型

CLI的一些實現(xiàn)將運行于現(xiàn)有的操作系統(tǒng)或運行時平臺上,這些平臺指定的數(shù)據(jù)類型要執(zhí)行某些特定的功能。元數(shù)據(jù)允許通過指定CLI的內(nèi)建和用戶定義類型如何被轉(zhuǎn)換成本地數(shù)據(jù)或者從本地數(shù)據(jù)轉(zhuǎn)換過來的方式,與這些本地數(shù)據(jù)類型進(jìn)行交互。這些轉(zhuǎn)換信息能被(使用關(guān)鍵詞marshal)用于:

  • 方法的返回類型,規(guī)定了一個本地數(shù)據(jù)類型實際被返回的和應(yīng)該被轉(zhuǎn)換回指定的CLI數(shù)據(jù)類型。
  • 方法的參數(shù),規(guī)定了被調(diào)用者提供的CLI數(shù)據(jù)類型應(yīng)該被轉(zhuǎn)換成指定的本地數(shù)據(jù)類型。(如果參數(shù)通過引用傳遞,更新的值應(yīng)該在調(diào)用結(jié)束后,從本地數(shù)據(jù)類型被轉(zhuǎn)換回CLI類型。)
  • 用戶定義類型字段,規(guī)定了任何企圖傳遞包含該字段的對象的時候,平臺方法都應(yīng)該作一份這個對象的拷貝,用指定的本地數(shù)據(jù)類型替換這些字段。(如果對象通過引用被傳遞,更新的值應(yīng)該在調(diào)用結(jié)束后被轉(zhuǎn)換回來。)

下面的表中列出了CLI支持的所有本地類型,并提供了每個類型的描述。(更多完整的描述請看第四部分中enum的定義System.Runtime.Interopservices.UnmanagedType,它提供了用于編碼這些類型的實際值。)所有0-63的編碼值被保留用于向后兼容所有已經(jīng)存在的CLI的執(zhí)行。64-127的值被留作將來用于這個和相關(guān)標(biāo)準(zhǔn)上。

NativeType ::=

Description

Name in the class

library enum type

UnmanagedType

‘[’ ‘]’

Native array. Type and size are determined at runtime from the actual marshaled array.

LPArray

|bool

Boolean. 4-byte integer value where any non- zero value represents TRUE, and 0 represents FALSE.

Bool

| float32

32-bit floating-point number.

R4

| float64

64-bit floating-point number.

R8

| [unsigned] int

Signed or unsigned integer, sized to hold a pointer on the platform

SysUInt or SysInt

| [unsigned] int8

Signed or unsigned 8-bit integer

U1 or I1

| [unsigned] int16

Signed or unsigned 16-bit integer

U2 or I2

| [unsigned] int32

Signed or unsigned 32-bit integer

U4 or I4

| [unsigned] int64

Signed or unsigned 64-bit integer

U8 or I8

|lpstr

A pointer to a null-terminated array of ANSI characters. The code page is implementation- specific.

LPStr

|lpwstr

A pointer to a null-terminated array of Unicode characters. The character encoding is implementation-specific.

LPWStr

| method

A function pointer.

FunctionPtr

| NativeType ‘[’ ‘]’

Array of NativeType. The length is determined at runtime by the size of the actual marshaled array.

LPArray

| NativeType ‘[’ Int32 ‘]’

Array of Native Type of length lnt32.

LPArray

| NativeType

‘[’ ‘+’ Int32 ‘]’

Array of NativeType with runtime supplied element size. The int32 specifies a parameter to the current method (counting from parameter number 0) that, at runtime, will contain the size of an element of the array in bytes. Can only be applied to methods, not fields.

LPArray

| NativeType

‘[’ Int32 ‘+’ Int32 ‘]’

Array of NativeType with runtime supplied element size. The first int32 specifies the number of elements in the array. The second 1nt32 specifies which parameter to the current method (counting from parameter number 0) will specify the additional number of elements in the array. Can only be applied to methods, not fields

LPArray

?

[例子:

.method int32 M1( int32 marshal(int32), bool[] marshal(bool[5]) )

方法 M1 帶了兩個參數(shù): 一個int32和一個帶有5 bool的數(shù)組.

.method int32 M2( int32 marshal(int32), bool[] marshal(bool[+1]) )

方法M2帶了兩個參數(shù): 一個 int32和一個 bool型數(shù)組: 數(shù)組元素的個數(shù)由第一個參數(shù)的值給定。

.method int32 M3( int32 marshal(int32), bool[] marshal(bool[7+1]) )

方法M3帶了兩個參數(shù): 一個int32和一個 bool型數(shù)組: 數(shù)組元素的個數(shù)由第一個參數(shù)的值加上7給定.]

?

接下篇:ECMA-335 (CLI) 標(biāo)準(zhǔn) 讀書筆記——總結(jié)CLI類型系統(tǒng)(下)

轉(zhuǎn)載于:https://www.cnblogs.com/cubean/archive/2010/04/07/1706657.html

總結(jié)

以上是生活随笔為你收集整理的ECMA-335 (CLI) 标准 读书笔记——总结CLI类型系统(上)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。