Bytecode: no longer have instruction pointer as a member variable of Evaluate class

silicon
Sébastien Villemot 2023-02-24 14:30:15 -05:00
parent 13b3208cdb
commit 0e1678c13a
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
3 changed files with 16 additions and 49 deletions

View File

@ -1048,6 +1048,7 @@ Evaluate::log10_1(double a)
void
Evaluate::compute_block_time(int Per_u_, bool evaluate, bool no_derivative)
{
auto it_code { currentBlockBeginning() };
int var{0}, lag{0};
UnaryOpcode op1;
BinaryOpcode op2;
@ -2261,23 +2262,16 @@ Evaluate::evaluate_over_periods(bool forward)
compute_block_time(0, false, false);
else
{
auto begining = it_code;
if (forward)
{
for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
{
it_code = begining;
compute_block_time(0, false, false);
}
compute_block_time(0, false, false);
it_ = periods+y_kmin-1; // Do not leave it_ in inconsistent state
}
else
{
for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
{
it_code = begining;
compute_block_time(0, false, false);
}
compute_block_time(0, false, false);
it_ = y_kmin; // Do not leave it_ in inconsistent state (see #1727)
}
}
@ -2295,14 +2289,12 @@ Evaluate::solve_simple_one_periods()
{
Per_y_ = it_*y_size;
ya = y[Block_Contain[0].Variable + Per_y_];
rewindCurrentBlock();
compute_block_time(0, false, false);
if (!isfinite(res1))
{
res1 = std::numeric_limits<double>::quiet_NaN();
while ((isinf(res1) || isnan(res1)) && (slowc > 1e-9))
{
rewindCurrentBlock();
compute_block_time(0, false, false);
if (!isfinite(res1))
{
@ -2367,9 +2359,9 @@ Evaluate::solve_simple_over_periods(bool forward)
void
Evaluate::gotoBlock(int block)
{
it_code = instructions_list.begin() + begin_block[block];
block_num = block;
auto *fb {static_cast<FBEGINBLOCK_ *>(*it_code)};
auto *fb {currentBlockTag()};
if (fb->op_code != Tags::FBEGINBLOCK)
throw FatalException {"Evaluate::gotoBlock: internal inconsistency"};
@ -2379,16 +2371,11 @@ Evaluate::gotoBlock(int block)
is_linear = fb->get_is_linear();
symbol_table_endo_nbr = fb->get_endo_nbr();
u_count_int = fb->get_u_count_int();
it_code++;
block_num = block;
}
void
Evaluate::evaluate_complete(bool no_derivatives)
{
rewindCurrentBlock();
compute_block_time(0, false, no_derivatives);
}
@ -2404,7 +2391,6 @@ Evaluate::compute_complete_2b(bool no_derivatives, double *_res1, double *_res2,
Per_u_ = (it_-y_kmin)*u_count_int;
Per_y_ = it_*y_size;
int shift = (it_-y_kmin) * size;
rewindCurrentBlock();
compute_block_time(Per_u_, false, no_derivatives);
if (!(isnan(res1) || isinf(res1)))
for (int i = 0; i < size; i++)
@ -2432,7 +2418,6 @@ Evaluate::compute_complete(bool no_derivatives, double &_res1, double &_res2, do
{
bool result;
res1 = 0;
rewindCurrentBlock();
compute_block_time(0, false, no_derivatives);
if (!(isnan(res1) || isinf(res1)))
{
@ -2513,6 +2498,7 @@ Evaluate::compute_complete(double lambda, double *crit)
void
Evaluate::printCurrentBlock()
{
auto it_code { currentBlockBeginning() };
mexPrintf("\nBlock %d\n", block_num+1);
mexPrintf("----------\n");
bool go_on {true};

View File

@ -53,9 +53,6 @@ private:
// Index of beginnings of blocks within instructions_list
vector<size_t> begin_block;
// Iterator to current bytecode instruction within “instructions_list”
it_code_type it_code;
ExpressionType EQN_type;
int EQN_equation, EQN_block, EQN_dvar1;
int EQN_lag1, EQN_lag2, EQN_lag3;
@ -71,6 +68,13 @@ private:
return reinterpret_cast<FBEGINBLOCK_ *>(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;
int EQN_block_number;
@ -120,13 +124,6 @@ protected:
The second output argument points to the tag past the expression. */
pair<string, it_code_type> print_expression(const it_code_type &expr_begin, const optional<it_code_type> &faulty_op = nullopt) const;
// Move pointer to the beginning of the current block (past the FBEGINBLOCK tag)
void
rewindCurrentBlock()
{
it_code = instructions_list.begin() + begin_block[block_num] + 1;
}
// Prints current block
void printCurrentBlock();

View File

@ -86,7 +86,6 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
{
Per_y_ = it_*y_size;
rewindCurrentBlock();
compute_block_time(0, true, false);
if (single_block)
for (int j = 0; j < size; j++)
@ -117,7 +116,6 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
{
Per_y_ = it_*y_size;
rewindCurrentBlock();
compute_block_time(0, true, false);
if (!single_block)
for (int j = 0; j < size; j++)
@ -156,7 +154,6 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
for (it_ = y_kmin; it_ < periods+y_kmin; it_++)
{
Per_y_ = it_*y_size;
rewindCurrentBlock();
compute_block_time(0, true, false);
if (!single_block)
for (int j = 0; j < size; j++)
@ -184,7 +181,6 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
{
Per_y_ = it_*y_size;
rewindCurrentBlock();
compute_block_time(0, true, false);
if (single_block)
for (int j = 0; j < size; j++)
@ -215,7 +211,6 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
{
Per_y_ = it_*y_size;
rewindCurrentBlock();
compute_block_time(0, true, false);
if (!single_block)
for (int j = 0; j < size; j++)
@ -251,7 +246,6 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
for (it_ = periods+y_kmin-1; it_ >= y_kmin; it_--)
{
Per_y_ = it_*y_size;
rewindCurrentBlock();
compute_block_time(0, true, false);
if (!single_block)
for (int j = 0; j < size; j++)
@ -277,7 +271,6 @@ Interpreter::evaluate_a_block(bool initialization, bool single_block, const stri
{
Per_u_ = (it_-y_kmin)*u_count_int;
Per_y_ = it_*y_size;
rewindCurrentBlock();
compute_block_time(Per_u_, true, false);
if (!single_block)
for (int j = 0; j < size; j++)
@ -340,10 +333,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
mexEvalString("drawnow;");
#endif
if (vector_table_conditional_local.size())
{
evaluate_a_block(true, single_block, bin_base_name);
rewindCurrentBlock();
}
evaluate_a_block(true, single_block, bin_base_name);
else
{
fixe_u(&u, u_count_int, u_count_int);
@ -365,10 +355,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
mexEvalString("drawnow;");
#endif
if (vector_table_conditional_local.size())
{
evaluate_a_block(true, single_block, bin_base_name);
rewindCurrentBlock();
}
evaluate_a_block(true, single_block, bin_base_name);
else
{
fixe_u(&u, u_count_int, u_count_int);
@ -396,10 +383,7 @@ Interpreter::simulate_a_block(const vector_table_conditional_local_type &vector_
return ERROR_ON_EXIT;
}
if (vector_table_conditional_local.size())
{
evaluate_a_block(true, single_block, bin_base_name);
rewindCurrentBlock();
}
evaluate_a_block(true, single_block, bin_base_name);
else
{
fixe_u(&u, u_count_int, u_count_int);