1.1 --- a/sourcepawn/jit/sp_vm_basecontext.h Sun Jul 06 05:04:38 2008 +0000
1.2 +++ b/sourcepawn/jit/sp_vm_basecontext.h Mon Jul 07 04:56:29 2008 +0000
1.3 @@ -34,91 +34,75 @@
1.4
1.5 #include "sp_vm_api.h"
1.6 #include "sp_vm_function.h"
1.7 +#include "BaseRuntime.h"
1.8 +#include "jit_shared.h"
1.9
1.10 /**
1.11 * :TODO: Make functions allocate as a lump instead of individual allocations!
1.12 */
1.13
1.14 -extern IProfiler *sm_profiler;
1.15 -
1.16 -namespace SourcePawn
1.17 +class BaseContext : public IPluginContext
1.18 {
1.19 - class BaseContext :
1.20 - public IPluginContext,
1.21 - public IPluginDebugInfo
1.22 - {
1.23 - public:
1.24 - BaseContext(sp_context_t *ctx);
1.25 - ~BaseContext();
1.26 - public: //IPluginContext
1.27 - IVirtualMachine *GetVirtualMachine();
1.28 - sp_context_t *GetContext();
1.29 - bool IsDebugging();
1.30 - int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn);
1.31 - IPluginDebugInfo *GetDebugInfo();
1.32 - int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
1.33 - int HeapPop(cell_t local_addr);
1.34 - int HeapRelease(cell_t local_addr);
1.35 - int FindNativeByName(const char *name, uint32_t *index);
1.36 - int GetNativeByIndex(uint32_t index, sp_native_t **native);
1.37 - uint32_t GetNativesNum();
1.38 - int FindPublicByName(const char *name, uint32_t *index);
1.39 - int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
1.40 - uint32_t GetPublicsNum();
1.41 - int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
1.42 - int FindPubvarByName(const char *name, uint32_t *index);
1.43 - int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
1.44 - uint32_t GetPubVarsNum();
1.45 - int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
1.46 - int LocalToString(cell_t local_addr, char **addr);
1.47 - int StringToLocal(cell_t local_addr, size_t chars, const char *source);
1.48 - int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
1.49 - int PushCell(cell_t value);
1.50 - int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
1.51 - int PushString(cell_t *local_addr, char **phys_addr, const char *string);
1.52 - int PushCellsFromArray(cell_t array[], unsigned int numcells);
1.53 - int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
1.54 - int BindNative(const sp_nativeinfo_t *native);
1.55 - int BindNativeToAny(SPVM_NATIVE_FUNC native);
1.56 - int Execute(uint32_t code_addr, cell_t *result);
1.57 - cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
1.58 - cell_t ThrowNativeError(const char *msg, ...);
1.59 - IPluginFunction *GetFunctionByName(const char *public_name);
1.60 - IPluginFunction *GetFunctionById(funcid_t func_id);
1.61 -#if defined SOURCEMOD_BUILD
1.62 - SourceMod::IdentityToken_t *GetIdentity();
1.63 - void SetIdentity(SourceMod::IdentityToken_t *token);
1.64 - cell_t *GetNullRef(SP_NULL_TYPE type);
1.65 - int LocalToStringNULL(cell_t local_addr, char **addr);
1.66 -#endif
1.67 - int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
1.68 - public: //IPluginDebugInfo
1.69 - int LookupFile(ucell_t addr, const char **filename);
1.70 - int LookupFunction(ucell_t addr, const char **name);
1.71 - int LookupLine(ucell_t addr, uint32_t *line);
1.72 - public:
1.73 - void SetContext(sp_context_t *_ctx);
1.74 - bool IsInExec();
1.75 - private:
1.76 - void SetErrorMessage(const char *msg, va_list ap);
1.77 - void FlushFunctionCache();
1.78 - void RefreshFunctionCache();
1.79 - private:
1.80 - sp_context_t *ctx;
1.81 -#if defined SOURCEMOD_BUILD
1.82 - SourceMod::IdentityToken_t *m_pToken;
1.83 - cell_t *m_pNullVec;
1.84 - cell_t *m_pNullString;
1.85 -#endif
1.86 - char m_MsgCache[1024];
1.87 - bool m_CustomMsg;
1.88 - bool m_InExec;
1.89 - unsigned int m_funcsnum;
1.90 -#if 0
1.91 - CFunction **m_priv_funcs;
1.92 -#endif
1.93 - CFunction **m_pub_funcs;
1.94 - };
1.95 +public:
1.96 + BaseContext(BaseRuntime *pRuntime);
1.97 + ~BaseContext();
1.98 +public: //IPluginContext
1.99 + IVirtualMachine *GetVirtualMachine();
1.100 + sp_context_t *GetContext();
1.101 + bool IsDebugging();
1.102 + int SetDebugBreak(void *newpfn, void *oldpfn);
1.103 + IPluginDebugInfo *GetDebugInfo();
1.104 + int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
1.105 + int HeapPop(cell_t local_addr);
1.106 + int HeapRelease(cell_t local_addr);
1.107 + int FindNativeByName(const char *name, uint32_t *index);
1.108 + int GetNativeByIndex(uint32_t index, sp_native_t **native);
1.109 + uint32_t GetNativesNum();
1.110 + int FindPublicByName(const char *name, uint32_t *index);
1.111 + int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
1.112 + uint32_t GetPublicsNum();
1.113 + int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
1.114 + int FindPubvarByName(const char *name, uint32_t *index);
1.115 + int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
1.116 + uint32_t GetPubVarsNum();
1.117 + int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
1.118 + int LocalToString(cell_t local_addr, char **addr);
1.119 + int StringToLocal(cell_t local_addr, size_t chars, const char *source);
1.120 + int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
1.121 + int PushCell(cell_t value);
1.122 + int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
1.123 + int PushString(cell_t *local_addr, char **phys_addr, const char *string);
1.124 + int PushCellsFromArray(cell_t array[], unsigned int numcells);
1.125 + int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
1.126 + int BindNative(const sp_nativeinfo_t *native);
1.127 + int BindNativeToAny(SPVM_NATIVE_FUNC native);
1.128 + int Execute(uint32_t code_addr, cell_t *result);
1.129 + cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
1.130 + cell_t ThrowNativeError(const char *msg, ...);
1.131 + IPluginFunction *GetFunctionByName(const char *public_name);
1.132 + IPluginFunction *GetFunctionById(funcid_t func_id);
1.133 + SourceMod::IdentityToken_t *GetIdentity();
1.134 + void SetIdentity(SourceMod::IdentityToken_t *token);
1.135 + cell_t *GetNullRef(SP_NULL_TYPE type);
1.136 + int LocalToStringNULL(cell_t local_addr, char **addr);
1.137 + int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
1.138 + int Execute(IPluginFunction *function, const cell_t *params, unsigned int num_params, cell_t *result);
1.139 + IPluginRuntime *GetRuntime();
1.140 +public:
1.141 + bool IsInExec();
1.142 +private:
1.143 + void SetErrorMessage(const char *msg, va_list ap);
1.144 + void _SetErrorMessage(const char *msg, ...);
1.145 +private:
1.146 + sp_plugin_t *m_pPlugin;
1.147 + SourceMod::IdentityToken_t *m_pToken;
1.148 + cell_t *m_pNullVec;
1.149 + cell_t *m_pNullString;
1.150 + char m_MsgCache[1024];
1.151 + bool m_CustomMsg;
1.152 + bool m_InExec;
1.153 + BaseRuntime *m_pRuntime;
1.154 + sp_context_t m_ctx;
1.155 };
1.156
1.157 #endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_