1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcepawn/jit/sp_vm_basecontext.h Sun Jul 06 04:59:39 2008 +0000
1.3 @@ -0,0 +1,124 @@
1.4 +/**
1.5 + * vim: set ts=4 :
1.6 + * =============================================================================
1.7 + * SourcePawn
1.8 + * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
1.9 + * =============================================================================
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify it under
1.12 + * the terms of the GNU General Public License, version 3.0, as published by the
1.13 + * Free Software Foundation.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 + * details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License along with
1.21 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 + *
1.23 + * As a special exception, AlliedModders LLC gives you permission to link the
1.24 + * code of this program (as well as its derivative works) to "Half-Life 2," the
1.25 + * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.26 + * by the Valve Corporation. You must obey the GNU General Public License in
1.27 + * all respects for all other code used. Additionally, AlliedModders LLC grants
1.28 + * this exception to all derivative works. AlliedModders LLC defines further
1.29 + * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.30 + * or <http://www.sourcemod.net/license.php>.
1.31 + *
1.32 + * Version: $Id$
1.33 + */
1.34 +
1.35 +#ifndef _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
1.36 +#define _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
1.37 +
1.38 +#include "sp_vm_api.h"
1.39 +#include "sp_vm_function.h"
1.40 +
1.41 +/**
1.42 + * :TODO: Make functions allocate as a lump instead of individual allocations!
1.43 + */
1.44 +
1.45 +extern IProfiler *sm_profiler;
1.46 +
1.47 +namespace SourcePawn
1.48 +{
1.49 + class BaseContext :
1.50 + public IPluginContext,
1.51 + public IPluginDebugInfo
1.52 + {
1.53 + public:
1.54 + BaseContext(sp_context_t *ctx);
1.55 + ~BaseContext();
1.56 + public: //IPluginContext
1.57 + IVirtualMachine *GetVirtualMachine();
1.58 + sp_context_t *GetContext();
1.59 + bool IsDebugging();
1.60 + int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn);
1.61 + IPluginDebugInfo *GetDebugInfo();
1.62 + int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
1.63 + int HeapPop(cell_t local_addr);
1.64 + int HeapRelease(cell_t local_addr);
1.65 + int FindNativeByName(const char *name, uint32_t *index);
1.66 + int GetNativeByIndex(uint32_t index, sp_native_t **native);
1.67 + uint32_t GetNativesNum();
1.68 + int FindPublicByName(const char *name, uint32_t *index);
1.69 + int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
1.70 + uint32_t GetPublicsNum();
1.71 + int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
1.72 + int FindPubvarByName(const char *name, uint32_t *index);
1.73 + int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
1.74 + uint32_t GetPubVarsNum();
1.75 + int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
1.76 + int LocalToString(cell_t local_addr, char **addr);
1.77 + int StringToLocal(cell_t local_addr, size_t chars, const char *source);
1.78 + int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
1.79 + int PushCell(cell_t value);
1.80 + int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
1.81 + int PushString(cell_t *local_addr, char **phys_addr, const char *string);
1.82 + int PushCellsFromArray(cell_t array[], unsigned int numcells);
1.83 + int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
1.84 + int BindNative(const sp_nativeinfo_t *native);
1.85 + int BindNativeToAny(SPVM_NATIVE_FUNC native);
1.86 + int Execute(uint32_t code_addr, cell_t *result);
1.87 + cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
1.88 + cell_t ThrowNativeError(const char *msg, ...);
1.89 + IPluginFunction *GetFunctionByName(const char *public_name);
1.90 + IPluginFunction *GetFunctionById(funcid_t func_id);
1.91 +#if defined SOURCEMOD_BUILD
1.92 + SourceMod::IdentityToken_t *GetIdentity();
1.93 + void SetIdentity(SourceMod::IdentityToken_t *token);
1.94 + cell_t *GetNullRef(SP_NULL_TYPE type);
1.95 + int LocalToStringNULL(cell_t local_addr, char **addr);
1.96 +#endif
1.97 + int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
1.98 + public: //IPluginDebugInfo
1.99 + int LookupFile(ucell_t addr, const char **filename);
1.100 + int LookupFunction(ucell_t addr, const char **name);
1.101 + int LookupLine(ucell_t addr, uint32_t *line);
1.102 + public:
1.103 + void SetContext(sp_context_t *_ctx);
1.104 + bool IsInExec();
1.105 + private:
1.106 + void SetErrorMessage(const char *msg, va_list ap);
1.107 + void FlushFunctionCache();
1.108 + void RefreshFunctionCache();
1.109 + private:
1.110 + sp_context_t *ctx;
1.111 +#if defined SOURCEMOD_BUILD
1.112 + SourceMod::IdentityToken_t *m_pToken;
1.113 + cell_t *m_pNullVec;
1.114 + cell_t *m_pNullString;
1.115 +#endif
1.116 + char m_MsgCache[1024];
1.117 + bool m_CustomMsg;
1.118 + bool m_InExec;
1.119 + unsigned int m_funcsnum;
1.120 +#if 0
1.121 + CFunction **m_priv_funcs;
1.122 +#endif
1.123 + CFunction **m_pub_funcs;
1.124 + };
1.125 +};
1.126 +
1.127 +#endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_