committed public api changes (context and plugin are now private)
--HG-- branch : refac-jit extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/branches/refac-jit%402374
This commit is contained in:
parent
3f38171d8c
commit
31dd23fbd9
@ -41,10 +41,8 @@
|
||||
#include "sp_vm_types.h"
|
||||
|
||||
/** SourcePawn Engine API Version */
|
||||
#define SOURCEPAWN_ENGINE_API_VERSION 3
|
||||
|
||||
/** SourcePawn VM API Version */
|
||||
#define SOURCEPAWN_VM_API_VERSION 7
|
||||
#define SOURCEPAWN_ENGINE_API_VERSION 4
|
||||
#define SOURCEPAWN_ENGINE2_API_VERSION 1
|
||||
|
||||
#if !defined SOURCEMOD_BUILD
|
||||
#define SOURCEMOD_BUILD
|
||||
@ -57,6 +55,9 @@ namespace SourceMod
|
||||
};
|
||||
#endif
|
||||
|
||||
struct sp_context_s;
|
||||
typedef struct sp_context_s sp_context_t;
|
||||
|
||||
namespace SourcePawn
|
||||
{
|
||||
class IVirtualMachine;
|
||||
@ -185,7 +186,8 @@ namespace SourcePawn
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Executes the forward, resets the pushed parameter list, and performs any copybacks.
|
||||
* @brief Executes the function, resets the pushed parameter list, and
|
||||
* performs any copybacks.
|
||||
*
|
||||
* @param result Pointer to store return value in.
|
||||
* @return Error code, if any.
|
||||
@ -206,9 +208,9 @@ namespace SourcePawn
|
||||
virtual int CallFunction(const cell_t *params, unsigned int num_params, cell_t *result) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns which plugin this function belongs to.
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @return IPluginContext pointer to parent plugin.
|
||||
* @return GetDefaultContext() of parent runtime.
|
||||
*/
|
||||
virtual IPluginContext *GetParentContext() =0;
|
||||
|
||||
@ -227,6 +229,37 @@ namespace SourcePawn
|
||||
* @return Function id.
|
||||
*/
|
||||
virtual funcid_t GetFunctionID() =0;
|
||||
|
||||
/**
|
||||
* @brief Executes the forward, resets the pushed parameter list, and
|
||||
* performs any copybacks.
|
||||
*
|
||||
* Note: A function can only be executed given a context it was created in.
|
||||
*
|
||||
* @param ctx Context to execute the function in.
|
||||
* @param result Pointer to store return value in.
|
||||
* @return Error code, if any.
|
||||
*/
|
||||
virtual int Execute(IPluginContext *ctx, cell_t *result) =0;
|
||||
|
||||
/**
|
||||
* @brief Executes the function with the given parameter array.
|
||||
* Parameters are read in forward order (i.e. index 0 is parameter #1)
|
||||
* NOTE: You will get an error if you attempt to use CallFunction() with
|
||||
* previously pushed parameters.
|
||||
*
|
||||
* Note: A function can only be executed given a context it was created in.
|
||||
*
|
||||
* @param ctx Context to execute the function in.
|
||||
* @param params Array of cell parameters.
|
||||
* @param num_params Number of parameters to push.
|
||||
* @param result Pointer to store result of function on return.
|
||||
* @return SourcePawn error code (if any).
|
||||
*/
|
||||
virtual int CallFunction(IPluginContext *ctx,
|
||||
const cell_t *params,
|
||||
unsigned int num_params,
|
||||
cell_t *result) =0;
|
||||
};
|
||||
|
||||
|
||||
@ -262,43 +295,38 @@ namespace SourcePawn
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface to managing a context at runtime.
|
||||
* @brief Represents a JIT compilation or plugin loading options.
|
||||
*/
|
||||
class IPluginContext
|
||||
class ICompilation
|
||||
{
|
||||
public:
|
||||
/** Virtual destructor */
|
||||
virtual ~IPluginContext() { };
|
||||
/**
|
||||
* @brief Sets a compilation option.
|
||||
*
|
||||
* @param key Option name.
|
||||
* @param val Option value.
|
||||
* @return True on success, false on failure.
|
||||
*/
|
||||
virtual bool SetOption(const char *key, const char *val) =0;
|
||||
|
||||
/**
|
||||
* @brief Aborts the compilation and destroys this object.
|
||||
*/
|
||||
virtual void Abort() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface to managing a runtime plugin.
|
||||
*/
|
||||
class IPluginRuntime
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Returns the parent IVirtualMachine.
|
||||
*
|
||||
* @return Parent virtual machine pointer.
|
||||
* @brief Virtual destructor (you may call delete).
|
||||
*/
|
||||
virtual IVirtualMachine *GetVirtualMachine() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the child sp_context_t structure.
|
||||
*
|
||||
* @return Child sp_context_t structure.
|
||||
*/
|
||||
virtual sp_context_t *GetContext() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the plugin is in debug mode.
|
||||
*
|
||||
* @return True if in debug mode, false otherwise.
|
||||
*/
|
||||
virtual bool IsDebugging() =0;
|
||||
|
||||
/**
|
||||
* @brief Installs a debug break and returns the old one, if any.
|
||||
* This will fail if the plugin is not debugging.
|
||||
*
|
||||
* @param newpfn New function pointer.
|
||||
* @param oldpfn Pointer to retrieve old function pointer.
|
||||
*/
|
||||
virtual int SetDebugBreak(SPVM_DEBUGBREAK newpfn, SPVM_DEBUGBREAK *oldpfn) =0;
|
||||
virtual ~IPluginRuntime()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns debug info.
|
||||
@ -307,39 +335,6 @@ namespace SourcePawn
|
||||
*/
|
||||
virtual IPluginDebugInfo *GetDebugInfo() =0;
|
||||
|
||||
/**
|
||||
* @brief Allocates memory on the secondary stack of a plugin.
|
||||
* Note that although called a heap, it is in fact a stack.
|
||||
*
|
||||
* @param cells Number of cells to allocate.
|
||||
* @param local_addr Will be filled with data offset to heap.
|
||||
* @param phys_addr Physical address to heap memory.
|
||||
*/
|
||||
virtual int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr) =0;
|
||||
|
||||
/**
|
||||
* @brief Pops a heap address off the heap stack. Use this to free memory allocated with
|
||||
* SP_HeapAlloc().
|
||||
* Note that in SourcePawn, the heap is in fact a bottom-up stack. Deallocations
|
||||
* with this native should be performed in precisely the REVERSE order.
|
||||
*
|
||||
* @param local_addr Local address to free.
|
||||
*/
|
||||
virtual int HeapPop(cell_t local_addr) =0;
|
||||
|
||||
/**
|
||||
* @brief Releases a heap address using a different method than SP_HeapPop().
|
||||
* This allows you to release in any order. However, if you allocate N
|
||||
* objects, release only some of them, then begin allocating again,
|
||||
* you cannot go back and starting freeing the originals.
|
||||
* In other words, for each chain of allocations, if you start deallocating,
|
||||
* then allocating more in a chain, you must only deallocate from the current
|
||||
* allocation chain. This is basically HeapPop() except on a larger scale.
|
||||
*
|
||||
* @param local_addr Local address to free.
|
||||
*/
|
||||
virtual int HeapRelease(cell_t local_addr) =0;
|
||||
|
||||
/**
|
||||
* @brief Finds a native by name.
|
||||
*
|
||||
@ -419,7 +414,218 @@ namespace SourcePawn
|
||||
virtual uint32_t GetPubVarsNum() =0;
|
||||
|
||||
/**
|
||||
* @brief Round-about method of converting a plugin reference to a physical address
|
||||
* @brief Returns a function by name.
|
||||
*
|
||||
* @param public_name Name of the function.
|
||||
* @return A new IPluginFunction pointer, NULL if not found.
|
||||
*/
|
||||
virtual IPluginFunction *GetFunctionByName(const char *public_name) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns a function by its id.
|
||||
*
|
||||
* @param func_id Function ID.
|
||||
* @return A new IPluginFunction pointer, NULL if not found.
|
||||
*/
|
||||
virtual IPluginFunction *GetFunctionById(funcid_t func_id) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the default context. The default context
|
||||
* should not be destroyed.
|
||||
*
|
||||
* @return Default context pointer.
|
||||
*/
|
||||
virtual IPluginContext *GetDefaultContext() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the plugin is in debug mode.
|
||||
*
|
||||
* @return True if in debug mode, false otherwise.
|
||||
*/
|
||||
virtual bool IsDebugging() =0;
|
||||
|
||||
/**
|
||||
* @brief Applies new compilation/runtime settings to the runtime code.
|
||||
*
|
||||
* The compilation object is destroyed once this function completes.
|
||||
*
|
||||
* @return Error code (SP_ERROR_NONE on success).
|
||||
*/
|
||||
virtual int ApplyCompilationOptions(ICompilation *co) =0;
|
||||
|
||||
/**
|
||||
* @brief Sets whether or not the plugin is paused (cannot be run).
|
||||
*
|
||||
* @param pause Pause state.
|
||||
*/
|
||||
virtual void SetPauseState(bool paused) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns whether or not the plugin is paused (runnable).
|
||||
*
|
||||
* @return Pause state (true = paused, false = not).
|
||||
*/
|
||||
virtual bool IsPaused() =0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Interface to managing a context at runtime.
|
||||
*/
|
||||
class IPluginContext
|
||||
{
|
||||
public:
|
||||
/** Virtual destructor */
|
||||
virtual ~IPluginContext() { };
|
||||
public:
|
||||
/**
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @return NULL.
|
||||
*/
|
||||
virtual IVirtualMachine *GetVirtualMachine() =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @return Opaque pointer.
|
||||
*/
|
||||
virtual sp_context_t *GetContext() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns true if the plugin is in debug mode.
|
||||
*
|
||||
* @return True if in debug mode, false otherwise.
|
||||
*/
|
||||
virtual bool IsDebugging() =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param newpfn Unused.
|
||||
* @param oldpfn Unused.
|
||||
*/
|
||||
virtual int SetDebugBreak(void *newpfn, void *oldpfn) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @return NULL.
|
||||
*/
|
||||
virtual IPluginDebugInfo *GetDebugInfo() =0;
|
||||
|
||||
/**
|
||||
* @brief Allocates memory on the secondary stack of a plugin.
|
||||
* Note that although called a heap, it is in fact a stack.
|
||||
*
|
||||
* @param cells Number of cells to allocate.
|
||||
* @param local_addr Will be filled with data offset to heap.
|
||||
* @param phys_addr Physical address to heap memory.
|
||||
*/
|
||||
virtual int HeapAlloc(unsigned int cells, cell_t *local_addr, cell_t **phys_addr) =0;
|
||||
|
||||
/**
|
||||
* @brief Pops a heap address off the heap stack. Use this to free memory allocated with
|
||||
* SP_HeapAlloc().
|
||||
* Note that in SourcePawn, the heap is in fact a bottom-up stack. Deallocations
|
||||
* with this native should be performed in precisely the REVERSE order.
|
||||
*
|
||||
* @param local_addr Local address to free.
|
||||
*/
|
||||
virtual int HeapPop(cell_t local_addr) =0;
|
||||
|
||||
/**
|
||||
* @brief Releases a heap address using a different method than SP_HeapPop().
|
||||
* This allows you to release in any order. However, if you allocate N
|
||||
* objects, release only some of them, then begin allocating again,
|
||||
* you cannot go back and starting freeing the originals.
|
||||
* In other words, for each chain of allocations, if you start deallocating,
|
||||
* then allocating more in a chain, you must only deallocate from the current
|
||||
* allocation chain. This is basically HeapPop() except on a larger scale.
|
||||
*
|
||||
* @param local_addr Local address to free.
|
||||
*/
|
||||
virtual int HeapRelease(cell_t local_addr) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @param name Name of native.
|
||||
* @param index Optionally filled with native index number.
|
||||
*/
|
||||
virtual int FindNativeByName(const char *name, uint32_t *index) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @param index Index number of native.
|
||||
* @param native Optionally filled with pointer to native structure.
|
||||
*/
|
||||
virtual int GetNativeByIndex(uint32_t index, sp_native_t **native) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @return Filled with the number of natives.
|
||||
*/
|
||||
virtual uint32_t GetNativesNum() =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @param name Name of public
|
||||
* @param index Optionally filled with public index number.
|
||||
*/
|
||||
virtual int FindPublicByName(const char *name, uint32_t *index) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @param index Public function index number.
|
||||
* @param publicptr Optionally filled with pointer to public structure.
|
||||
*/
|
||||
virtual int GetPublicByIndex(uint32_t index, sp_public_t **publicptr) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @return Filled with the number of public functions.
|
||||
*/
|
||||
virtual uint32_t GetPublicsNum() =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @param index Public variable index number.
|
||||
* @param pubvar Optionally filled with pointer to pubvar structure.
|
||||
*/
|
||||
virtual int GetPubvarByIndex(uint32_t index, sp_pubvar_t **pubvar) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @param name Name of pubvar
|
||||
* @param index Optionally filled with pubvar index number.
|
||||
*/
|
||||
virtual int FindPubvarByName(const char *name, uint32_t *index) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @param index Index of public variable.
|
||||
* @param local_addr Address to store local address in.
|
||||
* @param phys_addr Address to store physically relocated in.
|
||||
*/
|
||||
virtual int GetPubvarAddrs(uint32_t index, cell_t *local_addr, cell_t **phys_addr) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated, use IPluginRuntime instead.
|
||||
*
|
||||
* @return Number of public variables.
|
||||
*/
|
||||
virtual uint32_t GetPubVarsNum() =0;
|
||||
|
||||
/**
|
||||
* @brief Converts a plugin reference to a physical address
|
||||
*
|
||||
* @param local_addr Local address in plugin.
|
||||
* @param phys_addr Optionally filled with relocated physical address.
|
||||
@ -445,8 +651,8 @@ namespace SourcePawn
|
||||
|
||||
/**
|
||||
* @brief Converts a physical UTF-8 string to a local address.
|
||||
* This function is the same as the ANSI version, except it will copy the maximum number of characters possible
|
||||
* without accidentally chopping a multi-byte character.
|
||||
* This function is the same as the ANSI version, except it will copy the maximum number
|
||||
* of characters possible without accidentally chopping a multi-byte character.
|
||||
*
|
||||
* @param local_addr Local address in plugin.
|
||||
* @param maxbytes Number of bytes to write, including NULL terminator.
|
||||
@ -459,48 +665,41 @@ namespace SourcePawn
|
||||
size_t *wrtnbytes) =0;
|
||||
|
||||
/**
|
||||
* @brief Pushes a cell onto the stack. Increases the parameter count by one.
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param value Cell value.
|
||||
* @param value Unused.
|
||||
*/
|
||||
virtual int PushCell(cell_t value) =0;
|
||||
|
||||
/**
|
||||
* @brief Pushes an array of cells onto the stack. Increases the parameter count by one.
|
||||
* If the function returns an error it will fail entirely, releasing anything allocated in the process.
|
||||
* Note that this does not release the heap, so you should release it after
|
||||
* calling Execute().
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param local_addr Filled with local address to release.
|
||||
* @param phys_addr Optionally filled with physical address of new array.
|
||||
* @param array Cell array to copy.
|
||||
* @param numcells Number of cells in the array to copy.
|
||||
* @param local_addr Unused.
|
||||
* @param phys_addr Unused.
|
||||
* @param array Unused.
|
||||
* @param numcells Unused.
|
||||
*/
|
||||
virtual int PushCellArray(cell_t *local_addr, cell_t **phys_addr, cell_t array[], unsigned int numcells) =0;
|
||||
|
||||
/**
|
||||
* @brief Pushes a string onto the stack (by reference) and increases the parameter count by one.
|
||||
* Note that this does not release the heap, so you should release it after
|
||||
* calling Execute().
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param local_addr Filled with local address to release.
|
||||
* @param phys_addr Optionally filled with physical address of new array.
|
||||
* @param string Source string to push.
|
||||
* @param local_addr Unused.
|
||||
* @param phys_addr Unused.
|
||||
* @param string Unused.
|
||||
*/
|
||||
virtual int PushString(cell_t *local_addr, char **phys_addr, const char *string) =0;
|
||||
|
||||
/**
|
||||
* @brief Individually pushes each cell of an array of cells onto the stack. Increases the
|
||||
* parameter count by the number of cells pushed.
|
||||
* If the function returns an error it will fail entirely, releasing anything allocated in the process.
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param array Array of cells to read from.
|
||||
* @param numcells Number of cells to read.
|
||||
* @param array Unused.
|
||||
* @param numcells Unused.
|
||||
*/
|
||||
virtual int PushCellsFromArray(cell_t array[], unsigned int numcells) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated; do not use.
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param natives Deprecated; do not use.
|
||||
* @param num Deprecated; do not use.
|
||||
@ -509,25 +708,25 @@ namespace SourcePawn
|
||||
virtual int BindNatives(const sp_nativeinfo_t *natives, unsigned int num, int overwrite) =0;
|
||||
|
||||
/**
|
||||
* @brief Deprecated; do not use.
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param native Deprecated; do not use.
|
||||
*/
|
||||
virtual int BindNative(const sp_nativeinfo_t *native) =0;
|
||||
|
||||
/**
|
||||
* @brief Binds a single native to any non-registered native.
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param native Native to bind.
|
||||
* @param native Unused.
|
||||
*/
|
||||
virtual int BindNativeToAny(SPVM_NATIVE_FUNC native) =0;
|
||||
|
||||
/**
|
||||
* @brief Executes a function ID located in this context.
|
||||
* @brief Deprecated, does nothing.
|
||||
*
|
||||
* @param code_addr Address to execute at.
|
||||
* @param result Pointer to store the return value (required).
|
||||
* @return Error code (if any) from the VM.
|
||||
* @param code_addr Unused.
|
||||
* @param result Unused.
|
||||
* @return SP_ERROR_ABORTED.
|
||||
*/
|
||||
virtual int Execute(uint32_t code_addr, cell_t *result) =0;
|
||||
|
||||
@ -608,6 +807,28 @@ namespace SourcePawn
|
||||
* @return True if in exec, false otherwise.
|
||||
*/
|
||||
virtual bool IsInExec() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the parent runtime of a context.
|
||||
*
|
||||
* @return Parent runtime.
|
||||
*/
|
||||
virtual IPluginRuntime *GetRuntime() =0;
|
||||
|
||||
/**
|
||||
* @brief Executes a function in the context. The function must be
|
||||
* a member of the context's parent runtime.
|
||||
*
|
||||
* @param function Function.
|
||||
* @param params Parameters.
|
||||
* @param num_params Number of parameters in the parameter array.
|
||||
* @param result Optional pointer to store the result on success.
|
||||
* @return Error code.
|
||||
*/
|
||||
virtual int Execute(IPluginFunction *function,
|
||||
const cell_t *params,
|
||||
unsigned int num_params,
|
||||
cell_t *result) =0;
|
||||
};
|
||||
|
||||
|
||||
@ -748,6 +969,9 @@ namespace SourcePawn
|
||||
virtual void OnCallbackEnd(int serial) =0;
|
||||
};
|
||||
|
||||
struct sp_plugin_s;
|
||||
typedef struct sp_plugin_s sp_plugin_t;
|
||||
|
||||
/**
|
||||
* @brief Contains helper functions used by VMs and the host app
|
||||
*/
|
||||
@ -755,30 +979,29 @@ namespace SourcePawn
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Loads a named file from a file pointer.
|
||||
* Note: Using this means the memory will be allocated by the VM.
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @param fp File pointer. May be at any offset. Not closed on return.
|
||||
* @param err Optional error code pointer.
|
||||
* @return A new plugin structure.
|
||||
* @param fp Unused.
|
||||
* @param err Unused.
|
||||
* @return NULL.
|
||||
*/
|
||||
virtual sp_plugin_t *LoadFromFilePointer(FILE *fp, int *err) =0;
|
||||
|
||||
/**
|
||||
* @brief Loads a file from a base memory address.
|
||||
* @brief Deprecated, do not use,
|
||||
*
|
||||
* @param base Base address of the plugin's memory region.
|
||||
* @param plugin If NULL, a new plugin pointer is returned.
|
||||
* Otherwise, the passed pointer is used.
|
||||
* @param err Optional error code pointer.
|
||||
* @return The resulting plugin pointer.
|
||||
* @param base Unused.
|
||||
* @param plugin Unused.
|
||||
* @param err Unused.
|
||||
* @return NULL.
|
||||
*/
|
||||
virtual sp_plugin_t *LoadFromMemory(void *base, sp_plugin_t *plugin, int *err) =0;
|
||||
|
||||
/**
|
||||
* Frees all of the memory associated with a plugin file.
|
||||
* If allocated using SP_LoadFromMemory, the base and plugin pointer
|
||||
* itself are not freed (so this may end up doing nothing).
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @param plugin Unused.
|
||||
* @return SP_ERROR_ABORTED.
|
||||
*/
|
||||
virtual int FreeFromMemory(sp_plugin_t *plugin) =0;
|
||||
|
||||
@ -826,9 +1049,9 @@ namespace SourcePawn
|
||||
virtual IDebugListener *SetDebugListener(IDebugListener *listener) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the number of plugins on the call stack.
|
||||
* @brief Deprecated, do not use.
|
||||
*
|
||||
* @return Number of contexts in the call stack.
|
||||
* @return 0.
|
||||
*/
|
||||
virtual unsigned int GetContextCallCount() =0;
|
||||
|
||||
@ -869,103 +1092,23 @@ namespace SourcePawn
|
||||
virtual void FreePageMemory(void *ptr) =0;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Dummy class for encapsulating private compilation data.
|
||||
*/
|
||||
class ICompilation
|
||||
{
|
||||
public:
|
||||
/** Virtual destructor */
|
||||
virtual ~ICompilation() { };
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Outlines the interface a Virtual Machine (JIT) must expose
|
||||
*/
|
||||
class IVirtualMachine
|
||||
class ISourcePawnEngine2
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Returns the current API version.
|
||||
* @brief Returns the second engine API version.
|
||||
*
|
||||
* @return API version.
|
||||
*/
|
||||
virtual unsigned int GetAPIVersion() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the string name of a VM implementation.
|
||||
*/
|
||||
virtual const char *GetVMName() =0;
|
||||
|
||||
/**
|
||||
* @brief Begins a new compilation
|
||||
*
|
||||
* @param plugin Pointer to a plugin structure.
|
||||
* @return New compilation pointer.
|
||||
*/
|
||||
virtual ICompilation *StartCompilation(sp_plugin_t *plugin) =0;
|
||||
|
||||
/**
|
||||
* @brief Sets a compilation option.
|
||||
*
|
||||
* @param co Pointer to a compilation.
|
||||
* @param key Option key name.
|
||||
* @param val Option value string.
|
||||
* @return True if option could be set, false otherwise.
|
||||
*/
|
||||
virtual bool SetCompilationOption(ICompilation *co, const char *key, const char *val) =0;
|
||||
|
||||
/**
|
||||
* @brief Finalizes a compilation into a new sp_context_t.
|
||||
* Note: This will free the ICompilation pointer.
|
||||
*
|
||||
* @param co Compilation pointer.
|
||||
* @param err Filled with error code on exit.
|
||||
* @return New plugin context.
|
||||
*/
|
||||
virtual sp_context_t *CompileToContext(ICompilation *co, int *err) =0;
|
||||
|
||||
/**
|
||||
* @brief Aborts a compilation and frees the ICompilation pointer.
|
||||
*
|
||||
* @param co Compilation pointer.
|
||||
*/
|
||||
virtual void AbortCompilation(ICompilation *co) =0;
|
||||
|
||||
/**
|
||||
* @brief Frees any internal variable usage on a context.
|
||||
*
|
||||
* @param ctx Context structure pointer.
|
||||
*/
|
||||
virtual void FreeContext(sp_context_t *ctx) =0;
|
||||
|
||||
/**
|
||||
* @brief Calls the "execute" function on a context.
|
||||
*
|
||||
* @param ctx Executes a function in a context.
|
||||
* @param code_addr Index into the code section.
|
||||
* @param result Pointer to store result into.
|
||||
* @return Error code (if any).
|
||||
*/
|
||||
virtual int ContextExecute(sp_context_t *ctx, uint32_t code_addr, cell_t *result) =0;
|
||||
|
||||
/**
|
||||
* @brief Given a context and a code address, returns the index of the function.
|
||||
*
|
||||
* @param ctx Context to search.
|
||||
* @param code_addr Index into the code section.
|
||||
* @param result Pointer to store result into.
|
||||
* @return True if code index is valid, false otherwise.
|
||||
*/
|
||||
virtual bool FunctionLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result) =0;
|
||||
|
||||
/**
|
||||
* @brief Returns the number of functions defined in the context.
|
||||
*
|
||||
* @param ctx Context to search.
|
||||
* @return Number of functions.
|
||||
*/
|
||||
virtual unsigned int FunctionCount(const sp_context_t *ctx) =0;
|
||||
virtual const char *GetEngineName() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns a version string.
|
||||
@ -975,21 +1118,24 @@ namespace SourcePawn
|
||||
virtual const char *GetVersionString() =0;
|
||||
|
||||
/**
|
||||
* @brief Returns a string describing optimizations.
|
||||
* @brief Creates a new compilation options object.
|
||||
*
|
||||
* @return String describing CPU specific optimizations.
|
||||
* @return Compilation options object.
|
||||
*/
|
||||
virtual const char *GetCPUOptimizations() =0;
|
||||
virtual ICompilation *StartCompilation() =0;
|
||||
|
||||
/**
|
||||
* @brief Given a context and a p-code address, returns the index of the function.
|
||||
* @brief Loads a plugin from disk.
|
||||
*
|
||||
* @param ctx Context to search.
|
||||
* @param code_addr Index into the p-code section.
|
||||
* @param result Pointer to store result into.
|
||||
* @return True if code index is valid, false otherwise.
|
||||
* If a compilation object is supplied, it is destroyed upon
|
||||
* the function's return.
|
||||
*
|
||||
* @param co Compilation options, or NULL for defaults.
|
||||
* @param file Path to the file to compile.
|
||||
* @param err Error code (filled on failure); required.
|
||||
* @return New runtime pointer, or NULL on failure.
|
||||
*/
|
||||
virtual bool FunctionPLookup(const sp_context_t *ctx, uint32_t code_addr, unsigned int *result) =0;
|
||||
virtual IPluginRuntime *LoadPlugin(ICompilation *co, const char *file, int *err) =0;
|
||||
|
||||
/**
|
||||
* @brief Creates a fake native and binds it to a general callback function.
|
||||
@ -1006,6 +1152,24 @@ namespace SourcePawn
|
||||
* @param func Pointer to the fake native created by CreateFakeNative.
|
||||
*/
|
||||
virtual void DestroyFakeNative(SPVM_NATIVE_FUNC func) =0;
|
||||
|
||||
/**
|
||||
* @brief Sets the debug listener. This should only be called once.
|
||||
* If called successively (using manual chaining), only the last function should
|
||||
* attempt to call back into the same plugin. Otherwise, globally cached states
|
||||
* can be accidentally overwritten.
|
||||
*
|
||||
* @param listener Pointer to an IDebugListener.
|
||||
* @return Old IDebugListener, or NULL if none.
|
||||
*/
|
||||
virtual IDebugListener *SetDebugListener(IDebugListener *listener) =0;
|
||||
|
||||
/**
|
||||
* @brief Sets the global profiler.
|
||||
*
|
||||
* @param profiler Profiler pointer.
|
||||
*/
|
||||
virtual void SetProfiler(IProfiler *profiler) =0;
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -47,8 +47,5 @@
|
||||
#define EXPORT_LINK extern "C" __attribute__((visibility("default")))
|
||||
#endif
|
||||
|
||||
/** No longer used */
|
||||
typedef SourcePawn::IVirtualMachine *(*SP_GETVM_FUNC)(SourcePawn::ISourcePawnEngine *);
|
||||
|
||||
#endif //_INCLUDE_SOURCEPAWN_VM_BASE_H_
|
||||
|
||||
|
@ -92,56 +92,6 @@ typedef uint32_t funcid_t; /**< Function index code */
|
||||
*** binary.
|
||||
**********************************************/
|
||||
|
||||
/**
|
||||
* @brief Information about the core plugin tables. These may or may not be present!
|
||||
*/
|
||||
typedef struct sp_plugin_infotab_s
|
||||
{
|
||||
const char *stringbase; /**< base of string table */
|
||||
uint32_t publics_num; /**< number of publics */
|
||||
sp_file_publics_t *publics; /**< public table */
|
||||
uint32_t natives_num; /**< number of natives */
|
||||
sp_file_natives_t *natives; /**< native table */
|
||||
uint32_t pubvars_num; /**< number of pubvars */
|
||||
sp_file_pubvars_t *pubvars; /**< pubvars table */
|
||||
} sp_plugin_infotab_t;
|
||||
|
||||
/**
|
||||
* @brief Information about the plugin's debug tables. These are all present if one is present.
|
||||
*/
|
||||
typedef struct sp_plugin_debug_s
|
||||
{
|
||||
const char *stringbase; /**< base of string table */
|
||||
uint32_t files_num; /**< number of files */
|
||||
sp_fdbg_file_t *files; /**< files table */
|
||||
uint32_t lines_num; /**< number of lines */
|
||||
sp_fdbg_line_t *lines; /**< lines table */
|
||||
uint32_t syms_num; /**< number of symbols */
|
||||
sp_fdbg_symbol_t *symbols; /**< symbol table */
|
||||
} sp_plugin_debug_t;
|
||||
|
||||
#define SP_FA_SELF_EXTERNAL (1<<0) /**< Allocation of structure is external */
|
||||
#define SP_FA_BASE_EXTERNAL (1<<1) /**< Allocation of base is external */
|
||||
|
||||
/**
|
||||
* @brief The rebased memory format of a plugin. This differs from the on-disk structure
|
||||
* to ensure that the format is properly read.
|
||||
*/
|
||||
typedef struct sp_plugin_s
|
||||
{
|
||||
uint8_t *base; /**< Base of memory for this plugin. */
|
||||
uint8_t *pcode; /**< P-Code of plugin */
|
||||
uint32_t pcode_size; /**< Size of p-code */
|
||||
uint8_t *data; /**< Data/memory layout */
|
||||
uint32_t data_size; /**< Size of data */
|
||||
uint32_t memory; /**< Required memory space */
|
||||
uint16_t flags; /**< Code flags */
|
||||
uint32_t allocflags; /**< Allocation flags */
|
||||
sp_plugin_infotab_t info; /**< Base info table */
|
||||
sp_plugin_debug_t debug; /**< Debug info table */
|
||||
} sp_plugin_t;
|
||||
|
||||
|
||||
namespace SourcePawn
|
||||
{
|
||||
class IPluginContext;
|
||||
@ -251,51 +201,7 @@ typedef struct sp_debug_symbol_s
|
||||
sp_fdbg_symbol_t *sym; /**< Pointer to original symbol */
|
||||
} sp_debug_symbol_t;
|
||||
|
||||
/**
|
||||
* Breaks into a debugger
|
||||
* Params:
|
||||
* [0] - plugin context
|
||||
* [1] - frm
|
||||
* [2] - cip
|
||||
*/
|
||||
typedef int (*SPVM_DEBUGBREAK)(struct sp_context_s *, uint32_t, uint32_t);
|
||||
|
||||
#define SPFLAG_PLUGIN_DEBUG (1<<0) /**< plugin is in debug mode */
|
||||
#define SPFLAG_PLUGIN_PAUSED (1<<1) /**< plugin is "paused" (blocked from executing) */
|
||||
|
||||
/**
|
||||
* @brief This is the heart of the VM. It contains all of the runtime
|
||||
* information about a plugin context. Note that user[0..3] can be used for any user based pointers.
|
||||
* However, vm[0..3] should not be touched, as it is reserved for the VM.
|
||||
*/
|
||||
typedef struct sp_context_s
|
||||
{
|
||||
void *codebase; /**< Base of generated code and memory */
|
||||
sp_plugin_t *plugin; /**< Pointer back to parent information */
|
||||
SourcePawn::IPluginContext *context; /**< Pointer to IPluginContext */
|
||||
SourcePawn::IVirtualMachine *vmbase; /**< Pointer to IVirtualMachine */
|
||||
void *user[4]; /**< User specific pointers */
|
||||
void *vm[4]; /**< VM specific pointers */
|
||||
uint32_t flags; /**< Compilation flags */
|
||||
SPVM_DEBUGBREAK dbreak; /**< Debug break function */
|
||||
uint8_t *memory; /**< Data chunk */
|
||||
ucell_t mem_size; /**< Total memory size; */
|
||||
cell_t data_size; /**< Data chunk size, always starts at 0 */
|
||||
cell_t heap_base; /**< Where the heap starts */
|
||||
cell_t hp; /**< Heap pointer */
|
||||
cell_t sp; /**< Stack pointer */
|
||||
cell_t frm; /**< Frame pointer */
|
||||
uint32_t pushcount; /**< Push count */
|
||||
int32_t n_err; /**< Error code set by a native */
|
||||
uint32_t n_idx; /**< Current native index being executed */
|
||||
sp_public_t *publics; /**< Public functions table */
|
||||
sp_pubvar_t *pubvars; /**< Public variables table */
|
||||
sp_native_t *natives; /**< Natives table */
|
||||
sp_debug_file_t *files; /**< Files */
|
||||
sp_debug_line_t *lines; /**< Lines */
|
||||
sp_debug_symbol_t *symbols; /**< Symbols */
|
||||
SourcePawn::IProfiler *profiler; /**< Pointer to IProfiler */
|
||||
uint32_t prof_flags; /**< Profiling flags */
|
||||
} sp_context_t;
|
||||
//#define SPFLAG_PLUGIN_DEBUG (1<<0) /**< plugin is in debug mode */
|
||||
//#define SPFLAG_PLUGIN_PAUSED (1<<1) /**< plugin is "paused" (blocked from executing) */
|
||||
|
||||
#endif //_INCLUDE_SOURCEPAWN_VM_TYPES_H
|
||||
|
Loading…
Reference in New Issue
Block a user