1164 {
1165
1166 ASTNode* loc;
1167 ASTRunner runner(
model_,
script, interactive, *
context_, loc, paylog, paylog !=
nullptr && includePastCashflows);
1168
1169 randomvariable_output_pattern pattern;
1171 pattern = randomvariable_output_pattern(randomvariable_output_pattern::pattern::expectation);
1173 pattern = randomvariable_output_pattern(randomvariable_output_pattern::pattern::left_middle_right);
1174 } else {
1175 QL_FAIL("model type not handled when setting output pattern for random variables");
1176 }
1177
1178 DLOG(
"run script engine, context before run is:");
1180
1181 if (interactive) {
1182 std::cerr << pattern << "\nInitial Context: \n" << (*context_) << std::endl;
1183 }
1184
1185 boost::timer::cpu_timer timer;
1186 try {
1188 root_->accept(runner);
1189 timer.stop();
1190 QL_REQUIRE(runner.value.size() == 1,
1191 "ScriptEngine::run(): value stack has wrong size (" << runner.value.size() << "), should be 1");
1192 QL_REQUIRE(runner.filter.size() == 1,
1193 "ScriptEngine::run(): filter stack has wrong size (" << runner.filter.size() << "), should be 1");
1194 DLOG(
"script engine successfully finished, context after run is:");
1195
1196 if (interactive) {
1197 std::cerr << "\nScript engine finished without errors. Context after run:" << std::endl;
1198 }
1199
1200 } catch (const std::exception& e) {
1201 std::ostringstream errorMessage;
1202 errorMessage << "Error during script execution: " << e.what() << " at "
1203 << (loc ?
to_string(loc->locationInfo) :
"(last visited ast node not known)") <<
": "
1205
1206 std::ostringstream strippedErrorMsg;
1207 strippedErrorMsg << "Error during script execution: " << e.what() << " at "
1208 << (loc ?
to_string(loc->locationInfo) :
"(last visited ast node not known)");
1209
1214
1215 if (interactive) {
1216 std::cerr << strippedErrorMsg.str() << "\n";
1218 std::cerr << "Context when hitting the error:" << std::endl;
1219 std::cerr << (*context_) << std::endl;
1220 std::cin.get();
1221 }
1222
1223 QL_FAIL(errorMessage.str());
1224 }
1225
1227 DLOG(
"Script engine running time: " << boost::timer::format(timer.elapsed()));
1228
1229 if (interactive) {
1230 std::cerr << pattern << *
context_ << std::endl;
1231 std::cin.get();
1232 }
1233}
#define DLOG(text)
Logging Macro (Level = Debug)
#define DLOGGERSTREAM(text)
std::string printCodeContext(std::string script, const ASTNode *loc, bool compact)
void reset(const ASTNodePtr root)
std::string to_string(const LocationInfo &l)