diff --git a/polymer/eduke32/build/include/m32script.h b/polymer/eduke32/build/include/m32script.h index 525b8e8ed..654318267 100644 --- a/polymer/eduke32/build/include/m32script.h +++ b/polymer/eduke32/build/include/m32script.h @@ -51,7 +51,6 @@ extern void VM_OnEvent(register int32_t iEventID, register int32_t iActor); extern void VM_ScriptInfo(void); extern void VM_Disasm(ofstype beg, int32_t size); -extern void C_ReportError(int32_t iError); extern int32_t Gv_NewVar(const char *pszLabel, intptr_t lValue, uint32_t dwFlags); extern int32_t Gv_NewArray(const char *pszLabel, void *arrayptr, intptr_t asize, uint32_t dwFlags); @@ -275,4 +274,23 @@ extern int32_t halfxdim16, midydim16; #define M32_PRINTERROR(Text, ...) OSD_Printf(OSD_ERROR "Line %d, %s: " Text "\n", g_errorLineNum, keyw[g_tw], ## __VA_ARGS__) + +// how local gamevars are allocated: + +// uncomment if variable-length arrays are available +//#define M32_LOCALS_VARARRAY + +// uncomment if alloca() is available +//#define M32_LOCALS_ALLOCA + +// if neither is there, use a constant number of them +#define M32_LOCALS_FIXEDNUM 64 + +#if defined M32_LOCALS_VARARRAY || defined M32_LOCALS_ALLOCA +# define M32_MAX_LOCALS MAXGAMEVARS +#else +# define M32_MAX_LOCALS M32_LOCALS_FIXEDNUM +#endif + + #endif diff --git a/polymer/eduke32/build/include/mutex.h b/polymer/eduke32/build/include/mutex.h index 2d4b1bf58..e927361c7 100644 --- a/polymer/eduke32/build/include/mutex.h +++ b/polymer/eduke32/build/include/mutex.h @@ -18,4 +18,4 @@ extern int32_t mutex_init(mutex_t *mutex); extern int32_t mutex_lock(mutex_t *mutex); extern int32_t mutex_unlock(mutex_t *mutex); -#endif \ No newline at end of file +#endif diff --git a/polymer/eduke32/build/include/prlights.h b/polymer/eduke32/build/include/prlights.h index 56fc75bfe..03a7c52d0 100644 --- a/polymer/eduke32/build/include/prlights.h +++ b/polymer/eduke32/build/include/prlights.h @@ -37,4 +37,4 @@ extern _prlight prlights[PR_MAXLIGHTS]; extern int32_t lightcount; #pragma pack(pop) -#endif \ No newline at end of file +#endif diff --git a/polymer/eduke32/source/m32def.c b/polymer/eduke32/source/m32def.c index da9d05199..711712196 100644 --- a/polymer/eduke32/source/m32def.c +++ b/polymer/eduke32/source/m32def.c @@ -33,7 +33,7 @@ static char g_szCurrentBlockName[BMAX_PATH] = "(none)", g_szLastBlockName[BMAX_P ////// compiler state vvv static const char *textptr, *start_textptr, *g_curkwptr; -static int32_t g_tw; +static int32_t def_tw; int32_t g_totalLines, g_lineNumber; int32_t g_numCompilerErrors, g_numCompilerWarnings; @@ -102,9 +102,6 @@ int32_t g_gameArrayCount=0, g_systemArrayCount=0; #define IFELSE_MAGIC 31337 -void C_ReportError(int32_t iError); -static void PrintErrorPosition(); - enum ScriptLabel_t { LABEL_ANY = -1, @@ -1545,7 +1542,7 @@ static int32_t C_ParseCommand(void) /// Bsprintf(g_szBuf,"PC(): '%.25s'",textptr); AddLog(g_szBuf); tw = C_GetNextKeyword(); - g_tw = tw; + def_tw = tw; // Bsprintf(tempbuf,"%s",keyw[tw]); AddLog(tempbuf); if (C_SkipComments()) @@ -2487,8 +2484,8 @@ repeatcase: uint16_t *numlocals = (cs.currentStateIdx >= 0) ? &statesinfo[cs.currentStateIdx].numlocals : &aEventNumLocals[cs.currentEvent]; - if (((int32_t)(*numlocals))+1 > MAXGAMEVARS) - C_CUSTOMERROR("too much local storage required (max: %d gamevar equivalents).", MAXGAMEVARS); + if (((int32_t)(*numlocals))+1 > M32_MAX_LOCALS) + C_CUSTOMERROR("too much local storage required (max: %d gamevar equivalents).", M32_MAX_LOCALS); else { hash_add(&h_localvars, tlabel, (int32_t)(*numlocals), 0); @@ -2523,8 +2520,8 @@ repeatcase: uint16_t *numlocals = (cs.currentStateIdx >= 0) ? &statesinfo[cs.currentStateIdx].numlocals : &aEventNumLocals[cs.currentEvent]; - if (((int32_t)(*numlocals))+asize > MAXGAMEVARS) - C_CUSTOMERROR("too much local storage required (max: %d gamevar equivalents).", MAXGAMEVARS); + if (((int32_t)(*numlocals))+asize > M32_MAX_LOCALS) + C_CUSTOMERROR("too much local storage required (max: %d gamevar equivalents).", M32_MAX_LOCALS); else { hash_add(&h_localvars, tlabel, ((int32_t)(*numlocals))|(asize<<16), 0); @@ -3809,7 +3806,7 @@ void C_ReportError(int32_t iError) break; case ERROR_LABELINUSE: initprintf("%s:%d: error: label `%s' is already in use by a %s.\n", - g_szScriptFileName, g_lineNumber, tlabel, g_tw==CON_DEFSTATE?"define":"state"); + g_szScriptFileName, g_lineNumber, tlabel, def_tw==CON_DEFSTATE?"define":"state"); break; case WARNING_DUPLICATECASE: initprintf("%s:%ld: warning: duplicate case ignored.\n", @@ -3833,10 +3830,10 @@ void C_ReportError(int32_t iError) } if (iError!=-1) - PrintErrorPosition(); + C_PrintErrorPosition(); } -static void PrintErrorPosition() +void C_PrintErrorPosition() { const char *b = g_curkwptr, *e=textptr; int32_t i, nchars; diff --git a/polymer/eduke32/source/m32def.h b/polymer/eduke32/source/m32def.h index 090083785..20ac80fbd 100644 --- a/polymer/eduke32/source/m32def.h +++ b/polymer/eduke32/source/m32def.h @@ -32,16 +32,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define C_CUSTOMERROR(Text, ...) do { \ C_ReportError(-1); \ initprintf("%s:%d: error: " Text "\n", g_szScriptFileName, g_lineNumber, ## __VA_ARGS__); \ - PrintErrorPosition(); \ + C_PrintErrorPosition(); \ g_numCompilerErrors++; \ } while (0) #define C_CUSTOMWARNING(Text, ...) do { \ C_ReportError(-1); \ initprintf("%s:%d: warning: " Text "\n", g_szScriptFileName, g_lineNumber, ## __VA_ARGS__); \ - PrintErrorPosition(); \ + C_PrintErrorPosition(); \ g_numCompilerWarnings++; \ } while (0) +extern void C_PrintErrorPosition(); +extern void C_ReportError(int32_t iError); + extern char g_szScriptFileName[BMAX_PATH]; extern int32_t g_totalLines, g_lineNumber; extern int32_t g_numCompilerErrors, g_numCompilerWarnings; @@ -103,6 +106,7 @@ extern vmstate_t vm_default; extern int32_t g_errorLineNum; +extern int32_t g_tw; extern const char *keyw[]; enum SystemString_t { diff --git a/polymer/eduke32/source/m32exec.c b/polymer/eduke32/source/m32exec.c index 6238c6a5f..74404f8ea 100644 --- a/polymer/eduke32/source/m32exec.c +++ b/polymer/eduke32/source/m32exec.c @@ -48,6 +48,7 @@ int32_t g_errorLineNum, g_tw; uint8_t aEventEnabled[MAXEVENTS]; uint32_t m32_drawlinepat=0xffffffff; +int32_t m32_script_expertmode = 0; instype *insptr; int32_t VM_Execute(int32_t once); @@ -152,7 +153,13 @@ void VM_OnEvent(register int32_t iEventID, register int32_t iActor) instype *oinsptr=insptr; vmstate_t vm_backup; void *olocalvars = aGameArrays[M32_LOCAL_ARRAY_ID].vals; - void *localvars = alloca(aEventNumLocals[iEventID] * sizeof(int32_t)); +#ifdef M32_LOCALS_VARARRAY + int32_t localvars[aEventNumLocals[iEventID]]; +#elif defined M32_LOCALS_ALLOCA + int32_t *localvars = alloca(aEventNumLocals[iEventID] * sizeof(int32_t)); +#else + int32_t localvars[M32_LOCALS_FIXEDNUM]; +#endif // needed since any read access before initialization would cause undefined behaviour if (aEventNumLocals[iEventID] > 0) @@ -341,7 +348,13 @@ skip_check: instype *tempscrptr = insptr+2; int32_t stateidx = *(insptr+1), o_g_st = vm.g_st, oret=vm.flags&VMFLAG_RETURN; void *olocalvars = aGameArrays[M32_LOCAL_ARRAY_ID].vals; - void *localvars = alloca(statesinfo[stateidx].numlocals * sizeof(int32_t)); +#ifdef M32_LOCALS_VARARRAY + int32_t localvars[statesinfo[stateidx].numlocals]; +#elif defined M32_LOCALS_ALLOCA + int32_t *localvars = alloca(statesinfo[stateidx].numlocals * sizeof(int32_t)); +#else + int32_t localvars[M32_LOCALS_FIXEDNUM]; +#endif // needed since any read access before initialization would cause undefined behaviour if (statesinfo[stateidx].numlocals > 0) diff --git a/polymer/eduke32/source/m32structures.c b/polymer/eduke32/source/m32structures.c index 811001bc5..aec416620 100644 --- a/polymer/eduke32/source/m32structures.c +++ b/polymer/eduke32/source/m32structures.c @@ -33,7 +33,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define ACCESS_USEVARS 2 #define ACCESS_SPRITEEXT 4 -int32_t m32_script_expertmode = 0; + +/// This file is #included into other files, so don't define variables here! static int32_t __fastcall VM_AccessWall(int32_t how, int32_t lVar1, int32_t lLabelID, int32_t lVar2)