add runvisitor hierarchy
[scilab.git] / scilab / modules / abstractSyntaxTree / src / cpp / run / runvisitor.cpp
1 /*
2 *  Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 *  Copyright (C) 2008-2008 - DIGITEO - Bruno JOFRET
4 *
5 *  This file must be used under the terms of the CeCILL.
6 *  This source file is licensed as described in the file COPYING, which
7 *  you should have received as part of this distribution.  The terms
8 *  are also available at
9 *  http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10 *
11 */
12
13 #include <cstdio>
14 #include <numeric>
15 #include <iostream>
16 #include "stack-def.h"
17
18 #include "runvisitor.hxx"
19 #include "execvisitor.hxx"
20 #include "timedvisitor.hxx"
21 #include "shortcutvisitor.hxx"
22 #include "conditionvisitor.hxx"
23
24 #include "timer.hxx"
25 #include "localization.h"
26
27 #include "yaspio.hxx"
28 #include "context.hxx"
29
30 using std::string;
31
32 bool bConditionState(ast::ConditionVisitor *exec);
33
34 void vTransposeRealMatrix(
35                         double *_pdblRealIn,
36                         int _iRowsIn,                   int _iColsIn,
37                         double *_pdblRealOut);
38
39 void vTransposeComplexMatrix(
40                         double *_pdblRealIn,    double *_pdblImgIn,
41                         int _iRowsIn,                   int _iColsIn,
42                         double *_pdblRealOut,   double *_pdblImgOut, bool _bConjugate);
43
44 namespace ast
45 {
46         template class RunVisitorT<ExecVisitor>;
47         template class RunVisitorT<TimedVisitor>;
48
49         template <class T>
50         void RunVisitorT<T>::visitprivate(const MatrixLineExp &e)
51         {
52         /*
53                 All processes are done in MatrixExp
54         */
55         }
56
57         template <class T>
58         void RunVisitorT<T>::visitprivate(const CellExp &e)
59         {
60                 /*
61                         FIXME : container type
62                 */
63         }
64
65         /** \name Visit Constant Expressions nodes.
66         ** \{ */
67         template <class T>
68         void RunVisitorT<T>::visitprivate(const StringExp &e)
69         {
70                 String *psz = new String(e.value_get().c_str());
71                 result_set(psz);
72         }
73
74         template <class T>
75         void RunVisitorT<T>::visitprivate(const CommentExp &e)
76         {
77                 /*
78                 Nothing to do
79                 */
80         }
81
82         template <class T>
83         void RunVisitorT<T>::visitprivate(const IntExp  &e)
84         {
85                 /*
86                 Int does not exist, Int8 - 16 - 32 - 64 functions
87                 */
88         }
89
90         template <class T>
91         void RunVisitorT<T>::visitprivate(const FloatExp  &e)
92         {
93                 /*
94                 Float does not exist, float function
95                 */
96         }
97
98         template <class T>
99         void RunVisitorT<T>::visitprivate(const DoubleExp  &e)
100         {
101                 Double *pdbl = new Double(e.value_get());
102                 result_set(pdbl);
103         }
104
105         template <class T>
106         void RunVisitorT<T>::visitprivate(const BoolExp  &e)
107         {
108                 Bool *pb = new Bool(e.value_get());
109                 result_set(pb);
110         }
111
112         template <class T>
113         void RunVisitorT<T>::visitprivate(const NilExp &e)
114         {
115                 /*
116                 FIXME :
117                 */
118         }
119
120         template <class T>
121         void RunVisitorT<T>::visitprivate(const SimpleVar &e)
122         {
123                 InternalType *pI = symbol::Context::getInstance()->get(e.name_get());
124                 if(pI != NULL)
125                 {
126                         result_set(pI);
127                         if(pI != NULL && pI->getAsCallable() == false && e.is_verbose())
128                         {
129                           std::ostringstream ostr;
130                                 ostr << e.name_get() << " = " << "(" << pI->getRef() << ")"<< std::endl;
131                           ostr << std::endl;
132                           ostr << pI->toString(10,75) << std::endl;
133                           YaspWrite((char *) ostr.str().c_str());
134                         }
135                 }
136                 else
137                 {
138                         char szError[bsiz];
139 #ifdef _MSC_VER
140                         sprintf_s(szError, bsiz, _("Undefined variable: %s\n"), e.name_get().c_str());
141 #else
142                         sprintf(szError, _("Undefined variable: %s\n"), e.name_get().c_str());
143 #endif
144                         throw string(szError);
145                         //Err, SimpleVar doesn't exist in Scilab scopes.
146                 }
147         }
148
149         template <class T>
150         void RunVisitorT<T>::visitprivate(const ColonVar &e)
151         {
152                 int pRank[1] = {2};
153                 Double dblCoef(1,2);
154                 dblCoef.val_set(0, 0, 0);
155                 dblCoef.val_set(0, 1, 1);
156
157                 MatrixPoly *pVar        = new MatrixPoly("$", 1, 1, pRank);
158                 Poly *poPoly                    = pVar->poly_get(0,0);
159                 poPoly->coef_set(&dblCoef);
160
161                 ImplicitList *pIL = new ImplicitList();
162                 pIL->start_set(new Double(1));
163                 pIL->step_set(new Double(1));
164                 pIL->end_set(pVar);
165                 result_set(pIL);
166                 /*
167                 : = 1:$
168                 */
169         }
170
171         template <class T>
172         void RunVisitorT<T>::visitprivate(const DollarVar &e)
173         {
174                 int pRank[1] = {2};
175                 Double dblCoef(1,2);
176                 dblCoef.val_set(0, 0, 0);
177                 dblCoef.val_set(0, 1, 1);
178
179                 MatrixPoly *pVar        = new MatrixPoly("$", 1, 1, pRank);
180                 Poly *poPoly                    = pVar->poly_get(0,0);
181                 poPoly->coef_set(&dblCoef);
182                 result_set(pVar);
183         }
184
185         template <class T>
186         void RunVisitorT<T>::visitprivate(const ArrayListVar &e)
187         {
188                 /*
189
190                 */
191         }
192
193         template <class T>
194         void RunVisitorT<T>::visitprivate(const FieldExp &e)
195         {
196                 /*
197                 a.b
198                 */
199           ExecVisitor execHead;
200                 try
201                 {
202                   e.head_get()->accept(execHead);
203                 }
204                 catch (string sz) 
205                   {
206                     throw sz;
207                   } 
208                 if (execHead.result_get() != NULL && !execHead.result_get()->isStruct())
209                   {
210                     char szError[bsiz];
211 #ifdef _MSC_VER
212                     sprintf_s(szError, bsiz, _("Attempt to reference field of non-structure array.\n"));
213 #else
214                     sprintf(szError, _("Attempt to reference field of non-structure array.\n"));
215 #endif
216                     throw string(szError);
217                   }
218                 else
219                   {
220                     // Manage 3 cases
221                     // head.ID
222                     // head.variable
223                     // head.functionCall
224                     SimpleVar *psvRightMember = dynamic_cast<SimpleVar *>(const_cast<Exp *>(e.tail_get()));
225                     if (psvRightMember != NULL)
226                       {
227                         Struct* psValue = execHead.result_get()->getAsStruct();
228                         if ( psValue->exists(psvRightMember->name_get()) )
229                           {
230                             result_set(psValue->get(psvRightMember->name_get())->clone());
231                           }
232                         else 
233                           {
234                             char szError[bsiz];
235 #ifdef _MSC_VER
236                             sprintf_s(szError, bsiz, _("Unknown field : %s.\n"), psvRightMember->name_get().c_str());
237 #else
238                             sprintf(szError, _("Unknown field : %s.\n"), psvRightMember->name_get().c_str());
239 #endif
240                             throw string(szError);
241                           }
242                       }
243                     else
244                       {
245                         char szError[bsiz];
246 #ifdef _MSC_VER
247                         sprintf_s(szError, bsiz, _("/!\\ Unmanaged FieldExp.\n"));
248 #else
249                         sprintf(szError, _("/!\\ Unmanaged FieldExp.\n"));
250 #endif
251                         throw string(szError);
252                       }
253                   }
254         }
255
256         template <class T>
257         void RunVisitorT<T>::visitprivate(const CallExp &e)
258         {
259                 T execFunc;
260                 std::list<Exp *>::const_iterator        i;
261
262                 e.name_get().accept(execFunc);
263                 if(execFunc.result_get() != NULL && execFunc.result_get()->isCallable())
264                 {//function call
265                         Callable *pCall = execFunc.result_get()->getAsCallable();
266                         types::typed_list out;
267                         types::typed_list in;
268
269                         //get function arguments
270                         ExecVisitor *execVar = new ast::ExecVisitor[e.args_get().size()]();
271                         int j = 0;
272                         for (j = 0, i = e.args_get().begin (); i != e.args_get().end (); ++i,j++)
273                         {
274                                 (*i)->accept (execVar[j]);
275                                 if(execVar[j].result_get()->getType() == InternalType::RealImplicitList)
276                                 {
277                                         ImplicitList* pIL = execVar[j].result_get()->getAsImplicitList();
278                                         execVar[j].result_set(pIL->extract_matrix());
279                                         delete pIL;
280                                 }
281                                 
282                                 if(execVar[j].is_single_result())
283                                 {
284                                                 in.push_back(execVar[j].result_get());
285                                                 execVar[j].result_get()->IncreaseRef();
286                                 }
287                                 else
288                                 {
289                                         for(int i = 0 ; i < execVar[j].result_size_get() ; i++)
290                                         {
291                                                 in.push_back(execVar[j].result_get(i));
292                                                 execVar[j].result_get(i)->IncreaseRef();
293                                         }
294                                 }
295                         }
296                         
297                         int iRetCount = Max(1, expected_size_get());
298
299                         T execCall;
300                         Function::ReturnValue Ret = pCall->call(in, iRetCount, out, &execCall);
301                         
302                         if(Ret == Callable::OK)
303                         {
304                                 if(expected_size_get() == 1 && out.size() == 0) //to manage ans
305                                 {
306                                         if((int)out.size() < expected_size_get())
307                                         {
308                                                 std::ostringstream os;
309                                                 os << "bad lhs, expected : " << expected_size_get() << " returned : " << out.size() << std::endl;
310                                                 throw os.str();
311                                         }
312                                 }
313
314                                 if(out.size() == 1)
315                                 {
316                                         result_set(out[0]);
317                                 }
318                                 else 
319                                 {
320                                         for(int i = 0 ; i < out.size() ; i++)
321                                         {
322                                                 result_set(i, out[i]);
323                                         }
324                                 }
325                         }
326                         else if(Ret == Callable::Error)
327                         {
328                                 std::ostringstream os;
329                                 char szError[bsiz];
330 #ifdef _MSC_VER
331                                 sprintf_s(szError, bsiz, _("Function \"%s\" failed\n"), pCall->getName().c_str());
332 #else
333                                 sprintf(szError, _("Function \"%s\" failed\n"), pCall->getName().c_str());
334 #endif
335                                 throw string(szError);
336                         }
337
338                         
339                         for (j = 0; j < e.args_get().size(); j++)
340                         {
341                                 execVar[j].result_get()->DecreaseRef();
342                         }
343                         
344 //                      std::cout << "before delete[]" << std::endl;
345                         delete[] execVar;
346 //                      std::cout << "after delete[]" << std::endl;
347                 }
348                 else if(execFunc.result_get() != NULL)
349                 {//a(xxx) with a variable, extraction
350
351                         //get symbol of variable
352                         InternalType *pIT = NULL;
353
354                         //WARNING can be a fieldexp
355                         const SimpleVar *Var = dynamic_cast<const SimpleVar*>(&e.name_get());
356                         if(Var != NULL)
357                         {
358                                 pIT = symbol::Context::getInstance()->get(Var->name_get());
359                         }
360                         else
361                         {
362                                 pIT = execFunc.result_get();
363                         }
364                         InternalType *pOut                      = NULL;
365                         std::vector<InternalType*> ResultList;
366                         int iArgDim                                                     = (int)e.args_get().size();
367                         bool bSeeAsVector                               = iArgDim == 1;
368
369                         //Create list of indexes
370                         //std::vector<std::vector<int>> IndexList;
371
372                         int *piIndexSeq         = NULL;
373                         int *piMaxDim                   = NULL;
374                         int *piDimSize          = new int[iArgDim];
375                         int iTotalCombi         = GetIndexList(e.args_get(), &piIndexSeq, &piMaxDim, pIT, piDimSize);
376
377                         switch(pIT->getType())
378                         {
379                         case InternalType::RealDouble :
380                                 pOut = pIT->getAsDouble()->extract(iTotalCombi, piIndexSeq, piMaxDim, piDimSize, bSeeAsVector);
381                                 break;
382                         case InternalType::RealBool : 
383                                 pOut = pIT->getAsBool()->extract(iTotalCombi, piIndexSeq, piMaxDim, piDimSize, bSeeAsVector);
384                                 break;
385                         case InternalType::RealInt :
386                                 pOut = pIT->getAsInt()->extract(iTotalCombi, piIndexSeq, piMaxDim, piDimSize, bSeeAsVector);
387                                 break;
388                         case InternalType::RealString :
389                                 pOut = pIT->getAsString()->extract(iTotalCombi, piIndexSeq, piMaxDim, piDimSize, bSeeAsVector);
390                                 break;
391                         case InternalType::RealList :
392                                 {
393                                         ResultList = pIT->getAsList()->extract(iTotalCombi, piIndexSeq, piMaxDim, piDimSize, bSeeAsVector);
394                                         for(int i = 0 ; i < ResultList.size() ; i++)
395                                         {
396                                                 result_set(i, ResultList[i]);
397                                         }
398                                         break;
399                                 }
400                         default :
401                                 break;
402                         }
403
404                         //Container type can return multiple items
405                         if(pIT->isContainer() == false)
406                         {
407                                 if(pOut == NULL)
408                                 {
409                                         std::ostringstream os;
410                                         os << "inconsistent row/column dimensions";
411                                         os << ((Location)(*e.args_get().begin())->location_get()).location_string_get() << std::endl;
412                                         throw os.str();
413                                 }
414                                 result_set(pOut);
415                         }
416                         else 
417                         {
418                                 if(ResultList.size() == 0)
419                                 {
420                                         std::ostringstream os;
421                                         os << "inconsistent row/column dimensions";
422                                         os << ((Location)(*e.args_get().begin())->location_get()).location_string_get() << std::endl;
423                                         throw os.str();
424                                 }
425                         }
426                         
427                         delete[] piDimSize;
428                         delete[] piIndexSeq;
429                         delete[] piMaxDim;
430                 }
431                 else
432                 {//result == NULL ,variable doesn't exist :(
433                         std::ostringstream os;
434                         char pst[bsiz];
435 #ifdef _MSC_VER
436                         sprintf_s(pst, bsiz, _("Undefined variable %s.\n"), e.name_get());
437 #else
438                         sprintf(pst, _("Undefined variable %s.\n"), e.name_get());
439 #endif
440                         throw string(pst);
441                 }
442         }
443
444         template <class T>
445         void RunVisitorT<T>::visitprivate(const IfExp  &e)
446         {
447                 //Create local exec visitor
448                 ConditionVisitor execMeTest;
449                 ShortCutVisitor SCTest;
450                 ExecVisitor execMeAction;
451                 bool bTestStatus                                                        = false;
452
453                 //condition
454                 e.test_get().accept(SCTest);
455                 e.test_get().accept(execMeTest);
456
457                 bTestStatus = bConditionState(&execMeTest);
458                 if(bTestStatus == true)
459                 {//condition == true
460                         if(e.is_breakable())
461                         {
462                                 ((Exp*)&e.then_get())->breakable_set();
463                         }
464
465                         if(e.is_returnable())
466                         {
467                                 ((Exp*)&e.then_get())->returnable_set();
468                         }
469
470                         e.then_get().accept(execMeAction);
471                 }
472                 else
473                 {//condition == false
474
475                         if(e.has_else())
476                         {
477                                 if(e.is_breakable())
478                                 {
479                                         ((Exp*)&e.else_get())->breakable_set();
480                                 }
481
482                                 if(e.is_returnable())
483                                 {
484                                         ((Exp*)&e.else_get())->returnable_set();
485                                 }
486
487                                 e.else_get().accept(execMeAction);
488                         }
489                 }
490
491                 if(e.is_breakable() && ( ((Exp*)&e.else_get())->is_break() || ((Exp*)&e.then_get())->is_break() ))
492                 {
493                         ((Exp*)&e)->break_set();
494                         ((Exp*)&e.else_get())->break_reset();
495                         ((Exp*)&e.then_get())->break_reset();
496                 }
497
498                 if(e.is_returnable() && ( ((Exp*)&e.else_get())->is_return() || ((Exp*)&e.then_get())->is_return() ))
499                 {
500                         ((Exp*)&e)->return_set();
501                         ((Exp*)&e.else_get())->return_reset();
502                         ((Exp*)&e.then_get())->return_reset();
503                 }
504         }
505
506         template <class T>
507         void RunVisitorT<T>::visitprivate(const TryCatchExp  &e)
508         {
509         }
510
511         template <class T>
512         void RunVisitorT<T>::visitprivate(const WhileExp  &e)
513         {
514                 ConditionVisitor execMeTest;
515                 ExecVisitor execMeAction;
516                 bool bTestStatus        = false;
517
518                 //allow break operation
519                 ((Exp*)&e.body_get())->breakable_set();
520                 //allow return operation
521                 if(e.is_returnable())
522                 {
523                         ((Exp*)&e.body_get())->is_returnable();
524                 }
525
526                 //condition
527                 e.test_get().accept(execMeTest);
528                 while(bConditionState(&execMeTest))
529                 {
530                         e.body_get().accept(execMeAction);
531                         if(e.body_get().is_break())
532                         {
533                                 break;
534                         }
535
536                         if(e.body_get().is_return())
537                         {
538                                 ((Exp*)&e)->return_set();
539                                 break;
540                         }
541                         e.test_get().accept(execMeTest);
542                 }
543         }
544
545         template <class T>
546         void RunVisitorT<T>::visitprivate(const ForExp  &e)
547         {
548                 ExecVisitor execVar;
549                 e.vardec_get().accept(execVar);
550
551                 //allow break operation
552                 ((Exp*)&e.body_get())->breakable_set();
553                 //allow return operation
554                 if(e.is_returnable())
555                 {
556                         ((Exp*)&e.body_get())->is_returnable();
557                 }
558
559                 if(execVar.result_get()->getType() == InternalType::RealImplicitList)
560                 {
561                         ExecVisitor execBody;
562                         ImplicitList* pVar = (ImplicitList*)execVar.result_get();
563 //                      std::cout << "ImplicitList references : " << pVar->getRef() << std::endl;
564
565                         InternalType *pIT = NULL;
566                         pIT = pVar->extract_value(0);
567                         string varName = e.vardec_get().name_get();
568                         symbol::Context::getInstance()->put(varName, *pIT);
569
570                         for(int i = 0 ; i < pVar->size_get() ; i++)
571                         {
572                                 if(pIT->getAsDouble())
573                                 {
574                                         Double *pDouble = pIT->getAsDouble();
575                                         pDouble->real_get()[0] = pVar->extract_value_double(i);
576                                 }
577                                 else if(pIT->getAsInt())
578                                 {
579                                         Int *pInt = pIT->getAsInt();
580                                         pInt->data_set(0, 0,  pVar->extract_value_int(i));
581                                 }
582                                 else
583                                 {
584                                         pIT = pVar->extract_value(i);
585                                         symbol::Context::getInstance()->put(varName, *pIT);
586                                 }
587
588                                 e.body_get().accept(execBody);
589                                 if(e.body_get().is_break())
590                                 {
591                                         break;
592                                 }
593
594                                 if(e.body_get().is_return())
595                                 {
596                                         ((Exp*)&e)->return_set();
597                                         break;
598                                 }
599                         }
600                         
601                         pVar->DecreaseRef();
602                 }
603                 else
604                 {//Matrix i = [1,3,2,6] or other type
605                         ExecVisitor execBody;
606                         GenericType* pVar = (GenericType*)execVar.result_get();
607                         for(int i = 0 ; i < pVar->cols_get() ; i++)
608                         {
609                                 GenericType* pNew = pVar->get_col_value(i);
610                                 symbol::Context::getInstance()->put(e.vardec_get().name_get(), *pNew);
611                                 e.body_get().accept(execBody);
612                                 if(e.body_get().is_break())
613                                 {
614                                         break;
615                                 }
616
617                                 if(e.body_get().is_return())
618                                 {
619                                         ((Exp*)&e)->return_set();
620                                         break;
621                                 }
622                         }
623                 }
624         }
625
626         template <class T>
627         void RunVisitorT<T>::visitprivate(const BreakExp &e)
628         {
629                 ((BreakExp*)&e)->break_set();
630         }
631
632         template <class T>
633         void RunVisitorT<T>::visitprivate(const ReturnExp &e)
634         {
635                 if(e.is_global() == false)
636                 {//return(x)
637                         ExecVisitor execVar;
638                         e.exp_get().accept(execVar);
639                         
640                         for(int i = 0 ; i < execVar.result_size_get() ; i++)
641                         {
642                                 result_set(i, execVar.result_get(i)->clone());
643                         }
644                 }
645                 ((Exp*)&e)->return_set();
646         }
647
648         template <class T>
649         void RunVisitorT<T>::visitprivate(const SelectExp &e)
650         {
651           // FIXME : exec select ... case ... else ... end
652                 ExecVisitor execMe;
653                 e.select_get()->accept(execMe);
654                 bool bCase = false;
655
656                 
657                 if(execMe.result_get() != NULL)
658                 {//find good case
659                         cases_t::iterator it;
660                         for(it = e.cases_get()->begin(); it != e.cases_get()->end() ; it++)
661                         {
662                                 ExecVisitor execCase;
663                                 CaseExp* pCase = *it;
664                                 pCase->test_get()->accept(execCase);
665                                 if(execCase.result_get() != NULL)
666                                 {
667                                         if(execCase.result_get()->isContainer()) //WARNING ONLY FOR CELL
668                                         {//check each item
669                                         }
670                                         else if(*execCase.result_get() == *execMe.result_get())
671                                         {//the good one
672                                                 ExecVisitor execBody;
673                                                 pCase->body_get()->accept(execBody);
674                                                 bCase = true;
675                                         }
676                                 }
677                         }
678                 }
679
680                 if(bCase == false)
681                 {//default case
682                         ExecVisitor execDefault;
683                         e.default_case_get()->accept(execDefault);
684                 }
685         }
686
687         template <class T>
688         void RunVisitorT<T>::visitprivate(const CaseExp &e)
689         {
690         }
691
692         template <class T>
693         void RunVisitorT<T>::visitprivate(const SeqExp  &e)
694         {
695                 T execMe;
696                 std::list<Exp *>::const_iterator        i;
697
698                 for (i = e.exps_get().begin (); i != e.exps_get().end (); ++i)
699                 {
700                         //ExecVisitor *execMe = getDefaultVisitor();
701                         if(e.is_breakable())
702                         {
703                                 (*i)->breakable_set();
704                         }
705
706                         if(e.is_returnable())
707                         {
708                                 (*i)->returnable_set();
709                         }
710
711                         (*i)->accept(execMe);
712
713                         if(execMe.result_get() != NULL)
714                         {
715                                 if(execMe.result_get()->getAsCallable())//to manage call without ()
716                                 {
717                                         Callable *pCall = execMe.result_get()->getAsCallable();
718                                         types::typed_list out;
719                                         types::typed_list in;
720
721                                         T execCall;
722                                         Function::ReturnValue Ret = pCall->call(in, (int)expected_size_get(), out, &execCall);
723
724                                         if(Ret == Callable::OK)
725                                         {
726                                                 if(expected_size_get() == 1 && out.size() == 0) //to manage ans
727                                                 {
728                                                         if((int)out.size() < expected_size_get())
729                                                         {
730                                                                 std::ostringstream os;
731                                                                 os << "bad lhs, expected : " << expected_size_get() << " returned : " << out.size() << std::endl;
732                                                                 throw os.str();
733                                                         }
734                                                 }
735
736                                                 for(int i = 0 ; i < out.size() ; i++)
737                                                 {
738                                                         out[i]->DecreaseRef();
739                                                         execMe.result_set(i, out[i]);
740                                                 }
741                                         }
742                                         else if(Ret == Callable::Error)
743                                         {
744                                                 std::ostringstream os;
745                                                 char szError[bsiz];
746 #ifdef _MSC_VER
747                                                 sprintf_s(szError, bsiz, _("Function \"%s\" failed\n"), pCall->getName().c_str());
748 #else
749                                                 sprintf(szError, _("Function \"%s\" failed\n"), pCall->getName().c_str());
750 #endif
751                                                 throw string(szError);
752                                         }
753                                 }
754
755                                 if(execMe.result_get()->isDeletable())
756                                 {
757                                         symbol::Context::getInstance()->put("ans", *execMe.result_get());
758                                         if((*i)->is_verbose())
759                                         {
760                                                 //TODO manage multiple returns
761                                                 std::ostringstream ostr;
762                                                 ostr << "ans = " << std::endl;
763                                                 ostr << std::endl;
764                                                 ostr << execMe.result_get()->toString(10,75) << std::endl;
765                                                 YaspWrite((char *)ostr.str().c_str());
766                                         }
767                                 }
768
769                         }
770
771                         if(((SeqExp*)&e)->is_breakable() && (*i)->is_break())
772                         {
773                                 ((SeqExp*)&e)->break_set();
774                                 break;
775                         }
776
777                         if(((SeqExp*)&e)->is_returnable() && (*i)->is_return())
778                         {
779                                 ((SeqExp*)&e)->return_set();
780                                 ((SeqExp*)(*i))->return_reset();
781                                 break;
782                         }
783                 }
784         }
785
786         template <class T>
787         void RunVisitorT<T>::visitprivate(const ArrayListExp  &e)
788         {
789                 std::list<Exp *>::const_iterator it;
790                 int i = 0;
791                 for(it = e.exps_get().begin() ; it != e.exps_get().end() ; it++)
792                 {
793                         ExecVisitor execArg;
794                         (*it)->accept(execArg);
795                         result_set(i, execArg.result_get()->clone());
796                         i++;
797                 }
798         }
799
800         template <class T>
801         void RunVisitorT<T>::visitprivate(const AssignListExp  &e)
802         {
803         }
804         /** \} */
805
806         /** \name Visit Single Operation nodes.
807         ** \{ */
808         template <class T>
809         void RunVisitorT<T>::visitprivate(const NotExp &e)
810         {
811                 /*
812                 @ or ~= !
813                 */
814                 ExecVisitor execMe;
815                 e.exp_get().accept(execMe);
816
817                 if(execMe.result_get()->isDouble())
818                 {
819                         Double *pdbl    = execMe.result_get()->getAsDouble();
820                         Bool *pReturn   = new Bool(pdbl->rows_get(), pdbl->cols_get());
821                         double *pR              = pdbl->real_get();
822                         int *piB                        = pReturn->bool_get();
823                         for(int i = 0 ; i < pdbl->size_get() ; i++)
824                         {
825                                 piB[i] = pR[i] == 0 ? 1 : 0;
826                         }
827                         result_set(pReturn);
828                 }
829                 else if(execMe.result_get()->isBool())
830                 {
831                         Bool *pb                        = execMe.result_get()->getAsBool();
832                         Bool *pReturn   = new Bool(pb->rows_get(), pb->cols_get());
833                         int *piR                        = pb->bool_get();
834                         int *piB                        = pReturn->bool_get();
835
836                         for(int i = 0 ; i < pb->size_get() ; i++)
837                         {
838                                 piB[i] = piR[i] == 1 ? 0 : 1;
839                         }
840                         result_set(pReturn);
841                 }
842         }
843
844         template <class T>
845         void RunVisitorT<T>::visitprivate(const TransposeExp &e)
846         {
847                 /*
848                 '
849                 */
850                 ExecVisitor execMe;
851                 e.exp_get().accept(execMe);
852
853                 bool bConjug = e.conjugate_get() == TransposeExp::_Conjugate_;
854
855                 if(execMe.result_get()->isImplicitList())
856                 {
857                         InternalType *pIT = execMe.result_get()->getAsImplicitList()->extract_matrix();
858                         execMe.result_set(pIT);
859                 }
860
861                 if(execMe.result_get()->isDouble())
862                 {
863                         Double *pdbl            = execMe.result_get()->getAsDouble();
864                         Double *pReturn = NULL;
865
866                         if(pdbl->isComplex())
867                         {
868                                 pReturn                         = new Double(pdbl->cols_get(), pdbl->rows_get(), true);
869                                 double *pInR    =       pdbl->real_get();
870                                 double *pInI    =       pdbl->img_get();
871                                 double *pOutR   =       pReturn->real_get();
872                                 double *pOutI   =       pReturn->img_get();
873
874                                 vTransposeComplexMatrix(pInR, pInI, pdbl->rows_get(), pdbl->cols_get(), pOutR, pOutI, bConjug);
875                         }
876                         else
877                         {
878                                 pReturn                         = new Double(pdbl->cols_get(), pdbl->rows_get(), false);
879                                 double *pInR    =       pdbl->real_get();
880                                 double *pOutR   =       pReturn->real_get();
881
882                                 vTransposeRealMatrix(pInR, pdbl->rows_get(), pdbl->cols_get(), pOutR);
883                         }
884                         result_set(pReturn);
885                 }
886                 else if(execMe.result_get()->isPoly())
887                 {
888                         MatrixPoly *pMP                 = execMe.result_get()->getAsPoly();
889                         MatrixPoly *pReturn     = NULL;
890
891                         //prepare rank array
892                         int* piRank = new int[pMP->size_get()];
893
894                         for(int i = 0 ; i < pMP->rows_get() ; i++)
895                         {
896                                 for(int j = 0 ; j < pMP->cols_get() ; j++)
897                                 {
898                                         piRank[i * pMP->cols_get() + j] = pMP->poly_get(i,j)->rank_get();
899                                 }
900                         }
901
902                         pReturn = new MatrixPoly(pMP->var_get(), pMP->cols_get(), pMP->rows_get(), piRank);
903                         pReturn->complex_set(pMP->isComplex());
904
905                         if(pMP->isComplex() && bConjug)
906                         {
907                                 for(int i = 0 ; i < pMP->rows_get() ; i++)
908                                 {
909                                         for(int j = 0 ; j < pMP->cols_get() ; j++)
910                                         {
911                                                 pReturn->poly_set(j, i, pMP->poly_get(i,j)->coef_get());
912                                                 double *pdblImg = pReturn->poly_get(j, i)->coef_img_get();
913                                                 for(int k = 0 ; k < pReturn->poly_get(j, i)->rank_get() ; k++)
914                                                 {
915                                                         pdblImg[k] *= -1;
916                                                 }
917                                         }
918                                 }
919                         }
920                         else
921                         {
922                                 for(int i = 0 ; i < pMP->rows_get() ; i++)
923                                 {
924                                         for(int j = 0 ; j < pMP->cols_get() ; j++)
925                                         {
926                                                 pReturn->poly_set(j, i, pMP->poly_get(i,j)->coef_get());
927                                         }
928                                 }
929                         }
930
931                         result_set(pReturn);
932                 }
933         }
934         /** \} */
935
936         /** \name Visit Declaration nodes.
937         ** \{ */
938         /** \brief Visit Var declarations. */
939         template <class T>
940         void RunVisitorT<T>::visitprivate(const VarDec  &e)
941         {
942                 /*Create local exec visitor*/
943                 ExecVisitor execMe;
944                 try
945                 {
946                         /*getting what to assign*/
947                         e.init_get().accept(execMe);
948                         result_set(execMe.result_get());
949                         result_get()->IncreaseRef();
950                 }
951                 catch(string sz)
952                 {
953                         throw sz;
954                 }
955         }
956
957         template <class T>
958         void RunVisitorT<T>::visitprivate(const FunctionDec  &e)
959         {
960                 /*
961                 function foo
962                 endfunction
963                 */
964                 std::list<ast::Var *>::const_iterator   i;
965
966                 //get input parameters list
967                 std::list<string> *pVarList = new std::list<string>();
968                 ArrayListVar *pListVar = (ArrayListVar *)&e.args_get();
969                 for(i = pListVar->vars_get().begin() ; i != pListVar->vars_get().end() ; i++)
970                 {
971                         pVarList->push_back(((SimpleVar*)(*i))->name_get());
972                 }
973
974                 //get output parameters list
975                 std::list<string> *pRetList = new std::list<string>();
976                 ArrayListVar *pListRet = (ArrayListVar *)&e.returns_get();
977                 for(i = pListRet->vars_get().begin() ; i != pListRet->vars_get().end() ; i++)
978                 {
979                         pRetList->push_back(((SimpleVar*)(*i))->name_get());
980                 }
981
982                 //types::Macro macro(VarList, RetList, (SeqExp&)e.body_get());
983                 types::Macro *pMacro = new types::Macro(e.name_get(), *pVarList, *pRetList, (SeqExp&)e.body_get(), "script");
984                 symbol::Context::getInstance()->AddMacro(pMacro);
985         }
986         /** \} */
987
988         /** \name Visit Type dedicated Expressions related node.
989         ** \{ */
990         template <class T>
991         void RunVisitorT<T>::visitprivate(const ListExp &e)
992         {
993                 ExecVisitor     execMeStart;
994                 ExecVisitor     execMeStep;
995                 ExecVisitor     execMeEnd;
996
997                 try
998                 {
999                         e.start_get().accept(execMeStart);
1000                         GenericType* pITStart = (GenericType*)execMeStart.result_get();
1001                         if(pITStart->rows_get() != 1 || pITStart->cols_get() != 1)
1002                         {
1003                                 throw 1;
1004                         }
1005
1006
1007                         e.step_get().accept(execMeStep);
1008                         GenericType* pITStep = (GenericType*)execMeStep.result_get();
1009                         if(pITStep->rows_get() != 1 || pITStep->cols_get() != 1)
1010                         {
1011                                 throw 2;
1012                         }
1013
1014                         e.end_get().accept(execMeEnd);
1015                         GenericType* pITEnd = (GenericType*)execMeEnd.result_get();
1016                         if(pITEnd->rows_get() != 1 || pITEnd->cols_get() != 1)
1017                         {
1018                                 throw 3;
1019                         }
1020
1021                         //check compatibility
1022
1023                         if(execMeStart.result_get()->getType() == InternalType::RealInt)
1024                         {//if Step or End are Int too, they must have the same precision
1025                                 Int::IntType IT = execMeStart.result_get()->getAsInt()->getIntType();
1026
1027                                 if(execMeStep.result_get()->getType() == InternalType::RealInt)
1028                                 {
1029                                         if(execMeStep.result_get()->getAsInt()->getIntType() != IT)
1030                                         {
1031                                                 throw string(_("Undefined operation for the given operands.\n"));
1032                                         }
1033                                 }
1034                                 else if(execMeStep.result_get()->getType() == InternalType::RealPoly)
1035                                 {
1036                                         throw string(_("Undefined operation for the given operands.\n"));
1037                                 }
1038
1039
1040                                 if(execMeEnd.result_get()->getType() == InternalType::RealInt)
1041                                 {
1042                                         if(execMeEnd.result_get()->getAsInt()->getIntType() != IT)
1043                                         {
1044                                                 throw string(_("Undefined operation for the given operands.\n"));
1045                                         }
1046                                 }
1047                                 else if(execMeEnd.result_get()->getType() == InternalType::RealPoly)
1048                                 {
1049                                         throw string(_("Undefined operation for the given operands.\n"));
1050                                 }
1051                         }
1052                         else if(execMeStart.result_get()->getType() == InternalType::RealPoly)
1053                         {
1054                                 if(execMeStep.result_get()->getType() == InternalType::RealInt)
1055                                 {
1056                                         throw string(_("Undefined operation for the given operands.\n"));
1057                                 }
1058
1059                                 if(execMeEnd.result_get()->getType() == InternalType::RealInt)
1060                                 {
1061                                         throw string(_("Undefined operation for the given operands.\n"));
1062                                 }
1063                         }
1064                         else if(execMeStep.result_get()->getType() == InternalType::RealInt)
1065                         {//if End are Int too, they must have the same precision
1066                                 Int::IntType IT = execMeStep.result_get()->getAsInt()->getIntType();
1067
1068                                 if(execMeEnd.result_get()->getType() == InternalType::RealInt)
1069                                 {
1070                                         if(execMeEnd.result_get()->getAsInt()->getIntType() != IT)
1071                                         {
1072                                                 throw string(_("Undefined operation for the given operands.\n"));
1073                                         }
1074                                 }
1075                         }
1076                         else if(execMeStep.result_get()->getType() == InternalType::RealPoly)
1077                         {
1078                                 if(execMeEnd.result_get()->getType() == InternalType::RealInt)
1079                                 {
1080                                         throw string(_("Undefined operation for the given operands.\n"));
1081                                 }
1082                         }
1083
1084                         ImplicitList *pIL       = new ImplicitList(
1085                                 execMeStart.result_get(),
1086                                 execMeStep.result_get(),
1087                                 execMeEnd.result_get());
1088
1089                         result_set(pIL);
1090                 }
1091                 catch(int iPos)
1092                 {
1093                         char st[bsiz];
1094 #ifdef _MSC_VER
1095                         sprintf_s(st, bsiz, _("%s: Wrong type for argument %d: Scalar expected.\n"), ":", iPos);
1096 #else
1097                         sprintf(st, _("%s: Wrong type for argument %d: Scalar expected.\n"), "::", 1);
1098 #endif
1099                         throw string(st);
1100                 }
1101                 catch(string sz)
1102                 {               
1103                         //TODO YaSp : Overloading
1104                         throw sz;
1105                 }
1106         }
1107         /** \} */
1108
1109         template <class T>
1110         int RunVisitorT<T>::GetIndexList(std::list<ast::Exp *>const& _plstArg, int** _piIndexSeq, int** _piMaxDim, InternalType *_pRefVar, int *_iDimSize)
1111         {
1112                 //Create list of indexes
1113                 //std::vector<std::vector<int>> IndexList;
1114                 symbol::Context *pcontext = symbol::Context::getInstance();
1115                 int iProductElem                                = (int)_plstArg.size();
1116                 int **piIndexList                               = NULL;
1117                 int *piTabsize                                  = NULL;
1118                 int iTotalCombi                                 = 1;
1119                 int k                                                                           = 0;
1120
1121                 piTabsize                       = new int[iProductElem];
1122                 piIndexList             = new int*[iProductElem];
1123
1124                 (*_piMaxDim)    = new int[iProductElem];
1125
1126                 T execMeArg;
1127                 std::list<Exp *>::const_iterator        i;
1128                 for(i = _plstArg.begin() ; i != _plstArg.end() ; i++,k++)
1129                 {
1130                         (*i)->accept(execMeArg);
1131                         InternalType *pIn = NULL;
1132                         Double *pDbl = NULL;
1133                         bool bDeleteDbl = false;
1134
1135                         if(execMeArg.result_get()->getType() == InternalType::RealImplicitList)
1136                         {//a:b:c
1137                                 int iMaxDim = 0;
1138                                 if(_pRefVar != NULL)
1139                                 {
1140                                         iMaxDim = GetVarMaxDim(_pRefVar, k, iProductElem);
1141                                 }
1142
1143                                 Double dbl(iMaxDim); // $
1144                                 ImplicitList *pIL = execMeArg.result_get()->getAsImplicitList();
1145                                 if(pIL->computable() == false)
1146                                 {
1147                                         if(pIL->start_type_get() == InternalType::RealPoly)
1148                                         {
1149                                                 MatrixPoly *poPoly      = (MatrixPoly*)pIL->start_get();
1150                                                 pIL->start_set(poPoly->evaluate(&dbl));
1151                                         }
1152                                         if(pIL->step_type_get() == InternalType::RealPoly)
1153                                         {
1154                                                 MatrixPoly *poPoly      = (MatrixPoly*)pIL->step_get();
1155                                                 pIL->step_set(poPoly->evaluate(&dbl));
1156                                         }
1157                                         if(pIL->end_type_get() == InternalType::RealPoly)
1158                                         {
1159                                                 MatrixPoly *poPoly      = (MatrixPoly*)pIL->end_get();
1160                                                 pIL->end_set(poPoly->evaluate(&dbl));
1161                                         }
1162                                 }
1163
1164                                 pDbl = (Double*)pIL->extract_matrix();
1165                                 bDeleteDbl = true;
1166                         }
1167                         else if(execMeArg.result_get()->getType() == InternalType::RealBool)
1168                         {
1169                                 Bool *pB                        = execMeArg.result_get()->getAsBool();
1170                                 int *piB                        = pB->bool_get();
1171
1172                                 //find true item count
1173                                 int iItemCount = 0;
1174                                 for(int i = 0 ; i < pB->size_get() ; i++)
1175                                 {
1176                                         if(piB[i])
1177                                         {
1178                                                 iItemCount++;
1179                                         }
1180                                 }
1181
1182                                 //allow new Double variable
1183                                 pDbl                                    = new Double(iItemCount, 1);
1184                                 double* pdbl    = pDbl->real_get();
1185
1186                                 int j = 0;
1187                                 for(int i = 0 ; i < pB->size_get() ; i++)
1188                                 {
1189                                         if(piB[i])
1190                                         {
1191                                                 pdbl[j++] = i + 1;
1192                                         }
1193                                 }
1194
1195                                 bDeleteDbl              = true;
1196                         }
1197                         else
1198                         {
1199                                 pIn = execMeArg.result_get();
1200
1201                                 if(pIn->getType() == InternalType::RealPoly)
1202                                 {//manage $
1203                                         MatrixPoly *pPoly = pIn->getAsPoly();
1204
1205                                         if(_pRefVar != NULL)
1206                                         {
1207                                                 int iMaxDim = GetVarMaxDim(_pRefVar, k, iProductElem);
1208                                                 Double dbl(iMaxDim); // $
1209                                                 pDbl = pPoly->evaluate(&dbl);
1210                                                 bDeleteDbl = true;
1211                                         }
1212                                         else
1213                                         {//houston we have a problem ...
1214                                                 Double dbl(0);
1215                                                 pDbl = pPoly->evaluate(&dbl);
1216
1217                                         }
1218                                 }
1219                                 else if(pIn->getType() == InternalType::RealDouble)
1220                                 {
1221                                         pDbl    = pIn->getAsDouble();//
1222                                 }
1223                                 else
1224                                 {//Heu ... ?
1225                                 }
1226                         }
1227
1228                         double *pData = pDbl->real_get();
1229
1230                         piTabsize[k] = pDbl->size_get();
1231                         piIndexList[k] = new int[piTabsize[k]];
1232
1233                         (*_piMaxDim)[k] = (int)(pData[0] + 0.5);
1234                         int iSize = pDbl->size_get();
1235                         if(_iDimSize != NULL)
1236                         {
1237                                 _iDimSize[k] = iSize;
1238                         }
1239
1240                         for(int j = 0 ; j < iSize ; j++)
1241                         {
1242                                 piIndexList[k][j] = (int)(pData[j] + 0.5);
1243                                 if(piIndexList[k][j] > (*_piMaxDim)[k])
1244                                 {
1245                                         (*_piMaxDim)[k] = piIndexList[k][j];
1246                                 }
1247                         }
1248                         iTotalCombi *= iSize;
1249
1250                         if(bDeleteDbl == true)
1251                         {
1252                                 delete pDbl;
1253                         }
1254                 }
1255
1256                 int iTabsize    = iTotalCombi * iProductElem;
1257                 *_piIndexSeq    = new int[iTabsize];
1258
1259                 if(iTabsize > 1)
1260                 {
1261                         ExpandList(piIndexList, piTabsize, iProductElem, *_piIndexSeq);
1262                 }
1263                 else
1264                 {
1265                         _piIndexSeq[0][0] = piIndexList[0][0];
1266                 }
1267
1268                 delete [] piTabsize;
1269
1270                 for(int i = 0 ; i < iProductElem ; i++)
1271                 {
1272                         delete[] piIndexList[i];
1273                 }
1274                 delete[] piIndexList;
1275                 return iTotalCombi;
1276         }
1277 }
1278
1279 using namespace ast;
1280 //using ast::ExecVisitor;
1281
1282 bool bConditionState(ast::ConditionVisitor *exec)
1283 {
1284         if(exec->is_boolean_result())
1285         {
1286                 return exec->result_bool_get();
1287         }
1288         else if(((GenericType*)exec->result_get())->isDouble() && ((Double*)exec->result_get())->isComplex() == false)
1289         {
1290                 Double *pR              = (Double*)exec->result_get();
1291                 double *pReal   = pR->real_get();
1292
1293                 for(int i = 0 ; i < pR->size_get() ; i++)
1294                 {
1295                         if(pReal[i] == 0)
1296                         {
1297                                 return false;
1298                         }
1299                 }
1300         }
1301         else if(((GenericType*)exec->result_get())->isBool())
1302         {
1303                 Bool *pB                = (Bool*)exec->result_get();
1304                 int *piData     = pB->bool_get();
1305
1306                 for(int i = 0 ; i < pB->size_get() ; i++)
1307                 {
1308                         if(piData[i] == 0)
1309                         {
1310                                 return false;
1311                                 break;
1312                         }
1313                 }
1314         }
1315         else if(((GenericType*)exec->result_get())->isInt())
1316         {
1317         }
1318         else
1319         {
1320                 return false;
1321         }
1322         return true;
1323 }
1324
1325 void vTransposeRealMatrix(double *_pdblRealIn, int _iRowsIn, int _iColsIn, double *_pdblRealOut)
1326 {
1327         int iIndex = 0;
1328         for(iIndex = 0 ; iIndex < _iRowsIn * _iColsIn ; iIndex++)
1329         {
1330                 int iNewCoord   = iIndex % _iRowsIn * _iColsIn + (iIndex / _iRowsIn);
1331                 _pdblRealOut[iNewCoord] = _pdblRealIn[iIndex];
1332         }
1333 }
1334
1335 void vTransposeComplexMatrix(double *_pdblRealIn, double *_pdblImgIn, int _iRowsIn, int _iColsIn, double *_pdblRealOut, double *_pdblImgOut, bool _bConjugate)
1336 {
1337         int iIndex = 0;
1338
1339         if(_bConjugate == false)
1340         {
1341                 for(iIndex = 0 ; iIndex < _iRowsIn * _iColsIn ; iIndex++)
1342                 {
1343                         int iNewCoord   = iIndex % _iRowsIn * _iColsIn + (iIndex / _iRowsIn);
1344
1345                         _pdblRealOut[iNewCoord] = _pdblRealIn[iIndex];
1346                         _pdblImgOut[iNewCoord]  = _pdblImgIn[iIndex];
1347                 }
1348         }
1349         else
1350         {
1351                 for(iIndex = 0 ; iIndex < _iRowsIn * _iColsIn ; iIndex++)
1352                 {
1353                         int iNewCoord   = iIndex % _iRowsIn * _iColsIn + (iIndex / _iRowsIn);
1354
1355                         _pdblRealOut[iNewCoord] = _pdblRealIn[iIndex];
1356                         //Conjugate
1357                         _pdblImgOut[iNewCoord]  = -_pdblImgIn[iIndex];
1358                 }
1359         }
1360 }
1361
1362 void ExpandList(int ** _piList, int *_piListSize, int _iListSizeSize, int *_piResultList)
1363 {
1364 //#define ORIGINAL_IMPLEM 
1365 #ifdef ORIGINAL_IMPLEM
1366         for(int i = _iListSizeSize - 1 ; i >= 0 ; i--)
1367         {
1368                 int iPreOcc = 1;
1369                 int iPostOcc = 1;
1370                 for(int k = 0 ; k < i ; k++)
1371                 {
1372                         if(k != i)
1373                         {
1374                                 iPreOcc *= _piListSize[k];
1375                         }
1376                 }
1377
1378                 for(int k = i + 1 ; k < _iListSizeSize ; k++)
1379                 {
1380                         if(k != i)
1381                         {
1382                                 iPostOcc *= _piListSize[k];
1383                         }
1384                 }
1385
1386                 int iSize = _piListSize[i];
1387                 for(int m = iSize - 1 ; m >= 0  ; m--)
1388                 {
1389                         for(int j1 = iPreOcc - 1 ; j1 >= 0 ; j1--)
1390                         {
1391                                 for(int j2 = iPostOcc - 1 ; j2 >= 0 ; j2--)
1392                                 {
1393                                         //Bloc Offset                           -> j1 * ( iPostOcc * iSize) * _iListSizeSize
1394                                         //Offset in Bloc                -> m * iPostOcc * _iListSizeSize
1395                                         //Offset in SubBloc -> j2 * _iListSizeSize + i
1396                                         int iPos = j1 * ( iPostOcc * iSize) * _iListSizeSize + m * iPostOcc * _iListSizeSize + j2 * _iListSizeSize + i;
1397                                         _piResultList[iPos] = _piList[i][m];
1398
1399                                 }
1400                         }
1401                 }
1402         }
1403 #else
1404         int iPreOcc= 1;
1405         int iPostOcc= std::accumulate(_piListSize, _piListSize + _iListSizeSize, 1, multiplies<int>());
1406         for(int i =0; i!= _iListSizeSize;++i)
1407         {
1408                 int const iSize = _piListSize[i];
1409                 int const delta(iPostOcc * _iListSizeSize);
1410                 int* ptr = _piResultList + i;
1411
1412                 iPostOcc /= iSize;
1413
1414                 for(int m(0); m != iSize; ++m,ptr += delta)
1415                 {
1416                         int const data=_piList[i][m];
1417                         for(int j1(0); j1 != iPreOcc; ++j1, ptr +=  delta * iSize)
1418                         {
1419                                 for(int j2(0); j2!= iPostOcc ; ++j2, ptr+=  _iListSizeSize) 
1420                                 {
1421                                         *ptr= data;
1422                                 }
1423                         }
1424                 }
1425                 iPreOcc *= iSize;
1426         }
1427 #endif
1428 }
1429
1430 int GetVarMaxDim(InternalType *_pIT, int _iCurrentDim, int _iMaxDim)
1431 {
1432         if(_pIT == NULL)
1433         {
1434                 return 0;
1435         }
1436         if(_iCurrentDim == 0)
1437         {
1438                 if(_iMaxDim != 1)
1439                 {
1440                         return ((GenericType*)_pIT)->rows_get();
1441                 }
1442                 else
1443                 {
1444                         return ((GenericType*)_pIT)->size_get();
1445                 }
1446         }
1447         else if(_iCurrentDim == 1)
1448         {
1449                 return ((GenericType*)_pIT)->cols_get();
1450         }
1451         else
1452         {//more than 2 dimansions ? :(
1453                 return ((GenericType*)_pIT)->size_get();
1454         }
1455 }