Commit b67359ce authored by Frédéric Karamé's avatar Frédéric Karamé

Factorization of code and add some corrections in comments.

parent f0e3871c
......@@ -138,24 +138,6 @@ Dynare.PreprocessorOptions(false, false, false, false, false, false, false, fals
```
Sets option `nograph` to true, `language` to "c++" (*ie* generates c++ routines instead of julia routines for the model) and `params_derivs_order` to 1 (the preprocessor computes the first order derivates with respect to the parameters).
"""
macro PreprocessorOptions(args...)
return begin
n, i = length(eval(args)), 1
opts = PreprocessorOptions()
while i<=n
@assert isa(eval(args[i]), Symbol) "Argument $(string(i)) has to be a Symbol (preprocessor option name)!"
if i==n || isa(eval(args[i+1]), Symbol)
PreprocessorOptions!(opts, eval(args[i]), true)
i+=1
else
PreprocessorOptions!(opts, eval(args[i]), eval(args[i+1]))
i+=2
end
end
opts
end
end
function SetPreprocessorOptions(args...)::PreprocessorOptions
n, i = length(args), 1
opts = PreprocessorOptions()
......@@ -172,6 +154,10 @@ function SetPreprocessorOptions(args...)::PreprocessorOptions
return opts
end
macro PreprocessorOptions(args...)
return SetPreprocessorOptions(args...)
end
"""
print(opt::PreprocessorOptions)
......@@ -256,50 +242,16 @@ function print(opt::PreprocessorOptions)
end
"""
compile(modfile::AbstractString, options::PreprocessorOptions)
Compiles `modfile` with `options`, calling the Dynare's preprocessor.
"""
function compile(modfile::AbstractString, options::PreprocessorOptions)
# Add current path to LOAD_PATH if necessary.
if isempty(findall((in)(LOAD_PATH), [pwd()]))
pushfirst!(LOAD_PATH, pwd())
end
# Append extension if necessary and check extension.
basename, ext = splitext(modfile)
if isempty(ext)
modfile = "$modfile.mod"
else
if ~isdynarefile(ext)
error("The Dynare model file must have a mod or dyn extension!")
end
end
# Call the preprocessor.
opts = split(print(options))
run(`$dynare $modfile $opts`)
end
@dynare(modfiles::Expr, opts...)
"""
compile(modfile::AbstractString, options::PreprocessorOptions)
Compiles `modfile` with default options, calling the Dynare's preprocessor.
"""
function compile(modfile::AbstractString)
opts = PreprocessorOptions()
compile(modfile, opts)
end
"""
@dynare(modfiles::Vector{AbstractString}, opts...)
Same as @dynare(modfile::AbstarctString, opts...) but for more than one mod file.
Same as @dynare(modfile::AbstractString, opts...) but for a set of mod files (`modfiles` is a vector of strings for the names of the mod files).
Uses given options.
```julia-repl
julia> @dynare ["test1", "test2"] :nograph :json "compute"
```
Compiles `test1.mod` and `test2.mod` with options `:nograph` and `:json`, the objects model_, options_ and oo_ corresponding to thess models
are respectively stored in a structures named `test1` and `test2`.
Compiles `test1.mod` and `test2.mod` with options `:nograph` and `:json`, the objects model_, options_ and oo_ corresponding to these models
are stored in structures named respectively `test1` and `test2`.
"""
macro dynare(modfiles::Expr, opts...)
if modfiles.head != :vect
......@@ -315,15 +267,16 @@ macro dynare(modfiles::Expr, opts...)
end
"""
@dynare(modfiles::Vector{AbstractString})
@dynare(modfiles::Expr)
Same as @dynare(modfile::AbstarctString) but for more than one mod file.
Same as @dynare(modfile::AbstractString) but for a set of mod files (`modfiles` is a vector of strings for the names of the mod files).
Uses default options.
```julia-repl
julia> @dynare ["test1", "test2"]
```
Compiles `test1.mod` and `test2.mod` with default options, the objects model_, options_ and oo_ corresponding to thess models
are respectively stored in a structures named `test1` and `test2`.
Compiles `test1.mod` and `test2.mod` with default options, the objects model_, options_ and oo_ corresponding to these models
are stored in structures named respectively `test1` and `test2`.
"""
macro dynare(modfiles::Expr)
if modfiles.head != :vect
......@@ -342,7 +295,7 @@ end
@dynare(modfile::AbstractString, opts)
Compiles a mod file (`modfile` is a string for the name of the mod files with or without extension) with non default
options, and load the generated objects into the workspace.
options, and loads the generated objects into the workspace.
```julia-repl
julia> @dynare "test1" :nograph :json "compute"
......@@ -360,7 +313,7 @@ end
@dynare(modfile::AbstractString)
Compiles a mod file (`modfile` is a string for the name of the mod files with or without extension) with default
options, and load the generated objects into the workspace.
options, and loads the generated objects into the workspace.
```julia-repl
julia> @dynare "test1"
......@@ -374,10 +327,45 @@ macro dynare(modfile::AbstractString)
return Expr(:import, Expr(:., Symbol(basename)))
end
"""
compile(modfile::AbstractString, options::PreprocessorOptions)
Compiles `modfile` with `options`, calling the Dynare's preprocessor.
"""
function compile(modfile::AbstractString, options::PreprocessorOptions)
# Add current path to LOAD_PATH if necessary.
if isempty(findall((in)(LOAD_PATH), [pwd()]))
pushfirst!(LOAD_PATH, pwd())
end
# Append extension if necessary and check extension.
basename, ext = splitext(modfile)
if isempty(ext)
modfile = "$modfile.mod"
else
if ~isdynarefile(ext)
error("The Dynare model file must have a mod or dyn extension!")
end
end
# Call the preprocessor.
opts = split(print(options))
run(`$dynare $modfile $opts`)
end
"""
compile(modfile::AbstractString)
Compiles `modfile` with default options, calling the Dynare's preprocessor.
"""
function compile(modfile::AbstractString)
opts = PreprocessorOptions()
compile(modfile, opts)
end
"""
compile(modfiles::Expr, opts...)
Compiles a set of mod files (`modfile` is a vector of strings for the names of the mod files) with options defined in opts.
Compiles a set of mod files (`modfiles` is a vector of strings for the names of the mod files) with options defined in opts.
# Examples
```julia-repl
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment