泛型(Vector)如何在AVM内部工作? [英] How do generics (Vector) work inside the AVM?
问题描述
支持泛型(目前只有 Vector。< *> ,并被Adobe称为后缀类型参数)被添加到Flash Player 10中,但唯一的 具体来说,我注意到一个新的操作码(0x53)和一个新的多重类型(0x1D)这似乎是相关的,但他们的用法没有记录。 注意:这个问题的答案已经知道,因为它更容易在这里找到比我的博客或Adobe Bug DB。 泛型类型,尽管很有可能。 对声明(无参数)泛型(Vector)的引用是通过一个常量(Vector,< int>,而不是Vector。<>)的引用是由一个类型化的泛型类型引用的一个新的多类型(0x1D),我称之为GenericName。 GenericName的格式如下: 显然泛型一般不支持,所以ParamCount将始终为1对于Vector。< *>)。 另一个有趣的事情是如何创建类的实例。在Flash 10(0x53)中添加了一个新的操作码,我将其称为MakeGenericType。 MakeGenericType用下面的堆栈声明: 它也有一个参数,U8(U30?)指定堆栈中有多少个参数。您一般会看到MakeGenericType是这样使用的: 如果你有以下... 现在您将拥有一个Vector实例。< int> p> Support for generics (currently only Vector.<*>, and called 'postfix type parameters' by Adobe) was added in Flash Player 10, but the only AVM2 documentation does not describe how these objects are accessed. Specifically, I noticed a new opcode (0x53) and a new multiname kind (0x1D) that seem relevant, but their usage is not documented. NB: This question was created with the answer already known as it is more easily found here than on my blog or the Adobe Bug DB. The reverse engineering work I did on this did not include declaring your own generic types, though it's very likely possible. References to the declaring (parameterless) generic type (Vector) are made through a regular qualified name (though any multiname should do). References to a typed generic type (Vector.<int> as opposed to Vector.<>) are made by a new multiname kind (0x1D), which I call GenericName. GenericName has a format like so: Where: Obviously generics are not generally supported yet, so ParamCount will always be 1 (for Vector.<*>). The other interesting thing is how instances of the class are created. A new opcode was added in Flash 10 (0x53), which I will call MakeGenericType. MakeGenericType is declared with the following stack: It also has one parameter, a U8 (U30?) specifying how many parameters are on the stack. You will generally see MakeGenericType being used like this: So if you had the following... You would now have an instance of Vector.<int> 这篇关于泛型(Vector)如何在AVM内部工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
[Kind] [TypeDefinition] [ParamCount] [Param1] [Param2] [ParamN]
$ ul
$ b $ pre $ TypeDefinition,ParameterType1,ParameterTypeN - > GenericType
GetLex [TypeDefinitionMultiname]
GetLex [ParameterTypeMultiname]
MakeGeneric [ParamCount]
Coerce [GenericNameMultiname]
Construct [ConstructorParamCount]
$ pre $ code $ GetLex __AS3 __。vec :: Vector
GetLex int
MakeGeneric 1
Coerce __AS3 __。vec :: Vector。< int>
构造0
[Kind] [TypeDefinition] [ParamCount] [Param1] [Param2] [ParamN]
TypeDefinition, ParameterType1, ParameterTypeN -> GenericType
GetLex [TypeDefinitionMultiname]
GetLex [ParameterTypeMultiname]
MakeGeneric [ParamCount]
Coerce [GenericNameMultiname]
Construct [ConstructorParamCount]
GetLex __AS3__.vec::Vector
GetLex int
MakeGeneric 1
Coerce __AS3__.vec::Vector.<int>
Construct 0