public/sourcepawn/sp_vm_types.h
author Paul Clothier <wazzled08@gmail.com>
Thu Sep 15 18:43:33 2011 -0400 (2011-09-15)
changeset 3391 4f2025d7af52
parent 2289 44045ead61cd
child 3977 fca2b54741ca
permissions -rw-r--r--
Updated TF2 SetPowerplayEnabled gamedata (bug 5095, r=psychonic).
dvander@372
     1
/**
dvander@375
     2
 * vim: set ts=4 :
ds@1330
     3
 * =============================================================================
dvander@1231
     4
 * SourcePawn
ds@1947
     5
 * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
ds@1330
     6
 * =============================================================================
dvander@372
     7
 *
ds@1330
     8
 * This program is free software; you can redistribute it and/or modify it under
ds@1330
     9
 * the terms of the GNU General Public License, version 3.0, as published by the
ds@1330
    10
 * Free Software Foundation.
dvander@379
    11
 * 
ds@1330
    12
 * This program is distributed in the hope that it will be useful, but WITHOUT
ds@1330
    13
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
ds@1330
    14
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
ds@1330
    15
 * details.
dvander@1231
    16
 *
ds@1330
    17
 * You should have received a copy of the GNU General Public License along with
ds@1330
    18
 * this program.  If not, see <http://www.gnu.org/licenses/>.
dvander@1231
    19
 *
ds@1330
    20
 * As a special exception, AlliedModders LLC gives you permission to link the
ds@1330
    21
 * code of this program (as well as its derivative works) to "Half-Life 2," the
ds@1330
    22
 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
ds@1330
    23
 * by the Valve Corporation.  You must obey the GNU General Public License in
ds@1330
    24
 * all respects for all other code used.  Additionally, AlliedModders LLC grants
ds@1330
    25
 * this exception to all derivative works.  AlliedModders LLC defines further
ds@1330
    26
 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
ds@1330
    27
 * or <http://www.sourcemod.net/license.php>.
dvander@372
    28
 *
dvander@372
    29
 * Version: $Id$
dvander@372
    30
 */
dvander@372
    31
dvander@324
    32
#ifndef _INCLUDE_SOURCEPAWN_VM_TYPES_H
dvander@324
    33
#define _INCLUDE_SOURCEPAWN_VM_TYPES_H
dvander@324
    34
dvander@372
    35
/**
dvander@372
    36
 * @file sp_vm_types.h
dvander@372
    37
 * @brief Contains all run-time SourcePawn structures.
dvander@372
    38
 */
dvander@372
    39
dvander@324
    40
#include "sp_file_headers.h"
dvander@324
    41
dvander@372
    42
typedef	uint32_t	ucell_t;			/**< Unsigned 32bit integer */
dvander@372
    43
typedef int32_t		cell_t;				/**< Basic 32bit signed integer type for plugins */
dvander@372
    44
typedef uint32_t	funcid_t;			/**< Function index code */
dvander@324
    45
dvander@324
    46
#include "sp_typeutil.h"
dvander@324
    47
dvander@372
    48
#define SP_MAX_EXEC_PARAMS				32	/**< Maximum number of parameters in a function */
dvander@324
    49
dvander@1908
    50
#define SP_JITCONF_DEBUG		"debug"		/**< Configuration option for debugging. */
dvander@1908
    51
#define SP_JITCONF_PROFILE		"profile"	/**< Configuration option for profiling. */
dvander@1908
    52
dvander@1908
    53
#define SP_PROF_NATIVES			(1<<0)		/**< Profile natives. */
dvander@1908
    54
#define SP_PROF_CALLBACKS		(1<<1)		/**< Profile callbacks. */
dvander@1908
    55
#define SP_PROF_FUNCTIONS		(1<<2)		/**< Profile functions. */
dvander@1908
    56
dvander@324
    57
/**
dvander@372
    58
 * @brief Error codes for SourcePawn routines.
dvander@324
    59
 */
dvander@372
    60
#define SP_ERROR_NONE					0	/**< No error occurred */
dvander@372
    61
#define SP_ERROR_FILE_FORMAT			1	/**< File format unrecognized */
dvander@372
    62
#define SP_ERROR_DECOMPRESSOR			2	/**< A decompressor was not found */
dvander@372
    63
#define SP_ERROR_HEAPLOW				3	/**< Not enough space left on the heap */
dvander@372
    64
#define SP_ERROR_PARAM					4	/**< Invalid parameter or parameter type */
dvander@372
    65
#define SP_ERROR_INVALID_ADDRESS		5	/**< A memory address was not valid */
dvander@372
    66
#define SP_ERROR_NOT_FOUND				6	/**< The object in question was not found */
dvander@372
    67
#define SP_ERROR_INDEX					7	/**< Invalid index parameter */
ds@729
    68
#define SP_ERROR_STACKLOW				8	/**< Not enough space left on the stack */
dvander@372
    69
#define SP_ERROR_NOTDEBUGGING			9	/**< Debug mode was not on or debug section not found */
dvander@372
    70
#define SP_ERROR_INVALID_INSTRUCTION	10	/**< Invalid instruction was encountered */
dvander@372
    71
#define SP_ERROR_MEMACCESS				11	/**< Invalid memory access */
dvander@372
    72
#define SP_ERROR_STACKMIN				12	/**< Stack went beyond its minimum value */
dvander@372
    73
#define SP_ERROR_HEAPMIN				13  /**< Heap went beyond its minimum value */
dvander@372
    74
#define SP_ERROR_DIVIDE_BY_ZERO			14	/**< Division by zero */
dvander@372
    75
#define SP_ERROR_ARRAY_BOUNDS			15	/**< Array index is out of bounds */
dvander@372
    76
#define SP_ERROR_INSTRUCTION_PARAM		16	/**< Instruction had an invalid parameter */
dvander@372
    77
#define SP_ERROR_STACKLEAK				17  /**< A native leaked an item on the stack */
dvander@372
    78
#define SP_ERROR_HEAPLEAK				18  /**< A native leaked an item on the heap */
dvander@372
    79
#define SP_ERROR_ARRAY_TOO_BIG			19	/**< A dynamic array is too big */
dvander@372
    80
#define SP_ERROR_TRACKER_BOUNDS			20	/**< Tracker stack is out of bounds */
dvander@372
    81
#define SP_ERROR_INVALID_NATIVE			21	/**< Native was pending or invalid */
dvander@372
    82
#define SP_ERROR_PARAMS_MAX				22	/**< Maximum number of parameters reached */
dvander@372
    83
#define SP_ERROR_NATIVE					23	/**< Error originates from a native */
dvander@372
    84
#define SP_ERROR_NOT_RUNNABLE			24	/**< Function or plugin is not runnable */
dvander@560
    85
#define SP_ERROR_ABORTED				25	/**< Function call was aborted */
dvander@2226
    86
#define SP_ERROR_CODE_TOO_OLD			26	/**< Code is too old for this VM */
dvander@2226
    87
#define SP_ERROR_CODE_TOO_NEW			27	/**< Code is too new for this VM */
dvander@372
    88
//Hey you! Update the string table if you add to the end of me! */
dvander@324
    89
dvander@324
    90
/**********************************************
dvander@324
    91
 *** The following structures are reference structures.
dvander@324
    92
 *** They are not essential to the API, but are used
dvander@324
    93
 ***  to hold the back end database format of the plugin
dvander@324
    94
 ***  binary.
dvander@324
    95
 **********************************************/
dvander@324
    96
dvander@324
    97
namespace SourcePawn
dvander@324
    98
{
dvander@324
    99
	class IPluginContext;
dvander@324
   100
	class IVirtualMachine;
dvander@1908
   101
	class IProfiler;
dvander@324
   102
};
dvander@324
   103
dvander@324
   104
struct sp_context_s;
dvander@324
   105
dvander@372
   106
/**
dvander@372
   107
 * @brief Native callback prototype, passed a context and a parameter stack (0=count, 1+=args).  
dvander@372
   108
 * A cell must be returned.
dvander@372
   109
 */
dvander@324
   110
typedef cell_t (*SPVM_NATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *);
dvander@324
   111
dvander@601
   112
/**
dvander@601
   113
 * @brief Fake native callback prototype, passed a context, parameter stack, and private data.
dvander@601
   114
 * A cell must be returned.
dvander@601
   115
 */
dvander@601
   116
typedef cell_t (*SPVM_FAKENATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *, void *);
dvander@601
   117
dvander@324
   118
/**********************************************
dvander@324
   119
 *** The following structures are bound to the VM/JIT.
dvander@324
   120
 *** Changing them will result in necessary recompilation.
dvander@324
   121
 **********************************************/
dvander@324
   122
dvander@324
   123
/**
dvander@372
   124
 * @brief Offsets and names to a public function.
dvander@324
   125
 */
dvander@324
   126
typedef struct sp_public_s
dvander@324
   127
{
dvander@372
   128
	funcid_t	funcid;		/**< Encoded function id */
dvander@372
   129
	uint32_t	code_offs;	/**< Relocated code offset */
dvander@372
   130
	const char *name;		/**< Name of function */
dvander@324
   131
} sp_public_t;
dvander@324
   132
dvander@324
   133
/**
dvander@372
   134
 * @brief Offsets and names to public variables.
dvander@372
   135
 *
dvander@372
   136
 * The offset is relocated and the name by default points back to the sp_plugin_infotab_t structure.
dvander@324
   137
 */
dvander@324
   138
typedef struct sp_pubvar_s
dvander@324
   139
{
dvander@372
   140
	cell_t	   *offs;		/**< Pointer to data */
dvander@372
   141
	const char *name;		/**< Name */
dvander@324
   142
} sp_pubvar_t;
dvander@324
   143
dvander@372
   144
#define SP_NATIVE_UNBOUND		(0)		/**< Native is undefined */
dvander@372
   145
#define SP_NATIVE_BOUND			(1)		/**< Native is bound */
dvander@324
   146
faluco@1089
   147
#define SP_NTVFLAG_OPTIONAL		(1<<0)	/**< Native is optional */
faluco@1089
   148
dvander@324
   149
/** 
dvander@372
   150
 * @brief Native lookup table, by default names point back to the sp_plugin_infotab_t structure.
dvander@324
   151
 */
dvander@324
   152
typedef struct sp_native_s
dvander@324
   153
{
dvander@372
   154
	SPVM_NATIVE_FUNC	pfn;	/**< Function pointer */
dvander@372
   155
	const char *		name;	/**< Name of function */
dvander@372
   156
	uint32_t			status;	/**< Status flags */
faluco@1089
   157
	uint32_t			flags;	/**< Native flags */
dvander@2086
   158
	void *				user;	/**< Host-specific data */
dvander@324
   159
} sp_native_t;
dvander@324
   160
dvander@324
   161
/** 
dvander@372
   162
 * @brief Used for setting natives from modules/host apps.
dvander@324
   163
 */
dvander@324
   164
typedef struct sp_nativeinfo_s
dvander@324
   165
{
dvander@372
   166
	const char		*name;	/**< Name of the native */
dvander@372
   167
	SPVM_NATIVE_FUNC func;	/**< Address of native implementation */
dvander@324
   168
} sp_nativeinfo_t;
dvander@324
   169
dvander@324
   170
/** 
dvander@372
   171
 * @brief Run-time debug file table
dvander@324
   172
 */
dvander@324
   173
typedef struct sp_debug_file_s
dvander@324
   174
{
dvander@372
   175
	uint32_t		addr;	/**< Address into code */
dvander@372
   176
	const char *	name;	/**< Name of file */
dvander@324
   177
} sp_debug_file_t;
dvander@324
   178
dvander@324
   179
/**
dvander@372
   180
 * @brief Contains run-time debug line table.
dvander@324
   181
 */
dvander@324
   182
typedef struct sp_debug_line_s
dvander@324
   183
{
dvander@372
   184
	uint32_t		addr;	/**< Address into code */
dvander@372
   185
	uint32_t		line;	/**< Line number */
dvander@324
   186
} sp_debug_line_t;
dvander@324
   187
dvander@372
   188
/**
dvander@372
   189
 * @brief These structures are equivalent.
dvander@372
   190
 */
dvander@324
   191
typedef sp_fdbg_arraydim_t	sp_debug_arraydim_t;
dvander@324
   192
dvander@324
   193
/**
dvander@372
   194
 * @brief The majority of this struct is already located in the parent 
dvander@372
   195
 * block.  Thus, only the relocated portions are required.
dvander@324
   196
 */
dvander@324
   197
typedef struct sp_debug_symbol_s
dvander@324
   198
{
dvander@372
   199
	uint32_t		codestart;	/**< Relocated code address */
ds@729
   200
	uint32_t		codeend;	/**< Relocated code end address */
dvander@372
   201
	const char *	name;		/**< Relocated name */
dvander@372
   202
	sp_debug_arraydim_t *dims;	/**< Relocated dimension struct, if any */
dvander@372
   203
	sp_fdbg_symbol_t	*sym;	/**< Pointer to original symbol */
dvander@324
   204
} sp_debug_symbol_t;
dvander@324
   205
dvander@324
   206
#endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H