diff options
Diffstat (limited to 'indra/lscript/lscript_execute.h')
-rw-r--r-- | indra/lscript/lscript_execute.h | 215 |
1 files changed, 189 insertions, 26 deletions
diff --git a/indra/lscript/lscript_execute.h b/indra/lscript/lscript_execute.h index 1e11d32d09..fc491ead0f 100644 --- a/indra/lscript/lscript_execute.h +++ b/indra/lscript/lscript_execute.h @@ -2,30 +2,25 @@ * @file lscript_execute.h * @brief Classes to execute bytecode * - * $LicenseInfo:firstyear=2002&license=viewergpl$ - * - * Copyright (c) 2002-2007, Linden Research, Inc. - * + * $LicenseInfo:firstyear=2002&license=viewerlgpl$ * Second Life Viewer Source Code - * The source code in this file ("Source Code") is provided by Linden Lab - * to you under the terms of the GNU General Public License, version 2.0 - * ("GPL"), unless you have obtained a separate licensing agreement - * ("Other License"), formally executed by you and Linden Lab. Terms of - * the GPL can be found in doc/GPL-license.txt in this distribution, or - * online at http://secondlife.com/developers/opensource/gplv2 + * Copyright (C) 2010, Linden Research, Inc. * - * There are special exceptions to the terms and conditions of the GPL as - * it is applied to this Source Code. View the full text of the exception - * in the file doc/FLOSS-exception.txt in this software distribution, or - * online at http://secondlife.com/developers/opensource/flossexception + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. * - * By copying, modifying or distributing this software, you acknowledge - * that you have read and understood your obligations described above, - * and agree to abide by those obligations. + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. * - * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO - * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, - * COMPLETENESS OR PERFORMANCE. + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA * $/LicenseInfo$ */ @@ -36,6 +31,8 @@ #include "linked_lists.h" #include "lscript_library.h" +class LLTimer; + // Return values for run() methods const U32 NO_DELETE_FLAG = 0x0000; const U32 DELETE_FLAG = 0x0001; @@ -367,24 +364,190 @@ public: class LLScriptExecute { public: - LLScriptExecute(FILE *fp); - LLScriptExecute(U8 *buffer); - ~LLScriptExecute(); + LLScriptExecute(); + virtual ~LLScriptExecute() = 0; + virtual S32 getVersion() const = 0; + virtual void deleteAllEvents() = 0; + virtual void addEvent(LLScriptDataCollection* event) = 0; + virtual U32 getEventCount() = 0; + virtual void removeEventType(LSCRIPTStateEventType event_type) = 0; + virtual S32 getFaults() = 0; + virtual void setFault(LSCRIPTRunTimeFaults fault) = 0; + virtual U32 getFreeMemory() = 0; + virtual S32 getParameter() = 0; + virtual void setParameter(S32 value) = 0; + virtual F32 getSleep() const = 0; + virtual void setSleep(F32 value) = 0; + virtual F32 getEnergy() const = 0; + virtual void setEnergy(F32 value) = 0; + virtual U64 getCurrentEvents() = 0; + virtual void setCurrentEvents(U64 value) = 0; + virtual U64 getEventHandlers() = 0; + virtual void setEventHandlers(U64 value) = 0; + virtual U64 getCurrentHandler() = 0; + virtual void setCurrentHandler(U64 value) = 0; + virtual BOOL isFinished() const = 0; + virtual BOOL isStateChangePending() const = 0; + virtual S32 writeState(U8 **dest, U32 header_size, U32 footer_size) = 0; // Allocate memory for header, state and footer return size of state. + virtual U32 getEventsSavedSize() = 0; // Returns 0 if events are written with state. + virtual S32 writeEvents(U8 *dest) = 0; // Must write and return exactly the number of bytes returned by getEventsSavedSize. + virtual void readEvents(U8* src, S32& offset) = 0; + virtual S32 readState(U8 *src) = 0; // Returns number of bytes read. + virtual void reset(); + virtual const U8* getBytecode() const = 0; + virtual U32 getBytecodeSize() const = 0; + virtual bool isMono() const = 0; + virtual void error() {;} // Processing that must be performed when error flag is set and so run is not called. + + virtual U32 getUsedMemory() = 0; + + // Run current event handler for a maximum of time_slice seconds. + // Updates current handler and current events registers. + virtual void resumeEventHandler(BOOL b_print, const LLUUID &id, F32 time_slice) = 0; + + // Run handler for event for a maximum of time_slice seconds. + // Updates current handler and current events registers. + virtual void callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) = 0;; + + // Run handler for next queued event for maximum of time_slice seconds. + // Updates current handler and current events registers. + // Removes processed event from queue. + virtual void callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice) = 0; + + // Run handler for event for a maximum of time_slice seconds. + // Updates current handler and current events registers. + // Removes processed event from queue. + virtual void callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) = 0; + + // Switch to next state. + // Returns new set of handled events. + virtual U64 nextState() = 0; + + // Returns time taken. + virtual F32 runQuanta(BOOL b_print, const LLUUID &id, + const char **errorstr, + F32 quanta, + U32& events_processed, LLTimer& timer); + + // NOTE: babbage: this must be used on occasions where another script may already be executing. Only 2 levels of nesting are allowed. + // Provided to support bizarre detach behaviour only. Do not use. + virtual F32 runNested(BOOL b_print, const LLUUID &id, + const char **errorstr, + F32 quanta, + U32& events_processed, LLTimer& timer); + + // Run smallest possible amount of code: an instruction for LSL2, a segment + // between save tests for Mono + void runInstructions(BOOL b_print, const LLUUID &id, + const char **errorstr, + U32& events_processed, + F32 quanta); + + bool isYieldDue() const; + + void setReset(BOOL b) {mReset = b;} + BOOL getReset() const { return mReset; } + + // Called when the script is scheduled to be run from newsim/LLScriptData + virtual void startRunning() = 0; + + // Called when the script is scheduled to be stopped from newsim/LLScriptData + virtual void stopRunning() = 0; + + // A timer is regularly checked to see if script takes too long, but we + // don't do it every opcode due to performance hits. + static void setTimerCheckSkip( S32 value ) { sTimerCheckSkip = value; } + static S32 getTimerCheckSkip() { return sTimerCheckSkip; } + +private: + + BOOL mReset; + + static S32 sTimerCheckSkip; // Number of times to skip the timer check for performance reasons +}; + +class LLScriptExecuteLSL2 : public LLScriptExecute +{ +public: + LLScriptExecuteLSL2(LLFILE *fp); + LLScriptExecuteLSL2(const U8* bytecode, U32 bytecode_size); + virtual ~LLScriptExecuteLSL2(); + + virtual S32 getVersion() const {return get_register(mBuffer, LREG_VN);} + virtual void deleteAllEvents() {mEventData.mEventDataList.deleteAllData();} + virtual void addEvent(LLScriptDataCollection* event); + virtual U32 getEventCount() {return mEventData.mEventDataList.getLength();} + virtual void removeEventType(LSCRIPTStateEventType event_type); + virtual S32 getFaults() {return get_register(mBuffer, LREG_FR);} + virtual void setFault(LSCRIPTRunTimeFaults fault) {set_fault(mBuffer, fault);} + virtual U32 getFreeMemory(); + virtual S32 getParameter(); + virtual void setParameter(S32 value); + virtual F32 getSleep() const; + virtual void setSleep(F32 value); + virtual F32 getEnergy() const; + virtual void setEnergy(F32 value); + virtual U64 getCurrentEvents() {return get_event_register(mBuffer, LREG_CE, getMajorVersion());} + virtual void setCurrentEvents(U64 value) {return set_event_register(mBuffer, LREG_CE, value, getMajorVersion());} + virtual U64 getEventHandlers() {return get_event_register(mBuffer, LREG_ER, getMajorVersion());} + virtual void setEventHandlers(U64 value) {set_event_register(mBuffer, LREG_ER, value, getMajorVersion());} + virtual U64 getCurrentHandler(); + virtual void setCurrentHandler(U64 value) {return set_event_register(mBuffer, LREG_IE, value, getMajorVersion());} + virtual BOOL isFinished() const {return get_register(mBuffer, LREG_IP) == 0;} + virtual BOOL isStateChangePending() const {return get_register(mBuffer, LREG_CS) != get_register(mBuffer, LREG_NS);} + virtual S32 writeState(U8 **dest, U32 header_size, U32 footer_size); // Not including Events. + virtual U32 getEventsSavedSize() {return mEventData.getSavedSize();} + virtual S32 writeEvents(U8 *dest) {return mEventData.write2bytestream(dest);} + virtual void readEvents(U8* src, S32& offset) {mEventData.set(src, offset);} + virtual S32 writeBytecode(U8 **dest); + virtual S32 readState(U8 *src); + virtual void reset(); + virtual const U8* getBytecode() const {return mBytecode;} + virtual U32 getBytecodeSize() const {return mBytecodeSize;} + virtual bool isMono() const {return false;} + virtual U32 getUsedMemory(); + // Run current event handler for a maximum of time_slice seconds. + // Updates current handler and current events registers. + virtual void resumeEventHandler(BOOL b_print, const LLUUID &id, F32 time_slice); + + // Run handler for event for a maximum of time_slice seconds. + // Updates current handler and current events registers. + virtual void callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice); + + // Run handler for next queued event for maximum of time_slice seconds. + // Updates current handler and current events registers. + // Removes processed event from queue. + virtual void callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice); + + // Run handler for event for a maximum of time_slice seconds. + // Updates current handler and current events registers. + // Removes processed event from queue. + virtual void callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice); + + // Switch to next state. + // Returns new set of handled events. + virtual U64 nextState(); void init(); - U32 run(BOOL b_print, const LLUUID &id, char **errorstr, BOOL &state_transition); BOOL (*mExecuteFuncs[0x100])(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id); U32 mInstructionCount; U8 *mBuffer; LLScriptEventData mEventData; - - static S64 sGlobalInstructionCount; + U8* mBytecode; // Initial state and bytecode. + U32 mBytecodeSize; private: + S32 getMajorVersion() const; void recordBoundaryError( const LLUUID &id ); void setStateEventOpcoodeStartSafely( S32 state, LSCRIPTStateEventType event, const LLUUID &id ); + + // Called when the script is scheduled to be run from newsim/LLScriptData + virtual void startRunning(); + + // Called when the script is scheduled to be stopped from newsim/LLScriptData + virtual void stopRunning(); }; #endif |