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
mxArray *mxDuplicateArray(const mxArray *ptr)
{
    InternalType *pIT = (InternalType *)ptr;
    if (pIT == NULL)
    {
        return 0;
    }

    return (mxArray *)pIT->clone();
}
Exemple #3
0
double mxGetEps(void)
{
    InternalType *pITEps = symbol::Context::getInstance()->get(symbol::Symbol(L"%eps"));
    if (pITEps && pITEps->isDouble())
    {
        return pITEps->getAs<Double>()->get(0);
    }

    return -1;
}
Exemple #4
0
double mxGetInf(void)
{
    InternalType *pITInf = symbol::Context::getInstance()->get(symbol::Symbol(L"%inf"));
    if (pITInf && pITInf->isDouble())
    {
        return pITInf->getAs<Double>()->get(0);
    }

    return -1;
}
Exemple #5
0
std::wstring Inspector::showUnreferencedItem(size_t _iPos)
{
    std::wstring st;
    InternalType* pIT = getUnreferencedItem(_iPos);
    if (pIT == NULL)
    {
        st = L"NULL";
    }
    else
    {
        st = pIT->getTypeStr();
    }
    return st;
}
Exemple #6
0
List* Cell::extractCell(typed_list* _pArgs)
{
    InternalType* pIT = extract(_pArgs);
    if (pIT == NULL || pIT->isCell() == false)
    {
        return NULL;
    }

    List* pList = new List();

    Cell* pCell = pIT->getAs<Cell>();
    for (int i = 0 ; i < pCell->getSize() ; i++)
    {
        pList->append(pCell->get(i));
    }
    pCell->killMe();
    return pList;
}
Exemple #7
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 #8
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 #9
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 #10
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 #11
0
/*--------------------------------------------------------------------------*/
Function::ReturnValue sci_load(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    if (in.size() < 1)
    {
        Scierror(999, _("%s: Wrong number of input argument(s): at least %d expected.\n"), fname.data(), 1);
        return types::Function::Error;
    }

    InternalType* pIT = in[0];
    if (pIT->getId() != InternalType::IdScalarString)
    {
        Scierror(999, _("%s: Wrong type for input argument #%d: A string expected.\n"), fname.data(), 1);
        return Function::Error;
    }

    String *pS = pIT->getAs<types::String>();
    wchar_t* pwstPathLib = expandPathVariableW(pS->get(0));
    char* pstPath = wide_string_to_UTF8(pwstPathLib);
    if (FileExist(pstPath))
    {
        if (isHDF5File(pstPath))
        {
            FREE(pstPath);
            FREE(pwstPathLib);

            //call overload
            std::wstring wstFuncName = L"%_sodload";
            ast::ExecVisitor exec;
            Callable::ReturnValue Ret = Callable::Error;
            Ret = Overload::call(wstFuncName, in, _iRetCount, out, &exec);
            return Ret;
        }
        else
        {
            int err = 0;
            Library* lib = loadlib(pS->get(0), &err);
            FREE(pstPath);

            switch (err)
            {
                case 0:
                    //no error
                    break;
                case 1:
                {
                    char* pstPath = wide_string_to_UTF8(pS->get(0));
                    Scierror(999, _("%s: %s is not a valid module file.\n"), fname.data(), pstPath);
                    FREE(pstPath);
                    return Function::Error;
                }
                case 2:
                {
                    Scierror(999, "%s: %s", fname.data(), _("Redefining permanent variable.\n"));
                    return Function::Error;
                }
                default:
                {
                    //nothing
                }
            }

            FREE(pwstPathLib);
            lib->killMe();
        }
    }
    else
    {
        Scierror(999, _("%s: Unable to open file: \"%ls\".\n"), fname.data(), pwstPathLib);
        FREE(pstPath);
        FREE(pwstPathLib);
        return Function::Error;
    }

    return Function::OK;
}
Exemple #12
0
/**
** toString to display Structs
** FIXME : Find a better indentation process
*/
bool Cell::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_iDims*/)
{
    int iPrecision = ConfigVariable::getFormatSize();

    if (isEmpty())
    {
        ostr << L"   {}";
    }
    else
    {
        //max len for each column
        int *piTypeLen = new int[getCols()];
        int *piSizeLen = new int[getCols()];

        memset(piTypeLen, 0x00, getCols() * sizeof(int));
        memset(piSizeLen, 0x00, getCols() * sizeof(int));

        for (int j = 0 ; j < getCols() ; j++)
        {
            for (int i = 0 ; i < getRows() ; i++)
            {
                _piDims[0] = i;
                _piDims[1] = j;

                int iPos = getIndex(_piDims);
                InternalType* pIT = get(iPos);

                if (pIT->isAssignable())
                {
                    //compute number of digits to write dimensions
                    int iTypeLen = 0;
                    if (pIT->isGenericType())
                    {
                        GenericType* pGT = pIT->getAs<GenericType>();
                        for (int k = 0 ; k < pGT->getDims() ; k++)
                        {
                            iTypeLen += static_cast<int>(log10(static_cast<double>(pGT->getDimsArray()[k])) + 1);
                        }
                        piSizeLen[j] = std::max(piSizeLen[j], iTypeLen + (pGT->getDims() - 1));//add number of "x"
                    }
                    else
                    {
                        //types non derived from ArrayOf.
                        int iSize = static_cast<int>(log10(static_cast<double>(pIT->getAs<GenericType>()->getRows())) + 1);
                        piSizeLen[j] = std::max(piSizeLen[j], iSize);
                    }
                }
                else
                {
                    //no size so let a white space, size == 1
                    piSizeLen[j] = std::max(piSizeLen[j], 1);
                }

                piTypeLen[j] = std::max(piTypeLen[j], static_cast<int>(pIT->getTypeStr().size()));
            }
        }

        for (int i = 0 ; i < getRows() ; i++)
        {
            for (int j = 0 ; j < getCols() ; j++)
            {
                _piDims[0] = i;
                _piDims[1] = j;
                int iPos = getIndex(_piDims);
                InternalType* pIT = get(iPos);

                ostr << L"  [";
                if (pIT->isAssignable())
                {
                    if (pIT->isGenericType())
                    {
                        //"  ixjxkxl type   "
                        GenericType* pGT = pIT->getAs<GenericType>();
                        std::wostringstream ostemp;
                        for (int k = 0 ; k < pGT->getDims() ; k++)
                        {
                            if (k != 0)
                            {
                                ostemp << L"x";
                            }
                            ostemp << pGT->getDimsArray()[k];
                        }
                        configureStream(&ostr, piSizeLen[j], iPrecision, ' ');
                        ostr << std::right << ostemp.str();
                    }
                    else
                    {
                        //" i   "
                        configureStream(&ostr, piSizeLen[j], iPrecision, ' ');
                        if (pIT->isList())
                        {
                            ostr << std::right << pIT->getAs<List>()->getSize();
                        }
                        else
                        {
                            ostr << std::right << 1;
                        }
                    }
                }
                else
                {
                    configureStream(&ostr, piSizeLen[j], iPrecision, ' ');
                    ostr << L"";//fill with space
                }
                ostr << L" ";
                configureStream(&ostr, piTypeLen[j], iPrecision, ' ');
                ostr << std::left << pIT->getTypeStr();
                ostr << L"]";
            }
            ostr << std::endl;
        }

        delete[] piSizeLen;
        delete[] piTypeLen;
    }
    ostr << std::endl;
    return true;
}
Exemple #13
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 #14
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;
    }
}