Storing Type Information

Tamarin stores the type information for a variable in the Traits object. The Traits information is stored within the actual ABC file. You can find the definition in the AVM2 manual. However, in the actual implementation, the type information is stored in two different fields in a Trait instance. The actual traits.builtinType field is used by the verifier. The traits.builtinType field isn't really interesting and isn't used that often by the verifier. Another structure, the SlotInfo, is used during the LIR and assembly stages.

Traits.h
struct SlotInfo
{
// lower 3 bits is type information
// upper 29 bits is the offset / 4.
// eg for (24)ebp, upper 29 bits should be 6
uint32_t offsetAndSST;

inline SlotStorageType sst() const {
return SlotStorageType(offsetAndSST & 7);
}

inline uint32_t offset() const {
return (offsetAndSST >> 3) << 2;
}
};

enum SlotStorageType
{
SST_atom,
SST_string,
SST_namespace,
SST_scriptobject,

SST_int32,
SST_uint32,
SST_bool32,
SST_double
};


The SlotInfo.offsetAndSST contains all the type information for a local variable at the LIR/x86 stages. The lower 3 bits contains type information while the upper 29 bits tells us the offset from the machine stack. This information is valuable as the type information tells the assembler how much space to allocate on the stack for the variable. For example, an integer only needs 4 bytes while a double needs 8 as they are long doubles. The actual offset from the stack is stored in the offset() method.