PageRenderTime 31ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/lscript/lscript_execute.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 553 lines | 414 code | 70 blank | 69 comment | 21 complexity | 651fee192f9e2a4c7f20fb4af169bfb7 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file lscript_execute.h
  3. * @brief Classes to execute bytecode
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LSCRIPT_EXECUTE_H
  27. #define LL_LSCRIPT_EXECUTE_H
  28. #include "lscript_byteconvert.h"
  29. #include "linked_lists.h"
  30. #include "lscript_library.h"
  31. class LLTimer;
  32. // Return values for run() methods
  33. const U32 NO_DELETE_FLAG = 0x0000;
  34. const U32 DELETE_FLAG = 0x0001;
  35. const U32 CREDIT_MONEY_FLAG = 0x0002;
  36. // list of op code execute functions
  37. BOOL run_noop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  38. BOOL run_pop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  39. BOOL run_pops(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  40. BOOL run_popl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  41. BOOL run_popv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  42. BOOL run_popq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  43. BOOL run_poparg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  44. BOOL run_popip(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  45. BOOL run_popbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  46. BOOL run_popsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  47. BOOL run_popslr(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  48. BOOL run_dup(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  49. BOOL run_dups(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  50. BOOL run_dupl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  51. BOOL run_dupv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  52. BOOL run_dupq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  53. BOOL run_store(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  54. BOOL run_stores(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  55. BOOL run_storel(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  56. BOOL run_storev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  57. BOOL run_storeq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  58. BOOL run_storeg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  59. BOOL run_storegs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  60. BOOL run_storegl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  61. BOOL run_storegv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  62. BOOL run_storegq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  63. BOOL run_loadp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  64. BOOL run_loadsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  65. BOOL run_loadlp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  66. BOOL run_loadvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  67. BOOL run_loadqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  68. BOOL run_loadgp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  69. BOOL run_loadgsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  70. BOOL run_loadglp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  71. BOOL run_loadgvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  72. BOOL run_loadgqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  73. BOOL run_push(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  74. BOOL run_pushs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  75. BOOL run_pushl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  76. BOOL run_pushv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  77. BOOL run_pushq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  78. BOOL run_pushg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  79. BOOL run_pushgs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  80. BOOL run_pushgl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  81. BOOL run_pushgv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  82. BOOL run_pushgq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  83. BOOL run_puship(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  84. BOOL run_pushbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  85. BOOL run_pushsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  86. BOOL run_pushargb(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  87. BOOL run_pushargi(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  88. BOOL run_pushargf(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  89. BOOL run_pushargs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  90. BOOL run_pushargv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  91. BOOL run_pushargq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  92. BOOL run_pushe(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  93. BOOL run_pushev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  94. BOOL run_pusheq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  95. BOOL run_pusharge(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  96. BOOL run_add(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  97. BOOL run_sub(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  98. BOOL run_mul(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  99. BOOL run_div(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  100. BOOL run_mod(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  101. BOOL run_eq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  102. BOOL run_neq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  103. BOOL run_leq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  104. BOOL run_geq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  105. BOOL run_less(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  106. BOOL run_greater(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  107. BOOL run_bitand(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  108. BOOL run_bitor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  109. BOOL run_bitxor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  110. BOOL run_booland(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  111. BOOL run_boolor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  112. BOOL run_shl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  113. BOOL run_shr(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  114. BOOL run_neg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  115. BOOL run_bitnot(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  116. BOOL run_boolnot(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  117. BOOL run_jump(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  118. BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  119. BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  120. BOOL run_state(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  121. BOOL run_call(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  122. BOOL run_return(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  123. BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  124. BOOL run_stacktos(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  125. BOOL run_stacktol(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  126. BOOL run_print(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  127. BOOL run_calllib(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  128. BOOL run_calllib_two_byte(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  129. void unknown_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  130. void integer_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  131. void integer_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  132. void integer_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  133. void float_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  134. void float_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  135. void float_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  136. void string_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  137. void string_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  138. void key_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  139. void key_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  140. void vector_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  141. void vector_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  142. void vector_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  143. void vector_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  144. void quaternion_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  145. void integer_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  146. void float_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  147. void string_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  148. void key_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  149. void vector_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  150. void quaternion_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  151. void list_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  152. void list_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  153. void list_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  154. void list_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  155. void list_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  156. void list_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  157. void list_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  158. void integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  159. void float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  160. void vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  161. void quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  162. class LLScriptDataCollection
  163. {
  164. public:
  165. LLScriptDataCollection(LSCRIPTStateEventType type, LLScriptLibData *data)
  166. : mType(type), mData(data)
  167. {
  168. }
  169. LLScriptDataCollection(U8 *src, S32 &offset)
  170. {
  171. S32 i, number;
  172. mType = (LSCRIPTStateEventType)bytestream2integer(src, offset);
  173. number = bytestream2integer(src, offset);
  174. mData = new LLScriptLibData[number];
  175. for (i = 0; i < number; i++)
  176. {
  177. mData[i].set(src, offset);
  178. }
  179. }
  180. ~LLScriptDataCollection()
  181. {
  182. delete [] mData;
  183. mData = NULL;
  184. }
  185. S32 getSavedSize()
  186. {
  187. S32 size = 0;
  188. // mTyoe
  189. size += 4;
  190. // number of entries
  191. size += 4;
  192. S32 i = 0;
  193. do
  194. {
  195. size += mData[i].getSavedSize();;
  196. }
  197. while (mData[i++].mType != LST_NULL);
  198. return size;
  199. }
  200. S32 write2bytestream(U8 *dest)
  201. {
  202. S32 offset = 0;
  203. // mTyoe
  204. integer2bytestream(dest, offset, mType);
  205. // count number of entries
  206. S32 number = 0;
  207. while (mData[number++].mType != LST_NULL)
  208. ;
  209. integer2bytestream(dest, offset, number);
  210. // now the entries themselves
  211. number = 0;
  212. do
  213. {
  214. offset += mData[number].write2bytestream(dest + offset);
  215. }
  216. while (mData[number++].mType != LST_NULL);
  217. return offset;
  218. }
  219. LSCRIPTStateEventType mType;
  220. LLScriptLibData *mData;
  221. };
  222. const S32 MAX_EVENTS_IN_QUEUE = 64;
  223. class LLScriptEventData
  224. {
  225. public:
  226. LLScriptEventData() {}
  227. LLScriptEventData(U8 *src, S32 &offset)
  228. {
  229. S32 i, number = bytestream2integer(src, offset);
  230. for (i = 0; i < number; i++)
  231. {
  232. mEventDataList.addData(new LLScriptDataCollection(src, offset));
  233. }
  234. }
  235. void set(U8 *src, S32 &offset)
  236. {
  237. S32 i, number = bytestream2integer(src, offset);
  238. for (i = 0; i < number; i++)
  239. {
  240. mEventDataList.addData(new LLScriptDataCollection(src, offset));
  241. }
  242. }
  243. ~LLScriptEventData()
  244. {
  245. mEventDataList.deleteAllData();
  246. }
  247. void addEventData(LLScriptDataCollection *data)
  248. {
  249. if (mEventDataList.getLength() < MAX_EVENTS_IN_QUEUE)
  250. mEventDataList.addDataAtEnd(data);
  251. else
  252. delete data;
  253. }
  254. LLScriptDataCollection *getNextEvent(LSCRIPTStateEventType type)
  255. {
  256. LLScriptDataCollection *temp;
  257. for (temp = mEventDataList.getFirstData();
  258. temp;
  259. temp = mEventDataList.getNextData())
  260. {
  261. if (temp->mType == type)
  262. {
  263. mEventDataList.removeCurrentData();
  264. return temp;
  265. }
  266. }
  267. return NULL;
  268. }
  269. LLScriptDataCollection *getNextEvent()
  270. {
  271. LLScriptDataCollection *temp;
  272. temp = mEventDataList.getFirstData();
  273. if (temp)
  274. {
  275. mEventDataList.removeCurrentData();
  276. return temp;
  277. }
  278. return NULL;
  279. }
  280. void removeEventType(LSCRIPTStateEventType type)
  281. {
  282. LLScriptDataCollection *temp;
  283. for (temp = mEventDataList.getFirstData();
  284. temp;
  285. temp = mEventDataList.getNextData())
  286. {
  287. if (temp->mType == type)
  288. {
  289. mEventDataList.deleteCurrentData();
  290. }
  291. }
  292. }
  293. S32 getSavedSize()
  294. {
  295. S32 size = 0;
  296. // number in linked list
  297. size += 4;
  298. LLScriptDataCollection *temp;
  299. for (temp = mEventDataList.getFirstData();
  300. temp;
  301. temp = mEventDataList.getNextData())
  302. {
  303. size += temp->getSavedSize();
  304. }
  305. return size;
  306. }
  307. S32 write2bytestream(U8 *dest)
  308. {
  309. S32 offset = 0;
  310. // number in linked list
  311. S32 number = mEventDataList.getLength();
  312. integer2bytestream(dest, offset, number);
  313. LLScriptDataCollection *temp;
  314. for (temp = mEventDataList.getFirstData();
  315. temp;
  316. temp = mEventDataList.getNextData())
  317. {
  318. offset += temp->write2bytestream(dest + offset);
  319. }
  320. return offset;
  321. }
  322. LLLinkedList<LLScriptDataCollection> mEventDataList;
  323. };
  324. class LLScriptExecute
  325. {
  326. public:
  327. LLScriptExecute();
  328. virtual ~LLScriptExecute() = 0;
  329. virtual S32 getVersion() const = 0;
  330. virtual void deleteAllEvents() = 0;
  331. virtual void addEvent(LLScriptDataCollection* event) = 0;
  332. virtual U32 getEventCount() = 0;
  333. virtual void removeEventType(LSCRIPTStateEventType event_type) = 0;
  334. virtual S32 getFaults() = 0;
  335. virtual void setFault(LSCRIPTRunTimeFaults fault) = 0;
  336. virtual U32 getFreeMemory() = 0;
  337. virtual S32 getParameter() = 0;
  338. virtual void setParameter(S32 value) = 0;
  339. virtual F32 getSleep() const = 0;
  340. virtual void setSleep(F32 value) = 0;
  341. virtual F32 getEnergy() const = 0;
  342. virtual void setEnergy(F32 value) = 0;
  343. virtual U64 getCurrentEvents() = 0;
  344. virtual void setCurrentEvents(U64 value) = 0;
  345. virtual U64 getEventHandlers() = 0;
  346. virtual void setEventHandlers(U64 value) = 0;
  347. virtual U64 getCurrentHandler() = 0;
  348. virtual void setCurrentHandler(U64 value) = 0;
  349. virtual BOOL isFinished() const = 0;
  350. virtual BOOL isStateChangePending() const = 0;
  351. virtual S32 writeState(U8 **dest, U32 header_size, U32 footer_size) = 0; // Allocate memory for header, state and footer return size of state.
  352. virtual U32 getEventsSavedSize() = 0; // Returns 0 if events are written with state.
  353. virtual S32 writeEvents(U8 *dest) = 0; // Must write and return exactly the number of bytes returned by getEventsSavedSize.
  354. virtual void readEvents(U8* src, S32& offset) = 0;
  355. virtual S32 readState(U8 *src) = 0; // Returns number of bytes read.
  356. virtual void reset();
  357. virtual const U8* getBytecode() const = 0;
  358. virtual U32 getBytecodeSize() const = 0;
  359. virtual bool isMono() const = 0;
  360. virtual void error() {;} // Processing that must be performed when error flag is set and so run is not called.
  361. virtual U32 getUsedMemory() = 0;
  362. // Run current event handler for a maximum of time_slice seconds.
  363. // Updates current handler and current events registers.
  364. virtual void resumeEventHandler(BOOL b_print, const LLUUID &id, F32 time_slice) = 0;
  365. // Run handler for event for a maximum of time_slice seconds.
  366. // Updates current handler and current events registers.
  367. virtual void callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) = 0;;
  368. // Run handler for next queued event for maximum of time_slice seconds.
  369. // Updates current handler and current events registers.
  370. // Removes processed event from queue.
  371. virtual void callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice) = 0;
  372. // Run handler for event for a maximum of time_slice seconds.
  373. // Updates current handler and current events registers.
  374. // Removes processed event from queue.
  375. virtual void callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) = 0;
  376. // Switch to next state.
  377. // Returns new set of handled events.
  378. virtual U64 nextState() = 0;
  379. // Returns time taken.
  380. virtual F32 runQuanta(BOOL b_print, const LLUUID &id,
  381. const char **errorstr,
  382. F32 quanta,
  383. U32& events_processed, LLTimer& timer);
  384. // NOTE: babbage: this must be used on occasions where another script may already be executing. Only 2 levels of nesting are allowed.
  385. // Provided to support bizarre detach behaviour only. Do not use.
  386. virtual F32 runNested(BOOL b_print, const LLUUID &id,
  387. const char **errorstr,
  388. F32 quanta,
  389. U32& events_processed, LLTimer& timer);
  390. // Run smallest possible amount of code: an instruction for LSL2, a segment
  391. // between save tests for Mono
  392. void runInstructions(BOOL b_print, const LLUUID &id,
  393. const char **errorstr,
  394. U32& events_processed,
  395. F32 quanta);
  396. bool isYieldDue() const;
  397. void setReset(BOOL b) {mReset = b;}
  398. BOOL getReset() const { return mReset; }
  399. // Called when the script is scheduled to be run from newsim/LLScriptData
  400. virtual void startRunning() = 0;
  401. // Called when the script is scheduled to be stopped from newsim/LLScriptData
  402. virtual void stopRunning() = 0;
  403. // A timer is regularly checked to see if script takes too long, but we
  404. // don't do it every opcode due to performance hits.
  405. static void setTimerCheckSkip( S32 value ) { sTimerCheckSkip = value; }
  406. static S32 getTimerCheckSkip() { return sTimerCheckSkip; }
  407. private:
  408. BOOL mReset;
  409. static S32 sTimerCheckSkip; // Number of times to skip the timer check for performance reasons
  410. };
  411. class LLScriptExecuteLSL2 : public LLScriptExecute
  412. {
  413. public:
  414. LLScriptExecuteLSL2(LLFILE *fp);
  415. LLScriptExecuteLSL2(const U8* bytecode, U32 bytecode_size);
  416. virtual ~LLScriptExecuteLSL2();
  417. virtual S32 getVersion() const {return get_register(mBuffer, LREG_VN);}
  418. virtual void deleteAllEvents() {mEventData.mEventDataList.deleteAllData();}
  419. virtual void addEvent(LLScriptDataCollection* event);
  420. virtual U32 getEventCount() {return mEventData.mEventDataList.getLength();}
  421. virtual void removeEventType(LSCRIPTStateEventType event_type);
  422. virtual S32 getFaults() {return get_register(mBuffer, LREG_FR);}
  423. virtual void setFault(LSCRIPTRunTimeFaults fault) {set_fault(mBuffer, fault);}
  424. virtual U32 getFreeMemory();
  425. virtual S32 getParameter();
  426. virtual void setParameter(S32 value);
  427. virtual F32 getSleep() const;
  428. virtual void setSleep(F32 value);
  429. virtual F32 getEnergy() const;
  430. virtual void setEnergy(F32 value);
  431. virtual U64 getCurrentEvents() {return get_event_register(mBuffer, LREG_CE, getMajorVersion());}
  432. virtual void setCurrentEvents(U64 value) {return set_event_register(mBuffer, LREG_CE, value, getMajorVersion());}
  433. virtual U64 getEventHandlers() {return get_event_register(mBuffer, LREG_ER, getMajorVersion());}
  434. virtual void setEventHandlers(U64 value) {set_event_register(mBuffer, LREG_ER, value, getMajorVersion());}
  435. virtual U64 getCurrentHandler();
  436. virtual void setCurrentHandler(U64 value) {return set_event_register(mBuffer, LREG_IE, value, getMajorVersion());}
  437. virtual BOOL isFinished() const {return get_register(mBuffer, LREG_IP) == 0;}
  438. virtual BOOL isStateChangePending() const {return get_register(mBuffer, LREG_CS) != get_register(mBuffer, LREG_NS);}
  439. virtual S32 writeState(U8 **dest, U32 header_size, U32 footer_size); // Not including Events.
  440. virtual U32 getEventsSavedSize() {return mEventData.getSavedSize();}
  441. virtual S32 writeEvents(U8 *dest) {return mEventData.write2bytestream(dest);}
  442. virtual void readEvents(U8* src, S32& offset) {mEventData.set(src, offset);}
  443. virtual S32 writeBytecode(U8 **dest);
  444. virtual S32 readState(U8 *src);
  445. virtual void reset();
  446. virtual const U8* getBytecode() const {return mBytecode;}
  447. virtual U32 getBytecodeSize() const {return mBytecodeSize;}
  448. virtual bool isMono() const {return false;}
  449. virtual U32 getUsedMemory();
  450. // Run current event handler for a maximum of time_slice seconds.
  451. // Updates current handler and current events registers.
  452. virtual void resumeEventHandler(BOOL b_print, const LLUUID &id, F32 time_slice);
  453. // Run handler for event for a maximum of time_slice seconds.
  454. // Updates current handler and current events registers.
  455. virtual void callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice);
  456. // Run handler for next queued event for maximum of time_slice seconds.
  457. // Updates current handler and current events registers.
  458. // Removes processed event from queue.
  459. virtual void callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice);
  460. // Run handler for event for a maximum of time_slice seconds.
  461. // Updates current handler and current events registers.
  462. // Removes processed event from queue.
  463. virtual void callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice);
  464. // Switch to next state.
  465. // Returns new set of handled events.
  466. virtual U64 nextState();
  467. void init();
  468. BOOL (*mExecuteFuncs[0x100])(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
  469. U32 mInstructionCount;
  470. U8 *mBuffer;
  471. LLScriptEventData mEventData;
  472. U8* mBytecode; // Initial state and bytecode.
  473. U32 mBytecodeSize;
  474. private:
  475. S32 getMajorVersion() const;
  476. void recordBoundaryError( const LLUUID &id );
  477. void setStateEventOpcoodeStartSafely( S32 state, LSCRIPTStateEventType event, const LLUUID &id );
  478. // Called when the script is scheduled to be run from newsim/LLScriptData
  479. virtual void startRunning();
  480. // Called when the script is scheduled to be stopped from newsim/LLScriptData
  481. virtual void stopRunning();
  482. };
  483. #endif