sourcepawn/jit/sp_vm_basecontext.h
author David Anderson <dvander@alliedmods.net>
Mon Jul 07 04:56:29 2008 +0000 (2008-07-07)
branchrefac-jit
changeset 2171 0885b66fcf81
parent 2169 d1e225d141fb
child 2173 c38e83232dcc
permissions -rw-r--r--
refac-jit is almost done i think, next comes getting core compatible.
dvander@2168
     1
/**
dvander@2168
     2
 * vim: set ts=4 :
dvander@2168
     3
 * =============================================================================
dvander@2168
     4
 * SourcePawn
dvander@2168
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
dvander@2168
     6
 * =============================================================================
dvander@2168
     7
 *
dvander@2168
     8
 * This program is free software; you can redistribute it and/or modify it under
dvander@2168
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
dvander@2168
    10
 * Free Software Foundation.
dvander@2168
    11
 * 
dvander@2168
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
dvander@2168
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
dvander@2168
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
dvander@2168
    15
 * details.
dvander@2168
    16
 *
dvander@2168
    17
 * You should have received a copy of the GNU General Public License along with
dvander@2168
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@2168
    19
 *
dvander@2168
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
dvander@2168
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
dvander@2168
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
dvander@2168
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
dvander@2168
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
dvander@2168
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
dvander@2168
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
dvander@2168
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@2168
    28
 *
dvander@2168
    29
 * Version: $Id$
dvander@2168
    30
 */
dvander@2168
    31
dvander@2168
    32
#ifndef _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
dvander@2168
    33
#define _INCLUDE_SOURCEPAWN_BASECONTEXT_H_
dvander@2168
    34
dvander@2168
    35
#include "sp_vm_api.h"
dvander@2168
    36
#include "sp_vm_function.h"
dvander@2171
    37
#include "BaseRuntime.h"
dvander@2171
    38
#include "jit_shared.h"
dvander@2168
    39
dvander@2168
    40
/**
dvander@2168
    41
 * :TODO: Make functions allocate as a lump instead of individual allocations!
dvander@2168
    42
 */
dvander@2168
    43
dvander@2171
    44
class BaseContext : public IPluginContext
dvander@2168
    45
{
dvander@2171
    46
public:
dvander@2171
    47
	BaseContext(BaseRuntime *pRuntime);
dvander@2171
    48
	~BaseContext();
dvander@2171
    49
public: //IPluginContext
dvander@2171
    50
	IVirtualMachine *GetVirtualMachine();
dvander@2171
    51
	sp_context_t *GetContext();
dvander@2171
    52
	bool IsDebugging();
dvander@2171
    53
	int SetDebugBreak(void *newpfn, void *oldpfn);
dvander@2171
    54
	IPluginDebugInfo *GetDebugInfo();
dvander@2171
    55
	int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr);
dvander@2171
    56
	int HeapPop(cell_t local_addr);
dvander@2171
    57
	int HeapRelease(cell_t local_addr);
dvander@2171
    58
	int FindNativeByName(const char *name, uint32_t *index);
dvander@2171
    59
	int GetNativeByIndex(uint32_t index, sp_native_t **native);
dvander@2171
    60
	uint32_t GetNativesNum();
dvander@2171
    61
	int FindPublicByName(const char *name, uint32_t *index);
dvander@2171
    62
	int GetPublicByIndex(uint32_t index, sp_public_t **publicptr);
dvander@2171
    63
	uint32_t GetPublicsNum();
dvander@2171
    64
	int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar);
dvander@2171
    65
	int FindPubvarByName(const char *name, uint32_t *index);
dvander@2171
    66
	int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr);
dvander@2171
    67
	uint32_t GetPubVarsNum();
dvander@2171
    68
	int LocalToPhysAddr(cell_t local_addr, cell_t **phys_addr);
dvander@2171
    69
	int LocalToString(cell_t local_addr, char **addr);
dvander@2171
    70
	int StringToLocal(cell_t local_addr, size_t chars, const char *source);
dvander@2171
    71
	int StringToLocalUTF8(cell_t local_addr, size_t maxbytes, const char *source, size_t *wrtnbytes);
dvander@2171
    72
	int PushCell(cell_t value);
dvander@2171
    73
	int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells);
dvander@2171
    74
	int PushString(cell_t *local_addr, char **phys_addr, const char *string);
dvander@2171
    75
	int PushCellsFromArray(cell_t array[], unsigned int numcells);
dvander@2171
    76
	int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite);
dvander@2171
    77
	int BindNative(const sp_nativeinfo_t *native);
dvander@2171
    78
	int BindNativeToAny(SPVM_NATIVE_FUNC native);
dvander@2171
    79
	int Execute(uint32_t code_addr, cell_t *result);
dvander@2171
    80
	cell_t ThrowNativeErrorEx(int error, const char *msg, ...);
dvander@2171
    81
	cell_t ThrowNativeError(const char *msg, ...);
dvander@2171
    82
	IPluginFunction *GetFunctionByName(const char *public_name);
dvander@2171
    83
	IPluginFunction *GetFunctionById(funcid_t func_id);
dvander@2171
    84
	SourceMod::IdentityToken_t *GetIdentity();
dvander@2171
    85
	void SetIdentity(SourceMod::IdentityToken_t *token);
dvander@2171
    86
	cell_t *GetNullRef(SP_NULL_TYPE type);
dvander@2171
    87
	int LocalToStringNULL(cell_t local_addr, char **addr);
dvander@2171
    88
	int BindNativeToIndex(uint32_t index, SPVM_NATIVE_FUNC native);
dvander@2171
    89
	int Execute(IPluginFunction *function, const cell_t *params, unsigned int num_params, cell_t *result);
dvander@2171
    90
	IPluginRuntime *GetRuntime();
dvander@2171
    91
public:
dvander@2171
    92
	bool IsInExec();
dvander@2171
    93
private:
dvander@2171
    94
	void SetErrorMessage(const char *msg, va_list ap);
dvander@2171
    95
	void _SetErrorMessage(const char *msg, ...);
dvander@2171
    96
private:
dvander@2171
    97
	sp_plugin_t *m_pPlugin;
dvander@2171
    98
	SourceMod::IdentityToken_t *m_pToken;
dvander@2171
    99
	cell_t *m_pNullVec;
dvander@2171
   100
	cell_t *m_pNullString;
dvander@2171
   101
	char m_MsgCache[1024];
dvander@2171
   102
	bool m_CustomMsg;
dvander@2171
   103
	bool m_InExec;
dvander@2171
   104
	BaseRuntime *m_pRuntime;
dvander@2171
   105
	sp_context_t m_ctx;
dvander@2168
   106
};
dvander@2168
   107
dvander@2168
   108
#endif //_INCLUDE_SOURCEPAWN_BASECONTEXT_H_