00001 /* 00002 FALCON - The Falcon Programming Language. 00003 FILE: flc_runtime.h 00004 00005 Short description 00006 ------------------------------------------------------------------- 00007 Author: Giancarlo Niccolai 00008 Begin: mer ago 18 2004 00009 00010 ------------------------------------------------------------------- 00011 (C) Copyright 2004: the FALCON developers (see list in AUTHORS file) 00012 00013 See LICENSE file for licensing details. 00014 */ 00015 00016 00017 #ifndef flc_RUNTIME_H 00018 #define flc_RUNTIME_H 00019 00020 #include <falcon/setup.h> 00021 #include <falcon/modloader.h> 00022 #include <falcon/common.h> 00023 #include <falcon/genericvector.h> 00024 #include <falcon/genericmap.h> 00025 #include <falcon/basealloc.h> 00026 00027 namespace Falcon { 00028 00029 class VMachine; 00030 00038 class ModuleDep: public BaseAlloc 00039 { 00040 Module *m_module; 00041 bool m_bIsPrivate; 00042 public: 00043 00044 ModuleDep( Module *mod, bool priv = false ): 00045 m_module( mod ), 00046 m_bIsPrivate( priv ) 00047 { 00048 mod->incref(); 00049 } 00050 00051 ~ModuleDep() { m_module->decref(); } 00052 00053 Module *module() const { return m_module; } 00054 bool isPrivate() const { return m_bIsPrivate; } 00055 void setPrivate( bool mode ) { m_bIsPrivate = mode; } 00056 }; 00057 00061 class FALCON_DYN_CLASS ModuleMap: public Map 00062 { 00063 public: 00064 ModuleMap(); 00065 }; 00066 00072 class FALCON_DYN_CLASS ModuleVector: public GenericVector 00073 { 00074 public: 00075 ModuleVector(); 00076 Module *moduleAt( uint32 pos ) const { return (*(ModuleDep**) at(pos))->module(); } 00077 ModuleDep *moduleDepAt( uint32 pos ) const { return *(ModuleDep**) at(pos); } 00078 }; 00079 00107 class FALCON_DYN_CLASS Runtime: public BaseAlloc 00108 { 00109 ModuleMap m_modules; 00110 ModuleVector m_modvect; 00111 ModuleLoader *m_loader; 00112 VMachine *m_provider; 00113 Map m_modPending; 00114 bool m_hasMainModule; 00115 00116 public: 00117 00138 Runtime( ModuleLoader *loader, VMachine *provider = 0 ); 00139 00140 00157 Runtime(); 00158 00165 ~Runtime(); 00166 00172 bool willLoad() { return m_loader != 0 ; } 00173 00190 void addModule( Module *mod, bool bIsPrivate = false ); 00191 00203 const ModuleMap *moduleMap() const { return &m_modules; } 00204 00206 const ModuleVector *moduleVector() const { return &m_modvect; } 00207 00211 Module *findModule( const String &name ) 00212 { 00213 ModuleDep **modp = (ModuleDep **) m_modules.find( &name ); 00214 if ( modp != 0 ) 00215 return (*modp)->module(); 00216 return 0; 00217 } 00218 00220 Module *findModuleByID( uint32 id ) { 00221 return m_modvect.moduleAt( id ); 00222 } 00223 00225 uint32 size() { return m_modvect.size(); } 00226 00227 00238 void loadName( const String &name, const String &parent = "", bool bIsPrivate=false ); 00239 00250 void loadFile( const String &file, bool bIsPrivate=false ); 00251 00256 bool hasPendingModules() const { return ! m_modPending.empty(); } 00257 00261 bool hasMainModule() const { return m_hasMainModule; } 00262 00274 void hasMainModule( bool b ) { m_hasMainModule = b; } 00275 }; 00276 00277 00278 } 00279 00280 #endif 00281 00282 /* end of flc_runtime.h */