* Bug 16191 fixed: now mode(0) and mode(1) are really compact.
[scilab.git] / scilab / modules / ast / src / cpp / ast / runvisitor.cpp
index 15d3580..dc7d63d 100644 (file)
@@ -2,11 +2,14 @@
  *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  *  Copyright (C) 2014 - Scilab Enterprises - Antoine ELIAS
  *
- *  This file must be used under the terms of the CeCILL.
- *  This source file is licensed as described in the file COPYING, which
- *  you should have received as part of this distribution.  The terms
- *  are also available at
- *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
  *
  */
 
 
 #include <string>
 
-#include "runvisitor.hxx"
 #include "execvisitor.hxx"
 #include "stepvisitor.hxx"
 #include "timedvisitor.hxx"
 #include "shortcutvisitor.hxx"
 #include "printvisitor.hxx"
-#include "mutevisitor.hxx"
 //#include "AnalysisVisitor.hxx"
+#include "debuggervisitor.hxx"
+#include "debugmanager.hxx"
 
 #include "visitor_common.hxx"
 
 
 #include "macrofile.hxx"
 #include "macro.hxx"
+#include "cell.hxx"
+#include "listinsert.hxx"
 #include "filemanager_interface.h"
 
 #include "runner.hxx"
 #include "threadmanagement.hxx"
 
+#include "coverage_instance.hxx"
+
 extern "C"
 {
 #include "sciprint.h"
 #include "os_string.h"
 #include "elem_common.h"
+#include "storeCommand.h"
+#include "prompt.h"
+#include "scilabRead.h"
 }
 
 namespace ast
 {
 template <class T>
-void RunVisitorT<T>::visitprivate(const CellExp &e)
+void RunVisitorT<T>::visitprivate(const StringExp & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    if (e.getConstant() == nullptr)
+    {
+        types::String *psz = new types::String(e.getValue().c_str());
+        (const_cast<StringExp *>(&e))->setConstant(psz);
+    }
+    setResult(e.getConstant());
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const DoubleExp & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    if (e.getConstant() == nullptr)
+    {
+        types::Double *pdbl = new types::Double(e.getValue());
+        (const_cast<DoubleExp *>(&e))->setConstant(pdbl);
+    }
+    setResult(e.getConstant());
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const BoolExp & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    if (e.getConstant() == nullptr)
+    {
+        types::Bool *pB = new types::Bool(e.getValue());
+        (const_cast<BoolExp *>(&e))->setConstant(pB);
+    }
+    setResult(e.getConstant());
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const NilExp & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    setResult(new types::Void());
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const SimpleVar & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    symbol::Context* ctx = symbol::Context::getInstance();
+    symbol::Variable* var = ((SimpleVar&)e).getStack();
+    types::InternalType *pI = ctx->get(var);
+    setResult(pI);
+    if (pI != nullptr)
+    {
+        if (e.isVerbose() && pI->isCallable() == false && ConfigVariable::isPrintOutput())
+        {
+            std::wostringstream ostr;
+            ostr << L" " << e.getSymbol().getName() << L"  = ";
+#ifndef NDEBUG
+            ostr << L"(" << pI->getRef() << L")";
+#endif
+            ostr << std::endl;
+            if (ConfigVariable::isPrintCompact() == false)
+            {
+                ostr << std::endl;                
+            }
+            scilabWriteW(ostr.str().c_str());
+            std::wostringstream ostrName;
+            ostrName << e.getSymbol().getName();
+            VariableToString(pI, ostrName.str().c_str());
+        }
+
+        //check if var is recalled in current scope like
+        //function f()
+        //  a; //<=> a=a;
+        //  a(2) = 18;
+        //endfunction
+        if (e.getParent()->isSeqExp())
+        {
+            if (ctx->getScopeLevel() > 1 && var->empty() == false && var->top()->m_iLevel != ctx->getScopeLevel())
+            {
+                //put var in current scope
+                ctx->put(var, pI);
+            }
+        }
+    }
+    else
+    {
+        char pstError[bsiz];
+        wchar_t* pwstError;
+
+        char* strErr = wide_string_to_UTF8(e.getSymbol().getName().c_str());
+
+        os_sprintf(pstError, _("Undefined variable: %s\n"), strErr);
+        pwstError = to_wide_string(pstError);
+        FREE(strErr);
+        std::wstring wstError(pwstError);
+        FREE(pwstError);
+        CoverageInstance::stopChrono((void*)&e);
+        throw InternalError(wstError, 999, e.getLocation());
+        //Err, SimpleVar doesn't exist in Scilab scopes.
+    }
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const ColonVar & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    types::Colon *pC = new types::Colon();
+    setResult(pC);
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const DollarVar & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    setResult(types::Polynom::Dollar());
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const BreakExp & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    const_cast<BreakExp*>(&e)->setBreak();
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const ContinueExp &e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    const_cast<ContinueExp*>(&e)->setContinue();
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const ArrayListExp & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    exps_t::const_iterator it;
+    int iNbExpSize = this->getExpectedSize();
+    this->setExpectedSize(1);
+
+    types::typed_list lstIT;
+    for (it = e.getExps().begin(); it != e.getExps().end(); it++)
+    {
+        (*it)->accept(*this);
+        for (int j = 0; j < getResultSize(); j++)
+        {
+            lstIT.push_back(getResult(j));
+        }
+    }
+
+    setResult(lstIT);
+
+    this->setExpectedSize(iNbExpSize);
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const VarDec & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    try
+    {
+        /*getting what to assign*/
+        e.getInit().accept(*this);
+        getResult()->IncreaseRef();
+    }
+    catch (const InternalError& error)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw error;
+    }
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+template <class T>
+void RunVisitorT<T>::visitprivate(const CellExp & e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+
     exps_t::const_iterator row;
     exps_t::const_iterator col;
     int iColMax = 0;
 
     exps_t lines = e.getLines();
     //check dimmension
-    for (row = lines.begin() ; row != lines.end() ; ++row )
+    for (row = lines.begin(); row != lines.end(); ++row)
     {
         exps_t cols = (*row)->getAs<MatrixLineExp>()->getColumns();
         if (iColMax == 0)
@@ -73,6 +268,7 @@ void RunVisitorT<T>::visitprivate(const CellExp &e)
             std::wostringstream os;
             os << _W("inconsistent row/column dimensions\n");
             //os << ((Location)(*row)->getLocation()).getLocationString() << std::endl;
+            CoverageInstance::stopChrono((void*)&e);
             throw InternalError(os.str(), 999, (*row)->getLocation());
         }
     }
@@ -84,16 +280,24 @@ void RunVisitorT<T>::visitprivate(const CellExp &e)
     int j = 0;
 
     //insert items in cell
-    for (i = 0, row = lines.begin() ; row != lines.end() ; ++row, ++i)
+    for (i = 0, row = lines.begin(); row != lines.end(); ++row, ++i)
     {
         exps_t cols = (*row)->getAs<MatrixLineExp>()->getColumns();
-        for (j = 0, col = cols.begin() ; col != cols.end() ; ++col, ++j)
+        for (j = 0, col = cols.begin(); col != cols.end(); ++col, ++j)
         {
-            (*col)->accept(*this);
-            InternalType *pIT = getResult();
+            try
+            {
+                (*col)->accept(*this);
+            }
+            catch (ScilabException &)
+            {
+                CoverageInstance::stopChrono((void*)&e);
+                throw;
+            }
+            types::InternalType *pIT = getResult();
             if (pIT->isImplicitList())
             {
-                InternalType * _pIT = pIT->getAs<ImplicitList>()->extractFullMatrix();
+                types::InternalType * _pIT = pIT->getAs<types::ImplicitList>()->extractFullMatrix();
                 pC->set(i, j, _pIT);
                 _pIT->killMe();
             }
@@ -107,6 +311,8 @@ void RunVisitorT<T>::visitprivate(const CellExp &e)
 
     //return new cell
     setResult(pC);
+
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
@@ -114,12 +320,15 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
 {
     /*
       a.b
-    */
+      */
+
+    CoverageInstance::invokeAndStartChrono((void*)&e);
 
     if (!e.getTail()->isSimpleVar())
     {
         wchar_t szError[bsiz];
         os_swprintf(szError, bsiz, _W("/!\\ Unmanaged FieldExp.\n").c_str());
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
 
@@ -129,6 +338,7 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
     }
     catch (const InternalError& error)
     {
+        CoverageInstance::stopChrono((void*)&e);
         throw error;
     }
 
@@ -136,6 +346,7 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
     {
         wchar_t szError[bsiz];
         os_swprintf(szError, bsiz, _W("Attempt to reference field of non-structure array.\n").c_str());
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
 
@@ -147,25 +358,26 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
         clearResult();
         wchar_t szError[bsiz];
         os_swprintf(szError, bsiz, _W("Not yet implemented in Scilab.\n").c_str());
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
 
     SimpleVar * psvRightMember = static_cast<SimpleVar *>(const_cast<Exp *>(e.getTail()));
     std::wstring wstField = psvRightMember->getSymbol().getName();
-    InternalType * pValue = getResult();
-    InternalType * pReturn = NULL;
+    types::InternalType * pValue = getResult();
+    types::InternalType * pReturn = NULL;
     bool ok = false;
 
     try
     {
         if (pValue->isGenericType() || pValue->isUserType())
         {
-            ok = pValue->getAs<GenericType>()->extract(wstField, pReturn);
+            ok = pValue->getAs<types::GenericType>()->extract(wstField, pReturn);
         }
     }
     catch (std::wstring & err)
     {
-        pValue->killMe();
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(err.c_str(), 999, e.getTail()->getLocation());
     }
 
@@ -175,6 +387,7 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
         {
             std::wostringstream os;
             os << _W("Invalid index.\n");
+            CoverageInstance::stopChrono((void*)&e);
             throw InternalError(os.str(), 999, e.getLocation());
         }
 
@@ -200,7 +413,7 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
         types::typed_list in;
         types::typed_list out;
 
-        String* pS = new String(wstField.c_str());
+        types::String* pS = new types::String(wstField.c_str());
 
         //TODO: in the case where overload is a macro there is no need to incref in
         // because args will be put in context, removed and killed if required.
@@ -211,12 +424,12 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
 
         in.push_back(pS);
         in.push_back(pValue);
-        Callable::ReturnValue Ret = Callable::Error;
+        types::Callable::ReturnValue Ret = types::Callable::Error;
         std::wstring stType = pValue->getShortTypeStr();
 
         try
         {
-            Ret = Overload::call(L"%" + stType + L"_e", in, 1, out, this);
+            Ret = Overload::call(L"%" + stType + L"_e", in, 1, out, true);
         }
         catch (const InternalError& ie)
         {
@@ -226,10 +439,11 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
                 //tlist/mlist name are truncated to 8 first character
                 if (stType.size() > 8)
                 {
-                    Ret = Overload::call(L"%" + stType.substr(0, 8) + L"_e", in, 1, out, this);
+                    Ret = Overload::call(L"%" + stType.substr(0, 8) + L"_e", in, 1, out, true);
                 }
                 else
                 {
+                    CoverageInstance::stopChrono((void*)&e);
                     throw ie;
                 }
             }
@@ -238,19 +452,21 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
                 // TList or Mlist
                 if (pValue->isList())
                 {
-                    Ret = Overload::call(L"%l_e", in, 1, out, this);
+                    Ret = Overload::call(L"%l_e", in, 1, out, true);
                 }
                 else
                 {
+                    CoverageInstance::stopChrono((void*)&e);
                     throw ie;
                 }
             }
         }
 
-        if (Ret != Callable::OK)
+        if (Ret != types::Callable::OK)
         {
             cleanInOut(in, out);
             setResult(NULL);
+            CoverageInstance::stopChrono((void*)&e);
             throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
         }
 
@@ -262,78 +478,126 @@ void RunVisitorT<T>::visitprivate(const FieldExp &e)
         pValue->killMe();
         wchar_t szError[bsiz];
         os_swprintf(szError, bsiz, _W("Attempt to reference field of non-structure array.\n").c_str());
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
+
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const IfExp  &e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+
     //Create local exec visitor
     ShortCutVisitor SCTest;
     bool bTestStatus = false;
 
     //condition
-    e.getTest().accept(SCTest);
-    e.getTest().accept(*this);
+    try
+    {
+        e.getTest().accept(SCTest);
+        e.getTest().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
 
     bTestStatus = getResult()->isTrue();
     clearResult();
-    if (bTestStatus == true)
+    try
     {
-        e.getThen().accept(*this);
+        if (bTestStatus == true)
+        {
+            e.getThen().accept(*this);
+        }
+        else if (e.hasElse())
+        {
+            e.getElse().accept(*this);
+        }
     }
-    else if (e.hasElse())
+    catch (ScilabException &)
     {
-        e.getElse().accept(*this);
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
     }
 
-    if (e.isBreakable()
-            && ( (&e.getElse())->isBreak()
-                 || (&e.getThen())->isBreak() ))
+    bool elseIsBreak = e.hasElse() && (&e.getElse())->isBreak();
+    if (e.isBreakable() && (elseIsBreak || (&e.getThen())->isBreak()))
     {
         const_cast<IfExp*>(&e)->setBreak();
-        const_cast<Exp*>(&e.getElse())->resetBreak();
         const_cast<Exp*>(&e.getThen())->resetBreak();
+        if (e.hasElse())
+        {
+            const_cast<Exp*>(&e.getElse())->resetBreak();
+        }
     }
 
-    if (e.isContinuable()
-            && ( (&e.getElse())->isContinue()
-                 || (&e.getThen())->isContinue() ))
+    bool elseIsContinue = e.hasElse() && (&e.getElse())->isContinue();
+    if (e.isContinuable() && (elseIsContinue || (&e.getThen())->isContinue()))
     {
         const_cast<IfExp*>(&e)->setContinue();
-        const_cast<Exp*>(&e.getElse())->resetContinue();
         const_cast<Exp*>(&e.getThen())->resetContinue();
+        if (e.hasElse())
+        {
+            const_cast<Exp*>(&e.getElse())->resetContinue();
+        }
     }
 
-    if (e.isReturnable()
-            && ( (&e.getElse())->isReturn()
-                 || (&e.getThen())->isReturn() ))
+    bool elseIsReturn = e.hasElse() && (&e.getElse())->isReturn();
+    if (e.isReturnable() && (elseIsReturn || (&e.getThen())->isReturn()))
     {
         const_cast<IfExp*>(&e)->setReturn();
-        const_cast<Exp*>(&e.getElse())->resetReturn();
         const_cast<Exp*>(&e.getThen())->resetReturn();
+        if (e.hasElse())
+        {
+            const_cast<Exp*>(&e.getElse())->resetReturn();
+        }
     }
+
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const WhileExp  &e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
 
     //Create local exec visitor
     ShortCutVisitor SCTest;
 
-    //manage & and | like && and ||
-    e.getTest().accept(SCTest);
-    //condition
-    e.getTest().accept(*this);
+    try
+    {
+        //manage & and | like && and ||
+        e.getTest().accept(SCTest);
+        //condition
+        e.getTest().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
 
-    InternalType* pIT = getResult();
+    types::InternalType* pIT = getResult();
 
     while (pIT->isTrue())
     {
         pIT->killMe();
-        e.getBody().accept(*this);
+        setResult(NULL);
+
+        try
+        {
+            e.getBody().accept(*this);
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
 
         //clear old result value before evaluate new one
         if (getResult() != NULL)
@@ -359,29 +623,47 @@ void RunVisitorT<T>::visitprivate(const WhileExp  &e)
             const_cast<Exp*>(&(e.getBody()))->resetContinue();
         }
 
-        e.getTest().accept(*this);
+        try
+        {
+            e.getTest().accept(*this);
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
         pIT = getResult();
     }
 
     //pIT->killMe();
     //clear result of condition or result of body
     clearResult();
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const ForExp  &e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
     symbol::Context* ctx = symbol::Context::getInstance();
     //vardec visit increase its result reference
-    e.getVardec().accept(*this);
-    InternalType* pIT = getResult();
+    try
+    {
+        e.getVardec().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+    types::InternalType* pIT = getResult();
 
     if (pIT->isImplicitList())
     {
         //get IL
-        ImplicitList* pVar = pIT->getAs<ImplicitList>();
+        types::ImplicitList* pVar = pIT->getAs<types::ImplicitList>();
         //get IL initial Type
-        InternalType * pIL = pVar->getInitalType();
+        types::InternalType * pIL = pVar->getInitalType();
         //std::cout << "for IL: " << pIL << std::endl;
         //std::cout << "  for IV: " << pIT << std::endl;
         //get index stack
@@ -391,6 +673,7 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
         {
             std::wostringstream os;
             os << _W("Redefining permanent variable.\n");
+            CoverageInstance::stopChrono((void*)&e);
             throw ast::InternalError(os.str(), 999, e.getVardec().getLocation());
         }
 
@@ -428,6 +711,7 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
                         {
                             std::wostringstream os;
                             os << _W("Redefining permanent variable.\n");
+                            CoverageInstance::stopChrono((void*)&e);
                             throw ast::InternalError(os.str(), 999, e.getVardec().getLocation());
                         }
 
@@ -451,6 +735,7 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
                 pIT->killMe();
 
                 setResult(NULL);
+                CoverageInstance::stopChrono((void*)&e);
                 throw ie;
             }
 
@@ -480,17 +765,18 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
     }
     else if (pIT->isList())
     {
-        List* pL = pIT->getAs<List>();
+        types::List* pL = pIT->getAs<types::List>();
         const int size = pL->getSize();
         symbol::Variable* var = e.getVardec().getAs<VarDec>()->getStack();
         for (int i = 0; i < size; ++i)
         {
-            InternalType* pNew = pL->get(i);
+            types::InternalType* pNew = pL->get(i);
 
             if (ctx->isprotected(var))
             {
                 std::wostringstream os;
                 os << _W("Redefining permanent variable.\n");
+                CoverageInstance::stopChrono((void*)&e);
                 throw ast::InternalError(os.str(), 999, e.getVardec().getLocation());
             }
             ctx->put(var, pNew);
@@ -505,6 +791,7 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
                 pIT->DecreaseRef();
                 pIT->killMe();
                 setResult(NULL);
+                CoverageInstance::stopChrono((void*)&e);
                 throw ie;
             }
 
@@ -531,22 +818,24 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
     else if (pIT->isGenericType())
     {
         //Matrix i = [1,3,2,6] or other type
-        GenericType* pVar = pIT->getAs<GenericType>();
+        types::GenericType* pVar = pIT->getAs<types::GenericType>();
         if (pVar->getDims() > 2)
         {
             pIT->DecreaseRef();
             pIT->killMe();
+            CoverageInstance::stopChrono((void*)&e);
             throw InternalError(_W("for expression can only manage 1 or 2 dimensions variables\n"), 999, e.getVardec().getLocation());
         }
 
         symbol::Variable* var = e.getVardec().getAs<VarDec>()->getStack();
         for (int i = 0; i < pVar->getCols(); i++)
         {
-            GenericType* pNew = pVar->getColumnValues(i);
+            types::GenericType* pNew = pVar->getColumnValues(i);
             if (pNew == NULL)
             {
                 pIT->DecreaseRef();
                 pIT->killMe();
+                CoverageInstance::stopChrono((void*)&e);
                 throw InternalError(_W("for expression : Wrong type for loop iterator.\n"), 999, e.getVardec().getLocation());
             }
 
@@ -554,6 +843,7 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
             {
                 std::wostringstream os;
                 os << _W("Redefining permanent variable.\n");
+                CoverageInstance::stopChrono((void*)&e);
                 throw InternalError(os.str(), 999, e.getVardec().getLocation());
             }
             ctx->put(var, pNew);
@@ -568,6 +858,7 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
                 pIT->DecreaseRef();
                 pIT->killMe();
                 setResult(NULL);
+                CoverageInstance::stopChrono((void*)&e);
                 throw ie;
             }
 
@@ -595,6 +886,7 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
     {
         pIT->DecreaseRef();
         pIT->killMe();
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(_W("for expression : Wrong type for loop iterator.\n"), 999, e.getVardec().getLocation());
     }
 
@@ -602,17 +894,21 @@ void RunVisitorT<T>::visitprivate(const ForExp  &e)
     pIT->killMe();
 
     setResult(NULL);
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const ReturnExp &e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
     if (e.isGlobal())
     {
         if (ConfigVariable::getPauseLevel() != 0 && symbol::Context::getInstance()->getScopeLevel() == ConfigVariable::getActivePauseLevel())
         {
             //return or resume
             ConfigVariable::DecreasePauseLevel();
+            ConfigVariable::macroFirstLine_end();
+            CoverageInstance::stopChrono((void*)&e);
             return;
         }
         else
@@ -624,18 +920,34 @@ void RunVisitorT<T>::visitprivate(const ReturnExp &e)
     {
         //return(x)
 
-        //in case of CallExp, we can return only one values
+        if (e.getParent() == nullptr || e.getParent()->isAssignExp() == false)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw InternalError(_W("With input arguments, return / resume expects output arguments.\n"), 999, e.getLocation());
+        }
+        //in case of CallExp, we can return only one value
         int iSaveExpectedSize = getExpectedSize();
         setExpectedSize(1);
-        e.getExp().accept(*this);
+        try
+        {
+            e.getExp().accept(*this);
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
         setExpectedSize(iSaveExpectedSize);
         const_cast<ReturnExp*>(&e)->setReturn();
     }
+
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const IntSelectExp &e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
     bool found = false;
     //e.getSelect()->accept(*this);
     //InternalType* pIT = getResult();
@@ -706,20 +1018,38 @@ void RunVisitorT<T>::visitprivate(const IntSelectExp &e)
 
     if (!found)
     {
-        e.getOriginal()->accept(*this);
+        try
+        {
+            e.getOriginal()->accept(*this);
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
     }
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const StringSelectExp &e)
 {
-    e.getSelect()->accept(*this);
-    InternalType* pIT = getResult();
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    try
+    {
+        e.getSelect()->accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+    types::InternalType* pIT = getResult();
     setResult(nullptr);
     bool found = false;
     if (pIT && pIT->isString())
     {
-        String * pStr = static_cast<String *>(pIT);
+        types::String * pStr = static_cast<types::String *>(pIT);
         if (pStr->getSize() == 1)
         {
             if (wchar_t * s = pStr->get(0))
@@ -756,6 +1086,7 @@ void RunVisitorT<T>::visitprivate(const StringSelectExp &e)
                     catch (const InternalError& ie)
                     {
                         pIT->killMe();
+                        CoverageInstance::stopChrono((void*)&e);
                         throw ie;
                     }
 
@@ -783,18 +1114,37 @@ void RunVisitorT<T>::visitprivate(const StringSelectExp &e)
 
     if (!found)
     {
-        e.getOriginal()->accept(*this);
+        try
+        {
+            e.getOriginal()->accept(*this);
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
     }
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const SelectExp &e)
 {
     // FIXME : exec select ... case ... else ... end
-    e.getSelect()->accept(*this);
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    try
+    {
+        e.getSelect()->accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+
     bool bCase = false;
 
-    InternalType* pIT = getResult();
+    types::InternalType* pIT = getResult();
     setResult(NULL);
     if (pIT)
     {
@@ -806,9 +1156,17 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
         exps_t cases = e.getCases();
         for (auto exp : cases)
         {
-            CaseExp* pCase = exp->getAs<CaseExp>();
-            pCase->getTest()->accept(*this);
-            InternalType *pITCase = getResult();
+            CaseExp * pCase = exp->getAs<CaseExp>();
+            try
+            {
+                pCase->getTest()->accept(*this);
+            }
+            catch (ScilabException &)
+            {
+                CoverageInstance::stopChrono((void*)&e);
+                throw;
+            }
+            types::InternalType *pITCase = getResult();
             setResult(NULL);
             if (pITCase)
             {
@@ -827,6 +1185,7 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
                     {
                         pIT->DecreaseRef();
                         pIT->killMe();
+                        CoverageInstance::stopChrono((void*)&e);
                         throw ie;
                     }
 
@@ -872,6 +1231,7 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
                 pIT->DecreaseRef();
                 pIT->killMe();
             }
+            CoverageInstance::stopChrono((void*)&e);
             throw ie;
         }
 
@@ -901,157 +1261,28 @@ void RunVisitorT<T>::visitprivate(const SelectExp &e)
         pIT->DecreaseRef();
         pIT->killMe();
     }
-}
-
-template <class T>
-void RunVisitorT<T>::visitprivate(const SeqExp  &e)
-{
-    for (auto exp : e.getExps())
-    {
-        if (exp->isCommentExp())
-        {
-            continue;
-        }
-
-        // interrupt me to execute a prioritary command
-        while (StaticRunner_isInterruptibleCommand() == 1 && StaticRunner_isRunnerAvailable() == 1)
-        {
-            StaticRunner_launch();
-            StaticRunner_setInterruptibleCommand(1);
-        }
-
-        try
-        {
-            //reset default values
-            setResult(NULL);
-            int iExpectedSize = getExpectedSize();
-            setExpectedSize(-1);
-            exp->accept(*this);
-            setExpectedSize(iExpectedSize);
-            InternalType * pIT = getResult();
-
-            // In case of exec file, set the file name in the Macro to store where it is defined.
-            int iFileID = ConfigVariable::getExecutedFileID();
-            if (iFileID && exp->isFunctionDec())
-            {
-                InternalType* pITMacro = symbol::Context::getInstance()->get(exp->getAs<FunctionDec>()->getSymbol());
-                if (pITMacro)
-                {
-                    types::Macro* pMacro = pITMacro->getAs<types::Macro>();
-                    const wchar_t* filename = getfile_filename(iFileID);
-                    // scilab.quit is not open with mopen
-                    // in this case filename is NULL because FileManager have not been filled.
-                    if (filename)
-                    {
-                        pMacro->setFileName(filename);
-                    }
-                }
-            }
-
-            if (pIT != NULL)
-            {
-                bool bImplicitCall = false;
-                if (pIT->isCallable()) //to manage call without ()
-                {
-                    Callable *pCall = pIT->getAs<Callable>();
-                    typed_list out;
-                    typed_list in;
-                    optional_list opt;
-
-                    try
-                    {
-                        //in this case of calling, we can return only one values
-                        int iSaveExpectedSize = getExpectedSize();
-                        setExpectedSize(1);
-
-                        pCall->invoke(in, opt, getExpectedSize(), out, *this, e);
-                        setExpectedSize(iSaveExpectedSize);
-
-                        if (out.size() == 0)
-                        {
-                            setResult(NULL);
-                        }
-                        else
-                        {
-                            setResult(out[0]);
-                        }
-
-                        bImplicitCall = true;
-                    }
-                    catch (const InternalError& ie)
-                    {
-                        if (ConfigVariable::getLastErrorFunction() == L"")
-                        {
-                            ConfigVariable::setLastErrorFunction(pCall->getName());
-                            ConfigVariable::setLastErrorLine(e.getLocation().first_line);
-                        }
-
-                        throw ie;
-                    }
-                }
-
-                //don't output Simplevar and empty result
-                if (getResult() != NULL && (!exp->isSimpleVar() || bImplicitCall))
-                {
-                    //symbol::Context::getInstance()->put(symbol::Symbol(L"ans"), *execMe.getResult());
-                    InternalType* pITAns = getResult();
-                    symbol::Context::getInstance()->put(m_pAns, pITAns);
-                    if (exp->isVerbose() && ConfigVariable::isPromptShow())
-                    {
-                        //TODO manage multiple returns
-                        scilabWriteW(L" ans  =\n\n");
-                        std::wostringstream ostrName;
-                        ostrName << L"ans";
-                        VariableToString(pITAns, ostrName.str().c_str());
-                    }
-                }
-
-                pIT->killMe();
-            }
-
-            if ((&e)->isBreakable() && exp->isBreak())
-            {
-                const_cast<SeqExp *>(&e)->setBreak();
-                exp->resetBreak();
-                break;
-            }
-
-            if ((&e)->isContinuable() && exp->isContinue())
-            {
-                const_cast<SeqExp *>(&e)->setContinue();
-                exp->resetContinue();
-                break;
-            }
-
-            if ((&e)->isReturnable() && exp->isReturn())
-            {
-                const_cast<SeqExp *>(&e)->setReturn();
-                exp->resetReturn();
-                break;
-            }
-        }
-        catch (const InternalError& ie)
-        {
-            ConfigVariable::fillWhereError(ie.GetErrorLocation().first_line);
-            throw ie;
-        }
-
-        // If something other than NULL is given to setResult, then that would imply
-        // to make a cleanup in visit(ForExp) for example (e.getBody().accept(*this);)
-        setResult(NULL);
-    }
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const NotExp &e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
     /*
       @ or ~ !
-    */
-    e.getExp().accept(*this);
+      */
+    try
+    {
+        e.getExp().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
 
-    InternalType * pValue = getResult();
-    InternalType * pReturn = NULL;
+    types::InternalType * pValue = getResult();
+    types::InternalType * pReturn = NULL;
     if (pValue->neg(pReturn))
     {
         if (pValue != pReturn)
@@ -1070,34 +1301,46 @@ void RunVisitorT<T>::visitprivate(const NotExp &e)
         pValue->IncreaseRef();
         in.push_back(pValue);
 
-        Callable::ReturnValue Ret = Overload::call(L"%" + pValue->getShortTypeStr() + L"_5", in, 1, out, this);
+        types::Callable::ReturnValue Ret = Overload::call(L"%" + pValue->getShortTypeStr() + L"_5", in, 1, out, true);
 
-        if (Ret != Callable::OK)
+        if (Ret != types::Callable::OK)
         {
             cleanInOut(in, out);
+            CoverageInstance::stopChrono((void*)&e);
             throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
         }
 
         setResult(out);
         cleanIn(in, out);
     }
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const TransposeExp &e)
 {
-    e.getExp().accept(*this);
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    try
+    {
+        e.getExp().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
 
     if (getResultSize() != 1)
     {
         clearResult();
         wchar_t szError[bsiz];
         os_swprintf(szError, bsiz, _W("%ls: Can not transpose multiple elements.\n").c_str(), L"Transpose");
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
 
-    InternalType * pValue = getResult();
-    InternalType * pReturn = NULL;
+    types::InternalType * pValue = getResult();
+    types::InternalType * pReturn = NULL;
     const bool bConjug = e.getConjugate() == TransposeExp::_Conjugate_;
 
     if ((bConjug && pValue->adjoint(pReturn)) || (!bConjug && pValue->transpose(pReturn)))
@@ -1108,6 +1351,7 @@ void RunVisitorT<T>::visitprivate(const TransposeExp &e)
         }
 
         setResult(pReturn);
+        CoverageInstance::stopChrono((void*)&e);
 
         return;
     }
@@ -1120,35 +1364,39 @@ void RunVisitorT<T>::visitprivate(const TransposeExp &e)
         pValue->IncreaseRef();
         in.push_back(pValue);
 
-        Callable::ReturnValue Ret;
+        types::Callable::ReturnValue Ret;
         if (bConjug)
         {
-            Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_t", in, 1, out, this);
+            Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_t", in, 1, out, true);
         }
         else
         {
-            Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_0", in, 1, out, this);
+            Ret = Overload::call(L"%" + getResult()->getShortTypeStr() + L"_0", in, 1, out, true);
         }
 
-        if (Ret != Callable::OK)
+        if (Ret != types::Callable::OK)
         {
             cleanInOut(in, out);
+            CoverageInstance::stopChrono((void*)&e);
             throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
         }
 
         setResult(out);
         cleanIn(in, out);
     }
+
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const FunctionDec & e)
 {
+    CoverageInstance::invokeAndStartChrono((void*)&e);
     symbol::Context* ctx = symbol::Context::getInstance();
     /*
       function foo
       endfunction
-    */
+      */
 
     // funcprot(0) : do nothing
     // funcprot(1) && warning(on) : warning
@@ -1171,43 +1419,21 @@ void RunVisitorT<T>::visitprivate(const FunctionDec & e)
     types::Macro *pMacro = new types::Macro(e.getSymbol().getName(), *pVarList, *pRetList,
                                             const_cast<SeqExp&>(static_cast<const SeqExp&>(e.getBody())), L"script");
     pMacro->setLines(e.getLocation().first_line, e.getLocation().last_line);
-
-    bool bEquals = false;
-    int iFuncProt = ConfigVariable::getFuncprot();
-    if (iFuncProt != 0)
+    if (e.getMacro())
     {
-        types::InternalType* pITFunc = ctx->get(((FunctionDec&)e).getStack());
-        if (pITFunc && pITFunc->isCallable())
-        {
-            if (pITFunc->isMacroFile())
-            {
-                types::MacroFile* pMF = pITFunc->getAs<types::MacroFile>();
-                bEquals = *pMF->getMacro() == *pMacro;
-            }
-            else if (pITFunc->isMacro())
-            {
-                types::Macro* pM = pITFunc->getAs<types::Macro>();
-                bEquals = *pM == *pMacro;
-            }
-        }
-        else
-        {
-            bEquals = true; //avoid msg but keep assignation
-        }
+        pMacro->setFileName(e.getMacro()->getFileName());
     }
 
-    if (bEquals == false && iFuncProt == 1 && ConfigVariable::getWarningMode())
+    if (ctx->isprotected(symbol::Symbol(pMacro->getName())))
     {
-        wchar_t pwstFuncName[1024];
-        os_swprintf(pwstFuncName, 1024, L"%-24ls", e.getSymbol().getName().c_str());
-        char* pstFuncName = wide_string_to_UTF8(pwstFuncName);
-
-
-        sciprint(_("Warning : redefining function: %s. Use funcprot(0) to avoid this message"), pstFuncName);
-        sciprint("\n");
-        FREE(pstFuncName);
+        delete pMacro;
+        std::wostringstream os;
+        os << _W("Redefining permanent variable.\n");
+        CoverageInstance::stopChrono((void*)&e);
+        throw InternalError(os.str(), 999, e.getLocation());
     }
-    else if (bEquals == false && iFuncProt == 2)
+
+    if (ctx->addMacro(pMacro) == false)
     {
         char pstError[1024];
         char* pstFuncName = wide_string_to_UTF8(e.getSymbol().getName().c_str());
@@ -1216,64 +1442,114 @@ void RunVisitorT<T>::visitprivate(const FunctionDec & e)
         std::wstring wstError(pwstError);
         FREE(pstFuncName);
         FREE(pwstError);
-        delete pMacro;
+        pMacro->killMe();
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(wstError, 999, e.getLocation());
     }
 
-
-    if (ctx->isprotected(symbol::Symbol(pMacro->getName())))
-    {
-        delete pMacro;
-        std::wostringstream os;
-        os << _W("Redefining permanent variable.\n");
-        throw InternalError(os.str(), 999, e.getLocation());
-    }
-
-    ctx->addMacro(pMacro);
-
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const ListExp &e)
 {
-    e.getStart().accept(*this);
-    GenericType* pITStart = static_cast<GenericType*>(getResult());
-    if ((pITStart->getSize() != 1 || (pITStart->isDouble() && pITStart->getAs<Double>()->isComplex())) &&
-            pITStart->isList() == false) // list case => call overload
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    try
     {
-        pITStart->killMe();
+        e.getStart().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+
+    types::InternalType* pITStart = getResult();
+    types::GenericType* pStart = static_cast<types::GenericType*>(pITStart);
+    if (pITStart == NULL ||
+            ((pITStart->isGenericType() == false || pStart->getSize() != 1 || (pStart->isDouble() && pStart->getAs<types::Double>()->isComplex())) &&
+             pStart->isList() == false)) // list case => call overload
+    {
+        setResult(NULL);
         wchar_t szError[bsiz];
-        os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 1);
+        if (pITStart && pITStart->isImplicitList())
+        {
+            os_swprintf(szError, bsiz, _W("%ls: Too many %ls or wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", L"':'", 1);
+        }
+        else
+        {
+            os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 1);
+        }
+
+        if (pITStart)
+        {
+            pITStart->killMe();
+        }
+
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
-    InternalType * piStart = pITStart;
 
-    e.getStep().accept(*this);
-    GenericType* pITStep = static_cast<GenericType*>(getResult());
-    if ((pITStep->getSize() != 1 || (pITStep->isDouble() && pITStep->getAs<Double>()->isComplex())) &&
-            pITStep->isList() == false) // list case => call overload
+    try
+    {
+        e.getStep().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+
+    types::InternalType* pITStep = getResult();
+    types::GenericType* pStep = static_cast<types::GenericType*>(pITStep);
+    setResult(NULL);
+    if (pITStep == NULL ||
+            ((pITStep->isGenericType() == false || pStep->getSize() != 1 || (pStep->isDouble() && pStep->getAs<types::Double>()->isComplex())) &&
+             pStep->isList() == false)) // list case => call overload
     {
         pITStart->killMe();
-        pITStep->killMe();
+        if (pITStep)
+        {
+            pITStep->killMe();
+        }
+
+        setResult(NULL);
         wchar_t szError[bsiz];
         os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 2);
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
-    InternalType* piStep = pITStep;
 
-    e.getEnd().accept(*this);
-    GenericType* pITEnd = static_cast<GenericType*>(getResult());
-    if ((pITEnd->getSize() != 1 || (pITEnd->isDouble() && pITEnd->getAs<Double>()->isComplex())) &&
-            pITEnd->isList() == false) // list case => call overload
+    try
+    {
+        e.getEnd().accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+
+    types::InternalType* pITEnd = getResult();
+    types::GenericType* pEnd = static_cast<types::GenericType*>(pITEnd);
+    setResult(NULL);
+    if (pITEnd == NULL ||
+            ((pITEnd->isGenericType() == false || pEnd->getSize() != 1 || (pEnd->isDouble() && pEnd->getAs<types::Double>()->isComplex())) &&
+             pEnd->isList() == false)) // list case => call overload
     {
         pITStart->killMe();
         pITStep->killMe();
-        pITEnd->killMe();
+        if (pITEnd)
+        {
+            pITEnd->killMe();
+        }
+
+        setResult(NULL);
         wchar_t szError[bsiz];
-        os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 3);
+        os_swprintf(szError, bsiz, _W("%ls: Wrong type for argument %d: Real scalar expected.\n").c_str(), L"':'", 2 + e.hasExplicitStep());
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(szError, 999, e.getLocation());
     }
-    InternalType* piEnd = pITEnd;
 
     ////check if implicitlist is 1:$ to replace by ':'
     //if (piStart->isDouble() && piStep->isDouble() && piEnd->isPoly())
@@ -1291,38 +1567,40 @@ void RunVisitorT<T>::visitprivate(const ListExp &e)
 
     //check compatibility
     // double : double : double or poly : poly : poly and mix like double : double : poly
-    if ((piStart->isPoly() || piStart->isDouble()) &&
-            (piStep->isPoly()  || piStep->isDouble())  &&
-            (piEnd->isPoly()   || piEnd->isDouble()))
+    if ((pStart->isPoly() || pStart->isDouble()) &&
+            (pStep->isPoly() || pStep->isDouble()) &&
+            (pEnd->isPoly() || pEnd->isDouble()))
     {
         // No need to kill piStart, ... because Implicit list ctor will incref them
-        setResult(new ImplicitList(piStart, piStep, piEnd));
+        setResult(new types::ImplicitList(pStart, pStep, pEnd));
+        CoverageInstance::stopChrono((void*)&e);
         return;
     }
 
     // int : double or int : int
-    if ( piStart->isInt()   &&
-            (piStep->isDouble() || piStep->isInt()) &&
-            piEnd->isInt())
+    if (pStart->isInt() &&
+            (pStep->isDouble() || pStep->isInt()) &&
+            pEnd->isInt())
     {
         // check for same int type int8, int 16 ...
-        if (piStart->getType() == piEnd->getType()  &&
-                (piStart->getType() == piStep->getType() ||
-                 piStep->isDouble()))
+        if (pStart->getType() == pEnd->getType() &&
+                (pStart->getType() == pStep->getType() ||
+                 pStep->isDouble()))
         {
             // No need to kill piStart, ... because Implicit list ctor will incref them
-            setResult(new ImplicitList(piStart, piStep, piEnd));
+            setResult(new types::ImplicitList(pStart, pStep, pEnd));
+            CoverageInstance::stopChrono((void*)&e);
             return;
         }
     }
 
     // Call Overload
-    Callable::ReturnValue Ret;
+    types::Callable::ReturnValue Ret;
     types::typed_list in;
     types::typed_list out;
 
-    piStart->IncreaseRef();
-    in.push_back(piStart);
+    pStart->IncreaseRef();
+    in.push_back(pStart);
 
     try
     {
@@ -1330,36 +1608,41 @@ void RunVisitorT<T>::visitprivate(const ListExp &e)
         {
             // 1:2:4
             //call overload %typeStart_b_typeStep
-            piStep->IncreaseRef();
-            in.push_back(piStep);
-            piEnd->IncreaseRef();
-            in.push_back(piEnd);
-            Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piStep->getShortTypeStr(), in, 1, out, this, true);
+            pStep->IncreaseRef();
+            in.push_back(pStep);
+            pEnd->IncreaseRef();
+            in.push_back(pEnd);
+            Ret = Overload::call(L"%" + pStart->getShortTypeStr() + L"_b_" + pStep->getShortTypeStr(), in, 1, out, true);
         }
         else
         {
             // 1:2
             //call overload %typeStart_b_typeEnd
-            piStep->killMe();
-            piEnd->IncreaseRef();
-            in.push_back(piEnd);
-            Ret = Overload::call(L"%" + piStart->getShortTypeStr() + L"_b_" + piEnd->getShortTypeStr(), in, 1, out, this, true);
+            pStep->killMe();
+            pEnd->IncreaseRef();
+            in.push_back(pEnd);
+            Ret = Overload::call(L"%" + pStart->getShortTypeStr() + L"_b_" + pEnd->getShortTypeStr(), in, 1, out, true);
         }
     }
     catch (const InternalError& error)
     {
+        setResult(NULL);
         cleanInOut(in, out);
+        CoverageInstance::stopChrono((void*)&e);
         throw error;
     }
 
-    if (Ret != Callable::OK)
+    if (Ret != types::Callable::OK)
     {
+        setResult(NULL);
         cleanInOut(in, out);
+        CoverageInstance::stopChrono((void*)&e);
         throw InternalError(ConfigVariable::getLastErrorMessage(), ConfigVariable::getLastErrorNumber(), e.getLocation());
     }
 
     setResult(out);
     cleanIn(in, out);
+    CoverageInstance::stopChrono((void*)&e);
 }
 
 template <class T>
@@ -1370,22 +1653,32 @@ void RunVisitorT<T>::visitprivate(const OptimizedExp &e)
 template <class T>
 void RunVisitorT<T>::visitprivate(const MemfillExp &e)
 {
-    e.getOriginal()->accept(*this);
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    try
+    {
+        e.getOriginal()->accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
 }
 
 template <class T>
 void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
 {
-    InternalType* pIT = NULL;
-    Double* ad = NULL;
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    types::InternalType* pIT = NULL;
+    types::Double* ad = NULL;
     int ar = 0;
     int ac = 0;
 
-    Double* xd = NULL;
+    types::Double* xd = NULL;
     int xr = 0;
     int xc = 0;
 
-    Double* yd = NULL;
+    types::Double* yd = NULL;
     int yr = 0;
     int yc = 0;
 
@@ -1393,11 +1686,20 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
 
     //y must be double
     const Exp &ye = e.getY();
-    ye.accept(*this);
+    try
+    {
+        ye.accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+
     pIT = getResult();
     if (pIT->isDouble())
     {
-        yd = pIT->getAs<Double>();
+        yd = pIT->getAs<types::Double>();
         if (yd->getDims() == 2 && yd->isComplex() == false)
         {
             yr = yd->getRows();
@@ -1406,25 +1708,51 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
         else
         {
             yd->killMe();
-            e.getOriginal()->accept(*this);
+            try
+            {
+                e.getOriginal()->accept(*this);
+            }
+            catch (ScilabException &)
+            {
+                CoverageInstance::stopChrono((void*)&e);
+                throw;
+            }
+            CoverageInstance::stopChrono((void*)&e);
             return;
         }
     }
     else
     {
         pIT->killMe();
-        e.getOriginal()->accept(*this);
+        try
+        {
+            e.getOriginal()->accept(*this);
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
+        CoverageInstance::stopChrono((void*)&e);
         return;
     }
 
     //x
     const Exp &xe = e.getX();
-    xe.accept(*this);
+    try
+    {
+        xe.accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
     pIT = getResult();
 
     if (pIT->isDouble())
     {
-        xd = pIT->getAs<Double>();
+        xd = pIT->getAs<types::Double>();
         if (xd->isScalar() && xd->isComplex() == false)
         {
             // x become a
@@ -1441,7 +1769,16 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
         {
             yd->killMe();
             xd->killMe();
-            e.getOriginal()->accept(*this);
+            try
+            {
+                e.getOriginal()->accept(*this);
+            }
+            catch (ScilabException &)
+            {
+                CoverageInstance::stopChrono((void*)&e);
+                throw;
+            }
+            CoverageInstance::stopChrono((void*)&e);
             return;
         }
     }
@@ -1449,19 +1786,36 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
     {
         pIT->killMe();
         yd->killMe();
-        e.getOriginal()->accept(*this);
+        try
+        {
+            e.getOriginal()->accept(*this);
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
+        CoverageInstance::stopChrono((void*)&e);
         return;
     }
 
     const Exp &ae = e.getA();
-    ae.accept(*this);
+    try
+    {
+        ae.accept(*this);
+    }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
     pIT = getResult();
 
     if (pIT->isDouble())
     {
         if (ad)
         {
-            xd = pIT->getAs<Double>();
+            xd = pIT->getAs<types::Double>();
             //X is scalar it become A
             //now use A as X
             if (xd->getDims() == 2 && xd->isComplex() == false)
@@ -1474,14 +1828,23 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
                 yd->killMe();
                 xd->killMe();
                 ad->killMe();
-                e.getOriginal()->accept(*this);
+                try
+                {
+                    e.getOriginal()->accept(*this);
+                }
+                catch (ScilabException &)
+                {
+                    CoverageInstance::stopChrono((void*)&e);
+                    throw;
+                }
+                CoverageInstance::stopChrono((void*)&e);
                 return;
             }
         }
         else
         {
             //a is a and it must be scalar
-            ad = pIT->getAs<Double>();
+            ad = pIT->getAs<types::Double>();
             if (/*ad->isScalar() && */ad->isComplex() == false)
             {
                 ar = ad->getRows(); //1;
@@ -1492,7 +1855,16 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
                 yd->killMe();
                 xd->killMe();
                 ad->killMe();
-                e.getOriginal()->accept(*this);
+                try
+                {
+                    e.getOriginal()->accept(*this);
+                }
+                catch (ScilabException &)
+                {
+                    CoverageInstance::stopChrono((void*)&e);
+                    throw;
+                }
+                throw;
                 return;
             }
         }
@@ -1502,60 +1874,150 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
         pIT->killMe();
         yd->killMe();
         xd->killMe();
-        e.getOriginal()->accept(*this);
-        return;
-    }
-
-    if (ad && xd && yd)
-    {
-        if ( ac == 1 &&
-                ar == 1 &&
-                xr == yr &&
-                xc == yc)
+        try
         {
-            //go !
-            int one = 1;
-            int size = xc * xr;
-            //Double* od = (Double*)yd->clone();
-            C2F(daxpy)(&size, ad->get(), xd->get(), &one, yd->get(), &one);
-            //setResult(od);
-            //yd->killMe();
-            xd->killMe();
-            ad->killMe();
-            return;
+            e.getOriginal()->accept(*this);
         }
-        else if (ac == xr && ar == yr && xc == yc)
+        catch (ScilabException &)
         {
-            char n = 'n';
-            double one = 1;
-            C2F(dgemm)(&n, &n, &ar, &xc, &ac, &one, ad->get(), &ar, xd->get(), &ac, &one, yd->get(), &ar);
-            xd->killMe();
-            ad->killMe();
-            return;
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
         }
+        CoverageInstance::stopChrono((void*)&e);
+        return;
     }
 
-    if (yd)
+    // If we get here we are certain that ad, xd & yd have been set
+    if (ac == 1 &&
+            ar == 1 &&
+            xr == yr &&
+            xc == yc)
     {
-        yd->killMe();
+        //go !
+        int one = 1;
+        int size = xc * xr;
+        //Double* od = (Double*)yd->clone();
+        C2F(daxpy)(&size, ad->get(), xd->get(), &one, yd->get(), &one);
+        //setResult(od);
+        //yd->killMe();
+        xd->killMe();
+        ad->killMe();
+        CoverageInstance::stopChrono((void*)&e);
+        return;
     }
-
-    if (xd)
+    else if (ac == xr && ar == yr && xc == yc)
     {
+        char n = 'n';
+        double one = 1;
+        C2F(dgemm)(&n, &n, &ar, &xc, &ac, &one, ad->get(), &ar, xd->get(), &ac, &one, yd->get(), &ar);
         xd->killMe();
+        ad->killMe();
+        CoverageInstance::stopChrono((void*)&e);
+        return;
     }
 
-    if (ad)
+    yd->killMe();
+    xd->killMe();
+    ad->killMe();
+
+    try
     {
-        ad->killMe();
+        e.getOriginal()->accept(*this);
     }
+    catch (ScilabException &)
+    {
+        CoverageInstance::stopChrono((void*)&e);
+        throw;
+    }
+    CoverageInstance::stopChrono((void*)&e);
 
-    e.getOriginal()->accept(*this);
     return;
 }
 
+template <class T>
+void RunVisitorT<T>::visitprivate(const TryCatchExp  &e)
+{
+    CoverageInstance::invokeAndStartChrono((void*)&e);
+    //save current prompt mode
+    bool oldVal = ConfigVariable::isSilentError();
+    int oldMode = ConfigVariable::getPromptMode();
+    //set mode silent for errors
+    ConfigVariable::setSilentError(true);
+
+    symbol::Context* pCtx = symbol::Context::getInstance();
+    try
+    {
+        int scope = pCtx->getScopeLevel();
+        int level = ConfigVariable::getRecursionLevel();
+        try
+        {
+            const_cast<Exp*>(&e.getTry())->setReturnable();
+            e.getTry().accept(*this);
+            //restore previous prompt mode
+            ConfigVariable::setSilentError(oldVal);
+
+            if (e.getTry().isReturn())
+            {
+                const_cast<Exp*>(&e.getTry())->resetReturn();
+                const_cast<TryCatchExp*>(&e)->setReturn();
+            }
+        }
+        catch (const RecursionException& /* re */)
+        {
+            ConfigVariable::setPromptMode(oldMode);
+
+            //close opened scope during try
+            while (pCtx->getScopeLevel() > scope)
+            {
+                pCtx->scope_end();
+            }
+
+            //decrease recursion to init value and close where
+            while (ConfigVariable::getRecursionLevel() > level)
+            {
+                ConfigVariable::where_end();
+                ConfigVariable::decreaseRecursion();
+            }
+
+            //print msg about recursion limit and trigger an error
+            wchar_t sz[1024];
+            os_swprintf(sz, 1024, _W("Recursion limit reached (%d).\n").data(), ConfigVariable::getRecursionLimit());
+            CoverageInstance::stopChrono((void*)&e);
+            throw ast::InternalError(sz);
+        }
+
+    }
+    catch (const InternalError& /* ie */)
+    {
+        //restore previous prompt mode
+        ConfigVariable::setSilentError(oldVal);
+        //to lock lasterror
+        ConfigVariable::setLastErrorCall();
+        // reset call stack filled when error occurred
+        ConfigVariable::resetWhereError();
+        try
+        {
+            const_cast<Exp*>(&e.getCatch())->setReturnable();
+            e.getCatch().accept(*this);
+            if (e.getCatch().isReturn())
+            {
+                const_cast<Exp*>(&e.getCatch())->resetReturn();
+                const_cast<TryCatchExp*>(&e)->setReturn();
+            }
+        }
+        catch (ScilabException &)
+        {
+            CoverageInstance::stopChrono((void*)&e);
+            throw;
+        }
+    }
+    CoverageInstance::stopChrono((void*)&e);
+}
+
+
 } /* namespace ast */
 
+#include "run_SeqExp.hpp"
 #include "run_CallExp.hpp"
 #include "run_MatrixExp.hpp"
 #include "run_OpExp.hpp"
@@ -1564,3 +2026,4 @@ void RunVisitorT<T>::visitprivate(const DAXPYExp &e)
 template EXTERN_AST class ast::RunVisitorT<ast::ExecVisitor>;
 template EXTERN_AST class ast::RunVisitorT<ast::StepVisitor>;
 template EXTERN_AST class ast::RunVisitorT<ast::TimedVisitor>;
+template EXTERN_AST class ast::RunVisitorT<ast::DebuggerVisitor>;