Update to the new SourcePawn compiler.

This imports the brand new SourcePawn compiler. The new compiler is much
faster to compile and generates significantly improved code around
array generation and array access.

There are a number of compatibility changes in the new compiler. Most of
these are due to improved type checking and error detection. The full
list of notes can be found here:

https://github.com/alliedmodders/sourcepawn/blob/master/docs/upgrading-1.11.md

Additionally, .smx files generated by the new compiler will NOT load on
earlier versions of SourceMod, including earlier versions of 1.11. Old
plugins will continue to load as normal.
This commit is contained in:
David Anderson
2021-10-26 17:45:48 -10:00
parent 38a069b97a
commit 2a06680252
4 changed files with 131 additions and 18 deletions
+121 -8
View File
@@ -35,6 +35,7 @@
#include "common_logic.h" #include "common_logic.h"
#include "CellArray.h" #include "CellArray.h"
#include <IHandleSys.h> #include <IHandleSys.h>
#include <amtl/am-raii.h>
/*********************************** /***********************************
* About the double array hack * * About the double array hack *
@@ -195,7 +196,7 @@ static cell_t sm_SortFloats(IPluginContext *pContext, const cell_t *params)
static cell_t *g_CurStringArray = NULL; static cell_t *g_CurStringArray = NULL;
static cell_t *g_CurRebaseMap = NULL; static cell_t *g_CurRebaseMap = NULL;
int sort_strings_asc(const void *blk1, const void *blk2) int sort_strings_asc_legacy(const void *blk1, const void *blk2)
{ {
cell_t reloc1 = *(cell_t *)blk1; cell_t reloc1 = *(cell_t *)blk1;
cell_t reloc2 = *(cell_t *)blk2; cell_t reloc2 = *(cell_t *)blk2;
@@ -206,7 +207,7 @@ int sort_strings_asc(const void *blk1, const void *blk2)
return strcmp(str1, str2); return strcmp(str1, str2);
} }
int sort_strings_desc(const void *blk1, const void *blk2) int sort_strings_desc_legacy(const void *blk1, const void *blk2)
{ {
cell_t reloc1 = *(cell_t *)blk1; cell_t reloc1 = *(cell_t *)blk1;
cell_t reloc2 = *(cell_t *)blk2; cell_t reloc2 = *(cell_t *)blk2;
@@ -217,7 +218,7 @@ int sort_strings_desc(const void *blk1, const void *blk2)
return strcmp(str2, str1); return strcmp(str2, str1);
} }
static cell_t sm_SortStrings(IPluginContext *pContext, const cell_t *params) static cell_t sm_SortStrings_Legacy(IPluginContext *pContext, const cell_t *params)
{ {
cell_t *array; cell_t *array;
cell_t array_size = params[2]; cell_t array_size = params[2];
@@ -245,11 +246,11 @@ static cell_t sm_SortStrings(IPluginContext *pContext, const cell_t *params)
if (type == Sort_Ascending) if (type == Sort_Ascending)
{ {
qsort(array, array_size, sizeof(cell_t), sort_strings_asc); qsort(array, array_size, sizeof(cell_t), sort_strings_asc_legacy);
} }
else if (type == Sort_Descending) else if (type == Sort_Descending)
{ {
qsort(array, array_size, sizeof(cell_t), sort_strings_desc); qsort(array, array_size, sizeof(cell_t), sort_strings_desc_legacy);
} }
else else
{ {
@@ -275,6 +276,69 @@ static cell_t sm_SortStrings(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
static IPluginContext* sSortContext = nullptr;
int sort_strings_asc(const void *blk1, const void *blk2)
{
cell_t str_addr1 = *(cell_t *)blk1;
cell_t str_addr2 = *(cell_t *)blk2;
char *str1;
char *str2;
if (sSortContext->LocalToString(str_addr1, &str1) != SP_ERROR_NONE ||
sSortContext->LocalToString(str_addr2, &str2) != SP_ERROR_NONE)
{
return 0;
}
return strcmp(str1, str2);
}
int sort_strings_desc(const void *blk1, const void *blk2)
{
cell_t str_addr1 = *(cell_t *)blk1;
cell_t str_addr2 = *(cell_t *)blk2;
char *str1;
char *str2;
if (sSortContext->LocalToString(str_addr1, &str1) != SP_ERROR_NONE ||
sSortContext->LocalToString(str_addr2, &str2) != SP_ERROR_NONE)
{
return 0;
}
return strcmp(str2, str1);
}
static cell_t sm_SortStrings(IPluginContext *pContext, const cell_t *params)
{
auto rt = pContext->GetRuntime();
if (!rt->UsesDirectArrays())
return sm_SortStrings_Legacy(pContext, params);
cell_t *array;
cell_t array_size = params[2];
cell_t type = params[3];
pContext->LocalToPhysAddr(params[1], &array);
ke::SaveAndSet<IPluginContext*> set_context(&sSortContext, pContext);
if (type == Sort_Ascending)
{
qsort(array, array_size, sizeof(cell_t), sort_strings_asc);
}
else if (type == Sort_Descending)
{
qsort(array, array_size, sizeof(cell_t), sort_strings_desc);
}
else
{
sort_random(array, array_size);
}
return 1;
}
struct sort_info struct sort_info
{ {
IPluginFunction *pFunc; IPluginFunction *pFunc;
@@ -335,7 +399,7 @@ static cell_t sm_SortCustom1D(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
int sort2d_amx_custom(const void *elem1, const void *elem2) static int sort2d_amx_custom_legacy(const void *elem1, const void *elem2)
{ {
if (g_SortInfo.eh->HasException()) if (g_SortInfo.eh->HasException())
return 0; return 0;
@@ -361,7 +425,7 @@ int sort2d_amx_custom(const void *elem1, const void *elem2)
return result; return result;
} }
static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params) static cell_t sm_SortCustom2D_Legacy(IPluginContext *pContext, const cell_t *params)
{ {
cell_t *array; cell_t *array;
cell_t array_size = params[2]; cell_t array_size = params[2];
@@ -401,7 +465,7 @@ static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params)
array[i] = i; array[i] = i;
} }
qsort(array, array_size, sizeof(cell_t), sort2d_amx_custom); qsort(array, array_size, sizeof(cell_t), sort2d_amx_custom_legacy);
/** Fixup process! */ /** Fixup process! */
for (int i=0; i<array_size; i++) for (int i=0; i<array_size; i++)
@@ -419,6 +483,55 @@ static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params)
return 1; return 1;
} }
static int sort2d_amx_custom(const void *elem1, const void *elem2)
{
if (g_SortInfo.eh->HasException())
return 0;
cell_t iv1 = *(cell_t *)elem1;
cell_t iv2 = *(cell_t *)elem2;
cell_t result = 0;
g_SortInfo.pFunc->PushCell(iv1);
g_SortInfo.pFunc->PushCell(iv2);
g_SortInfo.pFunc->PushCell(g_SortInfo.array_addr);
g_SortInfo.pFunc->PushCell(g_SortInfo.hndl);
g_SortInfo.pFunc->Invoke(&result);
return result;
}
static cell_t sm_SortCustom2D(IPluginContext *pContext, const cell_t *params)
{
auto rt = pContext->GetRuntime();
if (!rt->UsesDirectArrays())
return sm_SortCustom2D_Legacy(pContext, params);
cell_t *array;
cell_t array_size = params[2];
IPluginFunction *pFunction;
pContext->LocalToPhysAddr(params[1], &array);
if ((pFunction=pContext->GetFunctionById(params[3])) == NULL)
{
return pContext->ThrowNativeError("Function %x is not a valid function", params[3]);
}
sort_info oldinfo = g_SortInfo;
DetectExceptions eh(pContext);
g_SortInfo.pFunc = pFunction;
g_SortInfo.hndl = params[4];
g_SortInfo.array_addr = params[1];
g_SortInfo.eh = &eh;
qsort(array, array_size, sizeof(cell_t), sort2d_amx_custom);
g_SortInfo = oldinfo;
return 1;
}
enum SortType enum SortType
{ {
Sort_Integer = 0, Sort_Integer = 0,
+1 -1
View File
@@ -1286,7 +1286,7 @@ void WritePreviousMapsToText()
file.Close(); file.Close();
} }
char GetTextFilePath() char[] GetTextFilePath()
{ {
static char path[PLATFORM_MAX_PATH]; static char path[PLATFORM_MAX_PATH];
if (path[0] == '\0') if (path[0] == '\0')