mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-02-13 03:33:48 +00:00
Merging
This commit is contained in:
parent
f51ce3084f
commit
d666322a1b
23 changed files with 9203 additions and 7477 deletions
|
|
@ -40,13 +40,13 @@ namespace Compiler
|
|||
F64 consoleStringToNumber(const char *str, StringTableEntry file, U32 line)
|
||||
{
|
||||
F64 val = dAtof(str);
|
||||
if(val != 0)
|
||||
if (val != 0)
|
||||
return val;
|
||||
else if(!dStricmp(str, "true"))
|
||||
else if (!dStricmp(str, "true"))
|
||||
return 1;
|
||||
else if(!dStricmp(str, "false"))
|
||||
else if (!dStricmp(str, "false"))
|
||||
return 0;
|
||||
else if(file)
|
||||
else if (file)
|
||||
{
|
||||
Con::warnf(ConsoleLogEntry::General, "%s (%d): string always evaluates to 0.", file, line);
|
||||
return 0;
|
||||
|
|
@ -57,7 +57,7 @@ namespace Compiler
|
|||
//------------------------------------------------------------
|
||||
|
||||
CompilerStringTable *gCurrentStringTable, gGlobalStringTable, gFunctionStringTable;
|
||||
CompilerFloatTable *gCurrentFloatTable, gGlobalFloatTable, gFunctionFloatTable;
|
||||
CompilerFloatTable *gCurrentFloatTable, gGlobalFloatTable, gFunctionFloatTable;
|
||||
DataChunker gConsoleAllocator;
|
||||
CompilerIdentTable gIdentTable;
|
||||
|
||||
|
|
@ -71,16 +71,16 @@ namespace Compiler
|
|||
*ptr = (U32)ste;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void compileSTEtoCode(StringTableEntry ste, U32 ip, U32 *ptr)
|
||||
{
|
||||
if(ste)
|
||||
if (ste)
|
||||
getIdentTable().add(ste, ip);
|
||||
*ptr = 0;
|
||||
*(ptr+1) = 0;
|
||||
*(ptr + 1) = 0;
|
||||
}
|
||||
|
||||
void (*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr) = evalSTEtoCode;
|
||||
|
||||
void(*STEtoCode)(StringTableEntry ste, U32 ip, U32 *ptr) = evalSTEtoCode;
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
|
|
@ -88,23 +88,23 @@ namespace Compiler
|
|||
|
||||
//------------------------------------------------------------
|
||||
|
||||
CompilerStringTable *getCurrentStringTable() { return gCurrentStringTable; }
|
||||
CompilerStringTable &getGlobalStringTable() { return gGlobalStringTable; }
|
||||
CompilerStringTable *getCurrentStringTable() { return gCurrentStringTable; }
|
||||
CompilerStringTable &getGlobalStringTable() { return gGlobalStringTable; }
|
||||
CompilerStringTable &getFunctionStringTable() { return gFunctionStringTable; }
|
||||
|
||||
void setCurrentStringTable (CompilerStringTable* cst) { gCurrentStringTable = cst; }
|
||||
void setCurrentStringTable(CompilerStringTable* cst) { gCurrentStringTable = cst; }
|
||||
|
||||
CompilerFloatTable *getCurrentFloatTable() { return gCurrentFloatTable; }
|
||||
CompilerFloatTable &getGlobalFloatTable() { return gGlobalFloatTable; }
|
||||
CompilerFloatTable &getFunctionFloatTable() { return gFunctionFloatTable; }
|
||||
CompilerFloatTable *getCurrentFloatTable() { return gCurrentFloatTable; }
|
||||
CompilerFloatTable &getGlobalFloatTable() { return gGlobalFloatTable; }
|
||||
CompilerFloatTable &getFunctionFloatTable() { return gFunctionFloatTable; }
|
||||
|
||||
void setCurrentFloatTable (CompilerFloatTable* cst) { gCurrentFloatTable = cst; }
|
||||
void setCurrentFloatTable(CompilerFloatTable* cst) { gCurrentFloatTable = cst; }
|
||||
|
||||
CompilerIdentTable &getIdentTable() { return gIdentTable; }
|
||||
|
||||
void precompileIdent(StringTableEntry ident)
|
||||
{
|
||||
if(ident)
|
||||
if (ident)
|
||||
gGlobalStringTable.add(ident);
|
||||
}
|
||||
|
||||
|
|
@ -119,8 +119,8 @@ namespace Compiler
|
|||
getIdentTable().reset();
|
||||
}
|
||||
|
||||
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
|
||||
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
|
||||
void *consoleAlloc(U32 size) { return gConsoleAllocator.alloc(size); }
|
||||
void consoleAllocReset() { gConsoleAllocator.freeBlocks(); }
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -135,36 +135,40 @@ U32 CompilerStringTable::add(const char *str, bool caseSens, bool tag)
|
|||
{
|
||||
// Is it already in?
|
||||
Entry **walk;
|
||||
for(walk = &list; *walk; walk = &((*walk)->next))
|
||||
for (walk = &list; *walk; walk = &((*walk)->next))
|
||||
{
|
||||
if((*walk)->tag != tag)
|
||||
if ((*walk)->tag != tag)
|
||||
continue;
|
||||
|
||||
if(caseSens)
|
||||
if (caseSens)
|
||||
{
|
||||
if(!dStrcmp((*walk)->string, str))
|
||||
if (!dStrcmp((*walk)->string, str))
|
||||
return (*walk)->start;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!dStricmp((*walk)->string, str))
|
||||
if (!dStricmp((*walk)->string, str))
|
||||
return (*walk)->start;
|
||||
}
|
||||
}
|
||||
|
||||
// Write it out.
|
||||
Entry *newStr = (Entry *) consoleAlloc(sizeof(Entry));
|
||||
Entry *newStr = (Entry *)consoleAlloc(sizeof(Entry));
|
||||
*walk = newStr;
|
||||
newStr->next = NULL;
|
||||
newStr->start = totalLen;
|
||||
U32 len = dStrlen(str) + 1;
|
||||
if(tag && len < 7) // alloc space for the numeric tag 1 for tag, 5 for # and 1 for nul
|
||||
if (tag && len < 7) // alloc space for the numeric tag 1 for tag, 5 for # and 1 for nul
|
||||
len = 7;
|
||||
totalLen += len;
|
||||
newStr->string = (char *) consoleAlloc(len);
|
||||
newStr->string = (char *)consoleAlloc(len);
|
||||
newStr->len = len;
|
||||
newStr->tag = tag;
|
||||
dStrcpy(newStr->string, str);
|
||||
|
||||
// Put into the hash table.
|
||||
hashTable[str] = newStr;
|
||||
|
||||
return newStr->start;
|
||||
}
|
||||
|
||||
|
|
@ -189,7 +193,8 @@ void CompilerStringTable::reset()
|
|||
char *CompilerStringTable::build()
|
||||
{
|
||||
char *ret = new char[totalLen];
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
dMemset(ret, 0, totalLen);
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
dStrcpy(ret + walk->start, walk->string);
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -197,7 +202,7 @@ char *CompilerStringTable::build()
|
|||
void CompilerStringTable::write(Stream &st)
|
||||
{
|
||||
st.write(totalLen);
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
st.write(walk->len, walk->string);
|
||||
}
|
||||
|
||||
|
|
@ -207,15 +212,15 @@ U32 CompilerFloatTable::add(F64 value)
|
|||
{
|
||||
Entry **walk;
|
||||
U32 i = 0;
|
||||
for(walk = &list; *walk; walk = &((*walk)->next), i++)
|
||||
if(value == (*walk)->val)
|
||||
for (walk = &list; *walk; walk = &((*walk)->next), i++)
|
||||
if (value == (*walk)->val)
|
||||
return i;
|
||||
Entry *newFloat = (Entry *) consoleAlloc(sizeof(Entry));
|
||||
Entry *newFloat = (Entry *)consoleAlloc(sizeof(Entry));
|
||||
newFloat->val = value;
|
||||
newFloat->next = NULL;
|
||||
count++;
|
||||
*walk = newFloat;
|
||||
return count-1;
|
||||
return count - 1;
|
||||
}
|
||||
void CompilerFloatTable::reset()
|
||||
{
|
||||
|
|
@ -226,7 +231,7 @@ F64 *CompilerFloatTable::build()
|
|||
{
|
||||
F64 *ret = new F64[count];
|
||||
U32 i = 0;
|
||||
for(Entry *walk = list; walk; walk = walk->next, i++)
|
||||
for (Entry *walk = list; walk; walk = walk->next, i++)
|
||||
ret[i] = walk->val;
|
||||
return ret;
|
||||
}
|
||||
|
|
@ -234,7 +239,7 @@ F64 *CompilerFloatTable::build()
|
|||
void CompilerFloatTable::write(Stream &st)
|
||||
{
|
||||
st.write(count);
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
st.write(walk->val);
|
||||
}
|
||||
|
||||
|
|
@ -248,12 +253,12 @@ void CompilerIdentTable::reset()
|
|||
void CompilerIdentTable::add(StringTableEntry ste, U32 ip)
|
||||
{
|
||||
U32 index = gGlobalStringTable.add(ste, false);
|
||||
Entry *newEntry = (Entry *) consoleAlloc(sizeof(Entry));
|
||||
Entry *newEntry = (Entry *)consoleAlloc(sizeof(Entry));
|
||||
newEntry->offset = index;
|
||||
newEntry->ip = ip;
|
||||
for(Entry *walk = list; walk; walk = walk->next)
|
||||
for (Entry *walk = list; walk; walk = walk->next)
|
||||
{
|
||||
if(walk->offset == index)
|
||||
if (walk->offset == index)
|
||||
{
|
||||
newEntry->nextIdent = walk->nextIdent;
|
||||
walk->nextIdent = newEntry;
|
||||
|
|
@ -269,24 +274,24 @@ void CompilerIdentTable::write(Stream &st)
|
|||
{
|
||||
U32 count = 0;
|
||||
Entry * walk;
|
||||
for(walk = list; walk; walk = walk->next)
|
||||
for (walk = list; walk; walk = walk->next)
|
||||
count++;
|
||||
st.write(count);
|
||||
for(walk = list; walk; walk = walk->next)
|
||||
for (walk = list; walk; walk = walk->next)
|
||||
{
|
||||
U32 ec = 0;
|
||||
Entry * el;
|
||||
for(el = walk; el; el = el->nextIdent)
|
||||
for (el = walk; el; el = el->nextIdent)
|
||||
ec++;
|
||||
st.write(walk->offset);
|
||||
st.write(ec);
|
||||
for(el = walk; el; el = el->nextIdent)
|
||||
for (el = walk; el; el = el->nextIdent)
|
||||
st.write(el->ip);
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
U8 *CodeStream::allocCode(U32 sz)
|
||||
{
|
||||
U8 *ptr = NULL;
|
||||
|
|
@ -300,12 +305,12 @@ U8 *CodeStream::allocCode(U32 sz)
|
|||
return ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CodeData *data = new CodeData;
|
||||
data->data = (U8*)dMalloc(BlockSize);
|
||||
data->size = sz;
|
||||
data->next = NULL;
|
||||
|
||||
|
||||
if (mCodeHead)
|
||||
mCodeHead->next = data;
|
||||
mCodeHead = data;
|
||||
|
|
@ -313,21 +318,21 @@ U8 *CodeStream::allocCode(U32 sz)
|
|||
mCode = data;
|
||||
return data->data;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
|
||||
{
|
||||
AssertFatal(mFixStack.size() > 0, "Fix stack mismatch");
|
||||
|
||||
U32 fixStart = mFixStack[mFixStack.size()-1];
|
||||
for (U32 i=fixStart; i<mFixList.size(); i += 2)
|
||||
|
||||
U32 fixStart = mFixStack[mFixStack.size() - 1];
|
||||
for (U32 i = fixStart; i<mFixList.size(); i += 2)
|
||||
{
|
||||
FixType type = (FixType)mFixList[i+1];
|
||||
|
||||
FixType type = (FixType)mFixList[i + 1];
|
||||
|
||||
U32 fixedIp = 0;
|
||||
bool valid = true;
|
||||
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case FIXTYPE_LOOPBLOCKSTART:
|
||||
|
|
@ -344,7 +349,7 @@ void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
|
|||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (valid)
|
||||
{
|
||||
patch(mFixList[i], fixedIp);
|
||||
|
|
@ -353,7 +358,7 @@ void CodeStream::fixLoop(U32 loopBlockStart, U32 breakPoint, U32 continuePoint)
|
|||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
|
||||
{
|
||||
// Alloc stream
|
||||
|
|
@ -361,7 +366,7 @@ void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
|
|||
*stream = new U32[mCodePos + (numLineBreaks * 2)];
|
||||
dMemset(*stream, '\0', mCodePos + (numLineBreaks * 2));
|
||||
*size = mCodePos;
|
||||
|
||||
|
||||
// Dump chunks & line breaks
|
||||
U32 outBytes = mCodePos * sizeof(U32);
|
||||
U8 *outPtr = *((U8**)stream);
|
||||
|
|
@ -372,20 +377,20 @@ void CodeStream::emitCodeStream(U32 *size, U32 **stream, U32 **lineBreaks)
|
|||
outPtr += bytesToCopy;
|
||||
outBytes -= bytesToCopy;
|
||||
}
|
||||
|
||||
|
||||
*lineBreaks = *stream + mCodePos;
|
||||
dMemcpy(*lineBreaks, mBreakLines.address(), sizeof(U32) * mBreakLines.size());
|
||||
|
||||
|
||||
// Apply patches on top
|
||||
for (U32 i=0; i<mPatchList.size(); i++)
|
||||
for (U32 i = 0; i<mPatchList.size(); i++)
|
||||
{
|
||||
PatchEntry &e = mPatchList[i];
|
||||
(*stream)[e.addr] = e.value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
|
||||
void CodeStream::reset()
|
||||
{
|
||||
mCodePos = 0;
|
||||
|
|
@ -393,7 +398,7 @@ void CodeStream::reset()
|
|||
mFixLoopStack.clear();
|
||||
mFixList.clear();
|
||||
mBreakLines.clear();
|
||||
|
||||
|
||||
// Pop down to one code block
|
||||
CodeData *itr = mCode ? mCode->next : NULL;
|
||||
while (itr != NULL)
|
||||
|
|
@ -403,7 +408,7 @@ void CodeStream::reset()
|
|||
delete(itr);
|
||||
itr = next;
|
||||
}
|
||||
|
||||
|
||||
if (mCode)
|
||||
{
|
||||
mCode->size = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue