PageRenderTime 84ms CodeModel.GetById 13ms app.highlight 66ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/lscript/lscript_execute.h

https://bitbucket.org/lindenlab/viewer-beta/
C++ Header | 553 lines | 414 code | 70 blank | 69 comment | 21 complexity | 651fee192f9e2a4c7f20fb4af169bfb7 MD5 | raw file
  1/** 
  2 * @file lscript_execute.h
  3 * @brief Classes to execute bytecode
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#ifndef LL_LSCRIPT_EXECUTE_H
 28#define LL_LSCRIPT_EXECUTE_H
 29
 30#include "lscript_byteconvert.h"
 31#include "linked_lists.h"
 32#include "lscript_library.h"
 33
 34class LLTimer;
 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();
368	virtual ~LLScriptExecute()  = 0;
369	virtual S32 getVersion() const = 0;
370	virtual void deleteAllEvents() = 0;
371	virtual void addEvent(LLScriptDataCollection* event) = 0;
372	virtual U32 getEventCount() = 0;
373	virtual void removeEventType(LSCRIPTStateEventType event_type) = 0;
374	virtual S32 getFaults() = 0;
375	virtual void setFault(LSCRIPTRunTimeFaults fault) = 0;
376	virtual	U32 getFreeMemory() = 0;
377	virtual S32 getParameter() = 0;
378	virtual void setParameter(S32 value) = 0;
379	virtual F32 getSleep() const = 0;
380	virtual void setSleep(F32 value) = 0;
381	virtual F32 getEnergy() const = 0;
382	virtual void setEnergy(F32 value) = 0;
383	virtual U64 getCurrentEvents() = 0;
384	virtual void setCurrentEvents(U64 value) = 0;
385	virtual U64 getEventHandlers() = 0;
386	virtual void setEventHandlers(U64 value) = 0;
387	virtual U64 getCurrentHandler() = 0;
388	virtual void setCurrentHandler(U64 value) = 0;
389	virtual BOOL isFinished() const = 0;
390	virtual BOOL isStateChangePending() const = 0;
391	virtual S32 writeState(U8 **dest, U32 header_size, U32 footer_size) = 0; // Allocate memory for header, state and footer return size of state.
392	virtual U32 getEventsSavedSize() = 0; // Returns 0 if events are written with state.
393	virtual S32 writeEvents(U8 *dest) = 0; // Must write and return exactly the number of bytes returned by getEventsSavedSize.
394	virtual void readEvents(U8* src, S32& offset) = 0;
395	virtual S32 readState(U8 *src) = 0; // Returns number of bytes read.
396	virtual void reset();
397	virtual const U8* getBytecode() const = 0;
398	virtual U32 getBytecodeSize() const = 0;
399	virtual bool isMono() const = 0;
400	virtual void error() {;} // Processing that must be performed when error flag is set and so run is not called.
401
402	virtual U32 getUsedMemory() = 0;
403	
404	// Run current event handler for a maximum of time_slice seconds.
405	// Updates current handler and current events registers.
406	virtual void resumeEventHandler(BOOL b_print, const LLUUID &id, F32 time_slice) = 0;
407
408	// Run handler for event for a maximum of time_slice seconds.
409	// Updates current handler and current events registers.
410	virtual void callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) = 0;;
411
412	// Run handler for next queued event for maximum of time_slice seconds. 
413	// Updates current handler and current events registers.
414	// Removes processed event from queue.
415	virtual void callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice) = 0;
416
417	// Run handler for event for a maximum of time_slice seconds.
418	// Updates current handler and current events registers.
419	// Removes processed event from queue.
420	virtual void callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) = 0;
421
422	// Switch to next state.
423	// Returns new set of handled events.
424	virtual U64 nextState() = 0; 
425
426	// Returns time taken.
427	virtual F32 runQuanta(BOOL b_print, const LLUUID &id,
428						  const char **errorstr, 
429						  F32 quanta,
430						  U32& events_processed, LLTimer& timer);
431
432	// NOTE: babbage: this must be used on occasions where another script may already be executing. Only 2 levels of nesting are allowed.
433	// Provided to support bizarre detach behaviour only. Do not use.
434	virtual F32 runNested(BOOL b_print, const LLUUID &id,
435						  const char **errorstr, 
436						  F32 quanta,
437						  U32& events_processed, LLTimer& timer);
438
439	// Run smallest possible amount of code: an instruction for LSL2, a segment
440	// between save tests for Mono
441	void runInstructions(BOOL b_print, const LLUUID &id,
442						 const char **errorstr, 
443						 U32& events_processed,
444						 F32 quanta);
445
446	bool isYieldDue() const;
447
448	void setReset(BOOL b) {mReset = b;}
449	BOOL getReset() const { return mReset; }
450
451	// Called when the script is scheduled to be run from newsim/LLScriptData
452	virtual void startRunning() = 0;
453
454	// Called when the script is scheduled to be stopped from newsim/LLScriptData
455	virtual void stopRunning() = 0;
456	
457	// A timer is regularly checked to see if script takes too long, but we
458	// don't do it every opcode due to performance hits.
459	static void		setTimerCheckSkip( S32 value )			{ sTimerCheckSkip = value;		}
460	static S32		getTimerCheckSkip()						{ return sTimerCheckSkip;		}
461
462private:
463
464	BOOL mReset;
465
466	static	S32		sTimerCheckSkip;		// Number of times to skip the timer check for performance reasons
467};
468
469class LLScriptExecuteLSL2 : public LLScriptExecute
470{
471public:
472	LLScriptExecuteLSL2(LLFILE *fp);
473	LLScriptExecuteLSL2(const U8* bytecode, U32 bytecode_size);
474	virtual ~LLScriptExecuteLSL2();
475
476	virtual S32 getVersion() const {return get_register(mBuffer, LREG_VN);}
477	virtual void deleteAllEvents() {mEventData.mEventDataList.deleteAllData();}
478	virtual void addEvent(LLScriptDataCollection* event);
479	virtual U32 getEventCount() {return mEventData.mEventDataList.getLength();}
480	virtual void removeEventType(LSCRIPTStateEventType event_type);
481	virtual S32 getFaults() {return get_register(mBuffer, LREG_FR);}
482	virtual void setFault(LSCRIPTRunTimeFaults fault) {set_fault(mBuffer, fault);}
483	virtual U32 getFreeMemory();
484	virtual S32 getParameter();
485	virtual void setParameter(S32 value);
486	virtual F32 getSleep() const;
487	virtual void setSleep(F32 value);
488	virtual F32 getEnergy() const;
489	virtual void setEnergy(F32 value);
490	virtual U64 getCurrentEvents() {return get_event_register(mBuffer, LREG_CE, getMajorVersion());}
491	virtual void setCurrentEvents(U64 value) {return set_event_register(mBuffer, LREG_CE, value, getMajorVersion());}
492	virtual U64 getEventHandlers() {return get_event_register(mBuffer, LREG_ER, getMajorVersion());}
493	virtual void setEventHandlers(U64 value) {set_event_register(mBuffer, LREG_ER, value, getMajorVersion());}
494	virtual U64 getCurrentHandler();
495	virtual void setCurrentHandler(U64 value) {return set_event_register(mBuffer, LREG_IE, value, getMajorVersion());}	
496	virtual BOOL isFinished() const {return get_register(mBuffer, LREG_IP) == 0;}
497	virtual BOOL isStateChangePending() const {return get_register(mBuffer, LREG_CS) != get_register(mBuffer, LREG_NS);}
498	virtual S32 writeState(U8 **dest, U32 header_size, U32 footer_size); // Not including Events.
499	virtual U32 getEventsSavedSize() {return mEventData.getSavedSize();}
500	virtual S32 writeEvents(U8 *dest) {return mEventData.write2bytestream(dest);}
501	virtual void readEvents(U8* src, S32& offset) {mEventData.set(src, offset);}
502	virtual S32 writeBytecode(U8 **dest);
503	virtual S32 readState(U8 *src);
504	virtual void reset();
505	virtual const U8* getBytecode() const {return mBytecode;}
506	virtual U32 getBytecodeSize() const {return mBytecodeSize;}
507	virtual bool isMono() const {return false;}
508	virtual U32 getUsedMemory();
509	// Run current event handler for a maximum of time_slice seconds.
510	// Updates current handler and current events registers.
511	virtual void resumeEventHandler(BOOL b_print, const LLUUID &id, F32 time_slice);
512
513	// Run handler for event for a maximum of time_slice seconds.
514	// Updates current handler and current events registers.
515	virtual void callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice);
516
517	// Run handler for next queued event for maximum of time_slice seconds. 
518	// Updates current handler and current events registers.
519	// Removes processed event from queue.
520	virtual void callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice);
521
522	// Run handler for event for a maximum of time_slice seconds.
523	// Updates current handler and current events registers.
524	// Removes processed event from queue.
525	virtual void callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice);
526
527	// Switch to next state.
528	// Returns new set of handled events.
529	virtual U64 nextState(); 
530
531	void init();
532
533	BOOL (*mExecuteFuncs[0x100])(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
534
535	U32						mInstructionCount;
536	U8						*mBuffer;
537	LLScriptEventData		mEventData;
538	U8*						mBytecode; // Initial state and bytecode.
539	U32						mBytecodeSize;
540
541private:
542	S32 getMajorVersion() const;
543	void		recordBoundaryError( const LLUUID &id );
544	void		setStateEventOpcoodeStartSafely( S32 state, LSCRIPTStateEventType event, const LLUUID &id );
545
546	// Called when the script is scheduled to be run from newsim/LLScriptData
547	virtual void startRunning();
548
549	// Called when the script is scheduled to be stopped from newsim/LLScriptData
550	virtual void stopRunning();
551};
552
553#endif