char* in2post(char* equation){
	char* copy = strdup(equation);										//Initialize a copy of the original equation
	char** equationArray = (char**)malloc(256*sizeof(char*));	//Initialize an array of strings to hold 256 strings
	char* p = strtok(copy," ");											//Tokenizer to delimit a space
	int i = 0;																	//Iterator
	int arraySize = 0;														//Keep track of the size of the array of strings
	char* postfix = (char*)malloc(128*sizeof(char));				//Initialize a variable to hold the postfix expression with suitable size

	//Creates an array containing the delimited
	while(p != NULL) {
		equationArray[i++] = p;
		p = strtok(NULL, " ");
		arraySize++;
	}

	char* stack[arraySize];				//Creates a stack with enough size to hold all the postfix operator/operands

	//Iterate through each operand and operator for infix to postfix conversion
	for( i = 0; i < arraySize; i++){
		//Determine if the element is an operator
		if(strcmp(equationArray[i], "+") == 0 || strcmp(equationArray[i],"-") == 0 || strcmp(equationArray[i], "*") == 0 || strcmp(equationArray[i], "/") == 0
			  	|| strcmp(equationArray[i], "(") == 0 || strcmp(equationArray[i], ")") == 0) {
			//Push to stack if there are no elements in the stack
			if(topIndex == -1) {
				push(equationArray[i], stack);
			}
			//If it's plus or minus, it will concatenate the last element of
			//the stack as long as the priority is the same of higher.
			else if(strcmp(equationArray[i], "(") == 0) {
				push(equationArray[i], stack);
			}	
			else if(strcmp(equationArray[i], ")") == 0) {
				while(strcmp(top(stack), "(") != 0) {
					strcat(postfix, pop(stack));
					strcat(postfix, " ");
				}
				pop(stack);
			}
			else if(strcmp(equationArray[i], "+") == 0 || strcmp(equationArray[i], "-") == 0){
				while(strcmp(top(stack), "+") == 0 || strcmp(top(stack), "-") ==0 || strcmp(top(stack), "*") == 0 || strcmp(top(stack),"/") == 0 ) {
					strcat(postfix, pop(stack));
					strcat(postfix, " ");
				}
				//Pushes most recent operator to stack
				push(equationArray[i], stack);
			}
			//If it's a multiplication or division symbol, it keeps
			//concatenating the top stack elements as longa s it has the same
			//precendence.
			else if(strcmp(equationArray[i], "*") == 0 || strcmp(equationArray[i], "/") == 0) {
				while(strcmp(top(stack), "*") == 0 || strcmp(top(stack), "/") == 0 ) { 
					strcat(postfix, pop(stack));
					strcat(postfix, " ");
				}
				//Pushes most recent operator to stack
				push(equationArray[i], stack);
			}
		}
		//Concatenate to the postfix expression if element is an operand
		else {
			strcat(postfix, equationArray[i]);
			strcat(postfix, " ");
		}
	}
	//Concatenates all the remaining elements in the stack to the final
	//postfix expression
	while(topIndex != -1) {
		strcat(postfix, pop(stack));
		strcat(postfix, " ");
	}

	//Free memory used to hold copy
	free(copy);
	
	//Return the final postfix expression
	return postfix;
}
Example #2
0
void MotionMaster::UpdateFinalDistanceToTarget(float fDistance)
{
    if (!empty())
        top()->UpdateFinalDistance(fDistance);
}
Example #3
0
 size_t free() const                            { return pointer_delta(end(), top()); }
Example #4
0
const QRect XfitMan::availableGeometry(int screen) const
{
    QDesktopWidget *d = QApplication::desktop();

    if (screen < 0 || screen >= d->screenCount())
        screen = d->primaryScreen();

    QRect available = d->screenGeometry(screen);

    // Iterate over all the client windows and subtract from the available
    // area the space they reserved on the edges (struts).
    // Note: _NET_WORKAREA is not reliable as it exposes only one
    // rectangular area spanning all screens.
    Display *display = QX11Info::display();
    int x11Screen = d->isVirtualDesktop() ? DefaultScreen(display) : screen;

    Atom ret;
    int format, status;
    uchar* data = 0;
    ulong nitems, after;

    status = XGetWindowProperty(display, QX11Info::appRootWindow(x11Screen),
                                atom("_NET_CLIENT_LIST"), 0L, ~0L, False, XA_WINDOW,
                                &ret, &format, &nitems, &after, &data);

    if (status == Success && ret == XA_WINDOW && format == 32 && nitems)
    {
        const QRect desktopGeometry = d->rect();

        Window* xids = (Window*) data;
        for (quint32 i = 0; i < nitems; ++i)
        {
            ulong nitems2;
            uchar* data2 = 0;
            status = XGetWindowProperty(display, xids[i],
                                        atom("_NET_WM_STRUT_PARTIAL"), 0, 12, False, XA_CARDINAL,
                                        &ret, &format, &nitems2, &after, &data2);

            if (status == Success && ret == XA_CARDINAL && format == 32 && nitems2 == 12)
            {
                ulong* struts = (ulong*) data2;

                QRect left(desktopGeometry.x(),
                           desktopGeometry.y() + struts[4],
                           struts[0],
                           struts[5] - struts[4]);
                if (available.intersects(left))
                    available.setX(left.width());

                QRect right(desktopGeometry.x() + desktopGeometry.width() - struts[1],
                            desktopGeometry.y() + struts[6],
                            struts[1],
                            struts[7] - struts[6]);
                if (available.intersects(right))
                    available.setWidth(right.x() - available.x());

                QRect top(desktopGeometry.x() + struts[8],
                          desktopGeometry.y(),
                          struts[9] - struts[8],
                          struts[2]);
                if (available.intersects(top))
                    available.setY(top.height());

                QRect bottom(desktopGeometry.x() + struts[10],
                             desktopGeometry.y() + desktopGeometry.height() - struts[3],
                             struts[11] - struts[10],
                             struts[3]);
                if (available.intersects(bottom))
                    available.setHeight(bottom.y() - available.y());
            }
            if (data2)
                XFree(data2);
        }
    }
    if (data)
        XFree(data);

    return available;
}
Example #5
0
int
main (int argc, char **argv)
{
  return top (-1) + top (1);
}
Example #6
0
void pop()
{
    tableauDynamiqueAjouter(listeFonctionsDefinies, top());
    pileEject(pileBloque);
}
Example #7
0
void schedule()
{
//cs printf("activated\n");
 if(Current_Thread==NULL) // Main Thread was executing previously..
 {
  TERMINATED=0;
  if(!isempty(&ready_queue))       // If there are more threads...
  {
   Current_Thread=top(&ready_queue);
//c   printf("yes!! %p\n", Current_Thread);
   Global_id=Current_Thread->thread_id;

   swapcontext(&Main, &(Current_Thread->threads_context));
  }
  else                // If all threads are dead...
  {
//c   printf("main is getting set!\n");
   setcontext(&Main);
  }
 }
 else     //if someother thread was executing...
 {
  struct Task* tmp=next(&ready_queue, Current_Thread);
//c  printf("other way around and %p and current:%p\n", tmp, Current_Thread);
  if(tmp==NULL)  //if this was the last thread in the queue....
  {     //execute main fn.
//c   printf("it was null\n");
   if(TERMINATED==1)
   {
//c    printf("its gone!!\n");
    TERMINATED=0;
    remov(&ready_queue, Global_id);
    Current_Thread=NULL;
    setcontext(&Main);
   }
   else
   {
    struct Task* tmp1=Current_Thread;
    Current_Thread=NULL;
    swapcontext(&(tmp1->threads_context), &Main); 
   }
   
  }
  else
  {
   struct Task* tmp2=Current_Thread;
   Current_Thread=tmp;
   if(TERMINATED==1)
   {
    TERMINATED=0;
    remov(&ready_queue, Global_id);
    Global_id=tmp->thread_id;
//c    printf("context set for %p\n", tmp);

    setcontext(&(tmp->threads_context));
   }
   else
   {
    Global_id=tmp->thread_id;
//c    printf("running:%p\n", tmp);
    swapcontext(&(tmp2->threads_context), &(tmp->threads_context)); 
   }
   
  }
 }
}
Example #8
0
// reduce size so that top() != NULL
void MotionMaster::removeEmptyTops() {
	while (!top() && size() > 1) // we don't want to remove last element
	{
		--i_top;
	}
}
Example #9
0
void Nonbreakable::draw(bool update)
{

	if (type_ != REGULAR){
        glColor3ub(255,204,0);
        glBegin(GL_POLYGON);
        glVertex2d(left(),bottom());
        glVertex2d(right(),bottom());
        glVertex2d(right(),top());
        glVertex2d(left(),top());
        glEnd();
	
        if (type_ == QUESTION) {
        
            glColor3ub(255, 0, 0);
            
            glBegin(GL_POLYGON);
            glVertex2d(left()+6, bottom()+6);
            glVertex2d(left()+10, bottom()+6);
            glVertex2d(left()+10, bottom()+14);
            glVertex2d(left()+6, bottom()+14);
            glEnd();
        
            glBegin(GL_POLYGON);
            glVertex2d(left()+6, bottom()+2);
            glVertex2d(left()+10, bottom()+2);
            glVertex2d(left()+10, bottom()+4);
            glVertex2d(left()+6, bottom()+4);
            glEnd();
        
        }
    
    
        glColor3ub(0, 0, 0);
        glPointSize(2.0);
    
        glBegin(GL_POINTS);
        glVertex2d(left()+2, bottom()+2);
        glVertex2d(left()+2, top()-2);
        glVertex2d(right()-2, bottom()+2);
        glVertex2d(right()-2, top()-2);
        glEnd();
    
        glColor3ub(0, 0, 0);
        glBegin(GL_LINE_LOOP);
        glVertex2d(left(), bottom());
        glVertex2d(left(), top());
        glVertex2d(right(), top());
        glVertex2d(right(), bottom());
        glEnd();
    }
    else{
        
        glColor3ub(0, 0, 0);
        glBegin(GL_POLYGON);
        glVertex2d(left(), bottom());
        glVertex2d(right(), bottom());
        glVertex2d(right(), top());
        glEnd();
        
        glColor3ub(199, 133, 120);    
        glBegin(GL_POLYGON);
        glVertex2d(right(), top());
        glVertex2d(left(), top());
        glVertex2d(left(), bottom());
        glEnd();

        glColor3b(0, 0, 0);
        glBegin(GL_LINES);
        glVertex2d(left(), bottom());
        glVertex2d(right(), top());
        glEnd();
        
        glColor3ub(199, 133, 64);
        glBegin(GL_LINES);
        glVertex2d(left(), bottom());
        glVertex2d(right(), top());
        glEnd();
        
        glBegin(GL_POLYGON);
        glVertex2d(left()+4, bottom()+4);
        glVertex2d(left()+4, top()-4);
        glVertex2d(right()-4, top()-4);
        glVertex2d(right()-4, bottom()+4);
        glEnd();
        
        
    }
         
    
  
}
Example #10
0
MovementGeneratorType MotionMaster::GetCurrentMovementGeneratorType() const {
	if (empty())
		return IDLE_MOTION_TYPE;

	return top()->GetMovementGeneratorType();
}
Example #11
0
bool MotionMaster::GetDestination(float &x, float &y, float &z) {
	if (empty())
		return false;

	return top()->GetDestination(x, y, z);
}
bool KoTextLayoutTableArea::layoutTable(TableIterator *cursor)
{
    d->startOfArea = new TableIterator(cursor);
    d->headerRows = cursor->headerRows;
    d->totalMisFit = false;

    // If table is done we create an empty area and return true
    if (cursor->row == d->table->rows()) {
        setBottom(top());
        d->endOfArea = new TableIterator(cursor);
        return true;
    }
    layoutColumns();

    bool first = cursor->row == 0 && (d->cellAreas[0][0] == 0);
    if (first) { // are we at the beginning of the table
        cursor->row = 0;
        d->rowPositions[0] = top() + d->table->format().topMargin();
        d->headerOffsetX = 0;
        d->headerOffsetY = 0;
    } else {
        for (int row = 0; row < d->headerRows; ++row) {
            // Copy header rows
            d->headerRowPositions[row] = cursor->headerRowPositions[row];
            for (int col = 0; col < d->table->columns(); ++col) {
                d->cellAreas[row][col] = cursor->headerCellAreas[row][col];
            }
        }

        if (d->headerRows) {
            // Also set the position of the border below headers
            d->headerRowPositions[d->headerRows] = cursor->headerRowPositions[d->headerRows];
        }

        // If headerRows == 0 then the following reduces to: d->rowPositions[cursor->row] = top()
        d->headerOffsetY = top() - d->headerRowPositions[0];
        d->rowPositions[cursor->row] = d->headerRowPositions[d->headerRows] + d->headerOffsetY;

        // headerOffsetX should also be set
        d->headerOffsetX = d->columnPositions[0] - cursor->headerPositionX;
    }

    bool complete = first;
    qreal topBorderWidth = 0;
    qreal bottomBorderWidth = 0;
    qreal dummyWidth = 0;

    collectBorderThicknesss(cursor->row - 1, dummyWidth, topBorderWidth);
    collectBorderThicknesss(cursor->row, topBorderWidth, bottomBorderWidth);
    do {
        qreal nextBottomBorderWidth = 0;
        collectBorderThicknesss(cursor->row+1, bottomBorderWidth, nextBottomBorderWidth);

        d->lastRowHasSomething = false;

        complete = layoutRow(cursor, topBorderWidth, bottomBorderWidth);

        setBottom(d->rowPositions[cursor->row + 1] + bottomBorderWidth);
        topBorderWidth = bottomBorderWidth;
        bottomBorderWidth = nextBottomBorderWidth;


        if (complete) {
            setVirginPage(false);
            cursor->row++;
        }
    } while (complete && cursor->row < d->table->rows());

    if (cursor->row == d->table->rows()) {
        d->lastRowHasSomething = false;
    }


    if (first) { // were we at the beginning of the table
        for (int row = 0; row < d->headerRows; ++row) {
            // Copy header rows
            cursor->headerRowPositions[row] = d->rowPositions[row];
            d->headerRowPositions[row] = d->rowPositions[row];
            for (int col = 0; col < d->table->columns(); ++col) {
                cursor->headerCellAreas[row][col] = d->cellAreas[row][col];
            }
        }
        if (d->headerRows) {
            // Also set the position of the border below headers
            cursor->headerRowPositions[d->headerRows] = d->rowPositions[d->headerRows];
            d->headerRowPositions[d->headerRows] = d->rowPositions[d->headerRows];
        }
        cursor->headerPositionX = d->columnPositions[0];

        if (!virginPage() && d->totalMisFit) {
            //if we couldn't fit the header rows plus some then don't even try
            cursor->row = 0;
            nukeRow(cursor);
        }
    }

    d->endOfArea = new TableIterator(cursor);

    return complete;
}
Example #13
0
static mstate
_int_new_arena (size_t size)
{
  mstate a;
  heap_info *h;
  char *ptr;
  unsigned long misalign;

  h = new_heap (size + (sizeof (*h) + sizeof (*a) + MALLOC_ALIGNMENT),
                mp_.top_pad);
  if (!h)
    {
      /* Maybe size is too large to fit in a single heap.  So, just try
         to create a minimally-sized arena and let _int_malloc() attempt
         to deal with the large request via mmap_chunk().  */
      h = new_heap (sizeof (*h) + sizeof (*a) + MALLOC_ALIGNMENT, mp_.top_pad);
      if (!h)
        return 0;
    }
  a = h->ar_ptr = (mstate) (h + 1);
  malloc_init_state (a);
  a->attached_threads = 1;
  /*a->next = NULL;*/
  a->system_mem = a->max_system_mem = h->size;

  /* Set up the top chunk, with proper alignment. */
  ptr = (char *) (a + 1);
  misalign = (unsigned long) chunk2mem (ptr) & MALLOC_ALIGN_MASK;
  if (misalign > 0)
    ptr += MALLOC_ALIGNMENT - misalign;
  top (a) = (mchunkptr) ptr;
  set_head (top (a), (((char *) h + h->size) - ptr) | PREV_INUSE);

  LIBC_PROBE (memory_arena_new, 2, a, size);
  mstate replaced_arena = thread_arena;
  thread_arena = a;
  __libc_lock_init (a->mutex);

  __libc_lock_lock (list_lock);

  /* Add the new arena to the global list.  */
  a->next = main_arena.next;
  /* FIXME: The barrier is an attempt to synchronize with read access
     in reused_arena, which does not acquire list_lock while
     traversing the list.  */
  atomic_write_barrier ();
  main_arena.next = a;

  __libc_lock_unlock (list_lock);

  __libc_lock_lock (free_list_lock);
  detach_arena (replaced_arena);
  __libc_lock_unlock (free_list_lock);

  /* Lock this arena.  NB: Another thread may have been attached to
     this arena because the arena is now accessible from the
     main_arena.next list and could have been picked by reused_arena.
     This can only happen for the last arena created (before the arena
     limit is reached).  At this point, some arena has to be attached
     to two threads.  We could acquire the arena lock before list_lock
     to make it less likely that reused_arena picks this new arena,
     but this could result in a deadlock with
     __malloc_fork_lock_parent.  */

  __libc_lock_lock (a->mutex);

  return a;
}
Example #14
0
static int
heap_trim (heap_info *heap, size_t pad)
{
  mstate ar_ptr = heap->ar_ptr;
  unsigned long pagesz = GLRO (dl_pagesize);
  mchunkptr top_chunk = top (ar_ptr), p;
  heap_info *prev_heap;
  long new_size, top_size, top_area, extra, prev_size, misalign;

  /* Can this heap go away completely? */
  while (top_chunk == chunk_at_offset (heap, sizeof (*heap)))
    {
      prev_heap = heap->prev;
      prev_size = prev_heap->size - (MINSIZE - 2 * SIZE_SZ);
      p = chunk_at_offset (prev_heap, prev_size);
      /* fencepost must be properly aligned.  */
      misalign = ((long) p) & MALLOC_ALIGN_MASK;
      p = chunk_at_offset (prev_heap, prev_size - misalign);
      assert (chunksize_nomask (p) == (0 | PREV_INUSE)); /* must be fencepost */
      p = prev_chunk (p);
      new_size = chunksize (p) + (MINSIZE - 2 * SIZE_SZ) + misalign;
      assert (new_size > 0 && new_size < (long) (2 * MINSIZE));
      if (!prev_inuse (p))
        new_size += prev_size (p);
      assert (new_size > 0 && new_size < HEAP_MAX_SIZE);
      if (new_size + (HEAP_MAX_SIZE - prev_heap->size) < pad + MINSIZE + pagesz)
        break;
      ar_ptr->system_mem -= heap->size;
      LIBC_PROBE (memory_heap_free, 2, heap, heap->size);
      delete_heap (heap);
      heap = prev_heap;
      if (!prev_inuse (p)) /* consolidate backward */
        {
          p = prev_chunk (p);
          unlink_chunk (ar_ptr, p);
        }
      assert (((unsigned long) ((char *) p + new_size) & (pagesz - 1)) == 0);
      assert (((char *) p + new_size) == ((char *) heap + heap->size));
      top (ar_ptr) = top_chunk = p;
      set_head (top_chunk, new_size | PREV_INUSE);
      /*check_chunk(ar_ptr, top_chunk);*/
    }

  /* Uses similar logic for per-thread arenas as the main arena with systrim
     and _int_free by preserving the top pad and rounding down to the nearest
     page.  */
  top_size = chunksize (top_chunk);
  if ((unsigned long)(top_size) <
      (unsigned long)(mp_.trim_threshold))
    return 0;

  top_area = top_size - MINSIZE - 1;
  if (top_area < 0 || (size_t) top_area <= pad)
    return 0;

  /* Release in pagesize units and round down to the nearest page.  */
  extra = ALIGN_DOWN(top_area - pad, pagesz);
  if (extra == 0)
    return 0;

  /* Try to shrink. */
  if (shrink_heap (heap, extra) != 0)
    return 0;

  ar_ptr->system_mem -= extra;

  /* Success. Adjust top accordingly. */
  set_head (top_chunk, (top_size - extra) | PREV_INUSE);
  /*check_chunk(ar_ptr, top_chunk);*/
  return 1;
}
void QLongLongValidator::setBottom(qlonglong bottom)
{
    setRange(bottom, top());
}
Example #16
0
 Object Stack<Object>::topAndPop( )
 {
     Object topItem = top( );
     pop( );
     return topItem;
 }
Example #17
0
void renderScene(void) {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glPushMatrix();
                   alas();
    glPopMatrix();
    
    //bianglala
    glPushMatrix();
                   
                   glTranslatef(-20,16,-20);
                   glScalef(3,3,3);
                   glRotatef(135,0,1,0);
                   ada();
                   ass();
                   kaki();
                   glPushMatrix();
                                  glRotatef(qwe,0,0,1);
                                  duduk();
                   glPopMatrix();
                   glColor3f(1.0,1.0,1.0);
   glPopMatrix();
   /////////////////bianglala////////////////////////
        
    //rajawali
    glPushMatrix();
                   
                   glTranslatef(20,17,-20);
                   glScalef(3,3,3);
                   glRotatef(0,1,0,0);
                   glPushMatrix();
                                  if(asd<70){
                                  glTranslatef( 0, asd/10, 0);}
                                  else {glTranslatef(0, fgh/10, 0);}
                                  donat();
                   glPopMatrix();
                   tiang();
                   glColor3f(1.0,1.0,1.0);
   glPopMatrix();
   /////////////rajawali//////////////
   
   //hysteria
   glPushMatrix();
                  
                  glTranslatef(20,13.5,20);
                  glScalef(3,3,3);
                  glPushMatrix();
                  if(ert<60){
                  glTranslatef( 0, ert/10, 0);}
                  else {glTranslatef(0, yui/10, 0);}
                  yangbiru();
                  glPopMatrix();
                  top();
   glPopMatrix();
   //////////hysteria////////////
   
  	
	//Menggambar Halaman
	glColor3f(0, 3, 0);
	glBegin(GL_QUADS);
		glVertex3f(-40.0, 0.1, -40.0);
		glVertex3f(-40.0, 0.1,  40.0);
		glVertex3f( 40.0, 0.1,  40.0);
		glVertex3f( 40.0, 0.1, -40.0);
	glEnd();
	
	
    glutSwapBuffers();
}
Example #18
0
void* pop(Stack *stack){
	void *removedElement;
	removedElement = top(stack);
	stack->top = stack->top-1;
		return removedElement;
}
Example #19
0
int main()
{
    int type;
    double op2;
    double x, y, ans;
    char s[MAXOP];

    printf(">> ");
    while ((type = getop(s)) != EOF) {
	switch (type) {
	case NUMBER:
	    push(atof(s));
	    break;
	case PLUS:
	    push(pop() + pop());
	    break;
	case TIMES:
	    push(pop() * pop());
	    break;
	case MINUS:
	    op2 = pop();
	    push(pop() - op2);
	    break;
	case DIVIDE:
	    op2 = pop();
	    if (op2 != 0.0)
		push(pop() / op2);
	    else
		printf("error: zero divisor!\n");
	    break;
	case REMAIN:
	    op2 = pop();
	    if (op2 != 0.0)
		push((double) ((long) pop() % (long) op2));
	    else
		printf("error: zero divisor!\n");
	    break;
	case TOP:
	    top();
	    getch();
	    printf(">> ");
	    break;
	case SWAP:
	    swap();
	    getch();
	    printf(">> ");
	    break;
	case CLEAR:
	    clear();
	    getch();
	    printf(">> ");
	    break;
	case SIN:
	    push(sin(pop()));
	    break;
	case COS:
	    push(cos(pop()));
	    break;
	case TAN:
	    push(tan(pop()));
	    break;
	case ASIN:
	    push(asin(pop()));
	    break;
	case ACOS:
	    push(acos(pop()));
	    break;
	case ATAN:
	    push(atan(pop()));
	    break;
	case EXP:
	    push(exp(pop()));
	    break;
	case POW:
	    op2 = pop();
	    push(pow(pop(), op2));
	    break;
	case LOG:
	    push(log(pop()));
	    break;
	case LOG10:
	    push(log10(pop()));
	    break;
	case SQRT:
	    push(sqrt(pop()));
	    break;
	case X:
	    push(x);
	    break;
	case Y:
	    push(y);
	    break;
	case ANS:
	    push(ans);
	    break;
	case SETX:
	    x = pop();
	    getch();
	    printf(">> ");
	    break;
	case SETY:
	    y = pop();
	    getch();
	    printf(">> ");
	    break;
	case '\n':
	    ans = pop();
	    printf("\t%.8g\n", ans);
	    printf(">> ");
	    break;
	default:
	    printf("error:unknown command %s\n", s);
	    break;
	}
    }
    printf("\n");
    return 0;
}
Example #20
0
double LinearRegression::gain()
{
    double g = bottom()!=0 ? top()/bottom():0;
    return (g);
}
Example #21
0
int sc_main(int argc, char* argv[]) {

  Top top("top");
  sc_core::sc_start();
  return 0;
}
Example #22
0
void MotionMaster::InitTop()
{
    top()->Initialize(*i_owner);
    needInit[i_top] = false;
}
Example #23
0
command_t 
make_command_tree(token_stream_t t)
{
 
  token_t sub_head = t->head;//the sub_head is t->head 
  token_t token_now = sub_head->next;
  Stack_t operators =initStack();
  Stack_t operands =initStack();//build two stacks to hold operands and operators
  command_t comm;//one command
  command_t prev = NULL;
  int line = token_now->line; 
  int counter=0;
  //if(token_now->next == NULL)
   // printf("Heere\n");
  while(token_now!=NULL)
  {
    counter++;
   // printf("the %d time loop, the type is %d", counter,token_now->t_type);
    if( !(token_now->t_type == LEFT_DERCTION || token_now->t_type == RIGHT_DERCTION) )
      {
        // make new command
        comm = (command_t)checked_malloc(sizeof( struct command ));
      }
    switch(token_now->t_type)
    
    {
      case AND:
      comm->type = AND_COMMAND;
      while (  !is_empty(operators) &&( top(operators)->type == PIPE_COMMAND || top(operators)->type == OR_COMMAND || top(operators)->type == AND_COMMAND ))
          {
            command_t pop_ops = pop(operators);//pop until the top ops has smaller presendence than
            if (!make_command_branch(pop_ops, operands))
              {
                error(2, 0, "Line %d: Syntax error. Not enough children to create new tree.", line);
                return NULL;
              }
          }
          push(operators,comm);//push ADD command to ops
          token_now = token_now->next;
          break;

        case OR:
      comm->type = OR_COMMAND;
      while (  !is_empty(operators) &&( top(operators)->type == PIPE_COMMAND || top(operators)->type == OR_COMMAND || top(operators)->type == AND_COMMAND ))
          {
            command_t pop_ops = pop(operators);//pop until the top ops has smaller presendence than
            if (!make_command_branch(pop_ops, operands))
              {
               error(2, 0, "Line %d: Syntax error. Not enough children to create new tree.", line);
                return NULL;
              }
          }
          push(operators,comm);//push ADD command to ops
          token_now = token_now->next;
          break;

        // push OR to ops
        push(operators,comm);
        break;

        case PIPELINE:
      comm->type = PIPE_COMMAND;
      while (  !is_empty(operators) && top(operators)->type == PIPE_COMMAND )
          {
            command_t pop_ops = pop(operators);//pop until the top ops has smaller presendence than
            if (!make_command_branch(pop_ops, operands))
              {
                error(2, 0, "Line %d: Syntax error. Not enough children to create new tree.", line);
                return NULL;
              }
          }
          push(operators,comm);//push PIPE command to ops
          token_now = token_now->next;
          break;

        case SEMICOLON:
          comm->type = SEQUENCE_COMMAND;

        // always pop since SEMICOLON <= all ops
          while (!is_empty(operators))
          {
            command_t pop_ops = pop(operators);
              if (!make_command_branch(pop_ops, operands))
              {
                error(2, 0, "Line %d: Syntax error. Not enough children to create new tree.", line);
                return NULL;
              }
          }

        // push SEMICOLON to ops
          push(operators,comm);
          token_now = token_now->next;
          break;

        case WORD:
          comm->type = SIMPLE_COMMAND;
          //seprated by word
          int num_words = 1;
          token_t count = token_now;
          while(count!=NULL&&count->next!=NULL&&count->next->t_type==WORD)//while next is still word
          {
            count = count ->next;
            num_words++;
          }
          comm->u.word = (char**)checked_malloc((num_words+1)*sizeof(char**));
          comm->u.word[0] = token_now->text;
          int i =1;
          while(i< num_words)
          {
            token_now = token_now->next;
            comm->u.word[i] = token_now->text;
            add_filename_to_dependlist(comm->u.word[i]);
            i++;
            //if(i == num_words)
          }
          comm->u.word[num_words] = NULL;
          push(operands,comm);
          token_now = token_now->next;
          break;

        case SUBSHELL:
        comm->type = SUBSHELL_COMMAND;

        // process subshell command tree
        token_stream_t subshell_token = convert_buffer_to_token_stream(token_now->text, strlen(token_now->text));
        command_t subshell_command = make_command_tree(subshell_token);
        comm->u.subshell_command = subshell_command;

        // push SUBSHELL tree to operands
        push(operands, comm);
        token_now = token_now->next;
        break;

      case LEFT_DERCTION:
        // check that previous command is a subshell or word
        if (prev== NULL || !(prev->type == SIMPLE_COMMAND || prev->type == SUBSHELL_COMMAND))
        {
         error(2, 0, "Line %d: Syntax error. ONLY words and SUBSHELL can follow redirection", line);
          return NULL;
        }
       /* else if (prev->output != NULL)
        {
          error(2, 0, "Line %d: Syntax error. Previous command already has output. ", line);
          return NULL;
        }*/
        else if (prev->input != NULL)
        {
          error(2, 0, "Line %d: Syntax error. Previous command already has input.", line);
          return NULL;
        }

        token_now= token_now->next;
        if (token_now->t_type == WORD) // followed by a word
        {
          //which is valid input
            prev->input = token_now->text;
            add_filename_to_dependlist(prev->input);
        }
        else
        {
          error(2, 0, "Line %d: Syntax error. Redirects must be followed by words.", line);
          return NULL;
        }
        token_now= token_now->next;
        // no pushing required
        break;

        case RIGHT_DERCTION:
        // check that previous command is a subshell or word
        if (prev== NULL || !(prev->type == SIMPLE_COMMAND || prev->type == SUBSHELL_COMMAND))
        {
          error(2, 0, "Line %d: Syntax error. ONLY words and SUBSHELL can follow redirection", line);
          return NULL;
        }
        else if (prev->output != NULL)
        {
          error(2, 0, "Line %d: Syntax error. Previous command already has output. ", line);
          return NULL;
        }
        /*else if (prev->input != NULL)
        {
          //error(2, 0, "Line %d: Syntax error. Previous command already has input.", line);
          return NULL;
        }*/

        token_now= token_now->next;
        if (token_now->t_type == WORD) // followed by a word
        {
          //which is valid output
            prev->output = token_now->text;
            //add output word to outfile_list
            outfile_t new_outfile = add_out_list (prev);
            prev->outfile_ptr = new_outfile;
        }
        else
        {
          error(2, 0, "Line %d: Syntax error. Redirects must be followed by words.", line);
          return NULL;
        }

        // no pushing required
        token_now= token_now->next;
        break;
        default:
        token_now = token_now->next;
        break;
      };
     prev = comm;
    // printf("the previous command is: %d\n", prev->type);
  }
  //printf("end first while");
 while(size(operators) > 0)
    {
      command_t pop_ops = pop(operators);

      if (!make_command_branch(pop_ops, operands))
      {
          error(2, 0, "Line %d: Syntax error. Not enough children to create new tree.", line);
          return NULL;
      }
    }

  // check for single root
    if (size(operands) != 1)
    {
      error(2, 0, "Line %d: Syntax error. Tree did not converge into single root.", line);
      return NULL;
    }

    command_t root = pop(operands); // the root should be the final tree left in operands

    return root;
}


void coll_box::get_corners( vec2_f24p8& lt_corner, vec2_f24p8& rt_corner, 
	vec2_f24p8& rb_corner, vec2_f24p8& lb_corner )
{
	lt_corner.x = lb_corner.x = left();
	rt_corner.x = rb_corner.x = right();
	
	lt_corner.y = rt_corner.y = top();
	lb_corner.y = rb_corner.y = bot();
}



void coll_box::get_block_coords_intersected_by_corners 
	( vec2_s32& lt_block_coord, vec2_s32& rt_block_coord,
	vec2_s32& rb_block_coord, vec2_s32& lb_block_coord )
{
	
	lt_block_coord.x = lb_block_coord.x = left().round_to_int() >> 4;
	rt_block_coord.x = rb_block_coord.x = right().round_to_int() >> 4;
	
	lt_block_coord.y = rt_block_coord.y = top().round_to_int() >> 4;
	lb_block_coord.y = rb_block_coord.y = bot().round_to_int() >> 4;
	
}



Example #25
0
void MotionMaster::MoveIdle()
{
    if (empty() || !isStatic(top()))
        push(&si_idleMovement);
}
Example #26
0
LowFrequencyCharactersDemo::LowFrequencyCharactersDemo(hkDemoEnvironment* env)
:	hkDefaultPhysicsDemo(env)
{

	//
	// Setup the camera
	//
	{
		hkVector4 from(  0.0f, 20.0f, -80.0f);
		hkVector4 to  (  0.0f,  0.0f,   0.0f);
		hkVector4 up  (  0.0f,  1.0f,   0.0f);
		setupDefaultCameras( env, from, to, up );

		forceShadowState(false);

	}

	//
	// Create the world
	//
	{
		hkpWorldCinfo info;
		info.setBroadPhaseWorldSize( 350.0f );  
		info.m_gravity.set(0, -9.8f, 0);
		info.m_collisionTolerance = 0.1f;		
		m_world = new hkpWorld( info );
		m_world->lock();

		hkpAgentRegisterUtil::registerAllAgents(m_world->getCollisionDispatcher());

		setupGraphics();
	}


	//
	//	Create a terrain 
	//
	TerrainHeightFieldShape* heightFieldShape;
	{
		hkpSampledHeightFieldBaseCinfo ci;
		ci.m_xRes = 64;
		ci.m_zRes = 64;
		ci.m_scale.set(4,1,4);

		//
		// Fill in a data array
		//
		m_data = hkAllocate<hkReal>(ci.m_xRes * ci.m_zRes, HK_MEMORY_CLASS_DEMO);
		for (int x = 0; x < ci.m_xRes; x++)
		{
			for (int z = 0; z < ci.m_xRes; z++)
			{
				hkReal dx,dz,height = 0;
				int octave = 1;
				// Add togther a few sine and cose waves
				for (int i=0; i< 3; i++)
				{
					dx = hkReal(x * octave) / ci.m_xRes;
					dz = hkReal(z * octave) / ci.m_zRes;
					height +=  (5 - (i * 2)) * hkMath::cos(dx * HK_REAL_PI) * hkMath::sin(dz * HK_REAL_PI);
					octave *= 4;
				}

				m_data[x*ci.m_zRes + z] = height;
			}
		}

		heightFieldShape = new TerrainHeightFieldShape( ci , m_data );
		//
		//	Create a fixed rigid body
		//
		{
			hkpRigidBodyCinfo rci;
			rci.m_motionType = hkpMotion::MOTION_FIXED;
			rci.m_position.setMul4( -0.5f, heightFieldShape->m_extents ); // center the heightfield
			rci.m_shape = heightFieldShape;
			rci.m_friction = 0.05f;

			hkpRigidBody* body = new hkpRigidBody( rci );

			m_world->addEntity(body)->removeReference();
		}

		heightFieldShape->removeReference();
	}

	//
	//	Create a character proxy object
	//
	{
		m_numBoxes = 0;
		m_numCapsules = 0;
		m_numSpheres = 0;
		
		// We'll store the simulation frequency in this 
		hkpPropertyValue val;

		// Construct shape phantoms for the characters
		hkPseudoRandomGenerator random(123);
		for (int i=0; i < NUM_CHARACTERS; i++)
		{

			// Create a random shape to represent the character
			hkpConvexShape* shape = HK_NULL;
			{
				hkReal scale = random.getRandReal01() * 0.25f + 0.75f;

				//Set the simulation frequency
				val.setInt( random.getRand32() % 3 );

				switch (val.getInt())
				{
					case 0:
						{
							hkVector4 top(0, scale * 0.4f, 0);
							hkVector4 bottom(0, -scale * 0.4f, 0);					
							shape = new hkpCapsuleShape(top, bottom, scale * 0.6f);
							m_numCapsules++;
						}
						break;
					case 1:
						{
							hkVector4 size(scale * 0.5f, scale , scale * 0.5f);
							shape = new hkpBoxShape(size);
							m_numBoxes++;
						}
						break;
					default:
						{
							shape = new hkpSphereShape(scale);
							m_numSpheres++;
						}
						break;
				}
			}

			hkpShapePhantom* phantom = new hkpSimpleShapePhantom( shape, hkTransform::getIdentity() );
			shape->removeReference();

			// Add the phantom to the world
			m_world->addPhantom(phantom);
			phantom->removeReference();

			HK_SET_OBJECT_COLOR( (hkUlong)phantom->getCollidable(), 0x7fffffff & hkColor::getRandomColor() );

			// Construct a character proxy
			hkpCharacterProxyCinfo cpci;
			random.getRandomVector11( cpci.m_position );
			cpci.m_position.mul4(32);
			cpci.m_position(1) = 10;
			cpci.m_up.setNeg4( m_world->getGravity() );
			cpci.m_up.normalize3();

			cpci.m_shapePhantom = phantom;
			m_characterProxy[i] = new hkpCharacterProxy( cpci );

			// Player is simulated at full frequency
			if (i==0)
			{
				val.setInt(0);
			}

			// Add the schedule property
			phantom->addProperty(HK_SCHEDULE_FREQUENCY, val);
		}
	}
	
	//
	// Create the Character state machine and context
	//
	hkpCharacterStateManager* manager;
	{
		hkpCharacterState* state;
		manager = new hkpCharacterStateManager();

		state = new hkpCharacterStateOnGround();
		manager->registerState( state,	HK_CHARACTER_ON_GROUND);
		state->removeReference();

		state = new hkpCharacterStateInAir();
		manager->registerState( state,	HK_CHARACTER_IN_AIR);
		state->removeReference();

		state = new hkpCharacterStateJumping();
		manager->registerState( state,	HK_CHARACTER_JUMPING);
		state->removeReference();

		state = new hkpCharacterStateClimbing();
		manager->registerState( state,	HK_CHARACTER_CLIMBING);
		state->removeReference();

	}

	// Create a context for each character
	{
		for (int i=0; i < NUM_CHARACTERS; i++)
		{
			m_characterContext[i] = new hkpCharacterContext(manager, HK_CHARACTER_ON_GROUND);
		}
		manager->removeReference();
	}
	
	// Current camera angle about up
	m_currentAngle = 0.0f;

	//Initialised the round robin counter
	m_tick = 0;

	m_world->unlock();
}
Example #27
0
void applyIF(void)
{
  evaluatetop();
  push(top()->value ? getN(2) : getN(3));
  evaluatetop();
}
Example #28
0
int
__malloc_set_state (void *msptr)
{
  struct malloc_save_state *ms = (struct malloc_save_state *) msptr;
  size_t i;
  mbinptr b;

  disallow_malloc_check = 1;
  ptmalloc_init ();
  if (ms->magic != MALLOC_STATE_MAGIC)
    return -1;

  /* Must fail if the major version is too high. */
  if ((ms->version & ~0xffl) > (MALLOC_STATE_VERSION & ~0xffl))
    return -2;

  (void) mutex_lock (&main_arena.mutex);
  /* There are no fastchunks.  */
  clear_fastchunks (&main_arena);
  if (ms->version >= 4)
    set_max_fast (ms->max_fast);
  else
    set_max_fast (64);  /* 64 used to be the value we always used.  */
  for (i = 0; i < NFASTBINS; ++i)
    fastbin (&main_arena, i) = 0;
  for (i = 0; i < BINMAPSIZE; ++i)
    main_arena.binmap[i] = 0;
  top (&main_arena) = ms->av[2];
  main_arena.last_remainder = 0;
  for (i = 1; i < NBINS; i++)
    {
      b = bin_at (&main_arena, i);
      if (ms->av[2 * i + 2] == 0)
        {
          assert (ms->av[2 * i + 3] == 0);
          first (b) = last (b) = b;
        }
      else
        {
          if (ms->version >= 3 &&
              (i < NSMALLBINS || (largebin_index (chunksize (ms->av[2 * i + 2])) == i &&
                                  largebin_index (chunksize (ms->av[2 * i + 3])) == i)))
            {
              first (b) = ms->av[2 * i + 2];
              last (b) = ms->av[2 * i + 3];
              /* Make sure the links to the bins within the heap are correct.  */
              first (b)->bk = b;
              last (b)->fd = b;
              /* Set bit in binblocks.  */
              mark_bin (&main_arena, i);
            }
          else
            {
              /* Oops, index computation from chunksize must have changed.
                 Link the whole list into unsorted_chunks.  */
              first (b) = last (b) = b;
              b = unsorted_chunks (&main_arena);
              ms->av[2 * i + 2]->bk = b;
              ms->av[2 * i + 3]->fd = b->fd;
              b->fd->bk = ms->av[2 * i + 3];
              b->fd = ms->av[2 * i + 2];
            }
        }
    }
  if (ms->version < 3)
    {
      /* Clear fd_nextsize and bk_nextsize fields.  */
      b = unsorted_chunks (&main_arena)->fd;
      while (b != unsorted_chunks (&main_arena))
        {
          if (!in_smallbin_range (chunksize (b)))
            {
              b->fd_nextsize = NULL;
              b->bk_nextsize = NULL;
            }
          b = b->fd;
        }
    }
  mp_.sbrk_base = ms->sbrk_base;
  main_arena.system_mem = ms->sbrked_mem_bytes;
  mp_.trim_threshold = ms->trim_threshold;
  mp_.top_pad = ms->top_pad;
  mp_.n_mmaps_max = ms->n_mmaps_max;
  mp_.mmap_threshold = ms->mmap_threshold;
  check_action = ms->check_action;
  main_arena.max_system_mem = ms->max_sbrked_mem;
  mp_.n_mmaps = ms->n_mmaps;
  mp_.max_n_mmaps = ms->max_n_mmaps;
  mp_.mmapped_mem = ms->mmapped_mem;
  mp_.max_mmapped_mem = ms->max_mmapped_mem;
  /* add version-dependent code here */
  if (ms->version >= 1)
    {
      /* Check whether it is safe to enable malloc checking, or whether
         it is necessary to disable it.  */
      if (ms->using_malloc_checking && !using_malloc_checking &&
          !disallow_malloc_check)
        __malloc_check_init ();
      else if (!ms->using_malloc_checking && using_malloc_checking)
        {
          __malloc_hook = NULL;
          __free_hook = NULL;
          __realloc_hook = NULL;
          __memalign_hook = NULL;
          using_malloc_checking = 0;
        }
    }
  if (ms->version >= 4)
    {
      mp_.arena_test = ms->arena_test;
      mp_.arena_max = ms->arena_max;
      narenas = ms->narenas;
    }
  check_malloc_state (&main_arena);

  (void) mutex_unlock (&main_arena.mutex);
  return 0;
}
Example #29
0
 size_t remaining() const                       { return end() == NULL ? 0 : pointer_delta(hard_end(), top()); }
Example #30
0
 //execute context
 l_thread::type_return l_thread::execute(l_call_context&  context)
 {
     //lock context
     context.lock();
     //save context
     register3(R_CONTEXT)      = l_variable( &context );
     //pc...
     unsigned int     pc       = 0;
     l_function&      function = m_vm->function(context.get_fun_id());
     l_list_command&  commands = function.m_commands;
     //macro
     #define raise(str)\
     {\
         push_error(str, pc, (unsigned int)commands[pc].m_line);\
         return T_RETURN_ERROR;\
     }
     #define vconst(c)  function.m_costants[c]
     #define top_size   (m_top+1)
     //for all commands
     for (pc = 0; pc < commands.size(); ++pc)
     {
         //current command
         l_command& cmp = commands[pc];
         //opcodes
         switch (cmp.m_op_code)
         {
             case L_JMP: pc = cmp.m_arg - 1; break;
             case L_RETURN:
                 //push return
                 if(cmp.m_arg)
                 {
                     //get value
                     register3(2) = pop();
                     //return...
                     return T_RETURN_VALUE;
                 }
                 else
                 {
                     //came back
                     return T_RETURN_VOID;
                 }
                 //..
             break;
                 
             case L_IF:
                 if(top().is_true())
                 {
                     pc = cmp.m_arg - 1;
                 }
                 pop();
             break;
                 
             case L_IF0:
                 if(top().is_false())
                 {
                     pc = cmp.m_arg - 1;
                 }
                 pop();
             break;
                 
             case L_IF_OR_POP:
                 if(top().is_true())
                 {
                     pc = cmp.m_arg - 1;
                 }
                 else
                 {
                     pop();
                 }
             break;
                 
             case L_IF0_OR_POP:
                 if(top().is_false())
                 {
                     pc = cmp.m_arg - 1;
                 }
                 else
                 {
                     pop();
                 }
             break;
                 
             case L_PUSH:          push( stack(cmp.m_arg) );  break;
             case L_PUSH_NULL:     push( l_variable() );      break;
             case L_PUSH_TRUE:     push( l_variable(true) );  break;
             case L_PUSH_FALSE:    push( l_variable(false) ); break;
             case L_PUSHK:         push( vconst(cmp.m_arg) ); break;
             case L_CLOSER:
             {
                 //get value
                 l_variable& call_fun = vconst(cmp.m_arg);
                 //...
                 if(call_fun.is_function())
                 {
                     
                     //new context
                     register3(0) = l_closer::gc_new(get_gc());
                     //init context
                     register3(0).to<l_closer>()->init(call_fun.m_value.m_fid, this, l_variable(&context));
                     //push context
                     push(register3(0));
                 }
             }
             break;
                 ////////////////////////////////////////////////////////////
             case L_ADD:
                 if(!stack(1).add(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_MUL:
                 if(!stack(1).mul(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_SUB:
                 if(!stack(1).sub(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_DIV:
                 if(!stack(1).div(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_MOD:
                 if(!stack(1).mod(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_UNM:
                 if(!stack(0).unm(stack(0))) raise("not valid operation");
             break;
             ////////////////////////////////////////////////////////////
             case L_EQ:
                 if(!stack(1).equal(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_NEQ:
                 if(!stack(1).not_equal(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_RT:
                 if(!stack(1).rt(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_RE:
                 if(!stack(1).re(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_LT:
                 if(!stack(1).lt(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_LE:
                 if(!stack(1).le(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
             ////////////////////////////////////////////////////////////
             case L_NOT:
                 if(!stack(0).not_value(stack(0))) raise("not valid operation");
             break;
                 
             case L_OR:
                 if(!stack(1).or_value(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
                 
             case L_AND:
                 if(!stack(1).and_value(stack(0),stack(1))) raise("not valid operation");
                 pop();
             break;
             ////////////////////////////////////////////////////////////
             case L_GET_GLOBAL:
                 push( global(context,cmp.m_arg) );
             break;
                 
             case L_SET_GLOBAL:
                 global(context,cmp.m_arg) = pop();
             break;
             ////////////////////////////////////////////////////////////
             case L_GET_LOCAL:
                 push( strick_local(context,cmp.m_arg) );
             break;
                 
             case L_SET_LOCAL:
                 strick_local(context,cmp.m_arg) = pop();
             break;
             ////////////////////////////////////////////////////////////
             case L_SET_UP_VALUE:
                 local(context,cmp.m_arg) = pop();
             break;
                 
             case L_GET_UP_VALUE:
                 push( local(context,cmp.m_arg) );
             break;
             ////////////////////////////////////////////////////////////
             case L_GET_THIS:
                 push(context.this_field());
             break;
             case L_SET_THIS:
                 context.this_field() = pop();
             break;
             case L_SET_THIS_NPOP:
                 context.this_field() = stack(cmp.m_arg);
             break;
             ////////////////////////////////////////////////////////////
             case L_NEW_ARRAY:
             {
                 register3(0) = l_array::gc_new(get_gc());
                 //init ?
                 if( cmp.m_arg > 0 )
                 {
                     //types
                     l_array* vector = register3(0).array();
                     //put stack into vector
                     for(int i = cmp.m_arg-1; i >= 0; --i)
                     {
                         vector->operator[](i) = pop();
                     }
                 }
                 //push array (n.b. gc run...)
                 push( register3(0) );
             }
             break;
             //alloc tablet
             case L_NEW_TABLE:
             {
                 register3(0) = l_table::gc_new(get_gc());
                 //init ?
                 if( cmp.m_arg > 0 )
                 {
                     //types
                     l_table* table = register3(0).table();
                     //assert
                     assert(!(cmp.m_arg % 2));
                     //put stack into vector
                     for(int i = (cmp.m_arg)-1; i >= 0; i-=2)
                     {
                         //push key and value
                         table->operator[](stack(1)) = stack(0);
                         //pop value
                         pop();
                         //pop key
                         pop();
                     }
                 }
                 //push table (n.b. gc run...)
                 push( register3(0) );
             }
             break;
             case L_GET_AT_VAL:
             {
                       l_variable& r_b = stack(1);
                 const l_variable& r_c = stack(0);
                 //try
                 if ( r_b.is_object() )
                 {
                     //is a vector
                     if(r_b.is_array())
                     {
                         //types
                         l_array* vector = r_b.array();
                         //to size int
                         size_t index = 0;
                         //cast
                         if( r_c.is_int() )  index= (size_t)r_c.m_value.m_i;
                         else if( r_c.is_float() )index= (size_t)r_c.m_value.m_f;
                         else raise( "value isn't a valid key" );
                         //save last
                         get_this() = stack(1);
                         //get
                         stack(1)   = vector->operator[](index) ;
                     }
                     else if(r_b.is_table())
                     {
                         //types
                         l_table* table =  r_b.table();
                         //is a string?
                         if(!r_c.is_string()) raise( "value isn't a valid key" );
                         //save last
                         get_this() = stack(1);
                         //get and pop value
                         stack(1) = table->operator[](r_c);
                     }
                     else
                     {
                         raise( "value isn't a vector/table, field not available" );
                     }
                 }
                 else
                 {
                     raise( "value isn't a vector/table/object, field not avaliable" );
                 }
                 //pop index
                 pop();
             }
             break;
             case L_SET_AT_VAL:
             {
                 //get table/array
                       l_variable& r_a = stack(2);
                 //get index
                 const l_variable& r_b = stack(1);
                 //try
                 if ( r_a.is_object() )
                 {
                     //is a vector
                     if(r_a.is_array())
                     {
                         //types
                         l_array* vector = r_a.array();
                         //to size int
                         size_t index = 0;
                         //cast
                              if( r_b.is_int()   ) index= (size_t)r_b.m_value.m_i;
                         else if( r_b.is_float() ) index= (size_t)r_b.m_value.m_f;
                         else raise( "value isn't a valid key" );
                         //get and pop value
                         vector->operator[](index) = pop();
                     }
                     else if(r_a.is_table())
                     {
                         //types
                         l_table* table =  r_a.table();
                         //is a string?
                         if(!r_b.is_string()) raise( "value isn't a valid key" );
                         //get and pop value
                         table->operator[](r_b) = pop();
                     }
                     else
                     {
                         raise( "value isn't a vector/table, field not available" );
                     }
                 }
                 else
                 {
                     //pop value
                     pop();
                 }
                 //pop index
                 pop();
                 //pop array/tablet
                 pop();
             }
             break;
             //for in
             case L_IT:
             {
                 //get index
                 l_variable& r_a = top();
                 //..
                 //try
                 if ( r_a.is_object() )
                 {
                     //get object
                     l_obj* this_obj = (l_obj*)r_a.m_value.m_pobj;
                     //is a vector
                     if(r_a.is_array())
                     {
                         //types
                         l_array* vector = r_a.array();
                         //pop value
                         pop();
                         //push it
                         push( vector->get_it() );
                     }
                     else if (r_a.is_table())
                     {
                         //types
                         l_table* table = r_a.table();
                         //pop value
                         pop();
                         //push it
                         push( table->get_it() );
                     }
                     else if (r_a.to<l_xrange>())
                     {
                         //types
                         l_xrange* xrange = static_cast< l_xrange* > ( this_obj );
                         //pop value
                         pop();
                         //push it
                         push( xrange->get_it() );
                     }
                     else
                     {
                         raise( "this value not have a iterator" );
                     }
                 }
                 else
                 {
                     //pop value
                     pop();
                     //..
                     raise( "value isn't a table/array/object, iterator not supported" );
                 }
             }
             break;
             //for of
             case L_FOR_IN:
             case L_FOR_OF:
             {
                 //get index
                 l_variable& r_it = top();
                 //try
                 if ( r_it.is_iterator() )
                 {
                     //types
                     l_iterator* l_it  = r_it.iterator();
                     //is array it
                     if(l_it)
                     {
                         //else assert
                         assert(l_it);
                         //push it
                         if(l_it->valid())
                         {
                             if(cmp.m_op_code == L_FOR_OF)
                             {
                                 //get next
                                 push( l_it->get() );
                             }
                             else //L_FOR_IN
                             {
                                 //get next
                                 push( l_it->get_id() );
                             }
                             //next
                             l_it->self_next();
                         }
                         else
                         {
                             //pop iterator
                             pop();
                             //and jump
                             pc = cmp.m_arg - 1;
                         }
                     }
                     else
                     {
                         raise( "value isn't a valid iterator" );
                     }
                 }
                 else
                 {
                     //pop it
                     pop();
                     //and jump
                     pc = cmp.m_arg - 1;
                     //...
                     raise( "value isn't an iterator" );
                 }
             }
             break;
             case L_THIS_CALL:
             case L_CALL:
             {
                 //get index
                 register3(0) = pop();
                 //get args
                 if( register3(0).is_cfunction() )
                 {
                     //return size
                     int n_return = register3(0).m_value.m_pcfun(this,cmp.m_arg);
                     //assert (1 return)
                     assert(n_return <= 1);
                     //error
                     if(n_return<0)
                     {
                         raise( "native call exception" );
                     }
                     else if(n_return>1)
                     {
                         raise( "native call can't return more than a value" );
                     }
                     //pop args
                     for(int i=0; i < cmp.m_arg; ++i)
                     {
                         pop();
                     }
                     //if return
                     if(n_return) push(get_return());
                 }
                 else if( register3(0).is_closer() )
                 {
                     //get context
                     l_closer* closer = register3(0).to<l_closer>();
                     //else assert
                     if(!closer){ assert(0); };
                     //new function
                     l_function& call_fun    = m_vm->function(closer->get_fun_id());
                     //save last context
                     l_variable last_ctx     = register3(R_CONTEXT);
                     //new context
                     register3(1)            = l_call_context::gc_new(get_gc());
                     l_call_context* new_ctx = register3(1).to<l_call_context>();
                     //this?
                     if(cmp.m_op_code == L_THIS_CALL)
                     {
                         new_ctx->this_field() = get_this();
                     }
                     //init
                     new_ctx->init(*closer);
                     //lock context
                     new_ctx->lock();
                     //n args
                     unsigned int n_fun_args = call_fun.m_args_size;
                     //alloc array args..?
                     if (call_fun.m_have_args_list)
                     {
                         //alloc array
                         register3(3) = l_array::gc_new(get_gc());
                     }
                     //put arguments
                     for(unsigned int
                         arg  = 0;
                         arg != cmp.m_arg;
                       ++arg)
                     {
                         if (arg < n_fun_args)
                         {
                             new_ctx->variable( call_fun.constant(arg) ) = pop();
                         }
                         else if (call_fun.m_have_args_list)
                         {
                             register3(3).array()->push(pop());
                         }
                         else
                         {
                             pop();
                         }
                     }
                     //add var list
                     if (call_fun.m_have_args_list)
                     {
                         //push array
                         new_ctx->variable( call_fun.constant(n_fun_args) ) = register3(3);
                         //to null
                         register3(3) = l_variable();
                     }
                     //save stack
                     long stack_top_bf_call = m_top;
                     //execute call
                     type_return n_return = execute(*new_ctx);
                     //error?
                     if(n_return==T_RETURN_ERROR)
                     {
                         raise( "call exception" );
                     }
                     //unlock context
                     new_ctx->unlock();
                     //reset last context
                     register3(R_CONTEXT) = last_ctx;
                     //restore stack
                     m_top = stack_top_bf_call;
                     //return?
                     if(n_return == T_RETURN_VALUE)
                     {
                         push(register3(2));
                     }
                 }
                 else
                 {
                     raise( "value isn't an function" );
                 }
                 //dealloc
                 if(cmp.m_op_code == L_THIS_CALL)
                 {
                     get_this() = l_variable();
                 }
             }
             break;
                 
             default:  break;
         }
     }
     
     return T_RETURN_VOID;
 }