Exemplo n.º 1
0
	Atom VectorClass::applyTypeArgs(int argc, Atom* argv)
	{
		//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 type = argv[0];
		AvmCore* core = this->core();

		if (ISNULL(type))
			return toplevel()->objectVectorClass->atom();

		if (atomKind(type) != kObjectType)
			toplevel()->throwVerifyError(kCorruptABCError);

		ScriptObject* so = AvmCore::atomToScriptObject(type);

		if (so == toplevel()->intClass)
			return toplevel()->intVectorClass->atom();
		else if (so == toplevel()->numberClass)
			return toplevel()->doubleVectorClass->atom();
		else if (so == toplevel()->uintClass)
			return toplevel()->uintVectorClass->atom();

		Traits* param_traits = so->vtable->ivtable->traits;
		Stringp fullname = VectorClass::makeVectorClassName(core, param_traits);

		if (!instantiated_types->contains(fullname->atom()))
		{
			VTable* vtab = this->vtable->newParameterizedVTable(param_traits, fullname);

			ObjectVectorClass* new_type = new (vtab->gc(), vtab->getExtraSize()) ObjectVectorClass(vtab);
			new_type->index_type = (ClassClosure*)AvmCore::atomToScriptObject(type);
			new_type->setDelegate(toplevel()->classClass->prototype);

			// Is this right?  Should each instantiation get its own prototype?
			new_type->prototype = toplevel()->objectVectorClass->prototype;
			instantiated_types->add(fullname->atom(), new_type->atom());
		}
		return (Atom)instantiated_types->get(fullname->atom());
	}
Exemplo n.º 2
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();
    }