| 240 | #define SCRIPT_NAME "/tutorials/integration/cpp/06_interop.das" |
| 241 | |
| 242 | void tutorial() { |
| 243 | TextPrinter tout; |
| 244 | ModuleGroup dummyLibGroup; |
| 245 | auto fAccess = make_smart<FsFileAccess>(); |
| 246 | |
| 247 | auto program = compileDaScript(getDasRoot() + SCRIPT_NAME, |
| 248 | fAccess, tout, dummyLibGroup); |
| 249 | if (program->failed()) { |
| 250 | tout << "Compilation failed:\n"; |
| 251 | for (auto & err : program->errors) { |
| 252 | tout << reportError(err.at, err.what, err.extra, |
| 253 | err.fixme, err.cerr); |
| 254 | } |
| 255 | return; |
| 256 | } |
| 257 | |
| 258 | Context ctx(program->getContextStackSize()); |
| 259 | if (!program->simulate(ctx, tout)) { |
| 260 | tout << "Simulation failed:\n"; |
| 261 | for (auto & err : program->errors) { |
| 262 | tout << reportError(err.at, err.what, err.extra, |
| 263 | err.fixme, err.cerr); |
| 264 | } |
| 265 | return; |
| 266 | } |
| 267 | |
| 268 | auto fnTest = ctx.findFunction("test"); |
| 269 | if (!fnTest) { |
| 270 | tout << "Function 'test' not found\n"; |
| 271 | return; |
| 272 | } |
| 273 | |
| 274 | ctx.evalWithCatch(fnTest, nullptr); |
| 275 | if (auto ex = ctx.getException()) { |
| 276 | tout << "Exception: " << ex << "\n"; |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | int main(int, char * []) { |
| 281 | NEED_ALL_DEFAULT_MODULES; |
no test coverage detected