Logo Search packages:      
Sourcecode: falconpl version File versions  Download package

bool Falcon::VMachine::prepare ( const String startSym,
uint32  paramCount = 0 
)

Prepares a routine. The launch() method calls prepare() and run() in succession. A debugging environment should call prepare() and then singleStep() iteratively.

Todo:
allow to call classes at startup. Something like "all-classes" a-la-java

Definition at line 859 of file vm.cpp.

References Falcon::Module::code(), Falcon::Symbol::declaredAt(), Falcon::Map::find(), Falcon::Module::findGlobalSymbol(), Falcon::Symbol::getFuncDef(), Falcon::LiveModule::globals(), Falcon::Symbol::isFunction(), Falcon::SymModule::liveModule(), Falcon::FuncDef::locals(), m_code, m_currentGlobals, m_currentModule, m_globalSyms, m_mainModule, m_pc, m_stack, m_symbol, Falcon::Symbol::module(), Falcon::LiveModule::module(), Falcon::Module::name(), Falcon::Symbol::name(), Falcon::FuncDef::offset(), Falcon::FuncDef::params(), raiseError(), reset(), and Falcon::SymModule::symbol().

{

   // we must have at least one module.
   LiveModule *curMod;

   if( m_mainModule == 0 ) {
      // I don't want an assertion, as it may be removed in optimized compilation
      // while the calling app must still be warned.
      m_symbol = 0;
      return false;
   }

   Symbol *execSym = m_mainModule->module()->findGlobalSymbol( startSym );
   if ( execSym == 0 )
   {
      SymModule *it_global = (SymModule *) m_globalSyms.find( &startSym );
      if( it_global == 0 ) {
         m_symbol = 0;
         raiseError( new CodeError(
            ErrorParam( e_undef_sym ).origin( e_orig_vm ).extra( startSym ).
            symbol( "prepare" ).
            module( "core.vm" ) )
            );
         return false;
      }
      else {
         execSym =  it_global->symbol();
         curMod = it_global->liveModule();
      }
   }
   else
      curMod = m_mainModule; // module position

   /** \todo allow to call classes at startup. Something like "all-classes" a-la-java */
   if ( ! execSym->isFunction() ) {
      raiseError( new CodeError(
            ErrorParam( e_non_callable, execSym->declaredAt() ).origin( e_orig_vm ).
            symbol( execSym->name() ).
            module( execSym->module()->name() ) )
            );
      return false;
   }

   // ok, let's setup execution environment.
   const Module *mod = execSym->module();
   m_code = mod->code();
      FuncDef *tg_def = execSym->getFuncDef();
   m_pc = tg_def->offset();
   m_symbol = execSym;
   m_currentGlobals = &curMod->globals();
   m_currentModule = curMod->module();

   // reset the VM to ready it for execution
   reset();

      // manage an internal function
   // ensure against optional parameters.
   if( paramCount < tg_def->params() )
   {
      m_stack->resize( tg_def->params() - paramCount );
      paramCount = tg_def->params();
   }

      // space for locals
   if ( tg_def->locals() > 0 )
      m_stack->resize( tg_def->locals() );

   return true;
}


Generated by  Doxygen 1.6.0   Back to index