PageRenderTime 52ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 1ms

/indra/lscript/lscript_execute/lscript_execute.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 2573 lines | 2132 code | 271 blank | 170 comment | 218 complexity | 4cc2cbaf9c9efb150b48760b7912722d MD5 | raw file
Possible License(s): LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. /**
  2. * @file lscript_execute.cpp
  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. #include "linden_common.h"
  27. #include <algorithm>
  28. #include <sstream>
  29. #include "lscript_execute.h"
  30. #include "lltimer.h"
  31. #include "lscript_readlso.h"
  32. #include "lscript_library.h"
  33. #include "lscript_heapruntime.h"
  34. #include "lscript_alloc.h"
  35. #include "llstat.h"
  36. // Static
  37. const S32 DEFAULT_SCRIPT_TIMER_CHECK_SKIP = 4;
  38. S32 LLScriptExecute::sTimerCheckSkip = DEFAULT_SCRIPT_TIMER_CHECK_SKIP;
  39. void (*binary_operations[LST_EOF][LST_EOF])(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  40. void (*unary_operations[LST_EOF])(U8 *buffer, LSCRIPTOpCodesEnum opcode);
  41. const char* LSCRIPTRunTimeFaultStrings[LSRF_EOF] = /*Flawfinder: ignore*/
  42. {
  43. "Invalid", // LSRF_INVALID,
  44. "Math Error", // LSRF_MATH,
  45. "Stack-Heap Collision", // LSRF_STACK_HEAP_COLLISION,
  46. "Bounds Check Error", // LSRF_BOUND_CHECK_ERROR,
  47. "Heap Error", // LSRF_HEAP_ERROR,
  48. "Version Mismatch", // LSRF_VERSION_MISMATCH,
  49. "Missing Inventory", // LSRF_MISSING_INVENTORY,
  50. "Hit Sandbox Limit", // LSRF_SANDBOX,
  51. "Chat Overrun", // LSRF_CHAT_OVERRUN,
  52. "Too Many Listens", // LSRF_TOO_MANY_LISTENS,
  53. "Lists may not contain lists", // LSRF_NESTING_LISTS,
  54. "CLI Exception" // LSRF_CLI
  55. };
  56. void LLScriptExecuteLSL2::startRunning() {}
  57. void LLScriptExecuteLSL2::stopRunning() {}
  58. const char* URL_REQUEST_GRANTED = "URL_REQUEST_GRANTED";
  59. const char* URL_REQUEST_DENIED = "URL_REQUEST_DENIED";
  60. // HTTP Requests to LSL scripts will time out after 25 seconds.
  61. const U64 LSL_HTTP_REQUEST_TIMEOUT_USEC = 25 * USEC_PER_SEC;
  62. LLScriptExecuteLSL2::LLScriptExecuteLSL2(LLFILE *fp)
  63. {
  64. U8 sizearray[4];
  65. size_t filesize;
  66. S32 pos = 0;
  67. if (fread(&sizearray, 1, 4, fp) != 4)
  68. {
  69. llwarns << "Short read" << llendl;
  70. filesize = 0;
  71. } else {
  72. filesize = bytestream2integer(sizearray, pos);
  73. }
  74. mBuffer = new U8[filesize];
  75. fseek(fp, 0, SEEK_SET);
  76. if (fread(mBuffer, 1, filesize, fp) != filesize)
  77. {
  78. llwarns << "Short read" << llendl;
  79. }
  80. fclose(fp);
  81. init();
  82. }
  83. LLScriptExecuteLSL2::LLScriptExecuteLSL2(const U8* bytecode, U32 bytecode_size)
  84. {
  85. mBuffer = new U8[TOP_OF_MEMORY];
  86. memset(mBuffer + bytecode_size, 0, TOP_OF_MEMORY - bytecode_size);
  87. S32 src_offset = 0;
  88. S32 dest_offset = 0;
  89. bytestream2bytestream(mBuffer, dest_offset, bytecode, src_offset, bytecode_size);
  90. mBytecodeSize = bytecode_size;
  91. mBytecode = new U8[mBytecodeSize];
  92. memcpy(mBytecode, bytecode, mBytecodeSize);
  93. init();
  94. }
  95. LLScriptExecute::~LLScriptExecute() {}
  96. LLScriptExecuteLSL2::~LLScriptExecuteLSL2()
  97. {
  98. delete[] mBuffer;
  99. delete[] mBytecode;
  100. }
  101. void LLScriptExecuteLSL2::init()
  102. {
  103. S32 i, j;
  104. mInstructionCount = 0;
  105. for (i = 0; i < 256; i++)
  106. {
  107. mExecuteFuncs[i] = run_noop;
  108. }
  109. mExecuteFuncs[LSCRIPTOpCodes[LOPC_NOOP]] = run_noop;
  110. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POP]] = run_pop;
  111. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPS]] = run_pops;
  112. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPL]] = run_popl;
  113. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPV]] = run_popv;
  114. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPQ]] = run_popq;
  115. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPARG]] = run_poparg;
  116. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPIP]] = run_popip;
  117. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPBP]] = run_popbp;
  118. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPSP]] = run_popsp;
  119. mExecuteFuncs[LSCRIPTOpCodes[LOPC_POPSLR]] = run_popslr;
  120. mExecuteFuncs[LSCRIPTOpCodes[LOPC_DUP]] = run_dup;
  121. mExecuteFuncs[LSCRIPTOpCodes[LOPC_DUPS]] = run_dups;
  122. mExecuteFuncs[LSCRIPTOpCodes[LOPC_DUPL]] = run_dupl;
  123. mExecuteFuncs[LSCRIPTOpCodes[LOPC_DUPV]] = run_dupv;
  124. mExecuteFuncs[LSCRIPTOpCodes[LOPC_DUPQ]] = run_dupq;
  125. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STORE]] = run_store;
  126. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STORES]] = run_stores;
  127. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREL]] = run_storel;
  128. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREV]] = run_storev;
  129. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREQ]] = run_storeq;
  130. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREG]] = run_storeg;
  131. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREGL]] = run_storegl;
  132. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREGS]] = run_storegs;
  133. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREGV]] = run_storegv;
  134. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STOREGQ]] = run_storegq;
  135. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADP]] = run_loadp;
  136. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADSP]] = run_loadsp;
  137. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADLP]] = run_loadlp;
  138. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADVP]] = run_loadvp;
  139. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADQP]] = run_loadqp;
  140. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADGP]] = run_loadgp;
  141. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADGSP]] = run_loadgsp;
  142. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADGLP]] = run_loadglp;
  143. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADGVP]] = run_loadgvp;
  144. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LOADGQP]] = run_loadgqp;
  145. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSH]] = run_push;
  146. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHS]] = run_pushs;
  147. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHL]] = run_pushl;
  148. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHV]] = run_pushv;
  149. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHQ]] = run_pushq;
  150. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHG]] = run_pushg;
  151. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHGS]] = run_pushgs;
  152. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHGL]] = run_pushgl;
  153. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHGV]] = run_pushgv;
  154. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHGQ]] = run_pushgq;
  155. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHIP]] = run_puship;
  156. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHSP]] = run_pushsp;
  157. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHBP]] = run_pushbp;
  158. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHARGB]] = run_pushargb;
  159. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHARGI]] = run_pushargi;
  160. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHARGF]] = run_pushargf;
  161. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHARGS]] = run_pushargs;
  162. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHARGV]] = run_pushargv;
  163. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHARGQ]] = run_pushargq;
  164. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHE]] = run_pushe;
  165. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHEV]] = run_pushev;
  166. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHEQ]] = run_pusheq;
  167. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PUSHARGE]] = run_pusharge;
  168. mExecuteFuncs[LSCRIPTOpCodes[LOPC_ADD]] = run_add;
  169. mExecuteFuncs[LSCRIPTOpCodes[LOPC_SUB]] = run_sub;
  170. mExecuteFuncs[LSCRIPTOpCodes[LOPC_MUL]] = run_mul;
  171. mExecuteFuncs[LSCRIPTOpCodes[LOPC_DIV]] = run_div;
  172. mExecuteFuncs[LSCRIPTOpCodes[LOPC_MOD]] = run_mod;
  173. mExecuteFuncs[LSCRIPTOpCodes[LOPC_EQ]] = run_eq;
  174. mExecuteFuncs[LSCRIPTOpCodes[LOPC_NEQ]] = run_neq;
  175. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LEQ]] = run_leq;
  176. mExecuteFuncs[LSCRIPTOpCodes[LOPC_GEQ]] = run_geq;
  177. mExecuteFuncs[LSCRIPTOpCodes[LOPC_LESS]] = run_less;
  178. mExecuteFuncs[LSCRIPTOpCodes[LOPC_GREATER]] = run_greater;
  179. mExecuteFuncs[LSCRIPTOpCodes[LOPC_BITAND]] = run_bitand;
  180. mExecuteFuncs[LSCRIPTOpCodes[LOPC_BITOR]] = run_bitor;
  181. mExecuteFuncs[LSCRIPTOpCodes[LOPC_BITXOR]] = run_bitxor;
  182. mExecuteFuncs[LSCRIPTOpCodes[LOPC_BOOLAND]] = run_booland;
  183. mExecuteFuncs[LSCRIPTOpCodes[LOPC_BOOLOR]] = run_boolor;
  184. mExecuteFuncs[LSCRIPTOpCodes[LOPC_SHL]] = run_shl;
  185. mExecuteFuncs[LSCRIPTOpCodes[LOPC_SHR]] = run_shr;
  186. mExecuteFuncs[LSCRIPTOpCodes[LOPC_NEG]] = run_neg;
  187. mExecuteFuncs[LSCRIPTOpCodes[LOPC_BITNOT]] = run_bitnot;
  188. mExecuteFuncs[LSCRIPTOpCodes[LOPC_BOOLNOT]] = run_boolnot;
  189. mExecuteFuncs[LSCRIPTOpCodes[LOPC_JUMP]] = run_jump;
  190. mExecuteFuncs[LSCRIPTOpCodes[LOPC_JUMPIF]] = run_jumpif;
  191. mExecuteFuncs[LSCRIPTOpCodes[LOPC_JUMPNIF]] = run_jumpnif;
  192. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STATE]] = run_state;
  193. mExecuteFuncs[LSCRIPTOpCodes[LOPC_CALL]] = run_call;
  194. mExecuteFuncs[LSCRIPTOpCodes[LOPC_RETURN]] = run_return;
  195. mExecuteFuncs[LSCRIPTOpCodes[LOPC_CAST]] = run_cast;
  196. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STACKTOS]] = run_stacktos;
  197. mExecuteFuncs[LSCRIPTOpCodes[LOPC_STACKTOL]] = run_stacktol;
  198. mExecuteFuncs[LSCRIPTOpCodes[LOPC_PRINT]] = run_print;
  199. mExecuteFuncs[LSCRIPTOpCodes[LOPC_CALLLIB]] = run_calllib;
  200. mExecuteFuncs[LSCRIPTOpCodes[LOPC_CALLLIB_TWO_BYTE]] = run_calllib_two_byte;
  201. for (i = 0; i < LST_EOF; i++)
  202. {
  203. for (j = 0; j < LST_EOF; j++)
  204. {
  205. binary_operations[i][j] = unknown_operation;
  206. }
  207. }
  208. binary_operations[LST_INTEGER][LST_INTEGER] = integer_integer_operation;
  209. binary_operations[LST_INTEGER][LST_FLOATINGPOINT] = integer_float_operation;
  210. binary_operations[LST_INTEGER][LST_VECTOR] = integer_vector_operation;
  211. binary_operations[LST_FLOATINGPOINT][LST_INTEGER] = float_integer_operation;
  212. binary_operations[LST_FLOATINGPOINT][LST_FLOATINGPOINT] = float_float_operation;
  213. binary_operations[LST_FLOATINGPOINT][LST_VECTOR] = float_vector_operation;
  214. binary_operations[LST_STRING][LST_STRING] = string_string_operation;
  215. binary_operations[LST_STRING][LST_KEY] = string_key_operation;
  216. binary_operations[LST_KEY][LST_STRING] = key_string_operation;
  217. binary_operations[LST_KEY][LST_KEY] = key_key_operation;
  218. binary_operations[LST_VECTOR][LST_INTEGER] = vector_integer_operation;
  219. binary_operations[LST_VECTOR][LST_FLOATINGPOINT] = vector_float_operation;
  220. binary_operations[LST_VECTOR][LST_VECTOR] = vector_vector_operation;
  221. binary_operations[LST_VECTOR][LST_QUATERNION] = vector_quaternion_operation;
  222. binary_operations[LST_QUATERNION][LST_QUATERNION] = quaternion_quaternion_operation;
  223. binary_operations[LST_INTEGER][LST_LIST] = integer_list_operation;
  224. binary_operations[LST_FLOATINGPOINT][LST_LIST] = float_list_operation;
  225. binary_operations[LST_STRING][LST_LIST] = string_list_operation;
  226. binary_operations[LST_KEY][LST_LIST] = key_list_operation;
  227. binary_operations[LST_VECTOR][LST_LIST] = vector_list_operation;
  228. binary_operations[LST_QUATERNION][LST_LIST] = quaternion_list_operation;
  229. binary_operations[LST_LIST][LST_INTEGER] = list_integer_operation;
  230. binary_operations[LST_LIST][LST_FLOATINGPOINT] = list_float_operation;
  231. binary_operations[LST_LIST][LST_STRING] = list_string_operation;
  232. binary_operations[LST_LIST][LST_KEY] = list_key_operation;
  233. binary_operations[LST_LIST][LST_VECTOR] = list_vector_operation;
  234. binary_operations[LST_LIST][LST_QUATERNION] = list_quaternion_operation;
  235. binary_operations[LST_LIST][LST_LIST] = list_list_operation;
  236. for (i = 0; i < LST_EOF; i++)
  237. {
  238. unary_operations[i] = unknown_operation;
  239. }
  240. unary_operations[LST_INTEGER] = integer_operation;
  241. unary_operations[LST_FLOATINGPOINT] = float_operation;
  242. unary_operations[LST_VECTOR] = vector_operation;
  243. unary_operations[LST_QUATERNION] = quaternion_operation;
  244. }
  245. // Utility routine for when there's a boundary error parsing bytecode
  246. void LLScriptExecuteLSL2::recordBoundaryError( const LLUUID &id )
  247. {
  248. set_fault(mBuffer, LSRF_BOUND_CHECK_ERROR);
  249. llwarns << "Script boundary error for ID " << id << llendl;
  250. }
  251. // set IP to the event handler with some error checking
  252. void LLScriptExecuteLSL2::setStateEventOpcoodeStartSafely( S32 state, LSCRIPTStateEventType event, const LLUUID &id )
  253. {
  254. S32 opcode_start = get_state_event_opcoode_start( mBuffer, state, event );
  255. if ( opcode_start == -1 )
  256. {
  257. recordBoundaryError( id );
  258. }
  259. else
  260. {
  261. set_ip( mBuffer, opcode_start );
  262. }
  263. }
  264. S32 lscript_push_variable(LLScriptLibData *data, U8 *buffer);
  265. void LLScriptExecuteLSL2::resumeEventHandler(BOOL b_print, const LLUUID &id, F32 time_slice)
  266. {
  267. // call opcode run function pointer with buffer and IP
  268. mInstructionCount++;
  269. S32 value = get_register(mBuffer, LREG_IP);
  270. S32 tvalue = value;
  271. S32 opcode = safe_instruction_bytestream2byte(mBuffer, tvalue);
  272. mExecuteFuncs[opcode](mBuffer, value, b_print, id);
  273. set_ip(mBuffer, value);
  274. add_register_fp(mBuffer, LREG_ESR, -0.1f);
  275. // lsa_print_heap(mBuffer);
  276. if (b_print)
  277. {
  278. lsa_print_heap(mBuffer);
  279. printf("ip: 0x%X\n", get_register(mBuffer, LREG_IP));
  280. printf("sp: 0x%X\n", get_register(mBuffer, LREG_SP));
  281. printf("bp: 0x%X\n", get_register(mBuffer, LREG_BP));
  282. printf("hr: 0x%X\n", get_register(mBuffer, LREG_HR));
  283. printf("hp: 0x%X\n", get_register(mBuffer, LREG_HP));
  284. }
  285. // NOTE: Babbage: all mExecuteFuncs return false.
  286. }
  287. void LLScriptExecuteLSL2::callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice)
  288. {
  289. S32 major_version = getMajorVersion();
  290. // push a zero to be popped
  291. lscript_push(mBuffer, 0);
  292. // push sp as current bp
  293. S32 sp = get_register(mBuffer, LREG_SP);
  294. lscript_push(mBuffer, sp);
  295. // Update current handler and current events registers.
  296. set_event_register(mBuffer, LREG_IE, LSCRIPTStateBitField[event], major_version);
  297. U64 current_events = get_event_register(mBuffer, LREG_CE, major_version);
  298. current_events &= ~LSCRIPTStateBitField[event];
  299. set_event_register(mBuffer, LREG_CE, current_events, major_version);
  300. // now, push any additional stack space
  301. U32 current_state = get_register(mBuffer, LREG_CS);
  302. S32 additional_size = get_event_stack_size(mBuffer, current_state, event);
  303. lscript_pusharge(mBuffer, additional_size);
  304. // now set the bp correctly
  305. sp = get_register(mBuffer, LREG_SP);
  306. sp += additional_size;
  307. set_bp(mBuffer, sp);
  308. // set IP to the function
  309. S32 opcode_start = get_state_event_opcoode_start(mBuffer, current_state, event);
  310. set_ip(mBuffer, opcode_start);
  311. }
  312. //void callStateExitHandler()
  313. //{
  314. // // push a zero to be popped
  315. // lscript_push(mBuffer, 0);
  316. // // push sp as current bp
  317. // S32 sp = get_register(mBuffer, LREG_SP);
  318. // lscript_push(mBuffer, sp);
  319. //
  320. // // now, push any additional stack space
  321. // S32 additional_size = get_event_stack_size(mBuffer, current_state, LSTT_STATE_EXIT);
  322. // lscript_pusharge(mBuffer, additional_size);
  323. //
  324. // sp = get_register(mBuffer, LREG_SP);
  325. // sp += additional_size;
  326. // set_bp(mBuffer, sp);
  327. //
  328. // // set IP to the event handler
  329. // S32 opcode_start = get_state_event_opcoode_start(mBuffer, current_state, LSTT_STATE_EXIT);
  330. // set_ip(mBuffer, opcode_start);
  331. //}
  332. //
  333. //void callStateEntryHandler()
  334. //{
  335. // // push a zero to be popped
  336. // lscript_push(mBuffer, 0);
  337. // // push sp as current bp
  338. // S32 sp = get_register(mBuffer, LREG_SP);
  339. // lscript_push(mBuffer, sp);
  340. //
  341. // event = return_first_event((S32)LSCRIPTStateBitField[LSTT_STATE_ENTRY]);
  342. // set_event_register(mBuffer, LREG_IE, LSCRIPTStateBitField[event], major_version);
  343. // current_events &= ~LSCRIPTStateBitField[event];
  344. // set_event_register(mBuffer, LREG_CE, current_events, major_version);
  345. //
  346. // // now, push any additional stack space
  347. // S32 additional_size = get_event_stack_size(mBuffer, current_state, event) - size;
  348. // lscript_pusharge(mBuffer, additional_size);
  349. //
  350. // // now set the bp correctly
  351. // sp = get_register(mBuffer, LREG_SP);
  352. // sp += additional_size + size;
  353. // set_bp(mBuffer, sp);
  354. // // set IP to the function
  355. // S32 opcode_start = get_state_event_opcoode_start(mBuffer, current_state, event);
  356. // set_ip(mBuffer, opcode_start);
  357. //}
  358. void LLScriptExecuteLSL2::callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice)
  359. {
  360. S32 major_version = getMajorVersion();
  361. LLScriptDataCollection* eventdata;
  362. for (eventdata = mEventData.mEventDataList.getFirstData(); eventdata; eventdata = mEventData.mEventDataList.getNextData())
  363. {
  364. if (eventdata->mType == event)
  365. {
  366. // push a zero to be popped
  367. lscript_push(mBuffer, 0);
  368. // push sp as current bp
  369. S32 sp = get_register(mBuffer, LREG_SP);
  370. lscript_push(mBuffer, sp);
  371. // Update current handler and current events registers.
  372. set_event_register(mBuffer, LREG_IE, LSCRIPTStateBitField[event], major_version);
  373. U64 current_events = get_event_register(mBuffer, LREG_CE, major_version);
  374. current_events &= ~LSCRIPTStateBitField[event];
  375. set_event_register(mBuffer, LREG_CE, current_events, major_version);
  376. // push any arguments that need to be pushed onto the stack
  377. // last piece of data will be type LST_NULL
  378. LLScriptLibData *data = eventdata->mData;
  379. U32 size = 0;
  380. while (data->mType)
  381. {
  382. size += lscript_push_variable(data, mBuffer);
  383. data++;
  384. }
  385. // now, push any additional stack space
  386. U32 current_state = get_register(mBuffer, LREG_CS);
  387. S32 additional_size = get_event_stack_size(mBuffer, current_state, event) - size;
  388. lscript_pusharge(mBuffer, additional_size);
  389. // now set the bp correctly
  390. sp = get_register(mBuffer, LREG_SP);
  391. sp += additional_size + size;
  392. set_bp(mBuffer, sp);
  393. // set IP to the function
  394. S32 opcode_start = get_state_event_opcoode_start(mBuffer, current_state, event);
  395. set_ip(mBuffer, opcode_start);
  396. mEventData.mEventDataList.deleteCurrentData();
  397. break;
  398. }
  399. }
  400. }
  401. void LLScriptExecuteLSL2::callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice)
  402. {
  403. S32 major_version = getMajorVersion();
  404. LLScriptDataCollection* eventdata = mEventData.getNextEvent();
  405. if (eventdata)
  406. {
  407. LSCRIPTStateEventType event = eventdata->mType;
  408. // make sure that we can actually handle this one
  409. if (LSCRIPTStateBitField[event] & event_register)
  410. {
  411. // push a zero to be popped
  412. lscript_push(mBuffer, 0);
  413. // push sp as current bp
  414. S32 sp = get_register(mBuffer, LREG_SP);
  415. lscript_push(mBuffer, sp);
  416. // Update current handler and current events registers.
  417. set_event_register(mBuffer, LREG_IE, LSCRIPTStateBitField[event], major_version);
  418. U64 current_events = get_event_register(mBuffer, LREG_CE, major_version);
  419. current_events &= ~LSCRIPTStateBitField[event];
  420. set_event_register(mBuffer, LREG_CE, current_events, major_version);
  421. // push any arguments that need to be pushed onto the stack
  422. // last piece of data will be type LST_NULL
  423. LLScriptLibData *data = eventdata->mData;
  424. U32 size = 0;
  425. while (data->mType)
  426. {
  427. size += lscript_push_variable(data, mBuffer);
  428. data++;
  429. }
  430. // now, push any additional stack space
  431. U32 current_state = get_register(mBuffer, LREG_CS);
  432. S32 additional_size = get_event_stack_size(mBuffer, current_state, event) - size;
  433. lscript_pusharge(mBuffer, additional_size);
  434. // now set the bp correctly
  435. sp = get_register(mBuffer, LREG_SP);
  436. sp += additional_size + size;
  437. set_bp(mBuffer, sp);
  438. // set IP to the function
  439. S32 opcode_start = get_state_event_opcoode_start(mBuffer, current_state, event);
  440. set_ip(mBuffer, opcode_start);
  441. }
  442. else
  443. {
  444. llwarns << "Somehow got an event that we're not registered for!" << llendl;
  445. }
  446. delete eventdata;
  447. }
  448. }
  449. U64 LLScriptExecuteLSL2::nextState()
  450. {
  451. // copy NS to CS
  452. S32 next_state = get_register(mBuffer, LREG_NS);
  453. set_register(mBuffer, LREG_CS, next_state);
  454. // copy new state's handled events into ER (SR + CS*4 + 4)
  455. return get_handled_events(mBuffer, next_state);
  456. }
  457. //virtual
  458. void LLScriptExecuteLSL2::addEvent(LLScriptDataCollection* event)
  459. {
  460. mEventData.addEventData(event);
  461. }
  462. //virtual
  463. void LLScriptExecuteLSL2::removeEventType(LSCRIPTStateEventType event_type)
  464. {
  465. mEventData.removeEventType(event_type);
  466. }
  467. //virtual
  468. F32 LLScriptExecuteLSL2::getSleep() const
  469. {
  470. return get_register_fp(mBuffer, LREG_SLR);
  471. }
  472. //virtual
  473. void LLScriptExecuteLSL2::setSleep(F32 value)
  474. {
  475. set_register_fp(mBuffer, LREG_SLR, value);
  476. }
  477. //virtual
  478. U64 LLScriptExecuteLSL2::getCurrentHandler()
  479. {
  480. return get_event_register(mBuffer, LREG_IE, getMajorVersion());
  481. }
  482. //virtual
  483. F32 LLScriptExecuteLSL2::getEnergy() const
  484. {
  485. return get_register_fp(mBuffer, LREG_ESR);
  486. }
  487. //virtual
  488. void LLScriptExecuteLSL2::setEnergy(F32 value)
  489. {
  490. set_register_fp(mBuffer, LREG_ESR, value);
  491. }
  492. //virtual
  493. U32 LLScriptExecuteLSL2::getFreeMemory()
  494. {
  495. return get_register(mBuffer, LREG_SP) - get_register(mBuffer, LREG_HP);
  496. }
  497. //virtual
  498. S32 LLScriptExecuteLSL2::getParameter()
  499. {
  500. return get_register(mBuffer, LREG_PR);
  501. }
  502. //virtual
  503. void LLScriptExecuteLSL2::setParameter(S32 value)
  504. {
  505. set_register(mBuffer, LREG_PR, value);
  506. }
  507. S32 LLScriptExecuteLSL2::writeState(U8 **dest, U32 header_size, U32 footer_size)
  508. {
  509. // data format:
  510. // 4 bytes of size of Registers, Name and Description, and Global Variables
  511. // Registers, Name and Description, and Global Variables data
  512. // 4 bytes of size of Heap
  513. // Heap data
  514. // 4 bytes of stack size
  515. // Stack data
  516. S32 registers_size = get_register(mBuffer, LREG_GFR);
  517. if (get_register(mBuffer, LREG_HP) > TOP_OF_MEMORY)
  518. reset_hp_to_safe_spot(mBuffer);
  519. S32 heap_size = get_register(mBuffer, LREG_HP) - get_register(mBuffer, LREG_HR);
  520. S32 stack_size = get_register(mBuffer, LREG_TM) - get_register(mBuffer, LREG_SP);
  521. S32 total_size = registers_size + LSCRIPTDataSize[LST_INTEGER] +
  522. heap_size + LSCRIPTDataSize[LST_INTEGER] +
  523. stack_size + LSCRIPTDataSize[LST_INTEGER];
  524. // actually allocate data
  525. delete[] *dest;
  526. *dest = new U8[header_size + total_size + footer_size];
  527. memset(*dest, 0, header_size + total_size + footer_size);
  528. S32 dest_offset = header_size;
  529. S32 src_offset = 0;
  530. // registers
  531. integer2bytestream(*dest, dest_offset, registers_size);
  532. // llinfos << "Writing CE: " << getCurrentEvents() << llendl;
  533. bytestream2bytestream(*dest, dest_offset, mBuffer, src_offset, registers_size);
  534. // heap
  535. integer2bytestream(*dest, dest_offset, heap_size);
  536. src_offset = get_register(mBuffer, LREG_HR);
  537. bytestream2bytestream(*dest, dest_offset, mBuffer, src_offset, heap_size);
  538. // stack
  539. integer2bytestream(*dest, dest_offset, stack_size);
  540. src_offset = get_register(mBuffer, LREG_SP);
  541. bytestream2bytestream(*dest, dest_offset, mBuffer, src_offset, stack_size);
  542. return total_size;
  543. }
  544. S32 LLScriptExecuteLSL2::writeBytecode(U8 **dest)
  545. {
  546. // data format:
  547. // registers through top of heap
  548. // Heap data
  549. S32 total_size = get_register(mBuffer, LREG_HP);
  550. // actually allocate data
  551. delete [] *dest;
  552. *dest = new U8[total_size];
  553. S32 dest_offset = 0;
  554. S32 src_offset = 0;
  555. bytestream2bytestream(*dest, dest_offset, mBuffer, src_offset, total_size);
  556. return total_size;
  557. }
  558. S32 LLScriptExecuteLSL2::readState(U8 *src)
  559. {
  560. // first, blitz heap and stack
  561. S32 hr = get_register(mBuffer, LREG_HR);
  562. S32 tm = get_register(mBuffer, LREG_TM);
  563. memset(mBuffer + hr, 0, tm - hr);
  564. S32 src_offset = 0;
  565. S32 dest_offset = 0;
  566. S32 size;
  567. // read register size
  568. size = bytestream2integer(src, src_offset);
  569. // copy data into register area
  570. bytestream2bytestream(mBuffer, dest_offset, src, src_offset, size);
  571. // llinfos << "Read CE: " << getCurrentEvents() << llendl;
  572. if (get_register(mBuffer, LREG_TM) != TOP_OF_MEMORY)
  573. {
  574. llwarns << "Invalid state. Top of memory register does not match"
  575. << " constant." << llendl;
  576. reset_hp_to_safe_spot(mBuffer);
  577. return -1;
  578. }
  579. // read heap size
  580. size = bytestream2integer(src, src_offset);
  581. // set dest offset
  582. dest_offset = get_register(mBuffer, LREG_HR);
  583. if (dest_offset + size > TOP_OF_MEMORY)
  584. {
  585. reset_hp_to_safe_spot(mBuffer);
  586. return -1;
  587. }
  588. // copy data into heap area
  589. bytestream2bytestream(mBuffer, dest_offset, src, src_offset, size);
  590. // read stack size
  591. size = bytestream2integer(src, src_offset);
  592. // set dest offset
  593. dest_offset = get_register(mBuffer, LREG_SP);
  594. if (dest_offset + size > TOP_OF_MEMORY)
  595. {
  596. reset_hp_to_safe_spot(mBuffer);
  597. return -1;
  598. }
  599. // copy data into heap area
  600. bytestream2bytestream(mBuffer, dest_offset, src, src_offset, size);
  601. // Return offset to first byte after read data.
  602. return src_offset;
  603. }
  604. void LLScriptExecuteLSL2::reset()
  605. {
  606. LLScriptExecute::reset();
  607. const U8 *src = getBytecode();
  608. S32 size = getBytecodeSize();
  609. if (!src)
  610. return;
  611. // first, blitz heap and stack
  612. S32 hr = get_register(mBuffer, LREG_HR);
  613. S32 tm = get_register(mBuffer, LREG_TM);
  614. memset(mBuffer + hr, 0, tm - hr);
  615. S32 dest_offset = 0;
  616. S32 src_offset = 0;
  617. bytestream2bytestream(mBuffer, dest_offset, src, src_offset, size);
  618. }
  619. S32 LLScriptExecuteLSL2::getMajorVersion() const
  620. {
  621. S32 version = getVersion();
  622. S32 major_version = 0;
  623. if (version == LSL2_VERSION1_END_NUMBER){
  624. major_version = 1;
  625. }
  626. else if (version == LSL2_VERSION_NUMBER)
  627. {
  628. major_version = 2;
  629. }
  630. return major_version;
  631. }
  632. U32 LLScriptExecuteLSL2::getUsedMemory()
  633. {
  634. return getBytecodeSize();
  635. }
  636. LLScriptExecute::LLScriptExecute() :
  637. mReset(FALSE)
  638. {
  639. }
  640. void LLScriptExecute::reset()
  641. {
  642. mReset = FALSE;
  643. }
  644. bool LLScriptExecute::isYieldDue() const
  645. {
  646. if(mReset)
  647. {
  648. return true;
  649. }
  650. if(getSleep() > 0.f)
  651. {
  652. return true;
  653. }
  654. if(isFinished())
  655. {
  656. return true;
  657. }
  658. // State changes can occur within a single time slice,
  659. // but LLScriptData's clean up is required. Yield here
  660. // to allow LLScriptData to perform cleanup and then call
  661. // runQuanta again.
  662. if(isStateChangePending())
  663. {
  664. return true;
  665. }
  666. return false;
  667. }
  668. // Run smallest number of instructions possible:
  669. // a single instruction for LSL2, a segment between save tests for Mono
  670. void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id,
  671. const char **errorstr,
  672. U32& events_processed,
  673. F32 quanta)
  674. {
  675. // is there a fault?
  676. // if yes, print out message and exit
  677. S32 value = getVersion();
  678. S32 major_version = 0;
  679. if (value == LSL2_VERSION1_END_NUMBER)
  680. {
  681. major_version = 1;
  682. }
  683. else if (value == LSL2_VERSION_NUMBER)
  684. {
  685. major_version = 2;
  686. }
  687. else
  688. {
  689. setFault(LSRF_VERSION_MISMATCH);
  690. }
  691. value = getFaults();
  692. if (value > LSRF_INVALID && value < LSRF_EOF)
  693. {
  694. if (b_print)
  695. {
  696. printf("Error!\n");
  697. }
  698. *errorstr = LSCRIPTRunTimeFaultStrings[value];
  699. return;
  700. }
  701. else
  702. {
  703. *errorstr = NULL;
  704. }
  705. if (! isFinished())
  706. {
  707. resumeEventHandler(b_print, id, quanta);
  708. return;
  709. }
  710. else
  711. {
  712. // make sure that IE is zero
  713. setCurrentHandler(0);
  714. // if no, we're in a state and waiting for an event
  715. U64 current_events = getCurrentEvents();
  716. U64 event_register = getEventHandlers();
  717. // check NS to see if need to switch states (NS != CS)
  718. if (isStateChangePending())
  719. {
  720. // ok, blow away any pending events
  721. deleteAllEvents();
  722. // if yes, check state exit flag is set
  723. if (current_events & LSCRIPTStateBitField[LSTT_STATE_EXIT])
  724. {
  725. // if yes, clear state exit flag
  726. setCurrentHandler(LSCRIPTStateBitField[LSTT_STATE_EXIT]);
  727. current_events &= ~LSCRIPTStateBitField[LSTT_STATE_EXIT];
  728. setCurrentEvents(current_events);
  729. // check state exit event handler
  730. // if there is a handler, call it
  731. if (event_register & LSCRIPTStateBitField[LSTT_STATE_EXIT])
  732. {
  733. ++events_processed;
  734. callEventHandler(LSTT_STATE_EXIT, id, quanta);
  735. return;
  736. }
  737. }
  738. // if no handler or no state exit flag switch to new state
  739. // set state entry flag and clear other CE flags
  740. current_events = LSCRIPTStateBitField[LSTT_STATE_ENTRY];
  741. setCurrentEvents(current_events);
  742. U64 handled_events = nextState();
  743. setEventHandlers(handled_events);
  744. }
  745. // try to get next event from stack
  746. BOOL b_done = FALSE;
  747. LSCRIPTStateEventType event = LSTT_NULL;
  748. current_events = getCurrentEvents();
  749. event_register = getEventHandlers();
  750. // first, check to see if state_entry or onrez are raised and handled
  751. if ((current_events & LSCRIPTStateBitField[LSTT_STATE_ENTRY])
  752. &&(current_events & event_register))
  753. {
  754. ++events_processed;
  755. callEventHandler(LSTT_STATE_ENTRY, id, quanta);
  756. b_done = TRUE;
  757. }
  758. else if ((current_events & LSCRIPTStateBitField[LSTT_REZ])
  759. &&(current_events & event_register))
  760. {
  761. ++events_processed;
  762. callQueuedEventHandler(LSTT_REZ, id, quanta);
  763. b_done = TRUE;
  764. }
  765. if (!b_done)
  766. {
  767. // Call handler for next queued event.
  768. if(getEventCount() > 0)
  769. {
  770. ++events_processed;
  771. callNextQueuedEventHandler(event_register, id, quanta);
  772. }
  773. else
  774. {
  775. // if no data waiting, do it the old way:
  776. U64 handled_current = current_events & event_register;
  777. if (handled_current)
  778. {
  779. event = return_first_event((S32)handled_current);
  780. ++events_processed;
  781. callEventHandler(event, id, quanta);
  782. }
  783. }
  784. b_done = TRUE;
  785. }
  786. }
  787. }
  788. // Run for a single timeslice, or until a yield or state transition is due
  789. F32 LLScriptExecute::runQuanta(BOOL b_print, const LLUUID &id, const char **errorstr, F32 quanta, U32& events_processed, LLTimer& timer)
  790. {
  791. S32 timer_checks = 0;
  792. F32 inloop = 0;
  793. // Loop while not finished, yield not due and time remaining
  794. // NOTE: Default implementation does not do adaptive timer skipping
  795. // to preserve current LSL behaviour and not break scripts that rely
  796. // on current execution speed.
  797. while(true)
  798. {
  799. runInstructions(b_print, id, errorstr,
  800. events_processed, quanta);
  801. if(isYieldDue())
  802. {
  803. break;
  804. }
  805. else if(timer_checks++ >= LLScriptExecute::sTimerCheckSkip)
  806. {
  807. inloop = timer.getElapsedTimeF32();
  808. if(inloop > quanta)
  809. {
  810. break;
  811. }
  812. timer_checks = 0;
  813. }
  814. }
  815. if (inloop == 0.0f)
  816. {
  817. inloop = timer.getElapsedTimeF32();
  818. }
  819. return inloop;
  820. }
  821. F32 LLScriptExecute::runNested(BOOL b_print, const LLUUID &id, const char **errorstr, F32 quanta, U32& events_processed, LLTimer& timer)
  822. {
  823. return LLScriptExecute::runQuanta(b_print, id, errorstr, quanta, events_processed, timer);
  824. }
  825. BOOL run_noop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  826. {
  827. if (b_print)
  828. printf("[0x%X]\tNOOP\n", offset);
  829. offset++;
  830. return FALSE;
  831. }
  832. BOOL run_pop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  833. {
  834. if (b_print)
  835. printf("[0x%X]\tPOP\n", offset);
  836. offset++;
  837. lscript_poparg(buffer, LSCRIPTDataSize[LST_INTEGER]);
  838. return FALSE;
  839. }
  840. BOOL run_pops(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  841. {
  842. if (b_print)
  843. printf("[0x%X]\tPOPS\n", offset);
  844. offset++;
  845. S32 address = lscript_pop_int(buffer);
  846. if (address)
  847. lsa_decrease_ref_count(buffer, address);
  848. return FALSE;
  849. }
  850. BOOL run_popl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  851. {
  852. if (b_print)
  853. printf("[0x%X]\tPOPL\n", offset);
  854. offset++;
  855. S32 address = lscript_pop_int(buffer);
  856. if (address)
  857. lsa_decrease_ref_count(buffer, address);
  858. return FALSE;
  859. }
  860. BOOL run_popv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  861. {
  862. if (b_print)
  863. printf("[0x%X]\tPOPV\n", offset);
  864. offset++;
  865. lscript_poparg(buffer, LSCRIPTDataSize[LST_VECTOR]);
  866. return FALSE;
  867. }
  868. BOOL run_popq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  869. {
  870. if (b_print)
  871. printf("[0x%X]\tPOPQ\n", offset);
  872. offset++;
  873. lscript_poparg(buffer, LSCRIPTDataSize[LST_QUATERNION]);
  874. return FALSE;
  875. }
  876. BOOL run_poparg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  877. {
  878. if (b_print)
  879. printf("[0x%X]\tPOPARG ", offset);
  880. offset++;
  881. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  882. if (b_print)
  883. printf("%d\n", arg);
  884. lscript_poparg(buffer, arg);
  885. return FALSE;
  886. }
  887. BOOL run_popip(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  888. {
  889. if (b_print)
  890. printf("[0x%X]\tPOPIP\n", offset);
  891. offset++;
  892. offset = lscript_pop_int(buffer);
  893. return FALSE;
  894. }
  895. BOOL run_popbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  896. {
  897. if (b_print)
  898. printf("[0x%X]\tPOPBP\n", offset);
  899. offset++;
  900. S32 bp = lscript_pop_int(buffer);
  901. set_bp(buffer, bp);
  902. return FALSE;
  903. }
  904. BOOL run_popsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  905. {
  906. if (b_print)
  907. printf("[0x%X]\tPOPSP\n", offset);
  908. offset++;
  909. S32 sp = lscript_pop_int(buffer);
  910. set_sp(buffer, sp);
  911. return FALSE;
  912. }
  913. BOOL run_popslr(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  914. {
  915. if (b_print)
  916. printf("[0x%X]\tPOPSLR\n", offset);
  917. offset++;
  918. S32 slr = lscript_pop_int(buffer);
  919. set_register(buffer, LREG_SLR, slr);
  920. return FALSE;
  921. }
  922. BOOL run_dup(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  923. {
  924. if (b_print)
  925. printf("[0x%X]\tDUP\n", offset);
  926. offset++;
  927. S32 sp = get_register(buffer, LREG_SP);
  928. S32 value = bytestream2integer(buffer, sp);
  929. lscript_push(buffer, value);
  930. return FALSE;
  931. }
  932. BOOL run_dups(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  933. {
  934. if (b_print)
  935. printf("[0x%X]\tDUPS\n", offset);
  936. offset++;
  937. S32 sp = get_register(buffer, LREG_SP);
  938. S32 value = bytestream2integer(buffer, sp);
  939. lscript_push(buffer, value);
  940. lsa_increase_ref_count(buffer, value);
  941. return FALSE;
  942. }
  943. BOOL run_dupl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  944. {
  945. if (b_print)
  946. printf("[0x%X]\tDUPL\n", offset);
  947. offset++;
  948. S32 sp = get_register(buffer, LREG_SP);
  949. S32 value = bytestream2integer(buffer, sp);
  950. lscript_push(buffer, value);
  951. lsa_increase_ref_count(buffer, value);
  952. return FALSE;
  953. }
  954. BOOL run_dupv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  955. {
  956. if (b_print)
  957. printf("[0x%X]\tDUPV\n", offset);
  958. offset++;
  959. S32 sp = get_register(buffer, LREG_SP);
  960. LLVector3 value;
  961. bytestream2vector(value, buffer, sp);
  962. lscript_push(buffer, value);
  963. return FALSE;
  964. }
  965. BOOL run_dupq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  966. {
  967. if (b_print)
  968. printf("[0x%X]\tDUPV\n", offset);
  969. offset++;
  970. S32 sp = get_register(buffer, LREG_SP);
  971. LLQuaternion value;
  972. bytestream2quaternion(value, buffer, sp);
  973. lscript_push(buffer, value);
  974. return FALSE;
  975. }
  976. BOOL run_store(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  977. {
  978. if (b_print)
  979. printf("[0x%X]\tSTORE ", offset);
  980. offset++;
  981. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  982. if (b_print)
  983. printf("0x%X\n", arg);
  984. S32 sp = get_register(buffer, LREG_SP);
  985. S32 value = bytestream2integer(buffer, sp);
  986. lscript_local_store(buffer, arg, value);
  987. return FALSE;
  988. }
  989. BOOL run_stores(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  990. {
  991. if (b_print)
  992. printf("[0x%X]\tSTORES ", offset);
  993. offset++;
  994. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  995. if (b_print)
  996. printf("0x%X\n", arg);
  997. S32 sp = get_register(buffer, LREG_SP);
  998. S32 value = bytestream2integer(buffer, sp);
  999. S32 address = lscript_local_get(buffer, arg);
  1000. lscript_local_store(buffer, arg, value);
  1001. lsa_increase_ref_count(buffer, value);
  1002. if (address)
  1003. lsa_decrease_ref_count(buffer, address);
  1004. return FALSE;
  1005. }
  1006. BOOL run_storel(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1007. {
  1008. if (b_print)
  1009. printf("[0x%X]\tSTOREL ", offset);
  1010. offset++;
  1011. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1012. if (b_print)
  1013. printf("0x%X\n", arg);
  1014. S32 sp = get_register(buffer, LREG_SP);
  1015. S32 value = bytestream2integer(buffer, sp);
  1016. S32 address = lscript_local_get(buffer, arg);
  1017. lscript_local_store(buffer, arg, value);
  1018. lsa_increase_ref_count(buffer, value);
  1019. if (address)
  1020. lsa_decrease_ref_count(buffer, address);
  1021. return FALSE;
  1022. }
  1023. BOOL run_storev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1024. {
  1025. if (b_print)
  1026. printf("[0x%X]\tSTOREV ", offset);
  1027. offset++;
  1028. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1029. if (b_print)
  1030. printf("0x%X\n", arg);
  1031. LLVector3 value;
  1032. S32 sp = get_register(buffer, LREG_SP);
  1033. bytestream2vector(value, buffer, sp);
  1034. lscript_local_store(buffer, arg, value);
  1035. return FALSE;
  1036. }
  1037. BOOL run_storeq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1038. {
  1039. if (b_print)
  1040. printf("[0x%X]\tSTOREQ ", offset);
  1041. offset++;
  1042. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1043. if (b_print)
  1044. printf("0x%X\n", arg);
  1045. LLQuaternion value;
  1046. S32 sp = get_register(buffer, LREG_SP);
  1047. bytestream2quaternion(value, buffer, sp);
  1048. lscript_local_store(buffer, arg, value);
  1049. return FALSE;
  1050. }
  1051. BOOL run_storeg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1052. {
  1053. if (b_print)
  1054. printf("[0x%X]\tSTOREG ", offset);
  1055. offset++;
  1056. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1057. if (b_print)
  1058. printf("0x%X\n", arg);
  1059. S32 sp = get_register(buffer, LREG_SP);
  1060. S32 value = bytestream2integer(buffer, sp);
  1061. lscript_global_store(buffer, arg, value);
  1062. return FALSE;
  1063. }
  1064. BOOL run_storegs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1065. {
  1066. if (b_print)
  1067. printf("[0x%X]\tSTOREGS ", offset);
  1068. offset++;
  1069. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1070. if (b_print)
  1071. printf("0x%X\n", arg);
  1072. S32 sp = get_register(buffer, LREG_SP);
  1073. S32 value = bytestream2integer(buffer, sp);
  1074. S32 address = lscript_global_get(buffer, arg);
  1075. lscript_global_store(buffer, arg, value);
  1076. lsa_increase_ref_count(buffer, value);
  1077. if (address)
  1078. lsa_decrease_ref_count(buffer, address);
  1079. return FALSE;
  1080. }
  1081. BOOL run_storegl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1082. {
  1083. if (b_print)
  1084. printf("[0x%X]\tSTOREGL ", offset);
  1085. offset++;
  1086. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1087. if (b_print)
  1088. printf("0x%X\n", arg);
  1089. S32 sp = get_register(buffer, LREG_SP);
  1090. S32 value = bytestream2integer(buffer, sp);
  1091. S32 address = lscript_global_get(buffer, arg);
  1092. lscript_global_store(buffer, arg, value);
  1093. lsa_increase_ref_count(buffer, value);
  1094. if (address)
  1095. lsa_decrease_ref_count(buffer, address);
  1096. return FALSE;
  1097. }
  1098. BOOL run_storegv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1099. {
  1100. if (b_print)
  1101. printf("[0x%X]\tSTOREGV ", offset);
  1102. offset++;
  1103. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1104. if (b_print)
  1105. printf("0x%X\n", arg);
  1106. LLVector3 value;
  1107. S32 sp = get_register(buffer, LREG_SP);
  1108. bytestream2vector(value, buffer, sp);
  1109. lscript_global_store(buffer, arg, value);
  1110. return FALSE;
  1111. }
  1112. BOOL run_storegq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1113. {
  1114. if (b_print)
  1115. printf("[0x%X]\tSTOREGQ ", offset);
  1116. offset++;
  1117. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1118. if (b_print)
  1119. printf("0x%X\n", arg);
  1120. LLQuaternion value;
  1121. S32 sp = get_register(buffer, LREG_SP);
  1122. bytestream2quaternion(value, buffer, sp);
  1123. lscript_global_store(buffer, arg, value);
  1124. return FALSE;
  1125. }
  1126. BOOL run_loadp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1127. {
  1128. if (b_print)
  1129. printf("[0x%X]\tSTOREP ", offset);
  1130. offset++;
  1131. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1132. if (b_print)
  1133. printf("0x%X\n", arg);
  1134. S32 value = lscript_pop_int(buffer);
  1135. lscript_local_store(buffer, arg, value);
  1136. return FALSE;
  1137. }
  1138. BOOL run_loadsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1139. {
  1140. if (b_print)
  1141. printf("[0x%X]\tSTORESP ", offset);
  1142. offset++;
  1143. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1144. if (b_print)
  1145. printf("0x%X\n", arg);
  1146. S32 value = lscript_pop_int(buffer);
  1147. S32 address = lscript_local_get(buffer, arg);
  1148. if (address)
  1149. lsa_decrease_ref_count(buffer, address);
  1150. lscript_local_store(buffer, arg, value);
  1151. return FALSE;
  1152. }
  1153. BOOL run_loadlp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1154. {
  1155. if (b_print)
  1156. printf("[0x%X]\tSTORELP ", offset);
  1157. offset++;
  1158. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1159. if (b_print)
  1160. printf("0x%X\n", arg);
  1161. S32 value = lscript_pop_int(buffer);
  1162. S32 address = lscript_local_get(buffer, arg);
  1163. if (address)
  1164. lsa_decrease_ref_count(buffer, address);
  1165. lscript_local_store(buffer, arg, value);
  1166. return FALSE;
  1167. }
  1168. BOOL run_loadvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1169. {
  1170. if (b_print)
  1171. printf("[0x%X]\tSTOREVP ", offset);
  1172. offset++;
  1173. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1174. if (b_print)
  1175. printf("0x%X\n", arg);
  1176. LLVector3 value;
  1177. lscript_pop_vector(buffer, value);
  1178. lscript_local_store(buffer, arg, value);
  1179. return FALSE;
  1180. }
  1181. BOOL run_loadqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1182. {
  1183. if (b_print)
  1184. printf("[0x%X]\tSTOREQP ", offset);
  1185. offset++;
  1186. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1187. if (b_print)
  1188. printf("0x%X\n", arg);
  1189. LLQuaternion value;
  1190. lscript_pop_quaternion(buffer, value);
  1191. lscript_local_store(buffer, arg, value);
  1192. return FALSE;
  1193. }
  1194. BOOL run_loadgp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1195. {
  1196. if (b_print)
  1197. printf("[0x%X]\tSTOREGP ", offset);
  1198. offset++;
  1199. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1200. if (b_print)
  1201. printf("0x%X\n", arg);
  1202. S32 value = lscript_pop_int(buffer);
  1203. lscript_global_store(buffer, arg, value);
  1204. return FALSE;
  1205. }
  1206. BOOL run_loadgsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1207. {
  1208. if (b_print)
  1209. printf("[0x%X]\tSTOREGSP ", offset);
  1210. offset++;
  1211. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1212. if (b_print)
  1213. printf("%d\n", arg);
  1214. S32 value = lscript_pop_int(buffer);
  1215. S32 address = lscript_global_get(buffer, arg);
  1216. if (address)
  1217. lsa_decrease_ref_count(buffer, address);
  1218. lscript_global_store(buffer, arg, value);
  1219. return FALSE;
  1220. }
  1221. BOOL run_loadglp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1222. {
  1223. if (b_print)
  1224. printf("[0x%X]\tSTOREGLP ", offset);
  1225. offset++;
  1226. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1227. if (b_print)
  1228. printf("0x%X\n", arg);
  1229. S32 value = lscript_pop_int(buffer);
  1230. S32 address = lscript_global_get(buffer, arg);
  1231. if (address)
  1232. lsa_decrease_ref_count(buffer, address);
  1233. lscript_global_store(buffer, arg, value);
  1234. return FALSE;
  1235. }
  1236. BOOL run_loadgvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1237. {
  1238. if (b_print)
  1239. printf("[0x%X]\tSTOREGVP ", offset);
  1240. offset++;
  1241. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1242. if (b_print)
  1243. printf("0x%X\n", arg);
  1244. LLVector3 value;
  1245. lscript_pop_vector(buffer, value);
  1246. lscript_global_store(buffer, arg, value);
  1247. return FALSE;
  1248. }
  1249. BOOL run_loadgqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1250. {
  1251. if (b_print)
  1252. printf("[0x%X]\tSTOREGQP ", offset);
  1253. offset++;
  1254. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1255. if (b_print)
  1256. printf("0x%X\n", arg);
  1257. LLQuaternion value;
  1258. lscript_pop_quaternion(buffer, value);
  1259. lscript_global_store(buffer, arg, value);
  1260. return FALSE;
  1261. }
  1262. BOOL run_push(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1263. {
  1264. if (b_print)
  1265. printf("[0x%X]\tPUSH ", offset);
  1266. offset++;
  1267. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1268. if (b_print)
  1269. printf("0x%X\n", arg);
  1270. S32 value = lscript_local_get(buffer, arg);
  1271. lscript_push(buffer, value);
  1272. return FALSE;
  1273. }
  1274. BOOL run_pushs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1275. {
  1276. if (b_print)
  1277. printf("[0x%X]\tPUSHS ", offset);
  1278. offset++;
  1279. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1280. if (b_print)
  1281. printf("0x%X\n", arg);
  1282. S32 value = lscript_local_get(buffer, arg);
  1283. lscript_push(buffer, value);
  1284. lsa_increase_ref_count(buffer, value);
  1285. return FALSE;
  1286. }
  1287. BOOL run_pushl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1288. {
  1289. if (b_print)
  1290. printf("[0x%X]\tPUSHL ", offset);
  1291. offset++;
  1292. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1293. if (b_print)
  1294. printf("0x%X\n", arg);
  1295. S32 value = lscript_local_get(buffer, arg);
  1296. lscript_push(buffer, value);
  1297. lsa_increase_ref_count(buffer, value);
  1298. return FALSE;
  1299. }
  1300. BOOL run_pushv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1301. {
  1302. if (b_print)
  1303. printf("[0x%X]\tPUSHV ", offset);
  1304. offset++;
  1305. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1306. if (b_print)
  1307. printf("0x%X\n", arg);
  1308. LLVector3 value;
  1309. lscript_local_get(buffer, arg, value);
  1310. lscript_push(buffer, value);
  1311. return FALSE;
  1312. }
  1313. BOOL run_pushq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1314. {
  1315. if (b_print)
  1316. printf("[0x%X]\tPUSHQ ", offset);
  1317. offset++;
  1318. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1319. if (b_print)
  1320. printf("0x%X\n", arg);
  1321. LLQuaternion value;
  1322. lscript_local_get(buffer, arg, value);
  1323. lscript_push(buffer, value);
  1324. return FALSE;
  1325. }
  1326. BOOL run_pushg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1327. {
  1328. if (b_print)
  1329. printf("[0x%X]\tPUSHG ", offset);
  1330. offset++;
  1331. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1332. if (b_print)
  1333. printf("0x%X\n", arg);
  1334. S32 value = lscript_global_get(buffer, arg);
  1335. lscript_push(buffer, value);
  1336. return FALSE;
  1337. }
  1338. BOOL run_pushgs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1339. {
  1340. if (b_print)
  1341. printf("[0x%X]\tPUSHGS ", offset);
  1342. offset++;
  1343. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1344. if (b_print)
  1345. printf("0x%X\n", arg);
  1346. S32 value = lscript_global_get(buffer, arg);
  1347. lscript_push(buffer, value);
  1348. lsa_increase_ref_count(buffer, value);
  1349. return FALSE;
  1350. }
  1351. BOOL run_pushgl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1352. {
  1353. if (b_print)
  1354. printf("[0x%X]\tPUSHGL ", offset);
  1355. offset++;
  1356. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1357. if (b_print)
  1358. printf("0x%X\n", arg);
  1359. S32 value = lscript_global_get(buffer, arg);
  1360. lscript_push(buffer, value);
  1361. lsa_increase_ref_count(buffer, value);
  1362. return FALSE;
  1363. }
  1364. BOOL run_pushgv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1365. {
  1366. if (b_print)
  1367. printf("[0x%X]\tPUSHGV ", offset);
  1368. offset++;
  1369. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1370. if (b_print)
  1371. printf("0x%X\n", arg);
  1372. LLVector3 value;
  1373. lscript_global_get(buffer, arg, value);
  1374. lscript_push(buffer, value);
  1375. return FALSE;
  1376. }
  1377. BOOL run_pushgq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1378. {
  1379. if (b_print)
  1380. printf("[0x%X]\tPUSHGQ ", offset);
  1381. offset++;
  1382. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1383. if (b_print)
  1384. printf("0x%X\n", arg);
  1385. LLQuaternion value;
  1386. lscript_global_get(buffer, arg, value);
  1387. lscript_push(buffer, value);
  1388. return FALSE;
  1389. }
  1390. BOOL run_puship(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1391. {
  1392. if (b_print)
  1393. printf("[0x%X]\tPUSHIP\n", offset);
  1394. offset++;
  1395. lscript_push(buffer, offset);
  1396. return FALSE;
  1397. }
  1398. BOOL run_pushbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1399. {
  1400. if (b_print)
  1401. printf("[0x%X]\tPUSHBP\n", offset);
  1402. offset++;
  1403. lscript_push(buffer, get_register(buffer, LREG_BP));
  1404. return FALSE;
  1405. }
  1406. BOOL run_pushsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1407. {
  1408. if (b_print)
  1409. printf("[0x%X]\tPUSHSP\n", offset);
  1410. offset++;
  1411. lscript_push(buffer, get_register(buffer, LREG_SP));
  1412. return FALSE;
  1413. }
  1414. BOOL run_pushargb(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1415. {
  1416. if (b_print)
  1417. printf("[0x%X]\tPUSHGARGB ", offset);
  1418. offset++;
  1419. U8 arg = safe_instruction_bytestream2byte(buffer, offset);
  1420. if (b_print)
  1421. printf("%d\n", (U32)arg);
  1422. lscript_push(buffer, arg);
  1423. return FALSE;
  1424. }
  1425. BOOL run_pushargi(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1426. {
  1427. if (b_print)
  1428. printf("[0x%X]\tPUSHARGI ", offset);
  1429. offset++;
  1430. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1431. if (b_print)
  1432. printf("%d\n", arg);
  1433. lscript_push(buffer, arg);
  1434. return FALSE;
  1435. }
  1436. BOOL run_pushargf(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1437. {
  1438. if (b_print)
  1439. printf("[0x%X]\tPUSHARGF ", offset);
  1440. offset++;
  1441. F32 arg = safe_instruction_bytestream2float(buffer, offset);
  1442. if (b_print)
  1443. printf("%f\n", arg);
  1444. lscript_push(buffer, arg);
  1445. return FALSE;
  1446. }
  1447. BOOL run_pushargs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1448. {
  1449. if (b_print)
  1450. printf("[0x%X]\tPUSHARGS ", offset);
  1451. S32 toffset = offset;
  1452. safe_instruction_bytestream_count_char(buffer, toffset);
  1453. S32 size = toffset - offset;
  1454. char *arg = new char[size];
  1455. offset++;
  1456. safe_instruction_bytestream2char(arg, buffer, offset, size);
  1457. if (b_print)
  1458. printf("%s\n", arg);
  1459. S32 address = lsa_heap_add_data(buffer, new LLScriptLibData(arg), get_max_heap_size(buffer), TRUE);
  1460. lscript_push(buffer, address);
  1461. delete [] arg;
  1462. return FALSE;
  1463. }
  1464. BOOL run_pushargv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1465. {
  1466. if (b_print)
  1467. printf("[0x%X]\tPUSHARGV ", offset);
  1468. offset++;
  1469. LLVector3 arg;
  1470. safe_instruction_bytestream2vector(arg, buffer, offset);
  1471. if (b_print)
  1472. printf("< %f, %f, %f >\n", arg.mV[VX], arg.mV[VY], arg.mV[VZ]);
  1473. lscript_push(buffer, arg);
  1474. return FALSE;
  1475. }
  1476. BOOL run_pushargq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1477. {
  1478. if (b_print)
  1479. printf("[0x%X]\tPUSHARGQ ", offset);
  1480. offset++;
  1481. LLQuaternion arg;
  1482. safe_instruction_bytestream2quaternion(arg, buffer, offset);
  1483. if (b_print)
  1484. printf("< %f, %f, %f, %f >\n", arg.mQ[VX], arg.mQ[VY], arg.mQ[VZ], arg.mQ[VS]);
  1485. lscript_push(buffer, arg);
  1486. return FALSE;
  1487. }
  1488. BOOL run_pushe(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1489. {
  1490. if (b_print)
  1491. printf("[0x%X]\tPUSHE\n", offset);
  1492. offset++;
  1493. lscript_pusharge(buffer, LSCRIPTDataSize[LST_INTEGER]);
  1494. return FALSE;
  1495. }
  1496. BOOL run_pushev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1497. {
  1498. if (b_print)
  1499. printf("[0x%X]\tPUSHEV\n", offset);
  1500. offset++;
  1501. lscript_pusharge(buffer, LSCRIPTDataSize[LST_VECTOR]);
  1502. return FALSE;
  1503. }
  1504. BOOL run_pusheq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1505. {
  1506. if (b_print)
  1507. printf("[0x%X]\tPUSHEQ\n", offset);
  1508. offset++;
  1509. lscript_pusharge(buffer, LSCRIPTDataSize[LST_QUATERNION]);
  1510. return FALSE;
  1511. }
  1512. BOOL run_pusharge(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id)
  1513. {
  1514. if (b_print)
  1515. printf("[0x%X]\tPUSHARGE ", offset);
  1516. offset++;
  1517. S32 arg = safe_instruction_bytestream2integer(buffer, offset);
  1518. if (b_print)
  1519. printf("%d\n", arg);
  1520. lscript_pusharge(buffer, arg);
  1521. return FALSE;
  1522. }
  1523. void print_type(U8 type)
  1524. {
  1525. if (type == LSCRIPTTypeByte[LST_INTEGER])
  1526. {
  1527. printf("integer");
  1528. }
  1529. else if (type == LSCRIPTTypeByte[LST_FLOATINGPOINT])
  1530. {
  1531. printf("float");
  1532. }
  1533. else if (type == LSCRIPTTypeByte[LST_STRING])
  1534. {
  1535. printf("string");
  1536. }
  1537. else if (type == LSCRIPTTypeByte[LST_KEY])
  1538. {
  1539. printf("key");
  1540. }
  1541. else if (type == LSCRIPTTypeByte[LST_VECTOR])
  1542. {
  1543. printf("vector");
  1544. }
  1545. else if (type == LSCRIPTTypeByte[LST_QUATERNION])
  1546. {
  1547. printf("quaternion");
  1548. }
  1549. else if (type == LSCRIPTTypeByte[LST_LIST])
  1550. {
  1551. printf("list");
  1552. }
  1553. }
  1554. void unknown_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode)
  1555. {
  1556. printf("Unknown arithmetic operation!\n");
  1557. }
  1558. void integer_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode)
  1559. {
  1560. S32 lside = lscript_pop_int(buffer);
  1561. S32 rside = lscript_pop_int(buffer);
  1562. S32 result = 0;
  1563. switch(opcode)
  1564. {
  1565. case LOPC_ADD:
  1566. result = lside + rside;
  1567. break;
  1568. case LOPC_SUB:
  1569. result = lside - rside;
  1570. break;
  1571. case LOPC_MUL:
  1572. result = lside * rside;
  1573. break;
  1574. case LOPC_DIV:
  1575. if (rside){
  1576. if( ( rside == -1 ) || ( rside == (S

Large files files are truncated, but you can click here to view the full file