2008-02-03 11:28:36 +01:00
|
|
|
|
/*
|
2023-01-05 16:40:04 +01:00
|
|
|
|
* Copyright © 2007-2023 Dynare Team
|
2008-02-03 11:28:36 +01:00
|
|
|
|
*
|
|
|
|
|
* 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
|
2021-06-09 16:52:20 +02:00
|
|
|
|
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-02-03 11:28:36 +01:00
|
|
|
|
*/
|
|
|
|
|
|
2023-12-01 15:39:01 +01:00
|
|
|
|
#ifndef BYTECODE_HH
|
|
|
|
|
#define BYTECODE_HH
|
2014-12-17 09:37:43 +01:00
|
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
|
#include <filesystem>
|
2009-10-16 18:34:27 +02:00
|
|
|
|
#include <fstream>
|
2022-06-23 14:28:13 +02:00
|
|
|
|
#include <ios>
|
2023-02-17 22:20:40 +01:00
|
|
|
|
#include <type_traits>
|
2023-11-30 15:28:57 +01:00
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
2022-06-23 14:28:13 +02:00
|
|
|
|
|
|
|
|
|
#include "CommonEnums.hh"
|
2022-06-16 17:52:14 +02:00
|
|
|
|
|
2009-10-16 18:34:27 +02:00
|
|
|
|
using namespace std;
|
|
|
|
|
|
2023-12-14 14:52:50 +01:00
|
|
|
|
namespace Bytecode
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// The different tags encoding a bytecode instruction
|
2023-12-14 16:17:22 +01:00
|
|
|
|
enum class Tag
|
2023-11-30 15:28:57 +01:00
|
|
|
|
{
|
|
|
|
|
FLDZ, // Loads a zero onto the stack
|
|
|
|
|
FLDC, // Loads a constant term onto the stack
|
|
|
|
|
|
|
|
|
|
FDIMT, // Defines the number of temporary terms - dynamic context (the period has to be indicated)
|
|
|
|
|
FDIMST, // Defines the number of temporary terms - static context (the period hasn’t to be
|
|
|
|
|
// indicated)
|
|
|
|
|
FLDT, // Loads a temporary term onto the stack - dynamic context (the period has to be indicated)
|
|
|
|
|
FLDST, // Loads a temporary term onto the stack - static context (the period hasn’t to be
|
|
|
|
|
// indicated)
|
|
|
|
|
FSTPT, // Stores a temporary term from the stack - dynamic context (the period has to be
|
|
|
|
|
// indicated)
|
|
|
|
|
FSTPST, // Stores a temporary term from the stack - static context (the period hasn’t to be
|
|
|
|
|
// indicated)
|
|
|
|
|
|
|
|
|
|
FLDU, // Loads an element of the vector U onto the stack - dynamic context (the period has to be
|
|
|
|
|
// indicated)
|
|
|
|
|
FLDSU, // Loads an element of the vector U onto the stack - static context (the period hasn’t to
|
|
|
|
|
// be indicated)
|
|
|
|
|
FSTPU, // Stores an element of the vector U from the stack - dynamic context (the period has to be
|
|
|
|
|
// indicated)
|
|
|
|
|
FSTPSU, // Stores an element of the vector U from the stack - static context (the period hasn’t to
|
|
|
|
|
// be indicated)
|
|
|
|
|
|
|
|
|
|
FLDV, // Loads a variable (described in SymbolType) onto the stack - dynamic context (the period
|
|
|
|
|
// has to be indicated)
|
|
|
|
|
FLDSV, // Loads a variable (described in SymbolType) onto the stack - static context (the period
|
|
|
|
|
// hasn’t to be indicated)
|
|
|
|
|
FLDVS, // Loads a variable (described in SymbolType) onto the stack - dynamic context but inside
|
|
|
|
|
// the STEADY_STATE operator (the period hasn’t to be indicated)
|
|
|
|
|
FSTPV, // Stores a variable (described in SymbolType) from the stack - dynamic context (the period
|
|
|
|
|
// has to be indicated)
|
|
|
|
|
FSTPSV, // Stores a variable (described in SymbolType) from the stack - static context (the period
|
|
|
|
|
// hasn’t to be indicated)
|
|
|
|
|
|
|
|
|
|
FLDR, // Loads a residual onto the stack
|
|
|
|
|
FSTPR, // Stores a residual from the stack
|
|
|
|
|
|
|
|
|
|
FSTPG, // Stores a derivative from the stack
|
|
|
|
|
FSTPG2, // Stores a derivative matrix for a static model from the stack
|
|
|
|
|
FSTPG3, // Stores a derivative matrix for a dynamic model from the stack
|
|
|
|
|
|
|
|
|
|
FUNARY, // A unary operator
|
|
|
|
|
FBINARY, // A binary operator
|
|
|
|
|
FTRINARY, // A trinary operator
|
|
|
|
|
|
|
|
|
|
FJMPIFEVAL, // Jump if evaluate = true
|
|
|
|
|
FJMP, // Jump
|
|
|
|
|
|
|
|
|
|
FBEGINBLOCK, // Marks the beginning of a model block
|
|
|
|
|
FENDBLOCK, // Marks the end of a model block
|
|
|
|
|
FENDEQU, // Marks the last equation of the block; for a block that has to be solved, the
|
|
|
|
|
// derivatives appear just after this flag
|
|
|
|
|
FEND, // Marks the end of the model code
|
|
|
|
|
|
|
|
|
|
FNUMEXPR, // Stores the expression type and references
|
|
|
|
|
|
|
|
|
|
FCALL, // Call an external function
|
|
|
|
|
FLDTEF, // Loads the result of an external function onto the stack
|
|
|
|
|
FSTPTEF, // Stores the result of an external function from the stack
|
|
|
|
|
FLDTEFD, // Loads the result of the 1st derivative of an external function onto the stack
|
|
|
|
|
FSTPTEFD, // Stores the result of the 1st derivative of an external function from the stack
|
|
|
|
|
FLDTEFDD, // Loads the result of the 2nd derivative of an external function onto the stack
|
|
|
|
|
FSTPTEFDD // Stores the result of the 2nd derivative of an external function from the stack
|
|
|
|
|
};
|
2008-02-03 11:28:36 +01:00
|
|
|
|
|
2021-02-01 11:10:59 +01:00
|
|
|
|
enum class ExpressionType
|
2023-11-30 15:28:57 +01:00
|
|
|
|
{
|
|
|
|
|
TemporaryTerm,
|
|
|
|
|
ModelEquation,
|
|
|
|
|
FirstEndoDerivative,
|
|
|
|
|
FirstExoDerivative,
|
|
|
|
|
FirstExodetDerivative,
|
|
|
|
|
};
|
2010-01-22 17:42:08 +01:00
|
|
|
|
|
2022-07-08 16:00:02 +02:00
|
|
|
|
enum class ExternalFunctionCallType
|
2023-11-30 15:28:57 +01:00
|
|
|
|
{
|
|
|
|
|
levelWithoutDerivative,
|
|
|
|
|
levelWithFirstDerivative,
|
|
|
|
|
levelWithFirstAndSecondDerivative,
|
|
|
|
|
separatelyProvidedFirstDerivative,
|
|
|
|
|
numericalFirstDerivative,
|
|
|
|
|
separatelyProvidedSecondDerivative,
|
|
|
|
|
numericalSecondDerivative
|
|
|
|
|
};
|
2022-07-08 16:00:02 +02:00
|
|
|
|
|
2009-12-16 18:13:23 +01:00
|
|
|
|
struct Block_contain_type
|
|
|
|
|
{
|
|
|
|
|
int Equation, Variable, Own_Derivative;
|
|
|
|
|
};
|
2009-10-16 18:34:27 +02:00
|
|
|
|
|
2023-12-14 14:52:50 +01:00
|
|
|
|
class Writer;
|
2022-06-23 14:28:13 +02:00
|
|
|
|
|
2023-12-14 14:52:50 +01:00
|
|
|
|
struct Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 16:17:22 +01:00
|
|
|
|
const Tag tag;
|
|
|
|
|
explicit Instruction(Tag tag_arg) : tag {tag_arg}
|
2023-09-01 13:50:57 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
2023-11-30 15:28:57 +01:00
|
|
|
|
|
2023-09-01 13:50:57 +02:00
|
|
|
|
protected:
|
|
|
|
|
/* This is a base class, so the destructor should be either public+virtual or
|
|
|
|
|
protected+non-virtual. We opt for the latter, because otherwise this class
|
|
|
|
|
would no longer be POD; its memory representation would also include
|
|
|
|
|
runtime type information, and our crude serialization technique (copying the
|
|
|
|
|
whole object from memory) would thus not work. */
|
2023-12-14 14:52:50 +01:00
|
|
|
|
~Instruction() = default;
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDZ final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FLDZ() : Instruction {Tag::FLDZ}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FEND final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FEND() : Instruction {Tag::FEND}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FENDBLOCK final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FENDBLOCK() : Instruction {Tag::FENDBLOCK}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FENDEQU final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FENDEQU() : Instruction {Tag::FENDEQU}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FDIMT final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int size;
|
|
|
|
|
explicit FDIMT(int size_arg) : Instruction {Tag::FDIMT}, size {size_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FDIMST final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int size;
|
|
|
|
|
explicit FDIMST(int size_arg) : Instruction {Tag::FDIMST}, size {size_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDC final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const double value;
|
|
|
|
|
explicit FLDC(double value_arg) : Instruction {Tag::FLDC}, value {value_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDU final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FLDU(int pos_arg) : Instruction {Tag::FLDU}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDSU final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FLDSU(int pos_arg) : Instruction {Tag::FLDSU}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDR final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FLDR(int pos_arg) : Instruction {Tag::FLDR}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDT final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FLDT(int pos_arg) : Instruction {Tag::FLDT}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDST final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FLDST(int pos_arg) : Instruction {Tag::FLDST}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPT final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FSTPT(int pos_arg) : Instruction {Tag::FSTPT}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPST final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FSTPST(int pos_arg) : Instruction {Tag::FSTPST}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPR final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FSTPR(int pos_arg) : Instruction {Tag::FSTPR}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPU final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FSTPU(int pos_arg) : Instruction {Tag::FSTPU}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPSU final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FSTPSU(int pos_arg) : Instruction {Tag::FSTPSU}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPG final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FSTPG(int pos_arg) : Instruction {Tag::FSTPG}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPG2 final : public Instruction
|
2010-01-22 11:03:29 +01:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int row, col;
|
|
|
|
|
FSTPG2(int row_arg, int col_arg) : Instruction {Tag::FSTPG2}, row {row_arg}, col {col_arg}
|
2010-01-22 11:03:29 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-01-22 11:03:29 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPG3 final : public Instruction
|
2010-07-23 11:20:24 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int row, col, lag, col_pos;
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FSTPG3(int row_arg, int col_arg, int lag_arg, int col_pos_arg) :
|
2023-12-14 17:07:06 +01:00
|
|
|
|
Instruction {Tag::FSTPG3}, row {row_arg}, col {col_arg}, lag {lag_arg}, col_pos {col_pos_arg}
|
2010-07-23 11:20:24 +02:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-07-23 11:20:24 +02:00
|
|
|
|
};
|
2010-01-22 11:03:29 +01:00
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FUNARY final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const UnaryOpcode op_code;
|
|
|
|
|
explicit FUNARY(UnaryOpcode op_code_arg) : Instruction {Tag::FUNARY}, op_code {op_code_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FBINARY final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const BinaryOpcode op_code;
|
|
|
|
|
explicit FBINARY(BinaryOpcode op_code_arg) : Instruction {Tag::FBINARY}, op_code {op_code_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FTRINARY final : public Instruction
|
2010-04-16 16:54:55 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const TrinaryOpcode op_code;
|
|
|
|
|
explicit FTRINARY(TrinaryOpcode op_code_arg) : Instruction {Tag::FTRINARY}, op_code {op_code_arg}
|
2010-04-16 16:54:55 +02:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-04-16 16:54:55 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FJMPIFEVAL final : public Instruction
|
2010-07-23 11:20:24 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FJMPIFEVAL(int pos_arg) : Instruction {Tag::FJMPIFEVAL}, pos {pos_arg}
|
2010-07-23 11:20:24 +02:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FJMP final : public Instruction
|
2010-07-23 11:20:24 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int pos;
|
|
|
|
|
explicit FJMP(int pos_arg) : Instruction {Tag::FJMP}, pos {pos_arg}
|
2010-07-23 11:20:24 +02:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-07-23 11:20:24 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDTEF final : public Instruction
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int number;
|
|
|
|
|
explicit FLDTEF(int number_arg) : Instruction {Tag::FLDTEF}, number {number_arg}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPTEF final : public Instruction
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int number;
|
|
|
|
|
explicit FSTPTEF(int number_arg) : Instruction {Tag::FSTPTEF}, number {number_arg}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDTEFD final : public Instruction
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int indx, row;
|
|
|
|
|
FLDTEFD(int indx_arg, int row_arg) : Instruction {Tag::FLDTEFD}, indx {indx_arg}, row {row_arg}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPTEFD final : public Instruction
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int indx, row;
|
|
|
|
|
FSTPTEFD(int indx_arg, int row_arg) : Instruction {Tag::FSTPTEFD}, indx {indx_arg}, row {row_arg}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDTEFDD final : public Instruction
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int indx, row, col;
|
|
|
|
|
FLDTEFDD(int indx_arg, int row_arg, int col_arg) :
|
|
|
|
|
Instruction {Tag::FLDTEFDD}, indx {indx_arg}, row {row_arg}, col {col_arg}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPTEFDD final : public Instruction
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const int indx, row, col;
|
|
|
|
|
FSTPTEFDD(int indx_arg, int row_arg, int col_arg) :
|
|
|
|
|
Instruction {Tag::FSTPTEF}, indx {indx_arg}, row {row_arg}, col {col_arg}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDVS final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const SymbolType type;
|
|
|
|
|
const int pos;
|
|
|
|
|
FLDVS(SymbolType type_arg, int pos_arg) : Instruction {Tag::FLDVS}, type {type_arg}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDSV final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const SymbolType type;
|
|
|
|
|
const int pos;
|
|
|
|
|
FLDSV(SymbolType type_arg, int pos_arg) : Instruction {Tag::FLDSV}, type {type_arg}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPSV final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const SymbolType type;
|
|
|
|
|
const int pos;
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FSTPSV(SymbolType type_arg, int pos_arg) :
|
2023-12-14 17:07:06 +01:00
|
|
|
|
Instruction {Tag::FSTPSV}, type {type_arg}, pos {pos_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FLDV final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const SymbolType type;
|
|
|
|
|
const int pos, lead_lag;
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FLDV(SymbolType type_arg, int pos_arg, int lead_lag_arg) :
|
2023-12-14 17:07:06 +01:00
|
|
|
|
Instruction {Tag::FLDV}, type {type_arg}, pos {pos_arg}, lead_lag {lead_lag_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 17:07:06 +01:00
|
|
|
|
struct FSTPV final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2023-12-14 17:07:06 +01:00
|
|
|
|
const SymbolType type;
|
|
|
|
|
const int pos, lead_lag;
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FSTPV(SymbolType type_arg, int pos_arg, int lead_lag_arg) :
|
2023-12-14 17:07:06 +01:00
|
|
|
|
Instruction {Tag::FSTPV}, type {type_arg}, pos {pos_arg}, lead_lag {lead_lag_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 16:17:22 +01:00
|
|
|
|
class FCALL final : public Instruction
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
2022-06-23 14:28:13 +02:00
|
|
|
|
template<typename B>
|
2023-12-14 14:52:50 +01:00
|
|
|
|
friend Writer& operator<<(Writer& code_file, const B& instr);
|
2023-11-30 15:28:57 +01:00
|
|
|
|
|
2022-06-23 14:28:13 +02:00
|
|
|
|
private:
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int nb_output_arguments, nb_input_arguments, indx;
|
2010-12-10 11:50:27 +01:00
|
|
|
|
string func_name;
|
|
|
|
|
string arg_func_name;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
int add_input_arguments {0}, row {0}, col {0};
|
2022-07-08 16:00:02 +02:00
|
|
|
|
ExternalFunctionCallType call_type;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
|
2010-12-10 11:50:27 +01:00
|
|
|
|
public:
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FCALL(int nb_output_arguments_arg, int nb_input_arguments_arg, string func_name_arg, int indx_arg,
|
|
|
|
|
ExternalFunctionCallType call_type_arg) :
|
|
|
|
|
Instruction {Tag::FCALL},
|
2023-11-30 15:28:57 +01:00
|
|
|
|
nb_output_arguments {nb_output_arguments_arg},
|
|
|
|
|
nb_input_arguments {nb_input_arguments_arg},
|
|
|
|
|
indx {indx_arg},
|
|
|
|
|
func_name {move(func_name_arg)},
|
|
|
|
|
call_type {call_type_arg}
|
2019-12-16 19:42:59 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2023-02-17 22:20:40 +01:00
|
|
|
|
/* Deserializing constructor.
|
|
|
|
|
Updates the code pointer to point beyond the bytes read. */
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FCALL(char*& code) : Instruction {Tag::FCALL}
|
2023-02-17 22:20:40 +01:00
|
|
|
|
{
|
2023-12-14 16:17:22 +01:00
|
|
|
|
code += sizeof(tag);
|
2023-02-17 22:20:40 +01:00
|
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
|
auto read_member = [&code](auto& member) {
|
2023-02-17 22:20:40 +01:00
|
|
|
|
member = *reinterpret_cast<add_pointer_t<decltype(member)>>(code);
|
|
|
|
|
code += sizeof member;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
read_member(nb_output_arguments);
|
|
|
|
|
read_member(nb_input_arguments);
|
|
|
|
|
read_member(indx);
|
|
|
|
|
read_member(add_input_arguments);
|
|
|
|
|
read_member(row);
|
|
|
|
|
read_member(col);
|
|
|
|
|
read_member(call_type);
|
|
|
|
|
|
|
|
|
|
int size;
|
|
|
|
|
read_member(size);
|
|
|
|
|
func_name = code;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
code += size + 1;
|
2023-02-17 22:20:40 +01:00
|
|
|
|
|
|
|
|
|
read_member(size);
|
|
|
|
|
arg_func_name = code;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
code += size + 1;
|
2023-02-17 22:20:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-06-17 14:29:12 +02:00
|
|
|
|
string
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_function_name()
|
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
// printf("get_function_name => func_name=%s\n",func_name.c_str());fflush(stdout);
|
2010-12-10 11:50:27 +01:00
|
|
|
|
return func_name;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_nb_output_arguments()
|
|
|
|
|
{
|
2022-06-17 15:33:54 +02:00
|
|
|
|
return nb_output_arguments;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_nb_input_arguments()
|
|
|
|
|
{
|
2022-06-17 15:33:54 +02:00
|
|
|
|
return nb_input_arguments;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_indx()
|
|
|
|
|
{
|
2022-06-17 15:33:54 +02:00
|
|
|
|
return indx;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
void
|
2010-12-10 11:50:27 +01:00
|
|
|
|
set_arg_func_name(string arg_arg_func_name)
|
|
|
|
|
{
|
2023-12-13 10:28:54 +01:00
|
|
|
|
arg_func_name = move(arg_arg_func_name);
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
string
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_arg_func_name()
|
|
|
|
|
{
|
|
|
|
|
return arg_func_name;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
void
|
2022-06-20 17:49:09 +02:00
|
|
|
|
set_nb_add_input_arguments(int arg_add_input_arguments)
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
|
|
|
|
add_input_arguments = arg_add_input_arguments;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_nb_add_input_arguments()
|
|
|
|
|
{
|
|
|
|
|
return add_input_arguments;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
void
|
2022-06-20 17:49:09 +02:00
|
|
|
|
set_row(int arg_row)
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
|
|
|
|
row = arg_row;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_row()
|
|
|
|
|
{
|
|
|
|
|
return row;
|
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
void
|
2022-06-20 17:49:09 +02:00
|
|
|
|
set_col(int arg_col)
|
2010-12-10 11:50:27 +01:00
|
|
|
|
{
|
|
|
|
|
col = arg_col;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-12-10 11:50:27 +01:00
|
|
|
|
get_col()
|
|
|
|
|
{
|
|
|
|
|
return col;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-07-08 16:00:02 +02:00
|
|
|
|
ExternalFunctionCallType
|
|
|
|
|
get_call_type()
|
2011-02-04 16:25:38 +01:00
|
|
|
|
{
|
2022-07-08 16:00:02 +02:00
|
|
|
|
return call_type;
|
2011-02-04 16:25:38 +01:00
|
|
|
|
}
|
2010-12-10 11:50:27 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 16:17:22 +01:00
|
|
|
|
class FNUMEXPR final : public Instruction
|
2010-01-22 17:42:08 +01:00
|
|
|
|
{
|
|
|
|
|
private:
|
2022-06-17 15:33:54 +02:00
|
|
|
|
ExpressionType expression_type;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
int equation; // Equation number (non-block-specific) (or temporary term number for
|
|
|
|
|
// ExpressionType::TemporaryTerm)
|
2022-07-26 14:51:48 +02:00
|
|
|
|
int dvariable1; // For derivatives, type-specific ID of the derivation variable
|
2023-11-30 15:28:57 +01:00
|
|
|
|
int lag1; // For derivatives, lead/lag of the derivation variable
|
2010-01-22 17:42:08 +01:00
|
|
|
|
public:
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FNUMEXPR(const ExpressionType expression_type_arg, int equation_arg) :
|
|
|
|
|
Instruction {Tag::FNUMEXPR},
|
2023-11-30 15:28:57 +01:00
|
|
|
|
expression_type {expression_type_arg},
|
|
|
|
|
equation {equation_arg},
|
|
|
|
|
dvariable1 {0},
|
|
|
|
|
lag1 {0}
|
2010-01-22 17:42:08 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FNUMEXPR(const ExpressionType expression_type_arg, int equation_arg, int dvariable1_arg) :
|
|
|
|
|
Instruction {Tag::FNUMEXPR},
|
2023-11-30 15:28:57 +01:00
|
|
|
|
expression_type {expression_type_arg},
|
|
|
|
|
equation {equation_arg},
|
|
|
|
|
dvariable1 {dvariable1_arg},
|
|
|
|
|
lag1 {0}
|
2010-01-22 17:42:08 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FNUMEXPR(const ExpressionType expression_type_arg, int equation_arg, int dvariable1_arg,
|
|
|
|
|
int lag1_arg) :
|
|
|
|
|
Instruction {Tag::FNUMEXPR},
|
2023-11-30 15:28:57 +01:00
|
|
|
|
expression_type {expression_type_arg},
|
|
|
|
|
equation {equation_arg},
|
|
|
|
|
dvariable1 {dvariable1_arg},
|
|
|
|
|
lag1 {lag1_arg}
|
2010-01-22 17:42:08 +01:00
|
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
ExpressionType
|
2010-01-22 17:42:08 +01:00
|
|
|
|
get_expression_type()
|
|
|
|
|
{
|
2022-06-17 15:33:54 +02:00
|
|
|
|
return expression_type;
|
2010-01-22 17:42:08 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-01-22 17:42:08 +01:00
|
|
|
|
get_equation()
|
|
|
|
|
{
|
|
|
|
|
return equation;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-01-22 17:42:08 +01:00
|
|
|
|
get_dvariable1()
|
|
|
|
|
{
|
|
|
|
|
return dvariable1;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
int
|
2010-01-22 17:42:08 +01:00
|
|
|
|
get_lag1()
|
|
|
|
|
{
|
|
|
|
|
return lag1;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2010-01-22 17:42:08 +01:00
|
|
|
|
};
|
|
|
|
|
|
2023-12-14 16:17:22 +01:00
|
|
|
|
class FBEGINBLOCK final : public Instruction
|
2009-10-16 18:34:27 +02:00
|
|
|
|
{
|
2022-06-23 14:28:13 +02:00
|
|
|
|
template<typename B>
|
2023-12-14 14:52:50 +01:00
|
|
|
|
friend Writer& operator<<(Writer& code_file, const B& instr);
|
2023-11-30 15:28:57 +01:00
|
|
|
|
|
2009-10-16 18:34:27 +02:00
|
|
|
|
private:
|
2023-11-30 15:28:57 +01:00
|
|
|
|
int size {0};
|
2022-06-20 14:44:55 +02:00
|
|
|
|
BlockSimulationType type;
|
2009-12-16 14:21:31 +01:00
|
|
|
|
vector<int> variable;
|
|
|
|
|
vector<int> equation;
|
2020-05-06 14:02:58 +02:00
|
|
|
|
vector<int> exogenous;
|
|
|
|
|
vector<int> det_exogenous;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
bool is_linear {false};
|
2009-10-23 13:26:29 +02:00
|
|
|
|
vector<Block_contain_type> Block_Contain_;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
int u_count_int {0};
|
|
|
|
|
int nb_col_jacob {0};
|
2023-01-17 13:47:02 +01:00
|
|
|
|
int det_exo_size, exo_size;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
|
2009-10-16 18:34:27 +02:00
|
|
|
|
public:
|
2023-01-17 13:47:02 +01:00
|
|
|
|
/* Constructor when derivatives w.r.t. exogenous are present (only makes
|
|
|
|
|
sense when there is no block-decomposition, since there is no provision for
|
|
|
|
|
derivatives w.r.t. endogenous not belonging to the block) */
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FBEGINBLOCK(int size_arg, BlockSimulationType type_arg, int first_element, int block_size,
|
|
|
|
|
const vector<int>& variable_arg, const vector<int>& equation_arg, bool is_linear_arg,
|
|
|
|
|
int u_count_int_arg, int nb_col_jacob_arg, int det_exo_size_arg, int exo_size_arg,
|
|
|
|
|
vector<int> det_exogenous_arg, vector<int> exogenous_arg) :
|
|
|
|
|
Instruction {Tag::FBEGINBLOCK},
|
2023-11-30 15:28:57 +01:00
|
|
|
|
size {size_arg},
|
|
|
|
|
type {type_arg},
|
|
|
|
|
variable {variable_arg.begin() + first_element,
|
|
|
|
|
variable_arg.begin() + (first_element + block_size)},
|
|
|
|
|
equation {equation_arg.begin() + first_element,
|
|
|
|
|
equation_arg.begin() + (first_element + block_size)},
|
|
|
|
|
exogenous {move(exogenous_arg)},
|
|
|
|
|
det_exogenous {move(det_exogenous_arg)},
|
|
|
|
|
is_linear {is_linear_arg},
|
|
|
|
|
u_count_int {u_count_int_arg},
|
|
|
|
|
nb_col_jacob {nb_col_jacob_arg},
|
|
|
|
|
det_exo_size {det_exo_size_arg},
|
|
|
|
|
exo_size {exo_size_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
|
{
|
2018-10-04 17:18:27 +02:00
|
|
|
|
}
|
2023-01-17 13:47:02 +01:00
|
|
|
|
// Constructor when derivatives w.r.t. exogenous are absent
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FBEGINBLOCK(int size_arg, BlockSimulationType type_arg, int first_element, int block_size,
|
|
|
|
|
const vector<int>& variable_arg, const vector<int>& equation_arg, bool is_linear_arg,
|
|
|
|
|
int u_count_int_arg, int nb_col_jacob_arg) :
|
|
|
|
|
Instruction {Tag::FBEGINBLOCK},
|
2023-11-30 15:28:57 +01:00
|
|
|
|
size {size_arg},
|
|
|
|
|
type {type_arg},
|
|
|
|
|
variable {variable_arg.begin() + first_element,
|
|
|
|
|
variable_arg.begin() + (first_element + block_size)},
|
|
|
|
|
equation {equation_arg.begin() + first_element,
|
|
|
|
|
equation_arg.begin() + (first_element + block_size)},
|
|
|
|
|
is_linear {is_linear_arg},
|
|
|
|
|
u_count_int {u_count_int_arg},
|
|
|
|
|
nb_col_jacob {nb_col_jacob_arg},
|
|
|
|
|
det_exo_size {0},
|
|
|
|
|
exo_size {0}
|
2018-10-04 17:18:27 +02:00
|
|
|
|
{
|
2010-07-23 11:20:24 +02:00
|
|
|
|
}
|
2023-02-17 22:20:40 +01:00
|
|
|
|
/* Deserializing constructor.
|
|
|
|
|
Updates the code pointer to point beyond the bytes read. */
|
2023-12-14 16:17:22 +01:00
|
|
|
|
FBEGINBLOCK(char*& code) : Instruction {Tag::FBEGINBLOCK}
|
2023-02-17 22:20:40 +01:00
|
|
|
|
{
|
2023-12-14 16:17:22 +01:00
|
|
|
|
code += sizeof(tag);
|
2023-02-17 22:20:40 +01:00
|
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
|
auto read_member = [&code](auto& member) {
|
2023-02-17 22:20:40 +01:00
|
|
|
|
member = *reinterpret_cast<add_pointer_t<decltype(member)>>(code);
|
|
|
|
|
code += sizeof member;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
read_member(size);
|
|
|
|
|
read_member(type);
|
|
|
|
|
for (int i {0}; i < size; i++)
|
|
|
|
|
{
|
|
|
|
|
Block_contain_type bc;
|
|
|
|
|
read_member(bc.Variable);
|
|
|
|
|
read_member(bc.Equation);
|
2023-12-13 15:37:07 +01:00
|
|
|
|
Block_Contain_.push_back(bc);
|
2023-02-17 22:20:40 +01:00
|
|
|
|
}
|
|
|
|
|
if (type == BlockSimulationType::solveTwoBoundariesSimple
|
|
|
|
|
|| type == BlockSimulationType::solveTwoBoundariesComplete
|
|
|
|
|
|| type == BlockSimulationType::solveBackwardComplete
|
|
|
|
|
|| type == BlockSimulationType::solveForwardComplete)
|
|
|
|
|
{
|
|
|
|
|
read_member(is_linear);
|
|
|
|
|
read_member(u_count_int);
|
|
|
|
|
}
|
|
|
|
|
read_member(nb_col_jacob);
|
|
|
|
|
read_member(det_exo_size);
|
|
|
|
|
read_member(exo_size);
|
|
|
|
|
|
|
|
|
|
for (int i {0}; i < det_exo_size; i++)
|
|
|
|
|
{
|
|
|
|
|
int tmp_i;
|
|
|
|
|
read_member(tmp_i);
|
|
|
|
|
det_exogenous.push_back(tmp_i);
|
|
|
|
|
}
|
|
|
|
|
for (int i {0}; i < exo_size; i++)
|
|
|
|
|
{
|
|
|
|
|
int tmp_i;
|
|
|
|
|
read_member(tmp_i);
|
|
|
|
|
exogenous.push_back(tmp_i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2009-12-16 18:13:23 +01:00
|
|
|
|
get_size()
|
|
|
|
|
{
|
|
|
|
|
return size;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 14:44:55 +02:00
|
|
|
|
BlockSimulationType
|
2009-12-16 18:13:23 +01:00
|
|
|
|
get_type()
|
|
|
|
|
{
|
|
|
|
|
return type;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
bool
|
2009-12-16 18:13:23 +01:00
|
|
|
|
get_is_linear()
|
|
|
|
|
{
|
|
|
|
|
return is_linear;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
int
|
2009-12-16 18:13:23 +01:00
|
|
|
|
get_u_count_int()
|
|
|
|
|
{
|
|
|
|
|
return u_count_int;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
vector<Block_contain_type>
|
2009-12-16 18:13:23 +01:00
|
|
|
|
get_Block_Contain()
|
|
|
|
|
{
|
|
|
|
|
return Block_Contain_;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
int
|
2010-07-23 11:20:24 +02:00
|
|
|
|
get_nb_col_jacob()
|
|
|
|
|
{
|
|
|
|
|
return nb_col_jacob;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-07-23 11:20:24 +02:00
|
|
|
|
get_exo_size()
|
|
|
|
|
{
|
|
|
|
|
return exo_size;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-20 17:49:09 +02:00
|
|
|
|
int
|
2010-07-23 11:20:24 +02:00
|
|
|
|
get_det_exo_size()
|
|
|
|
|
{
|
|
|
|
|
return det_exo_size;
|
2023-12-14 17:07:06 +01:00
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
vector<int>
|
2015-09-22 12:45:27 +02:00
|
|
|
|
get_endogenous()
|
|
|
|
|
{
|
|
|
|
|
return variable;
|
|
|
|
|
}
|
2022-06-17 14:29:12 +02:00
|
|
|
|
vector<int>
|
2015-09-22 12:45:27 +02:00
|
|
|
|
get_exogenous()
|
|
|
|
|
{
|
|
|
|
|
return exogenous;
|
|
|
|
|
}
|
2009-10-16 18:34:27 +02:00
|
|
|
|
};
|
|
|
|
|
|
2022-06-23 14:28:13 +02:00
|
|
|
|
// Superclass of std::ofstream for writing a sequence of bytecode instructions
|
2023-12-14 14:52:50 +01:00
|
|
|
|
class Writer : private ofstream
|
2022-06-23 14:28:13 +02:00
|
|
|
|
{
|
|
|
|
|
template<typename B>
|
2023-12-14 14:52:50 +01:00
|
|
|
|
friend Writer& operator<<(Writer& code_file, const B& instr);
|
2023-11-30 15:28:57 +01:00
|
|
|
|
|
2022-06-23 14:28:13 +02:00
|
|
|
|
private:
|
|
|
|
|
// Stores the positions of all instructions in the byte stream
|
|
|
|
|
vector<pos_type> instructions_positions;
|
2023-11-30 15:28:57 +01:00
|
|
|
|
|
2022-06-23 14:28:13 +02:00
|
|
|
|
public:
|
2023-12-14 14:52:50 +01:00
|
|
|
|
Writer(const filesystem::path& filename);
|
2022-06-23 14:28:13 +02:00
|
|
|
|
// Returns the number of the next instruction to be written
|
|
|
|
|
int
|
|
|
|
|
getInstructionCounter() const
|
|
|
|
|
{
|
|
|
|
|
return static_cast<int>(instructions_positions.size());
|
|
|
|
|
}
|
|
|
|
|
/* Overwrites an existing instruction, given its number.
|
|
|
|
|
It is the responsibility of the caller to ensure that the new instruction
|
|
|
|
|
occupies exactly as many bytes as the former one. */
|
|
|
|
|
template<typename B>
|
|
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
|
overwriteInstruction(int instruction_number, const B& new_instruction)
|
2022-06-23 14:28:13 +02:00
|
|
|
|
{
|
|
|
|
|
seekp(instructions_positions.at(instruction_number));
|
|
|
|
|
*this << new_instruction;
|
|
|
|
|
instructions_positions.pop_back();
|
|
|
|
|
seekp(0, ios_base::end);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Overloads of operator<< for writing bytecode instructions
|
|
|
|
|
|
|
|
|
|
template<typename B>
|
2023-12-14 14:52:50 +01:00
|
|
|
|
Writer&
|
|
|
|
|
operator<<(Writer& code_file, const B& instr)
|
2022-06-23 14:28:13 +02:00
|
|
|
|
{
|
|
|
|
|
code_file.instructions_positions.push_back(code_file.tellp());
|
2023-11-30 15:28:57 +01:00
|
|
|
|
code_file.write(reinterpret_cast<const char*>(&instr), sizeof(B));
|
2022-06-23 14:28:13 +02:00
|
|
|
|
return code_file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<>
|
2023-12-14 16:17:22 +01:00
|
|
|
|
Writer& operator<<(Writer& code_file, const FCALL& instr);
|
2022-06-23 14:28:13 +02:00
|
|
|
|
|
|
|
|
|
template<>
|
2023-12-14 16:17:22 +01:00
|
|
|
|
Writer& operator<<(Writer& code_file, const FBEGINBLOCK& instr);
|
2023-12-14 14:52:50 +01:00
|
|
|
|
|
|
|
|
|
}
|
2022-06-23 14:28:13 +02:00
|
|
|
|
|
2023-12-01 15:39:01 +01:00
|
|
|
|
#endif
|