1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/sourcepawn/jit/sp_vm_basecontext.h Fri Jul 11 08:18:43 2008 +0000
1.3 @@ -0,0 +1,114 @@
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 +#include "BaseRuntime.h"
1.41 +#include "jit_shared.h"
1.42 +
1.43 +/**
1.44 + * :TODO: Make functions allocate as a lump instead of individual allocations!
1.45 + */
1.46 +
1.47 +class BaseContext : public IPluginContext
1.48 +{
1.49 +public:
1.50 + BaseContext(BaseRuntime *pRuntime);
1.51 + ~BaseContext();
1.52 +public: //IPluginContext
1.53 + IVirtualMachine *GetVirtualMachine();
1.54 + sp_context_t *GetContext();
1.55 + sp_context_t *GetCtx();
1.56 + bool IsDebugging();
1.57 + int SetDebugBreak(void *newpfn, void *oldpfn);
1.58 + IPluginDebugInfo *GetDebugInfo();
1.59 + int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
1.60 + int HeapPop(cell_t local_addr);
1.61 + int HeapRelease(cell_t local_addr);
1.62 + int FindNativeByName(const char *name, uint32_t *index);
1.63 + int GetNativeByIndex(uint32_t index, sp_native_t **native);
1.64 + uint32_t GetNativesNum();
1.65 + int FindPublicByName(const char *name, uint32_t *index);
1.66 + int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
1.67 + uint32_t GetPublicsNum();
1.68 + int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
1.69 + int FindPubvarByName(const char *name, uint32_t *index);
1.70 + int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
1.71 + uint32_t GetPubVarsNum();
1.72 + int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
1.73 + int LocalToString(cell_t local_addr, char **addr);
1.74 + int StringToLocal(cell_t local_addr, size_t chars, const char *source);
1.75 + int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
1.76 + int PushCell(cell_t value);
1.77 + int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
1.78 + int PushString(cell_t *local_addr, char **phys_addr, const char *string);
1.79 + int PushCellsFromArray(cell_t array[], unsigned int numcells);
1.80 + int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
1.81 + int BindNative(const sp_nativeinfo_t *native);
1.82 + int BindNativeToAny(SPVM_NATIVE_FUNC native);
1.83 + int Execute(uint32_t code_addr, cell_t *result);
1.84 + cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
1.85 + cell_t ThrowNativeError(const char *msg, ...);
1.86 + IPluginFunction *GetFunctionByName(const char *public_name);
1.87 + IPluginFunction *GetFunctionById(funcid_t func_id);
1.88 + SourceMod::IdentityToken_t *GetIdentity();
1.89 + cell_t *GetNullRef(SP_NULL_TYPE type);
1.90 + int LocalToStringNULL(cell_t local_addr, char **addr);
1.91 + int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
1.92 + int Execute2(IPluginFunction *function, const cell_t *params, unsigned int num_params, cell_t *result);
1.93 + IPluginRuntime *GetRuntime();
1.94 + int GetLastNativeError();
1.95 + cell_t *GetLocalParams();
1.96 + void SetKey(int k, void *value);
1.97 + bool GetKey(int k, void **value);
1.98 + void Refresh();
1.99 +public:
1.100 + bool IsInExec();
1.101 +private:
1.102 + void SetErrorMessage(const char *msg, va_list ap);
1.103 + void _SetErrorMessage(const char *msg, ...);
1.104 +private:
1.105 + sp_plugin_t *m_pPlugin;
1.106 + cell_t *m_pNullVec;
1.107 + cell_t *m_pNullString;
1.108 + char m_MsgCache[1024];
1.109 + bool m_CustomMsg;
1.110 + bool m_InExec;
1.111 + BaseRuntime *m_pRuntime;
1.112 + sp_context_t m_ctx;
1.113 + void *m_keys[4];
1.114 + bool m_keys_set[4];
1.115 +};
1.116 +
1.117 +#endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_