CodeInterpreter.hh 54.4 KB
Newer Older
1
/*
Houtan Bastani's avatar
Houtan Bastani committed
2
 * Copyright (C) 2007-2015 Dynare Team
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This file is part of Dynare.
 *
 * Dynare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dynare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

20 21
#ifndef _CODEINTERPRETER_HH
#define _CODEINTERPRETER_HH
22
//#define DEBUGL
23 24
#include <iostream>

25 26 27 28
#include <cstdlib>
#include <cstdio>
#include <fstream>
#include <cstring>
29
#include <vector>
30 31 32 33
#ifdef LINBCG
# include "linbcg.hh"
#endif
#ifdef BYTE_CODE
34 35 36 37 38
# ifndef DEBUG_EX
#  include "mex.h"
# else
#  include "mex_interface.hh"
# endif
39 40
#endif

41
#include <stdint.h>
42

43 44
#define NEAR_ZERO (1e-12)

45 46 47
using namespace std;

/**
48 49 50
 * \enum Tags
 * \brief The differents flags of the bytecode
 */
51 52
enum Tags
  {
53 54
    FLDZ,         //!< Stores zero in the stack - 0 (0)
    FLDC,         //!< Stores a constant term in the stack - 1 (1)
55

56 57 58 59 60 61
    FDIMT,        //!< Defines the number of temporary terms - dynamic context (the period has to be indicated) - 2 (2)
    FDIMST,       //!< Defines the number of temporary terms - static context (the period hasn't to be indicated) - 3  (3)
    FLDT,         //!< Stores a temporary term in the stack - dynamic context (the period has to be indicated) - 4 (4)
    FLDST,        //!< Stores a temporary term in the stack - static context (the period hasn't to be indicated) - 5 (5)
    FSTPT,        //!< Loads a temporary term from the stack - dynamic context (the period has to be indicated) - 6 (6)
    FSTPST,       //!< Loads a temporary term from the stack - static context (the period hasn't to be indicated) - 7 (7)
62

63 64 65 66
    FLDU,         //!< Stores an element of the vector U in the stack - dynamic context (the period has to be indicated) - 8 (8)
    FLDSU,        //!< Stores an element of the vector U in the stack - static context (the period hasn't to be indicated) - 9 (9)
    FSTPU,        //!< Loads an element of the vector U from the stack - dynamic context (the period has to be indicated) - A (10)
    FSTPSU,       //!< Loads an element of the vector U from the stack - static context (the period hasn't to be indicated) - B (11)
67

68 69 70 71 72
    FLDV,         //!< Stores a variable (described in SymbolType) in the stack - dynamic context (the period has to be indicated) - C (12)
    FLDSV,        //!< Stores a variable (described in SymbolType) in the stack - static context (the period hasn't to be indicated) - D (13)
    FLDVS,        //!< Stores a variable (described in SymbolType) in the stack - dynamic context but inside the STEADYSTATE function (the period hasn't to be indicated) - E (14)
    FSTPV,        //!< Loads a variable (described in SymbolType) from the stack - dynamic context (the period has to be indicated) - F (15)
    FSTPSV,       //!< Loads a variable (described in SymbolType) from the stack - static context (the period hasn't to be indicated) - 10 (16)
73

74 75
    FLDR,         //!< Stores a residual in the stack - 11 (17)
    FSTPR,        //!< Loads a residual from the stack - 12 (18)
76

77 78 79 80
    FSTPG,        //!< Loads a derivative from the stack - 13 (19)
    FSTPG2,       //!< Loads a derivative matrix for static model from the stack - 14 (20)
    FSTPG3,       //!< Loads a derivative matrix for a dynamic model from the stack - 15 (21)
    FSTPG4,       //!< Loads a second order derivative matrix for a dynamic model from the stack - 16 (22)
81

82 83 84
    FUNARY,       //!< A Unary operator - 17 (23)
    FBINARY,      //!< A binary operator - 18 (24)
    FTRINARY,     //!< A trinary operator - 19 (25)
85

86
    FCUML,        //!< Cumulates the result - 1A (26)
87

88 89
    FJMPIFEVAL,   //!< Jump if evaluate = true - 1B (27)
    FJMP,         //!< Jump - 1C (28)
90

91 92 93 94 95 96 97
    FBEGINBLOCK,  //!< Defines the begining of a model block - 1D (29)
    FENDBLOCK,    //!< Defines the end of a model block - 1E (30)
    FENDEQU,      //!< Defines the last equation of the block. For block that has to be solved, the derivatives appear just after this flag - 1F (31)
    FEND,         //!< Defines the end of the model code - 20 (32)

    FOK,          //!< Used for debugging purpose - 21 (33)

98 99 100 101 102 103 104 105 106 107 108
    FNUMEXPR,     //!< Store the expression type and references - 22 (34)

    FCALL,        //!< Call an external function - 23 (35)
    FPUSH,        //!< Push a double in the stack - 24 (36)
    FPOP,         //!< Pop a double from the stack - 25 (37)
    FLDTEF,       //!< Stores the result of an external function in the stack - 26 (38)
    FSTPTEF,      //!< Loads the result of an external function from the stack- 27 (39)
    FLDTEFD,      //!< Stores the result of an external function in the stack - 28 (40)
    FSTPTEFD,     //!< Loads the result of an external function from the stack- 29 (41)
    FLDTEFDD,     //!< Stores the result of an external function in the stack - 28 (42)
    FSTPTEFDD     //!< Loads the result of an external function from the stack- 29 (43)
109

110
  };
111

sebastien's avatar
sebastien committed
112 113
enum BlockType
  {
114 115 116 117
    SIMULTANS,  //!< Simultaneous time separable block
    PROLOGUE,   //!< Prologue block (one equation at the beginning, later merged)
    EPILOGUE,   //!< Epilogue block (one equation at the beginning, later merged)
    SIMULTAN    //!< Simultaneous time unseparable block
sebastien's avatar
sebastien committed
118 119
  };

120 121 122 123
enum EquationType
  {
    E_UNKNOWN,              //!< Unknown equation type
    E_EVALUATE,             //!< Simple evaluation, normalized variable on left-hand side
ferhat's avatar
ferhat committed
124
    E_EVALUATE_S,           //!< Simple evaluation, normalize using the first order derivative
125 126 127
    E_SOLVE                 //!< No simple evaluation of the equation, it has to be solved
  };

128 129 130 131
enum BlockSimulationType
  {
    UNKNOWN,                      //!< Unknown simulation type
    EVALUATE_FORWARD,             //!< Simple evaluation, normalized variable on left-hand side, forward
132
    EVALUATE_BACKWARD,            //!< Simple evaluation, normalized variable on left-hand side, backward
133
    SOLVE_FORWARD_SIMPLE,         //!< Block of one equation, newton solver needed, forward
134 135
    SOLVE_BACKWARD_SIMPLE,        //!< Block of one equation, newton solver needed, backward
    SOLVE_TWO_BOUNDARIES_SIMPLE,  //!< Block of one equation, newton solver needed, forward & ackward
136
    SOLVE_FORWARD_COMPLETE,       //!< Block of several equations, newton solver needed, forward
137
    SOLVE_BACKWARD_COMPLETE,      //!< Block of several equations, newton solver needed, backward
138
    SOLVE_TWO_BOUNDARIES_COMPLETE //!< Block of several equations, newton solver needed, forward and backwar
139
  };
140 141

//! Enumeration of possible symbol types
sebastien's avatar
sebastien committed
142
/*! Warning: do not to change existing values for 0 to 4: the values matter for homotopy_setup command */
143
enum SymbolType
144
  {
145 146 147 148 149 150 151 152
    eEndogenous = 0,                //!< Endogenous
    eExogenous = 1,                 //!< Exogenous
    eExogenousDet = 2,              //!< Exogenous deterministic
    eParameter = 4,                 //!< Parameter
    eModelLocalVariable = 10,       //!< Local variable whose scope is model (pound expression)
    eModFileLocalVariable = 11,     //!< Local variable whose scope is mod file (model excluded)
    eExternalFunction = 12,         //!< External (user-defined) function
    eTrend = 13,                    //!< Trend variable
153
    eStatementDeclaredVariable = 14, //!< Local variable assigned within a Statement (see subsample statement for example)
154 155
    eLogTrend = 15,                 //!< Log-trend variable
    eUnusedEndogenous = 16
156 157
  };

158 159 160 161 162
enum ExpressionType
  {
    TemporaryTerm,
    ModelEquation,
    FirstEndoDerivative,
163
    FirstOtherEndoDerivative,
164 165 166 167 168 169 170 171 172 173 174 175 176
    FirstExoDerivative,
    FirstExodetDerivative,
    FirstParamDerivative,
    SecondEndoDerivative,
    SecondExoDerivative,
    SecondExodetDerivative,
    SecondParamDerivative,
    ThirdEndoDerivative,
    ThirdExoDerivative,
    ThirdExodetDerivative,
    ThirdParamDerivative
  };

177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
enum UnaryOpcode
  {
    oUminus,
    oExp,
    oLog,
    oLog10,
    oCos,
    oSin,
    oTan,
    oAcos,
    oAsin,
    oAtan,
    oCosh,
    oSinh,
    oTanh,
    oAcosh,
    oAsinh,
    oAtanh,
195
    oSqrt,
196 197
    oAbs,
    oSign,
198
    oSteadyState,
199 200
    oSteadyStateParamDeriv, // for the derivative of the STEADY_STATE operator w.r.t. to a parameter
    oSteadyStateParam2ndDeriv, // for the 2nd derivative of the STEADY_STATE operator w.r.t. to a parameter
201 202
    oExpectation,
    oErf
203
  };
sebastien's avatar
sebastien committed
204

205 206 207 208 209 210 211
enum BinaryOpcode
  {
    oPlus,
    oMinus,
    oTimes,
    oDivide,
    oPower,
212
    oPowerDeriv, // for the derivative of the power function (see trac ticket #78)
213 214 215 216 217 218 219 220
    oEqual,
    oMax,
    oMin,
    oLess,
    oGreater,
    oLessEqual,
    oGreaterEqual,
    oEqualEqual,
221
    oDifferent
222 223
  };

sebastien's avatar
sebastien committed
224 225
enum TrinaryOpcode
  {
226 227
    oNormcdf,
    oNormpdf
sebastien's avatar
sebastien committed
228 229
  };

230 231 232 233 234 235 236 237 238 239 240
enum external_function_type
{
  ExternalFunctionWithoutDerivative,
  ExternalFunctionWithFirstDerivative,
  ExternalFunctionWithFirstandSecondDerivative,
  ExternalFunctionNumericalFirstDerivative,
  ExternalFunctionFirstDerivative,
  ExternalFunctionNumericalSecondDerivative,
  ExternalFunctionSecondDerivative
};

241 242 243 244 245 246 247 248 249
enum PriorDistributions
  {
    eNoShape = 0,
    eBeta = 1,
    eGamma = 2,
    eNormal = 3,
    eInvGamma = 4,
    eInvGamma1 = 4,
    eUniform = 5,
250
    eInvGamma2 = 6,
251 252
    eDirichlet = 7,
    eWeibull = 8
253 254
  };

Houtan Bastani's avatar
temp  
Houtan Bastani committed
255 256 257 258 259 260 261 262 263 264 265 266 267
enum NodeTreeReference
  {
    eResiduals = 0,
    eFirstDeriv = 1,
    eSecondDeriv = 2,
    eThirdDeriv = 3,
    eResidualsParamsDeriv = 4,
    eJacobianParamsDeriv = 5,
    eResidualsParamsSecondDeriv = 6,
    eJacobianParamsSecondDeriv = 7,
    eHessianParamsDeriv = 8
  };

268 269 270 271
struct Block_contain_type
{
  int Equation, Variable, Own_Derivative;
};
272

273
#pragma pack(push, 1)
274 275 276 277 278
class TagWithoutArgument
{
protected:
  uint8_t op_code;
public:
279 280
  inline
  TagWithoutArgument(uint8_t op_code_arg) : op_code(op_code_arg)
281 282 283
  {
  };
  inline void
284
  write(ostream &CompileCode, unsigned int &instruction_number)
285 286
  {
    CompileCode.write(reinterpret_cast<char *>(this), sizeof(*this));
287
    instruction_number++;
288
  };
289 290 291 292 293 294 295 296 297
};

template < class T1 >
class TagWithOneArgument
{
protected:
  uint8_t op_code;
  T1 arg1;
public:
298 299
  inline
  TagWithOneArgument(uint8_t op_code_arg) : op_code(op_code_arg)
300 301
  {
  };
302 303
  inline
  TagWithOneArgument(uint8_t op_code_arg, T1 arg_arg1) : op_code(op_code_arg), arg1(arg_arg1)
304 305 306
  {
  };
  inline void
307
  write(ostream &CompileCode, unsigned int &instruction_number)
308 309
  {
    CompileCode.write(reinterpret_cast<char *>(this), sizeof(TagWithOneArgument));
310
    instruction_number++;
311
  };
312 313 314 315 316 317 318 319 320 321
};

template < class T1, class T2 >
class TagWithTwoArguments
{
protected:
  uint8_t op_code;
  T1 arg1;
  T2 arg2;
public:
322 323
  inline
  TagWithTwoArguments(uint8_t op_code_arg) : op_code(op_code_arg)
324 325
  {
  };
326 327
  inline
  TagWithTwoArguments(uint8_t op_code_arg, T1 arg_arg1, T2 arg_arg2) : op_code(op_code_arg), arg1(arg_arg1), arg2(arg_arg2)
328 329 330
  {
  };
  inline void
331
  write(ostream &CompileCode, unsigned int &instruction_number)
332 333
  {
    CompileCode.write(reinterpret_cast<char *>(this), sizeof(*this));
334
    instruction_number++;
335
  };
336 337 338 339 340 341 342 343 344 345 346
};

template < class T1, class T2, class T3 >
class TagWithThreeArguments
{
protected:
  uint8_t op_code;
  T1 arg1;
  T2 arg2;
  T3 arg3;
public:
347 348
  inline
  TagWithThreeArguments(uint8_t op_code_arg) : op_code(op_code_arg)
349 350
  {
  };
351 352
  inline
  TagWithThreeArguments(uint8_t op_code_arg, T1 arg_arg1, T2 arg_arg2, T3 arg_arg3) : op_code(op_code_arg), arg1(arg_arg1), arg2(arg_arg2), arg3(arg_arg3)
353 354 355
  {
  };
  inline void
356
  write(ostream &CompileCode, unsigned int &instruction_number)
357 358
  {
    CompileCode.write(reinterpret_cast<char *>(this), sizeof(*this));
359
    instruction_number++;
360
  };
361 362
};

363 364 365 366 367 368 369 370 371 372
template < class T1, class T2, class T3, class T4 >
class TagWithFourArguments
{
protected:
  uint8_t op_code;
  T1 arg1;
  T2 arg2;
  T3 arg3;
  T4 arg4;
public:
373 374
  inline
  TagWithFourArguments(uint8_t op_code_arg) : op_code(op_code_arg)
375 376
  {
  };
377 378
  inline
  TagWithFourArguments(uint8_t op_code_arg, T1 arg_arg1, T2 arg_arg2, T3 arg_arg3, T4 arg_arg4) : op_code(op_code_arg), arg1(arg_arg1), arg2(arg_arg2), arg3(arg_arg3), arg4(arg_arg4)
379 380 381 382 383 384 385 386 387 388
  {
  };
  inline void
  write(ostream &CompileCode, unsigned int &instruction_number)
  {
    CompileCode.write(reinterpret_cast<char *>(this), sizeof(*this));
    instruction_number++;
  };
};

389 390 391
class FLDZ_ : public TagWithoutArgument
{
public:
392 393
  inline
  FLDZ_() : TagWithoutArgument(FLDZ)
394 395
  {
  };
396 397 398 399 400
};

class FEND_ : public TagWithoutArgument
{
public:
401 402
  inline
  FEND_() : TagWithoutArgument(FEND)
403 404
  {
  };
405 406 407 408 409
};

class FENDBLOCK_ : public TagWithoutArgument
{
public:
410 411
  inline
  FENDBLOCK_() : TagWithoutArgument(FENDBLOCK)
412 413
  {
  };
414 415 416 417 418
};

class FENDEQU_ : public TagWithoutArgument
{
public:
419 420
  inline
  FENDEQU_() : TagWithoutArgument(FENDEQU)
421 422
  {
  };
423 424 425 426 427
};

class FCUML_ : public TagWithoutArgument
{
public:
428 429
  inline
  FCUML_() : TagWithoutArgument(FCUML)
430 431
  {
  };
432 433
};

434 435 436
class FPUSH_ : public TagWithoutArgument
{
public:
437 438
  inline
  FPUSH_() : TagWithoutArgument(FPUSH)
439 440 441 442 443 444 445
  {
  };
};

class FPOP_ : public TagWithoutArgument
{
public:
446 447
  inline
  FPOP_() : TagWithoutArgument(FPOP)
448 449 450 451
  {
  };
};

452 453 454
class FDIMT_ : public TagWithOneArgument<unsigned int>
{
public:
455 456
  inline
  FDIMT_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FDIMT)
457 458
  {
  };
459 460
  inline
  FDIMT_(unsigned int size_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FDIMT, size_arg)
461 462 463 464 465 466 467
  {
  };
  inline unsigned int
  get_size()
  {
    return arg1;
  };
468 469 470 471 472
};

class FDIMST_ : public TagWithOneArgument<unsigned int>
{
public:
473 474
  inline
  FDIMST_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FDIMST)
475 476
  {
  };
477 478
  inline
  FDIMST_(const unsigned int size_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FDIMST, size_arg)
479 480 481 482 483 484 485
  {
  };
  inline unsigned int
  get_size()
  {
    return arg1;
  };
486 487 488 489 490
};

class FLDC_ : public TagWithOneArgument<double>
{
public:
491 492
  inline
  FLDC_() : TagWithOneArgument<double>::TagWithOneArgument(FLDC)
493 494
  {
  };
495 496
  inline
  FLDC_(const double value_arg) : TagWithOneArgument<double>::TagWithOneArgument(FLDC, value_arg)
497 498 499 500 501 502 503
  {
  };
  inline double
  get_value()
  {
    return arg1;
  };
504 505 506 507 508
};

class FLDU_ : public TagWithOneArgument<unsigned int>
{
public:
509 510
  inline
  FLDU_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDU)
511 512
  {
  };
513 514
  inline
  FLDU_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDU, pos_arg)
515 516 517 518 519 520 521
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
522 523 524 525 526
};

class FLDSU_ : public TagWithOneArgument<unsigned int>
{
public:
527 528
  inline
  FLDSU_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDSU)
529 530
  {
  };
531 532
  inline
  FLDSU_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDSU, pos_arg)
533 534 535 536 537 538 539
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
540 541 542 543 544
};

class FLDR_ : public TagWithOneArgument<unsigned int>
{
public:
545 546
  inline
  FLDR_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDR)
547 548
  {
  };
549 550
  inline
  FLDR_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDR, pos_arg)
551 552 553 554 555 556 557
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
558 559 560 561 562
};

class FLDT_ : public TagWithOneArgument<unsigned int>
{
public:
563 564
  inline
  FLDT_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDT)
565 566
  {
  };
567 568
  inline
  FLDT_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDT, pos_arg)
569 570 571 572 573 574 575
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
576 577 578 579 580
};

class FLDST_ : public TagWithOneArgument<unsigned int>
{
public:
581 582
  inline
  FLDST_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDST)
583 584
  {
  };
585 586
  inline
  FLDST_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDST, pos_arg)
587 588 589 590 591 592 593
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
594 595 596 597 598
};

class FSTPT_ : public TagWithOneArgument<unsigned int>
{
public:
599 600
  inline
  FSTPT_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPT)
601 602
  {
  };
603 604
  inline
  FSTPT_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPT, pos_arg)
605 606 607 608 609 610 611
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
612 613 614 615 616
};

class FSTPST_ : public TagWithOneArgument<unsigned int>
{
public:
617 618
  inline
  FSTPST_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPST)
619 620
  {
  };
621 622
  inline
  FSTPST_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPST, pos_arg)
623 624 625 626 627 628 629
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
630 631 632 633 634
};

class FSTPR_ : public TagWithOneArgument<unsigned int>
{
public:
635 636
  inline
  FSTPR_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPR)
637 638
  {
  };
639 640
  inline
  FSTPR_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPR, pos_arg)
641 642 643 644 645 646 647
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
648 649 650 651 652
};

class FSTPU_ : public TagWithOneArgument<unsigned int>
{
public:
653 654
  inline
  FSTPU_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPU)
655 656
  {
  };
657 658
  inline
  FSTPU_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPU, pos_arg)
659 660 661 662 663 664 665
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
666 667 668 669 670
};

class FSTPSU_ : public TagWithOneArgument<unsigned int>
{
public:
671 672
  inline
  FSTPSU_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPSU)
673 674
  {
  };
675 676
  inline
  FSTPSU_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPSU, pos_arg)
677 678 679 680 681 682 683
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
684 685 686 687 688
};

class FSTPG_ : public TagWithOneArgument<unsigned int>
{
public:
689 690
  inline
  FSTPG_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPG, 0)
691 692
  {
  };
693 694
  inline
  FSTPG_(const unsigned int pos_arg) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPG, pos_arg)
695 696 697 698 699 700 701
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  };
702 703
};

704 705 706
class FSTPG2_ : public TagWithTwoArguments<unsigned int, unsigned int>
{
public:
707 708
  inline
  FSTPG2_() : TagWithTwoArguments<unsigned int, unsigned int>::TagWithTwoArguments(FSTPG2, 0, 0)
709 710
  {
  };
711 712
  inline
  FSTPG2_(const unsigned int pos_arg1, const unsigned int pos_arg2) : TagWithTwoArguments<unsigned int, unsigned int>::TagWithTwoArguments(FSTPG2, pos_arg1, pos_arg2)
713 714 715 716 717 718 719 720 721 722 723 724 725 726
  {
  };
  inline unsigned int
  get_row()
  {
    return arg1;
  };
  inline unsigned int
  get_col()
  {
    return arg2;
  };
};

727 728 729
class FSTPG3_ : public TagWithFourArguments<unsigned int, unsigned int, int, unsigned int>
{
public:
730 731
  inline
  FSTPG3_() : TagWithFourArguments<unsigned int, unsigned int, int, unsigned int>::TagWithFourArguments(FSTPG3, 0, 0, 0, 0)
732 733
  {
  };
734 735
  inline
  FSTPG3_(const unsigned int pos_arg1, const unsigned int pos_arg2, const int pos_arg3, const unsigned int pos_arg4) : TagWithFourArguments<unsigned int, unsigned int, int, unsigned int>::TagWithFourArguments(FSTPG3, pos_arg1, pos_arg2, pos_arg3, pos_arg4)
736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
  {
  };
  inline unsigned int
  get_row()
  {
    return arg1;
  };
  inline unsigned int
  get_col()
  {
    return arg2;
  };
  inline int
  get_lag()
  {
    return arg2;
  };
  inline unsigned int
  get_col_pos()
  {
    return arg4;
  };
};
759

760 761 762
class FUNARY_ : public TagWithOneArgument<uint8_t>
{
public:
763 764
  inline
  FUNARY_() : TagWithOneArgument<uint8_t>::TagWithOneArgument(FUNARY)
765 766
  {
  };
767 768
  inline
  FUNARY_(uint8_t op_type_arg) : TagWithOneArgument<uint8_t>::TagWithOneArgument(FUNARY, op_type_arg)
769 770 771 772 773 774 775
  {
  };
  inline uint8_t
  get_op_type()
  {
    return arg1;
  };
776 777 778 779 780
};

class FBINARY_ : public TagWithOneArgument<uint8_t>
{
public:
781 782
  inline
  FBINARY_() : TagWithOneArgument<uint8_t>::TagWithOneArgument(FBINARY)
783 784
  {
  };
785 786
  inline
  FBINARY_(const int op_type_arg) : TagWithOneArgument<uint8_t>::TagWithOneArgument(FBINARY, op_type_arg)
787 788 789 790 791 792 793
  {
  };
  inline uint8_t
  get_op_type()
  {
    return arg1;
  };
794 795
};

796 797 798
class FTRINARY_ : public TagWithOneArgument<uint8_t>
{
public:
799 800
  inline
  FTRINARY_() : TagWithOneArgument<uint8_t>::TagWithOneArgument(FTRINARY)
801 802
  {
  };
803 804
  inline
  FTRINARY_(const int op_type_arg) : TagWithOneArgument<uint8_t>::TagWithOneArgument(FTRINARY, op_type_arg)
805 806 807 808 809 810 811 812 813
  {
  };
  inline uint8_t
  get_op_type()
  {
    return arg1;
  };
};

814 815 816
class FOK_ : public TagWithOneArgument<int>
{
public:
817 818
  inline
  FOK_() : TagWithOneArgument<int>::TagWithOneArgument(FOK)
819 820
  {
  };
821 822
  inline
  FOK_(const int arg_arg) : TagWithOneArgument<int>::TagWithOneArgument(FOK, arg_arg)
823 824 825 826 827 828 829
  {
  };
  inline int
  get_arg()
  {
    return arg1;
  };
830 831
};

832 833 834
class FJMPIFEVAL_ : public TagWithOneArgument<unsigned int>
{
public:
835 836
  inline
  FJMPIFEVAL_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FJMPIFEVAL)
837 838
  {
  };
839 840
  inline
  FJMPIFEVAL_(unsigned int arg_pos) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FJMPIFEVAL, arg_pos)
841 842 843 844 845 846 847 848 849 850 851 852
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  }
};

class FJMP_ : public TagWithOneArgument<unsigned int>
{
public:
853 854
  inline
  FJMP_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FJMP)
855 856
  {
  };
857 858
  inline
  FJMP_(unsigned int arg_pos) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FJMP, arg_pos)
859 860 861 862 863 864 865 866 867
  {
  };
  inline unsigned int
  get_pos()
  {
    return arg1;
  }
};

868 869 870
class FLDTEF_ : public TagWithOneArgument<unsigned int>
{
public:
871 872
  inline
  FLDTEF_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDTEF)
873 874
  {
  };
875 876
  inline
  FLDTEF_(unsigned int number) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FLDTEF, number)
877 878 879 880 881 882 883 884 885 886 887 888
  {
  };
  inline unsigned int
  get_number()
  {
    return arg1;
  }
};

class FSTPTEF_ : public TagWithOneArgument<unsigned int>
{
public:
889 890
  inline
  FSTPTEF_() : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPTEF)
891 892
  {
  };
893 894
  inline
  FSTPTEF_(unsigned int number) : TagWithOneArgument<unsigned int>::TagWithOneArgument(FSTPTEF, number)
895 896 897 898 899 900 901 902 903 904 905 906
  {
  };
  inline unsigned int
  get_number()
  {
    return arg1;
  }
};

class FLDTEFD_ : public TagWithTwoArguments<unsigned int, unsigned int>
{
public:
907 908
  inline
  FLDTEFD_() : TagWithTwoArguments<unsigned int, unsigned int>::TagWithTwoArguments(FLDTEFD)
909 910
  {
  };
911 912
  inline
  FLDTEFD_(unsigned int indx, unsigned int row) : TagWithTwoArguments<unsigned int, unsigned int>::TagWithTwoArguments(FLDTEFD, indx, row)
913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929
  {
  };
  inline unsigned int
  get_indx()
  {
    return arg1;
  };
  inline unsigned int
  get_row()
  {
    return arg2;
  };
};

class FSTPTEFD_ : public TagWithTwoArguments<unsigned int, unsigned int>
{
public:
930 931
  inline
  FSTPTEFD_() : TagWithTwoArguments<unsigned int, unsigned int>::TagWithTwoArguments(FSTPTEFD)
932 933
  {
  };
934 935
  inline
  FSTPTEFD_(unsigned int indx, unsigned int row) : TagWithTwoArguments<unsigned int, unsigned int>::TagWithTwoArguments(FSTPTEFD, indx, row)
936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
  {
  };
  inline unsigned int
  get_indx()
  {
    return arg1;
  };
  inline unsigned int
  get_row()
  {
    return arg2;
  };
};

class FLDTEFDD_ : public TagWithThreeArguments<unsigned int, unsigned int, unsigned int>
{
public:
953 954
  inline
  FLDTEFDD_() : TagWithThreeArguments<unsigned int, unsigned int, unsigned int>::TagWithThreeArguments(FLDTEFDD)
955 956
  {
  };
957 958
  inline
  FLDTEFDD_(unsigned int indx, unsigned int row, unsigned int col) : TagWithThreeArguments<unsigned int, unsigned int, unsigned int>::TagWithThreeArguments(FLDTEFDD, indx, row, col)
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980
  {
  };
  inline unsigned int
  get_indx()
  {
    return arg1;
  };
  inline unsigned int
  get_row()
  {
    return arg2;
  };
  inline unsigned int
  get_col()
  {
    return arg3;
  };
};

class FSTPTEFDD_ : public TagWithThreeArguments<unsigned int, unsigned int, unsigned int>
{
public:
981 982
  inline
  FSTPTEFDD_() : TagWithThreeArguments<unsigned int, unsigned int, unsigned int>::TagWithThreeArguments(FSTPTEFDD)
983 984
  {
  };
985 986
  inline
  FSTPTEFDD_(unsigned int indx, unsigned int row, unsigned int col) : TagWithThreeArguments<unsigned int, unsigned int, unsigned int>::TagWithThreeArguments(FSTPTEF, indx, row, col)
987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
  {
  };
  inline unsigned int
  get_indx()
  {
    return arg1;
  };
  inline unsigned int
  get_row()
  {
    return arg2;
  };
  inline unsigned int
  get_col()
  {
    return arg3;
  };
};

1006 1007 1008
class FLDVS_ : public TagWithTwoArguments<uint8_t, unsigned int>
{
public:
1009 1010
  inline
  FLDVS_() : TagWithTwoArguments<uint8_t, unsigned int>::TagWithTwoArguments(FLDVS)
1011 1012
  {
  };
1013 1014
  inline
  FLDVS_(uint8_t type_arg, const unsigned int pos_arg) : TagWithTwoArguments<uint8_t, unsigned int>::TagWithTwoArguments(FLDVS, type_arg, pos_arg)
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
  {
  };
  inline uint8_t
  get_type()
  {
    return arg1;
  };
  inline unsigned int
  get_pos()
  {
    return arg2;
  };
1027 1028 1029 1030 1031
};

class FLDSV_ : public TagWithTwoArguments<uint8_t, unsigned int>
{
public:
1032 1033
  inline
  FLDSV_() : TagWithTwoArguments<uint8_t, unsigned int>::TagWithTwoArguments(FLDSV)
1034 1035
  {
  };
1036 1037
  inline
  FLDSV_(const uint8_t type_arg, const unsigned int pos_arg) :
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050
    TagWithTwoArguments<uint8_t, unsigned int>::TagWithTwoArguments(FLDSV, type_arg, pos_arg)
  {
  };
  inline uint8_t
  get_type()
  {
    return arg1;
  };
  inline unsigned int
  get_pos()
  {
    return arg2;
  };
1051 1052 1053 1054 1055
};

class FSTPSV_ : public TagWithTwoArguments<uint8_t, unsigned int>
{
public:
1056 1057
  inline
  FSTPSV_() : TagWithTwoArguments<uint8_t, unsigned int>::TagWithTwoArguments(FSTPSV)
1058 1059
  {
  };
1060 1061
  inline
  FSTPSV_(const uint8_t type_arg, const unsigned int pos_arg) :
1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
    TagWithTwoArguments<uint8_t, unsigned int>::TagWithTwoArguments(FSTPSV, type_arg, pos_arg)
  {
  };
  inline uint8_t
  get_type()
  {
    return arg1;
  };
  inline unsigned int
  get_pos()
  {
    return arg2;
  };
1075 1076 1077 1078 1079
};

class FLDV_ : public TagWithThreeArguments<uint8_t, unsigned int, int>
{
public:
1080 1081
  inline
  FLDV_() : TagWithThreeArguments<uint8_t, unsigned int, int>::TagWithThreeArguments(FLDV)
1082 1083
  {
  };
1084 1085
  inline
  FLDV_(const int type_arg, const unsigned int pos_arg) :
1086 1087 1088
    TagWithThreeArguments<uint8_t, unsigned int, int>::TagWithThreeArguments(FLDV, type_arg, pos_arg, 0)
  {
  };
1089 1090
  inline
  FLDV_(const int type_arg, const unsigned int pos_arg, const int lead_lag_arg) :
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108
    TagWithThreeArguments<uint8_t, unsigned int, int>::TagWithThreeArguments(FLDV, type_arg, pos_arg, lead_lag_arg)
  {
  };
  inline uint8_t
  get_type()
  {
    return arg1;
  };
  inline unsigned int
  get_pos()
  {
    return arg2;
  };
  inline int
  get_lead_lag()
  {
    return arg3;
  };
1109 1110 1111 1112 1113
};

class FSTPV_ : public TagWithThreeArguments<uint8_t, unsigned int, int>
{
public:
1114 1115
  inline
  FSTPV_() : TagWithThreeArguments<uint8_t, unsigned int, int>::TagWithThreeArguments(FSTPV)
1116 1117
  {
  };
1118 1119
  inline
  FSTPV_(const int type_arg, const unsigned int pos_arg) :
1120 1121 1122
    TagWithThreeArguments<uint8_t, unsigned int, int>::TagWithThreeArguments(FSTPV, type_arg, pos_arg, 0)
  {
  };
1123 1124
  inline
  FSTPV_(const int type_arg, const unsigned int pos_arg, const int lead_lag_arg) :
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
    TagWithThreeArguments<uint8_t, unsigned int, int>::TagWithThreeArguments(FSTPV, type_arg, pos_arg, lead_lag_arg)
  {
  };
  inline uint8_t
  get_type()
  {
    return arg1;
  };
  inline unsigned int
  get_pos()
  {
    return arg2;
  };
  inline int
  get_lead_lag()
  {
    return arg3;
  };
1143 1144
};

1145 1146 1147 1148 1149 1150 1151
class FCALL_ : public TagWithFourArguments<unsigned int, unsigned int, string, unsigned int>
{
  string func_name;
  string arg_func_name;
  unsigned int add_input_arguments, row, col;
  external_function_type function_type;
public:
1152 1153
  inline
  FCALL_() : TagWithFourArguments<unsigned int, unsigned int, string, unsigned int>::TagWithFourArguments(FCALL)
1154 1155 1156 1157 1158 1159 1160
  {
    arg_func_name = "";
    add_input_arguments = 0;
    row = 0;
    col = 0;
    function_type = ExternalFunctionWithoutDerivative;
  };
1161 1162
  inline
  FCALL_(unsigned int nb_output_arguments, unsigned int nb_input_arguments, string f_name, unsigned int indx) :
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
    TagWithFourArguments<unsigned int, unsigned int, string, unsigned int>::TagWithFourArguments(FCALL, nb_output_arguments, nb_input_arguments, f_name, indx)
  {
    arg_func_name = "";
    add_input_arguments = 0;
    row = 0;
    col = 0;
    function_type = ExternalFunctionWithoutDerivative;
    func_name = f_name;
  };
  inline string
  get_function_name()
  {
    //printf("get_function_name => func_name=%s\n",func_name.c_str());fflush(stdout);
    return func_name;
  };
  inline unsigned int
  get_nb_output_arguments()
  {
    return arg1;
  };
  inline unsigned int
  get_nb_input_arguments()
  {
    return arg2;
  };
  inline unsigned int
  get_indx()
  {
    return arg4;
  };
  inline void
  set_arg_func_name(string arg_arg_func_name)
  {
    arg_func_name = arg_arg_func_name;
  };
  inline string
  get_arg_func_name()
  {
    return arg_func_name;
  };
  inline void
  set_nb_add_input_arguments(unsigned int arg_add_input_arguments)
  {
    add_input_arguments = arg_add_input_arguments;
  };
  inline unsigned int
  get_nb_add_input_arguments()
  {
    return add_input_arguments;
  };
  inline void
  set_row(unsigned int arg_row)
  {
    row = arg_row;
  };
  inline unsigned int
  get_row()
  {
    return row;
  }
  inline void
  set_col(unsigned int arg_col)
  {
    col = arg_col;
  };
  inline unsigned int
  get_col()
  {
    return col;
  };
  inline void
  set_function_type(external_function_type arg_function_type)