示例#1
0
    VectorBaseObject* ObjectVectorObject::newVector(uint32 length)
    {
        Atom args[1] = {t->atom()};

        ObjectVectorClass* vecclass = (ObjectVectorClass*)AvmCore::atomToScriptObject(toplevel()->vectorClass->applyTypeArgs(1, args));
        return vecclass->newVector(length);
    }
	ObjectVectorObject* VectorClass::newVector(ClassClosure* type, uint32 length)
	{
		Atom args[1] = {type->atom()};

		ObjectVectorClass* vecclass = (ObjectVectorClass*)AvmCore::atomToScriptObject(applyTypeArgs(1, args));
		return vecclass->newVector(length);
	}
示例#3
0
    Atom VectorClass::applyTypeArgs(int argc, Atom* argv)
    {
        Toplevel* toplevel = this->toplevel();

        //Vector only takes 1 type argument
        AvmAssert(argc==1);
        if (argc != 1)
        {
            toplevel->typeErrorClass()->throwError(kWrongTypeArgCountError, traits()->formatClassName(), core()->toErrorString(1), core()->toErrorString(argc));
        }

        Atom const typeAtom = argv[0];

        ClassClosure* parameterizedType;
        if (ISNULL(typeAtom))
        {
            parameterizedType = toplevel->objectVectorClass;
        }
        else
        {
            if (atomKind(typeAtom) != kObjectType)
                toplevel->throwVerifyError(kCorruptABCError);

            ScriptObject* typeObj = AvmCore::atomToScriptObject(typeAtom);
            if (typeObj == toplevel->intClass)
            {
                parameterizedType = toplevel->intVectorClass;
            }
            else if (typeObj == toplevel->uintClass)
            {
                parameterizedType = toplevel->uintVectorClass;
            }
            else if (typeObj == toplevel->numberClass)
            {
                parameterizedType = toplevel->doubleVectorClass;
            }
            else
            {
                // if we have an object, we must have an itraits (otherwise the typearg is not a Class)
                Traits* typeTraits = typeObj->vtable->traits->itraits;
                if (!typeTraits)
                    toplevel->throwVerifyError(kCorruptABCError);

                ClassClosure* typeClass = (ClassClosure*)typeObj;
                Domain* typeDomain = typeObj->traits()->pool->domain;
                if ((parameterizedType = typeDomain->getParameterizedType(typeClass)) == NULL)
                {
                    Stringp fullname = VectorClass::makeVectorClassName(core(), typeTraits);

                    VTable* vt = this->vtable->newParameterizedVTable(typeTraits, fullname);

                    ObjectVectorClass* parameterizedVector = new (vt->gc(), vt->getExtraSize()) ObjectVectorClass(vt);
                    parameterizedVector->index_type = typeClass;
                    parameterizedVector->setDelegate(toplevel->classClass->prototypePtr());

                    // Is this right?  Should each instantiation get its own prototype?
                    parameterizedVector->setPrototypePtr(toplevel->objectVectorClass->prototypePtr());
                    typeDomain->addParameterizedType(typeClass, parameterizedVector);

                    parameterizedType = parameterizedVector;
                }
            }
        }

        return parameterizedType->atom();
    }