diff options
Diffstat (limited to 'linden/indra/lscript/lscript_execute')
5 files changed, 58 insertions, 36 deletions
diff --git a/linden/indra/lscript/lscript_execute/lscript_execute.cpp b/linden/indra/lscript/lscript_execute/lscript_execute.cpp index 3adfe32..d178a16 100644 --- a/linden/indra/lscript/lscript_execute/lscript_execute.cpp +++ b/linden/indra/lscript/lscript_execute/lscript_execute.cpp | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2002-2008, Linden Research, Inc. | 7 | * Copyright (c) 2002-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
@@ -60,6 +60,9 @@ const char* LSCRIPTRunTimeFaultStrings[LSRF_EOF] = /*Flawfinder: ignore*/ | |||
60 | "CLI Exception" // LSRF_CLI | 60 | "CLI Exception" // LSRF_CLI |
61 | }; | 61 | }; |
62 | 62 | ||
63 | void LLScriptExecuteLSL2::startRunning() {} | ||
64 | void LLScriptExecuteLSL2::stopRunning() {} | ||
65 | |||
63 | LLScriptExecuteLSL2::LLScriptExecuteLSL2(LLFILE *fp) | 66 | LLScriptExecuteLSL2::LLScriptExecuteLSL2(LLFILE *fp) |
64 | { | 67 | { |
65 | U8 sizearray[4]; | 68 | U8 sizearray[4]; |
@@ -327,8 +330,9 @@ void LLScriptExecuteLSL2::resumeEventHandler(BOOL b_print, const LLUUID &id, F32 | |||
327 | // NOTE: Babbage: all mExecuteFuncs return false. | 330 | // NOTE: Babbage: all mExecuteFuncs return false. |
328 | } | 331 | } |
329 | 332 | ||
330 | void LLScriptExecuteLSL2::callEventHandler(LSCRIPTStateEventType event, S32 major_version, const LLUUID &id, F32 time_slice) | 333 | void LLScriptExecuteLSL2::callEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) |
331 | { | 334 | { |
335 | S32 major_version = getMajorVersion(); | ||
332 | // push a zero to be popped | 336 | // push a zero to be popped |
333 | lscript_push(mBuffer, 0); | 337 | lscript_push(mBuffer, 0); |
334 | // push sp as current bp | 338 | // push sp as current bp |
@@ -403,8 +407,9 @@ void LLScriptExecuteLSL2::callEventHandler(LSCRIPTStateEventType event, S32 majo | |||
403 | // set_ip(mBuffer, opcode_start); | 407 | // set_ip(mBuffer, opcode_start); |
404 | //} | 408 | //} |
405 | 409 | ||
406 | void LLScriptExecuteLSL2::callQueuedEventHandler(LSCRIPTStateEventType event, S32 major_version, const LLUUID &id, F32 time_slice) | 410 | void LLScriptExecuteLSL2::callQueuedEventHandler(LSCRIPTStateEventType event, const LLUUID &id, F32 time_slice) |
407 | { | 411 | { |
412 | S32 major_version = getMajorVersion(); | ||
408 | LLScriptDataCollection* eventdata; | 413 | LLScriptDataCollection* eventdata; |
409 | 414 | ||
410 | for (eventdata = mEventData.mEventDataList.getFirstData(); eventdata; eventdata = mEventData.mEventDataList.getNextData()) | 415 | for (eventdata = mEventData.mEventDataList.getFirstData(); eventdata; eventdata = mEventData.mEventDataList.getNextData()) |
@@ -452,8 +457,9 @@ void LLScriptExecuteLSL2::callQueuedEventHandler(LSCRIPTStateEventType event, S3 | |||
452 | } | 457 | } |
453 | } | 458 | } |
454 | 459 | ||
455 | void LLScriptExecuteLSL2::callNextQueuedEventHandler(U64 event_register, S32 major_version, const LLUUID &id, F32 time_slice) | 460 | void LLScriptExecuteLSL2::callNextQueuedEventHandler(U64 event_register, const LLUUID &id, F32 time_slice) |
456 | { | 461 | { |
462 | S32 major_version = getMajorVersion(); | ||
457 | LLScriptDataCollection* eventdata = mEventData.getNextEvent(); | 463 | LLScriptDataCollection* eventdata = mEventData.getNextEvent(); |
458 | if (eventdata) | 464 | if (eventdata) |
459 | { | 465 | { |
@@ -541,9 +547,9 @@ void LLScriptExecuteLSL2::setSleep(F32 value) | |||
541 | } | 547 | } |
542 | 548 | ||
543 | //virtual | 549 | //virtual |
544 | U64 LLScriptExecuteLSL2::getCurrentHandler(S32 version) | 550 | U64 LLScriptExecuteLSL2::getCurrentHandler() |
545 | { | 551 | { |
546 | return get_event_register(mBuffer, LREG_IE, version); | 552 | return get_event_register(mBuffer, LREG_IE, getMajorVersion()); |
547 | } | 553 | } |
548 | 554 | ||
549 | //virtual | 555 | //virtual |
@@ -724,6 +730,20 @@ void LLScriptExecuteLSL2::reset() | |||
724 | bytestream2bytestream(mBuffer, dest_offset, src, src_offset, size); | 730 | bytestream2bytestream(mBuffer, dest_offset, src, src_offset, size); |
725 | } | 731 | } |
726 | 732 | ||
733 | S32 LLScriptExecuteLSL2::getMajorVersion() const | ||
734 | { | ||
735 | S32 version = getVersion(); | ||
736 | S32 major_version = 0; | ||
737 | if (version == LSL2_VERSION1_END_NUMBER){ | ||
738 | major_version = 1; | ||
739 | } | ||
740 | else if (version == LSL2_VERSION_NUMBER) | ||
741 | { | ||
742 | major_version = 2; | ||
743 | } | ||
744 | return major_version; | ||
745 | } | ||
746 | |||
727 | LLScriptExecute::LLScriptExecute() : | 747 | LLScriptExecute::LLScriptExecute() : |
728 | mReset(FALSE) | 748 | mReset(FALSE) |
729 | { | 749 | { |
@@ -751,6 +771,10 @@ bool LLScriptExecute::isYieldDue() const | |||
751 | return true; | 771 | return true; |
752 | } | 772 | } |
753 | 773 | ||
774 | // State changes can occur within a single time slice, | ||
775 | // but LLScriptData's clean up is required. Yield here | ||
776 | // to allow LLScriptData to perform cleanup and then call | ||
777 | // runQuanta again. | ||
754 | if(isStateChangePending()) | 778 | if(isStateChangePending()) |
755 | { | 779 | { |
756 | return true; | 780 | return true; |
@@ -763,7 +787,6 @@ bool LLScriptExecute::isYieldDue() const | |||
763 | // a single instruction for LSL2, a segment between save tests for Mono | 787 | // a single instruction for LSL2, a segment between save tests for Mono |
764 | void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, | 788 | void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, |
765 | const char **errorstr, | 789 | const char **errorstr, |
766 | BOOL &state_transition, | ||
767 | U32& events_processed, | 790 | U32& events_processed, |
768 | F32 quanta) | 791 | F32 quanta) |
769 | { | 792 | { |
@@ -806,17 +829,15 @@ void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, | |||
806 | else | 829 | else |
807 | { | 830 | { |
808 | // make sure that IE is zero | 831 | // make sure that IE is zero |
809 | setCurrentHandler(0, major_version); | 832 | setCurrentHandler(0); |
810 | 833 | ||
811 | // if no, we're in a state and waiting for an event | 834 | // if no, we're in a state and waiting for an event |
812 | U64 current_events = getCurrentEvents(major_version); | 835 | U64 current_events = getCurrentEvents(); |
813 | U64 event_register = getEventHandlers(major_version); | 836 | U64 event_register = getEventHandlers(); |
814 | 837 | ||
815 | // check NS to see if need to switch states (NS != CS) | 838 | // check NS to see if need to switch states (NS != CS) |
816 | if (isStateChangePending()) | 839 | if (isStateChangePending()) |
817 | { | 840 | { |
818 | state_transition = TRUE; | ||
819 | |||
820 | // ok, blow away any pending events | 841 | // ok, blow away any pending events |
821 | deleteAllEvents(); | 842 | deleteAllEvents(); |
822 | 843 | ||
@@ -824,16 +845,16 @@ void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, | |||
824 | if (current_events & LSCRIPTStateBitField[LSTT_STATE_EXIT]) | 845 | if (current_events & LSCRIPTStateBitField[LSTT_STATE_EXIT]) |
825 | { | 846 | { |
826 | // if yes, clear state exit flag | 847 | // if yes, clear state exit flag |
827 | setCurrentHandler(LSCRIPTStateBitField[LSTT_STATE_EXIT], major_version); | 848 | setCurrentHandler(LSCRIPTStateBitField[LSTT_STATE_EXIT]); |
828 | current_events &= ~LSCRIPTStateBitField[LSTT_STATE_EXIT]; | 849 | current_events &= ~LSCRIPTStateBitField[LSTT_STATE_EXIT]; |
829 | setCurrentEvents(current_events, major_version); | 850 | setCurrentEvents(current_events); |
830 | 851 | ||
831 | // check state exit event handler | 852 | // check state exit event handler |
832 | // if there is a handler, call it | 853 | // if there is a handler, call it |
833 | if (event_register & LSCRIPTStateBitField[LSTT_STATE_EXIT]) | 854 | if (event_register & LSCRIPTStateBitField[LSTT_STATE_EXIT]) |
834 | { | 855 | { |
835 | ++events_processed; | 856 | ++events_processed; |
836 | callEventHandler(LSTT_STATE_EXIT, major_version, id, quanta); | 857 | callEventHandler(LSTT_STATE_EXIT, id, quanta); |
837 | return; | 858 | return; |
838 | } | 859 | } |
839 | } | 860 | } |
@@ -841,32 +862,32 @@ void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, | |||
841 | // if no handler or no state exit flag switch to new state | 862 | // if no handler or no state exit flag switch to new state |
842 | // set state entry flag and clear other CE flags | 863 | // set state entry flag and clear other CE flags |
843 | current_events = LSCRIPTStateBitField[LSTT_STATE_ENTRY]; | 864 | current_events = LSCRIPTStateBitField[LSTT_STATE_ENTRY]; |
844 | setCurrentEvents(current_events, major_version); | 865 | setCurrentEvents(current_events); |
845 | 866 | ||
846 | U64 handled_events = nextState(); | 867 | U64 handled_events = nextState(); |
847 | setEventHandlers(handled_events, major_version); | 868 | setEventHandlers(handled_events); |
848 | } | 869 | } |
849 | 870 | ||
850 | // try to get next event from stack | 871 | // try to get next event from stack |
851 | BOOL b_done = FALSE; | 872 | BOOL b_done = FALSE; |
852 | LSCRIPTStateEventType event = LSTT_NULL; | 873 | LSCRIPTStateEventType event = LSTT_NULL; |
853 | 874 | ||
854 | current_events = getCurrentEvents(major_version); | 875 | current_events = getCurrentEvents(); |
855 | event_register = getEventHandlers(major_version); | 876 | event_register = getEventHandlers(); |
856 | 877 | ||
857 | // first, check to see if state_entry or onrez are raised and handled | 878 | // first, check to see if state_entry or onrez are raised and handled |
858 | if ((current_events & LSCRIPTStateBitField[LSTT_STATE_ENTRY]) | 879 | if ((current_events & LSCRIPTStateBitField[LSTT_STATE_ENTRY]) |
859 | &&(current_events & event_register)) | 880 | &&(current_events & event_register)) |
860 | { | 881 | { |
861 | ++events_processed; | 882 | ++events_processed; |
862 | callEventHandler(LSTT_STATE_ENTRY, major_version, id, quanta); | 883 | callEventHandler(LSTT_STATE_ENTRY, id, quanta); |
863 | b_done = TRUE; | 884 | b_done = TRUE; |
864 | } | 885 | } |
865 | else if ((current_events & LSCRIPTStateBitField[LSTT_REZ]) | 886 | else if ((current_events & LSCRIPTStateBitField[LSTT_REZ]) |
866 | &&(current_events & event_register)) | 887 | &&(current_events & event_register)) |
867 | { | 888 | { |
868 | ++events_processed; | 889 | ++events_processed; |
869 | callQueuedEventHandler(LSTT_REZ, major_version, id, quanta); | 890 | callQueuedEventHandler(LSTT_REZ, id, quanta); |
870 | b_done = TRUE; | 891 | b_done = TRUE; |
871 | } | 892 | } |
872 | 893 | ||
@@ -876,7 +897,7 @@ void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, | |||
876 | if(getEventCount() > 0) | 897 | if(getEventCount() > 0) |
877 | { | 898 | { |
878 | ++events_processed; | 899 | ++events_processed; |
879 | callNextQueuedEventHandler(event_register, major_version, id, quanta); | 900 | callNextQueuedEventHandler(event_register, id, quanta); |
880 | b_done = TRUE; | 901 | b_done = TRUE; |
881 | } | 902 | } |
882 | else | 903 | else |
@@ -887,7 +908,7 @@ void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, | |||
887 | { | 908 | { |
888 | event = return_first_event((S32)handled_current); | 909 | event = return_first_event((S32)handled_current); |
889 | ++events_processed; | 910 | ++events_processed; |
890 | callEventHandler(event, major_version, id, quanta); | 911 | callEventHandler(event, id, quanta); |
891 | } | 912 | } |
892 | b_done = TRUE; | 913 | b_done = TRUE; |
893 | } | 914 | } |
@@ -895,8 +916,8 @@ void LLScriptExecute::runInstructions(BOOL b_print, const LLUUID &id, | |||
895 | } | 916 | } |
896 | } | 917 | } |
897 | 918 | ||
898 | // Run for a single timeslice, or until a yield is due | 919 | // Run for a single timeslice, or until a yield or state transition is due |
899 | F32 LLScriptExecute::runQuanta(BOOL b_print, const LLUUID &id, const char **errorstr, BOOL &state_transition, F32 quanta, U32& events_processed, LLTimer& timer) | 920 | F32 LLScriptExecute::runQuanta(BOOL b_print, const LLUUID &id, const char **errorstr, F32 quanta, U32& events_processed, LLTimer& timer) |
900 | { | 921 | { |
901 | U32 timer_checks = 0; | 922 | U32 timer_checks = 0; |
902 | F32 inloop = 0; | 923 | F32 inloop = 0; |
@@ -907,7 +928,7 @@ F32 LLScriptExecute::runQuanta(BOOL b_print, const LLUUID &id, const char **erro | |||
907 | // on current execution speed. | 928 | // on current execution speed. |
908 | while(true) | 929 | while(true) |
909 | { | 930 | { |
910 | runInstructions(b_print, id, errorstr, state_transition, | 931 | runInstructions(b_print, id, errorstr, |
911 | events_processed, quanta); | 932 | events_processed, quanta); |
912 | 933 | ||
913 | static const S32 lsl_timer_check_skip = 4; | 934 | static const S32 lsl_timer_check_skip = 4; |
@@ -3277,7 +3298,7 @@ BOOL run_state(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id) | |||
3277 | { | 3298 | { |
3278 | major_version = 2; | 3299 | major_version = 2; |
3279 | } | 3300 | } |
3280 | 3301 | ||
3281 | S32 current_state = get_register(buffer, LREG_CS); | 3302 | S32 current_state = get_register(buffer, LREG_CS); |
3282 | if (state != current_state) | 3303 | if (state != current_state) |
3283 | { | 3304 | { |
@@ -3985,7 +4006,6 @@ void lscript_run(const std::string& filename, BOOL b_debug) | |||
3985 | LLTimer timer; | 4006 | LLTimer timer; |
3986 | 4007 | ||
3987 | const char *error; | 4008 | const char *error; |
3988 | BOOL b_state; | ||
3989 | LLScriptExecuteLSL2 *execute = NULL; | 4009 | LLScriptExecuteLSL2 *execute = NULL; |
3990 | 4010 | ||
3991 | if (filename.empty()) | 4011 | if (filename.empty()) |
@@ -4009,7 +4029,7 @@ void lscript_run(const std::string& filename, BOOL b_debug) | |||
4009 | 4029 | ||
4010 | do { | 4030 | do { |
4011 | LLTimer timer2; | 4031 | LLTimer timer2; |
4012 | execute->runQuanta(b_debug, LLUUID::null, &error, b_state, | 4032 | execute->runQuanta(b_debug, LLUUID::null, &error, |
4013 | time_slice, events_processed, timer2); | 4033 | time_slice, events_processed, timer2); |
4014 | } while (!execute->isFinished()); | 4034 | } while (!execute->isFinished()); |
4015 | 4035 | ||
@@ -4044,7 +4064,8 @@ void lscript_pop_variable(LLScriptLibData *data, U8 *buffer, char type) | |||
4044 | break; | 4064 | break; |
4045 | case 'k': | 4065 | case 'k': |
4046 | data->mType = LST_KEY; | 4066 | data->mType = LST_KEY; |
4047 | 4067 | data->mKey = NULL; | |
4068 | |||
4048 | base_address = lscript_pop_int(buffer); | 4069 | base_address = lscript_pop_int(buffer); |
4049 | // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization | 4070 | // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization |
4050 | // and function clean up of ref counts isn't based on scope (a mistake, I know) | 4071 | // and function clean up of ref counts isn't based on scope (a mistake, I know) |
@@ -4063,7 +4084,7 @@ void lscript_pop_variable(LLScriptLibData *data, U8 *buffer, char type) | |||
4063 | } | 4084 | } |
4064 | lsa_decrease_ref_count(buffer, base_address); | 4085 | lsa_decrease_ref_count(buffer, base_address); |
4065 | } | 4086 | } |
4066 | else | 4087 | if (data->mKey == NULL) |
4067 | { | 4088 | { |
4068 | data->mKey = new char[1]; | 4089 | data->mKey = new char[1]; |
4069 | data->mKey[0] = 0; | 4090 | data->mKey[0] = 0; |
@@ -4071,6 +4092,7 @@ void lscript_pop_variable(LLScriptLibData *data, U8 *buffer, char type) | |||
4071 | break; | 4092 | break; |
4072 | case 's': | 4093 | case 's': |
4073 | data->mType = LST_STRING; | 4094 | data->mType = LST_STRING; |
4095 | data->mString = NULL; | ||
4074 | 4096 | ||
4075 | base_address = lscript_pop_int(buffer); | 4097 | base_address = lscript_pop_int(buffer); |
4076 | // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization | 4098 | // this bit of nastiness is to get around that code paths to local variables can result in lack of initialization |
@@ -4090,7 +4112,7 @@ void lscript_pop_variable(LLScriptLibData *data, U8 *buffer, char type) | |||
4090 | } | 4112 | } |
4091 | lsa_decrease_ref_count(buffer, base_address); | 4113 | lsa_decrease_ref_count(buffer, base_address); |
4092 | } | 4114 | } |
4093 | else | 4115 | if (data->mString == NULL) |
4094 | { | 4116 | { |
4095 | data->mString = new char[1]; | 4117 | data->mString = new char[1]; |
4096 | data->mString[0] = 0; | 4118 | data->mString[0] = 0; |
diff --git a/linden/indra/lscript/lscript_execute/lscript_heapruntime.cpp b/linden/indra/lscript/lscript_execute/lscript_heapruntime.cpp index 42030fa..d502275 100644 --- a/linden/indra/lscript/lscript_execute/lscript_heapruntime.cpp +++ b/linden/indra/lscript/lscript_execute/lscript_heapruntime.cpp | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2002-2008, Linden Research, Inc. | 7 | * Copyright (c) 2002-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
diff --git a/linden/indra/lscript/lscript_execute/lscript_heapruntime.h b/linden/indra/lscript/lscript_execute/lscript_heapruntime.h index 2490683..69bd80f 100644 --- a/linden/indra/lscript/lscript_execute/lscript_heapruntime.h +++ b/linden/indra/lscript/lscript_execute/lscript_heapruntime.h | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2002-2008, Linden Research, Inc. | 7 | * Copyright (c) 2002-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
diff --git a/linden/indra/lscript/lscript_execute/lscript_readlso.cpp b/linden/indra/lscript/lscript_execute/lscript_readlso.cpp index bfd59a7..6dc1474 100644 --- a/linden/indra/lscript/lscript_execute/lscript_readlso.cpp +++ b/linden/indra/lscript/lscript_execute/lscript_readlso.cpp | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2002-2008, Linden Research, Inc. | 7 | * Copyright (c) 2002-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |
diff --git a/linden/indra/lscript/lscript_execute/lscript_readlso.h b/linden/indra/lscript/lscript_execute/lscript_readlso.h index ab339e0..90ebb7b 100644 --- a/linden/indra/lscript/lscript_execute/lscript_readlso.h +++ b/linden/indra/lscript/lscript_execute/lscript_readlso.h | |||
@@ -4,7 +4,7 @@ | |||
4 | * | 4 | * |
5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ | 5 | * $LicenseInfo:firstyear=2002&license=viewergpl$ |
6 | * | 6 | * |
7 | * Copyright (c) 2002-2008, Linden Research, Inc. | 7 | * Copyright (c) 2002-2009, Linden Research, Inc. |
8 | * | 8 | * |
9 | * Second Life Viewer Source Code | 9 | * Second Life Viewer Source Code |
10 | * The source code in this file ("Source Code") is provided by Linden Lab | 10 | * The source code in this file ("Source Code") is provided by Linden Lab |