Exemple #1
0
void LazyFunction::apply(Expr& target, ListNode* args, Environment* rho)
{
    // number of args should match definition
    ListNode* anames = argNames_;
    if (anames->length() != args->length())
    {
        error("argument length mismatch");
        return;
    }

    // convert arguments into thunks
    ListNode* newargs = makeThunks(args, rho);

    // make new environment
    Environment* newrho = new Environment(anames, newargs, context_);

    // evaluate body in new environment
    if (body_())
    {
        body_()->eval(target, valueOps, newrho);
    }
    else
    {
        target = 0;
    }

    newrho = 0;
}
Exemple #2
0
int main(int argc, const char * argv[]) {
//    ListNode *n = new ListNode(1);
//    n->addNode(2)->addNode(3)->addNode(4)->addNode(5);
//    
//    Solution a;
//    a.reverseBetween(n, 2, 4);
    
    
//    ListNode *n = new ListNode(5);
//    
//    Solution a;
//    a.reverseBetween(n, 1, 1);
    
    
//    ListNode *n = new ListNode(3);
//    n->addNode(5);
//    
//    Solution a;
//    a.reverseBetween(n, 1, 2);
 
    
    ListNode *n = new ListNode(1);
    n->addNode(2)->addNode(3);
    
    Solution a;
    a.reverseBetween(n, 1, 2);
    
    
    return 0;
}
ParseNode *
ParseNode::append(ParseNodeKind kind, JSOp op, ParseNode *left, ParseNode *right,
                  FullParseHandler *handler)
{
    if (!left || !right)
        return nullptr;

    MOZ_ASSERT(left->isKind(kind) && left->isOp(op) && (js_CodeSpec[op].format & JOF_LEFTASSOC));

    ListNode *list;
    if (left->pn_arity == PN_LIST) {
        list = &left->as<ListNode>();
    } else {
        ParseNode *pn1 = left->pn_left, *pn2 = left->pn_right;
        list = handler->new_<ListNode>(kind, op, pn1);
        if (!list)
            return nullptr;
        list->append(pn2);
    }

    list->append(right);
    list->pn_pos.end = right->pn_pos.end;

    return list;
}
Exemple #4
0
bool List::member(ICollectible *c) const{
    for(ListNode *current = head; current != NULL; current = current->getNext())
        if(current->getElem() == c)
            return true;
    return false;
        
}
Exemple #5
0
ParseNode*
ParseNode::appendOrCreateList(ParseNodeKind kind, JSOp op, ParseNode* left, ParseNode* right,
                              FullParseHandler* handler, ParseContext<FullParseHandler>* pc)
{
    // The asm.js specification is written in ECMAScript grammar terms that
    // specify *only* a binary tree.  It's a royal pain to implement the asm.js
    // spec to act upon n-ary lists as created below.  So for asm.js, form a
    // binary tree of lists exactly as ECMAScript would by skipping the
    // following optimization.
    if (!pc->useAsmOrInsideUseAsm()) {
        // Left-associative trees of a given operator (e.g. |a + b + c|) are
        // binary trees in the spec: (+ (+ a b) c) in Lisp terms.  Recursively
        // processing such a tree, exactly implemented that way, would blow the
        // the stack.  We use a list node that uses O(1) stack to represent
        // such operations: (+ a b c).
        if (left->isKind(kind) && left->isOp(op) && (js_CodeSpec[op].format & JOF_LEFTASSOC)) {
            ListNode* list = &left->as<ListNode>();

            list->append(right);
            list->pn_pos.end = right->pn_pos.end;

            return list;
        }
    }

    ParseNode* list = handler->new_<ListNode>(kind, op, left);
    if (!list)
        return nullptr;

    list->append(right);
    return list;
}
Exemple #6
0
//
// SquadObj::LoadState
//
// Load a state configuration scope
//
void SquadObj::LoadState(FScope *fScope)
{
  // Call parent scope first
  GameObj::LoadState(fScope);

  // Get specific config scope
  fScope = fScope->GetFunction(SCOPE_CONFIG);
  FScope *sScope;

  while ((sScope = fScope->NextFunction()) != NULL)
  {
    switch (sScope->NameCrc())
    {
      case 0xEDF0E1CF: // "Team"
        SetTeam(Team::Name2Team(StdLoad::TypeString(sScope)));
        break;

      case 0x2F382D90: // "ModifierSettings"
        settings.LoadState(sScope);
        break;

      case 0xE3554C44: // "Node"
      {
        ListNode *node = list.Append();
        StdLoad::TypeReaper(sScope, *node);
        node->LoadState(sScope);
        break;
      }
    }
  }
}
  vector< Point2d > PointPersistentList::enumerateNE(coord_t x, coord_t y) {
    vector< Point2d > v;
    // determine the time at which to search by searching for the x
    int index = binarySearchX(x);
    // if set of points is empty, bail out
    if(index == -1) return v;
    // while the closest point is too small
    while(points_sorted_by_x[index].x < x) {
      // check the previous point, which should be larger since the
      // array is sorted by x descending
      --index;
      // if we have passed the beginning of the array, then there are no
      // points within the query region
      if(index < 0)
	return v;
    }
    // get the first node in this list at time index
    ListNode<Point2d, Point2d::yxdesc >* pln = points_right.getList(index);
    // while the current point is not null and has a greater or equal
    // y than the query
    while(pln != NULL && pln->data.y >= y) {
      // push the point onto the list to be returned
      v.push_back(pln->data);
      // move on to next point
      pln = pln->getNext(index);
    }
    return v;
  }
Exemple #8
0
bool LinkedList::removeFromBack(string &output)
{
    if (!isEmpty())
    {

        ListNode* currNode = head;
        ListNode* prevNode;


        // move to second last node
        while (currNode->getNext() != NULL)
        {
            prevNode = currNode;
            currNode = currNode->getNext();
        }
            

        output = currNode->value;
        delete currNode;
        prevNode->next = NULL;
        last = prevNode;
    }
    else
    {
        return false;
    }
        
}
Exemple #9
0
void PtrListRep::remove(void* element)
{
    if(element!=NULL && _first!=NULL)
    {
        for(ListNode* n=_first; n!=NULL; n=n->getNext())
        {
            void* el = n->getElement();
            if(el==element)
            { // remove the node
                ListNode* prev = n->getPrevious();
                ListNode* next = n->getNext();

                if(prev!=NULL)
                    prev->setNext(next);
                else // the node is the very first
                    _first = next;

                if(next!=NULL)
                    next->setPrevious(prev);
                else // the node is the last
                    _last = prev;

                delete n;
                break;
            }
        }
    }
}
Exemple #10
0
void DoNetList(FILE *pFout, BomKeyNode *pBkn, ListNode *pNetList){
  KeyValNode *kvn;
  MapNode *mn;
  ListNode *ln;
  int c,d;
  const char *net_in;
  char net_out[32];
  for(c = 0; c < pNetList->count(); c++){
    mn = pNetList->getNode(c);
    if(mn->nodeType() == 2){
      kvn = (KeyValNode*)mn;
      mn = kvn->value();
      if(mn->nodeType() == 3 && mn != pNetList){
	net_in = kvn->key();
	if(net_in[0] != '*'){
	  strcpy(net_out, net_in);
	}else{
	  sprintf(net_out, "unnamed_%s", &(net_in[1]));
	}
	fprintf(pFout, "%s\t", net_out);
	
	ln = (ListNode *) mn;
	for(d = 0; d < ln->count(); d++){
	  fprintf(pFout, "%s",pBkn->printRef(ln->getNode(d)));
	}
	fprintf(pFout, "\n");
      }
    }
  }  
}
Exemple #11
0
// Print the list.
void ListNode::Print () {
	ListNode* list = this;
	for (; list; list = list->Rest()) {
		cout << list->First() << " ";
	}
	cout << endl;
}
void LinkedList::Remove(void* item)
{
	if (frontNode)
	{
		ListNode* currNode = frontNode;
		do
		{
			if (currNode->GetItem() == item)
			{
				break;
			}
			currNode = currNode->GetNext();
		} while (currNode);
		if (currNode)
		{
			delete currNode;
			numItems--;
			if (numItems == 0)
			{
				frontNode = NULL;
				backNode = NULL;
			}
		}
	}
}
Exemple #13
0
    /*!
     * Create middlephase jobs according to the \ref BroadPhaseJob.
     *
     * See also \ref MiddlePhaseJobCreator and \ref
     * DetectorDeformManager::pickAlgorithmFor
     */
    void Pipeline::createMiddlePhaseJobs(BroadPhaseJob* broadPhaseJob) {
        List<CollisionPair*>& jobResults = broadPhaseJob->getJobResultsReference();
        for (ListNode<CollisionPair*>* node = jobResults.getFirstNode(); node; node = node->getNext()) {
            CollisionPair* pair = node->getData();

            // TODO make CollisionPair store Proxy pointers.
            //      we usually dont care about the BVs when reading the pairs!!
            Proxy* p1 = pair->bvol1->getHierarchyNode()->getProxy();
            Proxy* p2 = pair->bvol2->getHierarchyNode()->getProxy();

            if (p1->getProxyType() & PROXYTYPE_DEFORMABLE ||
                    p2->getProxyType() & PROXYTYPE_DEFORMABLE) {

                if (mWorld->getUseCollisionCaching()) {
                    bool cacheApplied = mWorld->getCollisionCache()->applyCacheIfAvailable(p1, p2);
                    if (cacheApplied) {
                        continue;
                    }
                }

                DetectorDeformAlgorithm* algorithm = mDetectorDeformManager->pickAlgorithmFor(p1, p2);
                if (algorithm) {
                    // TODO: fix API.
                    //       createCollisionJobFor() uses CollisionPair,
                    //       pickAlgorithmFor() uses two Proxy pointers.
                    //       choose one!
                    algorithm->createCollisionJobFor(*pair);
                }
            }
        }


        mMiddlePhaseJobCreator->createJobs(broadPhaseJob);
    }
Exemple #14
0
void KdTree::add( KdTreeNode* kdnode, Object* ob )
{
	//std::cout<<_buffer_l<<std::endl;
	ListNode* node = &_ListNodeBuffer[_buffer_l++];
	node->setObject( ob );
	node->setNext( kdnode->getList() );
	kdnode->setList( node );
}
void List<NODETYPE>::concatenate(List<NODETYPE> &listSecond) {
    ListNode<NODETYPE> *currentPtr = listSecond.firstPtr;

    while (currentPtr != 0) {
        insertAtBack(currentPtr->getData());
        currentPtr = currentPtr->nextPtr;
    }
}
Exemple #16
0
void List::copy(List L){
		Head = NULL;
		ListNode * temp = L.Head;
		while(temp!=NULL){
			this->append(temp->getData());
			temp=temp->getNext();
		}
}
Exemple #17
0
// Add to the end of the list
ListNode * LinkedList::append(const int val)
{
  ListNode *node = &head;

  while (node->hasNext()) {
    node = node->getNext();
  }
  return node->setNext(new ListNode(val));
}
Exemple #18
0
    template <class Type> Type List<Type>::GetAt(LISTNODE pNode)
    {
        ListNode<Type>                *pListNode = (ListNode<Type> *)pNode;

        // Faults if you pass NULL
        _ASSERTE(pNode);

        return pListNode->GetItem();
    }
Exemple #19
0
List::~List() {
    ListNode *current = head;
    ListNode *next;
    while (current != NULL) {
        next = current->getNext();
        delete current;
        current = next;
    }
}
Exemple #20
0
// draw nodes which are fully attached to the list
void List::draw_connected(const Cairo::RefPtr<Cairo::Context> & cr) {
		ListNode * n = head;
	while (n != NULL) {
		n->draw(cr);
		n->printed = true;
		draw_arrows(cr, n);
		n = n->next;
	}
}
Exemple #21
0
void PointerFIFO::put(void* val)
{
	ListNode *node = allocate();
	node->data(val);
	node->next(NULL);
	if (mTail!=NULL) mTail->next(node);
	mTail=node;
	if (mHead==NULL) mHead=node;
	mSize++;
}
Exemple #22
0
// Show the contents of the list
void LinkedList::print(void)
{
  ListNode *node = head.getNext();

  while (node != 0) {
    cout << setw(6) << node->getVal();
    node = node->getNext();
  }
  cout << endl;
}
Exemple #23
0
void* PtrListIterator::next()
{
    if(_lead==NULL)
        throw IndexOutOfBoundsException();

    void* element = _lead->getElement();
    _lead = _lead->getNext();

    return element;
}
Exemple #24
0
Object* List::getNext()
{
	if(actual != NULL ) {
		ListNode* temp = actual;
		actual = actual->getNext();
		return temp->getObject();
	}
	else
		return NULL;
}
Exemple #25
0
ListIterator<Object> List<Object>::findPrevious( const Object& data ) const {
	ListNode<Object>* node = head;
	while( node->getNext() != NULL && node->getNext()->getElement() != data ) {
		node = node->getNext();
	}
	if (node->getNext() == NULL) {
		node = NULL;
	}
	return ListIterator<Object>( node );
}
Exemple #26
0
ListNode* LinkedList::findSpot(int input){
   if(isEmpty()){
      return listHead;
   }
   ListNode* temp = listHead;
   while(temp->getNext() != NULL && temp->getNext()->getData() < input){
      temp = temp->getNext();
   }
   return temp;
}
Exemple #27
0
int isTrue(Expression* cond)
{
    // the only thing false is nil
    ListNode* nval = cond->isList();
    if (nval && nval->isNil())
    {
        return 0;
    }
    return 1;
}
Exemple #28
0
int main(int argc, const char * argv[])
{
    ListNode h (2);
    h.addNode(3)->addNode(4)->addNode(5)->addNode(7)->addNode(9);
    
    ListNode *nh = removeIf( &h , remove_fn_e );
    
    printList(nh);
    
    return 0;
}
Exemple #29
0
void PointerFIFO::push_front(void* val)	// by pat
{
	// Pat added this routine for completeness, but never used or tested.
	// The first person to use this routine should remove this assert.
	ListNode *node = allocate();
	node->data(val);
	node->next(mHead);
	mHead = node;
	if (!mTail) mTail=node;
	mSize++;
}
Exemple #30
0
void List<Object>::remove( const Object& data ) {
	ListIterator<Object> iter = findPrevious( data );
	if (iter.isValid()) {
		ListNode<Object>* node = findPrevious( data ).current;
		if (node->getNext() != NULL) {
			ListNode<Object> *oldNode = node->getNext();
			node->setNext( node->getNext()->getNext() );  // Skip oldNode
			delete oldNode;
		}
	}
}