Exemple #1
0
   void Shutdown()
   {
      if( s_searchPath != 0 )
         delete s_searchPath;
     
      delete memPool;
      memPool = 0;

      delete s_moduleCache;
      s_moduleCache = 0;

      releaseLanguage();
      releaseEncodings();

      // clear all the service ( and VSF );
      s_mtx.lock();
      if( s_serviceMap )
      {
         MapIterator mi = s_serviceMap->begin();
         while ( mi.hasCurrent() ) {
            delete *(VFSProvider**) mi.currentValue();
            mi.next();
         }

         delete s_serviceMap;
         s_serviceMap = 0;
      }
      s_mtx.unlock();

	  //traits::releaseTraits();

	  gcMemShutdown(); 
   }
Exemple #2
0
void GenTree::generate( const SourceTree *st )
{
   // generate functions
   if ( ! st->functions().empty() ) {
      m_out->writeString( "FUNCTIONS: \n" );

      const StmtFunction *func = static_cast<const StmtFunction*>( st->functions().front() );
      while ( func != 0 )
      {
         m_out->writeString( "Function " + func->name() + "(" );
         const Symbol *fsym = func->symbol();
         const FuncDef *fdef = fsym->getFuncDef();

         if( fdef->params() != 0)
         {
            MapIterator iter = fdef->symtab().map().begin();
            bool first = true;

            while( iter.hasCurrent() )
            {
               const Symbol *param = *(const Symbol **) iter.currentValue();
               if( param->isParam() ) {
                  if ( first ) {
                     first = false;
                     m_out->writeString( " " );
                  }
                  else
                     m_out->writeString( ", " );

                  m_out->writeString( param->name() );
               }

               iter.next();
            }
         }
         m_out->writeString( " )\n" );

         if( func->hasStatic() ) {
            m_out->writeString( "STATIC:\n" );
            gen_block( func->staticBlock(), 1 );
         }

         gen_block( func->statements(), 1 );

         func = static_cast<const StmtFunction *>(func->next());
      }
      m_out->writeString( "\n" );
   }

   m_out->writeString( "CODE:\n" );
   gen_block( st->statements(), 0 );
}
Exemple #3
0
bool LineMap::save( Stream *out ) const
{
   uint32 s = endianInt32(size());
   out->write(  &s , sizeof( s ) );
   MapIterator iter = begin();
   while( iter.hasCurrent() )
   {

      s = endianInt32( *(uint32 *) iter.currentKey() );
      out->write(  &s , sizeof( s ) );
      s = endianInt32( *(uint32 *) iter.currentValue() );
      out->write(  &s , sizeof( s ) );
      iter.next();
   }

   return true;
}
Exemple #4
0
void GenTree::generate( const Statement *cmp, const char *specifier, bool sameline, int depth )
{

   if ( ! sameline ) {
      String line;
      line.writeNumber( (int64) cmp->line() );
      int pos = 0;
      while (pos + line.length() < 5 ) {
         pos ++;
         m_out->writeString( " " );
      }

      m_out->writeString( line + " : " );

      for (int i = 0; i < depth; i++ )
         m_out->writeString( " " );
   }

   if ( specifier != 0 ) {
      m_out->writeString( specifier );
      m_out->writeString( " " );
   }

   switch( cmp->type() )
   {
      case Statement::t_none: m_out->writeString( "(placeholder none statement)\n" ); break;
      case Statement::t_break: m_out->writeString( "BREAK\n" ); break;
      case Statement::t_continue:
         m_out->writeString( "CONTINUE" );
         if( static_cast< const StmtContinue *>( cmp )->dropping() )
            m_out->writeString( " DROPPING" );
         m_out->writeString( "\n" );
         break;

      case Statement::t_launch:
         m_out->writeString( "LAUNCH " );
         gen_value( static_cast< const StmtExpression *>( cmp )->value() );
         m_out->writeString( "\n" );
      break;

      case Statement::t_autoexp:
         m_out->writeString( "AUTOEXPR " );
         gen_value( static_cast< const StmtExpression *>( cmp )->value() );
         m_out->writeString( "\n" );
      break;

      case Statement::t_return:
         m_out->writeString( "RETURN " );
         gen_value( static_cast< const StmtExpression *>( cmp )->value() );
         m_out->writeString( "\n" );
      break;

      case Statement::t_fordot:
         m_out->writeString( "FORDOT " );
         gen_value( static_cast< const StmtExpression *>( cmp )->value() );
         m_out->writeString( "\n" );
      break;

      case Statement::t_raise:
         m_out->writeString( "RAISE " );
         gen_value( static_cast< const StmtExpression *>( cmp )->value() );
         m_out->writeString( "\n" );
      break;

      case Statement::t_give:
      {
         const StmtGive *give = static_cast< const StmtGive *>( cmp );
         m_out->writeString( "GIVE " );
         gen_array( give->attributes() );
         m_out->writeString( " to " );
         gen_array( give->objects() );
         m_out->writeString( "\n" );
      }
      break;

      case Statement::t_self_print:
      {
         const StmtSelfPrint *sp = static_cast< const StmtSelfPrint *>( cmp );

         m_out->writeString( "FAST PRINT " );

         gen_array( sp->toPrint() );
         m_out->writeString( "\n" );
      }
      break;

      case Statement::t_if:
      {
         m_out->writeString( "IF " );
         const StmtIf *sif = static_cast< const StmtIf *>( cmp );
         gen_value( sif->condition() );
         m_out->writeString( "\n" );
         gen_block( sif->children(), depth );
         const Statement *stmt = sif->elifChildren().front();
         while( stmt != 0 ) {
            generate( stmt, 0, false, depth + 1 );
            stmt = static_cast<const Statement *>(stmt->next());
         }
         gen_block( sif->elseChildren(), depth, "ELSE" );
      }
      break;

      case Statement::t_select:
      case Statement::t_switch:
      {
         if ( cmp->type() == Statement::t_switch )
            m_out->writeString( "SWITCH " );
         else
            m_out->writeString( "SELECT " );

         const StmtSwitch *sw = static_cast< const StmtSwitch *>( cmp );
         gen_value( sw->switchItem() );
         m_out->writeString( "\n" );

         // generates the switch lists
         MapIterator iter;

         // generatest the switch integer list
         if ( !sw->intCases().empty() )
         {
            m_out->writeString( "INT cases " );
            iter = sw->intCases().begin();
            while( iter.hasCurrent() )
            {
               Value *first = *(Value **) iter.currentKey();
               uint32 second = *(uint32 *) iter.currentValue();
               String temp;
               temp.writeNumber( (int64) second );

               gen_value( first );
               m_out->writeString( "->" + temp + "; " );
               iter.next();
            }
            m_out->writeString( "\n" );
         }

         if ( !sw->rngCases().empty() )
         {
            m_out->writeString( "RANGE cases " );
            iter = sw->rngCases().begin();
            while( iter.hasCurrent() )
            {
               Value *first = *(Value **) iter.currentKey();
               uint32 second = *(uint32 *) iter.currentValue();
               String temp;
               temp.writeNumber( (int64) second );

               gen_value( first );
               m_out->writeString( "->" + temp + "; " );
               iter.next();
            }
            m_out->writeString( "\n" );
         }

         if ( !sw->strCases().empty() )
         {
            m_out->writeString( "STRING cases " );
            iter = sw->strCases().begin();
            while( iter.hasCurrent() )
            {
               Value *first = *(Value **) iter.currentKey();
               uint32 second = *(uint32 *) iter.currentValue();
               String temp;
               temp.writeNumber( (int64) second );

               gen_value( first );
               m_out->writeString( "->" + temp + "; " );
               iter.next();
            }
            m_out->writeString( "\n" );
         }

         if ( !sw->objCases().empty() )
         {
            m_out->writeString( "Symbol cases " );
            iter = sw->objCases().begin();
            while( iter.hasCurrent() )
            {
               Value *first = *(Value **) iter.currentKey();
               uint32 second = *(uint32 *) iter.currentValue();
               String temp;
               temp.writeNumber( (int64) second );

               gen_value( first );
               m_out->writeString( "->" + temp + "; " );
               iter.next();
            }
            m_out->writeString( "\n" );
         }


         // generates the blocks
         int blockId = 0;
         const Statement *stmt = sw->blocks().front();
         while( stmt != 0 ) {
            String blockStr;
            blockStr.writeNumber( (int64) blockId );
            if( blockId == sw->nilBlock() )
               m_out->writeString( "CASE BLOCK (NIL)" + blockStr + "\n" );
            else
               m_out->writeString( "CASE BLOCK " + blockStr + "\n" );

            generate( stmt, 0, false, depth + 1 );
            stmt = static_cast<const Statement *>(stmt->next());
            blockId ++ ;
         }
         if ( ! sw->defaultBlock().empty() )
         {
            m_out->writeString( "DEFAULT BLOCK\n" );
            gen_block( sw->defaultBlock(), depth + 1 );
         }

      }
      break;

      case Statement::t_case:
      {
         //m_out->writeString( "CASE \n" );
         const StmtCaseBlock *scase = static_cast< const StmtCaseBlock *>( cmp );
         gen_block( scase->children(), depth );
      }
      break;

      case Statement::t_catch:
      {
         //m_out->writeString( "CASE \n" );
         const StmtCatchBlock *scase = static_cast< const StmtCatchBlock *>( cmp );
         if ( scase->intoValue() != 0 )
         {
            m_out->writeString( "CATCH into " );
            gen_value( scase->intoValue() );
            m_out->writeString( "\n" );
         }
         else
            m_out->writeString( "CATCH witout into\n" );

         gen_block( scase->children(), depth );
      }
      break;

      case Statement::t_elif:
      {
         m_out->writeString( "ELIF " );
         const StmtElif *selif = static_cast< const StmtElif *>( cmp );
         gen_value( selif->condition() );
         m_out->writeString( "\n" );
         gen_block( selif->children(), depth );
      }
      break;

      case Statement::t_while:
      {

         const StmtWhile *wh = static_cast< const StmtWhile *>( cmp );
         m_out->writeString( "WHILE " );
         gen_value( wh->condition() );

         m_out->writeString( "\n" );
         gen_block( wh->children(), depth );
      }
      break;

      case Statement::t_loop:
      {
         const StmtLoop *wh = static_cast< const StmtLoop *>( cmp );
         m_out->writeString( "LOOP " );
         m_out->writeString( "\n" );
         gen_block( wh->children(), depth );

         if( wh->condition() != 0 )
         {
            m_out->writeString( "END LOOP WHEN " );
            gen_value( wh->condition() );
            m_out->writeString( "\n" );
         }
         else
            m_out->writeString( "END\n" );
      }
      break;

      case Statement::t_global:
      {
         m_out->writeString( "GLOBAL " );
         const StmtGlobal *sglobal = static_cast< const StmtGlobal *>( cmp );
         ListElement *iter = sglobal->getSymbols().begin();
         while ( iter != 0 ) {
            Symbol *sym = (Symbol *) iter->data();
            m_out->writeString( sym->name() + ", " );
            iter = iter->next();
         }
         m_out->writeString( "\n" );
      }
      break;

      case Statement::t_forin:
      {
         m_out->writeString( "FOR-IN " );
         const StmtForin *sfor = static_cast< const StmtForin *>( cmp );
         gen_array( sfor->dest() );
         m_out->writeString( " IN " );
         gen_value( sfor->source() );
         m_out->writeString( "\n" );
         gen_block( sfor->children(), depth );
         gen_block( sfor->firstBlock(), depth, "FORFIRST" );
         gen_block( sfor->middleBlock(), depth, "FORMIDDLE" );
         gen_block( sfor->lastBlock(), depth, "FORLAST" );
      }
      break;

      case Statement::t_try:
      {
         m_out->writeString( "TRY\n" );
         const StmtTry *stry = static_cast< const StmtTry *>( cmp );
         gen_block( stry->children(), depth );
         // generatest the switch integer list
         if ( ! stry->intCases().empty() )
         {
            m_out->writeString( "TYPE ID CATCHES " );
            MapIterator iter = stry->intCases().begin();
            while( iter.hasCurrent() )
            {
               Value *first = *(Value **) iter.currentKey();
               uint32 second = *(uint32 *) iter.currentValue();
               String temp;
               temp.writeNumber( (int64) second );

               gen_value( first );
               m_out->writeString( "->" + temp + "; " );
               iter.next();
            }
            m_out->writeString( "\n" );
         }

         // Generates the switch symbol list
         if ( ! stry->objCases().empty() )
         {
            m_out->writeString( "SYMBOL CATCHES " );
            MapIterator  iter = stry->objCases().begin();
            while( iter.hasCurrent() )
            {
               Value *first = *(Value **) iter.currentKey();
               uint32 second = *(uint32 *) iter.currentValue();
               String temp;
               temp.writeNumber( (int64) second );

               gen_value( first );
               m_out->writeString( "->" + temp + "; " );
               iter.next();
            }
            m_out->writeString( "\n" );
         }

         // generates the blocks
         int blockId = 0;
         const Statement *stmt = stry->handlers().front();
         while( stmt != 0 ) {
            String blockStr;
            blockStr.writeNumber( (int64) blockId );
            m_out->writeString( "HANDLER BLOCK " + blockStr + "\n" );

            generate( stmt, 0, false, depth + 1 );
            stmt = static_cast<const Statement *>( stmt->next() );
            blockId ++ ;
         }

         if ( stry->defaultHandler() != 0 )
         {
            m_out->writeString( "DEFAULT HANDLER" );
            if ( stry->defaultHandler()->intoValue() != 0 ) {
               m_out->writeString( " into " );
               gen_value( stry->defaultHandler()->intoValue() );
            }
            m_out->writeString( "\n" );
            gen_block( stry->defaultHandler()->children(), depth + 1 );
         }
      }
      break;

      case Statement::t_propdef:
      {
         m_out->writeString( "PROPDEF " );
         const StmtVarDef *spd = static_cast< const StmtVarDef *>( cmp );
         m_out->writeString( *spd->name() );
         m_out->writeString( "=" );
         gen_value( spd->value() );
         m_out->writeString( "\n" );
      }
      break;


      default:
         m_out->writeString( "????\n" );
   }
}