SGSValue SGSVirtualMachine::runFunction(int id,SGSArguments *args)
{
    return runFunction(getFrameStackTop().getValue(id)->operator SGSFunction *(),args);
}
SGSValue SGSVirtualMachine::runFunction(std::string functionName,SGSArguments *args)
{
    return runFunction(getFrameStackTop().getValue(m_analyzer.getIdentifierId(functionName.c_str()))->operator SGSFunction *(),args);
}
Ejemplo n.º 3
0
// The test definition
void TestRunnerVisitor::VisitTestDefinition(TestDefinition *TD) {
	TestResults results(mOrder);
	results.mColumnNames = mColumnNames;
	results.using_fork = !NoForkOpt.getValue();
	string test_name = TestResults::getColumnString(TEST_NAME, TD);
	results.mTmpFileName = test_name + "-tmp.txt";
	pid_t pid;

	if(NoForkOpt.getValue() == false) {
#ifdef __MINGW32__
		cout << "Warning: Running test in same address space as jcut" << endl;
		pid = 0;
#else
		if(pipe(results.mPipe) == -1)
			throw JCUTException("Could not create pipes for communication with the test "+test_name);

		pid = fork();
#endif
		if(pid == -1)
			throw JCUTException("Could not fork process for test "+test_name);
	}
	else
		pid = 0;

	if(pid == 0) { // Child process will execute the test
		if(TD->hasTestMockup()) {
			vector<MockupFunction*> mockups=
				TD->getTestMockup()->getMockupFixture()->getMockupFunctions();

			for(MockupFunction* m : mockups) {
				llvm::Function* change_to_mockup = m->getMockupFunction();
				mEE->runFunction(change_to_mockup,mArgs);
			}
		}

		runFunction(TD);

		llvm::Function* func = TD->getLLVMResultFunction();
		if(!func)
			assert(false && "Function test result not found!");
		llvm::GenericValue ret = mEE->runFunction(func, mArgs);
		TD->setPassingValue(ret.IntVal.getBoolValue());

		std::vector<ExpectedExpression*> failing;
		// @bug @todo Debug ExpectedExpressions: Try all possible combinations.
		// When the test does not have an expected result and the expected expression
		// should fail, it always passess.
		for(ExpectedExpression* ptr : mExpExpr) {
			llvm::Function* ee_func = ptr->getLLVMResultFunction();
			if(!ee_func)
				assert(false && "Function expected result result not found!");
			llvm::GenericValue ee_ret = mEE->runFunction(ee_func, mArgs);
			bool passed = ee_ret.IntVal.getBoolValue();
			if(passed == false)
				failing.push_back(ptr);
			TD->setPassingValue(passed);
		}
		mExpExpr.clear();

		// Do the opposite steps for the Mockups
		if(TD->hasTestMockup()) {
			vector<MockupFunction*> mockups =
				TD->getTestMockup()->getMockupFixture()->getMockupFunctions();
			for(MockupFunction* m : mockups) {
				llvm::Function* change_to_original = m->getOriginalFunction();
				mEE->runFunction(change_to_original,mArgs);
			}

			////////////////////////////////////////////////
			// Point to the mockup functions for the current group
			executeMockupFunctionsOnTopOfStack();
		}

		// Include failing ExpectedExpressions from before and after statements.
		if(!failing.empty())
			TD->setFailedExpectedExpressions(failing);

		results.collectTestResults(TD);
		results.saveToDisk();

		if(NoForkOpt.getValue() == false)
#ifdef __MINGW32__
			do {} while(0); // @todo implement fork in windows
#else
			_Exit(EXIT_SUCCESS);
#endif
	} // end of child process
	else { // Continue parent process
#ifdef __MINGW32__
		do {} while(0); // @todo implement fork in windows
#else
		int status = 0;
		waitpid(pid, &status, 0);
		if(WIFEXITED(status)) {
			// Child process ended normally
		} else {
			stringstream ss;
			string function_called = TD->getTestFunction()->
					getFunctionCall()->getFunctionCalledString();
			ss << "The function " << function_called
					<< " crashed during execution. More details:" << endl;
			ss << "I ran that function in a different process but it crashed. Please debug that function" << endl;
			if(WIFSIGNALED(status)) {
				ss << "Child process was terminated by signal: " << strsignal(status) << endl;
				if(WCOREDUMP(status))
					ss << "Child process produced a core dump!" << endl;
			}
			throw JCUTException(ss.str());
		}
#endif
	}

	results.mResults = results.readFromDisk();
	TD->setTestResults(results.mResults);
}
Ejemplo n.º 4
0
void gameLogic() {
	if (danmakux.player->x < 0) {
		if (danmakux.player->focused) danmakux.player->x += danmakux.player->focusspeed;
		else danmakux.player->x += danmakux.player->speed;
	}
	if (danmakux.player->x > danmakux.width-danmakux.player->width) {
		if (danmakux.player->focused) danmakux.player->x -= danmakux.player->focusspeed;
		else danmakux.player->x -= danmakux.player->speed;
	}
	if (danmakux.player->y < 0) {
		if (danmakux.player->focused) danmakux.player->y += danmakux.player->focusspeed;
		else danmakux.player->y += danmakux.player->speed;
	}
	if (danmakux.player->y > danmakux.height-danmakux.player->height) {
		if (danmakux.player->focused) danmakux.player->y -= danmakux.player->focusspeed;
		else danmakux.player->y -= danmakux.player->speed;
	}
	for (std::list<PlayerBullet>::iterator i = danmakux.playerbullets.begin(); i != danmakux.playerbullets.end(); i++) {
		if ((*i).x+(*i).width < 0 || (*i).y+(*i).height < 0 || (*i).x > danmakux.width || (*i).y > danmakux.height || (*i).dead) {
			plblt_close(&(*i));
			i = danmakux.playerbullets.erase(i);
			continue;
		}
		for (std::list<Enemy>::iterator j = danmakux.enemies.begin(); j != danmakux.enemies.end(); j++) {
			if (rect_intersects(&(*j).hitbox, &(*i).hitbox)) {
				(*j).health -= (*i).damage;
				plblt_close(&(*i));
				i = danmakux.playerbullets.erase(i);
				for (std::list<EnemyBullet>::iterator k = (*j).bullets.begin(); k != (*j).bullets.end(); k++) {
					if (circ_intersects(&(*k).hitbox, &danmakux.player->hitbox)) {
						danmakux.player->health -= (*k).damage;
						enblt_close(&(*k));
						k = (*j).bullets.erase(k);
					}
					if ((*k).x < 0 || (*k).y < 0 || (*k).x > danmakux.width || (*k).y > danmakux.height) {
						enblt_close(&(*k));
						k = (*j).bullets.erase(k);
					}
				}
				if ((*j).health <= 0) {
					(*j).dead = true;
					addItem("powerup");
				}
				if ((*j).dead && (*j).bullets.empty()) {
					enem_close(&(*j));
					j = danmakux.enemies.erase(j);
				}
			}
		}
	}
	if (danmakux.player->health <= 0) {
		danmakux.player->dead = true;
		//dying procedure
	}
	for (std::list<Item>::iterator i = danmakux.items.begin(); i != danmakux.items.end(); i++) {
		if ((*i).type == "wall") {
			if (danmakux.player->moveu && danmakux.player->y < (*i).y+(*i).height && danmakux.player->x > (*i).x && danmakux.player->x < (*i).x+(*i).width) {
				if (danmakux.player->focused) {
					danmakux.player->y += danmakux.player->focusspeed;
				}
				else {
					danmakux.player->y += danmakux.player->speed;
				}
			}
			if (danmakux.player->moved && danmakux.player->y > (*i).y && danmakux.player->x > (*i).x && danmakux.player->x < (*i).x+(*i).width) {
				if (danmakux.player->focused) {
					danmakux.player->y -= danmakux.player->focusspeed;
				}
				else {
					danmakux.player->y -= danmakux.player->speed;
				}
			}
			if (danmakux.player->movel && danmakux.player->x < (*i).x+(*i).width && danmakux.player->y > (*i).y && danmakux.player->y < (*i).y+(*i).height) {
				if (danmakux.player->focused) {
					danmakux.player->x += danmakux.player->focusspeed;
				}
				else {
					danmakux.player->x += danmakux.player->speed;
				}
			}
			if (danmakux.player->mover && danmakux.player->x > (*i).x && danmakux.player->y > (*i).y && danmakux.player->y < (*i).y+(*i).height) {
				if (danmakux.player->focused) {
					danmakux.player->x -= danmakux.player->focusspeed;
				}
				else {
					danmakux.player->x -= danmakux.player->speed;
				}
			}
		}
		if (rect_intersects(&(*i).hitbox, &danmakux.player->pickupbox)) {
			if ((*i).type == "powerup") {
				runFunction(&danmakux.player->script, "powerup");
			}
			item_close(&(*i));
			i = danmakux.items.erase(i);
		}
	}
}
Ejemplo n.º 5
0
int main(int argc, char** argv)  {
  runFunction(argc, argv);
}
Ejemplo n.º 6
0
int hpx_main()
{
    oclm::get_platform();
    //Open oclm/kernelUtil/kernels/speedTest.cl
    const std::string src = readCLFile("/kernels/speedTest.cl");
    // create a program from source ... possibly a vector of sources ...
    oclm::program p(src);
    
    std::cout << "Initializing Part 1 of the speed test: basic memory read/write and arithmetic operations.\n";
    std::vector<double> timeLocal;
    std::vector<double> timeGlobal;
    std::vector<double> timeVecAdd;
    const int iters = 19;
    for (int i = 0; i < iters; i++)
    {
        int numThreads = (int)std::pow((double)2, (double)i);
        std::string function = "assignLocal";
        std::cout << "Running basic tests with " << numThreads << " threads.\n";

        oclm::util::high_resolution_timer t;

        runFunction(p, numThreads, function);
        timeLocal.push_back(t.elapsed());
        
        function = "assignGlobal";
        t.restart();
        
        runFunction(p, numThreads, function);
        timeGlobal.push_back(t.elapsed());

        
        t.restart();
        
        function = "vecAdd";
        runFunction(p, numThreads, function);
        timeVecAdd.push_back(t.elapsed());
    }
    std::ofstream fout;
    fout.open("logSimple.txt");
    fout << "BASIC TESTS\n";
    const int width = 40;
    const int precision = 16;
    fout << "Basic (1x operation) tests to determine the I/O speed of the OpenCL device.\n";
    for (int i = 1; i < width * 3; i++)
        fout << "="; 
    fout << std::setiosflags(std::ios::right);
    fout << std::resetiosflags(std::ios::left);
    fout << std::endl;
    fout << std::setw(width) << "Local 1x Read, Global 1x Write";
    fout << std::setw(width) << "Global 1x Read/Write";
    fout << std::setw(width) << "Global 2x Read/1x Write";
    fout << std::endl;
    fout <<  "Function name in kernels/speedTest.cl:" << std::endl;
    fout << std::setw(width) << "assignLocal";
    fout << std::setw(width) << "assignGlobal";
    fout << std::setw(width) << "vecAdd";
    fout << std::endl;
    for (int i = 0; i < width * 3; i++)
        fout << "=";
    fout << std::endl;
    foutWrite(timeLocal, timeGlobal, timeVecAdd, iters, fout, precision, width);
    fout.close();
    std::cout << "Basic performance information output to logSimple.txt\n";
    
    timeLocal.clear();
    timeGlobal.clear();
    timeVecAdd.clear();

    std::cout << "Initializing Part 2 of the speed test: complex (1024x kernel repetitions) memory read/write and arithmetic operations.\n";
    for (int i = 0; i < iters; i++)
    {
        int numThreads = (int)std::pow((double)2, (double)i);
        std::string function = "assignLocalMany";
        std::cout << "Running complex tests with " << numThreads << " threads.\n";

        oclm::util::high_resolution_timer t;
        
        runFunction(p, numThreads, function);
        timeLocal.push_back(t.elapsed());
        
        function = "assignGlobalMany";
        t.restart();
        
        runFunction(p, numThreads, function);
        timeGlobal.push_back(t.elapsed());
        
        t.restart();
        
        function = "vecAddMany";
        runFunction(p, numThreads, function);
        timeVecAdd.push_back(t.elapsed());
    }
    fout.open("logComplex.txt");
    fout << "COMPLEX TESTS\n";
    fout << "Complex (1024x operation) tests to determine the memory read/write speed of the OpenCL device.\n";
    for (int i = 1; i < 90; i++)
        fout << "="; 
    fout << std::setiosflags(std::ios::right);
    fout << std::resetiosflags(std::ios::left);
    fout << std::endl;
    fout << std::setw(width) << "Local 1024x Read, Global 1024x Write";
    fout << std::setw(width) << "Global 1024x Read/Write";
    fout << std::setw(width) << "Global 2048x Read/1024x Write";
    fout << std::endl;
    fout <<  "Function name in kernels/speedTest.cl:" << std::endl;
    fout << std::setw(width) << "assignLocalMany";
    fout << std::setw(width) << "assignGlobalMany";
    fout << std::setw(width) << "vecAddMany";
    fout << std::endl;
    for (int i = 0; i < width * 3; i++)
        fout << "=";
    fout << std::endl;
    foutWrite(timeLocal, timeGlobal, timeVecAdd, iters, fout, precision, width);
    fout.close();
    std::cout << "Basic performance information output to logComplex.txt\n";
    std::cout << "Note: The basic tests are more to check the I/O rate of your OpenCL device. However, the complex tests can be very informative about the nature of memory access.\n"
        << "The first three functions in the .cl file are the basic tests, while the remaining three are the complex tests. Note how much longer it takes to access global memory rather than local memory.\n";
    //check if we're using Windows

    return hpx::finalize(); // Handles HPX shutdown
}
Ejemplo n.º 7
0
 void ScriptEngine::runFunction(bool warn_if_not_found, std::string function_name,
     std::function<void(asIScriptContext*)> callback)
 {
     std::function<void(asIScriptContext*)> get_return_value;
     runFunction(warn_if_not_found, function_name, callback, get_return_value);
 }
Ejemplo n.º 8
0
void enblt_update(EnemyBullet *blt) {
	runFunction(&blt->script, "update");
	enblt_loadPos(blt);
	enblt_animate(blt);
}
Ejemplo n.º 9
0
 void ScriptEngine::runFunction(std::string function_name,
     std::function<void(asIScriptContext*)> callback)
 {
     std::function<void(asIScriptContext*)> get_return_value;
     runFunction(function_name, callback, get_return_value);
 }