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;
}
+18
View File
@@ -22,6 +22,7 @@
#include <sh_list.h>
#include <sh_stack.h>
#include <sh_vector.h>
#include <sh_string.h>
#include "sm_globals.h"
#include "vm/sp_vm_basecontext.h"
#include "PluginInfoDatabase.h"
@@ -232,6 +233,14 @@ private:
Trie *m_pProps;
};
struct FakeNative
{
IPluginContext *ctx;
IPluginFunction *call;
String name;
SPVM_NATIVE_FUNC func;
};
class CPluginManager :
public IPluginManager,
public SMGlobalClass,
@@ -380,6 +389,10 @@ protected:
{
return m_MyIdent;
}
public:
bool AddFakeNative(IPluginFunction *pFunction, const char *name, SPVM_FAKENATIVE_FUNC func);
private:
void AddFakeNativesToPlugin(CPlugin *pPlugin);
private:
List<IPluginsListener *> m_listeners;
List<CPlugin *> m_plugins;
@@ -389,6 +402,11 @@ private:
Trie *m_LoadLookup;
bool m_AllPluginsLoaded;
IdentityToken_t *m_MyIdent;
/* Dynamic native stuff */
List<FakeNative *> m_Natives;
Trie *m_pNativeLookup;
};
extern CPluginManager g_PluginSys;