diff --git a/acc.dsp b/acc.dsp index a6e72c6..ffa8f6a 100644 --- a/acc.dsp +++ b/acc.dsp @@ -66,7 +66,7 @@ LINK32=link.exe # PROP Intermediate_Dir "Debug" # PROP Target_Dir "" # ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c -# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c +# ADD CPP /nologo /W3 /Gm /GX- /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe diff --git a/common.h b/common.h index 786d3f7..a94b56e 100644 --- a/common.h +++ b/common.h @@ -50,12 +50,12 @@ // Added Ty 07Jan2000 for error details #define MAX_STATEMENT_LENGTH 4096 -#define MAX_LANGUAGES 256 - #define MAX_FUNCTION_COUNT 256 #define MAX_IMPORTS 256 +#define MAX_SCRIPT_ARRAYS 255 + // Max number of include paths the user can specify // This includes the "working directory"! #define MAX_INCLUDE_PATHS 16 diff --git a/error.c b/error.c index 844613f..6f0c758 100644 --- a/error.c +++ b/error.c @@ -80,6 +80,8 @@ static struct { ERR_TOO_MANY_MAP_VARS, "Too many map variables." }, { ERR_TOO_MANY_SCRIPT_VARS, "Too many script variables." }, { ERR_TOO_MANY_FUNCTION_VARS, "Too many function variables." }, + { ERR_TOO_MANY_SCRIPT_ARRAYS, "Too many script arrays." }, + { ERR_TOO_MANY_FUNCTION_ARRAYS, "Too many function arrays." }, { ERR_MISSING_WVAR_INDEX, "Missing index in world variable declaration." }, { ERR_MISSING_GVAR_INDEX, "Missing index in global variable declaration." }, { ERR_BAD_WVAR_INDEX, "World variable index out of range." }, @@ -133,12 +135,6 @@ static struct { ERR_SCRIPT_ALREADY_DEFINED, "Script already has a body." }, { ERR_FUNCTION_ALREADY_DEFINED, "Function already has a body." }, { ERR_PARM_MUST_BE_VAR, "Parameter must be a variable." }, - { ERR_LANGCODE_SIZE, "Language code must be 2 or 3 characters long." }, - { ERR_MISSING_LBRACE_LOC, "Missing opening '{' in localization definition." }, - { ERR_MISSING_RBRACE_LOC, "Missing closing '}' in localization definition." }, - { ERR_MISSING_LOCALIZED, "Missing localized string." }, - { ERR_BAD_LANGCODE, "Language code must be all letters." }, - { ERR_MISSING_LANGCODE, "Missing language code in localization definiton." }, { ERR_MISSING_FONT_NAME, "Missing font name." }, { ERR_MISSING_LBRACE_FONTS, "Missing opening '{' in font list." }, { ERR_MISSING_RBRACE_FONTS, "Missing closing '}' in font list." }, diff --git a/error.h b/error.h index f4ce828..d9d7c2b 100644 --- a/error.h +++ b/error.h @@ -60,6 +60,8 @@ typedef enum ERR_STRING_LIT_NOT_FOUND, ERR_TOO_MANY_SCRIPT_VARS, ERR_TOO_MANY_FUNCTION_VARS, + ERR_TOO_MANY_SCRIPT_ARRAYS, + ERR_TOO_MANY_FUNCTION_ARRAYS, ERR_INVALID_DECLARATOR, ERR_BAD_LSPEC_ARG_COUNT, ERR_BAD_ARG_COUNT, @@ -99,12 +101,6 @@ typedef enum ERR_SCRIPT_ALREADY_DEFINED, ERR_FUNCTION_ALREADY_DEFINED, ERR_PARM_MUST_BE_VAR, - ERR_LANGCODE_SIZE, - ERR_MISSING_LBRACE_LOC, - ERR_MISSING_RBRACE_LOC, - ERR_MISSING_LOCALIZED, - ERR_BAD_LANGCODE, - ERR_MISSING_LANGCODE, ERR_MISSING_FONT_NAME, ERR_MISSING_LBRACE_FONTS, ERR_MISSING_RBRACE_FONTS, diff --git a/parse.c b/parse.c index 144401a..76779b5 100644 --- a/parse.c +++ b/parse.c @@ -143,8 +143,11 @@ static pcd_t TokenToPCD(tokenType_t token); static pcd_t GetPushVarPCD(symbolType_t symType); static pcd_t GetIncDecPCD(tokenType_t token, symbolType_t symbol); static int EvalConstExpression(void); +static void ParseArrayDims(int *size, int *ndim, int dims[MAX_ARRAY_DIMS]); +static void SymToArray(int symtype, symbolNode_t *sym, int index, int ndim, int size, int dims[MAX_ARRAY_DIMS]); static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices); static void InitializeArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int size); +static void InitializeScriptArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int size); static symbolNode_t *DemandSymbol(char *name); static symbolNode_t *SpeculateSymbol(char *name, boolean hasReturn); static symbolNode_t *SpeculateFunction(const char *name, boolean hasReturn); @@ -171,6 +174,8 @@ boolean pa_ConstExprIsString; // PRIVATE DATA DEFINITIONS ------------------------------------------------ static int ScriptVarCount; +static int ScriptArrayCount; +static int ScriptArraySize[MAX_SCRIPT_ARRAYS]; static statement_t StatementHistory[MAX_STATEMENT_DEPTH]; static int StatementIndex; static breakInfo_t BreakInfo[MAX_BREAK]; @@ -495,6 +500,10 @@ static void Outside(void) { MS_Message(MSG_DEBUG, "Allocations modified for exporting\n"); ImportMode = IMPORT_Exporting; + if(pc_EnforceHexen) + { + ERR_Error(ERR_HEXEN_COMPAT, YES); + } } else if(ImportMode == IMPORT_Importing) { @@ -533,6 +542,7 @@ static void OuterScript(void) CaseIndex = 0; StatementLevel = 0; ScriptVarCount = 0; + ScriptArrayCount = 0; SY_FreeLocals(); TK_NextToken(); @@ -738,7 +748,7 @@ static void OuterScript(void) { PC_AppendCmd(PCD_TERMINATE); } - PC_SetScriptVarCount(scriptNumber, scriptType, ScriptVarCount); + PC_SetScriptVarCount(scriptNumber, scriptType, ScriptVarCount, ScriptArrayCount, ScriptArraySize); pa_ScriptCount++; } @@ -761,6 +771,7 @@ static void OuterFunction(void) CaseIndex = 0; StatementLevel = 0; ScriptVarCount = 0; + ScriptArrayCount = 0; SY_FreeLocals(); TK_NextToken(); if(tk_Token != TK_STR && tk_Token != TK_INT && @@ -862,6 +873,10 @@ static void OuterFunction(void) } while(tk_Token == TK_COMMA); TK_TokenMustBe(TK_RPAREN, ERR_MISSING_RPAREN); } + if(pc_EnforceHexen) + { + ERR_Error(ERR_HEXEN_COMPAT, YES); + } sym->info.scriptFunc.sourceLine = defLine; sym->info.scriptFunc.sourceName = tk_SourceName; @@ -911,7 +926,7 @@ static void OuterFunction(void) sym->info.scriptFunc.predefined = NO; sym->info.scriptFunc.varCount = ScriptVarCount - sym->info.scriptFunc.argCount; - PC_AddFunction(sym); + PC_AddFunction(sym, ScriptArrayCount, ScriptArraySize); UnspeculateFunction(sym); InsideFunction = NULL; } @@ -925,7 +940,7 @@ static void OuterFunction(void) static void OuterMapVar(boolean local) { symbolNode_t *sym = NULL; - int index, i; + int index; MS_Message(MSG_DEBUG, "---- %s ----\n", local ? "LeadingStaticVarDeclare" : "OuterMapVar"); do @@ -980,75 +995,17 @@ static void OuterMapVar(boolean local) } else if(tk_Token == TK_LBRACKET) { - int size = 0; - int ndim = 0; - int dims[MAX_ARRAY_DIMS]; + int size, ndim, dims[MAX_ARRAY_DIMS]; - memset(dims, 0, sizeof(dims)); + ParseArrayDims(&size, &ndim, dims); - while(tk_Token == TK_LBRACKET) - { - if(ndim == MAX_ARRAY_DIMS) - { - ERR_Error(ERR_TOO_MANY_ARRAY_DIMS, YES); - do - { - TK_NextToken(); - } while(tk_Token != TK_COMMA && tk_Token != TK_SEMICOLON); - break; - } - TK_NextToken(); - if (tk_Token == TK_RBRACKET) - { - ERR_Error(ERR_NEED_ARRAY_SIZE, YES); - } - else - { - dims[ndim] = EvalConstExpression(); - if(dims[ndim] == 0) - { - ERR_Error(ERR_ZERO_DIMENSION, YES); - dims[ndim] = 1; - } - if(ndim == 0) - { - size = dims[ndim]; - } - else - { - size *= dims[ndim]; - } - } - ndim++; - TK_TokenMustBe(TK_RBRACKET, ERR_MISSING_RBRACKET); - TK_NextToken(); - } if(sym != NULL) { if(ImportMode != IMPORT_Importing) { PC_AddArray(index, size); } - MS_Message(MSG_DEBUG, "%s changed to an array of size %d\n", sym->name, size); - sym->type = SY_MAPARRAY; - sym->info.array.index = index; - sym->info.array.ndim = ndim; - sym->info.array.size = size; - if(ndim > 0) - { - sym->info.array.dimensions[ndim-1] = 1; - for(i = ndim - 2; i >= 0; --i) - { - sym->info.array.dimensions[i] = - sym->info.array.dimensions[i+1] * dims[i+1]; - } - } - MS_Message(MSG_DEBUG, " - with multipliers "); - for(i = 0; i < ndim; ++i) - { - MS_Message(MSG_DEBUG, "[%d]", sym->info.array.dimensions[i]); - } - MS_Message(MSG_DEBUG, "\n"); + SymToArray(SY_MAPARRAY, sym, index, size, ndim, dims); if(tk_Token == TK_ASSIGN) { InitializeArray(sym, dims, size); @@ -1223,6 +1180,7 @@ static void OuterDefine(boolean force) value = EvalConstExpression(); MS_Message(MSG_DEBUG, "Constant value: %d\n", value); sym->info.constant.value = value; + sym->info.constant.strValue = pa_ConstExprIsString ? strdup(STR_Get(value)) : NULL; // Defines inside an import are deleted when the import is popped. if(ImportMode != IMPORT_Importing || force) { @@ -1518,8 +1476,26 @@ static void LeadingVarDeclare(void) TK_NextToken(); if(tk_Token == TK_LBRACKET) { - ERR_Error(ERR_ARRAY_MAPVAR_ONLY, YES); - do {} while(TK_NextToken() != TK_COMMA && tk_Token != TK_SEMICOLON); + int size, ndim, dims[MAX_ARRAY_DIMS]; + + ParseArrayDims(&size, &ndim, dims); + if(sym != NULL) + { + ScriptVarCount--; + if(ScriptArrayCount == MAX_SCRIPT_ARRAYS) + { + ERR_Error(InsideFunction ? ERR_TOO_MANY_FUNCTION_ARRAYS : ERR_TOO_MANY_SCRIPT_ARRAYS, YES, NULL); + } + if(ScriptArrayCount < MAX_SCRIPT_ARRAYS) + { + ScriptArraySize[ScriptArrayCount] = size; + } + SymToArray(SY_SCRIPTARRAY, sym, ScriptArrayCount++, size, ndim, dims); + if(tk_Token == TK_ASSIGN) + { + InitializeScriptArray(sym, dims, size); + } + } } else if(tk_Token == TK_ASSIGN) { @@ -1784,6 +1760,7 @@ static void LeadingIdentifier(void) case SY_MAPVAR: case SY_WORLDVAR: case SY_GLOBALVAR: + case SY_SCRIPTARRAY: case SY_WORLDARRAY: case SY_GLOBALARRAY: LeadingVarAssign(sym); @@ -2256,9 +2233,9 @@ static void ActionOnCharRange(boolean write) sym = SpeculateSymbol(tk_String, NO); if((sym->type != SY_MAPARRAY) && (sym->type != SY_WORLDARRAY) - && (sym->type != SY_GLOBALARRAY)) + && (sym->type != SY_GLOBALARRAY) && (sym->type != SY_SCRIPTARRAY)) { - ERR_Error(ERR_NOT_AN_ARRAY, YES); + ERR_Error(ERR_NOT_AN_ARRAY, YES, sym->name); } TK_NextToken(); if(sym->info.array.ndim > 1) @@ -2332,7 +2309,12 @@ static void ActionOnCharRange(boolean write) } } - if(sym->type == SY_MAPARRAY) + if(sym->type == SY_SCRIPTARRAY) + { + if (write) PC_AppendCmd(PCD_STRCPYTOSCRIPTCHRANGE); + else PC_AppendCmd( rangeConstraints ? PCD_PRINTSCRIPTCHRANGE : PCD_PRINTSCRIPTCHARARRAY ); + } + else if(sym->type == SY_MAPARRAY) { if (write) PC_AppendCmd(PCD_STRCPYTOMAPCHRANGE); else PC_AppendCmd( rangeConstraints ? PCD_PRINTMAPCHRANGE : PCD_PRINTMAPCHARARRAY ); @@ -3082,7 +3064,8 @@ static void LeadingIncDec(int token) if(sym->type != SY_SCRIPTVAR && sym->type != SY_MAPVAR && sym->type != SY_WORLDVAR && sym->type != SY_GLOBALVAR && sym->type != SY_MAPARRAY && sym->type != SY_GLOBALARRAY - && sym->type != SY_WORLDARRAY && sym->type != SY_SCRIPTALIAS) + && sym->type != SY_WORLDARRAY && sym->type != SY_SCRIPTALIAS + && sym->type != SY_SCRIPTARRAY) { ERR_Error(ERR_INCDEC_OP_ON_NON_VAR, YES); TK_SkipPast(TK_SEMICOLON); @@ -3090,7 +3073,7 @@ static void LeadingIncDec(int token) } TK_NextToken(); if(sym->type == SY_MAPARRAY || sym->type == SY_WORLDARRAY - || sym->type == SY_GLOBALARRAY) + || sym->type == SY_GLOBALARRAY || sym->type == SY_SCRIPTARRAY) { ParseArrayIndices(sym, sym->info.array.ndim); } @@ -3132,7 +3115,7 @@ static void LeadingVarAssign(symbolNode_t *sym) { TK_NextToken(); // Fetch assignment operator if(sym->type == SY_MAPARRAY || sym->type == SY_WORLDARRAY - || sym->type == SY_GLOBALARRAY) + || sym->type == SY_GLOBALARRAY || sym->type == SY_SCRIPTARRAY) { ParseArrayIndices(sym, sym->info.array.ndim); } @@ -3213,21 +3196,21 @@ static pcd_t GetAssignPCD(tokenType_t token, symbolType_t symbol) static symbolType_t symbolLookup[] = { SY_SCRIPTVAR, SY_MAPVAR, SY_WORLDVAR, SY_GLOBALVAR, SY_MAPARRAY, - SY_WORLDARRAY, SY_GLOBALARRAY + SY_WORLDARRAY, SY_GLOBALARRAY, SY_SCRIPTARRAY }; - static pcd_t assignmentLookup[11][7] = + static pcd_t assignmentLookup[11][8] = { - { PCD_ASSIGNSCRIPTVAR, PCD_ASSIGNMAPVAR, PCD_ASSIGNWORLDVAR, PCD_ASSIGNGLOBALVAR, PCD_ASSIGNMAPARRAY, PCD_ASSIGNWORLDARRAY, PCD_ASSIGNGLOBALARRAY }, - { PCD_ADDSCRIPTVAR, PCD_ADDMAPVAR, PCD_ADDWORLDVAR, PCD_ADDGLOBALVAR, PCD_ADDMAPARRAY, PCD_ADDWORLDARRAY, PCD_ADDGLOBALARRAY }, - { PCD_SUBSCRIPTVAR, PCD_SUBMAPVAR, PCD_SUBWORLDVAR, PCD_SUBGLOBALVAR, PCD_SUBMAPARRAY, PCD_SUBWORLDARRAY, PCD_SUBGLOBALARRAY }, - { PCD_MULSCRIPTVAR, PCD_MULMAPVAR, PCD_MULWORLDVAR, PCD_MULGLOBALVAR, PCD_MULMAPARRAY, PCD_MULWORLDARRAY, PCD_MULGLOBALARRAY }, - { PCD_DIVSCRIPTVAR, PCD_DIVMAPVAR, PCD_DIVWORLDVAR, PCD_DIVGLOBALVAR, PCD_DIVMAPARRAY, PCD_DIVWORLDARRAY, PCD_DIVGLOBALARRAY }, - { PCD_MODSCRIPTVAR, PCD_MODMAPVAR, PCD_MODWORLDVAR, PCD_MODGLOBALVAR, PCD_MODMAPARRAY, PCD_MODWORLDARRAY, PCD_MODGLOBALARRAY }, - { PCD_ANDSCRIPTVAR, PCD_ANDMAPVAR, PCD_ANDWORLDVAR, PCD_ANDGLOBALVAR, PCD_ANDMAPARRAY, PCD_ANDWORLDARRAY, PCD_ANDGLOBALARRAY }, - { PCD_EORSCRIPTVAR, PCD_EORMAPVAR, PCD_EORWORLDVAR, PCD_EORGLOBALVAR, PCD_EORMAPARRAY, PCD_EORWORLDARRAY, PCD_EORGLOBALARRAY }, - { PCD_ORSCRIPTVAR, PCD_ORMAPVAR, PCD_ORWORLDVAR, PCD_ORGLOBALVAR, PCD_ORMAPARRAY, PCD_ORWORLDARRAY, PCD_ORGLOBALARRAY }, - { PCD_LSSCRIPTVAR, PCD_LSMAPVAR, PCD_LSWORLDVAR, PCD_LSGLOBALVAR, PCD_LSMAPARRAY, PCD_LSWORLDARRAY, PCD_LSGLOBALARRAY }, - { PCD_RSSCRIPTVAR, PCD_RSMAPVAR, PCD_RSWORLDVAR, PCD_RSGLOBALVAR, PCD_RSMAPARRAY, PCD_RSWORLDARRAY, PCD_RSGLOBALARRAY } + { PCD_ASSIGNSCRIPTVAR, PCD_ASSIGNMAPVAR, PCD_ASSIGNWORLDVAR, PCD_ASSIGNGLOBALVAR, PCD_ASSIGNMAPARRAY, PCD_ASSIGNWORLDARRAY, PCD_ASSIGNGLOBALARRAY, PCD_ASSIGNSCRIPTARRAY }, + { PCD_ADDSCRIPTVAR, PCD_ADDMAPVAR, PCD_ADDWORLDVAR, PCD_ADDGLOBALVAR, PCD_ADDMAPARRAY, PCD_ADDWORLDARRAY, PCD_ADDGLOBALARRAY, PCD_ADDSCRIPTARRAY }, + { PCD_SUBSCRIPTVAR, PCD_SUBMAPVAR, PCD_SUBWORLDVAR, PCD_SUBGLOBALVAR, PCD_SUBMAPARRAY, PCD_SUBWORLDARRAY, PCD_SUBGLOBALARRAY, PCD_SUBSCRIPTARRAY }, + { PCD_MULSCRIPTVAR, PCD_MULMAPVAR, PCD_MULWORLDVAR, PCD_MULGLOBALVAR, PCD_MULMAPARRAY, PCD_MULWORLDARRAY, PCD_MULGLOBALARRAY, PCD_MULSCRIPTARRAY }, + { PCD_DIVSCRIPTVAR, PCD_DIVMAPVAR, PCD_DIVWORLDVAR, PCD_DIVGLOBALVAR, PCD_DIVMAPARRAY, PCD_DIVWORLDARRAY, PCD_DIVGLOBALARRAY, PCD_DIVSCRIPTARRAY }, + { PCD_MODSCRIPTVAR, PCD_MODMAPVAR, PCD_MODWORLDVAR, PCD_MODGLOBALVAR, PCD_MODMAPARRAY, PCD_MODWORLDARRAY, PCD_MODGLOBALARRAY, PCD_MODSCRIPTARRAY }, + { PCD_ANDSCRIPTVAR, PCD_ANDMAPVAR, PCD_ANDWORLDVAR, PCD_ANDGLOBALVAR, PCD_ANDMAPARRAY, PCD_ANDWORLDARRAY, PCD_ANDGLOBALARRAY, PCD_ANDSCRIPTARRAY }, + { PCD_EORSCRIPTVAR, PCD_EORMAPVAR, PCD_EORWORLDVAR, PCD_EORGLOBALVAR, PCD_EORMAPARRAY, PCD_EORWORLDARRAY, PCD_EORGLOBALARRAY, PCD_EORSCRIPTARRAY }, + { PCD_ORSCRIPTVAR, PCD_ORMAPVAR, PCD_ORWORLDVAR, PCD_ORGLOBALVAR, PCD_ORMAPARRAY, PCD_ORWORLDARRAY, PCD_ORGLOBALARRAY, PCD_ORSCRIPTARRAY }, + { PCD_LSSCRIPTVAR, PCD_LSMAPVAR, PCD_LSWORLDVAR, PCD_LSGLOBALVAR, PCD_LSMAPARRAY, PCD_LSWORLDARRAY, PCD_LSGLOBALARRAY, PCD_LSSCRIPTARRAY }, + { PCD_RSSCRIPTVAR, PCD_RSMAPVAR, PCD_RSWORLDVAR, PCD_RSGLOBALVAR, PCD_RSMAPARRAY, PCD_RSWORLDARRAY, PCD_RSGLOBALARRAY, PCD_RSSCRIPTARRAY } }; for(i = 0; i < ARRAY_SIZE(tokenLookup); ++i) @@ -3592,7 +3575,7 @@ static void ExprFactor(void) if(sym->type != SY_SCRIPTVAR && sym->type != SY_MAPVAR && sym->type != SY_WORLDVAR && sym->type != SY_GLOBALVAR && sym->type != SY_MAPARRAY && sym->type != SY_WORLDARRAY - && sym->type != SY_GLOBALARRAY) + && sym->type != SY_GLOBALARRAY && sym->type != SY_SCRIPTARRAY) { ERR_Error(ERR_INCDEC_OP_ON_NON_VAR, YES); } @@ -3600,7 +3583,7 @@ static void ExprFactor(void) { TK_NextToken(); if(sym->type == SY_MAPARRAY || sym->type == SY_WORLDARRAY - || sym->type == SY_GLOBALARRAY) + || sym->type == SY_GLOBALARRAY || sym->type == SY_SCRIPTARRAY) { ParseArrayIndices(sym, sym->info.array.ndim); PC_AppendCmd(PCD_DUP); @@ -3626,6 +3609,7 @@ static void ExprFactor(void) case SY_SCRIPTALIAS: // FIXME break; + case SY_SCRIPTARRAY: case SY_MAPARRAY: case SY_WORLDARRAY: case SY_GLOBALARRAY: @@ -3637,7 +3621,7 @@ static void ExprFactor(void) case SY_WORLDVAR: case SY_GLOBALVAR: if(sym->type != SY_MAPARRAY && sym->type != SY_WORLDARRAY - && sym->type != SY_GLOBALARRAY) + && sym->type != SY_GLOBALARRAY && sym->type != SY_SCRIPTARRAY) { TK_NextToken(); if(tk_Token == TK_LBRACKET) @@ -3651,7 +3635,7 @@ static void ExprFactor(void) } if((tk_Token == TK_INC || tk_Token == TK_DEC) && (sym->type == SY_MAPARRAY || sym->type == SY_WORLDARRAY - || sym->type == SY_GLOBALARRAY)) + || sym->type == SY_GLOBALARRAY || sym->type == SY_SCRIPTARRAY)) { PC_AppendCmd(PCD_DUP); } @@ -3660,7 +3644,7 @@ static void ExprFactor(void) if(tk_Token == TK_INC || tk_Token == TK_DEC) { if(sym->type == SY_MAPARRAY || sym->type == SY_WORLDARRAY - || sym->type == SY_GLOBALARRAY) + || sym->type == SY_GLOBALARRAY || sym->type == SY_SCRIPTARRAY) { PC_AppendCmd(PCD_SWAP); } @@ -3966,6 +3950,8 @@ static pcd_t GetPushVarPCD(symbolType_t symType) return PCD_PUSHWORLDVAR; case SY_GLOBALVAR: return PCD_PUSHGLOBALVAR; + case SY_SCRIPTARRAY: + return PCD_PUSHSCRIPTARRAY; case SY_MAPARRAY: return PCD_PUSHMAPARRAY; case SY_WORLDARRAY: @@ -3998,6 +3984,7 @@ static pcd_t GetIncDecPCD(tokenType_t token, symbolType_t symbol) { TK_INC, SY_MAPVAR, PCD_INCMAPVAR }, { TK_INC, SY_WORLDVAR, PCD_INCWORLDVAR }, { TK_INC, SY_GLOBALVAR, PCD_INCGLOBALVAR }, + { TK_INC, SY_SCRIPTARRAY, PCD_INCSCRIPTARRAY }, { TK_INC, SY_MAPARRAY, PCD_INCMAPARRAY }, { TK_INC, SY_WORLDARRAY, PCD_INCWORLDARRAY }, { TK_INC, SY_GLOBALARRAY, PCD_INCGLOBALARRAY }, @@ -4006,6 +3993,7 @@ static pcd_t GetIncDecPCD(tokenType_t token, symbolType_t symbol) { TK_DEC, SY_MAPVAR, PCD_DECMAPVAR }, { TK_DEC, SY_WORLDVAR, PCD_DECWORLDVAR }, { TK_DEC, SY_GLOBALVAR, PCD_DECGLOBALVAR }, + { TK_DEC, SY_SCRIPTARRAY, PCD_DECSCRIPTARRAY }, { TK_DEC, SY_MAPARRAY, PCD_DECMAPARRAY }, { TK_DEC, SY_WORLDARRAY, PCD_DECWORLDARRAY }, { TK_DEC, SY_GLOBALARRAY, PCD_DECGLOBALARRAY }, @@ -4024,6 +4012,91 @@ static pcd_t GetIncDecPCD(tokenType_t token, symbolType_t symbol) return PCD_NOP; } +//========================================================================== +// +// ParseArrayDims +// +//========================================================================== + +static void ParseArrayDims(int *size_p, int *ndim_p, int dims[MAX_ARRAY_DIMS]) +{ + int size = 0; + int ndim = 0; + memset(dims, 0, sizeof(dims)); + + while(tk_Token == TK_LBRACKET) + { + if(ndim == MAX_ARRAY_DIMS) + { + ERR_Error(ERR_TOO_MANY_ARRAY_DIMS, YES); + do + { + TK_NextToken(); + } while(tk_Token != TK_COMMA && tk_Token != TK_SEMICOLON); + break; + } + TK_NextToken(); + if (tk_Token == TK_RBRACKET) + { + ERR_Error(ERR_NEED_ARRAY_SIZE, YES); + } + else + { + dims[ndim] = EvalConstExpression(); + if(dims[ndim] == 0) + { + ERR_Error(ERR_ZERO_DIMENSION, YES); + dims[ndim] = 1; + } + if(ndim == 0) + { + size = dims[ndim]; + } + else + { + size *= dims[ndim]; + } + } + ndim++; + TK_TokenMustBe(TK_RBRACKET, ERR_MISSING_RBRACKET); + TK_NextToken(); + } + if(pc_EnforceHexen) + { + TK_Undo(); // backup so error pointer is on last bracket instead of following token + ERR_Error(ERR_HEXEN_COMPAT, YES); + TK_NextToken(); + } + *size_p = size; + *ndim_p = ndim; +} + +static void SymToArray(int symtype, symbolNode_t *sym, int index, int size, int ndim, int dims[MAX_ARRAY_DIMS]) +{ + int i; + + MS_Message(MSG_DEBUG, "%s changed to an array of size %d\n", sym->name, size); + sym->type = symtype; + sym->info.array.index = index; + sym->info.array.ndim = ndim; + sym->info.array.size = size; + if(ndim > 0) + { + sym->info.array.dimensions[ndim-1] = 1; + for(i = ndim - 2; i >= 0; --i) + { + sym->info.array.dimensions[i] = + sym->info.array.dimensions[i+1] * dims[i+1]; + } + } + MS_Message(MSG_DEBUG, " - with multipliers "); + for(i = 0; i < ndim; ++i) + { + MS_Message(MSG_DEBUG, "[%d]", sym->info.array.dimensions[i]); + } + MS_Message(MSG_DEBUG, "\n"); +} + //========================================================================== // // ParseArrayIndices @@ -4043,8 +4116,8 @@ static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices) while(tk_Token == TK_LBRACKET) { TK_NextToken(); - if((sym->type == SY_MAPARRAY && i == requiredIndices) || - (sym->type != SY_MAPARRAY && i > 0)) + if(((sym->type == SY_MAPARRAY || sym->type == SY_SCRIPTARRAY) && i == requiredIndices) || + (sym->type != SY_MAPARRAY && sym->type != SY_SCRIPTARRAY && i > 0)) { if (!warned) { @@ -4096,6 +4169,12 @@ static void ParseArrayIndices(symbolNode_t *sym, int requiredIndices) } } +//========================================================================== +// +// ProcessArrayLevel +// +//========================================================================== + static void ProcessArrayLevel(int level, int *entry, int ndim, int dims[MAX_ARRAY_DIMS], int muls[MAX_ARRAY_DIMS], char *name) { @@ -4215,6 +4294,112 @@ static void InitializeArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int siz } } +//========================================================================== +// +// ProcessScriptArrayLevel +// +//========================================================================== + +static void ProcessScriptArrayLevel(int level, symbolNode_t *sym, int ndim, + int dims[MAX_ARRAY_DIMS], int muls[MAX_ARRAY_DIMS], char *name) +{ + int warned_too_many = NO; + int i; + int loc = 0; + + for(i = 0; ; ++i) + { + if(tk_Token == TK_COMMA) + { + loc += muls[level-1]; + TK_NextToken(); + } + else if(tk_Token == TK_RBRACE) + { + TK_NextToken(); + return; + } + else + { + if(level == ndim) + { + if(tk_Token == TK_LBRACE) + { + ERR_Error(ERR_TOO_MANY_DIM_USED, YES, name, ndim); + SkipBraceBlock(0); + TK_NextToken(); + loc++; + } + else + { + if(i >= dims[level - 1] && !warned_too_many) + { + warned_too_many = YES; + ERR_Error(ERR_TOO_MANY_ARRAY_INIT, YES); + } + PC_AppendPushVal(loc + i); + EvalExpression(); + PC_AppendCmd(PCD_ASSIGNSCRIPTARRAY); + PC_AppendShrink(sym->info.array.index); + } + } + else + { + //Bugfix for r3226 by Zom-B + if (i >= dims[level - 1]) + { + if (!warned_too_many) + { + warned_too_many = YES; + ERR_Error(ERR_TOO_MANY_ARRAY_INIT, YES); + } + } + TK_TokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR); + TK_NextToken(); + ProcessScriptArrayLevel(level+1, sym, ndim, dims, muls, name); + assert(level > 0); + loc += muls[level-1]; + } + if(i < dims[level-1]-1) + { + if(tk_Token != TK_RBRACE) + { + TK_TokenMustBe(TK_COMMA, ERR_MISSING_COMMA); + TK_NextToken(); + } + } + else + { + if(tk_Token != TK_COMMA) + { + TK_TokenMustBe(TK_RBRACE, ERR_MISSING_RBRACE_ARR); + } + else + { + TK_NextToken(); + } + } + } + } + TK_TokenMustBe(TK_RBRACE, ERR_MISSING_RBRACE_ARR); + TK_NextToken(); +} + +//========================================================================== +// +// InitializeScriptArray +// +//========================================================================== + +static void InitializeScriptArray(symbolNode_t *sym, int dims[MAX_ARRAY_DIMS], int size) +{ + TK_NextTokenMustBe(TK_LBRACE, ERR_MISSING_LBRACE_ARR); + TK_NextToken(); + ArrayHasStrings = NO; + ProcessScriptArrayLevel(1, sym, sym->info.array.ndim, dims, + sym->info.array.dimensions, sym->name); +} + //========================================================================== // // DemandSymbol diff --git a/pcode.c b/pcode.c index 9d5fd41..29edf17 100644 --- a/pcode.c +++ b/pcode.c @@ -28,11 +28,13 @@ typedef struct scriptInfo_s S_WORD number; U_BYTE type; U_BYTE argCount; + U_BYTE arrayCount; U_WORD varCount; U_WORD flags; int address; int srcLine; boolean imported; + int arraySizes[MAX_SCRIPT_ARRAYS]; } scriptInfo_t; typedef struct functionInfo_s @@ -40,8 +42,10 @@ typedef struct functionInfo_s U_BYTE hasReturnValue; U_BYTE argCount; U_BYTE localCount; + U_BYTE arrayCount; int address; int name; + int arraySizes[MAX_SCRIPT_ARRAYS]; } functionInfo_t; typedef struct mapVarInfo_s @@ -103,6 +107,7 @@ static int PushByteAddr; static char Imports[MAX_IMPORTS][9]; static int NumImports; static boolean HaveExtendedScripts; +static boolean HaveScriptArrays; static char *PCDNames[PCODE_COMMAND_COUNT] = { @@ -476,6 +481,24 @@ static char *PCDNames[PCODE_COMMAND_COUNT] = "PCD_CALLSTACK", // from Eternity "PCD_SCRIPTWAITNAMED", "PCD_TRANSLATIONRANGE3", + "PCD_GOTOSTACK", + "PCD_ASSIGNSCRIPTARRAY", + "PCD_PUSHSCRIPTARRAY", + "PCD_ADDSCRIPTARRAY", + "PCD_SUBSCRIPTARRAY", + "PCD_MULSCRIPTARRAY", + "PCD_DIVSCRIPTARRAY", + "PCD_MODSCRIPTARRAY", + "PCD_INCSCRIPTARRAY", + "PCD_DECSCRIPTARRAY", + "PCD_ANDSCRIPTARRAY", + "PCD_EORSCRIPTARRAY", + "PCD_ORSCRIPTARRAY", + "PCD_LSSCRIPTARRAY", + "PCD_RSSCRIPTARRAY", + "PCD_PRINTSCRIPTCHARARRAY", + "PCD_PRINTSCRIPTCHRANGE", + "PCD_STRCPYTOSCRIPTCHRANGE", }; // CODE -------------------------------------------------------------------- @@ -521,9 +544,10 @@ void PC_CloseObject(void) { PC_AppendByte (0); } - if(!pc_NoShrink || (NumLanguages > 1) || (NumStringLists > 0) || + if(!pc_NoShrink || (NumStringLists > 0) || (pc_FunctionCount > 0) || MapVariablesInit || NumArrays != 0 || - pc_EncryptStrings || NumImports != 0 || HaveExtendedScripts) + pc_EncryptStrings || NumImports != 0 || HaveExtendedScripts || + HaveScriptArrays) { if(pc_EnforceHexen) { @@ -672,9 +696,25 @@ static void CloseNew(void) } } + // Add chunks for scripts with arrays + for(i = 0; i < pc_ScriptCount; ++i) + { + if(ScriptInfo[i].arrayCount) + { + PC_Append("SARY", 4); + PC_AppendInt(2 + ScriptInfo[i].arrayCount * 4); + PC_AppendWord(ScriptInfo[i].number); + for(j = 0; j < ScriptInfo[i].arrayCount; ++j) + { + PC_AppendInt(ScriptInfo[i].arraySizes[j]); + } + } + } + // Write the string table for named scripts. STR_WriteListChunk(STRLIST_NAMEDSCRIPTS, MAKE4CC('S','N','A','M'), NO); + // Write the functions provided by this file. if(pc_FunctionCount > 0) { PC_Append("FUNC", 4); @@ -694,16 +734,25 @@ static void CloseNew(void) STR_WriteListChunk(STRLIST_FUNCTIONS, MAKE4CC('F','N','A','M'), NO); } - if(NumLanguages > 1) + // Add chunks for functions with arrays + for(i = 0; i < pc_FunctionCount; ++i) { - for(i = 0; i < NumLanguages; i++) + if(FunctionInfo[i].arrayCount) { - STR_WriteChunk(i, pc_EncryptStrings); + PC_Append("FARY", 4); + PC_AppendInt(2 + FunctionInfo[i].arrayCount * 4); + PC_AppendWord((U_WORD)i); + for(j = 0; j < FunctionInfo[i].arrayCount; ++j) + { + PC_AppendInt(FunctionInfo[i].arraySizes[j]); + } } } - else if(STR_ListSize(0) > 0) + + + if(STR_ListSize() > 0) { - STR_WriteChunk(0, pc_EncryptStrings); + STR_WriteChunk(pc_EncryptStrings); } STR_WriteListChunk(STRLIST_PICS, MAKE4CC('P','I','C','S'), NO); @@ -1426,6 +1475,7 @@ void PC_AddScript(int number, int type, int flags, int argCount) script->flags = flags; script->srcLine = tk_Line; script->imported = (ImportMode == IMPORT_Importing) ? YES : NO; + script->arrayCount = 0; pc_ScriptCount++; } } @@ -1439,7 +1489,7 @@ void PC_AddScript(int number, int type, int flags, int argCount) // //========================================================================== -void PC_SetScriptVarCount(int number, int type, int varCount) +void PC_SetScriptVarCount(int number, int type, int varCount, int arrayCount, int *arraySizes) { int i; @@ -1448,6 +1498,12 @@ void PC_SetScriptVarCount(int number, int type, int varCount) if(ScriptInfo[i].number == number && ScriptInfo[i].type == type) { ScriptInfo[i].varCount = varCount; + if (arrayCount > 0 && arrayCount < MAX_SCRIPT_ARRAYS) + { + ScriptInfo[i].arrayCount = (U_BYTE)arrayCount; + memcpy(ScriptInfo[i].arraySizes, arraySizes, arrayCount * sizeof(int)); + HaveScriptArrays = YES; + } break; } } @@ -1459,7 +1515,7 @@ void PC_SetScriptVarCount(int number, int type, int varCount) // //========================================================================== -void PC_AddFunction(symbolNode_t *sym) +void PC_AddFunction(symbolNode_t *sym, int arrayCount, int *arraySizes) { functionInfo_t *function; @@ -1467,11 +1523,6 @@ void PC_AddFunction(symbolNode_t *sym) { ERR_Error(ERR_TOO_MANY_FUNCTIONS, YES, NULL); } - else if(pc_EnforceHexen) - { - ERR_Error(ERR_HEXEN_COMPAT, YES); - } - function = &FunctionInfo[pc_FunctionCount]; function->hasReturnValue = (U_BYTE)sym->info.scriptFunc.hasReturnValue; function->argCount = (U_BYTE)sym->info.scriptFunc.argCount; @@ -1479,6 +1530,16 @@ void PC_AddFunction(symbolNode_t *sym) function->name = STR_AppendToList (STRLIST_FUNCTIONS, sym->name); function->address = sym->info.scriptFunc.address; sym->info.scriptFunc.funcNumber = pc_FunctionCount; + if (arrayCount > 0 && arrayCount < MAX_SCRIPT_ARRAYS) + { + function->arrayCount = (U_BYTE)arrayCount; + memcpy(function->arraySizes, arraySizes, arrayCount * sizeof(int)); + HaveScriptArrays = YES; + } + else + { + function->arrayCount = 0; + } pc_FunctionCount++; } diff --git a/pcode.h b/pcode.h index fdad84e..18f28ba 100644 --- a/pcode.h +++ b/pcode.h @@ -425,6 +425,24 @@ typedef enum PCD_CALLSTACK, // from Eternity PCD_SCRIPTWAITNAMED, PCD_TRANSLATIONRANGE3, + PCD_GOTOSTACK, + PCD_ASSIGNSCRIPTARRAY, + PCD_PUSHSCRIPTARRAY, + PCD_ADDSCRIPTARRAY, + PCD_SUBSCRIPTARRAY, + PCD_MULSCRIPTARRAY, + PCD_DIVSCRIPTARRAY, + PCD_MODSCRIPTARRAY, + PCD_INCSCRIPTARRAY, + PCD_DECSCRIPTARRAY, + PCD_ANDSCRIPTARRAY, + PCD_EORSCRIPTARRAY, + PCD_ORSCRIPTARRAY, + PCD_LSSCRIPTARRAY, + PCD_RSSCRIPTARRAY, + PCD_PRINTSCRIPTCHARARRAY, + PCD_PRINTSCRIPTCHRANGE, + PCD_STRCPYTOSCRIPTCHRANGE, PCODE_COMMAND_COUNT } pcd_t; @@ -452,8 +470,8 @@ void PC_Skip(size_t size); //void PC_SkipWord(void); void PC_SkipInt(void); void PC_AddScript(int number, int type, int flags, int argCount); -void PC_SetScriptVarCount(int number, int type, int varCount); -void PC_AddFunction(struct symbolNode_s *sym); +void PC_SetScriptVarCount(int number, int type, int varCount, int arrayCount, int *arraySizes); +void PC_AddFunction(struct symbolNode_s *sym, int arrayCount, int *sizes); void PC_PutMapVariable(int index, int value); void PC_NameMapVariable(int index, struct symbolNode_s *sym); void PC_AddArray(int index, int size); diff --git a/strlist.c b/strlist.c index 6fda296..daec46c 100644 --- a/strlist.c +++ b/strlist.c @@ -31,12 +31,6 @@ typedef struct stringInfo_t strings[MAX_STRINGS]; } stringList_t; -typedef struct -{ - char name[4]; - stringList_t list; -} languageInfo_t; - // EXTERNAL FUNCTION PROTOTYPES -------------------------------------------- // PUBLIC FUNCTION PROTOTYPES ---------------------------------------------- @@ -57,7 +51,7 @@ int NumLanguages, NumStringLists; // PRIVATE DATA DEFINITIONS ------------------------------------------------ -static languageInfo_t *LanguageInfo[MAX_LANGUAGES]; +static stringList_t MainStringList; static stringList_t *StringLists[NUM_STRLISTS]; // CODE -------------------------------------------------------------------- @@ -70,54 +64,19 @@ static stringList_t *StringLists[NUM_STRLISTS]; void STR_Init(void) { - NumLanguages = NumStringLists = 0; - STR_FindLanguage(NULL); // Default language is always number 0 + NumStringLists = 0; + MainStringList.stringCount = 0; } //========================================================================== // -// STR_FindLanguage +// STR_Get // //========================================================================== -int STR_FindLanguage(char *name) +char *STR_Get(int num) { - int i; - - if (name == NULL) - { - if (NumLanguages > 0) - { - return 0; - } - i = 0; - } - else - { - for(i = 0; i < NumLanguages; i++) - { - if (strcmp (name, LanguageInfo[i]->name) == 0) - { - return i; - } - } - } - if(i == NumLanguages) - { - LanguageInfo[i] = MS_Alloc(sizeof(languageInfo_t), ERR_OUT_OF_MEMORY); - memset(LanguageInfo[i]->name, 0, 4); - if(name != NULL) - { - strncpy(LanguageInfo[i]->name, name, 3); - } - LanguageInfo[i]->list.stringCount = 0; - NumLanguages++; - if(NumLanguages > 1 && pc_EnforceHexen) - { - ERR_Error(ERR_HEXEN_COMPAT, YES); - } - } - return i; + return MainStringList.strings[num].name; } //========================================================================== @@ -128,18 +87,7 @@ int STR_FindLanguage(char *name) int STR_Find(char *name) { - return STR_FindInLanguage(0, name); -} - -//========================================================================== -// -// STR_FindInLanguage -// -//========================================================================== - -int STR_FindInLanguage(int language, char *name) -{ - return STR_FindInSomeList (&LanguageInfo[language]->list, name); + return STR_FindInSomeList(&MainStringList, name); } //========================================================================== @@ -258,10 +206,6 @@ int STR_AppendToList(int list, char *name) StringLists[list] = MS_Alloc(sizeof(stringList_t), ERR_OUT_OF_MEMORY); StringLists[list]->stringCount = 0; NumStringLists++; - if(pc_EnforceHexen) - { - ERR_Error(ERR_HEXEN_COMPAT, YES); - } } return STR_PutStringInSomeList(StringLists[list], StringLists[list]->stringCount, name); } @@ -313,9 +257,9 @@ static int STR_PutStringInSomeList(stringList_t *list, int index, char *name) // //========================================================================== -int STR_ListSize(int list) +int STR_ListSize() { - return LanguageInfo[list]->list.stringCount; + return MainStringList.stringCount; } //========================================================================== @@ -332,10 +276,10 @@ void STR_WriteStrings(void) U_INT pad; MS_Message(MSG_DEBUG, "---- STR_WriteStrings ----\n"); - for(i = 0; i < LanguageInfo[0]->list.stringCount; i++) + for(i = 0; i < MainStringList.stringCount; i++) { - LanguageInfo[0]->list.strings[i].address = pc_Address; - PC_AppendString(LanguageInfo[0]->list.strings[i].name); + MainStringList.strings[i].address = pc_Address; + PC_AppendString(MainStringList.strings[i].name); } if(pc_Address%4 != 0) { // Need to align @@ -355,10 +299,10 @@ void STR_WriteList(void) int i; MS_Message(MSG_DEBUG, "---- STR_WriteList ----\n"); - PC_AppendInt((U_INT)LanguageInfo[0]->list.stringCount); - for(i = 0; i < LanguageInfo[0]->list.stringCount; i++) + PC_AppendInt((U_INT)MainStringList.stringCount); + for(i = 0; i < MainStringList.stringCount; i++) { - PC_AppendInt((U_INT)LanguageInfo[0]->list.strings[i].address); + PC_AppendInt((U_INT)MainStringList.strings[i].address); } } @@ -368,20 +312,19 @@ void STR_WriteList(void) // //========================================================================== -void STR_WriteChunk(int language, boolean encrypt) +void STR_WriteChunk(boolean encrypt) { - languageInfo_t *lang = LanguageInfo[language]; int lenadr; - MS_Message(MSG_DEBUG, "---- STR_WriteChunk %d ----\n", language); + MS_Message(MSG_DEBUG, "---- STR_WriteChunk ----\n"); PC_Append(encrypt ? "STRE" : "STRL", 4); lenadr = pc_Address; PC_SkipInt(); - PC_Append(&lang->name, 4); - PC_AppendInt(lang->list.stringCount); - PC_AppendInt(0); // Used in-game for stringing lists together + PC_AppendInt(0); + PC_AppendInt(MainStringList.stringCount); + PC_AppendInt(0); // Used in-game for stringing lists together (NOT!) - DumpStrings (&lang->list, lenadr, NO, encrypt); + DumpStrings (&MainStringList, lenadr, NO, encrypt); } //========================================================================== diff --git a/strlist.h b/strlist.h index 40d7f37..668d264 100644 --- a/strlist.h +++ b/strlist.h @@ -20,20 +20,19 @@ void STR_Init(void); int STR_Find(char *name); +char *STR_Get(int index); void STR_WriteStrings(void); void STR_WriteList(void); -int STR_FindLanguage(char *name); -int STR_FindInLanguage(int language, char *name); int STR_FindInList(int list, char *name); int STR_FindInListInsensitive(int list, char *name); int STR_AppendToList(int list, char *name); const char *STR_GetString(int list, int index); -void STR_WriteChunk(int language, boolean encrypt); +void STR_WriteChunk(boolean encrypt); void STR_WriteListChunk(int list, int id, boolean quad); -int STR_ListSize(int list); +int STR_ListSize(); // PUBLIC DATA DECLARATIONS ------------------------------------------------ -extern int NumLanguages, NumStringLists; +extern int NumStringLists; #endif diff --git a/symbol.c b/symbol.c index 3c6a6d0..e5dbf46 100644 --- a/symbol.c +++ b/symbol.c @@ -210,6 +210,7 @@ static char *SymbolTypeNames[] = "SY_MAPVAR", "SY_WORLDVAR", "SY_GLOBALVAR", + "SY_SCRIPTARRAY", "SY_MAPARRAY", "SY_WORLDARRAY", "SY_GLOBALARRAY", @@ -279,7 +280,7 @@ symbolNode_t *SY_FindGlobal(char *name) sym->unused = NO; if(sym->type == SY_SCRIPTFUNC) { - PC_AddFunction(sym); + PC_AddFunction(sym, 0, NULL); } else if(sym->type == SY_MAPVAR) { @@ -523,6 +524,11 @@ static void DeleteNode(symbolNode_t *node, symbolNode_t **parent_p) symbolNode_t **temp; char *nametemp; + if(node->type == SY_CONSTANT && node->info.constant.strValue != NULL) + { + free(node->info.constant.strValue); + node->info.constant.strValue = NULL; + } if(node->left == NULL) { *parent_p = node->right; diff --git a/symbol.h b/symbol.h index 104116e..901ff46 100644 --- a/symbol.h +++ b/symbol.h @@ -28,6 +28,7 @@ typedef enum SY_MAPVAR, SY_WORLDVAR, SY_GLOBALVAR, + SY_SCRIPTARRAY, SY_MAPARRAY, SY_WORLDARRAY, SY_GLOBALARRAY, @@ -64,6 +65,7 @@ typedef struct typedef struct { int value; + char *strValue; int fileDepth; } symConstant_t; diff --git a/token.c b/token.c index 38546a2..216ef6b 100644 --- a/token.c +++ b/token.c @@ -591,6 +591,7 @@ tokenType_t TK_NextToken(void) AlreadyGot = FALSE; return tk_Token; } + tk_String = TokenStringBuffer; validToken = NO; PrevMasterSourcePos = MasterSourcePos; do @@ -914,8 +915,17 @@ static boolean CheckForConstant(void) { return FALSE; } - tk_Token = TK_NUMBER; - tk_Number = sym->info.constant.value; + if(sym->info.constant.strValue != NULL) + { + MS_Message(MSG_DEBUG, "Constant string: %s\n", sym->info.constant.strValue); + tk_Token = TK_STRING; + tk_String = sym->info.constant.strValue; + } + else + { + tk_Token = TK_NUMBER; + tk_Number = sym->info.constant.value; + } return TRUE; }