lscript_byteformat.h
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:13k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file lscript_byteformat.h
  3.  * @brief Shared code between compiler and assembler and LSL
  4.  *
  5.  * $LicenseInfo:firstyear=2002&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2002-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #ifndef LL_LSCRIPT_BYTEFORMAT_H
  33. #define LL_LSCRIPT_BYTEFORMAT_H
  34. // Data shared between compiler/assembler and lscript execution code
  35. #include "stdtypes.h"
  36. const S32 LSL2_VERSION_NUMBER = 0x0200;
  37. const S32 LSL2_VERSION1_END_NUMBER = 0x0101;
  38. const S32 LSL2_VERSION2_START_NUMBER = 0x0200;
  39. const S32 LSL2_MAJOR_VERSION_ONE = 1;
  40. const S32 LSL2_MAJOR_VERSION_TWO = 2;
  41. const S32 LSL2_CURRENT_MAJOR_VERSION = LSL2_MAJOR_VERSION_TWO;
  42. const S32 TOP_OF_MEMORY = 16384;
  43. typedef enum e_lscript_registers
  44. {
  45. LREG_INVALID,
  46. LREG_IP, // instruction pointer
  47. LREG_VN, // version number
  48. LREG_BP, // base pointer - what local variables are referenced from
  49. LREG_SP, // stack pointer - where the top of the stack is
  50. LREG_HR, // heap register - where in memory does the heap start
  51. LREG_HP, // heap pointer - where is the top of the heap?
  52. LREG_CS, // current state - what state are we currently in?
  53. LREG_NS, // next state - what state are we currently in?
  54. LREG_CE, // current events - what events are waiting to be handled?
  55. LREG_IE, // in event - which event handler are we currently in?
  56. LREG_ER, // event register - what events do we have active handlers for?
  57. LREG_FR, // fault register - which errors are currently active?
  58. LREG_SLR, // sleep register - are we sleeping?
  59. LREG_GVR, // global variable register - where do global variables start
  60. LREG_GFR, // global function register - where do global functions start
  61. LREG_SR, // state register - where do states start
  62. LREG_TM, // top of memory - where is the top of memory
  63. LREG_PR, // parameter register - data passed to script from launcher
  64. LREG_ESR, // energy supply register - how much energy do we have on board?
  65. LREG_NCE, // 64 bit current envents - what events are waiting to be handled?
  66. LREG_NIE, // 64 bit in event - which event handler are we currently in?
  67. LREG_NER, // 64 bit event register - what events do we have active handlers for?
  68. LREG_EOF
  69. } LSCRIPTRegisters;
  70. const S32 gLSCRIPTRegisterAddresses[LREG_EOF] = /* Flawfinder: ignore */
  71. {
  72. 0, // LREG_INVALID
  73. 4, // LREG_IP
  74. 8, // LREG_VN
  75. 12, // LREG_BP
  76. 16, // LREG_SP
  77. 20, // LREG_HR
  78. 24, // LREG_HP
  79. 28, // LREG_CS
  80. 32, // LREG_NS
  81. 36, // LREG_CE
  82. 40, // LREG_IE
  83. 44, // LREG_ER
  84. 48, // LREG_FR
  85. 52, // LREG_SLR
  86. 56, // LREG_GVR
  87. 60, // LREG_GFR
  88. 72, // LREG_SR
  89. 0, // LREG_TM
  90. 64, // LREG_PR
  91. 68, // LREG_ESR
  92. 76, // LREG_NCE
  93. 84, // LREG_NIE
  94. 92, // LREG_NER
  95. };
  96. const char * const gLSCRIPTRegisterNames[LREG_EOF] =
  97. {
  98. "INVALID", // LREG_INVALID
  99. "IP", // LREG_IP
  100. "VN", // LREG_VN
  101. "BP", // LREG_BP
  102. "SP", // LREG_SP
  103. "HR", // LREG_HR
  104. "HP", // LREG_HP
  105. "CS", // LREG_CS
  106. "NS", // LREG_NS
  107. "CE", // LREG_CE
  108. "IE", // LREG_IE
  109. "ER", // LREG_ER
  110. "FR", // LREG_FR
  111. "SLR", // LREG_SLR
  112. "GVR", // LREG_GVR
  113. "GFR", // LREG_GFR
  114. "SR", // LREG_SR
  115. "TM", // LREG_TM
  116. "PR", // LREG_PR
  117. "ESR", // LREG_ESR
  118. "NCE", // LREG_NCE
  119. "NIE", // LREG_NIE
  120. "NER", // LREG_NER
  121. };
  122. typedef enum e_lscript_op_codes
  123. {
  124. LOPC_INVALID,
  125. LOPC_NOOP,
  126. LOPC_POP,
  127. LOPC_POPS,
  128. LOPC_POPL,
  129. LOPC_POPV,
  130. LOPC_POPQ,
  131. LOPC_POPARG,
  132. LOPC_POPIP,
  133. LOPC_POPBP,
  134. LOPC_POPSP,
  135. LOPC_POPSLR,
  136. LOPC_DUP,
  137. LOPC_DUPS,
  138. LOPC_DUPL,
  139. LOPC_DUPV,
  140. LOPC_DUPQ,
  141. LOPC_STORE,
  142. LOPC_STORES,
  143. LOPC_STOREL,
  144. LOPC_STOREV,
  145. LOPC_STOREQ,
  146. LOPC_STOREG,
  147. LOPC_STOREGS,
  148. LOPC_STOREGL,
  149. LOPC_STOREGV,
  150. LOPC_STOREGQ,
  151. LOPC_LOADP,
  152. LOPC_LOADSP,
  153. LOPC_LOADLP,
  154. LOPC_LOADVP,
  155. LOPC_LOADQP,
  156. LOPC_LOADGP,
  157. LOPC_LOADGLP,
  158. LOPC_LOADGSP,
  159. LOPC_LOADGVP,
  160. LOPC_LOADGQP,
  161. LOPC_PUSH,
  162. LOPC_PUSHS,
  163. LOPC_PUSHL,
  164. LOPC_PUSHV,
  165. LOPC_PUSHQ,
  166. LOPC_PUSHG,
  167. LOPC_PUSHGS,
  168. LOPC_PUSHGL,
  169. LOPC_PUSHGV,
  170. LOPC_PUSHGQ,
  171. LOPC_PUSHIP,
  172. LOPC_PUSHBP,
  173. LOPC_PUSHSP,
  174. LOPC_PUSHARGB,
  175. LOPC_PUSHARGI,
  176. LOPC_PUSHARGF,
  177. LOPC_PUSHARGS,
  178. LOPC_PUSHARGV,
  179. LOPC_PUSHARGQ,
  180. LOPC_PUSHE,
  181. LOPC_PUSHEV,
  182. LOPC_PUSHEQ,
  183. LOPC_PUSHARGE,
  184. LOPC_ADD,
  185. LOPC_SUB,
  186. LOPC_MUL,
  187. LOPC_DIV,
  188. LOPC_MOD,
  189. LOPC_EQ,
  190. LOPC_NEQ,
  191. LOPC_LEQ,
  192. LOPC_GEQ,
  193. LOPC_LESS,
  194. LOPC_GREATER,
  195. LOPC_BITAND,
  196. LOPC_BITOR,
  197. LOPC_BITXOR,
  198. LOPC_BOOLAND,
  199. LOPC_BOOLOR,
  200. LOPC_NEG,
  201. LOPC_BITNOT,
  202. LOPC_BOOLNOT,
  203. LOPC_JUMP,
  204. LOPC_JUMPIF,
  205. LOPC_JUMPNIF,
  206. LOPC_STATE,
  207. LOPC_CALL,
  208. LOPC_RETURN,
  209. LOPC_CAST,
  210. LOPC_STACKTOS,
  211. LOPC_STACKTOL,
  212. LOPC_PRINT,
  213. LOPC_CALLLIB,
  214. LOPC_CALLLIB_TWO_BYTE,
  215. LOPC_SHL,
  216. LOPC_SHR,
  217. LOPC_EOF
  218. } LSCRIPTOpCodesEnum;
  219. const U8 LSCRIPTOpCodes[LOPC_EOF] =
  220. {
  221. 0x00, // LOPC_INVALID
  222. 0x00, // LOPC_NOOP
  223. 0x01, // LOPC_POP
  224. 0x02, // LOPC_POPS
  225. 0x03, // LOPC_POPL
  226. 0x04, // LOPC_POPV
  227. 0x05, // LOPC_POPQ
  228. 0x06, // LOPC_POPARG
  229. 0x07, // LOPC_POPIP
  230. 0x08, // LOPC_POPBP
  231. 0x09, // LOPC_POPSP
  232. 0x0a, // LOPC_POPSLR
  233. 0x20, // LOPC_DUP
  234. 0x21, // LOPC_DUPS
  235. 0x22, // LOPC_DUPL
  236. 0x23, // LOPC_DUPV
  237. 0x24, // LOPC_DUPQ
  238. 0x30, // LOPC_STORE
  239. 0x31, // LOPC_STORES
  240. 0x32, // LOPC_STOREL
  241. 0x33, // LOPC_STOREV
  242. 0x34, // LOPC_STOREQ
  243. 0x35, // LOPC_STOREG
  244. 0x36, // LOPC_STOREGS
  245. 0x37, // LOPC_STOREGL
  246. 0x38, // LOPC_STOREGV
  247. 0x39, // LOPC_STOREGQ
  248. 0x3a, // LOPC_LOADP
  249. 0x3b, // LOPC_LOADSP
  250. 0x3c, // LOPC_LOADLP
  251. 0x3d, // LOPC_LOADVP
  252. 0x3e, // LOPC_LOADQP
  253. 0x3f, // LOPC_LOADGP
  254. 0x40, // LOPC_LOADGSP
  255. 0x41, // LOPC_LOADGLP
  256. 0x42, // LOPC_LOADGVP
  257. 0x43, // LOPC_LOADGQP
  258. 0x50, // LOPC_PUSH
  259. 0x51, // LOPC_PUSHS
  260. 0x52, // LOPC_PUSHL
  261. 0x53, // LOPC_PUSHV
  262. 0x54, // LOPC_PUSHQ
  263. 0x55, // LOPC_PUSHG
  264. 0x56, // LOPC_PUSHGS
  265. 0x57, // LOPC_PUSHGL
  266. 0x58, // LOPC_PUSHGV
  267. 0x59, // LOPC_PUSHGQ
  268. 0x5a, // LOPC_PUSHIP
  269. 0x5b, // LOPC_PUSHBP
  270. 0x5c, // LOPC_PUSHSP
  271. 0x5d, // LOPC_PUSHARGB
  272. 0x5e, // LOPC_PUSHARGI
  273. 0x5f, // LOPC_PUSHARGF
  274. 0x60, // LOPC_PUSHARGS
  275. 0x61, // LOPC_PUSHARGV
  276. 0x62, // LOPC_PUSHARGQ
  277. 0x63, // LOPC_PUSHE
  278. 0x64, // LOPC_PUSHEV
  279. 0x65, // LOPC_PUSHEQ
  280. 0x66, // LOPC_PUSHARGE
  281. 0x70, // LOPC_ADD
  282. 0x71, // LOPC_SUB
  283. 0x72, // LOPC_MUL
  284. 0x73, // LOPC_DIV
  285. 0x74, // LOPC_MOD
  286. 0x75, // LOPC_EQ
  287. 0x76, // LOPC_NEQ
  288. 0x77, // LOPC_LEQ
  289. 0x78, // LOPC_GEQ
  290. 0x79, // LOPC_LESS
  291. 0x7a, // LOPC_GREATER
  292. 0x7b, // LOPC_BITAND
  293. 0x7c, // LOPC_BITOR
  294. 0x7d, // LOPC_BITXOR
  295. 0x7e, // LOPC_BOOLAND
  296. 0x7f, // LOPC_BOOLOR
  297. 0x80, // LOPC_NEG
  298. 0x81, // LOPC_BITNOT
  299. 0x82, // LOPC_BOOLNOT
  300. 0x90, // LOPC_JUMP
  301. 0x91, // LOPC_JUMPIF
  302. 0x92, // LOPC_JUMPNIF
  303. 0x93, // LOPC_STATE
  304. 0x94, // LOPC_CALL
  305. 0x95, // LOPC_RETURN
  306. 0xa0, // LOPC_CAST
  307. 0xb0, // LOPC_STACKTOS
  308. 0xb1, // LOPC_STACKTOL
  309. 0xc0, // LOPC_PRINT
  310. 0xd0, // LOPC_CALLLIB
  311. 0xd1, // LOPC_CALLLIB_TWO_BYTE
  312. 0xe0, // LOPC_SHL
  313. 0xe1 // LOPC_SHR
  314. };
  315. typedef enum e_lscript_state_event_type
  316. {
  317. LSTT_NULL,
  318. LSTT_STATE_ENTRY,
  319. LSTT_STATE_EXIT,
  320. LSTT_TOUCH_START,
  321. LSTT_TOUCH,
  322. LSTT_TOUCH_END,
  323. LSTT_COLLISION_START,
  324. LSTT_COLLISION,
  325. LSTT_COLLISION_END,
  326. LSTT_LAND_COLLISION_START,
  327. LSTT_LAND_COLLISION,
  328. LSTT_LAND_COLLISION_END,
  329. LSTT_TIMER,
  330. LSTT_CHAT,
  331. LSTT_REZ,
  332. LSTT_SENSOR,
  333. LSTT_NO_SENSOR,
  334. LSTT_CONTROL,
  335. LSTT_MONEY,
  336. LSTT_EMAIL,
  337. LSTT_AT_TARGET,
  338. LSTT_NOT_AT_TARGET,
  339. LSTT_AT_ROT_TARGET,
  340. LSTT_NOT_AT_ROT_TARGET,
  341. LSTT_RTPERMISSIONS,
  342. LSTT_INVENTORY,
  343. LSTT_ATTACH,
  344. LSTT_DATASERVER,
  345. LSTT_LINK_MESSAGE,
  346. LSTT_MOVING_START,
  347. LSTT_MOVING_END,
  348. LSTT_OBJECT_REZ,
  349. LSTT_REMOTE_DATA,
  350. LSTT_HTTP_RESPONSE,
  351. LSTT_HTTP_REQUEST,
  352. LSTT_EOF,
  353. LSTT_STATE_BEGIN = LSTT_STATE_ENTRY,
  354. LSTT_STATE_END = LSTT_EOF
  355. } LSCRIPTStateEventType;
  356. const U64 LSCRIPTStateBitField[LSTT_EOF] =
  357. {
  358. 0x0000000000000000, // LSTT_NULL
  359. 0x0000000000000001, // LSTT_STATE_ENTRY
  360. 0x0000000000000002, // LSTT_STATE_EXIT
  361. 0x0000000000000004, // LSTT_TOUCH_START
  362. 0x0000000000000008, // LSTT_TOUCH
  363. 0x0000000000000010, // LSTT_TOUCH_END
  364. 0x0000000000000020, // LSTT_COLLISION_START
  365. 0x0000000000000040, // LSTT_COLLISION
  366. 0x0000000000000080, // LSTT_COLLISION_END
  367. 0x0000000000000100, // LSTT_LAND_COLLISION_START
  368. 0x0000000000000200, // LSTT_LAND_COLLISION
  369. 0x0000000000000400, // LSTT_LAND_COLLISION_END
  370. 0x0000000000000800, // LSTT_TIMER
  371. 0x0000000000001000, // LSTT_CHAT
  372. 0x0000000000002000, // LSTT_REZ
  373. 0x0000000000004000, // LSTT_SENSOR
  374. 0x0000000000008000, // LSTT_NO_SENSOR
  375. 0x0000000000010000, // LSTT_CONTROL
  376. 0x0000000000020000, // LSTT_MONEY
  377. 0x0000000000040000, // LSTT_EMAIL
  378. 0x0000000000080000, // LSTT_AT_TARGET
  379. 0x0000000000100000, // LSTT_NOT_AT_TARGET
  380. 0x0000000000200000, // LSTT_AT_ROT_TARGET
  381. 0x0000000000400000, // LSTT_NOT_AT_ROT_TARGET
  382. 0x0000000000800000, // LSTT_RTPERMISSIONS
  383. 0x0000000001000000, // LSTT_INVENTORY
  384. 0x0000000002000000, // LSTT_ATTACH
  385. 0x0000000004000000, // LSTT_DATASERVER
  386. 0x0000000008000000, //  LSTT_LINK_MESSAGE
  387. 0x0000000010000000, //  LSTT_MOVING_START
  388. 0x0000000020000000, //  LSTT_MOVING_END
  389. 0x0000000040000000, //  LSTT_OBJECT_REZ
  390. 0x0000000080000000, //  LSTT_REMOTE_DATA
  391. 0x0000000100000000LL, // LSTT_HTTP_RESPOSE
  392. 0x0000000200000000LL  // LSTT_HTTP_REQUEST
  393. };
  394. inline S32 get_event_handler_jump_position(U64 bit_field, LSCRIPTStateEventType type)
  395. {
  396. S32 count = 0, position = LSTT_STATE_ENTRY;
  397. while (position < type)
  398. {
  399. if (bit_field & 0x1)
  400. {
  401. count++;
  402. }
  403. bit_field >>= 1;
  404. position++;
  405. }
  406. return count;
  407. }
  408. inline S32 get_number_of_event_handlers(U64 bit_field)
  409. {
  410. S32 count = 0, position = 0;
  411. while (position < LSTT_EOF)
  412. {
  413. if (bit_field & 0x1)
  414. {
  415. count++;
  416. }
  417. bit_field >>= 1;
  418. position++;
  419. }
  420. return count;
  421. }
  422. typedef enum e_lscript_types
  423. {
  424. LST_NULL,
  425. LST_INTEGER,
  426. LST_FLOATINGPOINT,
  427. LST_STRING,
  428. LST_KEY,
  429. LST_VECTOR,
  430. LST_QUATERNION,
  431. LST_LIST,
  432. LST_UNDEFINED,
  433. LST_EOF
  434. } LSCRIPTType;
  435. const U8 LSCRIPTTypeByte[LST_EOF] =
  436. {
  437. LST_NULL,
  438. LST_INTEGER,
  439. LST_FLOATINGPOINT,
  440. LST_STRING,
  441. LST_KEY,
  442. LST_VECTOR,
  443. LST_QUATERNION,
  444. LST_LIST,
  445. LST_NULL,
  446. };
  447. const U8 LSCRIPTTypeHi4Bits[LST_EOF] =
  448. {
  449. LST_NULL,
  450. LST_INTEGER << 4,
  451. LST_FLOATINGPOINT << 4,
  452. LST_STRING << 4,
  453. LST_KEY << 4,
  454. LST_VECTOR << 4,
  455. LST_QUATERNION << 4,
  456. LST_LIST << 4,
  457. LST_UNDEFINED << 4,
  458. };
  459. const char * const LSCRIPTTypeNames[LST_EOF] =  /*Flawfinder: ignore*/
  460. {
  461. "VOID",
  462. "integer",
  463. "float",
  464. "string",
  465. "key",
  466. "vector",
  467. "quaternion",
  468. "list",
  469. "invalid"
  470. };
  471. const S32 LSCRIPTDataSize[LST_EOF] =
  472. {
  473. 0, // VOID
  474. 4, // integer
  475. 4, // float
  476. 4, // string
  477. 4, // key
  478. 12, // vector
  479. 16, // quaternion
  480. 4, // list
  481. 0 // invalid
  482. };
  483. typedef enum e_lscript_runtime_faults
  484. {
  485. LSRF_INVALID,
  486. LSRF_MATH,
  487. LSRF_STACK_HEAP_COLLISION,
  488. LSRF_BOUND_CHECK_ERROR,
  489. LSRF_HEAP_ERROR,
  490. LSRF_VERSION_MISMATCH,
  491. LSRF_MISSING_INVENTORY,
  492. LSRF_SANDBOX,
  493. LSRF_CHAT_OVERRUN,
  494. LSRF_TOO_MANY_LISTENS,
  495. LSRF_NESTING_LISTS,
  496. LSRF_CLI,
  497. LSRF_EOF
  498. } LSCRIPTRunTimeFaults;
  499. extern const char* LSCRIPTRunTimeFaultStrings[LSRF_EOF];  /*Flawfinder: ignore*/
  500. typedef enum e_lscript_runtime_permissions
  501. {
  502. SCRIPT_PERMISSION_DEBIT,
  503. SCRIPT_PERMISSION_TAKE_CONTROLS,
  504. SCRIPT_PERMISSION_REMAP_CONTROLS,
  505. SCRIPT_PERMISSION_TRIGGER_ANIMATION,
  506. SCRIPT_PERMISSION_ATTACH,
  507. SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
  508. SCRIPT_PERMISSION_CHANGE_LINKS,
  509. SCRIPT_PERMISSION_CHANGE_JOINTS,
  510. SCRIPT_PERMISSION_CHANGE_PERMISSIONS,
  511. SCRIPT_PERMISSION_TRACK_CAMERA,
  512. SCRIPT_PERMISSION_CONTROL_CAMERA,
  513. SCRIPT_PERMISSION_EOF
  514. } LSCRIPTRunTimePermissions;
  515. const U32 LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_EOF] =
  516. {
  517. (0x1 << 1), // SCRIPT_PERMISSION_DEBIT,
  518. (0x1 << 2), // SCRIPT_PERMISSION_TAKE_CONTROLS,
  519. (0x1 << 3), // SCRIPT_PERMISSION_REMAP_CONTROLS,
  520. (0x1 << 4), // SCRIPT_PERMISSION_TRIGGER_ANIMATION,
  521. (0x1 << 5), // SCRIPT_PERMISSION_ATTACH,
  522. (0x1 << 6), // SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
  523. (0x1 << 7), // SCRIPT_PERMISSION_CHANGE_LINKS,
  524. (0x1 << 8), // SCRIPT_PERMISSION_CHANGE_JOINTS,
  525. (0x1 << 9), // SCRIPT_PERMISSION_CHANGE_PERMISSIONS
  526. (0x1 << 10),// SCRIPT_PERMISSION_TRACK_CAMERA
  527. (0x1 << 11),// SCRIPT_PERMISSION_CONTROL_CAMERA
  528. };
  529. // http_request string constants
  530. extern const char* URL_REQUEST_GRANTED;
  531. extern const char* URL_REQUEST_DENIED;
  532. extern const U64 LSL_HTTP_REQUEST_TIMEOUT_USEC;
  533. #endif