泛型(Vector)如何在AVM内部工作? [英] How do generics (Vector) work inside the AVM?

查看:237
本文介绍了泛型(Vector)如何在AVM内部工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

支持泛型(目前只有 Vector。< *> ,并被Adobe称为后缀类型参数)被添加到Flash Player 10中,但唯一的

具体来说,我注意到一个新的操作码(0x53)和一个新的多重类型(0x1D)这似乎是相关的,但他们的用法没有记录。

注意:这个问题的答案已经知道,因为它更容易在这里找到比我的博客或Adobe Bug DB。

泛型类型,尽管很有可能。



对声明(无参数)泛型(Vector)的引用是通过一个常量(Vector,< int>,而不是Vector。<>)的引用是由一个类型化的泛型类型引用的一个新的多类型(0x1D),我称之为GenericName。 GenericName的格式如下:

  [Kind] [TypeDefinition] [ParamCount] [Param1] [Param2] [ParamN] 






$ ul
  • [TypeDefinition]是U30中的一个多元表

  • [ParamCount]是多少个类型参数的U8(U30?)
  • [ParamX]是一个U30的多表。



  • 显然泛型一般不支持,所以ParamCount将始终为1对于Vector。< *>)。



    另一个有趣的事情是如何创建类的实例。在Flash 10(0x53)中添加了一个新的操作码,我将其称为MakeGenericType。 MakeGenericType用下面的堆栈声明:
    $ b $ pre $ TypeDefinition,ParameterType1,ParameterTypeN - > GenericType

    它也有一个参数,U8(U30?)指定堆栈中有多少个参数。您一般会看到MakeGenericType是这样使用的:

      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

    现在您将拥有一个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:

    [Kind] [TypeDefinition] [ParamCount] [Param1] [Param2] [ParamN]
    

    Where:

    • [TypeDefinition] is a U30 into the multiname table
    • [ParamCount] is a U8 (U30?) of how many type parameters there are
    • [ParamX] is a U30 into the multiname table.

    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:

    TypeDefinition, ParameterType1, ParameterTypeN -> GenericType
    

    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:

    GetLex [TypeDefinitionMultiname]
    GetLex [ParameterTypeMultiname]
    MakeGeneric [ParamCount]
    Coerce [GenericNameMultiname]
    Construct [ConstructorParamCount]
    

    So if you had the following...

    GetLex __AS3__.vec::Vector
    GetLex int
    MakeGeneric 1
    Coerce __AS3__.vec::Vector.<int>
    Construct 0
    

    You would now have an instance of Vector.<int>

    这篇关于泛型(Vector)如何在AVM内部工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆