Esempio n. 1
0
void UnaryExpression::execute(Stack2 &stack)
{
    if(!customOpCall)
    {
        expr->execute(stack);
        void *ptr = stack.popPtr();
        typeDecl->createInstance(stack, true);
        void *rPtr = stack.popPtr();
        stack.pushPtr(rPtr);
        if(type == not_)
            *(bool*)rPtr = !(*(bool*)ptr);
        else if(type == minus)
        {
            if(dataType == float_)
                *(float*)rPtr = -(*(float*)ptr);
            else if(dataType == int_)
                *(int*)rPtr = -(*(int*)ptr);
            else
                ASSERT(false);
        }
        else
            ASSERT(false);
    }
    else
        customOpCall->execute(stack);
}
Esempio n. 2
0
void IfStatement::execute(Stack2 &stack)
{
    if(stack.owner && stack.owner->state == TaskDeclarationBase::restart)
        internalState = 0;

    bool b;
    switch(internalState)
    {
        case 0:
        expression->execute(stack);
        b = *(bool*)stack.popPtr();
        expression->executeCleanUp(stack);

        if(b)
        {
            internalState = 1;
            case 1:
            ifStatements->execute(stack);
            if(stack.interupt == Stack2::Yield)
                return;
        }
        else if(elseStatements)
        {
            internalState = 2;
            case 2:
            elseStatements->execute(stack);
            if(stack.interupt == Stack2::Yield)
                return;
        }
    }
    internalState = 0;
}
Esempio n. 3
0
void FunctionDeclaration::call(Stack2 &stack)
{
    PUSH_CALL_TREE(stack.executionContext->callTree, ident->name);

    ASSERT(statements);
    stack.pushFrame();

    statements->execute(stack);
    ASSERT(stack.interupt == Stack2::None || stack.interupt == Stack2::Return);
    stack.interupt = Stack2::None;

    for(size_t i = 0; i < paramDecls->size(); i++)
        stack.popPtr();
    stack.popFrame();

    POP_CALL_TREE(stack.executionContext->callTree);
}
Esempio n. 4
0
int main()
{
	Stack2 s;
	s.push(1);
	s.push(2);
	s.push(3);
	while(!s.empty()){
		cout << s.top() << endl;
		s.pop();
	}
}
Esempio n. 5
0
void DFS_M::dfs(int iRoot)
{
  Stack2< Pair<int,int> > fringe;
  //Queue< Pair<int,int> > fringe;

  fringe.push(Pair<int,int>(-1,iRoot));
  int precount = 0; // pre-order counter
  int poscount = 0; // post-order counter
  int inocount = 0; // in-order counter
  int P = -1;
  int forest=0;
  int cyclecount = 0; // number of cycles found so far
  
  while (precount < _graph.getVertexSize())
  { 
    while ( !fringe.empty() )
    {
      Pair<int,int> pair = fringe.getTop(); fringe.pop();
      int v0 = pair.first();
      int v1 = pair.second();
      
      if (v0==-2) {
        _postorder[v1]=poscount;
        ++poscount;
        continue;
      }

      if ( !_visited[v1] )
      {
        // first time we see this vertex, push a dummy edge on the fringe
        // before pushing all its children. When the dummy edge will be popped
        // that means all the subtrees rooted under this vertex v1, will have been
        // explored completely, and we can assign the postorder index to the vertex
        fringe.push(Pair<int,int>(-2,v1));
        _preorder[v1]=precount; ++precount;
        _visited[v1]=1;
        _parent[v1]=v0;
        _forest[v1]=forest;
  
        if ( v0 > -1 )
        {
          _matrix[v0][v1]='T';
        }
        //std::cout << "(" << v1 << ")" << std::endl;
    
        for ( GraphEdgeIter it = _graph.getEdgeIter(v1); !it.end(); ++it )
        {
          int v2 = *it;
          
          if (!_visited[v2]) {
            fringe.push(Pair<int,int>(v1,v2));
          } else { // already visited
            char edgeType = tagEdge(v1,v2);
            cycleCheck(edgeType, v1, v2, cyclecount);
          }
        }
      } else { // already visited
        char edgeType = tagEdge(v0,v1);
        cycleCheck(edgeType, v0, v1, cyclecount);
      }

    }

    if (fringe.empty() && precount<_graph.getVertexSize())
    {
      for (int i=0; i<_graph.getVertexSize(); ++i)
      {
          if (!_visited[i])
          {
            fringe.push(Pair<int,int>(-1,i));
            break;
          }
      }
      ++forest;
    }
  }
}