Richard Szalay

Tuesday, February 17, 2009

ASMock Beta 2 Released with Tutorial Series

ASMock beta 2 has been released and, other than Flash 10 Vector support, is largely a bugfix release. I've also added a seven part tutorial series on how to use the framework.

As always, any feedback can be added to the bug database or feature request trackers. Additionally, any feedback to the tutorial series (or requested examples) can be added to the SourceForge forum for the project.

The ASMock binary, source and FlexUnit samples can all be downloaded from the downloads page.

Labels: , ,

Wednesday, February 11, 2009

Generics (Vector) in the AVM2

So I finally got around to looking at vector's in the AVM2 yesterday (for asmock) after someone logged a bug and found that the Flash 10 features are not actually documented in the AVM2 Overview document. Fortunately, after some digging around, I uncovered enough to implement support. Here's what I found:

References to a typed generic type (Vector.<int> as opposed to Vector.<*>) are referenced 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 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>

Labels: , ,