compiledEval.cpp 67 KB

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