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