add serialization of AST before execute it 59/14559/10
Antoine ELIAS [Tue, 20 May 2014 16:01:42 +0000 (18:01 +0200)]
Change-Id: I52e93ccf3493bad7717ac5b36909ef2c6cf20290

21 files changed:
scilab/bin/scilab
scilab/modules/ast/Makefile.am
scilab/modules/ast/ast.vcxproj
scilab/modules/ast/ast.vcxproj.filters
scilab/modules/ast/includes/deserializervisitor.hxx [new file with mode: 0644]
scilab/modules/ast/includes/exps/ast.hxx
scilab/modules/ast/includes/exps/exp.hxx
scilab/modules/ast/includes/serializervisitor.hxx [new file with mode: 0644]
scilab/modules/ast/includes/visitor_common.hxx
scilab/modules/ast/src/cpp/visitor_common.cpp
scilab/modules/core/includes/InitScilab.h
scilab/modules/core/includes/tasks.hxx
scilab/modules/core/includes/timer.hxx
scilab/modules/core/src/cpp/InitScilab.cpp
scilab/modules/core/src/cpp/tasks.cpp
scilab/modules/functions/sci_gateway/cpp/sci_exec.cpp
scilab/modules/functions/sci_gateway/cpp/sci_execstr.cpp
scilab/modules/m2sci/macros/buildmacros.sce
scilab/modules/startup/src/cpp/scilab.cpp
scilab/modules/system_env/includes/configvariable.hxx
scilab/modules/system_env/src/cpp/configvariable.cpp

index d700ec2..74fa0e7 100755 (executable)
@@ -1061,7 +1061,7 @@ if test "$rest" = "yes"; then
                     exit 5
                 fi
                 ;;
-            --parse-trace|--pretty-print|--help|--AST-trace|--no-exec|--context-dump|--exec-verbose|--timed|--AST-timed)
+            --parse-trace|--pretty-print|--help|--AST-trace|--no-exec|--context-dump|--exec-verbose|--timed|--AST-timed|--serialize)
            #This are Scilab6 dedicated options.
                    ;;
             -psn_*)
index 43acbc2..d95f7a8 100644 (file)
@@ -19,6 +19,7 @@ libsciast_la_SOURCES = \
        src/cpp/run_MatrixExp.cpp \
        src/cpp/run_OpExp.cpp \
        src/cpp/run_AssignExp.cpp \
+
        src/cpp/visitor_common.cpp \
        src/cpp/printvisitor.cpp \
        src/cpp/debugvisitor.cpp \
index 0432cfa..fc35456 100644 (file)
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="includes\debugvisitor.hxx" />
+    <ClInclude Include="includes\deserializervisitor.hxx" />
     <ClInclude Include="includes\dummyvisitor.hxx" />
     <ClInclude Include="includes\dynlib_ast_tools.hxx" />
     <ClInclude Include="includes\execvisitor.hxx" />
     <ClInclude Include="includes\printvisitor.hxx" />
     <ClInclude Include="includes\runvisitor.hxx" />
     <ClInclude Include="includes\scilabexception.hxx" />
+    <ClInclude Include="includes\serializervisitor.hxx" />
     <ClInclude Include="includes\shortcutvisitor.hxx" />
     <ClInclude Include="includes\stepvisitor.hxx" />
     <ClInclude Include="includes\timedvisitor.hxx" />
index a7f99be..50b6997 100644 (file)
     <ClInclude Include="includes\visitor_common.hxx">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="includes\deserializervisitor.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
+    <ClInclude Include="includes\serializervisitor.hxx">
+      <Filter>Header Files</Filter>
+    </ClInclude>
   </ItemGroup>
 </Project>
\ No newline at end of file
diff --git a/scilab/modules/ast/includes/deserializervisitor.hxx b/scilab/modules/ast/includes/deserializervisitor.hxx
new file mode 100644 (file)
index 0000000..658ce16
--- /dev/null
@@ -0,0 +1,596 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2012-2013 - OCAMLPRO INRIA - Fabrice LE FESSANT
+ *  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
+ *
+ */
+#ifndef __DESERIALIZER_HXX__
+#define __DESERIALIZER_HXX__
+
+#include <list>
+#include <all.hxx>
+
+namespace ast
+{
+class DeserializeVisitor
+{
+private :
+
+    unsigned char *initial_buf;
+    unsigned char *buf;
+
+
+    unsigned int get_uint8(void)
+    {
+        return *buf++;
+    }
+
+    unsigned int get_uint32(void)
+    {
+        unsigned int c0 = get_uint8();
+        unsigned int c1 = get_uint8();
+        unsigned int c2 = get_uint8();
+        unsigned int c3 = get_uint8();
+        return c0 + ((c1 + ((c2 + (c3 << 8)) << 8 )) << 8 );
+    }
+
+    unsigned long long get_uint64(void)
+    {
+        unsigned long long c0 = get_uint32();
+        unsigned long long c1 = get_uint32();
+        return c0 + (c1 << 32 );
+    }
+
+    int get_int32(void)
+    {
+        return (int)get_uint32();
+    }
+
+    bool get_bool(void)
+    {
+        return get_uint8() == 1;
+    }
+
+    Location *get_location(void)
+    {
+        Location *loc = new Location();
+        loc->first_line = get_uint32();
+        loc->first_column = get_uint32();
+        loc->last_line = get_uint32();
+        loc->last_column = get_uint32();
+        return loc;
+    }
+
+    std::list<Exp*>* get_exps(void)
+    {
+        int nitems = get_uint32();
+        std::list<Exp*> *list = new  std::list<Exp*>;
+        for (int i = 0; i < nitems; i++)
+        {
+            Exp* exp = get_exp();
+            list->push_back(exp);
+        }
+        return list;
+    }
+
+    std::list<MatrixLineExp*>* get_MatrixLines(void)
+    {
+        int nitems = get_uint32();
+        std::list<MatrixLineExp*> *list = new  std::list<MatrixLineExp*>;
+        for (int i = 0; i < nitems; i++)
+        {
+            Location *line_loc = get_location();
+            std::list<Exp*>* columns = get_exps();
+            MatrixLineExp* line = new MatrixLineExp(*line_loc, * columns);
+            list->push_back(line);
+        }
+        return list;
+    }
+
+    std::list<Var*>* get_vars(void)
+    {
+        int nitems = get_uint32();
+        std::list<Var*> *list = new  std::list<Var*>;
+        for (int i = 0; i < nitems; i++)
+        {
+            Var* var = dynamic_cast<Var*>(get_exp());
+            list->push_back(var);
+        }
+        return list;
+    }
+
+    OpExp::Oper get_OpExp_Oper(void)
+    {
+        int code = get_uint8();
+        switch (code)
+        {
+            case 1 :
+                return  OpExp::plus;
+            case 2 :
+                return  OpExp::minus;
+            case 3 :
+                return  OpExp::times;
+            case 4 :
+                return  OpExp::rdivide;
+            case 5 :
+                return  OpExp::ldivide;
+            case 6 :
+                return  OpExp::power;
+
+            case 7 :
+                return  OpExp::dottimes;
+            case 8 :
+                return  OpExp::dotrdivide;
+            case 9 :
+                return  OpExp::dotldivide;
+            case 10 :
+                return  OpExp::dotpower;
+
+            case 11 :
+                return  OpExp::krontimes;
+            case 12 :
+                return  OpExp::kronrdivide;
+            case 13 :
+                return  OpExp::kronldivide;
+
+            case 14 :
+                return  OpExp::controltimes;
+            case 15 :
+                return  OpExp::controlrdivide;
+            case 16 :
+                return  OpExp::controlldivide;
+
+            case 17 :
+                return  OpExp::eq;
+            case 18 :
+                return  OpExp::ne;
+            case 19 :
+                return  OpExp::lt;
+            case 20 :
+                return  OpExp::le;
+            case 21 :
+                return  OpExp::gt;
+            case 22 :
+                return  OpExp::ge;
+
+            case 23 :
+                return  OpExp::unaryMinus;
+
+            case 24 :
+                return  OpExp::logicalAnd;
+            case 25 :
+                return  OpExp::logicalOr;
+            case 26 :
+                return  OpExp::logicalShortCutAnd;
+            case 27 :
+                return  OpExp::logicalShortCutOr;
+        }
+        std::cerr << "Unknown get_OpExp_Oper code " << code << std::endl;
+        exit(2);
+    }
+
+    IntExp::Prec get_IntExp_Prec(void)
+    {
+        int code = get_uint8();
+        switch (code)
+        {
+            case 1:
+                return IntExp::_8_;
+            case 2:
+                return IntExp::_16_;
+            case 3:
+                return IntExp::_32_;
+            case 4:
+                return IntExp::_64_;
+        }
+        std::cerr << "Unknown get_IntExp_Prec code " << code << std::endl;
+        exit(2);
+    }
+
+    TransposeExp::Kind get_TransposeExp_Kind(void)
+    {
+        int code = get_uint8();
+        switch (code)
+        {
+            case 1 :
+                return TransposeExp::_Conjugate_;
+            case 2 :
+                return TransposeExp::_NonConjugate_;
+        }
+        std::cerr << "Unknown get_TransposeExp_Kind code " << code << std::endl;
+        exit(2);
+    }
+
+    std::wstring* get_wstring(void)
+    {
+        unsigned int size = get_uint32();
+        wchar_t* ss = (wchar_t*)buf;
+        std::wstring* s = new std::wstring(ss, size / sizeof(wchar_t));
+        buf += size;
+        return s;
+    }
+
+    symbol::Symbol* get_Symbol(void)
+    {
+        std::wstring* s = get_wstring();
+        return new symbol::Symbol(*s);
+    }
+
+    double get_double(void)
+    {
+        double d = *(double*)buf;
+        buf += 8;
+        return d;
+    }
+
+    VarDec* get_VarDec(Location *vardec_location)
+    {
+        symbol::Symbol *name = get_Symbol();
+        Exp *init = get_exp();
+        VarDec* vardec = new VarDec(*vardec_location, *name, *init);
+        return vardec;
+    }
+
+
+    Exp* get_exp(void)
+    {
+        Exp* exp;
+        int code = get_uint8();
+        long long nodeNumber = get_uint64();
+        Location *loc = get_location();
+        bool is_verbose = get_bool();
+        int is_break = get_bool();
+        int is_breakable = get_bool();
+        int is_return = get_bool();
+        int is_returnable = get_bool();
+        int is_continue = get_bool();
+        int is_continuable = get_bool();
+
+
+        switch (code)
+        {
+            case 1:
+            {
+                std::list<Exp *>* l_body = get_exps();
+                exp = new SeqExp(*loc, *l_body);
+                break;
+            }
+            case 2:
+            {
+                std::wstring* s = get_wstring();
+                exp = new StringExp(*loc, *s);
+                break;
+            }
+            case 3:
+            {
+                std::wstring* s = get_wstring();
+                exp = new CommentExp(*loc, s);
+                break;
+            }
+            case 6:
+            {
+                double d = get_double();
+                exp = new DoubleExp(*loc, d);
+                break;
+            }
+            case 7:
+            {
+                bool b = get_bool();
+                exp = new BoolExp(*loc, b);
+                break;
+            }
+            case 8:
+            {
+                exp = new NilExp(*loc);
+                break;
+            }
+            case 9:
+            {
+                symbol::Symbol *name = get_Symbol();
+                exp = new SimpleVar(*loc, *name);
+                break;
+            }
+            case 10:
+            {
+                exp = new ColonVar(*loc);
+                break;
+            }
+            case 11:
+            {
+                exp = new DollarVar(*loc);
+                break;
+            }
+            case 12:
+            {
+                std::list<Var*>* vars = get_vars();
+                exp = new ArrayListVar(*loc, *vars);
+                break;
+            }
+            case 13:
+            {
+                Exp *head = get_exp();
+                Exp *tail = get_exp();
+                exp = new FieldExp(*loc, *head, *tail);
+                break;
+            }
+            case 14:
+            {
+                bool has_else = get_bool();
+                Exp* test = get_exp();
+                Exp* _then = get_exp();
+                IfExp* ifexp;
+                if ( has_else )
+                {
+                    Exp* _else = get_exp();
+                    ifexp = new IfExp(*loc, *test, *_then, *_else);
+                }
+                else
+                {
+                    ifexp = new IfExp(*loc, *test, *_then);
+                }
+                exp = ifexp;
+                break;
+            }
+            case 15:
+            {
+                Location *try_location = get_location();
+                Location *catch_location = get_location();
+                std::list<Exp *>* try_exps = get_exps();
+                std::list<Exp *>* catch_exps = get_exps();
+                SeqExp *tryexp = new SeqExp(*try_location, *try_exps);
+                SeqExp *catchexp = new SeqExp(*catch_location, *catch_exps);
+                exp = new TryCatchExp(*loc, *tryexp, *catchexp);
+                break;
+            }
+            case 16:
+            {
+                Exp* test = get_exp();
+                Exp* body = get_exp();
+                exp = new WhileExp(*loc, *test, *body);
+                break;
+            }
+            case 17:
+            {
+                Location *vardec_location = get_location();
+                VarDec* vardec = get_VarDec(vardec_location);
+                Exp* body = get_exp();
+                exp = new ForExp(*loc, *vardec, *body);
+                break;
+            }
+            case 18:
+            {
+                exp = new BreakExp(*loc);
+                break;
+            }
+            case 19:
+            {
+                exp = new ContinueExp(*loc);
+                break;
+            }
+            case 20:
+            {
+                bool is_global = get_bool();
+                if ( is_global )
+                {
+                    exp = new ReturnExp(*loc);
+                }
+                else
+                {
+                    Exp* returnExp_exp = get_exp();
+                    exp = new ReturnExp(*loc, returnExp_exp);
+                }
+                break;
+            }
+            case 21:
+            {
+                bool has_default = get_bool();
+                SeqExp * default_case = NULL;
+                if ( has_default )
+                {
+                    Location *default_case_location = get_location();
+                    std::list<Exp *>* default_case_exps = get_exps();
+                    default_case = new SeqExp(*default_case_location,
+                                              *default_case_exps);
+                }
+                Exp* select = get_exp();
+
+                int nitems = get_uint32();
+                std::list<CaseExp*> *cases = new  std::list<CaseExp*>;
+                for (int i = 0; i < nitems; i++)
+                {
+
+                    Location *case_location = get_location();
+                    Location *body_location = get_location();
+                    Exp* test = get_exp();
+                    std::list<Exp *>* body_exps = get_exps();
+                    SeqExp *body = new SeqExp(*body_location,  *body_exps);
+
+                    CaseExp* _case = new CaseExp(*case_location, *test, *body);
+                    cases->push_back(_case);
+                }
+
+
+                if ( has_default )
+                {
+                    exp = new SelectExp(*loc, *select, *cases, *default_case);
+                }
+                else
+                {
+                    exp = new SelectExp(*loc, *select, *cases);
+                }
+                break;
+            }
+            /* SHOULD NEVER HAPPEN
+            case 22: {
+            exp = new CaseExp(*loc);
+            break;
+            }
+            */
+            case 23:
+            {
+                std::list<MatrixLineExp *>* lines = get_MatrixLines();
+                exp = new CellExp(*loc, *lines);
+                break;
+            }
+            case 24:
+            {
+                std::list<Exp *>* exps = get_exps();
+                exp = new ArrayListExp(*loc, *exps);
+                break;
+            }
+            case 25:
+            {
+                std::list<Exp *>* exps = get_exps();
+                exp = new AssignListExp(*loc, *exps);
+                break;
+            }
+            case 26:
+            {
+                Exp* notexp = get_exp();
+                exp = new NotExp(*loc, *notexp);
+                break;
+            }
+            case 27:
+            {
+                TransposeExp::Kind kind = get_TransposeExp_Kind();
+                Exp* _exp = get_exp();
+                exp = new TransposeExp(*loc, *_exp, kind);
+                break;
+            }
+            case 28:
+            {
+                exp = get_VarDec(loc);
+                break;
+            }
+            case 29:
+            {
+                symbol::Symbol* name = get_Symbol();
+                Location *args_loc = get_location();
+                Location *returns_loc = get_location();
+                Exp* body = get_exp();
+                std::list <Var*>* args_list = get_vars();
+                std::list <Var*>* returns_list = get_vars();
+                ArrayListVar *args = new ArrayListVar(*args_loc, *args_list);
+                ArrayListVar *returns = new ArrayListVar(*returns_loc, *returns_list);
+                exp = new FunctionDec(*loc, *name, *args, *returns, *body);
+                break;
+            }
+            case 30:
+            {
+                Exp* _start = get_exp();
+                Exp* _step = get_exp();
+                Exp* _end = get_exp();
+                exp = new ListExp(*loc, *_start, *_step, *_end);
+                break;
+            }
+            case 31:
+            {
+                Exp* _left = get_exp();
+                Exp* _right = get_exp();
+                exp = new AssignExp(*loc, *_left, *_right);
+                break;
+            }
+            case 32:
+            {
+                OpExp::Oper oper = get_OpExp_Oper();
+                Exp *left = get_exp();
+                Exp *right = get_exp();
+                OpExp *_opexp  = new OpExp(*loc, *left, oper, *right);
+                exp = _opexp;
+                break;
+            }
+            case 33:
+            {
+                OpExp::Oper oper = get_OpExp_Oper();
+                Exp *left = get_exp();
+                Exp *right = get_exp();
+                LogicalOpExp *_opexp  =
+                    new LogicalOpExp(*loc, *left, oper, *right);
+                exp = _opexp;
+                break;
+            }
+            case 34:
+            {
+                std::list<MatrixLineExp *>* lines = get_MatrixLines();
+                exp = new MatrixExp(*loc, *lines);
+                break;
+            }
+            case 35:
+            {
+                Exp* name = get_exp();
+                std::list<Exp *> * args = get_exps();
+                exp = new CallExp(*loc, *name, *args);
+                break;
+            }
+            /* SHOULD NEVER HAPPEN
+            case 36: {
+            exp = new MatrixLineExp(*loc);
+            break;
+            }
+            */
+            case 37:
+            {
+                Exp* name = get_exp();
+                std::list<Exp *>* args = get_exps();
+                exp = new CellCallExp(*loc, *name, *args);
+                break;
+            }
+            default:
+                std::cerr << "Unknown code " << code << std::endl;
+                exit(2);
+        }
+
+        exp->set_verbose(is_verbose);
+        if (is_break)
+        {
+            exp->break_set();
+        }
+        if (is_breakable)
+        {
+            exp->breakable_set();
+        }
+        if (is_return)
+        {
+            exp->return_set();
+        }
+        if (is_returnable)
+        {
+            exp->returnable_set();
+        }
+        if (is_continue)
+        {
+            exp->continue_set();
+        }
+        if (is_continuable)
+        {
+            exp->continuable_set();
+        }
+        exp->nodeNumber_set(nodeNumber);
+
+        return exp;
+    }
+
+public :
+    DeserializeVisitor(unsigned char* buffer) : initial_buf(buffer), buf(buffer) {};
+
+    Exp* deserialize()
+    {
+        unsigned int size = get_uint32();
+        unsigned char scilabVersion[4];
+
+        scilabVersion[0] = get_uint8();
+        scilabVersion[1] = get_uint8();
+        scilabVersion[2] = get_uint8();
+        scilabVersion[3] = get_uint8();
+
+        return get_exp();
+    }
+};
+}
+#endif /* !__DESERIALIZER_HXX__  */
\ No newline at end of file
index 9f72f77..ca36542 100644 (file)
@@ -101,6 +101,10 @@ public:
         return nodeNumber;
     }
 
+    void nodeNumber_set(long long _nodeNumber)
+    {
+        nodeNumber = _nodeNumber;
+    }
 
 private:
     /** \brief Construct an Ast by copy. */
index 0f3af48..74a4c9d 100644 (file)
@@ -52,43 +52,6 @@ public:
     /** \} */
 
     virtual Exp* clone() = 0;
-    //{
-    //    Location* newloc = const_cast<Location*>(&location_get())->clone();
-    //    Exp* exp = new Exp(location_get());
-    //    exp->set_verbose(is_verbose());
-
-    //    if(is_break())
-    //    {
-    //        exp->break_set();
-    //    }
-
-    //    if(is_breakable())
-    //    {
-    //        exp->breakable_set();
-    //    }
-
-    //    if(is_return())
-    //    {
-    //        exp->return_set();
-    //    }
-
-    //    if(is_returnable())
-    //    {
-    //        exp->returnable_set();
-    //    }
-
-    //    if(is_continue())
-    //    {
-    //        exp->continue_set();
-    //    }
-
-    //    if(is_continuable())
-    //    {
-    //        exp->continuable_set();
-    //    }
-
-    //    return exp;
-    //}
 
 public:
     /** \brief Return if an expression should be displayed or not. */
diff --git a/scilab/modules/ast/includes/serializervisitor.hxx b/scilab/modules/ast/includes/serializervisitor.hxx
new file mode 100644 (file)
index 0000000..d7ead44
--- /dev/null
@@ -0,0 +1,582 @@
+/*
+ *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ *  Copyright (C) 2012-2013 - OCAMLPRO INRIA - Fabrice LE FESSANT
+ *  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
+ *
+ */
+
+#ifndef __SERIALIZER_HXX__
+#define __SERIALIZER_HXX__
+
+#include "dummyvisitor.hxx"
+#include "deserializervisitor.hxx"
+#include "timer.hxx"
+#include "version.h"
+
+#define FAGMENT_SIZE 65536
+
+namespace ast
+{
+class SerializeVisitor : public DummyVisitor
+{
+private :
+    unsigned char *buf;
+    int buflen;
+    int bufsize;
+    ast::Exp* ast;
+
+    unsigned char* get_buf(void)
+    {
+        need(1);
+        set_uint32(0, buflen);
+        //add scilab version
+        add_version();
+        return buf;
+    }
+
+    void add_version()
+    {
+        set_byte(4, (unsigned char)SCI_VERSION_MAJOR);
+        set_byte(5, (unsigned char)SCI_VERSION_MINOR);
+        set_byte(6, (unsigned char)SCI_VERSION_MAINTENANCE);
+        set_byte(7, (unsigned char)0);
+    }
+
+    void add_location(const Location& loc)
+    {
+        add_uint32(loc.first_line);
+        add_uint32(loc.first_column);
+        add_uint32(loc.last_line);
+        add_uint32(loc.last_column);
+    }
+    void add_ast(unsigned int code, const ast::Exp& e)
+    {
+        Location loc = e.location_get();
+        add_uint8(code);
+        add_uint64(e.nodeNumber_get());
+        add_location(e.location_get());
+        add_uint8(e.is_verbose());
+        add_uint8(e.is_break());
+        add_uint8(e.is_breakable());
+        add_uint8(e.is_return());
+        add_uint8(e.is_returnable());
+        add_uint8(e.is_continue());
+        add_uint8(e.is_continuable());
+    }
+
+    /* ensure that we have [size] bytes in the buffer */
+    void need(int size)
+    {
+        if ( bufsize - buflen < size )
+        {
+            bufsize = 2 * bufsize + size + FAGMENT_SIZE;
+            unsigned char *newbuf = (unsigned char*) malloc(bufsize * sizeof(unsigned char));
+            if ( buflen > 0 )
+            {
+                memcpy(newbuf, buf, buflen);
+            }
+            if ( buf != NULL)
+            {
+                free(buf);
+            }
+            else
+            {
+                buflen = 8;    /* space for final size of buf ( 4 bytes ) + scilab version ( 4 bytes )*/
+            }
+            buf = newbuf;
+        }
+    }
+
+    void add_byte(unsigned char n)
+    {
+        buf[buflen++] = n;
+    }
+
+    void add_uint8(unsigned char n)
+    {
+        need(1);
+        add_byte(n);
+    }
+
+    void add_uint32(unsigned int n)
+    {
+        need(4);
+        add_byte(n & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+    }
+
+    void add_uint64(unsigned long long n)
+    {
+        need(8);
+        add_byte(n & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+        add_byte((n >>= 8) & 0xff);
+    }
+
+    void add_double(double d)
+    {
+        need(8);
+        *(double*)(buf + buflen) = d;
+        buflen += 8;
+    }
+
+    void set_uint32(unsigned int pos, unsigned int n)
+    {
+        buf[pos++] = (n & 0xff);
+        n >>= 8;
+        buf[pos++] = (n & 0xff);
+        n >>= 8;
+        buf[pos++] = (n & 0xff);
+        n >>= 8;
+        buf[pos++] = (n & 0xff);
+    }
+
+    void set_byte(unsigned int pos, unsigned char n)
+    {
+        buf[pos] = n;
+    }
+
+    void add_wstring(const std::wstring &w)
+    {
+        int size = (int)w.size();
+        const wchar_t *c_str = w.c_str();
+        int final_size = size * sizeof(wchar_t);
+        add_uint32(final_size);
+        need(final_size);
+        memcpy(buf + buflen, c_str, final_size);
+        buflen += final_size;
+    }
+
+
+    void add_exps(const std::list<Exp *> exps)
+    {
+        add_uint32((unsigned int)exps.size());
+        std::list<Exp *>::const_iterator it;
+        for (it = exps.begin() ; it != exps.end() ; it++)
+        {
+            (*it)->accept(*this);
+        }
+    }
+
+    void add_vars(const ast::ArrayListVar& var)
+    {
+        add_uint32((unsigned int)var.vars_get().size());
+        std::list<Var *>::const_iterator it;
+        for (it = var.vars_get().begin() ; it != var.vars_get().end() ; it++)
+        {
+            (*it)->accept(*this);
+        }
+    }
+
+    void add_Symbol(const symbol::Symbol& e)
+    {
+        add_wstring(e.name_get());
+    }
+
+    void add_exp(const ast::Exp* e)
+    {
+        e->accept(*this);
+    }
+
+    void add_exp(const ast::Exp& e)
+    {
+        e.accept(*this);
+    }
+
+    void add_OpExp_Oper(const ast::OpExp::Oper oper)
+    {
+        int code = 253;
+        switch (oper)
+        {
+            case ast::OpExp::plus :
+                code = (1);
+                break;
+            case ast::OpExp::minus:
+                code = (2);
+                break;
+            case ast::OpExp::times:
+                code = (3);
+                break;
+            case ast::OpExp::rdivide:
+                code = (4);
+                break;
+            case ast::OpExp::ldivide:
+                code = (5);
+                break;
+            case ast::OpExp::power:
+                code = (6);
+                break;
+
+            case ast::OpExp::dottimes:
+                code = (7);
+                break;
+            case ast::OpExp::dotrdivide:
+                code = (8);
+                break;
+            case ast::OpExp::dotldivide:
+                code = (9);
+                break;
+            case ast::OpExp::dotpower:
+                code = (10);
+                break;
+
+            case ast::OpExp::krontimes:
+                code = (11);
+                break;
+            case ast::OpExp::kronrdivide:
+                code = (12);
+                break;
+            case ast::OpExp::kronldivide:
+                code = (13);
+                break;
+
+            case ast::OpExp::controltimes:
+                code = (14);
+                break;
+            case ast::OpExp::controlrdivide:
+                code = (15);
+                break;
+            case ast::OpExp::controlldivide:
+                code = (16);
+                break;
+
+            case ast::OpExp::eq:
+                code = (17);
+                break;
+            case ast::OpExp::ne:
+                code = (18);
+                break;
+            case ast::OpExp::lt:
+                code = (19);
+                break;
+            case ast::OpExp::le:
+                code = (20);
+                break;
+            case ast::OpExp::gt:
+                code = (21);
+                break;
+            case ast::OpExp::ge:
+                code = (22);
+                break;
+
+            case ast::OpExp::unaryMinus:
+                code = (23);
+                break;
+
+            case ast::OpExp::logicalAnd:
+                code = (24);
+                break;
+            case ast::OpExp::logicalOr:
+                code = (25);
+                break;
+            case ast::OpExp::logicalShortCutAnd:
+                code = (26);
+                break;
+            case ast::OpExp::logicalShortCutOr:
+                code = (27);
+                break;
+        }
+        add_uint8(code);
+    }
+
+    void add_IntExp_Prec(const ast::IntExp::Prec prec)
+    {
+        int code = 251;
+        switch (prec)
+        {
+            case ast::IntExp::_8_ :
+                code = (1);
+                break;
+            case ast::IntExp::_16_:
+                code = (2);
+                break;
+            case ast::IntExp::_32_:
+                code = (3);
+                break;
+            case ast::IntExp::_64_:
+                code = (4);
+                break;
+        }
+        add_uint8(code);
+    }
+
+    void add_TransposeExp_Kind(const ast::TransposeExp::Kind kind)
+    {
+        int code = 249;
+        switch (kind)
+        {
+            case ast::TransposeExp::_Conjugate_ :
+                code = (1);
+                break;
+            case ast::TransposeExp::_NonConjugate_:
+                code = (2);
+                break;
+        }
+        add_uint8(code);
+    }
+
+    void add_bool(bool b)
+    {
+        add_uint8(b);
+    }
+
+    void add_varDec(const ast::VarDec& varDec)
+    {
+        add_Symbol(varDec.name_get());
+        add_exp(varDec.init_get());
+    }
+
+    void add_MatrixLines(const  std::list<ast::MatrixLineExp*> *lines)
+    {
+        add_uint32((unsigned int)lines->size());
+        std::list<MatrixLineExp *>::const_iterator it;
+        for (it = lines->begin() ; it != lines->end() ; it++)
+        {
+            add_location((*it)->location_get());
+            add_exps((*it)->columns_get());
+        }
+    }
+
+    virtual void visit (const SeqExp &e)  /* done */
+    {
+        add_ast(1, e);
+        add_exps(e.exps_get());
+    }
+    void visit(const StringExp& e)  /* done */
+    {
+        add_ast(2, e);
+        add_wstring(e.value_get());
+    }
+    void visit(const CommentExp& e)  /* done */
+    {
+        add_ast(3, e);
+        add_wstring(e.comment_get());
+    }
+    void visit(const DoubleExp& e)  /* done */
+    {
+        add_ast(6, e);
+        add_double(e.value_get());
+    }
+    void visit(const BoolExp& e)  /* done */
+    {
+        add_ast(7, e);
+        add_bool(e.value_get());
+    }
+    void visit(const NilExp& e)  /* done */
+    {
+        add_ast(8, e);
+    }
+    void visit(const SimpleVar& e)  /* done */
+    {
+        add_ast(9, e);
+        add_Symbol(e.name_get());
+    }
+    void visit(const ColonVar& e)  /* done */
+    {
+        add_ast(10, e);
+    }
+    void visit(const DollarVar& e)  /* done */
+    {
+        add_ast(11, e);
+    }
+    void visit(const ArrayListVar& e)  /* done */
+    {
+        add_ast(12, e);
+        add_vars(e);
+    }
+    void visit(const FieldExp& e)  /* done */
+    {
+        add_ast(13, e);
+        add_exp(e.head_get());
+        add_exp(e.tail_get());
+    }
+    void visit(const IfExp& e)  /* done */
+    {
+        add_ast(14, e);
+        bool has_else = e.has_else();
+        add_bool(has_else);
+        add_exp(& e.test_get());
+        add_exp(& e.then_get());
+        if ( has_else )
+        {
+            add_exp(& e.else_get());
+        }
+    }
+    void visit(const TryCatchExp& e)  /* done */
+    {
+        add_ast(15, e);
+        add_location(e.try_get().location_get());
+        add_location(e.catch_get().location_get());
+        add_exps(e.try_get().exps_get());
+        add_exps(e.catch_get().exps_get());
+    }
+    void visit(const WhileExp& e)  /* done */
+    {
+        add_ast(16, e);
+        add_exp(& e.test_get());
+        add_exp(& e.body_get());
+    }
+    void visit(const ForExp& e)   /* done */
+    {
+        add_ast(17, e);
+        add_location(e.vardec_get().location_get());
+        add_varDec(e.vardec_get());
+        add_exp(& e.body_get());
+    }
+    void visit(const BreakExp& e)  /* done */
+    {
+        add_ast(18, e);
+    }
+    void visit(const ContinueExp& e)  /* done */
+    {
+        add_ast(19, e);
+    }
+    void visit(const ReturnExp& e)  /* done */
+    {
+        add_ast(20, e);
+        bool is_global = e.is_global();
+        add_bool(is_global);
+        if ( !is_global ) /* otherwise exp is NULL */
+        {
+            add_exp(& e.exp_get());
+        }
+    }
+    void visit(const SelectExp& e)
+    {
+        add_ast(21, e);
+        ast::SeqExp *default_case = e.default_case_get();
+        bool has_default = default_case != NULL;
+        add_bool( has_default );
+        if ( has_default )
+        {
+            add_location(default_case->location_get());
+            add_exps(default_case->exps_get());
+        }
+        add_exp(e.select_get());
+
+        add_uint32((unsigned int)e.cases_get()->size());
+        cases_t::const_iterator it;
+        for (it = e.cases_get()->begin() ; it != e.cases_get()->end() ; it++)
+        {
+            const ast::CaseExp *ce = *it;
+            add_location(ce->location_get() );
+            add_location(ce->body_get()->location_get() );
+            add_exp(ce->test_get());
+            add_exps(ce->body_get()->exps_get() );
+        }
+    }
+    void visit(const CellExp& e)  /* done */
+    {
+        add_ast(23, e);
+        add_MatrixLines(& e.lines_get());
+    }
+    void visit(const ArrayListExp& e)  /* done */
+    {
+        add_ast(24, e);
+        add_exps(e.exps_get());
+    }
+    void visit(const AssignListExp& e)  /* done */
+    {
+        add_ast(25, e);
+        add_exps(e.exps_get());
+    }
+    void visit(const NotExp& e)  /* done */
+    {
+        add_ast(26, e);
+        add_exp(e.exp_get() );
+    }
+    void visit(const TransposeExp& e)  /* done */
+    {
+        add_ast(27, e);
+        add_TransposeExp_Kind(e.conjugate_get());
+        add_exp(e.exp_get());
+    }
+    void visit(const VarDec& e)
+    {
+        add_ast(28, e);
+        add_varDec(e);
+    }
+    void visit(const FunctionDec& e)  /* done */
+    {
+        add_ast(29, e);
+        add_Symbol(e.name_get());
+        add_location(e.args_get().location_get());
+        add_location(e.returns_get().location_get());
+        add_exp(e.body_get());
+        add_vars(e.args_get());
+        add_vars(e.returns_get());
+    }
+    void visit(const ListExp& e)  /* done */
+    {
+        add_ast(30, e);
+        add_exp(e.start_get() );
+        add_exp(e.step_get() );
+        add_exp(e.end_get() );
+    }
+    void visit(const AssignExp& e)
+    {
+        add_ast(31, e);
+        add_exp(e.left_exp_get());
+        add_exp(e.right_exp_get());
+    }
+    void visit(const OpExp& e)  /* done */
+    {
+        add_ast(32, e);
+        add_OpExp_Oper(e.oper_get());
+        e.left_get().accept(*this);
+        e.right_get().accept(*this);
+    }
+    void visit(const LogicalOpExp& e)  /* done */
+    {
+        add_ast(33, e);
+        add_OpExp_Oper(e.oper_get());
+        e.left_get().accept(*this);
+        e.right_get().accept(*this);
+    }
+    void visit(const MatrixExp& e) /* done */
+    {
+        add_ast(34, e);
+        add_MatrixLines(& e.lines_get());
+    }
+    void visit(const CallExp& e)  /* done */
+    {
+        add_ast(35, e);
+        add_exp( e.name_get());
+        add_exps(e.args_get());
+    }
+    void visit(const MatrixLineExp& e)  /* SHOULD NEVER HAPPEN */
+    {
+        add_ast(36, e);
+    }
+    void visit(const CellCallExp& e)  /* done */
+    {
+        add_ast(37, e);
+        add_exp( e.name_get());
+        add_exps(e.args_get());
+    }
+
+public :
+    SerializeVisitor(ast::Exp* _ast) : ast(_ast), buf(NULL), buflen(0), bufsize(0) {}
+
+    unsigned char* serialize()
+    {
+        ast->accept(*this);
+        return get_buf();
+    }
+};
+}
+
+#endif /* !__SERIALIZER_HXX__ */
\ No newline at end of file
index 9856367..d1600e9 100644 (file)
@@ -13,6 +13,9 @@
 #ifndef AST_VISITOR_COMMON_HXX
 #define AST_VISITOR_COMMON_HXX
 
+
+#define ENABLE_EXTERNAL_TYPER
+
 #include "internal.hxx"
 #include "struct.hxx"
 #include "list.hxx"
@@ -61,5 +64,6 @@ EXTERN_AST void callOnPrompt(void);
 EXTERN_AST types::List* getPropertyTree(ast::Exp* e, types::List* pList);
 
 EXTERN_AST types::InternalType* insertionCall(const ast::Exp& e, types::typed_list* _pArgs, types::InternalType* _pVar, types::InternalType* _pInsert);
+EXTERN_AST ast::Exp* callTyper(ast::Exp* _tree, std::wstring _msg = std::wstring(L""));
 
 #endif //!AST_VISITOR_COMMON_HXX
index ce3b495..4a57c05 100644 (file)
@@ -20,6 +20,8 @@
 #include "struct.hxx"
 #include "context.hxx"
 #include "execvisitor.hxx"
+#include "serializervisitor.hxx"
+#include "deserializervisitor.hxx"
 
 #include "alltypes.hxx"
 
@@ -2091,3 +2093,52 @@ List* getPropertyTree(Exp* e, List* pList)
 
     return pList;
 }
+
+ast::Exp* callTyper(ast::Exp* _tree, std::wstring _msg)
+{
+    ast::Exp* newTree = NULL;
+    unsigned char *newast = NULL;
+    ast::SerializeVisitor* s = new ast::SerializeVisitor(_tree);
+    ast::DeserializeVisitor* d = NULL;
+
+    if (_msg.empty())
+    {
+        unsigned char* astbin = s->serialize();
+        //call ocamlpro typer
+        //char *newast = ocamlpro_typer(astbin);
+        //free(astbin);
+
+        //for debug
+        newast = astbin;
+
+        d = new ast::DeserializeVisitor(newast);
+        newTree = d->deserialize();
+    }
+    else
+    {
+        std::wstring msgS(_msg + L" serialize");
+        std::wstring msgD(_msg + L" deserialize");
+
+        Timer timer;
+        timer.start();
+        unsigned char* astbin = s->serialize();
+        timer.check(msgS.c_str());
+
+        //call ocamlpro typer
+        //char *newast = ocamlpro_typer(astbin);
+        //free(astbin);
+
+        //for debug
+        newast = astbin;
+
+        timer.start();
+        d = new ast::DeserializeVisitor(newast);
+        newTree = d->deserialize();
+        timer.check(msgD.c_str());
+    }
+
+    free(newast);
+    delete s;
+    delete d;
+    return newTree;
+}
index a2ca07e..82be107 100644 (file)
@@ -32,6 +32,7 @@ typedef struct
     char* pstFile;
     char* pstExec;
     char* pstLang;
+    int iSerialize;
 } ScilabEngineInfo;
 
 ScilabEngineInfo* InitScilabEngineInfo();
index 5e752ac..64e8d4f 100644 (file)
@@ -48,7 +48,7 @@ void printAstTask(ast::Exp *tree, bool timed);
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp *tree, bool timed, bool ASTtimed, bool execVerbose);
+void execAstTask(ast::Exp *tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose);
 
 /*
 ** Exec Tree with original visitor ( without template )
@@ -68,6 +68,6 @@ void dumpStackTask(bool timed);
 ** Execute scilab.start
 **
 */
-void execScilabStartTask(void);
-void execScilabQuitTask(void);
+void execScilabStartTask(bool _bSerialize);
+void execScilabQuitTask(bool _bSerialize);
 #endif /* !__TASKS_HXX__ */
index 769b799..404ea1e 100644 (file)
@@ -89,12 +89,12 @@ public:
     // Start a timer.  If it is already running, let it continue running.
     // Print an optional message.
 
-    inline void start(const char* msg = 0)
+    inline void start(const std::wstring _msg = std::wstring(L""))
     {
         // Print an optional message, something like "Starting timer t";
-        if (msg)
+        if (_msg.empty() == false)
         {
-            std::cerr << msg << std::endl;
+            std::wcerr << _msg << std::endl;
         }
 #ifndef _MSC_VER
         // FIXME : Tonio
@@ -120,19 +120,19 @@ public:
     //===========================================================================
     // Print out an optional message followed by the current timer timing.
 
-    inline double check(const char* msg, bool _bRestart = false)
+    inline double check(const std::wstring _msg, bool _bRestart = false)
     {
         // Print an optional message, something like "Checking timer t";
         double t = elapsed_time();
-        if (msg)
+        if (_msg.empty() == false)
         {
-            std::cerr << "[" << msg << "]" << " : ";
+            std::wcerr << L"[" << _msg << L"]" << L" : ";
         }
-        std::cerr << "Elapsed time ["
-                  << std::setiosflags(std::ios::fixed)
-                  << std::setprecision(3)
-                  << t << "] milliseconds"
-                  << std::endl;
+        std::wcerr << L"Elapsed time ["
+                   << std::setiosflags(std::ios::fixed)
+                   << std::setprecision(3)
+                   << t << L"] milliseconds"
+                   << std::endl;
 
         if (_bRestart == true)
         {
@@ -148,7 +148,7 @@ public:
 // for an ostream 'os' and a timer 't'.  For example, "cout << t" will
 // print out the total amount of time 't' has been "running".
 
-inline std::ostream& operator<<(std::ostream& os, Timer& t)
+inline std::wostream& operator<<(std::wostream& os, Timer& t)
 {
     os << std::setprecision(3)
        << std::setiosflags(std::ios::fixed)
index 6e31880..15e67b7 100644 (file)
@@ -223,7 +223,7 @@ int StartScilabEngine(ScilabEngineInfo* _pSEI)
     //execute scilab.start
     if (_pSEI->iNoStart == 0)
     {
-        execScilabStartTask();
+        execScilabStartTask(_pSEI->iSerialize != 0);
     }
 
     int pause = 0;
@@ -315,7 +315,7 @@ void StopScilabEngine(ScilabEngineInfo* _pSEI)
     }
     else if (_pSEI->iNoStart == 0)
     {
-        execScilabQuitTask();
+        execScilabQuitTask(_pSEI->iSerialize != 0);
     }
 
 
@@ -402,7 +402,7 @@ static Parser::ControlStatus processCommand(ScilabEngineInfo* _pSEI)
             {
                 //before calling YaspReader, try to call %onprompt function
                 callOnPrompt();
-                execAstTask(parser->getTree(), _pSEI->iTimed != 0, _pSEI->iAstTimed != 0, _pSEI->iExecVerbose != 0);
+                execAstTask(parser->getTree(), _pSEI->iSerialize != 0, _pSEI->iTimed != 0, _pSEI->iAstTimed != 0, _pSEI->iExecVerbose != 0);
             }
 
             /*
index f964150..5d46dff 100644 (file)
@@ -19,7 +19,7 @@
 #include "timedvisitor.hxx"
 #include "debugvisitor.hxx"
 #include "stepvisitor.hxx"
-#include "configvariable.hxx"
+#include "visitor_common.hxx"
 
 #include "scilabWrite.hxx"
 #include "runner.hxx"
@@ -51,7 +51,7 @@ void parseFileTask(Parser *parser, bool timed, const wchar_t* file_name, const w
 
     if (timed)
     {
-        _timer.check("Parsing");
+        _timer.check(L"Parsing");
     }
 }
 
@@ -75,7 +75,7 @@ void parseCommandTask(Parser *parser, bool timed, wchar_t *command)
 
     if (timed && parser->getControlStatus() == Parser::AllControlClosed)
     {
-        _timer.check("Parsing");
+        _timer.check(L"Parsing");
     }
 }
 
@@ -99,7 +99,7 @@ void dumpAstTask(ast::Exp *tree, bool timed)
 
     if (timed)
     {
-        _timer.check("AST Dump");
+        _timer.check(L"AST Dump");
     }
 }
 
@@ -123,7 +123,7 @@ void printAstTask(ast::Exp *tree, bool timed)
 
     if (timed)
     {
-        _timer.check("Pretty Print");
+        _timer.check(L"Pretty Print");
     }
 }
 
@@ -133,7 +133,7 @@ void printAstTask(ast::Exp *tree, bool timed)
 **
 ** Execute the stored AST.
 */
-void execAstTask(ast::Exp* tree, bool timed, bool ASTtimed, bool execVerbose)
+void execAstTask(ast::Exp* tree, bool serialize, bool timed, bool ASTtimed, bool execVerbose)
 {
     if (tree == NULL)
     {
@@ -161,12 +161,31 @@ void execAstTask(ast::Exp* tree, bool timed, bool ASTtimed, bool execVerbose)
         exec = new ast::ExecVisitor();
     }
 
-    Runner::execAndWait(tree, exec);
-    //delete exec;
+    ast::Exp* newTree = NULL;
+    if (serialize)
+    {
+        if (timed)
+        {
+            newTree = callTyper(tree, L"tasks");
+        }
+        else
+        {
+            newTree = callTyper(tree);
+        }
+
+        delete tree;
+    }
+    else
+    {
+        newTree = tree;
+    }
+
+    Runner::execAndWait(newTree, exec);
+    //DO NOT DELETE tree or newTree, they was deleted by Runner or previously;
 
     if (timed)
     {
-        _timer.check("Execute AST");
+        _timer.check(L"Execute AST");
     }
 }
 
@@ -186,7 +205,7 @@ void dumpStackTask(bool timed)
 
     if (timed)
     {
-        _timer.check("Dumping Stack");
+        _timer.check(L"Dumping Stack");
     }
 }
 
@@ -194,7 +213,7 @@ void dumpStackTask(bool timed)
 ** Execute scilab.start
 **
 */
-void execScilabStartTask(void)
+void execScilabStartTask(bool _bSerialize)
 {
     Parser parse;
     wstring stSCI = ConfigVariable::getSCIPath();
@@ -209,14 +228,14 @@ void execScilabStartTask(void)
         return;
     }
 
-    execAstTask(parse.getTree(), false, false, false);
+    execAstTask(parse.getTree(), _bSerialize, false, false, false);
 }
 
 /*
 ** Execute scilab.quit
 **
 */
-void execScilabQuitTask(void)
+void execScilabQuitTask(bool _bSerialize)
 {
     Parser parse;
     wstring stSCI = ConfigVariable::getSCIPath();
@@ -231,7 +250,7 @@ void execScilabQuitTask(void)
         return;
     }
 
-    execAstTask(parse.getTree(), false, false, false);
+    execAstTask(parse.getTree(), _bSerialize, false, false, false);
 }
 
 
index 52fec06..32b253c 100644 (file)
 */
 
 #include <string.h>
+#include "functions_gw.hxx"
+
 #include "parser.hxx"
 #include "funcmanager.hxx"
 #include "context.hxx"
-#include "functions_gw.hxx"
 #include "execvisitor.hxx"
 #include "mutevisitor.hxx"
 #include "printvisitor.hxx"
+#include "visitor_common.hxx"
 #include "scilabWrite.hxx"
 #include "scilabexception.hxx"
 #include "configvariable.hxx"
@@ -151,7 +153,24 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
             return Function::Error;
         }
 
-        pExp = parser.getTree();
+        if (ConfigVariable::getSerialize())
+        {
+            ast::Exp* temp = parser.getTree();
+            if (ConfigVariable::getTimed())
+            {
+                pExp = callTyper(temp, L"exec");
+            }
+            else
+            {
+                pExp = callTyper(temp);
+            }
+
+            delete temp;
+        }
+        else
+        {
+            pExp = parser.getTree();
+        }
     }
     else if (in[0]->isMacro())
     {
@@ -435,7 +454,7 @@ types::Function::ReturnValue sci_exec(types::typed_list &in, int _iRetCount, typ
         ConfigVariable::setLastErrorCall();
     }
 
-    delete parser.getTree();
+    delete pExp;
     mclose(iID);
     file.close();
     FREE(pstFile);
index 290644b..1a9efbb 100644 (file)
@@ -16,6 +16,7 @@
 #include "execvisitor.hxx"
 #include "mutevisitor.hxx"
 #include "printvisitor.hxx"
+#include "visitor_common.hxx"
 #include "scilabWrite.hxx"
 #include "scilabexception.hxx"
 #include "configvariable.hxx"
@@ -158,7 +159,24 @@ Function::ReturnValue sci_execstr(types::typed_list &in, int _iRetCount, types::
         }
     }
 
-    pExp = parser.getTree();
+    if (ConfigVariable::getSerialize())
+    {
+        ast::Exp* temp = parser.getTree();
+        if (ConfigVariable::getTimed())
+        {
+            pExp = callTyper(temp, L"execstr");
+        }
+        else
+        {
+            pExp = callTyper(temp);
+        }
+
+        delete temp;
+    }
+    else
+    {
+        pExp = parser.getTree();
+    }
 
     if (pExp == NULL)
     {
@@ -382,31 +400,7 @@ Function::ReturnValue sci_execstr(types::typed_list &in, int _iRetCount, types::
         ConfigVariable::setLastErrorCall();
     }
 
-    delete parser.getTree();
+    delete pExp;
     return Function::OK;
 }
 /*--------------------------------------------------------------------------*/
-
-/*
-               catch(ScilabError se)
-               {
-            if(bErrCatch && bMute == true)
-            {
-                //set mode silent for errors
-                ConfigVariable::setPromptMode(-1);
-            }
-
-            //store message
-            Scierror(ConfigVariable::getLastErrorNumber(), "%s", ConfigVariable::getLastErrorMessage().c_str());
-            iErr = ConfigVariable::getLastErrorNumber();
-            if(bErrCatch == false)
-            {
-               delete parser.getTree();
-                           return Function::Error;
-            }
-            break;
-               }
-*/
-
-/*
-*/
index a20ca7f..5c2fb0b 100644 (file)
@@ -13,17 +13,7 @@ if (isdef("genlib") == %f) then
     exec(SCI+"/modules/functions/scripts/buildmacros/loadgenlib.sce");
 end
 //------------------------------------
-genlib("m2scilib","SCI/modules/m2sci/macros");
-//------------------------------------
-mprintf(gettext("-- Creation of [%s] (Macros) --\n"),"m2sci");
-//------------------------------------
-
-lines(0);
-CurrentDirectorym2sci = get_absolute_file_path("buildmacros.sce");
-macrosdirs            = ["kernel","percent","sci_files"];
-
-for i=1:size(macrosdirs,"*") do
-    exec(CurrentDirectorym2sci+"/"+macrosdirs(i)+"/buildmacros.sce");
-end
-
-clear my_script_path CurrentDirectorym2sci macrosdirs
+genlib("m2scilib","SCI/modules/m2sci/macros", %f,%t);
+genlib("m2scikernellib","SCI/modules/m2sci/macros/kernel",%f,%t);
+genlib("m2scipercentlib","SCI/modules/m2sci/macros/percent",%f,%t);
+genlib("m2scisci_fileslib","SCI/modules/m2sci/macros/sci_files",%f,%t);
index b237bc8..66e7eb4 100644 (file)
@@ -108,6 +108,12 @@ static int get_option(const int argc, char *argv[], ScilabEngineInfo* _pSEI)
         else if (!strcmp("--timed", argv[i]))
         {
             _pSEI->iTimed = 1;
+            ConfigVariable::setTimed(true);
+        }
+        else if (!strcmp("--serialize", argv[i]))
+        {
+            _pSEI->iSerialize = 1;
+            ConfigVariable::setSerialize(true);
         }
         else if (!strcmp("--AST-timed", argv[i]))
         {
index 2cbd80c..716f32e 100644 (file)
@@ -288,9 +288,15 @@ public :
     // Command Line Arguments
 private :
     static std::vector<std::wstring> m_Args;
+    static bool m_bTimed;
+    static bool m_bSerialize;
 public :
     static void setCommandLineArgs(int _iArgs, char** _pstArgs);
     static wchar_t** getCommandLineArgs(int* _piCount);
+    static bool getTimed();
+    static void setTimed(bool _bTimed);
+    static bool getSerialize();
+    static void setSerialize(bool _bSerialize);
 
     //schur function
 private :
index 57f8199..eed3d34 100644 (file)
@@ -760,6 +760,8 @@ std::list<ConfigVariable::EntryPointStr*>* ConfigVariable::getEntryPointList()
 
 // Command Line Arguments
 std::vector<std::wstring> ConfigVariable::m_Args;
+bool ConfigVariable::m_bTimed = false;
+bool ConfigVariable::m_bSerialize = false;
 
 void ConfigVariable::setCommandLineArgs(int _iArgs, char** _pstArgs)
 {
@@ -784,6 +786,26 @@ wchar_t** ConfigVariable::getCommandLineArgs(int* _piCount)
     return pwstArgs;
 }
 
+bool ConfigVariable::getTimed()
+{
+    return m_bTimed;
+}
+
+void ConfigVariable::setTimed(bool _bTimed)
+{
+    m_bTimed = _bTimed;
+}
+
+bool ConfigVariable::getSerialize()
+{
+    return m_bSerialize;
+}
+
+void ConfigVariable::setSerialize(bool _bSerialize)
+{
+    m_bSerialize = _bSerialize;
+}
+
 /*
 ** \}
 */