Exemple #1
0
void Blocks::build() {
	int i = 0, j = 0, k = 0;
	int halfSize = 0;
	int round = 0;

	bool * block;
	///////////////////////////////

	block = newBlock();
	block[0] = one;
	build(block, 1);
	if (size >= 5) {
		halfSize = size % 2 == 0 ? (size / 2) : (size - 1) / 2;
		for (i = 1; i < halfSize; i++) {
			for (j = 1, round = 0; j < halfSize; j++) {
				round = 0;
				block = newBlock();
				for (k = 0; k < j; k++) {
					block[convert(i, k)] = one;
					round++;
				}
				for (k = 0; k < i; k++) {
					block[convert(k, j)] = one;
					round++;
				}
				block[convert(i, j)] = one;
				round++;
				build(block, round);
			}
		}
	}
}
Exemple #2
0
void initMainGameTable()
{
	int i;
	int j;
	int x,y;


	/* malloc memory space for blocks */

	for(i=0;i<VBLOCKS;i++)
		for(j=0;j<HBLOCKS;j++){
			gameTable[i][j]=newBlock();
		}


		printf("Block table malloced\n");


	/* assign positions to malloced blocks */


		
	

		for(i=0,y=0;i<VBLOCKS;i++)
			for(j=0,x=0;j<HBLOCKS;j++)
				setBlock(gameTable[i][j],j,i);
				
			
	 printf("Blocks placed\n");	

}
Exemple #3
0
	block_ptr XML::getChildren(const node_ptr spec, bool nested) {
		block_ptr startBlock, curBlock;
		node_ptr tmpSpec(spec);
		
		while (tmpSpec) {
			block_ptr newBlock(new blocks::Block);
			
			getOpArgs(tmpSpec, newBlock);
			
			if (curBlock == nullptr) {
				startBlock = newBlock;
				curBlock = startBlock;
			} else {
				curBlock->next(newBlock);
				curBlock = curBlock->next();
			}
			
			tmpSpec.reset(tmpSpec->next_sibling(), null_deleter());
		}
		
		if (!nested) {
			curBlock->next(startBlock);
		}
		
		return startBlock;
	}
Exemple #4
0
void GalFile::readFile(const QString &fileName)
{
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
        return;

   QTextStream in(&file);
   QString line = in.readLine().simplified();
   if (line.toUpper().startsWith("ATF"))
       _metaData.insert("version",line.split(QRegExp("[,\\s+]")).last());
   else
       qDebug() << "no Gal file";

   QStringList headndata = in.readLine().simplified().split(QRegExp("\\s+"));
   int headCount = headndata.first().toInt();
   _colCount = headndata.last().toInt();
   QRegExp blockRx("Block[0-9]+");
   QRegExpValidator blockV(blockRx, 0);
   int pos=0;
   while (!in.atEnd() && headCount > 0) {
        QStringList headline = in.readLine().simplified().split('=');
        if(blockV.validate(headline.first(),pos))
            newBlock(headline.first().mid(5).toInt(),headline.last());
        else
            _metaData.insert(headline.first(),headline.last());
        headCount--;
   }
   qDebug() << _blocks.count();
   setColumnHeader(in.readLine().simplified());
   while (!in.atEnd())
   {
       setSpotData(in.readLine().simplified().remove("\""));
   }
   emit fileRead();
}
Exemple #5
0
blockDescriptor* newTBlock() {
	blockDescriptor* block = newBlock(2, 3);
	//###
	// #
	block->rotations[0][0][0] = '#';
	block->rotations[0][0][1] = '#';
	block->rotations[0][0][2] = '#';
	block->rotations[0][1][1] = '#';
	// #
	//###
	block->rotations[2][0][1] = '#';
	block->rotations[2][1][0] = '#';
	block->rotations[2][1][1] = '#';
	block->rotations[2][1][2] = '#';
	//#
	//##
	//#
	block->rotations[1][0][0] = '#';
	block->rotations[1][1][0] = '#';
	block->rotations[1][1][1] = '#';
	block->rotations[1][2][0] = '#';
	// #
	//##
	// #
	block->rotations[3][0][1] = '#';
	block->rotations[3][1][0] = '#';
	block->rotations[3][1][1] = '#';
	block->rotations[3][2][1] = '#';
	return block;
}
Exemple #6
0
void loadObject(string pathname) {
   HandleList hl;
   static char fullPath[MAX_PATH_NAME];

   hl = newBlock(HandleList);
   switch (pathname[0]) {
     case '/':
       strcpy(fullPath, pathname);
       break;
     case '~':
       strcpy(fullPath, expandPathname(pathname));
       break;
     default:
       getcwd(fullPath, MAX_PATH_NAME);
       strcat(fullPath, "/");
       strcat(fullPath, pathname);
       break;
   }
   hl->handle = dlopen(fullPath, RTLD_NOW);
   if (hl->handle == NULL) {
      freeBlock(hl);
      error("loadObject: %s", dlerror());
   }
   hl->link = handles;
   handles = hl;
}
Exemple #7
0
Map cloneMap(Map map) {
   Map newmap;

   newmap = newBlock(Map);
   enableIteration(newmap, newMapIterator);
   newmap->bst = cloneBST(map->bst);
   return newmap;
}
Exemple #8
0
Map newMap() {
   Map map;

   map = newBlock(Map);
   enableIteration(map, newMapIterator);
   map->bst = newBST(string);
   return map;
}
FifoFreeStoreWithoutTLS::FifoFreeStoreWithoutTLS ()
    : m_pages (GlobalPagedFreeStore::getInstance ())
{
    if (m_pages->getPageBytes () < sizeof (Block) + 256)
        Throw (Error ().fail (__FILE__, __LINE__, TRANS ("the block size is too small")));

    m_active = newBlock ();
}
Exemple #10
0
void* my_alloc(int size){
   int leftOver = size%sizeof(void*);
   size +=leftOver;
   Block* open_block = free_head;
   Block* previous_block = NULL;
   int req_size = size+overhead;
   while(open_block){
       if(size <= open_block->block_size){
	    //split and add head
		   printf("Head Block Size:%i\n",free_head->block_size);
	        if(req_size<=free_head->block_size){
		       //free_head->block_size = size;
		        free_head = (Block*)newBlock(free_head,req_size);
		        return &open_block->data;
        //split and not add head
	       }else if(req_size<=open_block->block_size){
		        previous_block->next_block =(Block*) newBlock(open_block,req_size);
		        open_block->next_block = NULL;
		        open_block->block_size = size;
		        return &open_block->data;

        //not split and add head
	       }else if(req_size>free_head->block_size){
                 free_head = free_head->next_block;
                 open_block->next_block = NULL;
                 return &open_block->data;
        //not split and add head
	       }else{
	       	   previous_block = open_block;
                return &previous_block->data;
	      }
	

       }else{
	   previous_block = open_block;
	   open_block = open_block->next_block;
}


}
return 0;

}
Exemple #11
0
void JitWriter::startBlock(const FrameState* frame) {
  newBlock(frame->abc_pc, frame);
  MethodSignaturep signature = method_->getMethodSignature();
  const Type** types = new (abc_->alloc0()) const Type*[signature->frame_size()];
  FrameRange<const FrameValue> from = range(&frame->value(0), frame, signature);
  FrameRange<const Type*> t = range(types, frame, signature);
  for (; !from.empty(); from.popFront(), t.popFront())
    t.front() = jit_mgr_->lattice()->makeType(from.front());
  current_block_->start_types = types;
}
Exemple #12
0
blockDescriptor* newColumnBlock() {
	blockDescriptor* block = newBlock(4, 1);
	for(int i = 0; i < 4; i++) {
		block->rotations[0][i][0] = '#';
		block->rotations[2][i][0] = '#';
		block->rotations[1][0][i] = '#';
		block->rotations[3][0][i] = '#';
	}
	return block;
}
Exemple #13
0
    void GLSLShader::splitBranches() {
        // Conversion to StatementPtr overload is ambiguous otherwise.
        StatementPtr main_stmt(main);

        StatementPtr ref;
        while (IfCodeNodePtr p = findBranch(main_stmt, ref)) {

            CodeNodePtr condition = p->getChildren()[0];
            CodeNodePtr truePart  = p->getChildren()[1];
            CodeNodePtr falsePart = p->getChildren()[2];

            string name = newRegisterName();

            CodeNodePtr nameReference(
                    new NameCodeNode(
                        name,
                        p->getType(),
                        p->getFrequency(),
                        NullValue,
                        ValueNode::BUILTIN)); // suitable substitute for local

            replace(main_stmt, p, nameReference);
            
            DeclarationPtr decl(new Declaration(p->getType(), name));

            AssignmentPtr assignTrue(new Assignment);
            assignTrue->define = false;
            assignTrue->lhs = name;
            assignTrue->rhs = truePart;

            AssignmentPtr assignFalse(new Assignment);
            assignFalse->define = false;
            assignFalse->lhs = name;
            assignFalse->rhs = falsePart;

            IfStatementPtr ifst(new IfStatement);
            ifst->condition = condition;
            ifst->setTrue(assignTrue);
            ifst->setFalse(assignFalse);

            BlockPtr newBlock(new Block);
            newBlock->statements.push_back(decl);
            newBlock->statements.push_back(ifst);
            newBlock->statements.push_back(ref);

            if (main_stmt == ref) {
                REN_DYNAMIC_CAST_PTR(main, Block, ref);
                assert(main);
                main_stmt = main;
            } else {
                replace(main_stmt, ref, newBlock);
            }
        }
    }
Exemple #14
0
blockDescriptor* newSquareBlock() {
	blockDescriptor* block = newBlock(2, 2);
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 2; j++) {
			for(int k = 0; k < 2; k++) {
				block->rotations[i][j][k] = '#';
			}
		}
	}
	return block;
}
Exemple #15
0
void MultiDataDistribution2D::addBlock(int x0, int x1, int y0, int y1, int envelopeWidth, int procId) {
    OLB_PRECONDITION( x0>=0 && y0>=0 );
    OLB_PRECONDITION( x1<nx && y1<ny );
    OLB_PRECONDITION( x0 <= x1 && y0 <= y1 );

    BlockParameters2D newBlock(x0, x1, y0, y1, envelopeWidth, procId,
                               x0==0, x1==nx-1, y0==0, y1==ny-1);
    computeNormalOverlaps(newBlock);
    blocks.push_back(newBlock);
    computePeriodicOverlaps();
}
Exemple #16
0
    void GLSLShader::share() {
        ReferenceMap rm;
        countReferences(main, rm);

//        std::cout << "++++\n";
//        output(std::cout);

        // Conversion to StatementPtr overload is ambiguous otherwise.
        StatementPtr main_stmt(main);
        while (CodeNodePtr p = findMultiplyReferenced(main_stmt, rm)) {
            ReferenceList rl = rm[p];
            ReferencePath prefix(getCommonPrefix(rl));
            assert(prefix[0] == main);

            string name = newRegisterName();

            CodeNodePtr nameReference(
                    new NameCodeNode(
                        name,
                        p->getType(),
                        p->getFrequency(),
                        NullValue,
                        ValueNode::BUILTIN)); // suitable substitute for local

            replace(main_stmt, p, nameReference);

            AssignmentPtr ns(new Assignment);
            ns->define = true;
            ns->lhs = name;
            ns->rhs = p;

            assert(!prefix.empty());
            StatementPtr lastInCommonPrefix(prefix[prefix.size() - 1]);

            // Make a new block.
            BlockPtr newBlock(new Block);
            newBlock->statements.push_back(ns);
            newBlock->statements.push_back(lastInCommonPrefix);

            if (main_stmt == lastInCommonPrefix) {
                main = newBlock;
                main_stmt = main;
            } else {
                replace(main_stmt, lastInCommonPrefix, newBlock);
            }

            rm.clear();
            countReferences(main, rm);

//            std::cout << "++++\n";
//            output(std::cout);
        }
    }
Exemple #17
0
Iterator newListIterator(int size, CompareFn cmpFn) {
   Iterator iterator;

   iterator = newBlock(Iterator);
   enableIteration(iterator, 0);
   iterator->elementSize = size;
   iterator->stepFn = stepListIterator;
   iterator->cmpFn = cmpFn;
   iterator->head = iterator->tail = NULL;
   iterator->data = NULL;
   return iterator;
}
Exemple #18
0
Iterator newStepIterator(int size, StepIteratorFn stepFn) {
   Iterator iterator;

   iterator = newBlock(Iterator);
   enableIteration(iterator, 0);
   iterator->elementSize = size;
   iterator->stepFn = stepFn;
   iterator->cmpFn = NULL;
   iterator->head = iterator->tail = NULL;
   iterator->data = NULL;
   return iterator;
}
Exemple #19
0
/* mkGrid:
 * Create grid data structure.
 * cellHint provides rough idea of how many cells
 * may be needed.
 */
Grid *mkGrid(int cellHint)
{
    Grid *g;

    g = GNEW(Grid);
    _grid = g;			/* see comment above */
    g->data = dtopen(&gridDisc, Dtoset);
    g->listMem = 0;
    g->listSize = 0;
    g->cellMem = newBlock(cellHint);
    return g;
}
Exemple #20
0
  /** This method is called by this->relocate when object that has shrunk
   * and so has left a bit of free space after itself on the file;
   * or when an object gets moved to a new spot.
   *
   * @param pos :: position in the file of the START of the new free block
   * @param size :: size of the free block
   */
  void DiskBuffer::freeBlock(uint64_t const pos, uint64_t const size)
  {
    if (size == 0) return;
    m_freeMutex.lock();

    // Make the block
    FreeBlock newBlock(pos, size);
    // Insert it
    std::pair<freeSpace_t::iterator,bool> p = m_free.insert( newBlock );

    // Failed insert? Should not happen since the map is NOT unique
    // Or, if the map has only 1 item then it cannot do any merging. This solves a hanging bug in MacOS. Refs #3652
    if (!p.second || m_free.size() <= 1)
    {
      m_freeMutex.unlock();
      return;
    }

    // This is where we inserted
    freeSpace_t::iterator it = p.first;
    if (it != m_free.begin())
    {
      freeSpace_t::iterator it_before = it; --it_before;
      // There is a block before
      FreeBlock block_before = *it_before;
      if (FreeBlock::merge(block_before, newBlock))
      {
        // Change the map by replacing the old "before" block with the new merged one
        m_free.replace(it_before, block_before);
        // Remove the block we just inserted
        m_free.erase(it);
        // For cases where the new block was between two blocks.
        newBlock = block_before;
        it = it_before;
      }
    }
    // Get an iterator to the block AFTER this one
    freeSpace_t::iterator it_after = it; ++it_after;
    // There is a block after
    if (it_after != m_free.end())
    {
      FreeBlock block_after = *it_after;
      if (FreeBlock::merge(newBlock, block_after))
      {
        // Change the map by replacing the old "new" block with the new merged one
        m_free.replace(it, newBlock);
        // Remove the block that was after this one
        m_free.erase(it_after);
      }
    }

    m_freeMutex.unlock();
  }
Exemple #21
0
    void EtherIPC::handleGetBlock() {
        QJsonValue jv;
        if ( !readReply(jv) ) {
            return bail();
        }

        const QJsonObject block = jv.toObject();
        const quint64 num = Helpers::toQUInt64(block.value("number"));
        emit getBlockNumberDone(num);
        emit newBlock(block);
        done();
    }
Exemple #22
0
bool * Blocks::blockCopy(bool block[]) {
	int i = 0, j = 0;

	bool * blockCopy;
	///////////////////////

	blockCopy = newBlock();
	for (i = 0; i < size; i++) {
		for (j = 0; j + i < size; j++) {
			blockCopy[convert(i, j)] = block[convert(i, j)];
		}
	}
	return blockCopy;
}
Exemple #23
0
static autoBlock_t *GetSabun(autoBlock_t *fileImage1, autoBlock_t *fileImage2)
{
	autoBlock_t *sabun = newBlock();
	uint index;

	for(index = 0; index < getSize(fileImage2); index++)
	{
		int chr1 = refByte(fileImage1, index);
		int chr2 = getByte(fileImage2, index);

		addByte(sabun, chr1 ^ chr2);
	}
	return sabun;
}
Exemple #24
0
void *lmAlloc(struct lm *lm, size_t size)
/* Allocate memory from local pool. */
{
struct lmBlock *mb = lm->blocks;
void *ret;
size_t memLeft = mb->end - mb->free;
if (memLeft < size)
    mb = newBlock(lm, size);
ret = mb->free;
mb->free += ((size+lm->allignAdd)&lm->allignMask);
if (mb->free > mb->end)
    mb->free = mb->end;
return ret;
}
  void run(StatementPtr s) {
    m_state = AstWalkerStateVec(s);
    m_pass = 1;
    m_cur = 0;
    newBlock();
    m_head = m_cur;
    AstWalker::walk(*this, this->m_state, ConstructRawPtr(), ConstructRawPtr());
    for (LabelInfoMap::iterator it = m_labelInfoMap.begin(),
           end = m_labelInfoMap.end(); it != end; ++it) {
      LabelInfo &li = it->second;
      if (li.first && li.second.size()) {
        for (GotoStatementPtrVec::iterator ii = li.second.begin(),
               ee = li.second.end(); ii != ee; ++ii) {
          addEdge(*ii, AfterConstruct, li.first, BeforeConstruct);
        }
      }
    }
    newBlock();

    m_state = AstWalkerStateVec(s);
    m_pass = 2;
    m_cur = m_head;
    AstWalker::walk(*this, this->m_state, ConstructRawPtr(), ConstructRawPtr());
  }
Exemple #26
0
/* getCell:
 * Create a new cell using memory blocks.
 */
static cell *getCell(Grid * g)
{
    cell *cp;
    block_t *bp = g->cellCur;	/* current block */

    if (bp->cur == bp->endp) {	/* current block is full */
	if (bp->next == 0) {
	    bp->next = newBlock(2 * (bp->endp - bp->mem));
	}
	bp = g->cellCur = bp->next;
	bp->cur = bp->mem;
    }
    cp = bp->cur++;
    return cp;
}
Exemple #27
0
static GObject newGObject(int type) {
   GObject gobj;

   gobj = newBlock(GObject);
   gobj->type = type;
   gobj->x = 0;
   gobj->y = 0;
   gobj->width = 0;
   gobj->height = 0;
   gobj->color = "BLACK";
   gobj->fillColor = NULL;
   gobj->filled = false;
   gobj->visible = true;
   gobj->parent = NULL;
   return gobj;
}
Exemple #28
0
/* add a thunk block to get us out of an infinite loop */
static void makeNonInfinite(BLOCK *b)
{
    BLOCKLIST *bi = newBlock(), *bi2, **bt;
    QUAD *quad, *quad2;

    blockArray[bi->block->blocknum] = bi->block;
    bi->block->unuseThunk = TRUE;

    bi->block->succ = oAlloc(sizeof(BLOCKLIST));
    bi->block->succ->block = blockArray[exitBlock];
    
    bi->block->pred = oAlloc(sizeof(BLOCKLIST));
    bi->block->pred->block = b;
    
    bt = &b->succ;
    while (*bt)
        bt = &(*bt)->next;
    *bt = bi;

    bi2 = oAlloc(sizeof(BLOCKLIST));
    bi2->block = bi->block;
    
    bt = &blockArray[exitBlock]->pred;
    while (*bt)
        bt = &(*bt)->next;
    *bt = bi2;

    /* note : the following does NOT insert jmps for the
     * newly added block
     */
    *criticalThunkPtr = quad = Alloc(sizeof(QUAD));
    criticalThunkPtr = & quad->fwd;
    quad->dc.opcode = i_block;
    quad->block = bi->block;
    quad->dc.v.label = bi->block->blocknum;

    *criticalThunkPtr = quad2 = Alloc(sizeof(QUAD));
    criticalThunkPtr = & quad2->fwd;
    quad2->back = quad;
    quad2->dc.opcode = i_blockend;
    quad2->block = bi->block;
//	quad2->dc.v.label = bi->block->blocknum;
                        
    bi->block->head = quad;
    bi->block->tail = quad2;
    
}
/** Sets the free space map. Should only be used when loading a file.
 * @param[in] free :: vector containing free space index to set */
void DiskBuffer::setFreeSpaceVector(std::vector<uint64_t> &free) {
  m_free.clear();

  if (free.size() % 2 != 0)
    throw std::length_error("Free vector size is not a factor of 2.");

  for (auto it = free.begin(); it != free.end(); it += 2) {
    auto it_next = boost::next(it);

    if (*it == 0 && *it_next == 0) {
      continue; // Not really a free space block!
    }

    FreeBlock newBlock(*it, *it_next);
    m_free.insert(newBlock);
  }
}
Exemple #30
0
void JitWriter::writeOp1(const FrameState* frame, const uint8_t *pc,
                         AbcOpcode abcop, uint32_t opd1, Traits*) {
  analyze(abcop, pc, frame);
  if (needSavedScopes(pc, abcop))
    abc_->abc_instrs.put(pc, new (abc_->alloc_) AbcInstr(abcop, opd1));
  if (isBranchOpcode(abcop)) {
    const uint8_t* nextpc = pc + 4;
    int offset = int32_t(opd1);
    if (abcop == OP_jump) {
      abc_->analyzeEnd(current_block_, nextpc + offset);
      finishBlock(nextpc);
    } else {
      abc_->analyzeBranch(current_block_, abcop, nextpc, offset);
      finishBlock(nextpc);
      newBlock(nextpc, frame);
    }
  }
}