| 5 | #define TUTORIAL_NAME "/scripts/daSTestAOT/test.das" |
| 6 | |
| 7 | void tutorial () { |
| 8 | TextPrinter tout; // output stream for all compiler messages (stdout. for stringstream use TextWriter) |
| 9 | ModuleGroup dummyLibGroup; // module group for compiled program |
| 10 | CodeOfPolicies policies; // compiler setup |
| 11 | auto fAccess = make_smart<FsFileAccess>(); // default file access |
| 12 | policies.aot = true; |
| 13 | // compile program |
| 14 | auto program = compileDaScript(getDasRoot() + TUTORIAL_NAME, fAccess, tout, dummyLibGroup, false, policies); |
| 15 | if ( program->failed() ) { |
| 16 | // if compilation failed, report errors |
| 17 | tout << "failed to compile\n"; |
| 18 | for ( auto & err : program->errors ) { |
| 19 | tout << reportError(err.at, err.what, err.extra, err.fixme, err.cerr ); |
| 20 | } |
| 21 | return; |
| 22 | } |
| 23 | // create daScript context |
| 24 | Context ctx(program->getContextStackSize()); |
| 25 | if ( !program->simulate(ctx, tout) ) { |
| 26 | // if interpretation failed, report errors |
| 27 | tout << "failed to simulate\n"; |
| 28 | for ( auto & err : program->errors ) { |
| 29 | tout << reportError(err.at, err.what, err.extra, err.fixme, err.cerr ); |
| 30 | } |
| 31 | return; |
| 32 | } |
| 33 | // find function 'test' in the context |
| 34 | auto fnTest = ctx.findFunction("test"); |
| 35 | if ( !fnTest ) { |
| 36 | tout << "function 'test' not found\n"; |
| 37 | return; |
| 38 | } |
| 39 | // verify if 'test' is a function, with the correct signature |
| 40 | // note, this operation is slow, so don't do it every time for every call |
| 41 | if ( !verifyCall<bool>(fnTest->debugInfo, dummyLibGroup) ) { |
| 42 | tout << "function 'test', call arguments do not match. expecting def test : void\n"; |
| 43 | return; |
| 44 | } |
| 45 | // evaluate 'test' function in the context |
| 46 | ctx.evalWithCatch(fnTest, nullptr); |
| 47 | if ( auto ex = ctx.getException() ) { // if function cased panic, report it |
| 48 | tout << "exception: " << ex << "\n"; |
| 49 | return; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | int main(int argc, char * argv[]) |
| 54 | { |
no test coverage detected