public/sourcepawn/sp_vm_types.h

Go to the documentation of this file.
00001 /**
00002  * vim: set ts=4 :
00003  * =============================================================================
00004  * SourcePawn
00005  * Copyright (C) 2004-2008 AlliedModders LLC.  All rights reserved.
00006  * =============================================================================
00007  *
00008  * This program is free software; you can redistribute it and/or modify it under
00009  * the terms of the GNU General Public License, version 3.0, as published by the
00010  * Free Software Foundation.
00011  * 
00012  * This program is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00014  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00015  * details.
00016  *
00017  * You should have received a copy of the GNU General Public License along with
00018  * this program.  If not, see <http://www.gnu.org/licenses/>.
00019  *
00020  * As a special exception, AlliedModders LLC gives you permission to link the
00021  * code of this program (as well as its derivative works) to "Half-Life 2," the
00022  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
00023  * by the Valve Corporation.  You must obey the GNU General Public License in
00024  * all respects for all other code used.  Additionally, AlliedModders LLC grants
00025  * this exception to all derivative works.  AlliedModders LLC defines further
00026  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
00027  * or <http://www.sourcemod.net/license.php>.
00028  *
00029  * Version: $Id$
00030  */
00031 
00032 #ifndef _INCLUDE_SOURCEPAWN_VM_TYPES_H
00033 #define _INCLUDE_SOURCEPAWN_VM_TYPES_H
00034 
00035 /**
00036  * @file sp_vm_types.h
00037  * @brief Contains all run-time SourcePawn structures.
00038  */
00039 
00040 #include "sp_file_headers.h"
00041 
00042 typedef   uint32_t  ucell_t;                      /**< Unsigned 32bit integer */
00043 typedef int32_t               cell_t;                                 /**< Basic 32bit signed integer type for plugins */
00044 typedef uint32_t    funcid_t;                     /**< Function index code */
00045 
00046 #include "sp_typeutil.h"
00047 
00048 #define SP_MAX_EXEC_PARAMS                                  32        /**< Maximum number of parameters in a function */
00049 
00050 #define SP_JITCONF_DEBUG                "debug"             /**< Configuration option for debugging. */
00051 #define SP_JITCONF_PROFILE              "profile" /**< Configuration option for profiling. */
00052 
00053 #define SP_PROF_NATIVES                           (1<<0)              /**< Profile natives. */
00054 #define SP_PROF_CALLBACKS               (1<<1)              /**< Profile callbacks. */
00055 #define SP_PROF_FUNCTIONS               (1<<2)              /**< Profile functions. */
00056 
00057 /**
00058  * @brief Error codes for SourcePawn routines.
00059  */
00060 #define SP_ERROR_NONE                                                 0         /**< No error occurred */
00061 #define SP_ERROR_FILE_FORMAT                      1         /**< File format unrecognized */
00062 #define SP_ERROR_DECOMPRESSOR                     2         /**< A decompressor was not found */
00063 #define SP_ERROR_HEAPLOW                                    3         /**< Not enough space left on the heap */
00064 #define SP_ERROR_PARAM                                                4         /**< Invalid parameter or parameter type */
00065 #define SP_ERROR_INVALID_ADDRESS                  5         /**< A memory address was not valid */
00066 #define SP_ERROR_NOT_FOUND                                  6         /**< The object in question was not found */
00067 #define SP_ERROR_INDEX                                                7         /**< Invalid index parameter */
00068 #define SP_ERROR_STACKLOW                                   8         /**< Not enough space left on the stack */
00069 #define SP_ERROR_NOTDEBUGGING                     9         /**< Debug mode was not on or debug section not found */
00070 #define SP_ERROR_INVALID_INSTRUCTION    10        /**< Invalid instruction was encountered */
00071 #define SP_ERROR_MEMACCESS                                  11        /**< Invalid memory access */
00072 #define SP_ERROR_STACKMIN                                   12        /**< Stack went beyond its minimum value */
00073 #define SP_ERROR_HEAPMIN                                    13  /**< Heap went beyond its minimum value */
00074 #define SP_ERROR_DIVIDE_BY_ZERO                             14        /**< Division by zero */
00075 #define SP_ERROR_ARRAY_BOUNDS                     15        /**< Array index is out of bounds */
00076 #define SP_ERROR_INSTRUCTION_PARAM                16        /**< Instruction had an invalid parameter */
00077 #define SP_ERROR_STACKLEAK                                  17  /**< A native leaked an item on the stack */
00078 #define SP_ERROR_HEAPLEAK                                   18  /**< A native leaked an item on the heap */
00079 #define SP_ERROR_ARRAY_TOO_BIG                              19        /**< A dynamic array is too big */
00080 #define SP_ERROR_TRACKER_BOUNDS                             20        /**< Tracker stack is out of bounds */
00081 #define SP_ERROR_INVALID_NATIVE                             21        /**< Native was pending or invalid */
00082 #define SP_ERROR_PARAMS_MAX                                 22        /**< Maximum number of parameters reached */
00083 #define SP_ERROR_NATIVE                                               23        /**< Error originates from a native */
00084 #define SP_ERROR_NOT_RUNNABLE                     24        /**< Function or plugin is not runnable */
00085 #define SP_ERROR_ABORTED                                    25        /**< Function call was aborted */
00086 #define SP_ERROR_CODE_TOO_OLD                     26        /**< Code is too old for this VM */
00087 #define SP_ERROR_CODE_TOO_NEW                     27        /**< Code is too new for this VM */
00088 //Hey you! Update the string table if you add to the end of me! */
00089 
00090 /**********************************************
00091  *** The following structures are reference structures.
00092  *** They are not essential to the API, but are used
00093  ***  to hold the back end database format of the plugin
00094  ***  binary.
00095  **********************************************/
00096 
00097 namespace SourcePawn
00098 {
00099           class IPluginContext;
00100           class IVirtualMachine;
00101           class IProfiler;
00102 };
00103 
00104 struct sp_context_s;
00105 
00106 /**
00107  * @brief Native callback prototype, passed a context and a parameter stack (0=count, 1+=args).  
00108  * A cell must be returned.
00109  */
00110 typedef cell_t (*SPVM_NATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *);
00111 
00112 /**
00113  * @brief Fake native callback prototype, passed a context, parameter stack, and private data.
00114  * A cell must be returned.
00115  */
00116 typedef cell_t (*SPVM_FAKENATIVE_FUNC)(SourcePawn::IPluginContext *, const cell_t *, void *);
00117 
00118 /**********************************************
00119  *** The following structures are bound to the VM/JIT.
00120  *** Changing them will result in necessary recompilation.
00121  **********************************************/
00122 
00123 /**
00124  * @brief Offsets and names to a public function.
00125  */
00126 typedef struct sp_public_s
00127 {
00128           funcid_t  funcid;             /**< Encoded function id */
00129           uint32_t  code_offs;          /**< Relocated code offset */
00130           const char *name;             /**< Name of function */
00131 } sp_public_t;
00132 
00133 /**
00134  * @brief Offsets and names to public variables.
00135  *
00136  * The offset is relocated and the name by default points back to the sp_plugin_infotab_t structure.
00137  */
00138 typedef struct sp_pubvar_s
00139 {
00140           cell_t       *offs;           /**< Pointer to data */
00141           const char *name;             /**< Name */
00142 } sp_pubvar_t;
00143 
00144 #define SP_NATIVE_UNBOUND               (0)                 /**< Native is undefined */
00145 #define SP_NATIVE_BOUND                           (1)                 /**< Native is bound */
00146 
00147 #define SP_NTVFLAG_OPTIONAL             (1<<0)    /**< Native is optional */
00148 
00149 /** 
00150  * @brief Native lookup table, by default names point back to the sp_plugin_infotab_t structure.
00151  */
00152 typedef struct sp_native_s
00153 {
00154           SPVM_NATIVE_FUNC    pfn;      /**< Function pointer */
00155           const char *                  name;     /**< Name of function */
00156           uint32_t                      status;   /**< Status flags */
00157           uint32_t                      flags;    /**< Native flags */
00158           void *                                  user;     /**< Host-specific data */
00159 } sp_native_t;
00160 
00161 /** 
00162  * @brief Used for setting natives from modules/host apps.
00163  */
00164 typedef struct sp_nativeinfo_s
00165 {
00166           const char                    *name;    /**< Name of the native */
00167           SPVM_NATIVE_FUNC func;        /**< Address of native implementation */
00168 } sp_nativeinfo_t;
00169 
00170 /** 
00171  * @brief Run-time debug file table
00172  */
00173 typedef struct sp_debug_file_s
00174 {
00175           uint32_t            addr;     /**< Address into code */
00176           const char *        name;     /**< Name of file */
00177 } sp_debug_file_t;
00178 
00179 /**
00180  * @brief Contains run-time debug line table.
00181  */
00182 typedef struct sp_debug_line_s
00183 {
00184           uint32_t            addr;     /**< Address into code */
00185           uint32_t            line;     /**< Line number */
00186 } sp_debug_line_t;
00187 
00188 /**
00189  * @brief These structures are equivalent.
00190  */
00191 typedef sp_fdbg_arraydim_t    sp_debug_arraydim_t;
00192 
00193 /**
00194  * @brief The majority of this struct is already located in the parent 
00195  * block.  Thus, only the relocated portions are required.
00196  */
00197 typedef struct sp_debug_symbol_s
00198 {
00199           uint32_t            codestart;          /**< Relocated code address */
00200           uint32_t            codeend;  /**< Relocated code end address */
00201           const char *        name;               /**< Relocated name */
00202           sp_debug_arraydim_t *dims;    /**< Relocated dimension struct, if any */
00203           sp_fdbg_symbol_t    *sym;     /**< Pointer to original symbol */
00204 } sp_debug_symbol_t;
00205 
00206 #endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H

Generated on Sun Dec 28 23:26:25 2008 for SourceMod SDK by  doxygen 1.5.1