| 60 | } |
| 61 | |
| 62 | void Test(double *testTimes) |
| 63 | { |
| 64 | asIScriptEngine *engine = asCreateScriptEngine(ANGELSCRIPT_VERSION); |
| 65 | COutStream out; |
| 66 | engine->SetMessageCallback(asMETHOD(COutStream,Callback), &out, asCALL_THISCALL); |
| 67 | RegisterScriptArray(engine, false); |
| 68 | |
| 69 | asIScriptModule *mod = engine->GetModule(0, asGM_ALWAYS_CREATE); |
| 70 | mod->AddScriptSection(TESTNAME, script, strlen(script), 0); |
| 71 | mod->Build(); |
| 72 | |
| 73 | #ifndef _DEBUG |
| 74 | asIScriptContext *ctx = engine->CreateContext(); |
| 75 | ctx->Prepare(mod->GetFunctionByDecl("void TestArray()")); |
| 76 | |
| 77 | double time = GetSystemTimer(); |
| 78 | |
| 79 | int r = 0; |
| 80 | |
| 81 | // Test mixed creation of array object and access of elements |
| 82 | r = ctx->Execute(); |
| 83 | |
| 84 | time = GetSystemTimer() - time; |
| 85 | |
| 86 | if( r != 0 ) |
| 87 | { |
| 88 | printf("Execution didn't terminate with asEXECUTION_FINISHED\n"); |
| 89 | if( r == asEXECUTION_EXCEPTION ) |
| 90 | { |
| 91 | printf("Script exception\n"); |
| 92 | asIScriptFunction *func = ctx->GetExceptionFunction(); |
| 93 | printf("Func: %s\n", func->GetName()); |
| 94 | printf("Line: %d\n", ctx->GetExceptionLineNumber()); |
| 95 | printf("Desc: %s\n", ctx->GetExceptionString()); |
| 96 | } |
| 97 | } |
| 98 | else |
| 99 | testTimes[0] = time; |
| 100 | |
| 101 | ctx->Prepare(mod->GetFunctionByDecl("void TestArray2()")); |
| 102 | |
| 103 | time = GetSystemTimer(); |
| 104 | |
| 105 | // Test pure access of elements |
| 106 | // http://www.gamedev.net/topic/661177-qtscript-vs-angelscript/ |
| 107 | |
| 108 | // TODO: run-time optimize: By allowing the application to tell the compiler how a call can be inlined |
| 109 | // it would be possible to optimize this further. The inlined version of opIndex |
| 110 | // would look something like: |
| 111 | // |
| 112 | // ChkIdx index, length // Check if the index is valid |
| 113 | // ADDSi v24 // Move the this pointer to the internal buffer |
| 114 | // RDSPtr // Dereference pointer |
| 115 | // ADDSi v8 // Move the this pointer to the start of the array |
| 116 | // ADDSi index, element size // Move the this pointer to the correct element |
| 117 | // PopRPtr // Load the address of the reference into the register |
| 118 | // Pop 4 // Remove the index argument from the stack |
| 119 | // |
nothing calls this directly
no test coverage detected