Ejemplo n.º 1
0
void ScriptedFitnessFunction::addCustomScriptContextStructures() {

	ScriptingContext::addCustomScriptContextStructures();
	
	QScriptValue error = mScript->evaluate(QString("function terminateTry() {")
					  + "  nerd.terminateCurrentTry() };");
	if(mScript->hasUncaughtException()) {
		reportError(QString("Could not add defVar function. ") 
						+ error.toString());
		return;
	}

	error = mScript->evaluate("var fitness = nerd.fitness;");
	if(mScript->hasUncaughtException()) {
		reportError(QString("Could not add fitness variable. ") 
						+ error.toString());
		return;
	}

	defineVariable("tryCount", EvolutionConstants::VALUE_EXECUTION_NUMBER_OF_TRIES, false);
	defineVariable("stepCount", EvolutionConstants::VALUE_EXECUTION_NUMBER_OF_STEPS, false);

	error = mScript->evaluate(
			"function _calculateFitness() { fitness = nerd.fitness; nerd.fitness = this.calc(); };");
	if(mScript->hasUncaughtException()) {
		reportError(QString("Could not add _calculateFitness() method. Naming conflict? ")
					+ error.toString());
		return;
	}
}
Ejemplo n.º 2
0
sExpression *evalDefineSyntax(sExpression *exp, sEnvironment *env){
  if(isDefinitionSyntax(exp) && isSyntaxRules( cadr(toList( cdr(toList(exp)))))){
    sSymbol *name = toSymb(cadr(toList(exp)));
    sExpression *rules = cdr(toList( cdr(toList( cadr(toList( cdr(toList( exp))))))));
    defineVariable(name, callProcSyntaxRules(rules), env);
    return &sTrue;
  }
  return &sError;
}
Ejemplo n.º 3
0
void EXParser::loadDefaultVariables(void)

{

	defineVariable("pi",   3.14159);   //pi constant

	//defineVariable("e",    2.718282);  //eulers constant

}
Ejemplo n.º 4
0
/* BAD PART. NEEDS REFACTORING */
void Configurator::handleConfigurationFileLine(std::string line, int type) {
	std::string configurationExpressions[] = {CONFIGURATIONEXPRESSIONS};
	int numberOfExpressions = sizeof(configurationExpressions) / sizeof(std::string);
	double value = -1;
	for(int i = 0; i < numberOfExpressions; i++) {
		std::string toFind(configurationExpressions[i]);
		std::size_t found = line.find(toFind);
		if (found != std::string::npos) {
			value = getNumberFromString(line);
			defineVariable(i, value, type);
		}
	}
}
Ejemplo n.º 5
0
Archivo: exec.c Proyecto: phyrrus9/lang
void XS08(struct S08_st *d) {
	//var = expression;
	int eval;
	int (*fnc)(void *) = NULL;
	defineVariable(&variableList, d->name); //define if not exists
	switch (d->t) {
		case tE01:
			fnc = &XE01;
			break;
		case tE02:
			fnc = &XE02;
			break;
		case tE03:
			fnc = &XE03;
			break;
		default:
			fprintf(stderr, "Unknown expression\n");
			abort();
	}
	eval = *fnc(d->match);
	setVariable(&variableList, d->name, eval);
}
Ejemplo n.º 6
0
Archivo: exec.c Proyecto: phyrrus9/lang
void XS06(struct S06_st *d) {
	//def var
	if (!defineVariable(&variableList, d->name))
		fprintf(stderr, "%s is already defined!\n", d->name);
}
Ejemplo n.º 7
0
sExpression *evalDefine(sExpression *exp, sEnvironment *env){
  if(defineVariable(definitionSymbol(exp), eval(definitionValue(exp, env), env), env)){
    return &sTrue;
  }
  return &sFalse;
}