julia: initial preprocessor stub
parent
f7ad244247
commit
d70817ba1e
|
@ -24,19 +24,10 @@ function dynare(modfile)
|
|||
# Process modfile
|
||||
println(string("Using ", WORD_SIZE, "-bit preprocessor"))
|
||||
preprocessor = string(dirname(@__FILE__()), "/preprocessor", WORD_SIZE, "/dynare_m")
|
||||
run(`$preprocessor $modfile`)
|
||||
|
||||
# Temporary: clean up Matlab output
|
||||
basename = split(modfile, ".mod", false)
|
||||
mfiles = filter(r".*\.m", readdir())
|
||||
for file in mfiles
|
||||
if isempty(search(file, ".mod"))
|
||||
rm(file)
|
||||
end
|
||||
end
|
||||
rm(basename[1], recursive=true)
|
||||
run(`$preprocessor $modfile language=julia output=dynamic`)
|
||||
|
||||
# Load module created by preprocessor
|
||||
basename = split(modfile, ".mod", false)
|
||||
require(basename[1])
|
||||
end
|
||||
|
||||
|
|
|
@ -49,7 +49,7 @@ usage()
|
|||
{
|
||||
cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]"
|
||||
<< " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]"
|
||||
<< " [-D<variable>[=<value>]] [nostrict] [fast] [minimal_workspace] [output=dynamic|first|second|third] [language=C|C++]"
|
||||
<< " [-D<variable>[=<value>]] [nostrict] [fast] [minimal_workspace] [output=dynamic|first|second|third] [language=C|C++|julia]"
|
||||
#if defined(_WIN32) || defined(__CYGWIN32__)
|
||||
<< " [cygwin] [msvc]"
|
||||
#endif
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2014 Dynare Team
|
||||
* Copyright (C) 2014-2015 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -35,7 +35,7 @@ enum LanguageOutputType
|
|||
c, // outputs files for C
|
||||
cpp, // outputs files for C++
|
||||
cuda, // outputs files for CUDA (not yet implemented)
|
||||
julia, // outputs files for Julia (not yet implemented)
|
||||
julia, // outputs files for Julia
|
||||
python, // outputs files for Python (not yet implemented) (not yet implemented)
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -75,7 +75,9 @@ all-local: $(PROGRAMS)
|
|||
ARCH="64"; \
|
||||
fi; \
|
||||
mkdir -p ../matlab/preprocessor$$ARCH ; \
|
||||
cd ../matlab/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS)
|
||||
cd ../matlab/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS) ; \
|
||||
mkdir -p ../../julia/preprocessor$$ARCH ; \
|
||||
cd ../../julia/preprocessor$$ARCH && $(LN_S) -f $(abs_srcdir)/$(PROGRAMS) $(PROGRAMS)
|
||||
|
||||
if HAVE_DOXYGEN
|
||||
html-local:
|
||||
|
|
|
@ -836,6 +836,9 @@ ModFile::writeExternalFiles(const string &basename, FileOutputType output, Langu
|
|||
case cpp:
|
||||
writeExternalFilesCC(basename, output);
|
||||
break;
|
||||
case julia:
|
||||
writeExternalFilesJulia(basename, output);
|
||||
break;
|
||||
default:
|
||||
cerr << "This case shouldn't happen. Contact the authors of Dynare" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -1051,3 +1054,42 @@ ModFile::writeModelCC(const string &basename) const
|
|||
mOutputFile.close();
|
||||
}
|
||||
|
||||
void
|
||||
ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output) const
|
||||
{
|
||||
ofstream jlOutputFile;
|
||||
if (basename.size())
|
||||
{
|
||||
string fname(basename);
|
||||
fname += ".jl";
|
||||
jlOutputFile.open(fname.c_str(), ios::out | ios::binary);
|
||||
if (!jlOutputFile.is_open())
|
||||
{
|
||||
cerr << "ERROR: Can't open file " << fname
|
||||
<< " for writing" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cerr << "ERROR: Missing file name" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
jlOutputFile << "module " << basename << endl
|
||||
<< "#" << endl
|
||||
<< "# Note : this file was automatically generated by Dynare" << endl
|
||||
<< "# from " << basename << ".mod" << endl
|
||||
<< "#" << endl
|
||||
<< "using model" << endl
|
||||
<< "using utils" << endl
|
||||
<< "export dynamicmodel!, staticmodel!, steadystate!" << endl
|
||||
<< "export model__" << endl
|
||||
<< "model__ = modeldescription()" << endl
|
||||
<< "model__.fname = \"" << basename << "\"" << endl;
|
||||
|
||||
symbol_table.writeJuliaOutput(jlOutputFile);
|
||||
|
||||
jlOutputFile << "end" << endl;
|
||||
jlOutputFile.close();
|
||||
}
|
||||
|
|
|
@ -155,6 +155,7 @@ public:
|
|||
void writeExternalFiles(const string &basename, FileOutputType output, LanguageOutputType language) const;
|
||||
void writeExternalFilesC(const string &basename, FileOutputType output) const;
|
||||
void writeExternalFilesCC(const string &basename, FileOutputType output) const;
|
||||
void writeExternalFilesJulia(const string &basename, FileOutputType output) const;
|
||||
//! Writes C output files only => No further Matlab processing
|
||||
void writeCOutputFiles(const string &basename) const;
|
||||
void writeModelC(const string &basename) const;
|
||||
|
|
|
@ -718,3 +718,75 @@ SymbolTable::getOrigEndogenous() const
|
|||
origendogs.insert(it->second);
|
||||
return origendogs;
|
||||
}
|
||||
|
||||
void
|
||||
SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenException)
|
||||
{
|
||||
if (!frozen)
|
||||
throw NotYetFrozenException();
|
||||
|
||||
if (exo_nbr() > 0)
|
||||
{
|
||||
output << "model__.exonames = [\"" << getName(exo_ids[0]) << "\"";
|
||||
for (int id = 1; id < exo_nbr(); id++)
|
||||
output << ", \"" << getName(exo_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.tex_exonames = [\"" << getTeXName(exo_ids[0]) << "\"";
|
||||
for (int id = 1; id < exo_nbr(); id++)
|
||||
output << ", \"" << getTeXName(exo_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.long_exonames = [\"" << getLongName(exo_ids[0]) << "\"";
|
||||
for (int id = 1; id < exo_nbr(); id++)
|
||||
output << ", \"" << getLongName(exo_ids[id]) << "\"";
|
||||
output << "]" << endl;
|
||||
}
|
||||
|
||||
if (exo_det_nbr() > 0)
|
||||
{
|
||||
output << "model__.exodetnames = [\"" << getName(exo_det_ids[0]) << "\"";
|
||||
for (int id = 1; id < exo_det_nbr(); id++)
|
||||
output << ", \"" << getName(exo_det_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.tex_exodetnames = [\"" << getTeXName(exo_det_ids[0]) << "\"";
|
||||
for (int id = 1; id < exo_det_nbr(); id++)
|
||||
output << ", \"" << getTeXName(exo_det_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.long_exodetnames = [\"" << getLongName(exo_det_ids[0]) << "\"";
|
||||
for (int id = 1; id < exo_det_nbr(); id++)
|
||||
output << ", \"" << getLongName(exo_det_ids[id]) << "\"";
|
||||
output << "]" << endl;
|
||||
}
|
||||
|
||||
if (endo_nbr() > 0)
|
||||
{
|
||||
output << "model__.endonames = [\"" << getName(endo_ids[0]) << "\"";
|
||||
for (int id = 1; id < endo_nbr(); id++)
|
||||
output << ", \"" << getName(endo_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.tex_endonames = [\"" << getTeXName(endo_ids[0]) << "\"";
|
||||
for (int id = 1; id < endo_nbr(); id++)
|
||||
output << ", \"" << getTeXName(endo_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.long_endonames = [\"" << getLongName(endo_ids[0]) << "\"";
|
||||
for (int id = 1; id < endo_nbr(); id++)
|
||||
output << ", \"" << getLongName(endo_ids[id]) << "\"";
|
||||
output << "]" << endl;
|
||||
}
|
||||
|
||||
if (param_nbr() > 0)
|
||||
{
|
||||
output << "model__.paramnames = [\"" << getName(param_ids[0]) << "\"";
|
||||
for (int id = 1; id < param_nbr(); id++)
|
||||
output << ", \"" << getName(param_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.tex_paramnames = [\"" << getTeXName(param_ids[0]) << "\"";
|
||||
for (int id = 1; id < param_nbr(); id++)
|
||||
output << ", \"" << getTeXName(param_ids[id]) << "\"";
|
||||
output << "]" << endl
|
||||
<< "model__.long_paramnames = [\"" << getLongName(param_ids[0]) << "\"";
|
||||
for (int id = 1; id < param_nbr(); id++)
|
||||
output << ", \"" << getLongName(param_ids[id]) << "\"";
|
||||
output << "]" << endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -283,6 +283,8 @@ public:
|
|||
inline int orig_endo_nbr() const throw (NotYetFrozenException);
|
||||
//! Write output of this class
|
||||
void writeOutput(ostream &output) const throw (NotYetFrozenException);
|
||||
//! Write Julia output of this class
|
||||
void writeJuliaOutput(ostream &output) const throw (NotYetFrozenException);
|
||||
//! Write C output of this class
|
||||
void writeCOutput(ostream &output) const throw (NotYetFrozenException);
|
||||
//! Write CC output of this class
|
||||
|
|
Loading…
Reference in New Issue