compiledEval.cpp 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028
  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. AbstractClassRep* rep = AbstractClassRep::findClassRep( objectName );
  556. if (rep != NULL) {
  557. Con::errorf(ConsoleLogEntry::General, "%s: Cannot name object [%s] the same name as a script class.",
  558. getFileLine(ip), objectName);
  559. ip = failJump;
  560. STR.popFrame();
  561. break;
  562. }
  563. SimObject *obj = Sim::findObject( objectName );
  564. if (obj /*&& !obj->isLocalName()*/)
  565. {
  566. if ( isSingleton )
  567. {
  568. // Make sure we're not trying to change types
  569. if ( dStricmp( obj->getClassName(), callArgv[1] ) != 0 )
  570. {
  571. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare object [%s] with a different class [%s] - was [%s].",
  572. getFileLine(ip), objectName, callArgv[1], obj->getClassName());
  573. ip = failJump;
  574. STR.popFrame();
  575. break;
  576. }
  577. // We're creating a singleton, so use the found object
  578. // instead of creating a new object.
  579. currentNewObject = obj;
  580. }
  581. else
  582. {
  583. const char* redefineBehavior = Con::getVariable( "$Con::redefineBehavior" );
  584. if( dStricmp( redefineBehavior, "replaceExisting" ) == 0 )
  585. {
  586. // Save our constructor args as the argv vector is stored on the
  587. // string stack and may get stomped if deleteObject triggers
  588. // script execution.
  589. const char* savedArgv[ StringStack::MaxArgs ];
  590. dMemcpy( savedArgv, callArgv, sizeof( savedArgv[ 0 ] ) * callArgc );
  591. obj->deleteObject();
  592. obj = NULL;
  593. dMemcpy( callArgv, savedArgv, sizeof( callArgv[ 0 ] ) * callArgc );
  594. }
  595. else if( dStricmp( redefineBehavior, "renameNew" ) == 0 )
  596. {
  597. for( U32 i = 1;; ++ i )
  598. {
  599. String newName = String::ToString( "%s%i", objectName, i );
  600. if( !Sim::findObject( newName ) )
  601. {
  602. objectName = StringTable->insert( newName );
  603. break;
  604. }
  605. }
  606. }
  607. else if( dStricmp( redefineBehavior, "unnameNew" ) == 0 )
  608. {
  609. objectName = StringTable->insert( "" );
  610. }
  611. else if( dStricmp( redefineBehavior, "postfixNew" ) == 0 )
  612. {
  613. const char* postfix = Con::getVariable( "$Con::redefineBehaviorPostfix" );
  614. String newName = String::ToString( "%s%s", objectName, postfix );
  615. if( Sim::findObject( newName ) )
  616. {
  617. Con::errorf( ConsoleLogEntry::General, "%s: Cannot re-declare object with postfix [%s].",
  618. getFileLine(ip), newName.c_str() );
  619. ip = failJump;
  620. STR.popFrame();
  621. break;
  622. }
  623. else
  624. objectName = StringTable->insert( newName );
  625. }
  626. else
  627. {
  628. Con::errorf(ConsoleLogEntry::General, "%s: Cannot re-declare object [%s].",
  629. getFileLine(ip), objectName);
  630. ip = failJump;
  631. STR.popFrame();
  632. break;
  633. }
  634. }
  635. }
  636. }
  637. STR.popFrame();
  638. if(!currentNewObject)
  639. {
  640. // Well, looks like we have to create a new object.
  641. ConsoleObject *object = ConsoleObject::create(callArgv[1]);
  642. // Deal with failure!
  643. if(!object)
  644. {
  645. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-conobject class %s.", getFileLine(ip), callArgv[1]);
  646. ip = failJump;
  647. break;
  648. }
  649. // Do special datablock init if appropros
  650. if(isDataBlock)
  651. {
  652. SimDataBlock *dataBlock = dynamic_cast<SimDataBlock *>(object);
  653. if(dataBlock)
  654. {
  655. dataBlock->assignId();
  656. }
  657. else
  658. {
  659. // They tried to make a non-datablock with a datablock keyword!
  660. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-datablock class %s.", getFileLine(ip), callArgv[1]);
  661. // Clean up...
  662. delete object;
  663. ip = failJump;
  664. break;
  665. }
  666. }
  667. // Finally, set currentNewObject to point to the new one.
  668. currentNewObject = dynamic_cast<SimObject *>(object);
  669. // Deal with the case of a non-SimObject.
  670. if(!currentNewObject)
  671. {
  672. Con::errorf(ConsoleLogEntry::General, "%s: Unable to instantiate non-SimObject class %s.", getFileLine(ip), callArgv[1]);
  673. delete object;
  674. ip = failJump;
  675. break;
  676. }
  677. // Set the declaration line
  678. currentNewObject->setDeclarationLine(lineNumber);
  679. // Set the file that this object was created in
  680. currentNewObject->setFilename(name);
  681. // Does it have a parent object? (ie, the copy constructor : syntax, not inheriance)
  682. if(*objParent)
  683. {
  684. // Find it!
  685. SimObject *parent;
  686. if(Sim::findObject(objParent, parent))
  687. {
  688. // Con::printf(" - Parent object found: %s", parent->getClassName());
  689. currentNewObject->setCopySource( parent );
  690. currentNewObject->assignFieldsFrom( parent );
  691. }
  692. else
  693. {
  694. if ( Con::gObjectCopyFailures == -1 )
  695. Con::errorf(ConsoleLogEntry::General, "%s: Unable to find parent object %s for %s.", getFileLine(ip), objParent, callArgv[1]);
  696. else
  697. ++Con::gObjectCopyFailures;
  698. // Fail to create the object.
  699. delete object;
  700. ip = failJump;
  701. break;
  702. }
  703. }
  704. // If a name was passed, assign it.
  705. if( objectName[ 0 ] )
  706. {
  707. if( !isInternal )
  708. currentNewObject->assignName( objectName );
  709. else
  710. currentNewObject->setInternalName( objectName );
  711. // Set the original name
  712. currentNewObject->setOriginalName( objectName );
  713. }
  714. // Do the constructor parameters.
  715. if(!currentNewObject->processArguments(callArgc-3, callArgv+3))
  716. {
  717. delete currentNewObject;
  718. currentNewObject = NULL;
  719. ip = failJump;
  720. break;
  721. }
  722. // If it's not a datablock, allow people to modify bits of it.
  723. if(!isDataBlock)
  724. {
  725. currentNewObject->setModStaticFields(true);
  726. currentNewObject->setModDynamicFields(true);
  727. }
  728. }
  729. // Advance the IP past the create info...
  730. ip += 6;
  731. break;
  732. }
  733. case OP_ADD_OBJECT:
  734. {
  735. // See OP_SETCURVAR for why we do this.
  736. curFNDocBlock = NULL;
  737. curNSDocBlock = NULL;
  738. // Do we place this object at the root?
  739. bool placeAtRoot = code[ip++];
  740. // Con::printf("Adding object %s", currentNewObject->getName());
  741. // Make sure it wasn't already added, then add it.
  742. if(currentNewObject->isProperlyAdded() == false)
  743. {
  744. bool ret = false;
  745. Message *msg = dynamic_cast<Message *>(currentNewObject);
  746. if(msg)
  747. {
  748. SimObjectId id = Message::getNextMessageID();
  749. if(id != 0xffffffff)
  750. ret = currentNewObject->registerObject(id);
  751. else
  752. Con::errorf("%s: No more object IDs available for messages", getFileLine(ip));
  753. }
  754. else
  755. ret = currentNewObject->registerObject();
  756. if(! ret)
  757. {
  758. // This error is usually caused by failing to call Parent::initPersistFields in the class' initPersistFields().
  759. Con::warnf(ConsoleLogEntry::General, "%s: Register object failed for object %s of class %s.", getFileLine(ip), currentNewObject->getName(), currentNewObject->getClassName());
  760. delete currentNewObject;
  761. ip = failJump;
  762. break;
  763. }
  764. }
  765. // Are we dealing with a datablock?
  766. SimDataBlock *dataBlock = dynamic_cast<SimDataBlock *>(currentNewObject);
  767. static String errorStr;
  768. // If so, preload it.
  769. if(dataBlock && !dataBlock->preload(true, errorStr))
  770. {
  771. Con::errorf(ConsoleLogEntry::General, "%s: preload failed for %s: %s.", getFileLine(ip),
  772. currentNewObject->getName(), errorStr.c_str());
  773. dataBlock->deleteObject();
  774. ip = failJump;
  775. break;
  776. }
  777. // What group will we be added to, if any?
  778. U32 groupAddId = intStack[_UINT];
  779. SimGroup *grp = NULL;
  780. SimSet *set = NULL;
  781. bool isMessage = dynamic_cast<Message *>(currentNewObject) != NULL;
  782. if(!placeAtRoot || !currentNewObject->getGroup())
  783. {
  784. if(! isMessage)
  785. {
  786. if(! placeAtRoot)
  787. {
  788. // Otherwise just add to the requested group or set.
  789. if(!Sim::findObject(groupAddId, grp))
  790. Sim::findObject(groupAddId, set);
  791. }
  792. if(placeAtRoot)
  793. {
  794. // Deal with the instantGroup if we're being put at the root or we're adding to a component.
  795. if( Con::gInstantGroup.isEmpty()
  796. || !Sim::findObject( Con::gInstantGroup, grp ) )
  797. grp = Sim::getRootGroup();
  798. }
  799. }
  800. // If we didn't get a group, then make sure we have a pointer to
  801. // the rootgroup.
  802. if(!grp)
  803. grp = Sim::getRootGroup();
  804. // add to the parent group
  805. grp->addObject(currentNewObject);
  806. // If for some reason the add failed, add the object to the
  807. // root group so it won't leak.
  808. if( !currentNewObject->getGroup() )
  809. Sim::getRootGroup()->addObject( currentNewObject );
  810. // add to any set we might be in
  811. if(set)
  812. set->addObject(currentNewObject);
  813. }
  814. // store the new object's ID on the stack (overwriting the group/set
  815. // id, if one was given, otherwise getting pushed)
  816. if(placeAtRoot)
  817. intStack[_UINT] = currentNewObject->getId();
  818. else
  819. intStack[++_UINT] = currentNewObject->getId();
  820. break;
  821. }
  822. case OP_END_OBJECT:
  823. {
  824. // If we're not to be placed at the root, make sure we clean up
  825. // our group reference.
  826. bool placeAtRoot = code[ip++];
  827. if(!placeAtRoot)
  828. _UINT--;
  829. break;
  830. }
  831. case OP_FINISH_OBJECT:
  832. {
  833. //Assert( objectCreationStackIndex >= 0 );
  834. // Restore the object info from the stack [7/9/2007 Black]
  835. currentNewObject = objectCreationStack[ --objectCreationStackIndex ].newObject;
  836. failJump = objectCreationStack[ objectCreationStackIndex ].failJump;
  837. break;
  838. }
  839. case OP_JMPIFFNOT:
  840. if(floatStack[_FLT--])
  841. {
  842. ip++;
  843. break;
  844. }
  845. ip = code[ip];
  846. break;
  847. case OP_JMPIFNOT:
  848. if(intStack[_UINT--])
  849. {
  850. ip++;
  851. break;
  852. }
  853. ip = code[ip];
  854. break;
  855. case OP_JMPIFF:
  856. if(!floatStack[_FLT--])
  857. {
  858. ip++;
  859. break;
  860. }
  861. ip = code[ip];
  862. break;
  863. case OP_JMPIF:
  864. if(!intStack[_UINT--])
  865. {
  866. ip ++;
  867. break;
  868. }
  869. ip = code[ip];
  870. break;
  871. case OP_JMPIFNOT_NP:
  872. if(intStack[_UINT])
  873. {
  874. _UINT--;
  875. ip++;
  876. break;
  877. }
  878. ip = code[ip];
  879. break;
  880. case OP_JMPIF_NP:
  881. if(!intStack[_UINT])
  882. {
  883. _UINT--;
  884. ip++;
  885. break;
  886. }
  887. ip = code[ip];
  888. break;
  889. case OP_JMP:
  890. ip = code[ip];
  891. break;
  892. // This fixes a bug when not explicitly returning a value.
  893. case OP_RETURN_VOID:
  894. STR.setStringValue("");
  895. // We're falling thru here on purpose.
  896. case OP_RETURN:
  897. if( iterDepth > 0 )
  898. {
  899. // Clear iterator state.
  900. while( iterDepth > 0 )
  901. {
  902. iterStack[ -- _ITER ].mIsStringIter = false;
  903. -- iterDepth;
  904. }
  905. const char* returnValue = STR.getStringValue();
  906. STR.rewind();
  907. STR.setStringValue( returnValue ); // Not nice but works.
  908. }
  909. goto execFinished;
  910. case OP_CMPEQ:
  911. intStack[_UINT+1] = bool(floatStack[_FLT] == floatStack[_FLT-1]);
  912. _UINT++;
  913. _FLT -= 2;
  914. break;
  915. case OP_CMPGR:
  916. intStack[_UINT+1] = bool(floatStack[_FLT] > floatStack[_FLT-1]);
  917. _UINT++;
  918. _FLT -= 2;
  919. break;
  920. case OP_CMPGE:
  921. intStack[_UINT+1] = bool(floatStack[_FLT] >= floatStack[_FLT-1]);
  922. _UINT++;
  923. _FLT -= 2;
  924. break;
  925. case OP_CMPLT:
  926. intStack[_UINT+1] = bool(floatStack[_FLT] < floatStack[_FLT-1]);
  927. _UINT++;
  928. _FLT -= 2;
  929. break;
  930. case OP_CMPLE:
  931. intStack[_UINT+1] = bool(floatStack[_FLT] <= floatStack[_FLT-1]);
  932. _UINT++;
  933. _FLT -= 2;
  934. break;
  935. case OP_CMPNE:
  936. intStack[_UINT+1] = bool(floatStack[_FLT] != floatStack[_FLT-1]);
  937. _UINT++;
  938. _FLT -= 2;
  939. break;
  940. case OP_XOR:
  941. intStack[_UINT-1] = intStack[_UINT] ^ intStack[_UINT-1];
  942. _UINT--;
  943. break;
  944. case OP_MOD:
  945. if( intStack[_UINT-1] != 0 )
  946. intStack[_UINT-1] = intStack[_UINT] % intStack[_UINT-1];
  947. else
  948. intStack[_UINT-1] = 0;
  949. _UINT--;
  950. break;
  951. case OP_BITAND:
  952. intStack[_UINT-1] = intStack[_UINT] & intStack[_UINT-1];
  953. _UINT--;
  954. break;
  955. case OP_BITOR:
  956. intStack[_UINT-1] = intStack[_UINT] | intStack[_UINT-1];
  957. _UINT--;
  958. break;
  959. case OP_NOT:
  960. intStack[_UINT] = !intStack[_UINT];
  961. break;
  962. case OP_NOTF:
  963. intStack[_UINT+1] = !floatStack[_FLT];
  964. _FLT--;
  965. _UINT++;
  966. break;
  967. case OP_ONESCOMPLEMENT:
  968. intStack[_UINT] = ~intStack[_UINT];
  969. break;
  970. case OP_SHR:
  971. intStack[_UINT-1] = intStack[_UINT] >> intStack[_UINT-1];
  972. _UINT--;
  973. break;
  974. case OP_SHL:
  975. intStack[_UINT-1] = intStack[_UINT] << intStack[_UINT-1];
  976. _UINT--;
  977. break;
  978. case OP_AND:
  979. intStack[_UINT-1] = intStack[_UINT] && intStack[_UINT-1];
  980. _UINT--;
  981. break;
  982. case OP_OR:
  983. intStack[_UINT-1] = intStack[_UINT] || intStack[_UINT-1];
  984. _UINT--;
  985. break;
  986. case OP_ADD:
  987. floatStack[_FLT-1] = floatStack[_FLT] + floatStack[_FLT-1];
  988. _FLT--;
  989. break;
  990. case OP_SUB:
  991. floatStack[_FLT-1] = floatStack[_FLT] - floatStack[_FLT-1];
  992. _FLT--;
  993. break;
  994. case OP_MUL:
  995. floatStack[_FLT-1] = floatStack[_FLT] * floatStack[_FLT-1];
  996. _FLT--;
  997. break;
  998. case OP_DIV:
  999. floatStack[_FLT-1] = floatStack[_FLT] / floatStack[_FLT-1];
  1000. _FLT--;
  1001. break;
  1002. case OP_NEG:
  1003. floatStack[_FLT] = -floatStack[_FLT];
  1004. break;
  1005. case OP_SETCURVAR:
  1006. var = U32toSTE(code[ip]);
  1007. ip++;
  1008. // If a variable is set, then these must be NULL. It is necessary
  1009. // to set this here so that the vector parser can appropriately
  1010. // identify whether it's dealing with a vector.
  1011. prevField = NULL;
  1012. prevObject = NULL;
  1013. curObject = NULL;
  1014. gEvalState.setCurVarName(var);
  1015. // In order to let docblocks work properly with variables, we have
  1016. // clear the current docblock when we do an assign. This way it
  1017. // won't inappropriately carry forward to following function decls.
  1018. curFNDocBlock = NULL;
  1019. curNSDocBlock = NULL;
  1020. break;
  1021. case OP_SETCURVAR_CREATE:
  1022. var = U32toSTE(code[ip]);
  1023. ip++;
  1024. // See OP_SETCURVAR
  1025. prevField = NULL;
  1026. prevObject = NULL;
  1027. curObject = NULL;
  1028. gEvalState.setCurVarNameCreate(var);
  1029. // See OP_SETCURVAR for why we do this.
  1030. curFNDocBlock = NULL;
  1031. curNSDocBlock = NULL;
  1032. break;
  1033. case OP_SETCURVAR_ARRAY:
  1034. var = STR.getSTValue();
  1035. // See OP_SETCURVAR
  1036. prevField = NULL;
  1037. prevObject = NULL;
  1038. curObject = NULL;
  1039. gEvalState.setCurVarName(var);
  1040. // See OP_SETCURVAR for why we do this.
  1041. curFNDocBlock = NULL;
  1042. curNSDocBlock = NULL;
  1043. break;
  1044. case OP_SETCURVAR_ARRAY_CREATE:
  1045. var = STR.getSTValue();
  1046. // See OP_SETCURVAR
  1047. prevField = NULL;
  1048. prevObject = NULL;
  1049. curObject = NULL;
  1050. gEvalState.setCurVarNameCreate(var);
  1051. // See OP_SETCURVAR for why we do this.
  1052. curFNDocBlock = NULL;
  1053. curNSDocBlock = NULL;
  1054. break;
  1055. case OP_LOADVAR_UINT:
  1056. intStack[_UINT+1] = gEvalState.getIntVariable();
  1057. _UINT++;
  1058. break;
  1059. case OP_LOADVAR_FLT:
  1060. floatStack[_FLT+1] = gEvalState.getFloatVariable();
  1061. _FLT++;
  1062. break;
  1063. case OP_LOADVAR_STR:
  1064. val = gEvalState.getStringVariable();
  1065. STR.setStringValue(val);
  1066. break;
  1067. case OP_SAVEVAR_UINT:
  1068. gEvalState.setIntVariable(intStack[_UINT]);
  1069. break;
  1070. case OP_SAVEVAR_FLT:
  1071. gEvalState.setFloatVariable(floatStack[_FLT]);
  1072. break;
  1073. case OP_SAVEVAR_STR:
  1074. gEvalState.setStringVariable(STR.getStringValue());
  1075. break;
  1076. case OP_SETCUROBJECT:
  1077. // Save the previous object for parsing vector fields.
  1078. prevObject = curObject;
  1079. val = STR.getStringValue();
  1080. // Sim::findObject will sometimes find valid objects from
  1081. // multi-component strings. This makes sure that doesn't
  1082. // happen.
  1083. for( const char* check = val; *check; check++ )
  1084. {
  1085. if( *check == ' ' )
  1086. {
  1087. val = "";
  1088. break;
  1089. }
  1090. }
  1091. curObject = Sim::findObject(val);
  1092. break;
  1093. case OP_SETCUROBJECT_INTERNAL:
  1094. ++ip; // To skip the recurse flag if the object wasn't found
  1095. if(curObject)
  1096. {
  1097. SimSet *set = dynamic_cast<SimSet *>(curObject);
  1098. if(set)
  1099. {
  1100. StringTableEntry intName = StringTable->insert(STR.getStringValue());
  1101. bool recurse = code[ip-1];
  1102. SimObject *obj = set->findObjectByInternalName(intName, recurse);
  1103. intStack[_UINT+1] = obj ? obj->getId() : 0;
  1104. _UINT++;
  1105. }
  1106. else
  1107. {
  1108. Con::errorf(ConsoleLogEntry::Script, "%s: Attempt to use -> on non-set %s of class %s.", getFileLine(ip-2), curObject->getName(), curObject->getClassName());
  1109. intStack[_UINT] = 0;
  1110. }
  1111. }
  1112. break;
  1113. case OP_SETCUROBJECT_NEW:
  1114. curObject = currentNewObject;
  1115. break;
  1116. case OP_SETCURFIELD:
  1117. // Save the previous field for parsing vector fields.
  1118. prevField = curField;
  1119. dStrcpy( prevFieldArray, curFieldArray );
  1120. curField = U32toSTE(code[ip]);
  1121. curFieldArray[0] = 0;
  1122. ip++;
  1123. break;
  1124. case OP_SETCURFIELD_ARRAY:
  1125. dStrcpy(curFieldArray, STR.getStringValue());
  1126. break;
  1127. case OP_SETCURFIELD_TYPE:
  1128. if(curObject)
  1129. curObject->setDataFieldType(code[ip], curField, curFieldArray);
  1130. ip++;
  1131. break;
  1132. case OP_LOADFIELD_UINT:
  1133. if(curObject)
  1134. intStack[_UINT+1] = U32(dAtoi(curObject->getDataField(curField, curFieldArray)));
  1135. else
  1136. {
  1137. // The field is not being retrieved from an object. Maybe it's
  1138. // a special accessor?
  1139. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1140. intStack[_UINT+1] = dAtoi( valBuffer );
  1141. }
  1142. _UINT++;
  1143. break;
  1144. case OP_LOADFIELD_FLT:
  1145. if(curObject)
  1146. floatStack[_FLT+1] = dAtof(curObject->getDataField(curField, curFieldArray));
  1147. else
  1148. {
  1149. // The field is not being retrieved from an object. Maybe it's
  1150. // a special accessor?
  1151. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1152. floatStack[_FLT+1] = dAtof( valBuffer );
  1153. }
  1154. _FLT++;
  1155. break;
  1156. case OP_LOADFIELD_STR:
  1157. if(curObject)
  1158. {
  1159. val = curObject->getDataField(curField, curFieldArray);
  1160. STR.setStringValue( val );
  1161. }
  1162. else
  1163. {
  1164. // The field is not being retrieved from an object. Maybe it's
  1165. // a special accessor?
  1166. getFieldComponent( prevObject, prevField, prevFieldArray, curField, valBuffer );
  1167. STR.setStringValue( valBuffer );
  1168. }
  1169. break;
  1170. case OP_SAVEFIELD_UINT:
  1171. STR.setIntValue(intStack[_UINT]);
  1172. if(curObject)
  1173. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1174. else
  1175. {
  1176. // The field is not being set on an object. Maybe it's
  1177. // a special accessor?
  1178. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1179. prevObject = NULL;
  1180. }
  1181. break;
  1182. case OP_SAVEFIELD_FLT:
  1183. STR.setFloatValue(floatStack[_FLT]);
  1184. if(curObject)
  1185. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1186. else
  1187. {
  1188. // The field is not being set on an object. Maybe it's
  1189. // a special accessor?
  1190. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1191. prevObject = NULL;
  1192. }
  1193. break;
  1194. case OP_SAVEFIELD_STR:
  1195. if(curObject)
  1196. curObject->setDataField(curField, curFieldArray, STR.getStringValue());
  1197. else
  1198. {
  1199. // The field is not being set on an object. Maybe it's
  1200. // a special accessor?
  1201. setFieldComponent( prevObject, prevField, prevFieldArray, curField );
  1202. prevObject = NULL;
  1203. }
  1204. break;
  1205. case OP_STR_TO_UINT:
  1206. intStack[_UINT+1] = STR.getIntValue();
  1207. _UINT++;
  1208. break;
  1209. case OP_STR_TO_FLT:
  1210. floatStack[_FLT+1] = STR.getFloatValue();
  1211. _FLT++;
  1212. break;
  1213. case OP_STR_TO_NONE:
  1214. // This exists simply to deal with certain typecast situations.
  1215. break;
  1216. case OP_FLT_TO_UINT:
  1217. intStack[_UINT+1] = (S64)floatStack[_FLT];
  1218. _FLT--;
  1219. _UINT++;
  1220. break;
  1221. case OP_FLT_TO_STR:
  1222. STR.setFloatValue(floatStack[_FLT]);
  1223. _FLT--;
  1224. break;
  1225. case OP_FLT_TO_NONE:
  1226. _FLT--;
  1227. break;
  1228. case OP_UINT_TO_FLT:
  1229. floatStack[_FLT+1] = (F32)intStack[_UINT];
  1230. _UINT--;
  1231. _FLT++;
  1232. break;
  1233. case OP_UINT_TO_STR:
  1234. STR.setIntValue(intStack[_UINT]);
  1235. _UINT--;
  1236. break;
  1237. case OP_UINT_TO_NONE:
  1238. _UINT--;
  1239. break;
  1240. case OP_LOADIMMED_UINT:
  1241. intStack[_UINT+1] = code[ip++];
  1242. _UINT++;
  1243. break;
  1244. case OP_LOADIMMED_FLT:
  1245. floatStack[_FLT+1] = curFloatTable[code[ip]];
  1246. ip++;
  1247. _FLT++;
  1248. break;
  1249. case OP_TAG_TO_STR:
  1250. code[ip-1] = OP_LOADIMMED_STR;
  1251. // it's possible the string has already been converted
  1252. if(U8(curStringTable[code[ip]]) != StringTagPrefixByte)
  1253. {
  1254. U32 id = GameAddTaggedString(curStringTable + code[ip]);
  1255. dSprintf(curStringTable + code[ip] + 1, 7, "%d", id);
  1256. *(curStringTable + code[ip]) = StringTagPrefixByte;
  1257. }
  1258. case OP_LOADIMMED_STR:
  1259. STR.setStringValue(curStringTable + code[ip++]);
  1260. break;
  1261. case OP_DOCBLOCK_STR:
  1262. {
  1263. // If the first word of the doc is '\class' or '@class', then this
  1264. // is a namespace doc block, otherwise it is a function doc block.
  1265. const char* docblock = curStringTable + code[ip++];
  1266. const char* sansClass = dStrstr( docblock, "@class" );
  1267. if( !sansClass )
  1268. sansClass = dStrstr( docblock, "\\class" );
  1269. if( sansClass )
  1270. {
  1271. // Don't save the class declaration. Scan past the 'class'
  1272. // keyword and up to the first whitespace.
  1273. sansClass += 7;
  1274. S32 index = 0;
  1275. while( ( *sansClass != ' ' ) && ( *sansClass != '\n' ) && *sansClass && ( index < ( nsDocLength - 1 ) ) )
  1276. {
  1277. nsDocBlockClass[index++] = *sansClass;
  1278. sansClass++;
  1279. }
  1280. nsDocBlockClass[index] = '\0';
  1281. curNSDocBlock = sansClass + 1;
  1282. }
  1283. else
  1284. curFNDocBlock = docblock;
  1285. }
  1286. break;
  1287. case OP_LOADIMMED_IDENT:
  1288. STR.setStringValue(U32toSTE(code[ip++]));
  1289. break;
  1290. case OP_CALLFUNC_RESOLVE:
  1291. // This deals with a function that is potentially living in a namespace.
  1292. fnNamespace = U32toSTE(code[ip+1]);
  1293. fnName = U32toSTE(code[ip]);
  1294. // Try to look it up.
  1295. ns = Namespace::find(fnNamespace);
  1296. nsEntry = ns->lookup(fnName);
  1297. if(!nsEntry)
  1298. {
  1299. ip+= 3;
  1300. Con::warnf(ConsoleLogEntry::General,
  1301. "%s: Unable to find function %s%s%s",
  1302. getFileLine(ip-4), fnNamespace ? fnNamespace : "",
  1303. fnNamespace ? "::" : "", fnName);
  1304. STR.popFrame();
  1305. break;
  1306. }
  1307. // Now fall through to OP_CALLFUNC...
  1308. case OP_CALLFUNC:
  1309. {
  1310. // This routingId is set when we query the object as to whether
  1311. // it handles this method. It is set to an enum from the table
  1312. // above indicating whether it handles it on a component it owns
  1313. // or just on the object.
  1314. S32 routingId = 0;
  1315. fnName = U32toSTE(code[ip]);
  1316. //if this is called from inside a function, append the ip and codeptr
  1317. if( gEvalState.getStackDepth() > 0 )
  1318. {
  1319. gEvalState.getCurrentFrame().code = this;
  1320. gEvalState.getCurrentFrame().ip = ip - 1;
  1321. }
  1322. U32 callType = code[ip+2];
  1323. ip += 3;
  1324. STR.getArgcArgv(fnName, &callArgc, &callArgv);
  1325. const char *componentReturnValue = "";
  1326. if(callType == FuncCallExprNode::FunctionCall)
  1327. {
  1328. if( !nsEntry )
  1329. {
  1330. // We must not have come from OP_CALLFUNC_RESOLVE, so figure out
  1331. // our own entry.
  1332. nsEntry = Namespace::global()->lookup( fnName );
  1333. }
  1334. ns = NULL;
  1335. }
  1336. else if(callType == FuncCallExprNode::MethodCall)
  1337. {
  1338. saveObject = gEvalState.thisObject;
  1339. gEvalState.thisObject = Sim::findObject(callArgv[1]);
  1340. if(!gEvalState.thisObject)
  1341. {
  1342. // Go back to the previous saved object.
  1343. gEvalState.thisObject = saveObject;
  1344. Con::warnf(ConsoleLogEntry::General,"%s: Unable to find object: '%s' attempting to call function '%s'", getFileLine(ip-4), callArgv[1], fnName);
  1345. STR.popFrame();
  1346. STR.setStringValue("");
  1347. break;
  1348. }
  1349. bool handlesMethod = gEvalState.thisObject->handlesConsoleMethod(fnName,&routingId);
  1350. if( handlesMethod && routingId == MethodOnComponent )
  1351. {
  1352. ICallMethod *pComponent = dynamic_cast<ICallMethod *>( gEvalState.thisObject );
  1353. if( pComponent )
  1354. componentReturnValue = pComponent->callMethodArgList( callArgc, callArgv, false );
  1355. }
  1356. ns = gEvalState.thisObject->getNamespace();
  1357. if(ns)
  1358. nsEntry = ns->lookup(fnName);
  1359. else
  1360. nsEntry = NULL;
  1361. }
  1362. else // it's a ParentCall
  1363. {
  1364. if(thisNamespace)
  1365. {
  1366. ns = thisNamespace->mParent;
  1367. if(ns)
  1368. nsEntry = ns->lookup(fnName);
  1369. else
  1370. nsEntry = NULL;
  1371. }
  1372. else
  1373. {
  1374. ns = NULL;
  1375. nsEntry = NULL;
  1376. }
  1377. }
  1378. Namespace::Entry::CallbackUnion * nsCb = NULL;
  1379. const char * nsUsage = NULL;
  1380. if (nsEntry)
  1381. {
  1382. nsCb = &nsEntry->cb;
  1383. nsUsage = nsEntry->mUsage;
  1384. routingId = 0;
  1385. }
  1386. if(!nsEntry || noCalls)
  1387. {
  1388. if(!noCalls && !( routingId == MethodOnComponent ) )
  1389. {
  1390. Con::warnf(ConsoleLogEntry::General,"%s: Unknown command %s.", getFileLine(ip-4), fnName);
  1391. if(callType == FuncCallExprNode::MethodCall)
  1392. {
  1393. Con::warnf(ConsoleLogEntry::General, " Object %s(%d) %s",
  1394. gEvalState.thisObject->getName() ? gEvalState.thisObject->getName() : "",
  1395. gEvalState.thisObject->getId(), Con::getNamespaceList(ns) );
  1396. }
  1397. }
  1398. STR.popFrame();
  1399. if( routingId == MethodOnComponent )
  1400. STR.setStringValue( componentReturnValue );
  1401. else
  1402. STR.setStringValue( "" );
  1403. break;
  1404. }
  1405. if(nsEntry->mType == Namespace::Entry::ConsoleFunctionType)
  1406. {
  1407. const char *ret = "";
  1408. if(nsEntry->mFunctionOffset)
  1409. ret = nsEntry->mCode->exec(nsEntry->mFunctionOffset, fnName, nsEntry->mNamespace, callArgc, callArgv, false, nsEntry->mPackage);
  1410. STR.popFrame();
  1411. STR.setStringValue(ret);
  1412. }
  1413. else
  1414. {
  1415. const char* nsName = ns? ns->mName: "";
  1416. #ifndef TORQUE_DEBUG
  1417. // [tom, 12/13/2006] This stops tools functions from working in the console,
  1418. // which is useful behavior when debugging so I'm ifdefing this out for debug builds.
  1419. if(nsEntry->mToolOnly && ! Con::isCurrentScriptToolScript())
  1420. {
  1421. Con::errorf(ConsoleLogEntry::Script, "%s: %s::%s - attempting to call tools only function from outside of tools.", getFileLine(ip-4), nsName, fnName);
  1422. }
  1423. else
  1424. #endif
  1425. if((nsEntry->mMinArgs && S32(callArgc) < nsEntry->mMinArgs) || (nsEntry->mMaxArgs && S32(callArgc) > nsEntry->mMaxArgs))
  1426. {
  1427. Con::warnf(ConsoleLogEntry::Script, "%s: %s::%s - wrong number of arguments (got %i, expected min %i and max %i).",
  1428. getFileLine(ip-4), nsName, fnName,
  1429. callArgc, nsEntry->mMinArgs, nsEntry->mMaxArgs);
  1430. Con::warnf(ConsoleLogEntry::Script, "%s: usage: %s", getFileLine(ip-4), nsEntry->mUsage);
  1431. STR.popFrame();
  1432. }
  1433. else
  1434. {
  1435. switch(nsEntry->mType)
  1436. {
  1437. case Namespace::Entry::StringCallbackType:
  1438. {
  1439. const char *ret = nsEntry->cb.mStringCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1440. STR.popFrame();
  1441. if(ret != STR.getStringValue())
  1442. STR.setStringValue(ret);
  1443. else
  1444. STR.setLen(dStrlen(ret));
  1445. break;
  1446. }
  1447. case Namespace::Entry::IntCallbackType:
  1448. {
  1449. S32 result = nsEntry->cb.mIntCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1450. STR.popFrame();
  1451. if(code[ip] == OP_STR_TO_UINT)
  1452. {
  1453. ip++;
  1454. intStack[++_UINT] = result;
  1455. break;
  1456. }
  1457. else if(code[ip] == OP_STR_TO_FLT)
  1458. {
  1459. ip++;
  1460. floatStack[++_FLT] = result;
  1461. break;
  1462. }
  1463. else if(code[ip] == OP_STR_TO_NONE)
  1464. ip++;
  1465. else
  1466. STR.setIntValue(result);
  1467. break;
  1468. }
  1469. case Namespace::Entry::FloatCallbackType:
  1470. {
  1471. F64 result = nsEntry->cb.mFloatCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1472. STR.popFrame();
  1473. if(code[ip] == OP_STR_TO_UINT)
  1474. {
  1475. ip++;
  1476. intStack[++_UINT] = (S64)result;
  1477. break;
  1478. }
  1479. else if(code[ip] == OP_STR_TO_FLT)
  1480. {
  1481. ip++;
  1482. floatStack[++_FLT] = result;
  1483. break;
  1484. }
  1485. else if(code[ip] == OP_STR_TO_NONE)
  1486. ip++;
  1487. else
  1488. STR.setFloatValue(result);
  1489. break;
  1490. }
  1491. case Namespace::Entry::VoidCallbackType:
  1492. nsEntry->cb.mVoidCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1493. if( code[ ip ] != OP_STR_TO_NONE && Con::getBoolVariable( "$Con::warnVoidAssignment", true ) )
  1494. Con::warnf(ConsoleLogEntry::General, "%s: Call to %s in %s uses result of void function call.", getFileLine(ip-4), fnName, functionName);
  1495. STR.popFrame();
  1496. STR.setStringValue("");
  1497. break;
  1498. case Namespace::Entry::BoolCallbackType:
  1499. {
  1500. bool result = nsEntry->cb.mBoolCallbackFunc(gEvalState.thisObject, callArgc, callArgv);
  1501. STR.popFrame();
  1502. if(code[ip] == OP_STR_TO_UINT)
  1503. {
  1504. ip++;
  1505. intStack[++_UINT] = result;
  1506. break;
  1507. }
  1508. else if(code[ip] == OP_STR_TO_FLT)
  1509. {
  1510. ip++;
  1511. floatStack[++_FLT] = result;
  1512. break;
  1513. }
  1514. else if(code[ip] == OP_STR_TO_NONE)
  1515. ip++;
  1516. else
  1517. STR.setIntValue(result);
  1518. break;
  1519. }
  1520. }
  1521. }
  1522. }
  1523. if(callType == FuncCallExprNode::MethodCall)
  1524. gEvalState.thisObject = saveObject;
  1525. break;
  1526. }
  1527. case OP_ADVANCE_STR:
  1528. STR.advance();
  1529. break;
  1530. case OP_ADVANCE_STR_APPENDCHAR:
  1531. STR.advanceChar(code[ip++]);
  1532. break;
  1533. case OP_ADVANCE_STR_COMMA:
  1534. STR.advanceChar('_');
  1535. break;
  1536. case OP_ADVANCE_STR_NUL:
  1537. STR.advanceChar(0);
  1538. break;
  1539. case OP_REWIND_STR:
  1540. STR.rewind();
  1541. break;
  1542. case OP_TERMINATE_REWIND_STR:
  1543. STR.rewindTerminate();
  1544. break;
  1545. case OP_COMPARE_STR:
  1546. intStack[++_UINT] = STR.compare();
  1547. break;
  1548. case OP_PUSH:
  1549. STR.push();
  1550. break;
  1551. case OP_PUSH_FRAME:
  1552. STR.pushFrame();
  1553. break;
  1554. case OP_ASSERT:
  1555. {
  1556. if( !intStack[_UINT--] )
  1557. {
  1558. const char *message = curStringTable + code[ip];
  1559. U32 breakLine, inst;
  1560. findBreakLine( ip - 1, breakLine, inst );
  1561. if ( PlatformAssert::processAssert( PlatformAssert::Fatal,
  1562. name ? name : "eval",
  1563. breakLine,
  1564. message ) )
  1565. {
  1566. if ( TelDebugger && TelDebugger->isConnected() && breakLine > 0 )
  1567. {
  1568. TelDebugger->breakProcess();
  1569. }
  1570. else
  1571. Platform::debugBreak();
  1572. }
  1573. }
  1574. ip++;
  1575. break;
  1576. }
  1577. case OP_BREAK:
  1578. {
  1579. //append the ip and codeptr before managing the breakpoint!
  1580. AssertFatal( gEvalState.getStackDepth() > 0, "Empty eval stack on break!");
  1581. gEvalState.getCurrentFrame().code = this;
  1582. gEvalState.getCurrentFrame().ip = ip - 1;
  1583. U32 breakLine;
  1584. findBreakLine(ip-1, breakLine, instruction);
  1585. if(!breakLine)
  1586. goto breakContinue;
  1587. TelDebugger->executionStopped(this, breakLine);
  1588. goto breakContinue;
  1589. }
  1590. case OP_ITER_BEGIN_STR:
  1591. {
  1592. iterStack[ _ITER ].mIsStringIter = true;
  1593. /* fallthrough */
  1594. }
  1595. case OP_ITER_BEGIN:
  1596. {
  1597. StringTableEntry varName = U32toSTE( code[ ip ] );
  1598. U32 failIp = code[ ip + 1 ];
  1599. IterStackRecord& iter = iterStack[ _ITER ];
  1600. iter.mVariable = gEvalState.getCurrentFrame().add( varName );
  1601. if( iter.mIsStringIter )
  1602. {
  1603. iter.mData.mStr.mString = STR.getStringValue();
  1604. iter.mData.mStr.mIndex = 0;
  1605. }
  1606. else
  1607. {
  1608. // Look up the object.
  1609. SimSet* set;
  1610. if( !Sim::findObject( STR.getStringValue(), set ) )
  1611. {
  1612. Con::errorf( ConsoleLogEntry::General, "No SimSet object '%s'", STR.getStringValue() );
  1613. Con::errorf( ConsoleLogEntry::General, "Did you mean to use 'foreach$' instead of 'foreach'?" );
  1614. ip = failIp;
  1615. continue;
  1616. }
  1617. // Set up.
  1618. iter.mData.mObj.mSet = set;
  1619. iter.mData.mObj.mIndex = 0;
  1620. }
  1621. _ITER ++;
  1622. iterDepth ++;
  1623. STR.push();
  1624. ip += 2;
  1625. break;
  1626. }
  1627. case OP_ITER:
  1628. {
  1629. U32 breakIp = code[ ip ];
  1630. IterStackRecord& iter = iterStack[ _ITER - 1 ];
  1631. if( iter.mIsStringIter )
  1632. {
  1633. const char* str = iter.mData.mStr.mString;
  1634. U32 startIndex = iter.mData.mStr.mIndex;
  1635. U32 endIndex = startIndex;
  1636. // Break if at end.
  1637. if( !str[ startIndex ] )
  1638. {
  1639. ip = breakIp;
  1640. continue;
  1641. }
  1642. // Find right end of current component.
  1643. if( !dIsspace( str[ endIndex ] ) )
  1644. do ++ endIndex;
  1645. while( str[ endIndex ] && !dIsspace( str[ endIndex ] ) );
  1646. // Extract component.
  1647. if( endIndex != startIndex )
  1648. {
  1649. char savedChar = str[ endIndex ];
  1650. const_cast< char* >( str )[ endIndex ] = '\0'; // We are on the string stack so this is okay.
  1651. iter.mVariable->setStringValue( &str[ startIndex ] );
  1652. const_cast< char* >( str )[ endIndex ] = savedChar;
  1653. }
  1654. else
  1655. iter.mVariable->setStringValue( "" );
  1656. // Skip separator.
  1657. if( str[ endIndex ] != '\0' )
  1658. ++ endIndex;
  1659. iter.mData.mStr.mIndex = endIndex;
  1660. }
  1661. else
  1662. {
  1663. U32 index = iter.mData.mObj.mIndex;
  1664. SimSet* set = iter.mData.mObj.mSet;
  1665. if( index >= set->size() )
  1666. {
  1667. ip = breakIp;
  1668. continue;
  1669. }
  1670. iter.mVariable->setIntValue( set->at( index )->getId() );
  1671. iter.mData.mObj.mIndex = index + 1;
  1672. }
  1673. ++ ip;
  1674. break;
  1675. }
  1676. case OP_ITER_END:
  1677. {
  1678. -- _ITER;
  1679. -- iterDepth;
  1680. STR.rewind();
  1681. iterStack[ _ITER ].mIsStringIter = false;
  1682. break;
  1683. }
  1684. case OP_INVALID:
  1685. default:
  1686. // error!
  1687. goto execFinished;
  1688. }
  1689. }
  1690. execFinished:
  1691. if ( telDebuggerOn && setFrame < 0 )
  1692. TelDebugger->popStackFrame();
  1693. if ( popFrame )
  1694. gEvalState.popFrame();
  1695. if(argv)
  1696. {
  1697. if(gEvalState.traceOn)
  1698. {
  1699. traceBuffer[0] = 0;
  1700. dStrcat(traceBuffer, "Leaving ");
  1701. if(packageName)
  1702. {
  1703. dStrcat(traceBuffer, "[");
  1704. dStrcat(traceBuffer, packageName);
  1705. dStrcat(traceBuffer, "]");
  1706. }
  1707. if(thisNamespace && thisNamespace->mName)
  1708. {
  1709. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  1710. "%s::%s() - return %s", thisNamespace->mName, thisFunctionName, STR.getStringValue());
  1711. }
  1712. else
  1713. {
  1714. dSprintf(traceBuffer + dStrlen(traceBuffer), sizeof(traceBuffer) - dStrlen(traceBuffer),
  1715. "%s() - return %s", thisFunctionName, STR.getStringValue());
  1716. }
  1717. Con::printf("%s", traceBuffer);
  1718. }
  1719. }
  1720. else
  1721. {
  1722. delete[] globalStrings;
  1723. globalStringsMaxLen = 0;
  1724. delete[] globalFloats;
  1725. globalStrings = NULL;
  1726. globalFloats = NULL;
  1727. }
  1728. smCurrentCodeBlock = saveCodeBlock;
  1729. if(saveCodeBlock && saveCodeBlock->name)
  1730. {
  1731. Con::gCurrentFile = saveCodeBlock->name;
  1732. Con::gCurrentRoot = saveCodeBlock->modPath;
  1733. }
  1734. decRefCount();
  1735. #ifdef TORQUE_DEBUG
  1736. AssertFatal(!(STR.mStartStackSize > stackStart), "String stack not popped enough in script exec");
  1737. AssertFatal(!(STR.mStartStackSize < stackStart), "String stack popped too much in script exec");
  1738. #endif
  1739. return STR.getStringValue();
  1740. }
  1741. //------------------------------------------------------------