int ConstantEntry::scanValue(const AbstractQoreNode* n) const { switch (get_node_type(n)) { case NT_LIST: { ConstListIterator i(reinterpret_cast<const QoreListNode*>(n)); while (i.next()) if (scanValue(i.getValue())) return -1; return 0; } case NT_HASH: { ConstHashIterator i(reinterpret_cast<const QoreHashNode*>(n)); while (i.next()) if (scanValue(i.getValue())) return -1; return 0; } // could have any value and could change at runtime case NT_OBJECT: case NT_FUNCREF: return -1; } return 0; }
/* scanVector - scan vector value */ void write_ctx::scanTuple(value v) { scanValue(CsTupleName(v)); int_t size = CsTupleSize(v); value *p = CsTupleAddress(v); while (--size >= 0) scanValue(*p++); }
/* scanObjectValue - write an obj value */ void write_ctx::scanObjectValue(value v) { each_property gen(c,v); for(value tag, val; gen(tag, val);) { scanValue(tag); scanValue(val); } }
/* writeVectorValue - write a vector value */ void write_ctx::scanVectorValue(value v) { int_t size = CsVectorSize(c,v); value *p = CsVectorAddress(c,v); while (--size >= 0) scanValue(*p++); }
double SingleBeamScanner::scanValue(int x,int y,int originX,int originY, int recursivedepth) { if(x<0||x>=polygon->nx || y<0||y>=polygon->ny || (x==originX && y == originY)) return 0; int status = polygon->matrix[x][y]->getStatus(); if(recursivedepth == 0) { if(status == 0) return 1.0; // ((x-originX)*(x-originX) + (y-originY)*(y-originY)); if(status == 1) return 0; if(status == 5) return 0; return 0; } double a = 0; if(status == 0) a = 0.5;//(recursivedepth*recursivedepth+1.0) / ((x-originX)*(x-originX) + (y-originY)*(y-originY)); if(status == 0 || status == 1) return (a + scanValue(x+1,y, originX,originY, recursivedepth-1) + scanValue(x-1,y, originX,originY, recursivedepth-1) + scanValue(x,y+1, originX,originY, recursivedepth-1) + scanValue(x,y-1, originX,originY, recursivedepth-1))/8; /* scanValue(x+1,y-1, originX,originY, recursivedepth-1) + //diagonalt scanValue(x-1,y+1, originX,originY, recursivedepth-1) + scanValue(x+1,y+1, originX,originY, recursivedepth-1) + scanValue(x-1,y-1, originX,originY, recursivedepth-1))*/ return 0; }
Value* interpereteValue(Token *t){ Value *v = NULL, *v2 = NULL, *v3 = NULL; if(t==NULL) return NULL; int nValueBuffOld=nValueBuff; int nValueExtraBuffOld = nValueExtraBuff; switch (t->type){ default: PERRORTOK("", t); v=interpereteValue(t->firstChild); break; case VALUE: v=interpereteValue(t->firstChild); break; case ASSIGNMENT: { interpereteValue(t->firstChild->nextSibling); v2 = valueBuff + nValueBuff; v = interpreteAssignment(getVarName((int)t->firstChild->extra), v2->type, v2->extra); break; } case VARIABLE: { std::string name(getVarName((int)t->extra)); v2 = getVal(name); v = valueBuff+nValueBuff++; switch(v2->type){ case INTEGER: v->type = INTEGER; v->extra = valueExtraBuff+nValueExtraBuff; *((int*)v->extra) = *((int*)v2->extra); nValueExtraBuff+=sizeof(int); break; case FLOAT: v->type = FLOAT; v->extra = valueExtraBuff+nValueExtraBuff; *((float*)v->extra) = *((float*)v2->extra); nValueExtraBuff+=sizeof(float); break; case STRING: v->type = STRING; v->extra = valueExtraBuff+nValueExtraBuff; strcpy((char*)v->extra, (char*)v2->extra); nValueExtraBuff+=strlen((char*)v->extra)+1; break; } } break; case STRING: v = valueBuff+nValueBuff++; v->type = STRING; v->extra = valueExtraBuff+nValueExtraBuff; strcpy((char*)v->extra, (char*)t->extra); nValueExtraBuff+=strlen((char*)v->extra)+1; break; case INTEGER: v = valueBuff+nValueBuff++; v->type = INTEGER; v->extra = valueExtraBuff+nValueExtraBuff; *((int*)v->extra) = *((int*)t->extra); nValueExtraBuff+=sizeof(int); break; case FLOAT: v = valueBuff+nValueBuff++; v->type = FLOAT; v->extra = valueExtraBuff+nValueExtraBuff; *((float*)v->extra) = *((float*)t->extra); nValueExtraBuff+=sizeof(float); break; case OPERATOR: v3 = valueBuff + nValueBuff - 1; if (!isOperatorSingle((int)t->extra)) { v2 = valueBuff+nValueBuff-2; int type = (int)t->extra; if(v2->type < v3->type){ convert(v2, (int)v3->type); }else if(v2->type > v3->type){ convert(v3, (int)v2->type); } } switch (v3->type){ case STRING: v = interpereteStringOperator(t, v2, v3); break; case FLOAT: v = interpereteFloatOperator(t, v2, v3); break; case INTEGER: v = interpereteIntegerOperator(t, v2, v3); break; } if (!isOperatorSingle((int)t->extra)) nValueBuff--; break; case FUNC_DEF: { FuncDefExtra *extra = (FuncDefExtra*)t->extra; std::string name(getVarName((int)extra->name->extra)); v2 = getVal(name); v2->type = FUNC_DEF; v2->extra = t; } break; case FUNC_CALL: { FuncCallExtra *extra = (FuncCallExtra*)t->extra; std::string name(getVarName((int)extra->name->extra)); if (name == "print") { printValues(extra->values); } else if (name == "scan") { scanValue(); } else { Value *val = getVal(name); currentStack++; Token *funcDefToken = (Token*)val->extra; FuncDefExtra *defExtra = (FuncDefExtra*)funcDefToken->extra; Token *t_val = extra->values; Token *t_def = defExtra->parameters; while (t_val) { interpereteValue(t_val->firstChild); v2 = valueBuff + nValueBuff; interpreteAssignment(getVarName((int)t_def->extra), v2->type, v2->extra); t_val = t_val->nextSibling; t_def = t_def->nextSibling; } interpreteFlow(defExtra->func_body); currentStack--; } } break; } v2 = interpereteValue(t->nextSibling); nValueBuff = nValueBuffOld; nValueExtraBuff = nValueExtraBuffOld; return v2?v2:v; }
int ConstantEntry::parseInit(ClassNs ptr) { //printd(5, "ConstantEntry::parseInit() this: %p '%s' pub: %d init: %d in_init: %d node: %p '%s' class context: %p '%s' ns: %p ('%s') pub: %d\n", this, name.c_str(), pub, init, in_init, node, get_type_name(node), ptr.getClass(), ptr.getClass() ? ptr.getClass()->name.c_str() : "<none>", ptr.getNs(), ptr.getNs() ? ptr.getNs()->name.c_str() : "<none>", ptr.getNs() ? ptr.getNs()->pub : 0); if (init) return 0; if (in_init) { parse_error("recursive constant reference found to constant '%s'", name.c_str()); return 0; } ConstantEntryInitHelper ceih(*this); if (!node) return 0; int lvids = 0; { // set parse location in case of errors ParseLocationHelper plh(loc); // push parse class context qore_class_private* p = ptr.getClass(); QoreParseClassHelper qpch(p ? p->cls : 0); // ensure that there is no accessible local variable state VariableBlockHelper vbh; // set parse options and warning mask for this statement ParseWarnHelper pwh(pwo); //printd(5, "ConstantEntry::parseInit() this: %p '%s' about to init node: %p '%s' class: %p '%s'\n", this, name.c_str(), node, get_type_name(node), p, p ? p->name.c_str() : "n/a"); if (typeInfo) typeInfo = 0; node = node->parseInit((LocalVar*)0, PF_CONST_EXPRESSION, lvids, typeInfo); } //printd(5, "ConstantEntry::parseInit() this: %p %s initialized to node: %p (%s) value: %d\n", this, name.c_str(), node, get_type_name(node), node->is_value()); if (node->is_value()) return 0; // do not evaluate expression if any parse exceptions have been thrown QoreProgram* pgm = getProgram(); if (pgm->parseExceptionRaised()) { discard(node, 0); node = 0; typeInfo = nothingTypeInfo; return -1; } // evaluate expression ExceptionSink xsink; { ReferenceHolder<AbstractQoreNode> v(node->eval(&xsink), &xsink); //printd(5, "ConstantEntry::parseInit() this: %p %s evaluated to node: %p (%s)\n", this, name.c_str(), *v, get_type_name(*v)); if (!xsink) { node->deref(&xsink); node = v.release(); if (!node) { node = nothing(); typeInfo = nothingTypeInfo; } else { typeInfo = getTypeInfoForValue(node); check_constant_cycle(pgm, node); // address circular refs: pgm->const->pgm } } else { node->deref(&xsink); node = 0; typeInfo = nothingTypeInfo; } } if (xsink.isEvent()) qore_program_private::addParseException(pgm, xsink, &loc); // scan for call references if (scanValue(node)) { saved_node = node; node = new RuntimeConstantRefNode(refSelf()); } return 0; }
Target SingleBeamScanner::findClose(int x,int y) { std::cout << "findclose" << std::endl; std::vector<Element*> neighbours; //int x_arr[] = {x , x+1, x+1 ,x+1 ,x ,x-1 ,x-1 ,x-1}; //int y_arr[] = {y-1 , y-1, y ,y+1 ,y+1 ,y+1 ,y ,y-1}; //Diagonalt int x_arr[] = {x , x+1, x ,x-1}; int y_arr[] = {y-1, y , y+1 ,y}; for(int i=0;i<4;i++) { if(x_arr[i]<0 || x_arr[i]>=polygon->nx || y_arr[i]<0 || y_arr[i]>=polygon->ny) continue; if(polygon->matrix[x_arr[i]][y_arr[i]]->getStatus() == 5) continue; if(polygon->matrix[x_arr[i]][y_arr[i]]->getStatus() == 0 || polygon->matrix[x_arr[i]][y_arr[i]]->getStatus() == 1) neighbours.push_back(polygon->matrix[x_arr[i]][y_arr[i]]); } //std::cout << "neighbours: " << neighbours.size() << std::endl; //for(int i=0;i<neighbours.size();i++) //{ //std::cout << "(" << neighbours.at(i)->getIndexX() << "," << neighbours.at(i)->getIndexY() << ")" << std::endl; //} //calulate the values of the neighbours double highestValue = -std::numeric_limits<double>::max(); bool unscanned = false; int index = -1; double scanweight = 1; double nearweight = 1.2;//.07; double headingweight = 0.7; for(int i=0;i<neighbours.size();i++) { Element* n = neighbours.at(i); double scanVal = scanweight * scanValue(n->getIndexX(),n->getIndexY(),x,y,0); double nearVal = nearweight * nearValue(n->getIndexX(),n->getIndexY(),x,y,0); double headingVal = headingweight * headingValue(n->getIndexX(),n->getIndexY(),x,y); std::cout << "\nElement : (" << n->getIndexX() << "," << n->getIndexY() << ")" << std::endl; std::cout << "scanValue : " << scanVal << std::endl; std::cout << "nearValue : " << nearVal << std::endl; std::cout << "headingValue : " << headingVal << std::endl; //std::cout << "highestValue: " << highestValue << std::endl; double value = scanVal + nearVal + headingVal; if(!unscanned) { if(n->getStatus() == 0) { highestValue = value; index = i; unscanned = true; std::cout << "unscanned element found" << std::endl; } else if(value > highestValue && scanVal !=0) { highestValue = value; index = i; std::cout << "scanned element is the best so far" << std::endl; } } else { if(unscanned && n->getStatus() == 0 && value > highestValue) { highestValue = value; index = i; std::cout << "unscanned element is the best so far" << std::endl; } } } if(index != -1 && highestValue != 0) { std::cout << "Best target: (" << neighbours.at(index)->getIndexX() << "," << neighbours.at(index)->getIndexY() << ")" << std::endl; int status = 0; //sucsess return Target(neighbours.at(index)->getIndexX(),neighbours.at(index)->getIndexY(),status); } int status = 1; //failed to find a good target return Target(x,y,status); }