Exemple #1
0
mwSize *mxGetDimensions(const mxArray *ptr)
{
    InternalType *pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        return NULL;
    }

    switch (pIT->getType())
    {
        case InternalType::ScilabList:
        case InternalType::ScilabMList:
        case InternalType::ScilabTList:
        {
            int *piDims = (int *)MALLOC(sizeof(int));

            piDims[0] = pIT->getAs<Container>()->getSize();
            return piDims;
        }
        default:
        {
            GenericType *pGT = pIT->getAs<GenericType>();
            if (pGT == NULL)
            {
                return NULL;
            }
            return pGT->getDimsArray();
        }
    }
    return NULL;
}
Exemple #2
0
mxClassID mxGetClassID(const mxArray *ptr)
{
    InternalType *pIT = dynamic_cast<InternalType*>((InternalType*)ptr);
    if (pIT == NULL)
    {
        return mxUNKNOWN_CLASS;
    }

    switch (pIT->getType())
    {
        case InternalType::ScilabInt8:
            return mxINT8_CLASS;
        case InternalType::ScilabUInt8:
            return mxUINT8_CLASS;
        case InternalType::ScilabInt16:
            return mxINT16_CLASS;
        case InternalType::ScilabUInt16:
            return mxUINT16_CLASS;
        case InternalType::ScilabInt32:
            return mxINT32_CLASS;
        case InternalType::ScilabUInt32:
            return mxUINT32_CLASS;
        case InternalType::ScilabInt64:
            return mxINT64_CLASS;
        case InternalType::ScilabUInt64:
            return mxUINT64_CLASS;
        case InternalType::ScilabString:
            return mxCHAR_CLASS;
        case InternalType::ScilabDouble:
            return mxDOUBLE_CLASS;
        case InternalType::ScilabBool:
            return mxLOGICAL_CLASS;
        case InternalType::ScilabFloat:
            return mxSINGLE_CLASS;
        case InternalType::ScilabStruct:
            return mxSTRUCT_CLASS;
        case InternalType::ScilabCell:
            return mxCELL_CLASS;
        case InternalType::ScilabFunction:
            return mxFUNCTION_CLASS;
        default:
            return mxUNKNOWN_CLASS;
    }
}
Exemple #3
0
int mxIsEmpty(const mxArray *ptr)
{
    InternalType * pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        //true or false, whatever ;)
        return 1;
    }

    switch (pIT->getType())
    {
        case InternalType::ScilabDouble:
        {
            Double *pD = pIT->getAs<Double>();
            return pD->getSize() == 0;
        }
        case InternalType::ScilabCell:
        {
            Cell *pC = pIT->getAs<Cell>();
            return pC->getSize() == 0;
        }
        case InternalType::ScilabContainer:
        case InternalType::ScilabList:
        case InternalType::ScilabMList:
        case InternalType::ScilabTList:
        {
            Container *pC = pIT->getAs<Container>();
            return pC->getSize() == 0;
        }
        default:
        {
            //other type can not be empty
            return 0;
        }
    }
}
Exemple #4
0
void RunVisitorT<T>::visitprivate(const LogicalOpExp &e)
{
    try
    {
        InternalType *pITR = NULL; //assign only in non shortcut operations.

        /*getting what to assign*/
        e.getLeft().accept(*this);
        InternalType *pITL = getResult();
        if (isSingleResult() == false)
        {
            std::wostringstream os;
            os << _W("Incompatible output argument.\n");
            //os << ((Location)e.right_get().getLocation()).getLocationString() << std::endl;
            throw ast::InternalError(os.str(), 999, e.getRight().getLocation());
        }

        setResult(NULL);

        if (pITL->getType() == GenericType::ScilabImplicitList)
        {
            ImplicitList* pIL = pITL->getAs<ImplicitList>();
            if (pIL->isComputable())
            {
                pITL = pIL->extractFullMatrix();
                pIL->killMe();
            }
        }

        InternalType *pResult   = NULL;

        switch (e.getOper())
        {
            case LogicalOpExp::logicalShortCutAnd :
            {
                pResult = GenericShortcutAnd(pITL);
                if (pResult)
                {
                    break;
                }

                //Continue to logicalAnd
            }
            case LogicalOpExp::logicalAnd :
            {
                /*getting what to assign*/
                e.getRight().accept(*this);
                pITR = getResult();
                if (isSingleResult() == false)
                {
                    std::wostringstream os;
                    os << _W("Incompatible output argument.\n");
                    //os << ((Location)e.right_get().getLocation()).getLocationString() << std::endl;
                    throw ast::InternalError(os.str(), 999, e.getRight().getLocation());
                }

                if (pITR->getType() == GenericType::ScilabImplicitList)
                {
                    ImplicitList* pIR = pITR->getAs<ImplicitList>();
                    if (pIR->isComputable())
                    {
                        pITR = pIR->extractFullMatrix();
                        pIR->killMe();
                    }
                }
                pResult = GenericLogicalAnd(pITL, pITR);
                break;
            }
            case LogicalOpExp::logicalShortCutOr :
            {
                pResult = GenericShortcutOr(pITL);
                if (pResult)
                {
                    break;
                }

                //Continue to logicalAnd
            }
            case LogicalOpExp::logicalOr :
            {
                /*getting what to assign*/
                e.getRight().accept(*this);
                pITR = getResult();
                if (isSingleResult() == false)
                {
                    std::wostringstream os;
                    os << _W("Incompatible output argument.\n");
                    //os << ((Location)e.right_get().getLocation()).getLocationString() << std::endl;
                    throw ast::InternalError(os.str(), 999, e.getRight().getLocation());
                }

                if (pITR->getType() == GenericType::ScilabImplicitList)
                {
                    ImplicitList* pIR = pITR->getAs<ImplicitList>();
                    if (pIR->isComputable())
                    {
                        pITR = pIR->extractFullMatrix();
                    }
                }
                pResult = GenericLogicalOr(pITL, pITR);
                break;
            }

            default :
                break;
        }
        //overloading
        if (pResult == NULL)
        {
            // We did not have any algorithm matching, so we try to call OverLoad
            pResult = callOverloadOpExp(e.getOper(), pITL, pITR);
        }

        setResult(pResult);

        // protect pResult in case where pITL or pITR equal pResult
        pResult->IncreaseRef();

        //clear left and/or right operands
        pITL->killMe();
        if (pITR)
        {
            pITR->killMe();
        }

        // unprotect pResult
        pResult->DecreaseRef();
    }
    catch (ast::InternalError& error)
    {
        clearResult();
        error.SetErrorLocation(e.getLocation());
        throw error;
    }

}
Exemple #5
0
void RunVisitorT<T>::visitprivate(const OpExp &e)
{
    InternalType * pITL = NULL, * pITR = NULL, * pResult = NULL;
    try
    {
        /*getting what to assign*/
        e.getLeft().accept(*this);
        if (isSingleResult() == false)
        {
            clearResult();
            std::wostringstream os;
            os << _W("Incompatible output argument.\n");
            //os << ((Location)e.right_get().getLocation()).getLocationString() << std::endl;
            throw ast::InternalError(os.str(), 999, e.getRight().getLocation());
        }
        pITL = getResult();

        /*getting what to assign*/
        e.getRight().accept(*this);
        if (isSingleResult() == false)
        {
            clearResult();
            std::wostringstream os;
            os << _W("Incompatible output argument.\n");
            //os << ((Location)e.right_get().getLocation()).getLocationString() << std::endl;
            throw ast::InternalError(os.str(), 999, e.getRight().getLocation());
        }
        pITR = getResult();

        if (pITL->getType() == GenericType::ScilabImplicitList)
        {
            ImplicitList* pIL = pITL->getAs<ImplicitList>();
            if (pIL->isComputable())
            {
                pITL = pIL->extractFullMatrix();
                pIL->killMe();
            }
        }

        if (pITR->getType() == GenericType::ScilabImplicitList)
        {
            ImplicitList* pIR = pITR->getAs<ImplicitList>();
            if (pIR->isComputable())
            {
                pITR = pIR->extractFullMatrix();
                pIR->killMe();
            }
        }

        switch (e.getOper())
        {
            case OpExp::plus :
            {
                pResult = GenericPlus(pITL, pITR);
                break;
            }
            case OpExp::unaryMinus :
            {
                pResult = GenericUnaryMinus(pITR);
                break;
            }
            case OpExp::minus :
            {
                pResult = GenericMinus(pITL, pITR);
                break;
            }
            case OpExp::times:
            {
                pResult = GenericTimes(pITL, pITR);
                break;
            }
            case OpExp::ldivide:
            {
                pResult = GenericLDivide(pITL, pITR);
                break;
            }
            case OpExp::dotldivide :
            {
                pResult = GenericDotLDivide(pITL, pITR);
                break;
            }
            case OpExp::rdivide:
            {
                pResult = GenericRDivide(pITL, pITR);
                break;
            }
            case OpExp::dotrdivide :
            {
                pResult = GenericDotRDivide(pITL, pITR);
                break;
            }
            case OpExp::dottimes :
            {
                pResult = GenericDotTimes(pITL, pITR);
                break;
            }
            case OpExp::dotpower :
            {
                pResult = GenericDotPower(pITL, pITR);
                break;
            }
            case OpExp::eq :
            {
                pResult = GenericComparisonEqual(pITL, pITR);
                break;
            }
            case OpExp::ne :
            {
                pResult = GenericComparisonNonEqual(pITL, pITR);
                break;
            }
            case OpExp::lt :
            {
                pResult = GenericLess(pITL, pITR);
                break;
            }
            case OpExp::le :
            {
                pResult = GenericLessEqual(pITL, pITR);
                break;
            }
            case OpExp::gt :
            {
                pResult = GenericGreater(pITL, pITR);
                break;
            }
            case OpExp::ge :
            {
                pResult = GenericGreaterEqual(pITL, pITR);
                break;
            }
            case OpExp::power :
            {
                pResult = GenericPower(pITL, pITR);
                break;
            }
            case OpExp::krontimes :
            {
                pResult = GenericKrontimes(pITL, pITR);
                break;
            }
            case OpExp::kronrdivide :
            {
                pResult = GenericKronrdivide(pITL, pITR);
                break;
            }
            case OpExp::kronldivide :
            {
                pResult = GenericKronldivide(pITL, pITR);
                break;
            }
            default :
                break;
        }

        //overloading
        if (pResult == NULL)
        {
            // We did not have any algorithm matching, so we try to call OverLoad
            pResult = callOverloadOpExp(e.getOper(), pITL, pITR);
        }

        setResult(pResult);

        //clear left and/or right operands
        if (pResult != pITL)
        {
            pITL->killMe();
        }

        if (pResult != pITR)
        {
            pITR->killMe();
        }
    }
    catch (ast::InternalError& error)
    {
        setResult(NULL);
        if (pResult)
        {
            pResult->killMe();
        }
        if (pITL && (pITL != pResult))
        {
            pITL->killMe();
        }
        if (pITR && (pITR != pResult))
        {
            pITR->killMe();
        }

        error.SetErrorLocation(e.getLocation());
        throw error;
    }

    /*if (e.getDecorator().res.isConstant())
    {

    }*/
}
Exemple #6
0
double mxGetScalar(const mxArray *ptr)
{
    // TODO: review spec
    InternalType *pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        return 0;
    }

    switch (pIT->getType())
    {
        case InternalType::ScilabDouble:
        {
            Double *pD = pIT->getAs<Double>();
            return pD->get(0);
        }
        case InternalType::ScilabBool:
        {
            Bool *pB = pIT->getAs<Bool>();
            return (double)pB->get(0);
        }
        case InternalType::ScilabInt8:
        {
            Int8 *pI = pIT->getAs<Int8>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt8:
        {
            UInt8 *pI = pIT->getAs<UInt8>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabInt16:
        {
            Int16 *pI = pIT->getAs<Int16>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt16:
        {
            UInt16 *pI = pIT->getAs<UInt16>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabInt32:
        {
            Int32 *pI = pIT->getAs<Int32>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt32:
        {
            UInt32 *pI = pIT->getAs<UInt32>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabInt64:
        {
            Int64 *pI = pIT->getAs<Int64>();
            return (double)pI->get(0);
        }
        case InternalType::ScilabUInt64:
        {
            UInt64 *pI = pIT->getAs<UInt64>();
            return (double)pI->get(0);
        }
        default:
            return 0;
    }
}
Exemple #7
0
void *mxGetImagData(const mxArray *ptr)
{
    InternalType *pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        return NULL;
    }

    switch (pIT->getType())
    {
        case InternalType::ScilabDouble:
        {
            Double *pD = pIT->getAs<Double>();
            return pD->getImg();
        }
        case InternalType::ScilabBool:
        {
            Bool *pB = pIT->getAs<Bool>();
            return pB->getImg();
        }
        case InternalType::ScilabInt8:
        {
            Int8 *pI = pIT->getAs<Int8>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt8:
        {
            UInt8 *pI = pIT->getAs<UInt8>();
            return pI->getImg();
        }
        case InternalType::ScilabInt16:
        {
            Int16 *pI = pIT->getAs<Int16>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt16:
        {
            UInt16 *pI = pIT->getAs<UInt16>();
            return pI->getImg();
        }
        case InternalType::ScilabInt32:
        {
            Int32 *pI = pIT->getAs<Int32>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt32:
        {
            UInt32 *pI = pIT->getAs<UInt32>();
            return pI->getImg();
        }
        case InternalType::ScilabInt64:
        {
            Int64 *pI = pIT->getAs<Int64>();
            return pI->getImg();
        }
        case InternalType::ScilabUInt64:
        {
            UInt64 *pI = pIT->getAs<UInt64>();
            return pI->getImg();
        }
        default:
            return NULL;
    }
}