mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 11:43:49 +00:00
Allow local variables to be used in eval.
This commit is contained in:
parent
5137e54a7c
commit
2d50f52cf1
5 changed files with 90 additions and 54 deletions
|
|
@ -34,6 +34,8 @@
|
|||
|
||||
#include "console/simBase.h"
|
||||
|
||||
extern FuncVars gEvalFuncVars;
|
||||
|
||||
namespace Compiler
|
||||
{
|
||||
|
||||
|
|
@ -86,6 +88,7 @@ namespace Compiler
|
|||
//------------------------------------------------------------
|
||||
|
||||
bool gSyntaxError = false;
|
||||
bool gIsEvalCompile = false;
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
|
|
@ -121,6 +124,7 @@ namespace Compiler
|
|||
getFunctionStringTable().reset();
|
||||
getIdentTable().reset();
|
||||
getFunctionVariableMappingTable().reset();
|
||||
gEvalFuncVars.clear();
|
||||
}
|
||||
|
||||
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
|
||||
|
|
@ -132,6 +136,44 @@ namespace Compiler
|
|||
|
||||
using namespace Compiler;
|
||||
|
||||
S32 FuncVars::assign(StringTableEntry var, TypeReq currentType, S32 lineNumber, bool isConstant)
|
||||
{
|
||||
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
|
||||
if (found != vars.end())
|
||||
{
|
||||
AssertISV(!found->second.isConstant, avar("Reassigning variable %s when it is a constant. File: %s Line : %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
|
||||
return found->second.reg;
|
||||
}
|
||||
|
||||
S32 id = counter++;
|
||||
vars[var] = { id, currentType, var, isConstant };
|
||||
variableNameMap[id] = var;
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
S32 FuncVars::lookup(StringTableEntry var, S32 lineNumber)
|
||||
{
|
||||
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
|
||||
AssertISV(found != vars.end(), avar("Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
|
||||
return found->second.reg;
|
||||
}
|
||||
|
||||
TypeReq FuncVars::lookupType(StringTableEntry var, S32 lineNumber)
|
||||
{
|
||||
std::unordered_map<StringTableEntry, Var>::iterator found = vars.find(var);
|
||||
|
||||
AssertISV(found != vars.end(), avar("Variable %s referenced before used when compiling script. File: %s Line: %d", var, CodeBlock::smCurrentParser->getCurrentFile(), lineNumber));
|
||||
return found->second.currentType;
|
||||
}
|
||||
|
||||
void FuncVars::clear()
|
||||
{
|
||||
vars.clear();
|
||||
variableNameMap.clear();
|
||||
counter = 0;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue