/* * Copyright © 2007-2023 Dynare Team * * 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 . */ #ifndef _EVALUATE_HH #define _EVALUATE_HH #include #include #include #include #include #include #include "Bytecode.hh" #include "BasicSymbolTable.hh" class Evaluate { private: using instructions_list_t = vector; using it_code_type = instructions_list_t::const_iterator; // Memory copy of the contents of the .cod file unique_ptr raw_bytecode; /* Owns read instructions that have their specialized deserializing constructors (and are thus not part of the “code” memory block) */ vector> deserialized_special_instrs; /* List of deserialized instructions Those are either pointers inside “raw_bytecode” or “deserialized_special_instrs” */ instructions_list_t instructions_list; // Number of blocks in the model int nb_blocks {0}; // Index of beginnings of blocks within instructions_list vector begin_block; int block_num; // Index of the current block int size; // Size of the current block ExpressionType EQN_type; int EQN_equation, EQN_dvar1; int EQN_lag1, EQN_lag2, EQN_lag3; string error_location(it_code_type expr_begin, it_code_type faulty_op, int it_) const; FBEGINBLOCK_ * currentBlockTag() const { return reinterpret_cast(instructions_list[begin_block[block_num]]); } // Returns iterator to first instruction in the current block (after FBEGINBLOCK) it_code_type currentBlockBeginning() { return instructions_list.begin() + begin_block[block_num] + 1; } protected: BasicSymbolTable &symbol_table; void evaluateBlock(int it_, double *__restrict__ y, const double *__restrict__ ya, int y_size, double *__restrict__ x, int nb_row_x, double *__restrict__ params, const double *__restrict__ steady_y, double *__restrict__ u, int Per_u_, double *__restrict__ T, int T_nrows, map &TEF, map, double> &TEFD, map, double> &TEFDD, double *__restrict__ r, double *__restrict__ g1, double *__restrict__ jacob, double *__restrict__ jacob_exo, double *__restrict__ jacob_exo_det, bool evaluate, bool no_derivatives); bool steady_state; /* Prints a bytecode expression in human readable form. If faulty_op is not default constructed, it should point to a tag within the expression that created a floating point exception, in which case the corresponding mathematical operator will be printed within braces. The second output argument points to the tag past the expression. */ pair print_expression(const it_code_type &expr_begin, const optional &faulty_op = nullopt) const; // Prints current block void printCurrentBlock(); void gotoBlock(int block); int getNumberOfTemporaryTerms() const; auto getCurrentBlockSize() const { return currentBlockTag()->get_size(); } auto getCurrentBlockType() const { return currentBlockTag()->get_type(); } auto isCurrentBlockLinear() const { return currentBlockTag()->get_is_linear(); } auto getCurrentBlockEquationsAndVariables() const { return currentBlockTag()->get_Block_Contain(); } auto getCurrentBlockUCount() const { return currentBlockTag()->get_u_count_int(); } auto getCurrentBlockExogenous() const { return currentBlockTag()->get_exogenous(); } auto getCurrentBlockEndogenous() const { return currentBlockTag()->get_endogenous(); } auto getCurrentBlockNbColJacob() const { return currentBlockTag()->get_nb_col_jacob(); } auto getCurrentBlockExoSize() const { return currentBlockTag()->get_exo_size(); } auto getCurrentBlockExoDetSize() const { return currentBlockTag()->get_det_exo_size(); } public: Evaluate(bool steady_state_arg, BasicSymbolTable &symbol_table_arg); // TODO: integrate into the constructor void loadCodeFile(const filesystem::path &codfile); int get_block_number() const { return nb_blocks; } }; #endif // _EVALUATE_HH