codeBlock.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512
  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 "console/console.h"
  23. #include "console/compiler.h"
  24. #include "console/codeBlock.h"
  25. #include "console/telnetDebugger.h"
  26. #include "console/ast.h"
  27. #include "core/strings/unicode.h"
  28. #include "core/strings/stringFunctions.h"
  29. #include "core/stringTable.h"
  30. #include "core/stream/fileStream.h"
  31. using namespace Compiler;
  32. bool CodeBlock::smInFunction = false;
  33. CodeBlock * CodeBlock::smCodeBlockList = NULL;
  34. CodeBlock * CodeBlock::smCurrentCodeBlock = NULL;
  35. ConsoleParser *CodeBlock::smCurrentParser = NULL;
  36. //-------------------------------------------------------------------------
  37. CodeBlock::CodeBlock()
  38. {
  39. globalStrings = NULL;
  40. functionStrings = NULL;
  41. functionStringsMaxLen = 0;
  42. globalStringsMaxLen = 0;
  43. globalFloats = NULL;
  44. functionFloats = NULL;
  45. lineBreakPairs = NULL;
  46. breakList = NULL;
  47. breakListSize = 0;
  48. refCount = 0;
  49. code = NULL;
  50. name = NULL;
  51. fullPath = NULL;
  52. modPath = NULL;
  53. }
  54. CodeBlock::~CodeBlock()
  55. {
  56. // Make sure we aren't lingering in the current code block...
  57. AssertFatal(smCurrentCodeBlock != this, "CodeBlock::~CodeBlock - Caught lingering in smCurrentCodeBlock!");
  58. if (name)
  59. removeFromCodeList();
  60. delete[] const_cast<char*>(globalStrings);
  61. delete[] const_cast<char*>(functionStrings);
  62. functionStringsMaxLen = 0;
  63. globalStringsMaxLen = 0;
  64. delete[] globalFloats;
  65. delete[] functionFloats;
  66. delete[] code;
  67. delete[] breakList;
  68. }
  69. //-------------------------------------------------------------------------
  70. StringTableEntry CodeBlock::getCurrentCodeBlockName()
  71. {
  72. if (CodeBlock::getCurrentBlock())
  73. return CodeBlock::getCurrentBlock()->name;
  74. else
  75. return NULL;
  76. }
  77. StringTableEntry CodeBlock::getCurrentCodeBlockFullPath()
  78. {
  79. if (CodeBlock::getCurrentBlock())
  80. return CodeBlock::getCurrentBlock()->fullPath;
  81. else
  82. return NULL;
  83. }
  84. StringTableEntry CodeBlock::getCurrentCodeBlockModName()
  85. {
  86. if (CodeBlock::getCurrentBlock())
  87. return CodeBlock::getCurrentBlock()->modPath;
  88. else
  89. return NULL;
  90. }
  91. CodeBlock *CodeBlock::find(StringTableEntry name)
  92. {
  93. for (CodeBlock *walk = CodeBlock::getCodeBlockList(); walk; walk = walk->nextFile)
  94. if (walk->name == name)
  95. return walk;
  96. return NULL;
  97. }
  98. //-------------------------------------------------------------------------
  99. void CodeBlock::addToCodeList()
  100. {
  101. // remove any code blocks with my name
  102. for (CodeBlock **walk = &smCodeBlockList; *walk; walk = &((*walk)->nextFile))
  103. {
  104. if ((*walk)->name == name)
  105. {
  106. *walk = (*walk)->nextFile;
  107. break;
  108. }
  109. }
  110. nextFile = smCodeBlockList;
  111. smCodeBlockList = this;
  112. }
  113. void CodeBlock::clearAllBreaks()
  114. {
  115. if (!lineBreakPairs)
  116. return;
  117. for (U32 i = 0; i < lineBreakPairCount; i++)
  118. {
  119. U32 *p = lineBreakPairs + i * 2;
  120. code[p[1]] = p[0] & 0xFF;
  121. }
  122. }
  123. void CodeBlock::clearBreakpoint(U32 lineNumber)
  124. {
  125. if (!lineBreakPairs)
  126. return;
  127. for (U32 i = 0; i < lineBreakPairCount; i++)
  128. {
  129. U32 *p = lineBreakPairs + i * 2;
  130. if ((p[0] >> 8) == lineNumber)
  131. {
  132. code[p[1]] = p[0] & 0xFF;
  133. return;
  134. }
  135. }
  136. }
  137. void CodeBlock::setAllBreaks()
  138. {
  139. if (!lineBreakPairs)
  140. return;
  141. for (U32 i = 0; i < lineBreakPairCount; i++)
  142. {
  143. U32 *p = lineBreakPairs + i * 2;
  144. code[p[1]] = OP_BREAK;
  145. }
  146. }
  147. bool CodeBlock::setBreakpoint(U32 lineNumber)
  148. {
  149. if (!lineBreakPairs)
  150. return false;
  151. for (U32 i = 0; i < lineBreakPairCount; i++)
  152. {
  153. U32 *p = lineBreakPairs + i * 2;
  154. if ((p[0] >> 8) == lineNumber)
  155. {
  156. code[p[1]] = OP_BREAK;
  157. return true;
  158. }
  159. }
  160. return false;
  161. }
  162. U32 CodeBlock::findFirstBreakLine(U32 lineNumber)
  163. {
  164. if (!lineBreakPairs)
  165. return 0;
  166. for (U32 i = 0; i < lineBreakPairCount; i++)
  167. {
  168. U32 *p = lineBreakPairs + i * 2;
  169. U32 line = (p[0] >> 8);
  170. if (lineNumber <= line)
  171. return line;
  172. }
  173. return 0;
  174. }
  175. struct LinePair
  176. {
  177. U32 instLine;
  178. U32 ip;
  179. };
  180. void CodeBlock::findBreakLine(U32 ip, U32 &line, U32 &instruction)
  181. {
  182. U32 min = 0;
  183. U32 max = lineBreakPairCount - 1;
  184. LinePair *p = (LinePair *)lineBreakPairs;
  185. U32 found;
  186. if (!lineBreakPairCount || p[min].ip > ip || p[max].ip < ip)
  187. {
  188. line = 0;
  189. instruction = OP_INVALID;
  190. return;
  191. }
  192. else if (p[min].ip == ip)
  193. found = min;
  194. else if (p[max].ip == ip)
  195. found = max;
  196. else
  197. {
  198. for (;;)
  199. {
  200. if (min == max - 1)
  201. {
  202. found = min;
  203. break;
  204. }
  205. U32 mid = (min + max) >> 1;
  206. if (p[mid].ip == ip)
  207. {
  208. found = mid;
  209. break;
  210. }
  211. else if (p[mid].ip > ip)
  212. max = mid;
  213. else
  214. min = mid;
  215. }
  216. }
  217. instruction = p[found].instLine & 0xFF;
  218. line = p[found].instLine >> 8;
  219. }
  220. const char *CodeBlock::getFileLine(U32 ip)
  221. {
  222. static char nameBuffer[256];
  223. U32 line, inst;
  224. findBreakLine(ip, line, inst);
  225. dSprintf(nameBuffer, sizeof(nameBuffer), "%s (%d)", name ? name : "<input>", line);
  226. return nameBuffer;
  227. }
  228. void CodeBlock::removeFromCodeList()
  229. {
  230. for (CodeBlock **walk = &smCodeBlockList; *walk; walk = &((*walk)->nextFile))
  231. {
  232. if (*walk == this)
  233. {
  234. *walk = nextFile;
  235. // clear out all breakpoints
  236. clearAllBreaks();
  237. break;
  238. }
  239. }
  240. // Let the telnet debugger know that this code
  241. // block has been unloaded and that it needs to
  242. // remove references to it.
  243. if (TelDebugger)
  244. TelDebugger->clearCodeBlockPointers(this);
  245. }
  246. void CodeBlock::calcBreakList()
  247. {
  248. U32 size = 0;
  249. S32 line = -1;
  250. U32 seqCount = 0;
  251. U32 i;
  252. for (i = 0; i < lineBreakPairCount; i++)
  253. {
  254. U32 lineNumber = lineBreakPairs[i * 2];
  255. if (lineNumber == U32(line + 1))
  256. seqCount++;
  257. else
  258. {
  259. if (seqCount)
  260. size++;
  261. size++;
  262. seqCount = 1;
  263. }
  264. line = lineNumber;
  265. }
  266. if (seqCount)
  267. size++;
  268. breakList = new U32[size];
  269. breakListSize = size;
  270. line = -1;
  271. seqCount = 0;
  272. size = 0;
  273. for (i = 0; i < lineBreakPairCount; i++)
  274. {
  275. U32 lineNumber = lineBreakPairs[i * 2];
  276. if (lineNumber == U32(line + 1))
  277. seqCount++;
  278. else
  279. {
  280. if (seqCount)
  281. breakList[size++] = seqCount;
  282. breakList[size++] = lineNumber - getMax(0, line) - 1;
  283. seqCount = 1;
  284. }
  285. line = lineNumber;
  286. }
  287. if (seqCount)
  288. breakList[size++] = seqCount;
  289. for (i = 0; i < lineBreakPairCount; i++)
  290. {
  291. U32 *p = lineBreakPairs + i * 2;
  292. p[0] = (p[0] << 8) | code[p[1]];
  293. }
  294. // Let the telnet debugger know that this code
  295. // block has been loaded and that it can add break
  296. // points it has for it.
  297. if (TelDebugger)
  298. TelDebugger->addAllBreakpoints(this);
  299. }
  300. bool CodeBlock::read(StringTableEntry fileName, Stream &st)
  301. {
  302. const StringTableEntry exePath = Platform::getMainDotCsDir();
  303. const StringTableEntry cwd = Platform::getCurrentDirectory();
  304. name = fileName;
  305. if (fileName)
  306. {
  307. fullPath = NULL;
  308. if (Platform::isFullPath(fileName))
  309. fullPath = fileName;
  310. if (dStrnicmp(exePath, fileName, dStrlen(exePath)) == 0)
  311. name = StringTable->insert(fileName + dStrlen(exePath) + 1, true);
  312. else if (dStrnicmp(cwd, fileName, dStrlen(cwd)) == 0)
  313. name = StringTable->insert(fileName + dStrlen(cwd) + 1, true);
  314. if (fullPath == NULL)
  315. {
  316. char buf[1024];
  317. fullPath = StringTable->insert(Platform::makeFullPathName(fileName, buf, sizeof(buf)), true);
  318. }
  319. modPath = Con::getModNameFromPath(fileName);
  320. }
  321. //
  322. addToCodeList();
  323. U32 globalSize, size, i;
  324. st.read(&size);
  325. if (size)
  326. {
  327. globalStrings = new char[size];
  328. globalStringsMaxLen = size;
  329. st.read(size, globalStrings);
  330. }
  331. globalSize = size;
  332. st.read(&size);
  333. if (size)
  334. {
  335. functionStrings = new char[size];
  336. functionStringsMaxLen = size;
  337. st.read(size, functionStrings);
  338. }
  339. st.read(&size);
  340. if (size)
  341. {
  342. globalFloats = new F64[size];
  343. for (i = 0; i < size; i++)
  344. st.read(&globalFloats[i]);
  345. }
  346. st.read(&size);
  347. if (size)
  348. {
  349. functionFloats = new F64[size];
  350. for (i = 0; i < size; i++)
  351. st.read(&functionFloats[i]);
  352. }
  353. U32 codeLength;
  354. st.read(&codeLength);
  355. st.read(&lineBreakPairCount);
  356. U32 totSize = codeLength + lineBreakPairCount * 2;
  357. code = new U32[totSize];
  358. // 0xFF is used as a flag to help compress the bytecode.
  359. // If detected, the bytecode is only a U8.
  360. for (i = 0; i < codeLength; i++)
  361. {
  362. U8 b;
  363. st.read(&b);
  364. if (b == 0xFF)
  365. st.read(&code[i]);
  366. else
  367. code[i] = b;
  368. }
  369. for (i = codeLength; i < totSize; i++)
  370. st.read(&code[i]);
  371. lineBreakPairs = code + codeLength;
  372. // StringTable-ize our identifiers.
  373. U32 identCount;
  374. st.read(&identCount);
  375. while (identCount--)
  376. {
  377. U32 offset;
  378. st.read(&offset);
  379. StringTableEntry ste;
  380. if (offset < globalSize)
  381. ste = StringTable->insert(globalStrings + offset);
  382. else
  383. ste = StringTable->EmptyString();
  384. U32 count;
  385. st.read(&count);
  386. while (count--)
  387. {
  388. U32 ip;
  389. st.read(&ip);
  390. #ifdef TORQUE_CPU_X64
  391. *(U64*)(code + ip) = (U64)ste;
  392. #else
  393. code[ip] = *((U32 *)&ste);
  394. #endif
  395. }
  396. }
  397. if (lineBreakPairCount)
  398. calcBreakList();
  399. return true;
  400. }
  401. bool CodeBlock::compile(const char *codeFileName, StringTableEntry fileName, const char *inScript, bool overrideNoDso)
  402. {
  403. AssertFatal(Con::isMainThread(), "Compiling code on a secondary thread");
  404. // This will return true, but return value is ignored
  405. char *script;
  406. chompUTF8BOM(inScript, &script);
  407. gSyntaxError = false;
  408. consoleAllocReset();
  409. STEtoCode = compileSTEtoCode;
  410. gStatementList = NULL;
  411. gAnonFunctionList = NULL;
  412. // Set up the parser.
  413. smCurrentParser = getParserForFile(fileName);
  414. AssertISV(smCurrentParser, avar("CodeBlock::compile - no parser available for '%s'!", fileName));
  415. // Now do some parsing.
  416. smCurrentParser->setScanBuffer(script, fileName);
  417. smCurrentParser->restart(NULL);
  418. smCurrentParser->parse();
  419. if (gStatementList)
  420. {
  421. if (gAnonFunctionList)
  422. {
  423. // Prepend anonymous functions to statement list, so they're defined already when
  424. // the statements run.
  425. gAnonFunctionList->append(gStatementList);
  426. gStatementList = gAnonFunctionList;
  427. }
  428. }
  429. if (gSyntaxError)
  430. {
  431. consoleAllocReset();
  432. return false;
  433. }
  434. #ifdef TORQUE_NO_DSO_GENERATION
  435. if (!overrideNoDso)
  436. return false;
  437. #endif // !TORQUE_NO_DSO_GENERATION
  438. FileStream st;
  439. if (!st.open(codeFileName, Torque::FS::File::Write))
  440. return false;
  441. st.write(U32(Con::DSOVersion));
  442. // Reset all our value tables...
  443. resetTables();
  444. smInFunction = false;
  445. CodeStream codeStream;
  446. U32 lastIp;
  447. if (gStatementList)
  448. {
  449. lastIp = compileBlock(gStatementList, codeStream, 0) + 1;
  450. }
  451. else
  452. {
  453. codeSize = 1;
  454. lastIp = 0;
  455. }
  456. codeStream.emit(OP_RETURN);
  457. codeStream.emitCodeStream(&codeSize, &code, &lineBreakPairs);
  458. lineBreakPairCount = codeStream.getNumLineBreaks();
  459. // Write string table data...
  460. getGlobalStringTable().write(st);
  461. getFunctionStringTable().write(st);
  462. // Write float table data...
  463. getGlobalFloatTable().write(st);
  464. getFunctionFloatTable().write(st);
  465. if (lastIp != codeSize)
  466. Con::errorf(ConsoleLogEntry::General, "CodeBlock::compile - precompile size mismatch, a precompile/compile function pair is probably mismatched.");
  467. U32 totSize = codeSize + codeStream.getNumLineBreaks() * 2;
  468. st.write(codeSize);
  469. st.write(lineBreakPairCount);
  470. // Write out our bytecode, doing a bit of compression for low numbers.
  471. U32 i;
  472. for (i = 0; i < codeSize; i++)
  473. {
  474. if (code[i] < 0xFF)
  475. st.write(U8(code[i]));
  476. else
  477. {
  478. st.write(U8(0xFF));
  479. st.write(code[i]);
  480. }
  481. }
  482. // Write the break info...
  483. for (i = codeSize; i < totSize; i++)
  484. st.write(code[i]);
  485. getIdentTable().write(st);
  486. consoleAllocReset();
  487. st.close();
  488. return true;
  489. }
  490. ConsoleValueRef CodeBlock::compileExec(StringTableEntry fileName, const char *inString, bool noCalls, S32 setFrame)
  491. {
  492. AssertFatal(Con::isMainThread(), "Compiling code on a secondary thread");
  493. // Check for a UTF8 script file
  494. char *string;
  495. chompUTF8BOM(inString, &string);
  496. STEtoCode = evalSTEtoCode;
  497. consoleAllocReset();
  498. name = fileName;
  499. if (fileName)
  500. {
  501. const StringTableEntry exePath = Platform::getMainDotCsDir();
  502. const StringTableEntry cwd = Platform::getCurrentDirectory();
  503. fullPath = NULL;
  504. if (Platform::isFullPath(fileName))
  505. fullPath = fileName;
  506. if (dStrnicmp(exePath, fileName, dStrlen(exePath)) == 0)
  507. name = StringTable->insert(fileName + dStrlen(exePath) + 1, true);
  508. else if (dStrnicmp(cwd, fileName, dStrlen(cwd)) == 0)
  509. name = StringTable->insert(fileName + dStrlen(cwd) + 1, true);
  510. if (fullPath == NULL)
  511. {
  512. char buf[1024];
  513. fullPath = StringTable->insert(Platform::makeFullPathName(fileName, buf, sizeof(buf)), true);
  514. }
  515. modPath = Con::getModNameFromPath(fileName);
  516. }
  517. if (name)
  518. addToCodeList();
  519. gStatementList = NULL;
  520. gAnonFunctionList = NULL;
  521. // Set up the parser.
  522. smCurrentParser = getParserForFile(fileName);
  523. AssertISV(smCurrentParser, avar("CodeBlock::compile - no parser available for '%s'!", fileName));
  524. // Now do some parsing.
  525. smCurrentParser->setScanBuffer(string, fileName);
  526. smCurrentParser->restart(NULL);
  527. smCurrentParser->parse();
  528. if (gStatementList)
  529. {
  530. if (gAnonFunctionList)
  531. {
  532. // Prepend anonymous functions to statement list, so they're defined already when
  533. // the statements run.
  534. gAnonFunctionList->append(gStatementList);
  535. gStatementList = gAnonFunctionList;
  536. }
  537. }
  538. if (!gStatementList)
  539. {
  540. delete this;
  541. return ConsoleValueRef();
  542. }
  543. resetTables();
  544. smInFunction = false;
  545. CodeStream codeStream;
  546. U32 lastIp = compileBlock(gStatementList, codeStream, 0);
  547. lineBreakPairCount = codeStream.getNumLineBreaks();
  548. globalStrings = getGlobalStringTable().build();
  549. globalStringsMaxLen = getGlobalStringTable().totalLen;
  550. functionStrings = getFunctionStringTable().build();
  551. functionStringsMaxLen = getFunctionStringTable().totalLen;
  552. globalFloats = getGlobalFloatTable().build();
  553. functionFloats = getFunctionFloatTable().build();
  554. codeStream.emit(OP_RETURN);
  555. codeStream.emitCodeStream(&codeSize, &code, &lineBreakPairs);
  556. //dumpInstructions(0, false);
  557. consoleAllocReset();
  558. if (lineBreakPairCount && fileName)
  559. calcBreakList();
  560. if (lastIp + 1 != codeSize)
  561. Con::warnf(ConsoleLogEntry::General, "precompile size mismatch, precompile: %d compile: %d", codeSize, lastIp);
  562. return exec(0, fileName, NULL, 0, 0, noCalls, NULL, setFrame);
  563. }
  564. //-------------------------------------------------------------------------
  565. void CodeBlock::incRefCount()
  566. {
  567. refCount++;
  568. }
  569. void CodeBlock::decRefCount()
  570. {
  571. refCount--;
  572. if (!refCount)
  573. delete this;
  574. }
  575. //-------------------------------------------------------------------------
  576. String CodeBlock::getFunctionArgs(U32 ip)
  577. {
  578. StringBuilder str;
  579. U32 fnArgc = code[ip + 5];
  580. for (U32 i = 0; i < fnArgc; ++i)
  581. {
  582. StringTableEntry var = CodeToSTE(code, ip + (i * 2) + 6);
  583. if (i != 0)
  584. str.append(", ");
  585. str.append("string ");
  586. // Try to capture junked parameters
  587. if (var[0])
  588. str.append(var + 1);
  589. else
  590. str.append("JUNK");
  591. }
  592. return str.end();
  593. }
  594. //-------------------------------------------------------------------------
  595. void CodeBlock::dumpInstructions(U32 startIp, bool upToReturn)
  596. {
  597. U32 ip = startIp;
  598. smInFunction = false;
  599. U32 endFuncIp = 0;
  600. while (ip < codeSize)
  601. {
  602. if (ip > endFuncIp)
  603. {
  604. smInFunction = false;
  605. }
  606. switch (code[ip++])
  607. {
  608. case OP_FUNC_DECL:
  609. {
  610. StringTableEntry fnName = CodeToSTE(code, ip);
  611. StringTableEntry fnNamespace = CodeToSTE(code, ip + 2);
  612. StringTableEntry fnPackage = CodeToSTE(code, ip + 4);
  613. bool hasBody = bool(code[ip + 6]);
  614. U32 newIp = code[ip + 7];
  615. U32 argc = code[ip + 8];
  616. endFuncIp = newIp;
  617. Con::printf("%i: OP_FUNC_DECL name=%s nspace=%s package=%s hasbody=%i newip=%i argc=%i",
  618. ip - 1, fnName, fnNamespace, fnPackage, hasBody, newIp, argc);
  619. // Skip args.
  620. ip += 9 + (argc * 2);
  621. smInFunction = true;
  622. break;
  623. }
  624. case OP_CREATE_OBJECT:
  625. {
  626. StringTableEntry objParent = CodeToSTE(code, ip);
  627. bool isDataBlock = code[ip + 2];
  628. bool isInternal = code[ip + 3];
  629. bool isSingleton = code[ip + 4];
  630. U32 lineNumber = code[ip + 5];
  631. U32 failJump = code[ip + 6];
  632. Con::printf("%i: OP_CREATE_OBJECT objParent=%s isDataBlock=%i isInternal=%i isSingleton=%i lineNumber=%i failJump=%i",
  633. ip - 1, objParent, isDataBlock, isInternal, isSingleton, lineNumber, failJump);
  634. ip += 7;
  635. break;
  636. }
  637. case OP_ADD_OBJECT:
  638. {
  639. bool placeAtRoot = code[ip++];
  640. Con::printf("%i: OP_ADD_OBJECT placeAtRoot=%i", ip - 1, placeAtRoot);
  641. break;
  642. }
  643. case OP_END_OBJECT:
  644. {
  645. bool placeAtRoot = code[ip++];
  646. Con::printf("%i: OP_END_OBJECT placeAtRoot=%i", ip - 1, placeAtRoot);
  647. break;
  648. }
  649. case OP_FINISH_OBJECT:
  650. {
  651. Con::printf("%i: OP_FINISH_OBJECT", ip - 1);
  652. break;
  653. }
  654. case OP_JMPIFFNOT:
  655. {
  656. Con::printf("%i: OP_JMPIFFNOT ip=%i", ip - 1, code[ip]);
  657. ++ip;
  658. break;
  659. }
  660. case OP_JMPIFNOT:
  661. {
  662. Con::printf("%i: OP_JMPIFNOT ip=%i", ip - 1, code[ip]);
  663. ++ip;
  664. break;
  665. }
  666. case OP_JMPIFF:
  667. {
  668. Con::printf("%i: OP_JMPIFF ip=%i", ip - 1, code[ip]);
  669. ++ip;
  670. break;
  671. }
  672. case OP_JMPIF:
  673. {
  674. Con::printf("%i: OP_JMPIF ip=%i", ip - 1, code[ip]);
  675. ++ip;
  676. break;
  677. }
  678. case OP_JMPIFNOT_NP:
  679. {
  680. Con::printf("%i: OP_JMPIFNOT_NP ip=%i", ip - 1, code[ip]);
  681. ++ip;
  682. break;
  683. }
  684. case OP_JMPIF_NP:
  685. {
  686. Con::printf("%i: OP_JMPIF_NP ip=%i", ip - 1, code[ip]);
  687. ++ip;
  688. break;
  689. }
  690. case OP_JMP:
  691. {
  692. Con::printf("%i: OP_JMP ip=%i", ip - 1, code[ip]);
  693. ++ip;
  694. break;
  695. }
  696. case OP_RETURN:
  697. {
  698. Con::printf("%i: OP_RETURN", ip - 1);
  699. if (upToReturn)
  700. return;
  701. break;
  702. }
  703. case OP_RETURN_VOID:
  704. {
  705. Con::printf("%i: OP_RETURNVOID", ip - 1);
  706. if (upToReturn)
  707. return;
  708. break;
  709. }
  710. case OP_RETURN_UINT:
  711. {
  712. Con::printf("%i: OP_RETURNUINT", ip - 1);
  713. if (upToReturn)
  714. return;
  715. break;
  716. }
  717. case OP_RETURN_FLT:
  718. {
  719. Con::printf("%i: OP_RETURNFLT", ip - 1);
  720. if (upToReturn)
  721. return;
  722. break;
  723. }
  724. case OP_CMPEQ:
  725. {
  726. Con::printf("%i: OP_CMPEQ", ip - 1);
  727. break;
  728. }
  729. case OP_CMPGR:
  730. {
  731. Con::printf("%i: OP_CMPGR", ip - 1);
  732. break;
  733. }
  734. case OP_CMPGE:
  735. {
  736. Con::printf("%i: OP_CMPGE", ip - 1);
  737. break;
  738. }
  739. case OP_CMPLT:
  740. {
  741. Con::printf("%i: OP_CMPLT", ip - 1);
  742. break;
  743. }
  744. case OP_CMPLE:
  745. {
  746. Con::printf("%i: OP_CMPLE", ip - 1);
  747. break;
  748. }
  749. case OP_CMPNE:
  750. {
  751. Con::printf("%i: OP_CMPNE", ip - 1);
  752. break;
  753. }
  754. case OP_XOR:
  755. {
  756. Con::printf("%i: OP_XOR", ip - 1);
  757. break;
  758. }
  759. case OP_MOD:
  760. {
  761. Con::printf("%i: OP_MOD", ip - 1);
  762. break;
  763. }
  764. case OP_BITAND:
  765. {
  766. Con::printf("%i: OP_BITAND", ip - 1);
  767. break;
  768. }
  769. case OP_BITOR:
  770. {
  771. Con::printf("%i: OP_BITOR", ip - 1);
  772. break;
  773. }
  774. case OP_NOT:
  775. {
  776. Con::printf("%i: OP_NOT", ip - 1);
  777. break;
  778. }
  779. case OP_NOTF:
  780. {
  781. Con::printf("%i: OP_NOTF", ip - 1);
  782. break;
  783. }
  784. case OP_ONESCOMPLEMENT:
  785. {
  786. Con::printf("%i: OP_ONESCOMPLEMENT", ip - 1);
  787. break;
  788. }
  789. case OP_SHR:
  790. {
  791. Con::printf("%i: OP_SHR", ip - 1);
  792. break;
  793. }
  794. case OP_SHL:
  795. {
  796. Con::printf("%i: OP_SHL", ip - 1);
  797. break;
  798. }
  799. case OP_AND:
  800. {
  801. Con::printf("%i: OP_AND", ip - 1);
  802. break;
  803. }
  804. case OP_OR:
  805. {
  806. Con::printf("%i: OP_OR", ip - 1);
  807. break;
  808. }
  809. case OP_ADD:
  810. {
  811. Con::printf("%i: OP_ADD", ip - 1);
  812. break;
  813. }
  814. case OP_SUB:
  815. {
  816. Con::printf("%i: OP_SUB", ip - 1);
  817. break;
  818. }
  819. case OP_MUL:
  820. {
  821. Con::printf("%i: OP_MUL", ip - 1);
  822. break;
  823. }
  824. case OP_DIV:
  825. {
  826. Con::printf("%i: OP_DIV", ip - 1);
  827. break;
  828. }
  829. case OP_NEG:
  830. {
  831. Con::printf("%i: OP_NEG", ip - 1);
  832. break;
  833. }
  834. case OP_INC:
  835. {
  836. Con::printf("%i: OP_INC varName=%s", ip - 1, CodeToSTE(code, ip));
  837. ip += 2;
  838. break;
  839. }
  840. case OP_DEC:
  841. {
  842. Con::printf("%i: OP_DEC varName=%s", ip - 1, CodeToSTE(code, ip));
  843. ip += 2;
  844. break;
  845. }
  846. case OP_SETCURVAR:
  847. {
  848. StringTableEntry var = CodeToSTE(code, ip);
  849. Con::printf("%i: OP_SETCURVAR var=%s", ip - 1, var);
  850. ip += 2;
  851. break;
  852. }
  853. case OP_SETCURVAR_CREATE:
  854. {
  855. StringTableEntry var = CodeToSTE(code, ip);
  856. Con::printf("%i: OP_SETCURVAR_CREATE var=%s", ip - 1, var);
  857. ip += 2;
  858. break;
  859. }
  860. case OP_SETCURVAR_ARRAY:
  861. {
  862. Con::printf("%i: OP_SETCURVAR_ARRAY", ip - 1);
  863. break;
  864. }
  865. case OP_SETCURVAR_ARRAY_VARLOOKUP:
  866. {
  867. StringTableEntry arrayName = CodeToSTE(code, ip);
  868. StringTableEntry arrayLookup = CodeToSTE(code, ip + 2);
  869. Con::printf("%i: OP_SETCURVAR_ARRAY_VARLOOKUP arrayName=%s arrayLookup=%s", ip - 1, arrayName, arrayLookup);
  870. ip += 4;
  871. break;
  872. }
  873. case OP_SETCURVAR_ARRAY_CREATE:
  874. {
  875. Con::printf("%i: OP_SETCURVAR_ARRAY_CREATE", ip - 1);
  876. break;
  877. }
  878. case OP_SETCURVAR_ARRAY_CREATE_VARLOOKUP:
  879. {
  880. StringTableEntry arrayName = CodeToSTE(code, ip);
  881. StringTableEntry arrayLookup = CodeToSTE(code, ip + 2);
  882. Con::printf("%i: OP_SETCURVAR_ARRAY_CREATE_VARLOOKUP arrayName=%s arrayLookup=%s", ip - 1, arrayName, arrayLookup);
  883. ip += 4;
  884. break;
  885. }
  886. case OP_LOADVAR_UINT:
  887. {
  888. Con::printf("%i: OP_LOADVAR_UINT", ip - 1);
  889. break;
  890. }
  891. case OP_LOADVAR_FLT:
  892. {
  893. Con::printf("%i: OP_LOADVAR_FLT", ip - 1);
  894. break;
  895. }
  896. case OP_LOADVAR_STR:
  897. {
  898. Con::printf("%i: OP_LOADVAR_STR", ip - 1);
  899. break;
  900. }
  901. case OP_LOADVAR_VAR:
  902. {
  903. Con::printf("%i: OP_LOADVAR_VAR", ip - 1);
  904. break;
  905. }
  906. case OP_SAVEVAR_UINT:
  907. {
  908. Con::printf("%i: OP_SAVEVAR_UINT", ip - 1);
  909. break;
  910. }
  911. case OP_SAVEVAR_FLT:
  912. {
  913. Con::printf("%i: OP_SAVEVAR_FLT", ip - 1);
  914. break;
  915. }
  916. case OP_SAVEVAR_STR:
  917. {
  918. Con::printf("%i: OP_SAVEVAR_STR", ip - 1);
  919. break;
  920. }
  921. case OP_SAVEVAR_VAR:
  922. {
  923. Con::printf("%i: OP_SAVEVAR_VAR", ip - 1);
  924. break;
  925. }
  926. case OP_SETCUROBJECT:
  927. {
  928. Con::printf("%i: OP_SETCUROBJECT", ip - 1);
  929. break;
  930. }
  931. case OP_SETCUROBJECT_NEW:
  932. {
  933. Con::printf("%i: OP_SETCUROBJECT_NEW", ip - 1);
  934. break;
  935. }
  936. case OP_SETCUROBJECT_INTERNAL:
  937. {
  938. Con::printf("%i: OP_SETCUROBJECT_INTERNAL", ip - 1);
  939. ++ip;
  940. break;
  941. }
  942. case OP_SETCURFIELD:
  943. {
  944. StringTableEntry curField = CodeToSTE(code, ip);
  945. Con::printf("%i: OP_SETCURFIELD field=%s", ip - 1, curField);
  946. ip += 2;
  947. break;
  948. }
  949. case OP_SETCURFIELD_ARRAY:
  950. {
  951. Con::printf("%i: OP_SETCURFIELD_ARRAY", ip - 1);
  952. break;
  953. }
  954. case OP_SETCURFIELD_ARRAY_VAR:
  955. {
  956. StringTableEntry var = CodeToSTE(code, ip);
  957. Con::printf("%i: OP_SETCURFIELD_ARRAY_VAR var=%s", ip - 1, var);
  958. ip += 2;
  959. break;
  960. }
  961. case OP_SETCURFIELD_THIS:
  962. {
  963. StringTableEntry curField = CodeToSTE(code, ip);
  964. Con::printf("%i: OP_SETCURFIELD_THIS field=%s", ip - 1, curField);
  965. ip += 2;
  966. break;
  967. }
  968. case OP_SETCURFIELD_TYPE:
  969. {
  970. U32 type = code[ip];
  971. Con::printf("%i: OP_SETCURFIELD_TYPE type=%i", ip - 1, type);
  972. ++ip;
  973. break;
  974. }
  975. case OP_LOADFIELD_UINT:
  976. {
  977. Con::printf("%i: OP_LOADFIELD_UINT", ip - 1);
  978. break;
  979. }
  980. case OP_LOADFIELD_FLT:
  981. {
  982. Con::printf("%i: OP_LOADFIELD_FLT", ip - 1);
  983. break;
  984. }
  985. case OP_LOADFIELD_STR:
  986. {
  987. Con::printf("%i: OP_LOADFIELD_STR", ip - 1);
  988. break;
  989. }
  990. case OP_SAVEFIELD_UINT:
  991. {
  992. Con::printf("%i: OP_SAVEFIELD_UINT", ip - 1);
  993. break;
  994. }
  995. case OP_SAVEFIELD_FLT:
  996. {
  997. Con::printf("%i: OP_SAVEFIELD_FLT", ip - 1);
  998. break;
  999. }
  1000. case OP_SAVEFIELD_STR:
  1001. {
  1002. Con::printf("%i: OP_SAVEFIELD_STR", ip - 1);
  1003. break;
  1004. }
  1005. case OP_STR_TO_UINT:
  1006. {
  1007. Con::printf("%i: OP_STR_TO_UINT", ip - 1);
  1008. break;
  1009. }
  1010. case OP_STR_TO_FLT:
  1011. {
  1012. Con::printf("%i: OP_STR_TO_FLT", ip - 1);
  1013. break;
  1014. }
  1015. case OP_STR_TO_NONE:
  1016. {
  1017. Con::printf("%i: OP_STR_TO_NONE", ip - 1);
  1018. break;
  1019. }
  1020. case OP_FLT_TO_UINT:
  1021. {
  1022. Con::printf("%i: OP_FLT_TO_UINT", ip - 1);
  1023. break;
  1024. }
  1025. case OP_FLT_TO_STR:
  1026. {
  1027. Con::printf("%i: OP_FLT_TO_STR", ip - 1);
  1028. break;
  1029. }
  1030. case OP_FLT_TO_NONE:
  1031. {
  1032. Con::printf("%i: OP_FLT_TO_NONE", ip - 1);
  1033. break;
  1034. }
  1035. case OP_UINT_TO_FLT:
  1036. {
  1037. Con::printf("%i: OP_SAVEFIELD_STR", ip - 1);
  1038. break;
  1039. }
  1040. case OP_UINT_TO_STR:
  1041. {
  1042. Con::printf("%i: OP_UINT_TO_STR", ip - 1);
  1043. break;
  1044. }
  1045. case OP_UINT_TO_NONE:
  1046. {
  1047. Con::printf("%i: OP_UINT_TO_NONE", ip - 1);
  1048. break;
  1049. }
  1050. case OP_COPYVAR_TO_NONE:
  1051. {
  1052. Con::printf("%i: OP_COPYVAR_TO_NONE", ip - 1);
  1053. break;
  1054. }
  1055. case OP_LOADIMMED_UINT:
  1056. {
  1057. U32 val = code[ip];
  1058. Con::printf("%i: OP_LOADIMMED_UINT val=%i", ip - 1, val);
  1059. ++ip;
  1060. break;
  1061. }
  1062. case OP_LOADIMMED_FLT:
  1063. {
  1064. F64 val = (smInFunction ? functionFloats : globalFloats)[code[ip]];
  1065. Con::printf("%i: OP_LOADIMMED_FLT val=%f", ip - 1, val);
  1066. ++ip;
  1067. break;
  1068. }
  1069. case OP_TAG_TO_STR:
  1070. {
  1071. const char* str = (smInFunction ? functionStrings : globalStrings) + code[ip];
  1072. Con::printf("%i: OP_TAG_TO_STR str=%s", ip - 1, str);
  1073. ++ip;
  1074. break;
  1075. }
  1076. case OP_LOADIMMED_STR:
  1077. {
  1078. const char* str = (smInFunction ? functionStrings : globalStrings) + code[ip];
  1079. Con::printf("%i: OP_LOADIMMED_STR str=%s", ip - 1, str);
  1080. ++ip;
  1081. break;
  1082. }
  1083. case OP_DOCBLOCK_STR:
  1084. {
  1085. const char* str = (smInFunction ? functionStrings : globalStrings) + code[ip];
  1086. Con::printf("%i: OP_DOCBLOCK_STR str=%s", ip - 1, str);
  1087. ++ip;
  1088. break;
  1089. }
  1090. case OP_LOADIMMED_IDENT:
  1091. {
  1092. StringTableEntry str = CodeToSTE(code, ip);
  1093. Con::printf("%i: OP_LOADIMMED_IDENT str=%s", ip - 1, str);
  1094. ip += 2;
  1095. break;
  1096. }
  1097. case OP_CALLFUNC_RESOLVE:
  1098. {
  1099. StringTableEntry fnNamespace = CodeToSTE(code, ip + 2);
  1100. StringTableEntry fnName = CodeToSTE(code, ip);
  1101. U32 callType = code[ip + 2];
  1102. Con::printf("%i: OP_CALLFUNC_RESOLVE name=%s nspace=%s callType=%s", ip - 1, fnName, fnNamespace,
  1103. callType == FuncCallExprNode::FunctionCall ? "FunctionCall"
  1104. : callType == FuncCallExprNode::MethodCall ? "MethodCall" : "ParentCall");
  1105. ip += 5;
  1106. break;
  1107. }
  1108. case OP_CALLFUNC:
  1109. {
  1110. StringTableEntry fnNamespace = CodeToSTE(code, ip + 2);
  1111. StringTableEntry fnName = CodeToSTE(code, ip);
  1112. U32 callType = code[ip + 4];
  1113. Con::printf("%i: OP_CALLFUNC name=%s nspace=%s callType=%s", ip - 1, fnName, fnNamespace,
  1114. callType == FuncCallExprNode::FunctionCall ? "FunctionCall"
  1115. : callType == FuncCallExprNode::MethodCall ? "MethodCall" : "ParentCall");
  1116. ip += 5;
  1117. break;
  1118. }
  1119. case OP_CALLFUNC_POINTER:
  1120. {
  1121. Con::printf("%i: OP_CALLFUNC_POINTER", ip - 1);
  1122. break;
  1123. }
  1124. case OP_CALLFUNC_THIS:
  1125. {
  1126. StringTableEntry fnName = CodeToSTE(code, ip);
  1127. Con::printf("%i: OP_CALLFUNC_THIS name=%s ", ip - 1, fnName);
  1128. ip += 2;
  1129. break;
  1130. }
  1131. case OP_ADVANCE_STR:
  1132. {
  1133. Con::printf("%i: OP_ADVANCE_STR", ip - 1);
  1134. break;
  1135. }
  1136. case OP_ADVANCE_STR_APPENDCHAR:
  1137. {
  1138. char ch = code[ip];
  1139. Con::printf("%i: OP_ADVANCE_STR_APPENDCHAR char=%c", ip - 1, ch);
  1140. ++ip;
  1141. break;
  1142. }
  1143. case OP_ADVANCE_STR_COMMA:
  1144. {
  1145. Con::printf("%i: OP_ADVANCE_STR_COMMA", ip - 1);
  1146. break;
  1147. }
  1148. case OP_ADVANCE_STR_NUL:
  1149. {
  1150. Con::printf("%i: OP_ADVANCE_STR_NUL", ip - 1);
  1151. break;
  1152. }
  1153. case OP_REWIND_STR:
  1154. {
  1155. Con::printf("%i: OP_REWIND_STR", ip - 1);
  1156. break;
  1157. }
  1158. case OP_TERMINATE_REWIND_STR:
  1159. {
  1160. Con::printf("%i: OP_TERMINATE_REWIND_STR", ip - 1);
  1161. break;
  1162. }
  1163. case OP_COMPARE_STR:
  1164. {
  1165. Con::printf("%i: OP_COMPARE_STR", ip - 1);
  1166. break;
  1167. }
  1168. case OP_PUSH:
  1169. {
  1170. Con::printf("%i: OP_PUSH", ip - 1);
  1171. break;
  1172. }
  1173. case OP_PUSH_UINT:
  1174. {
  1175. Con::printf("%i: OP_PUSH_UINT", ip - 1);
  1176. break;
  1177. }
  1178. case OP_PUSH_FLT:
  1179. {
  1180. Con::printf("%i: OP_PUSH_FLT", ip - 1);
  1181. break;
  1182. }
  1183. case OP_PUSH_VAR:
  1184. {
  1185. Con::printf("%i: OP_PUSH_VAR", ip - 1);
  1186. break;
  1187. }
  1188. case OP_PUSH_THIS:
  1189. {
  1190. Con::printf("%i: OP_PUSH_THIS varName=%s", ip - 1, CodeToSTE(code, ip));
  1191. ip += 2;
  1192. break;
  1193. }
  1194. case OP_PUSH_FRAME:
  1195. {
  1196. Con::printf("%i: OP_PUSH_FRAME", ip - 1);
  1197. break;
  1198. }
  1199. case OP_ASSERT:
  1200. {
  1201. const char* message = (smInFunction ? functionStrings : globalStrings) + code[ip];
  1202. Con::printf("%i: OP_ASSERT message=%s", ip - 1, message);
  1203. ++ip;
  1204. break;
  1205. }
  1206. case OP_BREAK:
  1207. {
  1208. Con::printf("%i: OP_BREAK", ip - 1);
  1209. break;
  1210. }
  1211. case OP_ITER_BEGIN:
  1212. {
  1213. StringTableEntry varName = CodeToSTE(code, ip);
  1214. U32 failIp = code[ip + 2];
  1215. Con::printf("%i: OP_ITER_BEGIN varName=%s failIp=%i", ip - 1, varName, failIp);
  1216. ip += 3;
  1217. break;
  1218. }
  1219. case OP_ITER_BEGIN_STR:
  1220. {
  1221. StringTableEntry varName = CodeToSTE(code, ip);
  1222. U32 failIp = code[ip + 2];
  1223. Con::printf("%i: OP_ITER_BEGIN varName=%s failIp=%i", ip - 1, varName, failIp);
  1224. ip += 3;
  1225. break;
  1226. }
  1227. case OP_ITER:
  1228. {
  1229. U32 breakIp = code[ip];
  1230. Con::printf("%i: OP_ITER breakIp=%i", ip - 1, breakIp);
  1231. ++ip;
  1232. break;
  1233. }
  1234. case OP_ITER_END:
  1235. {
  1236. Con::printf("%i: OP_ITER_END", ip - 1);
  1237. break;
  1238. }
  1239. default:
  1240. Con::printf("%i: !!INVALID!!", ip - 1);
  1241. break;
  1242. }
  1243. }
  1244. smInFunction = false;
  1245. }