aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/lscript/lscript_execute.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/lscript/lscript_execute.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/lscript/lscript_execute.h')
-rw-r--r--linden/indra/lscript/lscript_execute.h383
1 files changed, 383 insertions, 0 deletions
diff --git a/linden/indra/lscript/lscript_execute.h b/linden/indra/lscript/lscript_execute.h
new file mode 100644
index 0000000..736095a
--- /dev/null
+++ b/linden/indra/lscript/lscript_execute.h
@@ -0,0 +1,383 @@
1/**
2 * @file lscript_execute.h
3 * @brief Classes to execute bytecode
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LSCRIPT_EXECUTE_H
29#define LL_LSCRIPT_EXECUTE_H
30
31#include <stdio.h>
32#include "lscript_byteconvert.h"
33#include "linked_lists.h"
34#include "lscript_library.h"
35
36// Return values for run() methods
37const U32 NO_DELETE_FLAG = 0x0000;
38const U32 DELETE_FLAG = 0x0001;
39const U32 CREDIT_MONEY_FLAG = 0x0002;
40
41// list of op code execute functions
42BOOL run_noop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
43BOOL run_pop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
44BOOL run_pops(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
45BOOL run_popl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
46BOOL run_popv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
47BOOL run_popq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
48BOOL run_poparg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
49BOOL run_popip(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
50BOOL run_popbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
51BOOL run_popsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
52BOOL run_popslr(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
53
54BOOL run_dup(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
55BOOL run_dups(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
56BOOL run_dupl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
57BOOL run_dupv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
58BOOL run_dupq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
59
60BOOL run_store(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
61BOOL run_stores(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
62BOOL run_storel(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
63BOOL run_storev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
64BOOL run_storeq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
65BOOL run_storeg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
66BOOL run_storegs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
67BOOL run_storegl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
68BOOL run_storegv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
69BOOL run_storegq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
70BOOL run_loadp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
71BOOL run_loadsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
72BOOL run_loadlp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
73BOOL run_loadvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
74BOOL run_loadqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
75BOOL run_loadgp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
76BOOL run_loadgsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
77BOOL run_loadglp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
78BOOL run_loadgvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
79BOOL run_loadgqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
80
81BOOL run_push(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
82BOOL run_pushs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
83BOOL run_pushl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
84BOOL run_pushv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
85BOOL run_pushq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
86BOOL run_pushg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
87BOOL run_pushgs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
88BOOL run_pushgl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
89BOOL run_pushgv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
90BOOL run_pushgq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
91BOOL run_puship(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
92BOOL run_pushbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
93BOOL run_pushsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
94BOOL run_pushargb(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
95BOOL run_pushargi(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
96BOOL run_pushargf(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
97BOOL run_pushargs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
98BOOL run_pushargv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
99BOOL run_pushargq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
100BOOL run_pushe(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
101BOOL run_pushev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
102BOOL run_pusheq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
103BOOL run_pusharge(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
104
105BOOL run_add(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
106BOOL run_sub(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
107BOOL run_mul(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
108BOOL run_div(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
109BOOL run_mod(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
110
111BOOL run_eq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
112BOOL run_neq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
113BOOL run_leq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
114BOOL run_geq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
115BOOL run_less(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
116BOOL run_greater(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
117
118BOOL run_bitand(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
119BOOL run_bitor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
120BOOL run_bitxor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
121BOOL run_booland(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
122BOOL run_boolor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
123
124BOOL run_shl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
125BOOL run_shr(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
126
127BOOL run_neg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
128BOOL run_bitnot(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
129BOOL run_boolnot(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
130
131BOOL run_jump(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
132BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
133BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
134
135BOOL run_state(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
136BOOL run_call(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
137BOOL run_return(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
138BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
139BOOL run_stacktos(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
140BOOL run_stacktol(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
141
142BOOL run_print(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
143
144BOOL run_calllib(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
145BOOL run_calllib_two_byte(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
146
147void unknown_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
148void integer_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
149void integer_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
150void integer_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
151void float_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
152void float_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
153void float_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
154void string_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
155void string_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
156void key_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
157void key_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
158void vector_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
159void vector_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
160void vector_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
161void vector_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
162void quaternion_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
163
164
165void integer_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
166void float_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
167void string_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
168void key_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
169void vector_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
170void quaternion_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
171void list_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
172void list_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
173void list_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
174void list_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
175void list_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
176void list_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
177void list_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
178
179void integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
180void float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
181void vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
182void quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
183
184class LLScriptDataCollection
185{
186public:
187 LLScriptDataCollection(LSCRIPTStateEventType type, LLScriptLibData *data)
188 : mType(type), mData(data)
189 {
190 }
191 LLScriptDataCollection(U8 *src, S32 &offset)
192 {
193 S32 i, number;
194 mType = (LSCRIPTStateEventType)bytestream2integer(src, offset);
195 number = bytestream2integer(src, offset);
196
197 mData = new LLScriptLibData[number];
198
199 for (i = 0; i < number; i++)
200 {
201 mData[i].set(src, offset);
202 }
203
204 }
205
206 ~LLScriptDataCollection()
207 {
208 delete [] mData;
209 mData = NULL;
210 }
211
212 S32 getSavedSize()
213 {
214 S32 size = 0;
215 // mTyoe
216 size += 4;
217 // number of entries
218 size += 4;
219
220 S32 i = 0;
221 do
222 {
223 size += mData[i].getSavedSize();;
224 }
225 while (mData[i++].mType != LST_NULL);
226 return size;
227 }
228
229 S32 write2bytestream(U8 *dest)
230 {
231 S32 offset = 0;
232 // mTyoe
233 integer2bytestream(dest, offset, mType);
234 // count number of entries
235 S32 number = 0;
236 while (mData[number++].mType != LST_NULL)
237 ;
238 integer2bytestream(dest, offset, number);
239
240 // now the entries themselves
241 number = 0;
242 do
243 {
244 offset += mData[number].write2bytestream(dest + offset);
245 }
246 while (mData[number++].mType != LST_NULL);
247 return offset;
248 }
249
250
251 LSCRIPTStateEventType mType;
252 LLScriptLibData *mData;
253};
254const S32 MAX_EVENTS_IN_QUEUE = 64;
255
256class LLScriptEventData
257{
258public:
259 LLScriptEventData() {}
260 LLScriptEventData(U8 *src, S32 &offset)
261 {
262 S32 i, number = bytestream2integer(src, offset);
263 for (i = 0; i < number; i++)
264 {
265 mEventDataList.addData(new LLScriptDataCollection(src, offset));
266 }
267 }
268
269 void set(U8 *src, S32 &offset)
270 {
271 S32 i, number = bytestream2integer(src, offset);
272 for (i = 0; i < number; i++)
273 {
274 mEventDataList.addData(new LLScriptDataCollection(src, offset));
275 }
276 }
277
278 ~LLScriptEventData()
279 {
280 mEventDataList.deleteAllData();
281 }
282
283 void addEventData(LLScriptDataCollection *data)
284 {
285 if (mEventDataList.getLength() < MAX_EVENTS_IN_QUEUE)
286 mEventDataList.addDataAtEnd(data);
287 else
288 delete data;
289 }
290 LLScriptDataCollection *getNextEvent(LSCRIPTStateEventType type)
291 {
292 LLScriptDataCollection *temp;
293 for (temp = mEventDataList.getFirstData();
294 temp;
295 temp = mEventDataList.getNextData())
296 {
297 if (temp->mType == type)
298 {
299 mEventDataList.removeCurrentData();
300 return temp;
301 }
302 }
303 return NULL;
304 }
305 LLScriptDataCollection *getNextEvent()
306 {
307 LLScriptDataCollection *temp;
308 temp = mEventDataList.getFirstData();
309 if (temp)
310 {
311 mEventDataList.removeCurrentData();
312 return temp;
313 }
314 return NULL;
315 }
316 void removeEventType(LSCRIPTStateEventType type)
317 {
318 LLScriptDataCollection *temp;
319 for (temp = mEventDataList.getFirstData();
320 temp;
321 temp = mEventDataList.getNextData())
322 {
323 if (temp->mType == type)
324 {
325 mEventDataList.deleteCurrentData();
326 }
327 }
328 }
329
330 S32 getSavedSize()
331 {
332 S32 size = 0;
333 // number in linked list
334 size += 4;
335 LLScriptDataCollection *temp;
336 for (temp = mEventDataList.getFirstData();
337 temp;
338 temp = mEventDataList.getNextData())
339 {
340 size += temp->getSavedSize();
341 }
342 return size;
343 }
344
345 S32 write2bytestream(U8 *dest)
346 {
347 S32 offset = 0;
348 // number in linked list
349 S32 number = mEventDataList.getLength();
350 integer2bytestream(dest, offset, number);
351 LLScriptDataCollection *temp;
352 for (temp = mEventDataList.getFirstData();
353 temp;
354 temp = mEventDataList.getNextData())
355 {
356 offset += temp->write2bytestream(dest + offset);
357 }
358 return offset;
359 }
360
361 LLLinkedList<LLScriptDataCollection> mEventDataList;
362};
363
364class LLScriptExecute
365{
366public:
367 LLScriptExecute(FILE *fp);
368 LLScriptExecute(U8 *buffer);
369 ~LLScriptExecute();
370
371 void init();
372 U32 run(BOOL b_print, const LLUUID &id, char **errorstr, BOOL &state_transition);
373
374 BOOL (*mExecuteFuncs[0x100])(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
375
376 U32 mInstructionCount;
377 U8 *mBuffer;
378 LLScriptEventData mEventData;
379
380 static S64 sGlobalInstructionCount;
381};
382
383#endif