compiledEval.cpp 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #include "platform/platform.h"
  23. #include "console/console.h"
  24. #include "console/ast.h"
  25. #include "core/tAlgorithm.h"
  26. #include "core/strings/findMatch.h"
  27. #include "core/strings/stringUnit.h"
  28. #include "console/consoleInternal.h"
  29. #include "core/stream/fileStream.h"
  30. #include "console/compiler.h"
  31. #include "console/simBase.h"
  32. #include "console/telnetDebugger.h"
  33. #include "sim/netStringTable.h"
  34. #include "console/ICallMethod.h"
  35. #include "console/stringStack.h"
  36. #include "util/messaging/message.h"
  37. #include "core/frameAllocator.h"
  38. #ifndef TORQUE_TGB_ONLY
  39. #include "materials/materialDefinition.h"
  40. #include "materials/materialManager.h"
  41. #endif
  42. using namespace Compiler;
  43. enum EvalConstants {
  44. MaxStackSize = 1024,
  45. MethodOnComponent = -2
  46. };
  47. namespace Con
  48. {
  49. // Current script file name and root, these are registered as
  50. // console variables.
  51. extern StringTableEntry gCurrentFile;
  52. extern StringTableEntry gCurrentRoot;
  53. extern S32 gObjectCopyFailures;
  54. }
  55. /// Frame data for a foreach/foreach$ loop.
  56. struct IterStackRecord
  57. {
  58. /// If true, this is a foreach$ loop; if not, it's a foreach loop.
  59. bool mIsStringIter;
  60. /// The iterator variable.
  61. Dictionary::Entry* mVariable;
  62. /// Information for an object iterator loop.
  63. struct ObjectPos
  64. {
  65. /// The set being iterated over.
  66. SimSet* mSet;
  67. /// Current index in the set.
  68. U32 mIndex;
  69. };
  70. /// Information for a string iterator loop.
  71. struct StringPos
  72. {
  73. /// The raw string data on the string stack.
  74. const char* mString;
  75. /// Current parsing position.
  76. U32 mIndex;
  77. };
  78. union
  79. {
  80. ObjectPos mObj;
  81. StringPos mStr;
  82. } mData;
  83. };
  84. IterStackRecord iterStack[ MaxStackSize ];
  85. F64 floatStack[MaxStackSize];
  86. S64 intStack[MaxStackSize];
  87. StringStack STR;
  88. U32 _FLT = 0; ///< Stack pointer for floatStack.
  89. U32 _UINT = 0; ///< Stack pointer for intStack.
  90. U32 _ITER = 0; ///< Stack pointer for iterStack.
  91. namespace Con
  92. {
  93. const char *getNamespaceList(Namespace *ns)
  94. {
  95. U32 size = 1;
  96. Namespace * walk;
  97. for(walk = ns; walk; walk = walk->mParent)
  98. size += dStrlen(walk->mName) + 4;
  99. char *ret = Con::getReturnBuffer(size);
  100. ret[0] = 0;
  101. for(walk = ns; walk; walk = walk->mParent)
  102. {
  103. dStrcat(ret, walk->mName);
  104. if(walk->mParent)
  105. dStrcat(ret, " -> ");
  106. }
  107. return ret;
  108. }
  109. }
  110. //------------------------------------------------------------
  111. F64 consoleStringToNumber(const char *str, StringTableEntry file, U32 line)
  112. {
  113. F64 val = dAtof(str);
  114. if(val != 0)
  115. return val;
  116. else if(!dStricmp(str, "true"))
  117. return 1;
  118. else if(!dStricmp(str, "false"))
  119. return 0;
  120. else if(file)
  121. {
  122. Con::warnf(ConsoleLogEntry::General, "%s (%d): string always evaluates to 0.", file, line);
  123. return 0;
  124. }
  125. return 0;
  126. }
  127. //------------------------------------------------------------
  128. namespace Con
  129. {
  130. char *getReturnBuffer(U32 bufferSize)
  131. {
  132. return STR.getReturnBuffer(bufferSize);
  133. }
  134. char *getReturnBuffer( const char *stringToCopy )
  135. {
  136. U32 len = dStrlen( stringToCopy ) + 1;
  137. char *ret = STR.getReturnBuffer( len);
  138. dMemcpy( ret, stringToCopy, len );
  139. return ret;
  140. }
  141. char* getReturnBuffer( const String& str )
  142. {
  143. const U32 size = str.size();
  144. char* ret = STR.getReturnBuffer( size );
  145. dMemcpy( ret, str.c_str(), size );
  146. return ret;
  147. }
  148. char* getReturnBuffer( const StringBuilder& str )
  149. {
  150. char* buffer = Con::getReturnBuffer( str.length() + 1 );
  151. str.copy( buffer );
  152. buffer[ str.length() ] = '\0';
  153. return buffer;
  154. }
  155. char *getArgBuffer(U32 bufferSize)
  156. {
  157. return STR.getArgBuffer(bufferSize);
  158. }
  159. char *getFloatArg(F64 arg)
  160. {
  161. char *ret = STR.getArgBuffer(32);
  162. dSprintf(ret, 32, "%g", arg);
  163. return ret;
  164. }
  165. char *getIntArg(S32 arg)
  166. {
  167. char *ret = STR.getArgBuffer(32);
  168. dSprintf(ret, 32, "%d", arg);
  169. return ret;
  170. }
  171. char *getStringArg( const char *arg )
  172. {
  173. U32 len = dStrlen( arg ) + 1;
  174. char *ret = STR.getArgBuffer( len );
  175. dMemcpy( ret, arg, len );
  176. return ret;
  177. }
  178. char* getStringArg( const String& arg )
  179. {
  180. const U32 size = arg.size();
  181. char* ret = STR.getArgBuffer( size );
  182. dMemcpy( ret, arg.c_str(), size );
  183. return ret;
  184. }
  185. }
  186. //------------------------------------------------------------
  187. inline void ExprEvalState::setCurVarName(StringTableEntry name)
  188. {
  189. if(name[0] == '$')
  190. currentVariable = globalVars.lookup(name);
  191. else if( getStackDepth() > 0 )
  192. currentVariable = getCurrentFrame().lookup(name);
  193. if(!currentVariable && gWarnUndefinedScriptVariables)
  194. Con::warnf(ConsoleLogEntry::Script, "Variable referenced before assignment: %s", name);
  195. }
  196. inline void ExprEvalState::setCurVarNameCreate(StringTableEntry name)
  197. {
  198. if(name[0] == '$')
  199. currentVariable = globalVars.add(name);
  200. else if( getStackDepth() > 0 )
  201. currentVariable = getCurrentFrame().add(name);
  202. else
  203. {
  204. currentVariable = NULL;
  205. Con::warnf(ConsoleLogEntry::Script, "Accessing local variable in global scope... failed: %s", name);
  206. }
  207. }
  208. //------------------------------------------------------------
  209. inline S32 ExprEvalState::getIntVariable()
  210. {
  211. return currentVariable ? currentVariable->getIntValue() : 0;
  212. }
  213. inline F64 ExprEvalState::getFloatVariable()
  214. {
  215. return currentVariable ? currentVariable->getFloatValue() : 0;
  216. }
  217. inline const char *ExprEvalState::getStringVariable()
  218. {
  219. return currentVariable ? currentVariable->getStringValue() : "";
  220. }
  221. //------------------------------------------------------------
  222. inline void ExprEvalState::setIntVariable(S32 val)
  223. {
  224. AssertFatal(currentVariable != NULL, "Invalid evaluator state - trying to set null variable!");
  225. currentVariable->setIntValue(val);
  226. }
  227. inline void ExprEvalState::setFloatVariable(F64 val)
  228. {
  229. AssertFatal(currentVariable != NULL, "Invalid evaluator state - trying to set null variable!");
  230. currentVariable->setFloatValue(val);
  231. }
  232. inline void ExprEvalState::setStringVariable(const char *val)
  233. {
  234. AssertFatal(currentVariable != NULL, "Invalid evaluator state - trying to set null variable!");
  235. currentVariable->setStringValue(val);
  236. }
  237. //------------------------------------------------------------
  238. // Gets a component of an object's field value or a variable and returns it
  239. // in val.
  240. static void getFieldComponent( SimObject* object, StringTableEntry field, const char* array, StringTableEntry subField, char val[] )
  241. {
  242. const char* prevVal = NULL;
  243. // Grab value from object.
  244. if( object && field )
  245. prevVal = object->getDataField( field, array );
  246. // Otherwise, grab from the string stack. The value coming in will always
  247. // be a string because that is how multicomponent variables are handled.
  248. else
  249. prevVal = STR.getStringValue();
  250. // Make sure we got a value.
  251. if ( prevVal && *prevVal )
  252. {
  253. static const StringTableEntry xyzw[] =
  254. {
  255. StringTable->insert( "x" ),
  256. StringTable->insert( "y" ),
  257. StringTable->insert( "z" ),
  258. StringTable->insert( "w" )
  259. };
  260. static const StringTableEntry rgba[] =
  261. {
  262. StringTable->insert( "r" ),
  263. StringTable->insert( "g" ),
  264. StringTable->insert( "b" ),
  265. StringTable->insert( "a" )
  266. };
  267. // Translate xyzw and rgba into the indexed component
  268. // of the variable or field.
  269. if ( subField == xyzw[0] || subField == rgba[0] )
  270. dStrcpy( val, StringUnit::getUnit( prevVal, 0, " \t\n") );
  271. else if ( subField == xyzw[1] || subField == rgba[1] )
  272. dStrcpy( val, StringUnit::getUnit( prevVal, 1, " \t\n") );
  273. else if ( subField == xyzw[2] || subField == rgba[2] )
  274. dStrcpy( val, StringUnit::getUnit( prevVal, 2, " \t\n") );
  275. else if ( subField == xyzw[3] || subField == rgba[3] )
  276. dStrcpy( val, StringUnit::getUnit( prevVal, 3, " \t\n") );
  277. else
  278. val[0] = 0;
  279. }
  280. else
  281. val[0] = 0;
  282. }
  283. // Sets a component of an object's field value based on the sub field. 'x' will
  284. // set the first field, 'y' the second, and 'z' the third.
  285. static void setFieldComponent( SimObject* object, StringTableEntry field, const char* array, StringTableEntry subField )
  286. {
  287. // Copy the current string value
  288. char strValue[1024];
  289. dStrncpy( strValue, STR.getStringValue(), 1024 );
  290. char val[1024] = "";
  291. const char* prevVal = NULL;
  292. // Set the value on an object field.
  293. if( object && field )
  294. prevVal = object->getDataField( field, array );
  295. // Set the value on a variable.
  296. else if( gEvalState.currentVariable )
  297. prevVal = gEvalState.getStringVariable();
  298. // Ensure that the variable has a value
  299. if (!prevVal)
  300. return;
  301. static const StringTableEntry xyzw[] =
  302. {
  303. StringTable->insert( "x" ),
  304. StringTable->insert( "y" ),
  305. StringTable->insert( "z" ),
  306. StringTable->insert( "w" )
  307. };
  308. static const StringTableEntry rgba[] =
  309. {
  310. StringTable->insert( "r" ),
  311. StringTable->insert( "g" ),
  312. StringTable->insert( "b" ),
  313. StringTable->insert( "a" )
  314. };
  315. // Insert the value into the specified
  316. // component of the string.
  317. if ( subField == xyzw[0] || subField == rgba[0] )
  318. dStrcpy( val, StringUnit::setUnit( prevVal, 0, strValue, " \t\n") );
  319. else if ( subField == xyzw[1] || subField == rgba[1] )
  320. dStrcpy( val, StringUnit::setUnit( prevVal, 1, strValue, " \t\n") );
  321. else if ( subField == xyzw[2] || subField == rgba[2] )
  322. dStrcpy( val, StringUnit::setUnit( prevVal, 2, strValue, " \t\n") );
  323. else if ( subField == xyzw[3] || subField == rgba[3] )
  324. dStrcpy( val, StringUnit::setUnit( prevVal, 3, strValue, " \t\n") );
  325. if ( val[0] != 0 )
  326. {
  327. // Update the field or variable.
  328. if( object && field )
  329. object->setDataField( field, 0, val );
  330. else if( gEvalState.currentVariable )
  331. gEvalState.setStringVariable( val );
  332. }
  333. }
  334. const char *CodeBlock::exec(U32 ip, const char *functionName, Namespace *thisNamespace, U32 argc, const char **argv, bool noCalls, StringTableEntry packageName, S32 setFrame)
  335. {
  336. #ifdef TORQUE_DEBUG
  337. U32 stackStart = STR.mStartStackSize;
  338. #endif
  339. static char traceBuffer[1024];
  340. U32 i;
  341. U32 iterDepth = 0;
  342. incRefCount();
  343. F64 *curFloatTable;
  344. char *curStringTable;
  345. S32 curStringTableLen = 0; //clint to ensure we dont overwrite it
  346. STR.clearFunctionOffset();
  347. StringTableEntry thisFunctionName = NULL;
  348. bool popFrame = false;
  349. if(argv)
  350. {
  351. // assume this points into a function decl:
  352. U32 fnArgc = code[ip + 5];
  353. thisFunctionName = U32toSTE(code[ip]);
  354. argc = getMin(argc-1, fnArgc); // argv[0] is func name
  355. if(gEvalState.traceOn)
  356. {
  357. traceBuffer[0] = 0;
  358. dStrcat(traceBuffer, "Entering ");
  359. if(packageName)
  360. {
  361. dStrcat(traceBuffer, "[");
  362. dStrcat(traceBuffer, packageName);
  363. dStrcat(traceBuffer, "]");
  364. }
  365. if(thisNamespace && thisNamespace->mName)
  366. {
  367. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  368. "%s::%s(", thisNamespace->mName, thisFunctionName);
  369. }
  370. else
  371. {
  372. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  373. "%s(", thisFunctionName);
  374. }
  375. for(i = 0; i < argc; i++)
  376. {
  377. dStrcat(traceBuffer, argv[i+1]);
  378. if(i != argc - 1)
  379. dStrcat(traceBuffer, ", ");
  380. }
  381. dStrcat(traceBuffer, ")");
  382. Con::printf("%s", traceBuffer);
  383. }
  384. gEvalState.pushFrame(thisFunctionName, thisNamespace);
  385. popFrame = true;
  386. for(i = 0; i < argc; i++)
  387. {
  388. StringTableEntry var = U32toSTE(code[ip + i + 6]);
  389. gEvalState.setCurVarNameCreate(var);
  390. gEvalState.setStringVariable(argv[i+1]);
  391. }
  392. ip = ip + fnArgc + 6;
  393. curFloatTable = functionFloats;
  394. curStringTable = functionStrings;
  395. curStringTableLen = functionStringsMaxLen;
  396. }
  397. else
  398. {
  399. curFloatTable = globalFloats;
  400. curStringTable = globalStrings;
  401. curStringTableLen = globalStringsMaxLen;
  402. // If requested stack frame isn't available, request a new one
  403. // (this prevents assert failures when creating local
  404. // variables without a stack frame)
  405. if (gEvalState.getStackDepth() <= setFrame)
  406. setFrame = -1;
  407. // Do we want this code to execute using a new stack frame?
  408. if (setFrame < 0)
  409. {
  410. gEvalState.pushFrame(NULL, NULL);
  411. popFrame = true;
  412. }
  413. else
  414. {
  415. // We want to copy a reference to an existing stack frame
  416. // on to the top of the stack. Any change that occurs to
  417. // the locals during this new frame will also occur in the
  418. // original frame.
  419. S32 stackIndex = gEvalState.getStackDepth() - setFrame - 1;
  420. gEvalState.pushFrameRef( stackIndex );
  421. popFrame = true;
  422. }
  423. }
  424. // Grab the state of the telenet debugger here once
  425. // so that the push and pop frames are always balanced.
  426. const bool telDebuggerOn = TelDebugger && TelDebugger->isConnected();
  427. if ( telDebuggerOn && setFrame < 0 )
  428. TelDebugger->pushStackFrame();
  429. StringTableEntry var, objParent;
  430. StringTableEntry fnName;
  431. StringTableEntry fnNamespace, fnPackage;
  432. // Add local object creation stack [7/9/2007 Black]
  433. static const U32 objectCreationStackSize = 32;
  434. U32 objectCreationStackIndex = 0;
  435. struct {
  436. SimObject *newObject;
  437. U32 failJump;
  438. } objectCreationStack[ objectCreationStackSize ];
  439. SimObject *currentNewObject = 0;
  440. U32 failJump = 0;
  441. StringTableEntry prevField = NULL;
  442. StringTableEntry curField = NULL;
  443. SimObject *prevObject = NULL;
  444. SimObject *curObject = NULL;
  445. SimObject *saveObject=NULL;
  446. Namespace::Entry *nsEntry;
  447. Namespace *ns;
  448. const char* curFNDocBlock = NULL;
  449. const char* curNSDocBlock = NULL;
  450. const S32 nsDocLength = 128;
  451. char nsDocBlockClass[nsDocLength];
  452. U32 callArgc;
  453. const char **callArgv;
  454. static char curFieldArray[256];
  455. static char prevFieldArray[256];
  456. CodeBlock *saveCodeBlock = smCurrentCodeBlock;
  457. smCurrentCodeBlock = this;
  458. if(this->name)
  459. {
  460. Con::gCurrentFile = this->name;
  461. Con::gCurrentRoot = this->modPath;
  462. }
  463. const char * val;
  464. // The frame temp is used by the variable accessor ops (OP_SAVEFIELD_* and
  465. // OP_LOADFIELD_*) to store temporary values for the fields.
  466. static S32 VAL_BUFFER_SIZE = 1024;
  467. FrameTemp<char> valBuffer( VAL_BUFFER_SIZE );
  468. for(;;)
  469. {
  470. U32 instruction = code[ip++];
  471. nsEntry = NULL;
  472. breakContinue:
  473. switch(instruction)
  474. {
  475. case OP_FUNC_DECL:
  476. if(!noCalls)
  477. {
  478. fnName = U32toSTE(code[ip]);
  479. fnNamespace = U32toSTE(code[ip+1]);
  480. fnPackage = U32toSTE(code[ip+2]);
  481. bool hasBody = ( code[ ip + 3 ] & 0x01 ) != 0;
  482. U32 lineNumber = code[ ip + 3 ] >> 1;
  483. Namespace::unlinkPackages();
  484. ns = Namespace::find(fnNamespace, fnPackage);
  485. ns->addFunction(fnName, this, hasBody ? ip : 0, curFNDocBlock ? dStrdup( curFNDocBlock ) : NULL, lineNumber );// if no body, set the IP to 0
  486. if( curNSDocBlock )
  487. {
  488. if( fnNamespace == StringTable->lookup( nsDocBlockClass ) )
  489. {
  490. char *usageStr = dStrdup( curNSDocBlock );
  491. usageStr[dStrlen(usageStr)] = '\0';
  492. ns->mUsage = usageStr;
  493. ns->mCleanUpUsage = true;
  494. curNSDocBlock = NULL;
  495. }
  496. }
  497. Namespace::relinkPackages();
  498. // If we had a docblock, it's definitely not valid anymore, so clear it out.
  499. curFNDocBlock = NULL;
  500. //Con::printf("Adding function %s::%s (%d)", fnNamespace, fnName, ip);
  501. }
  502. ip = code[ip + 4];
  503. break;
  504. case OP_CREATE_OBJECT:
  505. {
  506. // Read some useful info.
  507. objParent = U32toSTE(code[ip ]);
  508. bool isDataBlock = code[ip + 1];
  509. bool isInternal = code[ip + 2];
  510. bool isSingleton = code[ip + 3];
  511. U32 lineNumber = code[ip + 4];
  512. failJump = code[ip + 5];
  513. // If we don't allow calls, we certainly don't allow creating objects!
  514. // Moved this to after failJump is set. Engine was crashing when
  515. // noCalls = true and an object was being created at the beginning of
  516. // a file. ADL.
  517. if(noCalls)
  518. {
  519. ip = failJump;
  520. break;
  521. }
  522. // Push the old info to the stack
  523. //Assert( objectCreationStackIndex < objectCreationStackSize );
  524. objectCreationStack[ objectCreationStackIndex ].newObject = currentNewObject;
  525. objectCreationStack[ objectCreationStackIndex++ ].failJump = failJump;
  526. // Get the constructor information off the stack.
  527. STR.getArgcArgv(NULL, &callArgc, &callArgv);
  528. const char* objectName = callArgv[ 2 ];
  529. // Con::printf("Creating object...");
  530. // objectName = argv[1]...
  531. currentNewObject = NULL;
  532. // Are we creating a datablock? If so, deal with case where we override
  533. // an old one.
  534. if(isDataBlock)
  535. {
  536. // Con::printf(" - is a datablock");
  537. // Find the old one if any.
  538. SimObject *db = Sim::getDataBlockGroup()->findObject( objectName );
  539. // Make sure we're not changing types on ourselves...
  540. if(db && dStricmp(db->getClassName(), callArgv[1]))
  541. {
  542. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare data block %s with a different class.", getFileLine(ip), objectName);
  543. ip = failJump;
  544. STR.popFrame();
  545. break;
  546. }
  547. // If there was one, set the currentNewObject and move on.
  548. if(db)
  549. currentNewObject = db;
  550. }
  551. else if (!isInternal)
  552. {
  553. // IF we aren't looking at a local/internal object, then check if
  554. // this object already exists in the global space
  555. SimObject *obj = Sim::findObject( objectName );
  556. if (obj /*&& !obj->isLocalName()*/)
  557. {
  558. if ( isSingleton )
  559. {
  560. // Make sure we're not trying to change types
  561. if ( dStricmp( obj->getClassName(), callArgv[1] ) != 0 )
  562. {
  563. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare object [%s] with a different class [%s] - was [%s].",
  564. getFileLine(ip), objectName, callArgv[1], obj->getClassName());
  565. ip = failJump;
  566. STR.popFrame();
  567. break;
  568. }
  569. // We're creating a singleton, so use the found object
  570. // instead of creating a new object.
  571. currentNewObject = obj;
  572. }
  573. else
  574. {
  575. const char* redefineBehavior = Con::getVariable( "$Con::redefineBehavior" );
  576. if( dStricmp( redefineBehavior, "replaceExisting" ) == 0 )
  577. {
  578. // Save our constructor args as the argv vector is stored on the
  579. // string stack and may get stomped if deleteObject triggers
  580. // script execution.
  581. const char* savedArgv[ StringStack::MaxArgs ];
  582. dMemcpy( savedArgv, callArgv, sizeof( savedArgv[ 0 ] ) * callArgc );
  583. obj->deleteObject();
  584. obj = NULL;
  585. dMemcpy( callArgv, savedArgv, sizeof( callArgv[ 0 ] ) * callArgc );
  586. }
  587. else if( dStricmp( redefineBehavior, "renameNew" ) == 0 )
  588. {
  589. for( U32 i = 1;; ++ i )
  590. {
  591. String newName = String::ToString( "%s%i", objectName, i );
  592. if( !Sim::findObject( newName ) )
  593. {
  594. objectName = StringTable->insert( newName );
  595. break;
  596. }
  597. }
  598. }
  599. else if( dStricmp( redefineBehavior, "unnameNew" ) == 0 )
  600. {
  601. objectName = StringTable->insert( "" );
  602. }
  603. else if( dStricmp( redefineBehavior, "postfixNew" ) == 0 )
  604. {
  605. const char* postfix = Con::getVariable( "$Con::redefineBehaviorPostfix" );
  606. String newName = String::ToString( "%s%s", objectName, postfix );
  607. if( Sim::findObject( newName ) )
  608. {
  609. Con::errorf( ConsoleLogEntry::General, "%s: Cannot re-declare object with postfix [%s].",
  610. getFileLine(ip), newName.c_str() );
  611. ip = failJump;
  612. STR.popFrame();
  613. break;
  614. }
  615. else
  616. objectName = StringTable->insert( newName );
  617. }
  618. else
  619. {
  620. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare object [%s].",
  621. getFileLine(ip), objectName);
  622. ip = failJump;
  623. STR.popFrame();
  624. break;
  625. }
  626. }
  627. }
  628. }
  629. STR.popFrame();
  630. if(!currentNewObject)
  631. {
  632. // Well, looks like we have to create a new object.
  633. ConsoleObject *object = ConsoleObject::create(callArgv[1]);
  634. // Deal with failure!
  635. if(!object)
  636. {
  637. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-conobject class %s.", getFileLine(ip), callArgv[1]);
  638. ip = failJump;
  639. break;
  640. }
  641. // Do special datablock init if appropros
  642. if(isDataBlock)
  643. {
  644. SimDataBlock *dataBlock = dynamic_cast<SimDataBlock *>(object);
  645. if(dataBlock)
  646. {
  647. dataBlock->assignId();
  648. }
  649. else
  650. {
  651. // They tried to make a non-datablock with a datablock keyword!
  652. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-datablock class %s.", getFileLine(ip), callArgv[1]);
  653. // Clean up...
  654. delete object;
  655. ip = failJump;
  656. break;
  657. }
  658. }
  659. // Finally, set currentNewObject to point to the new one.
  660. currentNewObject = dynamic_cast<SimObject *>(object);
  661. // Deal with the case of a non-SimObject.
  662. if(!currentNewObject)
  663. {
  664. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-SimObject class %s.", getFileLine(ip), callArgv[1]);
  665. delete object;
  666. ip = failJump;
  667. break;
  668. }
  669. // Set the declaration line
  670. currentNewObject->setDeclarationLine(lineNumber);
  671. // Set the file that this object was created in
  672. currentNewObject->setFilename(name);
  673. // Does it have a parent object? (ie, the copy constructor : syntax, not inheriance)
  674. if(*objParent)
  675. {
  676. // Find it!
  677. SimObject *parent;
  678. if(Sim::findObject(objParent, parent))
  679. {
  680. // Con::printf(" - Parent object found: %s", parent->getClassName());
  681. currentNewObject->setCopySource( parent );
  682. currentNewObject->assignFieldsFrom( parent );
  683. }
  684. else
  685. {
  686. if ( Con::gObjectCopyFailures == -1 )
  687. Con::errorf(ConsoleLogEntry::General, "%s: Unable to find parent object %s for %s.", getFileLine(ip), objParent, callArgv[1]);
  688. else
  689. ++Con::gObjectCopyFailures;
  690. // Fail to create the object.
  691. delete object;
  692. ip = failJump;
  693. break;
  694. }
  695. }
  696. // If a name was passed, assign it.
  697. if( objectName[ 0 ] )
  698. {
  699. if( !isInternal )
  700. currentNewObject->assignName( objectName );
  701. else
  702. currentNewObject->setInternalName( objectName );
  703. // Set the original name
  704. currentNewObject->setOriginalName( objectName );
  705. }
  706. // Do the constructor parameters.
  707. if(!currentNewObject->processArguments(callArgc-3, callArgv+3))
  708. {
  709. delete currentNewObject;
  710. currentNewObject = NULL;
  711. ip = failJump;
  712. break;
  713. }
  714. // If it's not a datablock, allow people to modify bits of it.
  715. if(!isDataBlock)
  716. {
  717. currentNewObject->setModStaticFields(true);
  718. currentNewObject->setModDynamicFields(true);
  719. }
  720. }
  721. // Advance the IP past the create info...
  722. ip += 6;
  723. break;
  724. }
  725. case OP_ADD_OBJECT:
  726. {
  727. // See OP_SETCURVAR for why we do this.
  728. curFNDocBlock = NULL;
  729. curNSDocBlock = NULL;
  730. // Do we place this object at the root?
  731. bool placeAtRoot = code[ip++];
  732. // Con::printf("Adding object %s", currentNewObject->getName());
  733. // Make sure it wasn't already added, then add it.
  734. if(currentNewObject->isProperlyAdded() == false)
  735. {
  736. bool ret = false;
  737. Message *msg = dynamic_cast<Message *>(currentNewObject);
  738. if(msg)
  739. {
  740. SimObjectId id = Message::getNextMessageID();
  741. if(id != 0xffffffff)
  742. ret = currentNewObject->registerObject(id);
  743. else
  744. Con::errorf("%s: No more object IDs available for messages", getFileLine(ip));
  745. }
  746. else
  747. ret = currentNewObject->registerObject();
  748. if(! ret)
  749. {
  750. // This error is usually caused by failing to call Parent::initPersistFields in the class' initPersistFields().
  751. Con::warnf(ConsoleLogEntry::General, "%s: Register object failed for object %s of class %s.", getFileLine(ip), currentNewObject->getName(), currentNewObject->getClassName());
  752. delete currentNewObject;
  753. ip = failJump;
  754. break;
  755. }
  756. }
  757. // Are we dealing with a datablock?
  758. SimDataBlock *dataBlock = dynamic_cast<SimDataBlock *>(currentNewObject);
  759. static String errorStr;
  760. // If so, preload it.
  761. if(dataBlock && !dataBlock->preload(true, errorStr))
  762. {
  763. Con::errorf(ConsoleLogEntry::General, "%s: preload failed for %s: %s.", getFileLine(ip),
  764. currentNewObject->getName(), errorStr.c_str());
  765. dataBlock->deleteObject();
  766. ip = failJump;
  767. break;
  768. }
  769. // What group will we be added to, if any?
  770. U32 groupAddId = intStack[_UINT];
  771. SimGroup *grp = NULL;
  772. SimSet *set = NULL;
  773. bool isMessage = dynamic_cast<Message *>(currentNewObject) != NULL;
  774. if(!placeAtRoot || !currentNewObject->getGroup())
  775. {
  776. if(! isMessage)
  777. {
  778. if(! placeAtRoot)
  779. {
  780. // Otherwise just add to the requested group or set.
  781. if(!Sim::findObject(groupAddId, grp))
  782. Sim::findObject(groupAddId, set);
  783. }
  784. if(placeAtRoot)
  785. {
  786. // Deal with the instantGroup if we're being put at the root or we're adding to a component.
  787. if( Con::gInstantGroup.isEmpty()
  788. || !Sim::findObject( Con::gInstantGroup, grp ) )
  789. grp = Sim::getRootGroup();
  790. }
  791. }
  792. // If we didn't get a group, then make sure we have a pointer to
  793. // the rootgroup.
  794. if(!grp)
  795. grp = Sim::getRootGroup();
  796. // add to the parent group
  797. grp->addObject(currentNewObject);
  798. // If for some reason the add failed, add the object to the
  799. // root group so it won't leak.
  800. if( !currentNewObject->getGroup() )
  801. Sim::getRootGroup()->addObject( currentNewObject );
  802. // add to any set we might be in
  803. if(set)
  804. set->addObject(currentNewObject);
  805. }
  806. // store the new object's ID on the stack (overwriting the group/set
  807. // id, if one was given, otherwise getting pushed)
  808. if(placeAtRoot)
  809. intStack[_UINT] = currentNewObject->getId();
  810. else
  811. intStack[++_UINT] = currentNewObject->getId();
  812. break;
  813. }
  814. case OP_END_OBJECT:
  815. {
  816. // If we're not to be placed at the root, make sure we clean up
  817. // our group reference.
  818. bool placeAtRoot = code[ip++];
  819. if(!placeAtRoot)
  820. _UINT--;
  821. break;
  822. }
  823. case OP_FINISH_OBJECT:
  824. {
  825. //Assert( objectCreationStackIndex >= 0 );
  826. // Restore the object info from the stack [7/9/2007 Black]
  827. currentNewObject = objectCreationStack[ --objectCreationStackIndex ].newObject;
  828. failJump = objectCreationStack[ objectCreationStackIndex ].failJump;
  829. break;
  830. }
  831. case OP_JMPIFFNOT:
  832. if(floatStack[_FLT--])
  833. {
  834. ip++;
  835. break;
  836. }
  837. ip = code[ip];
  838. break;
  839. case OP_JMPIFNOT:
  840. if(intStack[_UINT--])
  841. {
  842. ip++;
  843. break;
  844. }
  845. ip = code[ip];
  846. break;
  847. case OP_JMPIFF:
  848. if(!floatStack[_FLT--])
  849. {
  850. ip++;
  851. break;
  852. }
  853. ip = code[ip];
  854. break;
  855. case OP_JMPIF:
  856. if(!intStack[_UINT--])
  857. {
  858. ip ++;
  859. break;
  860. }
  861. ip = code[ip];
  862. break;
  863. case OP_JMPIFNOT_NP:
  864. if(intStack[_UINT])
  865. {
  866. _UINT--;
  867. ip++;
  868. break;
  869. }
  870. ip = code[ip];
  871. break;
  872. case OP_JMPIF_NP:
  873. if(!intStack[_UINT])
  874. {
  875. _UINT--;
  876. ip++;
  877. break;
  878. }
  879. ip = code[ip];
  880. break;
  881. case OP_JMP:
  882. ip = code[ip];
  883. break;
  884. // This fixes a bug when not explicitly returning a value.
  885. case OP_RETURN_VOID:
  886. STR.setStringValue("");
  887. // We're falling thru here on purpose.
  888. case OP_RETURN:
  889. if( iterDepth > 0 )
  890. {
  891. // Clear iterator state.
  892. while( iterDepth > 0 )
  893. {
  894. iterStack[ -- _ITER ].mIsStringIter = false;
  895. -- iterDepth;
  896. }
  897. const char* returnValue = STR.getStringValue();
  898. STR.rewind();
  899. STR.setStringValue( returnValue ); // Not nice but works.
  900. }
  901. goto execFinished;
  902. case OP_CMPEQ:
  903. intStack[_UINT+1] = bool(floatStack[_FLT] == floatStack[_FLT-1]);
  904. _UINT++;
  905. _FLT -= 2;
  906. break;
  907. case OP_CMPGR:
  908. intStack[_UINT+1] = bool(floatStack[_FLT] > floatStack[_FLT-1]);
  909. _UINT++;
  910. _FLT -= 2;
  911. break;
  912. case OP_CMPGE:
  913. intStack[_UINT+1] = bool(floatStack[_FLT] >= floatStack[_FLT-1]);
  914. _UINT++;
  915. _FLT -= 2;
  916. break;
  917. case OP_CMPLT:
  918. intStack[_UINT+1] = bool(floatStack[_FLT] < floatStack[_FLT-1]);
  919. _UINT++;
  920. _FLT -= 2;
  921. break;
  922. case OP_CMPLE:
  923. intStack[_UINT+1] = bool(floatStack[_FLT] <= floatStack[_FLT-1]);
  924. _UINT++;
  925. _FLT -= 2;
  926. break;
  927. case OP_CMPNE:
  928. intStack[_UINT+1] = bool(floatStack[_FLT] != floatStack[_FLT-1]);
  929. _UINT++;
  930. _FLT -= 2;
  931. break;
  932. case OP_XOR:
  933. intStack[_UINT-1] = intStack[_UINT] ^ intStack[_UINT-1];
  934. _UINT--;
  935. break;
  936. case OP_MOD:
  937. if( intStack[_UINT-1] != 0 )
  938. intStack[_UINT-1] = intStack[_UINT] % intStack[_UINT-1];
  939. else
  940. intStack[_UINT-1] = 0;
  941. _UINT--;
  942. break;
  943. case OP_BITAND:
  944. intStack[_UINT-1] = intStack[_UINT] & intStack[_UINT-1];
  945. _UINT--;
  946. break;
  947. case OP_BITOR:
  948. intStack[_UINT-1] = intStack[_UINT] | intStack[_UINT-1];
  949. _UINT--;
  950. break;
  951. case OP_NOT:
  952. intStack[_UINT] = !intStack[_UINT];
  953. break;
  954. case OP_NOTF:
  955. intStack[_UINT+1] = !floatStack[_FLT];
  956. _FLT--;
  957. _UINT++;
  958. break;
  959. case OP_ONESCOMPLEMENT:
  960. intStack[_UINT] = ~intStack[_UINT];
  961. break;
  962. case OP_SHR:
  963. intStack[_UINT-1] = intStack[_UINT] >> intStack[_UINT-1];
  964. _UINT--;
  965. break;
  966. case OP_SHL:
  967. intStack[_UINT-1] = intStack[_UINT] << intStack[_UINT-1];
  968. _UINT--;
  969. break;
  970. case OP_AND:
  971. intStack[_UINT-1] = intStack[_UINT] && intStack[_UINT-1];
  972. _UINT--;
  973. break;
  974. case OP_OR:
  975. intStack[_UINT-1] = intStack[_UINT] || intStack[_UINT-1];
  976. _UINT--;
  977. break;
  978. case OP_ADD:
  979. floatStack[_FLT-1] = floatStack[_FLT] + floatStack[_FLT-1];
  980. _FLT--;
  981. break;
  982. case OP_SUB:
  983. floatStack[_FLT-1] = floatStack[_FLT] - floatStack[_FLT-1];
  984. _FLT--;
  985. break;
  986. case OP_MUL:
  987. floatStack[_FLT-1] = floatStack[_FLT] * floatStack[_FLT-1];
  988. _FLT--;
  989. break;
  990. case OP_DIV:
  991. floatStack[_FLT-1] = floatStack[_FLT] / floatStack[_FLT-1];
  992. _FLT--;
  993. break;
  994. case OP_NEG:
  995. floatStack[_FLT] = -floatStack[_FLT];
  996. break;
  997. case OP_SETCURVAR:
  998. var = U32toSTE(code[ip]);
  999. ip++;
  1000. // If a variable is set, then these must be NULL. It is necessary
  1001. // to set this here so that the vector parser can appropriately
  1002. // identify whether it's dealing with a vector.
  1003. prevField = NULL;
  1004. prevObject = NULL;
  1005. curObject = NULL;
  1006. gEvalState.setCurVarName(var);
  1007. // In order to let docblocks work properly with variables, we have
  1008. // clear the current docblock when we do an assign. This way it
  1009. // won't inappropriately carry forward to following function decls.
  1010. curFNDocBlock = NULL;
  1011. curNSDocBlock = NULL;
  1012. break;
  1013. case OP_SETCURVAR_CREATE:
  1014. var = U32toSTE(code[ip]);
  1015. ip++;
  1016. // See OP_SETCURVAR
  1017. prevField = NULL;
  1018. prevObject = NULL;
  1019. curObject = NULL;
  1020. gEvalState.setCurVarNameCreate(var);
  1021. // See OP_SETCURVAR for why we do this.
  1022. curFNDocBlock = NULL;
  1023. curNSDocBlock = NULL;
  1024. break;
  1025. case OP_SETCURVAR_ARRAY:
  1026. var = STR.getSTValue();
  1027. // See OP_SETCURVAR
  1028. prevField = NULL;
  1029. prevObject = NULL;
  1030. curObject = NULL;
  1031. gEvalState.setCurVarName(var);
  1032. // See OP_SETCURVAR for why we do this.
  1033. curFNDocBlock = NULL;
  1034. curNSDocBlock = NULL;
  1035. break;
  1036. case OP_SETCURVAR_ARRAY_CREATE:
  1037. var = STR.getSTValue();
  1038. // See OP_SETCURVAR
  1039. prevField = NULL;
  1040. prevObject = NULL;
  1041. curObject = NULL;
  1042. gEvalState.setCurVarNameCreate(var);
  1043. // See OP_SETCURVAR for why we do this.
  1044. curFNDocBlock = NULL;
  1045. curNSDocBlock = NULL;
  1046. break;
  1047. case OP_LOADVAR_UINT:
  1048. intStack[_UINT+1] = gEvalState.getIntVariable();
  1049. _UINT++;
  1050. break;
  1051. case OP_LOADVAR_FLT:
  1052. floatStack[_FLT+1] = gEvalState.getFloatVariable();
  1053. _FLT++;
  1054. break;
  1055. case OP_LOADVAR_STR:
  1056. val = gEvalState.getStringVariable();
  1057. STR.setStringValue(val);
  1058. break;
  1059. case OP_SAVEVAR_UINT:
  1060. gEvalState.setIntVariable(intStack[_UINT]);
  1061. break;
  1062. case OP_SAVEVAR_FLT:
  1063. gEvalState.setFloatVariable(floatStack[_FLT]);
  1064. break;
  1065. case OP_SAVEVAR_STR:
  1066. gEvalState.setStringVariable(STR.getStringValue());
  1067. break;
  1068. case OP_SETCUROBJECT:
  1069. // Save the previous object for parsing vector fields.
  1070. prevObject = curObject;
  1071. val = STR.getStringValue();
  1072. // Sim::findObject will sometimes find valid objects from
  1073. // multi-component strings. This makes sure that doesn't
  1074. // happen.
  1075. for( const char* check = val; *check; check++ )
  1076. {
  1077. if( *check == ' ' )
  1078. {
  1079. val = "";
  1080. break;
  1081. }
  1082. }
  1083. curObject = Sim::findObject(val);
  1084. break;
  1085. case OP_SETCUROBJECT_INTERNAL:
  1086. ++ip; // To skip the recurse flag if the object wasn't found
  1087. if(curObject)
  1088. {
  1089. SimSet *set = dynamic_cast<SimSet *>(curObject);
  1090. if(set)
  1091. {
  1092. StringTableEntry intName = StringTable->insert(STR.getStringValue());
  1093. bool recurse = code[ip-1];
  1094. SimObject *obj = set->findObjectByInternalName(intName, recurse);
  1095. intStack[_UINT+1] = obj ? obj->getId() : 0;
  1096. _UINT++;
  1097. }
  1098. else
  1099. {
  1100. Con::errorf(ConsoleLogEntry::Script, "%s: Attempt to use -> on non-set %s of class %s.", getFileLine(ip-2), curObject->getName(), curObject->getClassName());
  1101. intStack[_UINT] = 0;
  1102. }
  1103. }
  1104. break;
  1105. case OP_SETCUROBJECT_NEW:
  1106. curObject = currentNewObject;
  1107. break;
  1108. case OP_SETCURFIELD:
  1109. // Save the previous field for parsing vector fields.
  1110. prevField = curField;
  1111. dStrcpy( prevFieldArray, curFieldArray );
  1112. curField = U32toSTE(code[ip]);
  1113. curFieldArray[0] = 0;
  1114. ip++;
  1115. break;
  1116. case OP_SETCURFIELD_ARRAY:
  1117. dStrcpy(curFieldArray, STR.getStringValue());
  1118. break;
  1119. case OP_SETCURFIELD_TYPE:
  1120. if(curObject)
  1121. curObject->setDataFieldType(code[ip], curField, curFieldArray);
  1122. ip++;
  1123. break;
  1124. case OP_LOADFIELD_UINT:
  1125. if(curObject)
  1126. intStack[_UINT+1] = U32(dAtoi(curObject->getDataField(curField, curFieldArray)));
  1127. else
  1128. {
  1129. // The field is not being retrieved from an object. Maybe it's
  1130. // a special accessor?
  1131. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1132. intStack[_UINT+1] = dAtoi( valBuffer );
  1133. }
  1134. _UINT++;
  1135. break;
  1136. case OP_LOADFIELD_FLT:
  1137. if(curObject)
  1138. floatStack[_FLT+1] = dAtof(curObject->getDataField(curField, curFieldArray));
  1139. else
  1140. {
  1141. // The field is not being retrieved from an object. Maybe it's
  1142. // a special accessor?
  1143. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1144. floatStack[_FLT+1] = dAtof( valBuffer );
  1145. }
  1146. _FLT++;
  1147. break;
  1148. case OP_LOADFIELD_STR:
  1149. if(curObject)
  1150. {
  1151. val = curObject->getDataField(curField, curFieldArray);
  1152. STR.setStringValue( val );
  1153. }
  1154. else
  1155. {
  1156. // The field is not being retrieved from an object. Maybe it's
  1157. // a special accessor?
  1158. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1159. STR.setStringValue( valBuffer );
  1160. }
  1161. break;
  1162. case OP_SAVEFIELD_UINT:
  1163. STR.setIntValue(intStack[_UINT]);
  1164. if(curObject)
  1165. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1166. else
  1167. {
  1168. // The field is not being set on an object. Maybe it's
  1169. // a special accessor?
  1170. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1171. prevObject = NULL;
  1172. }
  1173. break;
  1174. case OP_SAVEFIELD_FLT:
  1175. STR.setFloatValue(floatStack[_FLT]);
  1176. if(curObject)
  1177. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1178. else
  1179. {
  1180. // The field is not being set on an object. Maybe it's
  1181. // a special accessor?
  1182. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1183. prevObject = NULL;
  1184. }
  1185. break;
  1186. case OP_SAVEFIELD_STR:
  1187. if(curObject)
  1188. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1189. else
  1190. {
  1191. // The field is not being set on an object. Maybe it's
  1192. // a special accessor?
  1193. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1194. prevObject = NULL;
  1195. }
  1196. break;
  1197. case OP_STR_TO_UINT:
  1198. intStack[_UINT+1] = STR.getIntValue();
  1199. _UINT++;
  1200. break;
  1201. case OP_STR_TO_FLT:
  1202. floatStack[_FLT+1] = STR.getFloatValue();
  1203. _FLT++;
  1204. break;
  1205. case OP_STR_TO_NONE:
  1206. // This exists simply to deal with certain typecast situations.
  1207. break;
  1208. case OP_FLT_TO_UINT:
  1209. intStack[_UINT+1] = (S64)floatStack[_FLT];
  1210. _FLT--;
  1211. _UINT++;
  1212. break;
  1213. case OP_FLT_TO_STR:
  1214. STR.setFloatValue(floatStack[_FLT]);
  1215. _FLT--;
  1216. break;
  1217. case OP_FLT_TO_NONE:
  1218. _FLT--;
  1219. break;
  1220. case OP_UINT_TO_FLT:
  1221. floatStack[_FLT+1] = (F32)intStack[_UINT];
  1222. _UINT--;
  1223. _FLT++;
  1224. break;
  1225. case OP_UINT_TO_STR:
  1226. STR.setIntValue(intStack[_UINT]);
  1227. _UINT--;
  1228. break;
  1229. case OP_UINT_TO_NONE:
  1230. _UINT--;
  1231. break;
  1232. case OP_LOADIMMED_UINT:
  1233. intStack[_UINT+1] = code[ip++];
  1234. _UINT++;
  1235. break;
  1236. case OP_LOADIMMED_FLT:
  1237. floatStack[_FLT+1] = curFloatTable[code[ip]];
  1238. ip++;
  1239. _FLT++;
  1240. break;
  1241. case OP_TAG_TO_STR:
  1242. code[ip-1] = OP_LOADIMMED_STR;
  1243. // it's possible the string has already been converted
  1244. if(U8(curStringTable[code[ip]]) != StringTagPrefixByte)
  1245. {
  1246. U32 id = GameAddTaggedString(curStringTable + code[ip]);
  1247. dSprintf(curStringTable + code[ip] + 1, 7, "%d", id);
  1248. *(curStringTable + code[ip]) = StringTagPrefixByte;
  1249. }
  1250. case OP_LOADIMMED_STR:
  1251. STR.setStringValue(curStringTable + code[ip++]);
  1252. break;
  1253. case OP_DOCBLOCK_STR:
  1254. {
  1255. // If the first word of the doc is '\class' or '@class', then this
  1256. // is a namespace doc block, otherwise it is a function doc block.
  1257. const char* docblock = curStringTable + code[ip++];
  1258. const char* sansClass = dStrstr( docblock, "@class" );
  1259. if( !sansClass )
  1260. sansClass = dStrstr( docblock, "\\class" );
  1261. if( sansClass )
  1262. {
  1263. // Don't save the class declaration. Scan past the 'class'
  1264. // keyword and up to the first whitespace.
  1265. sansClass += 7;
  1266. S32 index = 0;
  1267. while( ( *sansClass != ' ' ) && ( *sansClass != '\n' ) && *sansClass && ( index < ( nsDocLength - 1 ) ) )
  1268. {
  1269. nsDocBlockClass[index++] = *sansClass;
  1270. sansClass++;
  1271. }
  1272. nsDocBlockClass[index] = '\0';
  1273. curNSDocBlock = sansClass + 1;
  1274. }
  1275. else
  1276. curFNDocBlock = docblock;
  1277. }
  1278. break;
  1279. case OP_LOADIMMED_IDENT:
  1280. STR.setStringValue(U32toSTE(code[ip++]));
  1281. break;
  1282. case OP_CALLFUNC_RESOLVE:
  1283. // This deals with a function that is potentially living in a namespace.
  1284. fnNamespace = U32toSTE(code[ip+1]);
  1285. fnName = U32toSTE(code[ip]);
  1286. // Try to look it up.
  1287. ns = Namespace::find(fnNamespace);
  1288. nsEntry = ns->lookup(fnName);
  1289. if(!nsEntry)
  1290. {
  1291. ip+= 3;
  1292. Con::warnf(ConsoleLogEntry::General,
  1293. "%s: Unable to find function %s%s%s",
  1294. getFileLine(ip-4), fnNamespace ? fnNamespace : "",
  1295. fnNamespace ? "::" : "", fnName);
  1296. STR.popFrame();
  1297. break;
  1298. }
  1299. // Now fall through to OP_CALLFUNC...
  1300. case OP_CALLFUNC:
  1301. {
  1302. // This routingId is set when we query the object as to whether
  1303. // it handles this method. It is set to an enum from the table
  1304. // above indicating whether it handles it on a component it owns
  1305. // or just on the object.
  1306. S32 routingId = 0;
  1307. fnName = U32toSTE(code[ip]);
  1308. //if this is called from inside a function, append the ip and codeptr
  1309. if( gEvalState.getStackDepth() > 0 )
  1310. {
  1311. gEvalState.getCurrentFrame().code = this;
  1312. gEvalState.getCurrentFrame().ip = ip - 1;
  1313. }
  1314. U32 callType = code[ip+2];
  1315. ip += 3;
  1316. STR.getArgcArgv(fnName, &callArgc, &callArgv);
  1317. const char *componentReturnValue = "";
  1318. if(callType == FuncCallExprNode::FunctionCall)
  1319. {
  1320. if( !nsEntry )
  1321. {
  1322. // We must not have come from OP_CALLFUNC_RESOLVE, so figure out
  1323. // our own entry.
  1324. nsEntry = Namespace::global()->lookup( fnName );
  1325. }
  1326. ns = NULL;
  1327. }
  1328. else if(callType == FuncCallExprNode::MethodCall)
  1329. {
  1330. saveObject = gEvalState.thisObject;
  1331. gEvalState.thisObject = Sim::findObject(callArgv[1]);
  1332. if(!gEvalState.thisObject)
  1333. {
  1334. // Go back to the previous saved object.
  1335. gEvalState.thisObject = saveObject;
  1336. Con::warnf(ConsoleLogEntry::General,"%s: Unable to find object: '%s' attempting to call function '%s'", getFileLine(ip-4), callArgv[1], fnName);
  1337. STR.popFrame();
  1338. break;
  1339. }
  1340. bool handlesMethod = gEvalState.thisObject->handlesConsoleMethod(fnName,&routingId);
  1341. if( handlesMethod && routingId == MethodOnComponent )
  1342. {
  1343. ICallMethod *pComponent = dynamic_cast<ICallMethod *>( gEvalState.thisObject );
  1344. if( pComponent )
  1345. componentReturnValue = pComponent->callMethodArgList( callArgc, callArgv, false );
  1346. }
  1347. ns = gEvalState.thisObject->getNamespace();
  1348. if(ns)
  1349. nsEntry = ns->lookup(fnName);
  1350. else
  1351. nsEntry = NULL;
  1352. }
  1353. else // it's a ParentCall
  1354. {
  1355. if(thisNamespace)
  1356. {
  1357. ns = thisNamespace->mParent;
  1358. if(ns)
  1359. nsEntry = ns->lookup(fnName);
  1360. else
  1361. nsEntry = NULL;
  1362. }
  1363. else
  1364. {
  1365. ns = NULL;
  1366. nsEntry = NULL;
  1367. }
  1368. }
  1369. Namespace::Entry::CallbackUnion * nsCb = NULL;
  1370. const char * nsUsage = NULL;
  1371. if (nsEntry)
  1372. {
  1373. nsCb = &nsEntry->cb;
  1374. nsUsage = nsEntry->mUsage;
  1375. routingId = 0;
  1376. }
  1377. if(!nsEntry || noCalls)
  1378. {
  1379. if(!noCalls && !( routingId == MethodOnComponent ) )
  1380. {
  1381. Con::warnf(ConsoleLogEntry::General,"%s: Unknown command %s.", getFileLine(ip-4), fnName);
  1382. if(callType == FuncCallExprNode::MethodCall)
  1383. {
  1384. Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s",
  1385. gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : "",
  1386. gEvalState.thisObject->getId(), Con::getNamespaceList(ns) );
  1387. }
  1388. }
  1389. STR.popFrame();
  1390. if( routingId == MethodOnComponent )
  1391. STR.setStringValue( componentReturnValue );
  1392. else
  1393. STR.setStringValue( "" );
  1394. break;
  1395. }
  1396. if(nsEntry->mType == Namespace::Entry::ConsoleFunctionType)
  1397. {
  1398. const char *ret = "";
  1399. if(nsEntry->mFunctionOffset)
  1400. ret = nsEntry->mCode->exec(nsEntry->mFunctionOffset, fnName, nsEntry->mNamespace, callArgc, callArgv, false, nsEntry->mPackage);
  1401. STR.popFrame();
  1402. STR.setStringValue(ret);
  1403. }
  1404. else
  1405. {
  1406. const char* nsName = ns? ns->mName: "";
  1407. #ifndef TORQUE_DEBUG
  1408. // [tom, 12/13/2006] This stops tools functions from working in the console,
  1409. // which is useful behavior when debugging so I'm ifdefing this out for debug builds.
  1410. if(nsEntry->mToolOnly && ! Con::isCurrentScriptToolScript())
  1411. {
  1412. Con::errorf(ConsoleLogEntry::Script, "%s: %s::%s - attempting to call tools only function from outside of tools.", getFileLine(ip-4), nsName, fnName);
  1413. }
  1414. else
  1415. #endif
  1416. if((nsEntry->mMinArgs && S32(callArgc) < nsEntry->mMinArgs) || (nsEntry->mMaxArgs && S32(callArgc) > nsEntry->mMaxArgs))
  1417. {
  1418. Con::warnf(ConsoleLogEntry::Script, "%s: %s::%s - wrong number of arguments (got %i, expected min %i and max %i).",
  1419. getFileLine(ip-4), nsName, fnName,
  1420. callArgc, nsEntry->mMinArgs, nsEntry->mMaxArgs);
  1421. Con::warnf(ConsoleLogEntry::Script, "%s: usage: %s", getFileLine(ip-4), nsEntry->mUsage);
  1422. STR.popFrame();
  1423. }
  1424. else
  1425. {
  1426. switch(nsEntry->mType)
  1427. {
  1428. case Namespace::Entry::StringCallbackType:
  1429. {
  1430. const char *ret = nsEntry->cb.mStringCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1431. STR.popFrame();
  1432. if(ret != STR.getStringValue())
  1433. STR.setStringValue(ret);
  1434. else
  1435. STR.setLen(dStrlen(ret));
  1436. break;
  1437. }
  1438. case Namespace::Entry::IntCallbackType:
  1439. {
  1440. S32 result = nsEntry->cb.mIntCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1441. STR.popFrame();
  1442. if(code[ip] == OP_STR_TO_UINT)
  1443. {
  1444. ip++;
  1445. intStack[++_UINT] = result;
  1446. break;
  1447. }
  1448. else if(code[ip] == OP_STR_TO_FLT)
  1449. {
  1450. ip++;
  1451. floatStack[++_FLT] = result;
  1452. break;
  1453. }
  1454. else if(code[ip] == OP_STR_TO_NONE)
  1455. ip++;
  1456. else
  1457. STR.setIntValue(result);
  1458. break;
  1459. }
  1460. case Namespace::Entry::FloatCallbackType:
  1461. {
  1462. F64 result = nsEntry->cb.mFloatCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1463. STR.popFrame();
  1464. if(code[ip] == OP_STR_TO_UINT)
  1465. {
  1466. ip++;
  1467. intStack[++_UINT] = (S64)result;
  1468. break;
  1469. }
  1470. else if(code[ip] == OP_STR_TO_FLT)
  1471. {
  1472. ip++;
  1473. floatStack[++_FLT] = result;
  1474. break;
  1475. }
  1476. else if(code[ip] == OP_STR_TO_NONE)
  1477. ip++;
  1478. else
  1479. STR.setFloatValue(result);
  1480. break;
  1481. }
  1482. case Namespace::Entry::VoidCallbackType:
  1483. nsEntry->cb.mVoidCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1484. if( code[ ip ] != OP_STR_TO_NONE && Con::getBoolVariable( "$Con::warnVoidAssignment", true ) )
  1485. Con::warnf(ConsoleLogEntry::General, "%s: Call to %s in %s uses result of void function call.", getFileLine(ip-4), fnName, functionName);
  1486. STR.popFrame();
  1487. STR.setStringValue("");
  1488. break;
  1489. case Namespace::Entry::BoolCallbackType:
  1490. {
  1491. bool result = nsEntry->cb.mBoolCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1492. STR.popFrame();
  1493. if(code[ip] == OP_STR_TO_UINT)
  1494. {
  1495. ip++;
  1496. intStack[++_UINT] = result;
  1497. break;
  1498. }
  1499. else if(code[ip] == OP_STR_TO_FLT)
  1500. {
  1501. ip++;
  1502. floatStack[++_FLT] = result;
  1503. break;
  1504. }
  1505. else if(code[ip] == OP_STR_TO_NONE)
  1506. ip++;
  1507. else
  1508. STR.setIntValue(result);
  1509. break;
  1510. }
  1511. }
  1512. }
  1513. }
  1514. if(callType == FuncCallExprNode::MethodCall)
  1515. gEvalState.thisObject = saveObject;
  1516. break;
  1517. }
  1518. case OP_ADVANCE_STR:
  1519. STR.advance();
  1520. break;
  1521. case OP_ADVANCE_STR_APPENDCHAR:
  1522. STR.advanceChar(code[ip++]);
  1523. break;
  1524. case OP_ADVANCE_STR_COMMA:
  1525. STR.advanceChar('_');
  1526. break;
  1527. case OP_ADVANCE_STR_NUL:
  1528. STR.advanceChar(0);
  1529. break;
  1530. case OP_REWIND_STR:
  1531. STR.rewind();
  1532. break;
  1533. case OP_TERMINATE_REWIND_STR:
  1534. STR.rewindTerminate();
  1535. break;
  1536. case OP_COMPARE_STR:
  1537. intStack[++_UINT] = STR.compare();
  1538. break;
  1539. case OP_PUSH:
  1540. STR.push();
  1541. break;
  1542. case OP_PUSH_FRAME:
  1543. STR.pushFrame();
  1544. break;
  1545. case OP_ASSERT:
  1546. {
  1547. if( !intStack[_UINT--] )
  1548. {
  1549. const char *message = curStringTable + code[ip];
  1550. U32 breakLine, inst;
  1551. findBreakLine( ip - 1, breakLine, inst );
  1552. if ( PlatformAssert::processAssert( PlatformAssert::Fatal,
  1553. name ? name : "eval",
  1554. breakLine,
  1555. message ) )
  1556. {
  1557. if ( TelDebugger && TelDebugger->isConnected() && breakLine > 0 )
  1558. {
  1559. TelDebugger->breakProcess();
  1560. }
  1561. else
  1562. Platform::debugBreak();
  1563. }
  1564. }
  1565. ip++;
  1566. break;
  1567. }
  1568. case OP_BREAK:
  1569. {
  1570. //append the ip and codeptr before managing the breakpoint!
  1571. AssertFatal( gEvalState.getStackDepth() > 0, "Empty eval stack on break!");
  1572. gEvalState.getCurrentFrame().code = this;
  1573. gEvalState.getCurrentFrame().ip = ip - 1;
  1574. U32 breakLine;
  1575. findBreakLine(ip-1, breakLine, instruction);
  1576. if(!breakLine)
  1577. goto breakContinue;
  1578. TelDebugger->executionStopped(this, breakLine);
  1579. goto breakContinue;
  1580. }
  1581. case OP_ITER_BEGIN_STR:
  1582. {
  1583. iterStack[ _ITER ].mIsStringIter = true;
  1584. /* fallthrough */
  1585. }
  1586. case OP_ITER_BEGIN:
  1587. {
  1588. StringTableEntry varName = U32toSTE( code[ ip ] );
  1589. U32 failIp = code[ ip + 1 ];
  1590. IterStackRecord& iter = iterStack[ _ITER ];
  1591. iter.mVariable = gEvalState.getCurrentFrame().add( varName );
  1592. if( iter.mIsStringIter )
  1593. {
  1594. iter.mData.mStr.mString = STR.getStringValue();
  1595. iter.mData.mStr.mIndex = 0;
  1596. }
  1597. else
  1598. {
  1599. // Look up the object.
  1600. SimSet* set;
  1601. if( !Sim::findObject( STR.getStringValue(), set ) )
  1602. {
  1603. Con::errorf( ConsoleLogEntry::General, "No SimSet object '%s'", STR.getStringValue() );
  1604. Con::errorf( ConsoleLogEntry::General, "Did you mean to use 'foreach$' instead of 'foreach'?" );
  1605. ip = failIp;
  1606. continue;
  1607. }
  1608. // Set up.
  1609. iter.mData.mObj.mSet = set;
  1610. iter.mData.mObj.mIndex = 0;
  1611. }
  1612. _ITER ++;
  1613. iterDepth ++;
  1614. STR.push();
  1615. ip += 2;
  1616. break;
  1617. }
  1618. case OP_ITER:
  1619. {
  1620. U32 breakIp = code[ ip ];
  1621. IterStackRecord& iter = iterStack[ _ITER - 1 ];
  1622. if( iter.mIsStringIter )
  1623. {
  1624. const char* str = iter.mData.mStr.mString;
  1625. U32 startIndex = iter.mData.mStr.mIndex;
  1626. U32 endIndex = startIndex;
  1627. // Break if at end.
  1628. if( !str[ startIndex ] )
  1629. {
  1630. ip = breakIp;
  1631. continue;
  1632. }
  1633. // Find right end of current component.
  1634. if( !dIsspace( str[ endIndex ] ) )
  1635. do ++ endIndex;
  1636. while( str[ endIndex ] && !dIsspace( str[ endIndex ] ) );
  1637. // Extract component.
  1638. if( endIndex != startIndex )
  1639. {
  1640. char savedChar = str[ endIndex ];
  1641. const_cast< char* >( str )[ endIndex ] = '\0'; // We are on the string stack so this is okay.
  1642. iter.mVariable->setStringValue( &str[ startIndex ] );
  1643. const_cast< char* >( str )[ endIndex ] = savedChar;
  1644. }
  1645. else
  1646. iter.mVariable->setStringValue( "" );
  1647. // Skip separator.
  1648. if( str[ endIndex ] != '\0' )
  1649. ++ endIndex;
  1650. iter.mData.mStr.mIndex = endIndex;
  1651. }
  1652. else
  1653. {
  1654. U32 index = iter.mData.mObj.mIndex;
  1655. SimSet* set = iter.mData.mObj.mSet;
  1656. if( index >= set->size() )
  1657. {
  1658. ip = breakIp;
  1659. continue;
  1660. }
  1661. iter.mVariable->setIntValue( set->at( index )->getId() );
  1662. iter.mData.mObj.mIndex = index + 1;
  1663. }
  1664. ++ ip;
  1665. break;
  1666. }
  1667. case OP_ITER_END:
  1668. {
  1669. -- _ITER;
  1670. -- iterDepth;
  1671. STR.rewind();
  1672. iterStack[ _ITER ].mIsStringIter = false;
  1673. break;
  1674. }
  1675. case OP_INVALID:
  1676. default:
  1677. // error!
  1678. goto execFinished;
  1679. }
  1680. }
  1681. execFinished:
  1682. if ( telDebuggerOn && setFrame < 0 )
  1683. TelDebugger->popStackFrame();
  1684. if ( popFrame )
  1685. gEvalState.popFrame();
  1686. if(argv)
  1687. {
  1688. if(gEvalState.traceOn)
  1689. {
  1690. traceBuffer[0] = 0;
  1691. dStrcat(traceBuffer, "Leaving ");
  1692. if(packageName)
  1693. {
  1694. dStrcat(traceBuffer, "[");
  1695. dStrcat(traceBuffer, packageName);
  1696. dStrcat(traceBuffer, "]");
  1697. }
  1698. if(thisNamespace && thisNamespace->mName)
  1699. {
  1700. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  1701. "%s::%s() - return %s", thisNamespace->mName, thisFunctionName, STR.getStringValue());
  1702. }
  1703. else
  1704. {
  1705. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  1706. "%s() - return %s", thisFunctionName, STR.getStringValue());
  1707. }
  1708. Con::printf("%s", traceBuffer);
  1709. }
  1710. }
  1711. else
  1712. {
  1713. delete[] globalStrings;
  1714. globalStringsMaxLen = 0;
  1715. delete[] globalFloats;
  1716. globalStrings = NULL;
  1717. globalFloats = NULL;
  1718. }
  1719. smCurrentCodeBlock = saveCodeBlock;
  1720. if(saveCodeBlock && saveCodeBlock->name)
  1721. {
  1722. Con::gCurrentFile = saveCodeBlock->name;
  1723. Con::gCurrentRoot = saveCodeBlock->modPath;
  1724. }
  1725. decRefCount();
  1726. #ifdef TORQUE_DEBUG
  1727. AssertFatal(!(STR.mStartStackSize > stackStart), "String stack not popped enough in script exec");
  1728. AssertFatal(!(STR.mStartStackSize < stackStart), "String stack popped too much in script exec");
  1729. #endif
  1730. return STR.getStringValue();
  1731. }
  1732. //------------------------------------------------------------