initial import of dynamic native code for both the JIT and plugins

note: dependency resolution is not done yet!

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40607
This commit is contained in:
David Anderson
2007-03-12 07:08:05 +00:00
parent 7ab8e2027b
commit 7c06d89b00
14 changed files with 963 additions and 5 deletions
+54 -1
View File
@@ -588,6 +588,7 @@ CPluginManager::CPluginManager()
m_LoadLookup = sm_trie_create();
m_AllPluginsLoaded = false;
m_MyIdent = NULL;
m_pNativeLookup = sm_trie_create();
}
CPluginManager::~CPluginManager()
@@ -598,9 +599,9 @@ CPluginManager::~CPluginManager()
* will crash anyway. YAY
*/
sm_trie_destroy(m_LoadLookup);
sm_trie_destroy(m_pNativeLookup);
}
void CPluginManager::LoadAll_FirstPass(const char *config, const char *basedir)
{
/* First read in the database of plugin settings */
@@ -958,6 +959,7 @@ bool CPluginManager::RunSecondPass(CPlugin *pPlugin, char *error, size_t maxleng
/* Bind all extra natives */
g_Extensions.BindAllNativesToPlugin(pPlugin);
AddFakeNativesToPlugin(pPlugin);
/* Find any unbound natives
* Right now, these are not allowed
@@ -1013,6 +1015,32 @@ void CPluginManager::AddCoreNativesToPlugin(CPlugin *pPlugin)
}
}
void CPluginManager::AddFakeNativesToPlugin(CPlugin *pPlugin)
{
IPluginContext *pContext = pPlugin->GetBaseContext();
sp_nativeinfo_t native;
List<FakeNative *>::iterator iter;
FakeNative *pNative;
sp_context_t *ctx;
for (iter = m_Natives.begin(); iter != m_Natives.end(); iter++)
{
pNative = (*iter);
ctx = pNative->ctx->GetContext();
if ((ctx->flags & SPFLAG_PLUGIN_PAUSED) == SPFLAG_PLUGIN_PAUSED)
{
/* Ignore natives in paused plugins */
continue;
}
native.name = pNative->name.c_str();
native.func = pNative->func;
if (pContext->BindNative(&native) == SP_ERROR_NONE)
{
/* :TODO: add to dependency list */
}
}
}
bool CPluginManager::UnloadPlugin(IPlugin *plugin)
{
CPlugin *pPlugin = (CPlugin *)plugin;
@@ -1675,3 +1703,28 @@ void CPluginManager::_SetPauseState(CPlugin *pl, bool paused)
}
}
bool CPluginManager::AddFakeNative(IPluginFunction *pFunction, const char *name, SPVM_FAKENATIVE_FUNC func)
{
if (sm_trie_retrieve(m_pNativeLookup, name, NULL))
{
return false;
}
FakeNative *pNative = new FakeNative;
pNative->func = g_pVM->CreateFakeNative(func, pNative);
if (!pNative->func)
{
delete pNative;
return false;
}
pNative->call = pFunction;
pNative->name.assign(name);
pNative->ctx = pFunction->GetParentContext();
m_Natives.push_back(pNative);
sm_trie_insert(m_pNativeLookup, name,pNative);
return true;
}