Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • 4.6
  • 5.x
  • 6.x
  • aux_vars_fix
  • julia
  • llvm-15
  • master
  • python-codegen
  • rework_pac
  • uop
  • julia-6.2.0
  • julia-6.3.0
  • julia-6.4.0
  • julia-7.0.0
14 results

Target

Select target project
No results found
Select Git revision
  • irf-matching-preprocessor-perfect-foresight
  • master
  • created_preprocessor_repo
3 results
Show changes
59 files
+ 4597
2060
Compare changes
  • Side-by-side
  • Inline

Files

+3 −0
Original line number Diff line number Diff line
@@ -11,9 +11,12 @@ BreakInheritanceList: AfterColon
Cpp11BracedListStyle: true
DeriveLineEnding: false
IndentPPDirectives: AfterHash
InsertNewlineAtEOF: true
PackConstructorInitializers: NextLine
PPIndentWidth: 1
PointerAlignment: Left
# RemoveParentheses: ReturnStatement
# RemoveSemicolon: true
SpaceAfterTemplateKeyword: false
SpaceBeforeParens: ControlStatements
SpaceBeforeCpp11BracedList: true
+19 −7
Original line number Diff line number Diff line
variables:
  TERM: linux
  MINGW32_BOOST_VERSION: 1.84.0-1
  MINGW64_BOOST_VERSION: 1.84.0-1
  MINGW64_BOOST_VERSION: 1.88.0-2
  WGET_OPTIONS: '--no-verbose --no-use-server-timestamps --retry-connrefused --retry-on-host-error'
  # To ensure that "false && true" fails, see https://gitlab.com/gitlab-org/gitlab-runner/-/issues/25394#note_412609647
  FF_ENABLE_BASH_EXIT_CODE_CHECK: 'true'
@@ -9,7 +8,7 @@ variables:
build_linux_x86_64:
  stage: build
  script:
    - meson setup -D buildtype=release build
    - meson setup --buildtype=release -Db_lto=true build
    - meson compile -C build -v
  artifacts:
    paths:
@@ -18,7 +17,7 @@ build_linux_x86_64:
build_linux_arm64:
  stage: build
  script:
    - meson setup -D buildtype=release --cross-file scripts/linux-arm64-cross.ini build
    - meson setup --buildtype=release -Db_lto=true --cross-file scripts/linux-arm64-cross.ini build
    - meson compile -C build -v
  artifacts:
    paths:
@@ -32,7 +31,7 @@ build_windows_x86_64:
    - mkdir -p deps
    - tar xf tarballs/mingw-w64-x86_64-boost-$MINGW64_BOOST_VERSION-any.pkg.tar.zst --directory deps
    - echo -e "[properties]\nboost_root = '$(pwd)/deps/mingw64/'" > boost.ini
    - meson setup -D buildtype=release --cross-file scripts/windows-cross.ini --cross-file boost.ini build
    - meson setup --buildtype=release -Db_lto=true --cross-file scripts/windows-cross.ini --cross-file boost.ini build
    - meson compile -C build -v
  cache:
    # This cache is shared between all branches, to save space
@@ -48,7 +47,7 @@ build_macos_x86_64:
  tags:
    - macOS
  script:
    - arch -x86_64 meson setup -D buildtype=release --native-file scripts/homebrew-native-x86_64.ini build
    - arch -x86_64 meson setup --buildtype=release -Db_lto=true --native-file scripts/homebrew-native-x86_64.ini build
    - arch -x86_64 meson compile -C build -v
  artifacts:
    paths:
@@ -60,7 +59,7 @@ build_macos_arm64:
    - macOS
  script:
    - export PATH="/opt/homebrew/bin:$PATH"
    - arch -arm64 meson setup -D buildtype=release --native-file scripts/homebrew-native-arm64.ini build
    - arch -arm64 meson setup --buildtype=release -Db_lto=true --native-file scripts/homebrew-native-arm64.ini build
    - arch -arm64 meson compile -C build -v
  artifacts:
    paths:
@@ -72,3 +71,16 @@ test_clang_format:
    - meson setup build-clang-format
    - ninja -C build-clang-format clang-format-check
  needs: []

test_clang_tidy:
  stage: test
  script:
    # Hack needed for meson < 1.6.0 which only looks for unversioned clang-tidy
    - mkdir -p ~/.local/bin && ln -s /usr/bin/clang-tidy-19 ~/.local/bin/clang-tidy
    - export PATH="$HOME/.local/bin:$PATH"
    - meson setup build-clang-tidy
    # Generate Flex and Bison files
    - meson compile -C build-clang-tidy
    - ninja -C build-clang-tidy clang-tidy
  needs: []
  when: manual
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
\pgfdeclareimage[height=0.8cm]{logo}{dlogo}
\institute[Dynare Team]{\pgfuseimage{logo}}

\date{23 May 2023}
\date{31 May 2024}

\AtBeginSection[]
{
@@ -156,9 +156,9 @@
    \item comparison operators: \texttt{< > <= >= == !=}
    \item logical operators: \verb+&& || !+
    \item range with unit increment: \texttt{1:4} is equivalent to
      real array \texttt{[1, 2, 3, 4]}. (NB: \texttt{[1:4]} is equivalent to an
      real array \texttt{[1, 2, 3, 4]} \\ (NB: \texttt{[1:4]} is equivalent to an
      array containing an array of reals, \textit{i.e.} \texttt{[[1, 2, 3, 4]]})
    \item range with user-defined increment: \texttt{4:-1.1:-1} is equivalent to real array \texttt{[4, 2.9, 1.8, 0.7, -0.4]}.
    \item range with user-defined increment: \\ \texttt{4:-1.1:-1} is equivalent to real array \texttt{[4, 2.9, 1.8, 0.7, -0.4]}
    \end{itemize}
  \end{block}

@@ -314,7 +314,7 @@ Then \texttt{distance(3, 4)} will be equivalent to \texttt{5}.
\end{frame}

\begin{frame}[fragile=singleslide]
  \frametitle{Defining macro-variables}
  \frametitle{Defining macro-variables (1/2)}

  The value of a macro-variable can be defined with the \verb+@#define+
  directive.
@@ -335,9 +335,31 @@ Then \texttt{distance(3, 4)} will be equivalent to \texttt{5}.
@#define t = ("US" in w)    // Equals true
\end{verbatim}
  \end{block}
  NB: You can define macro variables on the Dynare command line by using the \texttt{-D} option
\end{frame}

\begin{frame}[fragile=singleslide]
  \frametitle{Defining macro-variables (2/2)}
  Macro variables can also be defined on the Dynare command line by using the
  \texttt{-D} option, for easily switching between different flavours of a model.

  \begin{block}{Example 1}
\begin{verbatim}
dynare myfile.mod -Dx=5
\end{verbatim}
The macro-variable \texttt{x} will be equal to \texttt{5} when running \texttt{myfile.mod}.
\end{block}

\begin{block}{Example 2}
  Use single quotes around the \texttt{-D} option when there are spaces or
  special characters in the variable definition.
\begin{verbatim}
dynare myfile.mod '-DA=[ i in [1,2,3] when i > 1 ]'
\end{verbatim}
The macro-variable \texttt{A} will be equal to \texttt{[2,3]} when running \texttt{myfile.mod}.
\end{block}
\end{frame}


\begin{frame}[fragile=singleslide]
  \frametitle{Expression substitution}
  \framesubtitle{Dummy example}
@@ -611,7 +633,7 @@ end;
\begin{frame}
  \frametitle{Macro-related command line options}
  \begin{itemize}
  \item \texttt{savemacro}: Useful for debugging or learning purposes, saves the output of the macro processor. If your \texttt{.mod} file is called \texttt{file.mod}, the output is saved to \texttt{file-macroexp.mod}.
  \item \texttt{savemacro}: Useful for debugging or learning purposes, saves the output of the macro processor. If your \texttt{.mod} file is called \texttt{file.mod}, the output is saved to \texttt{file\_macroexp.mod}.
  \item NB: \texttt{savemacro=filename} allows a user-defined file name
  \item \texttt{linemacro}: In the output of \texttt{savemacro}, print line numbers where the macro directives were placed.
  \item \texttt{onlymacro}: Stops processing after the macro processing step.
@@ -866,7 +888,7 @@ rhos = [ 0.8, 0.9, 1];
    \ccbysa
    \column{0.71\textwidth}
    \tiny
    Copyright © 2008-2023 Dynare Team \\
    Copyright © 2008-2024 Dynare Team \\
    License: \href{http://creativecommons.org/licenses/by-sa/4.0/}{Creative
      Commons Attribution-ShareAlike 4.0}
  \end{columns}
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
# It is not used when building Dynare as a whole.

project('dynare-preprocessor', 'cpp',
        version : '6-unstable',
        version : '7-unstable',
        # NB: update C++ standard in .clang-format whenever the following is modified
        default_options : [ 'cpp_std=gnu++20', 'warning_level=2' ],
        meson_version : '>=0.64.0')
Original line number Diff line number Diff line
# Meson native file for compiling under Homebrew / arm64

[binaries]
cpp = '/opt/homebrew/bin/g++-13'
cpp = '/opt/homebrew/bin/g++-15'
flex = '/opt/homebrew/opt/flex/bin/flex'
bison = '/opt/homebrew/opt/bison/bin/bison'

Original line number Diff line number Diff line
# Meson native file for compiling under Homebrew / x86-64

[binaries]
cpp = '/usr/local/bin/g++-13'
cpp = '/usr/local/bin/g++-15'
flex = '/usr/local/opt/flex/bin/flex'
bison = '/usr/local/opt/bison/bin/bison'

scripts/wasm.ini

0 → 100644
+44 −0
Original line number Diff line number Diff line
# Meson cross file for creating a WebAssembly version of the preprocessor.
#
# Requires emscripten to be installed.
# Was successfully tested with emscripten 3.1.69 installed through emsdk
# tool, as described on: https://emscripten.org/docs/getting_started/downloads.html
# Don’t forget to source script snippet in current shell before running meson.
#
# Compilation creates a .wasm and .js wrapper under <builddir>/src/
#
# Can be run locally with node.js using:
#  node dynare-preprocessor.js file.mod
# NB: a version of node.js is shipped with emscripten (under the node/
# subdirectory), but another version should also work.

[binaries]
cpp = 'em++'

[host_machine]
system = 'emscripten'
# Could be changed to wasm64 if 4GB memory constraint is hit
# Some background: https://v8.dev/blog/4gb-wasm-memory
cpu_family = 'wasm32'
cpu = 'wasm32'
endian = 'little'

[built-in options]
# Never do a debug build, because otherwise the lack of optimisations can
# overflow the memory capacities.
buildtype = 'release'
# The -fexceptions flag (for both compilation and linking) is needed for an
# unknown reason (C++ compilers are supposed to always add exception support).
# The -Wno-unqualified-std-cast-call flag removes many warnings about “move”
# not being qualified with “std::” namespace.
# The -fexperimental-library flag is needed to get std::jthread support (it was
# supposed to no longer be necessary for LLVM 20, but for some reason we still
# need it).
cpp_args = [ '-fexceptions', '-Wno-unqualified-std-cast-call', '-fexperimental-library' ]
# NODERAWFS=1 is needed for accessing the local filesystem
cpp_link_args = [ '-s', 'NODERAWFS=1', '-fexceptions' ]

[properties]
# It’s necessary to use a different copy of Boost than the one under
# /usr/include, because otherwise GCC headers confuse Clang
boost_root = '/tmp/boost_1_86_0'
+5 −5
Original line number Diff line number Diff line
/*
 * Copyright © 2022-2023 Dynare Team
 * Copyright © 2022-2024 Dynare Team
 *
 * This file is part of Dynare.
 *
@@ -82,8 +82,8 @@ operator<<(Writer& code_file, const FBEGINBLOCK& instr)
  write_member(instr.type);
  for (int i = 0; i < instr.size; i++)
    {
      write_member(instr.variable[i]);
      write_member(instr.equation[i]);
      write_member(instr.variables[i]);
      write_member(instr.equations[i]);
    }
  if (instr.type == BlockSimulationType::solveTwoBoundariesSimple
      || instr.type == BlockSimulationType::solveTwoBoundariesComplete
@@ -97,8 +97,8 @@ operator<<(Writer& code_file, const FBEGINBLOCK& instr)
  write_member(instr.det_exo_size);
  write_member(instr.exo_size);

  for_each_n(instr.det_exogenous.begin(), instr.det_exo_size, write_member);
  for_each_n(instr.exogenous.begin(), instr.exo_size, write_member);
  ranges::for_each_n(instr.det_exogenous.begin(), instr.det_exo_size, write_member);
  ranges::for_each_n(instr.exogenous.begin(), instr.exo_size, write_member);

  return code_file;
}
+40 −54
Original line number Diff line number Diff line
/*
 * Copyright © 2007-2023 Dynare Team
 * Copyright © 2007-2024 Dynare Team
 *
 * This file is part of Dynare.
 *
@@ -20,6 +20,7 @@
#ifndef BYTECODE_HH
#define BYTECODE_HH

#include <concepts>
#include <filesystem>
#include <fstream>
#include <ios>
@@ -74,9 +75,8 @@ enum class Tag
  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
  FSTPG,  // Stores the derivative of a simple (single-equation) block in simulate mode
  FSTPG2, // Stores the derivative matrix of a block in evaluate mode

  FUNARY,   // A unary operator
  FBINARY,  // A binary operator
@@ -122,11 +122,6 @@ enum class ExternalFunctionCallType
  numericalSecondDerivative
};

struct Block_contain_type
{
  int Equation, Variable, Own_Derivative;
};

class Writer;

struct Instruction
@@ -145,6 +140,9 @@ protected:
  ~Instruction() = default;
};

template<typename T>
concept IsInstruction = derived_from<T, Instruction>;

struct FLDZ final : public Instruction
{
  FLDZ() : Instruction {Tag::FLDZ}
@@ -279,8 +277,7 @@ struct FSTPSU final : public Instruction

struct FSTPG final : public Instruction
{
  const int pos;
  explicit FSTPG(int pos_arg) : Instruction {Tag::FSTPG}, pos {pos_arg}
  explicit FSTPG() : Instruction {Tag::FSTPG}
  {
  }
};
@@ -293,15 +290,6 @@ struct FSTPG2 final : public Instruction
  }
};

struct FSTPG3 final : public Instruction
{
  const int row, col, lag, col_pos;
  FSTPG3(int row_arg, int col_arg, int lag_arg, int col_pos_arg) :
      Instruction {Tag::FSTPG3}, row {row_arg}, col {col_arg}, lag {lag_arg}, col_pos {col_pos_arg}
  {
  }
};

struct FUNARY final : public Instruction
{
  const UnaryOpcode op_code;
@@ -442,7 +430,7 @@ struct FSTPV final : public Instruction

class FCALL final : public Instruction
{
  template<typename B>
  template<IsInstruction B>
  friend Writer& operator<<(Writer& code_file, const B& instr);

private:
@@ -618,18 +606,17 @@ public:

class FBEGINBLOCK final : public Instruction
{
  template<typename B>
  template<IsInstruction B>
  friend Writer& operator<<(Writer& code_file, const B& instr);

private:
  int size {0};
  BlockSimulationType type;
  vector<int> variable;
  vector<int> equation;
  vector<int> variables;
  vector<int> equations;
  vector<int> exogenous;
  vector<int> det_exogenous;
  bool is_linear {false};
  vector<Block_contain_type> Block_Contain_;
  int u_count_int {0};
  int nb_col_jacob {0};
  int det_exo_size, exo_size;
@@ -639,16 +626,16 @@ public:
     sense when there is no block-decomposition, since there is no provision for
     derivatives w.r.t. endogenous not belonging to the block) */
  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) :
              const vector<int>& variables_arg, const vector<int>& equations_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},
      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)},
      variables {variables_arg.begin() + first_element,
                 variables_arg.begin() + (first_element + block_size)},
      equations {equations_arg.begin() + first_element,
                 equations_arg.begin() + (first_element + block_size)},
      exogenous {move(exogenous_arg)},
      det_exogenous {move(det_exogenous_arg)},
      is_linear {is_linear_arg},
@@ -660,15 +647,15 @@ public:
  }
  // Constructor when derivatives w.r.t. exogenous are absent
  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) :
              const vector<int>& variables_arg, const vector<int>& equations_arg,
              bool is_linear_arg, int u_count_int_arg, int nb_col_jacob_arg) :
      Instruction {Tag::FBEGINBLOCK},
      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)},
      variables {variables_arg.begin() + first_element,
                 variables_arg.begin() + (first_element + block_size)},
      equations {equations_arg.begin() + first_element,
                 equations_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},
@@ -689,12 +676,12 @@ public:

    read_member(size);
    read_member(type);
    variables.resize(size);
    equations.resize(size);
    for (int i {0}; i < size; i++)
      {
        Block_contain_type bc;
        read_member(bc.Variable);
        read_member(bc.Equation);
        Block_Contain_.push_back(bc);
        read_member(variables[i]);
        read_member(equations[i]);
      }
    if (type == BlockSimulationType::solveTwoBoundariesSimple
        || type == BlockSimulationType::solveTwoBoundariesComplete
@@ -742,10 +729,15 @@ public:
  {
    return u_count_int;
  }
  vector<Block_contain_type>
  get_Block_Contain()
  vector<int>
  get_variables()
  {
    return variables;
  }
  vector<int>
  get_equations()
  {
    return Block_Contain_;
    return equations;
  }
  int
  get_nb_col_jacob()
@@ -763,11 +755,6 @@ public:
    return det_exo_size;
  }
  vector<int>
  get_endogenous()
  {
    return variable;
  }
  vector<int>
  get_exogenous()
  {
    return exogenous;
@@ -777,7 +764,7 @@ public:
// Superclass of std::ofstream for writing a sequence of bytecode instructions
class Writer : private ofstream
{
  template<typename B>
  template<IsInstruction B>
  friend Writer& operator<<(Writer& code_file, const B& instr);

private:
@@ -795,9 +782,8 @@ public:
  /* 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
  overwriteInstruction(int instruction_number, const B& new_instruction)
  overwriteInstruction(int instruction_number, const IsInstruction auto& new_instruction)
  {
    seekp(instructions_positions.at(instruction_number));
    *this << new_instruction;
@@ -808,7 +794,7 @@ public:

// Overloads of operator<< for writing bytecode instructions

template<typename B>
template<IsInstruction B>
Writer&
operator<<(Writer& code_file, const B& instr)
{
+21 −10
Original line number Diff line number Diff line
/*
 * Copyright © 2007-2023 Dynare Team
 * Copyright © 2007-2024 Dynare Team
 *
 * This file is part of Dynare.
 *
@@ -25,14 +25,17 @@
 * command */
enum class SymbolType
{
  endogenous = 0,            //!< Endogenous
  exogenous = 1,             //!< Exogenous
  exogenousDet = 2,          //!< Exogenous deterministic
  parameter = 4,             //!< Parameter
  modelLocalVariable = 10,   //!< Local variable whose scope is model (pound expression)
  modFileLocalVariable = 11, //!< Local variable whose scope is mod file (model excluded)
  externalFunction = 12,     //!< External (user-defined) function
  trend = 13,                //!< Trend variable
  endogenous = 0,              // Endogenous (non-heterogeneous)
  exogenous = 1,               // Exogenous (non-heterogeneous)
  exogenousDet = 2,            // Exogenous deterministic (non-heterogeneous)
  parameter = 4,               // Parameter (non-heterogeneous)
  heterogeneousEndogenous = 5, // Endogenous that is heterogeneous across some dimension
  heterogeneousExogenous = 6,  // Exogenous that is heterogeneous across some dimension
  heterogeneousParameter = 7,  // Parameter that is heterogeneous across some dimension
  modelLocalVariable = 10,     // Local variable whose scope is model (pound expression)
  modFileLocalVariable = 11,   // Local variable whose scope is mod file (model excluded)
  externalFunction = 12,       // External (user-defined) function
  trend = 13,                  // Trend variable
  statementDeclaredVariable
  = 14, //!< Local variable assigned within a Statement (see subsample statement for example)
  logTrend = 15, //!< Log-trend variable
@@ -45,6 +48,13 @@ enum class SymbolType
  excludedVariable = 19 //!< Variable excluded via model_remove/var_remove/include_eqs/exclude_eqs
};

constexpr bool
isHeterogeneous(SymbolType type)
{
  return type == SymbolType::heterogeneousEndogenous || type == SymbolType::heterogeneousExogenous
         || type == SymbolType::heterogeneousParameter;
}

enum class UnaryOpcode
{
  uminus,
@@ -75,7 +85,8 @@ enum class UnaryOpcode
  erf,
  erfc,
  diff,
  adl
  adl,
  sum
};

enum class BinaryOpcode