12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2012 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- #include "console/console.h"
- #include "console/compiler.h"
- #include "console/codeBlock.h"
- #include "console/telnetDebugger.h"
- #include "console/ast.h"
- #include "core/strings/unicode.h"
- #include "core/strings/stringFunctions.h"
- #include "core/stringTable.h"
- #include "core/stream/fileStream.h"
- using namespace Compiler;
- bool CodeBlock::smInFunction = false;
- CodeBlock * CodeBlock::smCodeBlockList = NULL;
- CodeBlock * CodeBlock::smCurrentCodeBlock = NULL;
- ConsoleParser *CodeBlock::smCurrentParser = NULL;
- //-------------------------------------------------------------------------
- CodeBlock::CodeBlock()
- {
- globalStrings = NULL;
- functionStrings = NULL;
- functionStringsMaxLen = 0;
- globalStringsMaxLen = 0;
- globalFloats = NULL;
- functionFloats = NULL;
- lineBreakPairs = NULL;
- breakList = NULL;
- breakListSize = 0;
- refCount = 0;
- code = NULL;
- name = NULL;
- fullPath = NULL;
- modPath = NULL;
- codeSize = 0;
- lineBreakPairCount = 0;
- nextFile = NULL;
- }
- CodeBlock::~CodeBlock()
- {
- // Make sure we aren't lingering in the current code block...
- AssertFatal(smCurrentCodeBlock != this, "CodeBlock::~CodeBlock - Caught lingering in smCurrentCodeBlock!");
- if (name)
- removeFromCodeList();
- delete[] const_cast<char*>(globalStrings);
- delete[] const_cast<char*>(functionStrings);
- functionStringsMaxLen = 0;
- globalStringsMaxLen = 0;
- delete[] globalFloats;
- delete[] functionFloats;
- delete[] code;
- delete[] breakList;
- }
- //-------------------------------------------------------------------------
- StringTableEntry CodeBlock::getCurrentCodeBlockName()
- {
- if (CodeBlock::getCurrentBlock())
- return CodeBlock::getCurrentBlock()->name;
- else
- return NULL;
- }
- StringTableEntry CodeBlock::getCurrentCodeBlockFullPath()
- {
- if (CodeBlock::getCurrentBlock())
- return CodeBlock::getCurrentBlock()->fullPath;
- else
- return NULL;
- }
- StringTableEntry CodeBlock::getCurrentCodeBlockModName()
- {
- if (CodeBlock::getCurrentBlock())
- return CodeBlock::getCurrentBlock()->modPath;
- else
- return NULL;
- }
- CodeBlock *CodeBlock::find(StringTableEntry name)
- {
- for (CodeBlock *walk = CodeBlock::getCodeBlockList(); walk; walk = walk->nextFile)
- if (walk->name == name)
- return walk;
- return NULL;
- }
- //-------------------------------------------------------------------------
- void CodeBlock::addToCodeList()
- {
- // remove any code blocks with my name
- for (CodeBlock **walk = &smCodeBlockList; *walk; walk = &((*walk)->nextFile))
- {
- if ((*walk)->name == name)
- {
- *walk = (*walk)->nextFile;
- break;
- }
- }
- nextFile = smCodeBlockList;
- smCodeBlockList = this;
- }
- void CodeBlock::clearAllBreaks()
- {
- if (!lineBreakPairs)
- return;
- for (U32 i = 0; i < lineBreakPairCount; i++)
- {
- U32 *p = lineBreakPairs + i * 2;
- code[p[1]] = p[0] & 0xFF;
- }
- }
- void CodeBlock::clearBreakpoint(U32 lineNumber)
- {
- if (!lineBreakPairs)
- return;
- for (U32 i = 0; i < lineBreakPairCount; i++)
- {
- U32 *p = lineBreakPairs + i * 2;
- if ((p[0] >> 8) == lineNumber)
- {
- code[p[1]] = p[0] & 0xFF;
- return;
- }
- }
- }
- void CodeBlock::setAllBreaks()
- {
- if (!lineBreakPairs)
- return;
- for (U32 i = 0; i < lineBreakPairCount; i++)
- {
- U32 *p = lineBreakPairs + i * 2;
- code[p[1]] = OP_BREAK;
- }
- }
- bool CodeBlock::setBreakpoint(U32 lineNumber)
- {
- if (!lineBreakPairs)
- return false;
- for (U32 i = 0; i < lineBreakPairCount; i++)
- {
- U32 *p = lineBreakPairs + i * 2;
- if ((p[0] >> 8) == lineNumber)
- {
- code[p[1]] = OP_BREAK;
- return true;
- }
- }
- return false;
- }
- U32 CodeBlock::findFirstBreakLine(U32 lineNumber)
- {
- if (!lineBreakPairs)
- return 0;
- for (U32 i = 0; i < lineBreakPairCount; i++)
- {
- U32 *p = lineBreakPairs + i * 2;
- U32 line = (p[0] >> 8);
- if (lineNumber <= line)
- return line;
- }
- return 0;
- }
- struct LinePair
- {
- U32 instLine;
- U32 ip;
- };
- void CodeBlock::findBreakLine(U32 ip, U32 &line, U32 &instruction)
- {
- U32 min = 0;
- U32 max = lineBreakPairCount - 1;
- LinePair *p = (LinePair *)lineBreakPairs;
- U32 found;
- if (!lineBreakPairCount || p[min].ip > ip || p[max].ip < ip)
- {
- line = 0;
- instruction = OP_INVALID;
- return;
- }
- else if (p[min].ip == ip)
- found = min;
- else if (p[max].ip == ip)
- found = max;
- else
- {
- for (;;)
- {
- if (min == max - 1)
- {
- found = min;
- break;
- }
- U32 mid = (min + max) >> 1;
- if (p[mid].ip == ip)
- {
- found = mid;
- break;
- }
- else if (p[mid].ip > ip)
- max = mid;
- else
- min = mid;
- }
- }
- instruction = p[found].instLine & 0xFF;
- line = p[found].instLine >> 8;
- }
- const char *CodeBlock::getFileLine(U32 ip)
- {
- static char nameBuffer[256];
- U32 line, inst;
- findBreakLine(ip, line, inst);
- dSprintf(nameBuffer, sizeof(nameBuffer), "%s (%d)", name ? name : "<input>", line);
- return nameBuffer;
- }
- void CodeBlock::removeFromCodeList()
- {
- for (CodeBlock **walk = &smCodeBlockList; *walk; walk = &((*walk)->nextFile))
- {
- if (*walk == this)
- {
- *walk = nextFile;
- // clear out all breakpoints
- clearAllBreaks();
- break;
- }
- }
- // Let the telnet debugger know that this code
- // block has been unloaded and that it needs to
- // remove references to it.
- if (TelDebugger)
- TelDebugger->clearCodeBlockPointers(this);
- }
- void CodeBlock::calcBreakList()
- {
- U32 size = 0;
- S32 line = -1;
- U32 seqCount = 0;
- U32 i;
- for (i = 0; i < lineBreakPairCount; i++)
- {
- U32 lineNumber = lineBreakPairs[i * 2];
- if (lineNumber == U32(line + 1))
- seqCount++;
- else
- {
- if (seqCount)
- size++;
- size++;
- seqCount = 1;
- }
- line = lineNumber;
- }
- if (seqCount)
- size++;
- breakList = new U32[size];
- breakListSize = size;
- line = -1;
- seqCount = 0;
- size = 0;
- for (i = 0; i < lineBreakPairCount; i++)
- {
- U32 lineNumber = lineBreakPairs[i * 2];
- if (lineNumber == U32(line + 1))
- seqCount++;
- else
- {
- if (seqCount)
- breakList[size++] = seqCount;
- breakList[size++] = lineNumber - getMax(0, line) - 1;
- seqCount = 1;
- }
- line = lineNumber;
- }
- if (seqCount)
- breakList[size++] = seqCount;
- for (i = 0; i < lineBreakPairCount; i++)
- {
- U32 *p = lineBreakPairs + i * 2;
- p[0] = (p[0] << 8) | code[p[1]];
- }
- // Let the telnet debugger know that this code
- // block has been loaded and that it can add break
- // points it has for it.
- if (TelDebugger)
- TelDebugger->addAllBreakpoints(this);
- }
- bool CodeBlock::read(StringTableEntry fileName, Stream &st)
- {
- const StringTableEntry exePath = Platform::getMainDotCsDir();
- const StringTableEntry cwd = Platform::getCurrentDirectory();
- name = fileName;
- if (fileName)
- {
- fullPath = NULL;
- if (Platform::isFullPath(fileName))
- fullPath = fileName;
- if (dStrnicmp(exePath, fileName, dStrlen(exePath)) == 0)
- name = StringTable->insert(fileName + dStrlen(exePath) + 1, true);
- else if (dStrnicmp(cwd, fileName, dStrlen(cwd)) == 0)
- name = StringTable->insert(fileName + dStrlen(cwd) + 1, true);
- if (fullPath == NULL)
- {
- char buf[1024];
- fullPath = StringTable->insert(Platform::makeFullPathName(fileName, buf, sizeof(buf)), true);
- }
- modPath = Con::getModNameFromPath(fileName);
- }
- //
- addToCodeList();
- U32 globalSize, size, i;
- st.read(&size);
- if (size)
- {
- globalStrings = new char[size];
- globalStringsMaxLen = size;
- st.read(size, globalStrings);
- }
- globalSize = size;
- st.read(&size);
- if (size)
- {
- functionStrings = new char[size];
- functionStringsMaxLen = size;
- st.read(size, functionStrings);
- }
- st.read(&size);
- if (size)
- {
- globalFloats = new F64[size];
- for (i = 0; i < size; i++)
- st.read(&globalFloats[i]);
- }
- st.read(&size);
- if (size)
- {
- functionFloats = new F64[size];
- for (i = 0; i < size; i++)
- st.read(&functionFloats[i]);
- }
- U32 codeLength;
- st.read(&codeLength);
- st.read(&lineBreakPairCount);
- U32 totSize = codeLength + lineBreakPairCount * 2;
- code = new U32[totSize];
- // 0xFF is used as a flag to help compress the bytecode.
- // If detected, the bytecode is only a U8.
- for (i = 0; i < codeLength; i++)
- {
- U8 b;
- st.read(&b);
- if (b == 0xFF)
- st.read(&code[i]);
- else
- code[i] = b;
- }
- for (i = codeLength; i < totSize; i++)
- st.read(&code[i]);
- lineBreakPairs = code + codeLength;
- // StringTable-ize our identifiers.
- U32 identCount;
- st.read(&identCount);
- while (identCount--)
- {
- U32 offset;
- st.read(&offset);
- StringTableEntry ste;
- if (offset < globalSize)
- ste = StringTable->insert(globalStrings + offset);
- else
- ste = StringTable->EmptyString();
- U32 count;
- st.read(&count);
- while (count--)
- {
- U32 ip;
- st.read(&ip);
- #ifdef TORQUE_CPU_X64
- *(U64*)(code + ip) = (U64)ste;
- #else
- code[ip] = *((U32 *)&ste);
- #endif
- }
- }
- if (lineBreakPairCount)
- calcBreakList();
- return true;
- }
- bool CodeBlock::compile(const char *codeFileName, StringTableEntry fileName, const char *inScript, bool overrideNoDso)
- {
- AssertFatal(Con::isMainThread(), "Compiling code on a secondary thread");
- // This will return true, but return value is ignored
- char *script;
- chompUTF8BOM(inScript, &script);
- gSyntaxError = false;
- consoleAllocReset();
- STEtoCode = compileSTEtoCode;
- gStatementList = NULL;
- // Set up the parser.
- smCurrentParser = getParserForFile(fileName);
- AssertISV(smCurrentParser, avar("CodeBlock::compile - no parser available for '%s'!", fileName));
- // Now do some parsing.
- smCurrentParser->setScanBuffer(script, fileName);
- smCurrentParser->restart(NULL);
- smCurrentParser->parse();
- if (gSyntaxError)
- {
- consoleAllocReset();
- return false;
- }
- #ifdef TORQUE_NO_DSO_GENERATION
- if (!overrideNoDso)
- return false;
- #endif // !TORQUE_NO_DSO_GENERATION
- FileStream st;
- if (!st.open(codeFileName, Torque::FS::File::Write))
- return false;
- st.write(U32(Con::DSOVersion));
- // Reset all our value tables...
- resetTables();
- smInFunction = false;
- CodeStream codeStream;
- U32 lastIp;
- if (gStatementList)
- {
- lastIp = compileBlock(gStatementList, codeStream, 0) + 1;
- }
- else
- {
- codeSize = 1;
- lastIp = 0;
- }
- codeStream.emit(OP_RETURN);
- codeStream.emitCodeStream(&codeSize, &code, &lineBreakPairs);
- lineBreakPairCount = codeStream.getNumLineBreaks();
- // Write string table data...
- getGlobalStringTable().write(st);
- getFunctionStringTable().write(st);
- // Write float table data...
- getGlobalFloatTable().write(st);
- getFunctionFloatTable().write(st);
- if (lastIp != codeSize)
- Con::errorf(ConsoleLogEntry::General, "CodeBlock::compile - precompile size mismatch, a precompile/compile function pair is probably mismatched.");
- U32 totSize = codeSize + codeStream.getNumLineBreaks() * 2;
- st.write(codeSize);
- st.write(lineBreakPairCount);
- // Write out our bytecode, doing a bit of compression for low numbers.
- U32 i;
- for (i = 0; i < codeSize; i++)
- {
- if (code[i] < 0xFF)
- st.write(U8(code[i]));
- else
- {
- st.write(U8(0xFF));
- st.write(code[i]);
- }
- }
- // Write the break info...
- for (i = codeSize; i < totSize; i++)
- st.write(code[i]);
- getIdentTable().write(st);
- consoleAllocReset();
- st.close();
- return true;
- }
- ConsoleValue CodeBlock::compileExec(StringTableEntry fileName, const char *inString, bool noCalls, S32 setFrame)
- {
- AssertFatal(Con::isMainThread(), "Compiling code on a secondary thread");
- // Check for a UTF8 script file
- char *string;
- chompUTF8BOM(inString, &string);
- STEtoCode = evalSTEtoCode;
- consoleAllocReset();
- name = fileName;
- if (fileName)
- {
- const StringTableEntry exePath = Platform::getMainDotCsDir();
- const StringTableEntry cwd = Platform::getCurrentDirectory();
- fullPath = NULL;
- if (Platform::isFullPath(fileName))
- fullPath = fileName;
- if (dStrnicmp(exePath, fileName, dStrlen(exePath)) == 0)
- name = StringTable->insert(fileName + dStrlen(exePath) + 1, true);
- else if (dStrnicmp(cwd, fileName, dStrlen(cwd)) == 0)
- name = StringTable->insert(fileName + dStrlen(cwd) + 1, true);
- if (fullPath == NULL)
- {
- char buf[1024];
- fullPath = StringTable->insert(Platform::makeFullPathName(fileName, buf, sizeof(buf)), true);
- }
- modPath = Con::getModNameFromPath(fileName);
- }
- if (name)
- addToCodeList();
- gStatementList = NULL;
- // Set up the parser.
- smCurrentParser = getParserForFile(fileName);
- AssertISV(smCurrentParser, avar("CodeBlock::compile - no parser available for '%s'!", fileName));
- // Now do some parsing.
- smCurrentParser->setScanBuffer(string, fileName);
- smCurrentParser->restart(NULL);
- smCurrentParser->parse();
- if (!gStatementList)
- {
- delete this;
- return std::move(ConsoleValue());
- }
- resetTables();
- smInFunction = false;
- CodeStream codeStream;
- U32 lastIp = compileBlock(gStatementList, codeStream, 0);
- lineBreakPairCount = codeStream.getNumLineBreaks();
- globalStrings = getGlobalStringTable().build();
- globalStringsMaxLen = getGlobalStringTable().totalLen;
- functionStrings = getFunctionStringTable().build();
- functionStringsMaxLen = getFunctionStringTable().totalLen;
- globalFloats = getGlobalFloatTable().build();
- functionFloats = getFunctionFloatTable().build();
- codeStream.emit(OP_RETURN);
- codeStream.emitCodeStream(&codeSize, &code, &lineBreakPairs);
- if (Con::getBoolVariable("dump"))
- dumpInstructions(0, false);
- consoleAllocReset();
- if (lineBreakPairCount && fileName)
- calcBreakList();
- if (lastIp + 1 != codeSize)
- Con::warnf(ConsoleLogEntry::General, "precompile size mismatch, precompile: %d compile: %d", codeSize, lastIp);
- return std::move(exec(0, fileName, NULL, 0, 0, noCalls, NULL, setFrame));
- }
- //-------------------------------------------------------------------------
- void CodeBlock::incRefCount()
- {
- refCount++;
- }
- void CodeBlock::decRefCount()
- {
- refCount--;
- if (!refCount)
- delete this;
- }
- //-------------------------------------------------------------------------
- String CodeBlock::getFunctionArgs(U32 ip)
- {
- StringBuilder str;
- U32 fnArgc = code[ip + 8];
- for (U32 i = 0; i < fnArgc; ++i)
- {
- StringTableEntry var = CodeToSTE(code, ip + (i * 2) + 9);
- if (i != 0)
- str.append(", ");
- str.append("string ");
- // Try to capture junked parameters
- if (var[0])
- str.append(var + 1);
- else
- str.append("JUNK");
- }
- return str.end();
- }
- //-------------------------------------------------------------------------
- void CodeBlock::dumpInstructions(U32 startIp, bool upToReturn)
- {
- U32 ip = startIp;
- smInFunction = false;
- U32 endFuncIp = 0;
- while (ip < codeSize)
- {
- if (ip > endFuncIp)
- {
- smInFunction = false;
- }
- switch (code[ip++])
- {
- case OP_FUNC_DECL:
- {
- StringTableEntry fnName = CodeToSTE(code, ip);
- StringTableEntry fnNamespace = CodeToSTE(code, ip + 2);
- StringTableEntry fnPackage = CodeToSTE(code, ip + 4);
- bool hasBody = bool(code[ip + 6]);
- U32 newIp = code[ip + 7];
- U32 argc = code[ip + 8];
- U32 regCount = code[ip + 9];
- endFuncIp = newIp;
- Con::printf("%i: OP_FUNC_DECL name=%s nspace=%s package=%s hasbody=%i newip=%i argc=%i regCount=%i",
- ip - 1, fnName, fnNamespace, fnPackage, hasBody, newIp, argc, regCount);
- // Skip args.
- ip += 10 + argc;
- smInFunction = true;
- break;
- }
- case OP_CREATE_OBJECT:
- {
- StringTableEntry objParent = CodeToSTE(code, ip);
- bool isDataBlock = code[ip + 2];
- bool isInternal = code[ip + 3];
- bool isSingleton = code[ip + 4];
- U32 lineNumber = code[ip + 5];
- U32 failJump = code[ip + 6];
- Con::printf("%i: OP_CREATE_OBJECT objParent=%s isDataBlock=%i isInternal=%i isSingleton=%i lineNumber=%i failJump=%i",
- ip - 1, objParent, isDataBlock, isInternal, isSingleton, lineNumber, failJump);
- ip += 7;
- break;
- }
- case OP_ADD_OBJECT:
- {
- bool placeAtRoot = code[ip++];
- Con::printf("%i: OP_ADD_OBJECT placeAtRoot=%i", ip - 1, placeAtRoot);
- break;
- }
- case OP_END_OBJECT:
- {
- bool placeAtRoot = code[ip++];
- Con::printf("%i: OP_END_OBJECT placeAtRoot=%i", ip - 1, placeAtRoot);
- break;
- }
- case OP_FINISH_OBJECT:
- {
- Con::printf("%i: OP_FINISH_OBJECT", ip - 1);
- break;
- }
- case OP_JMPIFFNOT:
- {
- Con::printf("%i: OP_JMPIFFNOT ip=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_JMPIFNOT:
- {
- Con::printf("%i: OP_JMPIFNOT ip=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_JMPIFF:
- {
- Con::printf("%i: OP_JMPIFF ip=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_JMPIF:
- {
- Con::printf("%i: OP_JMPIF ip=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_JMPIFNOT_NP:
- {
- Con::printf("%i: OP_JMPIFNOT_NP ip=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_JMPIF_NP:
- {
- Con::printf("%i: OP_JMPIF_NP ip=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_JMP:
- {
- Con::printf("%i: OP_JMP ip=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_RETURN:
- {
- Con::printf("%i: OP_RETURN", ip - 1);
- if (upToReturn)
- return;
- break;
- }
- case OP_RETURN_VOID:
- {
- Con::printf("%i: OP_RETURNVOID", ip - 1);
- if (upToReturn)
- return;
- break;
- }
- case OP_RETURN_UINT:
- {
- Con::printf("%i: OP_RETURNUINT", ip - 1);
- if (upToReturn)
- return;
- break;
- }
- case OP_RETURN_FLT:
- {
- Con::printf("%i: OP_RETURNFLT", ip - 1);
- if (upToReturn)
- return;
- break;
- }
- case OP_CMPEQ:
- {
- Con::printf("%i: OP_CMPEQ", ip - 1);
- break;
- }
- case OP_CMPGR:
- {
- Con::printf("%i: OP_CMPGR", ip - 1);
- break;
- }
- case OP_CMPGE:
- {
- Con::printf("%i: OP_CMPGE", ip - 1);
- break;
- }
- case OP_CMPLT:
- {
- Con::printf("%i: OP_CMPLT", ip - 1);
- break;
- }
- case OP_CMPLE:
- {
- Con::printf("%i: OP_CMPLE", ip - 1);
- break;
- }
- case OP_CMPNE:
- {
- Con::printf("%i: OP_CMPNE", ip - 1);
- break;
- }
- case OP_XOR:
- {
- Con::printf("%i: OP_XOR", ip - 1);
- break;
- }
- case OP_MOD:
- {
- Con::printf("%i: OP_MOD", ip - 1);
- break;
- }
- case OP_BITAND:
- {
- Con::printf("%i: OP_BITAND", ip - 1);
- break;
- }
- case OP_BITOR:
- {
- Con::printf("%i: OP_BITOR", ip - 1);
- break;
- }
- case OP_NOT:
- {
- Con::printf("%i: OP_NOT", ip - 1);
- break;
- }
- case OP_NOTF:
- {
- Con::printf("%i: OP_NOTF", ip - 1);
- break;
- }
- case OP_ONESCOMPLEMENT:
- {
- Con::printf("%i: OP_ONESCOMPLEMENT", ip - 1);
- break;
- }
- case OP_SHR:
- {
- Con::printf("%i: OP_SHR", ip - 1);
- break;
- }
- case OP_SHL:
- {
- Con::printf("%i: OP_SHL", ip - 1);
- break;
- }
- case OP_AND:
- {
- Con::printf("%i: OP_AND", ip - 1);
- break;
- }
- case OP_OR:
- {
- Con::printf("%i: OP_OR", ip - 1);
- break;
- }
- case OP_ADD:
- {
- Con::printf("%i: OP_ADD", ip - 1);
- break;
- }
- case OP_SUB:
- {
- Con::printf("%i: OP_SUB", ip - 1);
- break;
- }
- case OP_MUL:
- {
- Con::printf("%i: OP_MUL", ip - 1);
- break;
- }
- case OP_DIV:
- {
- Con::printf("%i: OP_DIV", ip - 1);
- break;
- }
- case OP_NEG:
- {
- Con::printf("%i: OP_NEG", ip - 1);
- break;
- }
- case OP_INC:
- {
- Con::printf("%i: OP_INC reg=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_SETCURVAR:
- {
- StringTableEntry var = CodeToSTE(code, ip);
- Con::printf("%i: OP_SETCURVAR var=%s", ip - 1, var);
- ip += 2;
- break;
- }
- case OP_SETCURVAR_CREATE:
- {
- StringTableEntry var = CodeToSTE(code, ip);
- Con::printf("%i: OP_SETCURVAR_CREATE var=%s", ip - 1, var);
- ip += 2;
- break;
- }
- case OP_SETCURVAR_ARRAY:
- {
- Con::printf("%i: OP_SETCURVAR_ARRAY", ip - 1);
- break;
- }
- case OP_SETCURVAR_ARRAY_CREATE:
- {
- Con::printf("%i: OP_SETCURVAR_ARRAY_CREATE", ip - 1);
- break;
- }
- case OP_LOADVAR_UINT:
- {
- Con::printf("%i: OP_LOADVAR_UINT", ip - 1);
- break;
- }
- case OP_LOADVAR_FLT:
- {
- Con::printf("%i: OP_LOADVAR_FLT", ip - 1);
- break;
- }
- case OP_LOADVAR_STR:
- {
- Con::printf("%i: OP_LOADVAR_STR", ip - 1);
- break;
- }
- case OP_SAVEVAR_UINT:
- {
- Con::printf("%i: OP_SAVEVAR_UINT", ip - 1);
- break;
- }
- case OP_SAVEVAR_FLT:
- {
- Con::printf("%i: OP_SAVEVAR_FLT", ip - 1);
- break;
- }
- case OP_SAVEVAR_STR:
- {
- Con::printf("%i: OP_SAVEVAR_STR", ip - 1);
- break;
- }
- case OP_LOAD_LOCAL_VAR_UINT:
- {
- Con::printf("%i: OP_LOAD_LOCAL_VAR_UINT reg=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_LOAD_LOCAL_VAR_FLT:
- {
- Con::printf("%i: OP_LOAD_LOCAL_VAR_FLT reg=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_LOAD_LOCAL_VAR_STR:
- {
- Con::printf("%i: OP_LOAD_LOCAL_VAR_STR reg=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_SAVE_LOCAL_VAR_UINT:
- {
- Con::printf("%i: OP_SAVE_LOCAL_VAR_UINT reg=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_SAVE_LOCAL_VAR_FLT:
- {
- Con::printf("%i: OP_SAVE_LOCAL_VAR_FLT reg=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_SAVE_LOCAL_VAR_STR:
- {
- Con::printf("%i: OP_SAVE_LOCAL_VAR_STR reg=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_SETCUROBJECT:
- {
- Con::printf("%i: OP_SETCUROBJECT", ip - 1);
- break;
- }
- case OP_SETCUROBJECT_NEW:
- {
- Con::printf("%i: OP_SETCUROBJECT_NEW", ip - 1);
- break;
- }
- case OP_SETCUROBJECT_INTERNAL:
- {
- Con::printf("%i: OP_SETCUROBJECT_INTERNAL", ip - 1);
- ++ip;
- break;
- }
- case OP_SETCURFIELD:
- {
- StringTableEntry curField = CodeToSTE(code, ip);
- Con::printf("%i: OP_SETCURFIELD field=%s", ip - 1, curField);
- ip += 2;
- break;
- }
- case OP_SETCURFIELD_ARRAY:
- {
- Con::printf("%i: OP_SETCURFIELD_ARRAY", ip - 1);
- break;
- }
- case OP_SETCURFIELD_TYPE:
- {
- U32 type = code[ip];
- Con::printf("%i: OP_SETCURFIELD_TYPE type=%i", ip - 1, type);
- ++ip;
- break;
- }
- case OP_LOADFIELD_UINT:
- {
- Con::printf("%i: OP_LOADFIELD_UINT", ip - 1);
- break;
- }
- case OP_LOADFIELD_FLT:
- {
- Con::printf("%i: OP_LOADFIELD_FLT", ip - 1);
- break;
- }
- case OP_LOADFIELD_STR:
- {
- Con::printf("%i: OP_LOADFIELD_STR", ip - 1);
- break;
- }
- case OP_SAVEFIELD_UINT:
- {
- Con::printf("%i: OP_SAVEFIELD_UINT", ip - 1);
- break;
- }
- case OP_SAVEFIELD_FLT:
- {
- Con::printf("%i: OP_SAVEFIELD_FLT", ip - 1);
- break;
- }
- case OP_SAVEFIELD_STR:
- {
- Con::printf("%i: OP_SAVEFIELD_STR", ip - 1);
- break;
- }
- case OP_STR_TO_UINT:
- {
- Con::printf("%i: OP_STR_TO_UINT", ip - 1);
- break;
- }
- case OP_STR_TO_FLT:
- {
- Con::printf("%i: OP_STR_TO_FLT", ip - 1);
- break;
- }
- case OP_STR_TO_NONE:
- {
- Con::printf("%i: OP_STR_TO_NONE", ip - 1);
- break;
- }
- case OP_FLT_TO_UINT:
- {
- Con::printf("%i: OP_FLT_TO_UINT", ip - 1);
- break;
- }
- case OP_FLT_TO_STR:
- {
- Con::printf("%i: OP_FLT_TO_STR", ip - 1);
- break;
- }
- case OP_UINT_TO_FLT:
- {
- Con::printf("%i: OP_UINT_TO_FLT", ip - 1);
- break;
- }
- case OP_UINT_TO_STR:
- {
- Con::printf("%i: OP_UINT_TO_STR", ip - 1);
- break;
- }
- case OP_NUM_TO_NONE:
- {
- Con::printf("%i: OP_NUM_TO_NONE", ip - 1);
- break;
- }
- case OP_LOADIMMED_UINT:
- {
- U32 val = code[ip];
- Con::printf("%i: OP_LOADIMMED_UINT val=%i", ip - 1, val);
- ++ip;
- break;
- }
- case OP_LOADIMMED_FLT:
- {
- F64 val = (smInFunction ? functionFloats : globalFloats)[code[ip]];
- Con::printf("%i: OP_LOADIMMED_FLT val=%f", ip - 1, val);
- ++ip;
- break;
- }
- case OP_TAG_TO_STR:
- {
- const char* str = (smInFunction ? functionStrings : globalStrings) + code[ip];
- Con::printf("%i: OP_TAG_TO_STR str=%s", ip - 1, str);
- ++ip;
- break;
- }
- case OP_LOADIMMED_STR:
- {
- const char* str = (smInFunction ? functionStrings : globalStrings) + code[ip];
- Con::printf("%i: OP_LOADIMMED_STR str=%s", ip - 1, str);
- ++ip;
- break;
- }
- case OP_DOCBLOCK_STR:
- {
- const char* str = (smInFunction ? functionStrings : globalStrings) + code[ip];
- Con::printf("%i: OP_DOCBLOCK_STR str=%s", ip - 1, str);
- ++ip;
- break;
- }
- case OP_LOADIMMED_IDENT:
- {
- StringTableEntry str = CodeToSTE(code, ip);
- Con::printf("%i: OP_LOADIMMED_IDENT str=%s", ip - 1, str);
- ip += 2;
- break;
- }
- case OP_CALLFUNC:
- {
- StringTableEntry fnNamespace = CodeToSTE(code, ip + 2);
- StringTableEntry fnName = CodeToSTE(code, ip);
- U32 callType = code[ip + 4];
- StringTableEntry callTypeName;
- switch (callType)
- {
- case FuncCallExprNode::FunctionCall: callTypeName = "FunctionCall"; break;
- case FuncCallExprNode::MethodCall: callTypeName = "MethodCall"; break;
- case FuncCallExprNode::ParentCall: callTypeName = "ParentCall"; break;
- case FuncCallExprNode::StaticCall: callTypeName = "StaticCall"; break;
- }
- Con::printf("%i: OP_CALLFUNC name=%s nspace=%s callType=%s", ip - 1, fnName, fnNamespace, callTypeName);
- ip += 5;
- break;
- }
- case OP_ADVANCE_STR:
- {
- Con::printf("%i: OP_ADVANCE_STR", ip - 1);
- break;
- }
- case OP_ADVANCE_STR_APPENDCHAR:
- {
- char ch = code[ip];
- Con::printf("%i: OP_ADVANCE_STR_APPENDCHAR char=%c", ip - 1, ch);
- ++ip;
- break;
- }
- case OP_ADVANCE_STR_COMMA:
- {
- Con::printf("%i: OP_ADVANCE_STR_COMMA", ip - 1);
- break;
- }
- case OP_ADVANCE_STR_NUL:
- {
- Con::printf("%i: OP_ADVANCE_STR_NUL", ip - 1);
- break;
- }
- case OP_REWIND_STR:
- {
- Con::printf("%i: OP_REWIND_STR", ip - 1);
- break;
- }
- case OP_TERMINATE_REWIND_STR:
- {
- Con::printf("%i: OP_TERMINATE_REWIND_STR", ip - 1);
- break;
- }
- case OP_COMPARE_STR:
- {
- Con::printf("%i: OP_COMPARE_STR", ip - 1);
- break;
- }
- case OP_PUSH:
- {
- Con::printf("%i: OP_PUSH", ip - 1);
- break;
- }
- case OP_PUSH_UINT:
- {
- Con::printf("%i: OP_PUSH_UINT", ip - 1);
- break;
- }
- case OP_PUSH_FLT:
- {
- Con::printf("%i: OP_PUSH_FLT", ip - 1);
- break;
- }
- case OP_PUSH_FRAME:
- {
- Con::printf("%i: OP_PUSH_FRAME count=%i", ip - 1, code[ip]);
- ++ip;
- break;
- }
- case OP_ASSERT:
- {
- const char* message = (smInFunction ? functionStrings : globalStrings) + code[ip];
- Con::printf("%i: OP_ASSERT message=%s", ip - 1, message);
- ++ip;
- break;
- }
- case OP_BREAK:
- {
- Con::printf("%i: OP_BREAK", ip - 1);
- break;
- }
- case OP_ITER_BEGIN:
- {
- bool isGlobal = code[ip];
- if (isGlobal)
- {
- StringTableEntry varName = CodeToSTE(code, ip + 1);
- U32 failIp = code[ip + 3];
- Con::printf("%i: OP_ITER_BEGIN varName=%s failIp=%i isGlobal=%s", ip - 1, varName, failIp, "true");
- ip += 4;
- }
- else
- {
- S32 reg = code[ip + 1];
- U32 failIp = code[ip + 2];
- Con::printf("%i: OP_ITER_BEGIN varRegister=%d failIp=%i isGlobal=%s", ip - 1, reg, failIp, "false");
- ip += 3;
- }
- break;
- }
- case OP_ITER_BEGIN_STR:
- {
- bool isGlobal = code[ip];
- if (isGlobal)
- {
- StringTableEntry varName = CodeToSTE(code, ip + 1);
- U32 failIp = code[ip + 3];
- Con::printf("%i: OP_ITER_BEGIN_STR varName=%s failIp=%i isGlobal=%s", ip - 1, varName, failIp, "true");
- ip += 4;
- }
- else
- {
- S32 reg = code[ip + 1];
- U32 failIp = code[ip + 2];
- Con::printf("%i: OP_ITER_BEGIN_STR varRegister=%d failIp=%i isGlobal=%s", ip - 1, reg, failIp, "false");
- ip += 3;
- }
- break;
- }
- case OP_ITER:
- {
- U32 breakIp = code[ip];
- Con::printf("%i: OP_ITER breakIp=%i", ip - 1, breakIp);
- ++ip;
- break;
- }
- case OP_ITER_END:
- {
- Con::printf("%i: OP_ITER_END", ip - 1);
- break;
- }
- default:
- Con::printf("%i: !!INVALID!!", ip - 1);
- break;
- }
- }
- smInFunction = false;
- }
|