lscript_execute.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LSCRIPT_EXECUTE_H
00033 #define LL_LSCRIPT_EXECUTE_H
00034 
00035 #include "lscript_byteconvert.h"
00036 #include "linked_lists.h"
00037 #include "lscript_library.h"
00038 
00039 // Return values for run() methods
00040 const U32 NO_DELETE_FLAG        = 0x0000;
00041 const U32 DELETE_FLAG           = 0x0001;
00042 const U32 CREDIT_MONEY_FLAG     = 0x0002;
00043 
00044 // list of op code execute functions
00045 BOOL run_noop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00046 BOOL run_pop(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00047 BOOL run_pops(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00048 BOOL run_popl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00049 BOOL run_popv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00050 BOOL run_popq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00051 BOOL run_poparg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00052 BOOL run_popip(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00053 BOOL run_popbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00054 BOOL run_popsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00055 BOOL run_popslr(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00056 
00057 BOOL run_dup(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00058 BOOL run_dups(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00059 BOOL run_dupl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00060 BOOL run_dupv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00061 BOOL run_dupq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00062 
00063 BOOL run_store(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00064 BOOL run_stores(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00065 BOOL run_storel(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00066 BOOL run_storev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00067 BOOL run_storeq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00068 BOOL run_storeg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00069 BOOL run_storegs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00070 BOOL run_storegl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00071 BOOL run_storegv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00072 BOOL run_storegq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00073 BOOL run_loadp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00074 BOOL run_loadsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00075 BOOL run_loadlp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00076 BOOL run_loadvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00077 BOOL run_loadqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00078 BOOL run_loadgp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00079 BOOL run_loadgsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00080 BOOL run_loadglp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00081 BOOL run_loadgvp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00082 BOOL run_loadgqp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00083 
00084 BOOL run_push(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00085 BOOL run_pushs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00086 BOOL run_pushl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00087 BOOL run_pushv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00088 BOOL run_pushq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00089 BOOL run_pushg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00090 BOOL run_pushgs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00091 BOOL run_pushgl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00092 BOOL run_pushgv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00093 BOOL run_pushgq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00094 BOOL run_puship(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00095 BOOL run_pushbp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00096 BOOL run_pushsp(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00097 BOOL run_pushargb(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00098 BOOL run_pushargi(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00099 BOOL run_pushargf(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00100 BOOL run_pushargs(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00101 BOOL run_pushargv(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00102 BOOL run_pushargq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00103 BOOL run_pushe(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00104 BOOL run_pushev(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00105 BOOL run_pusheq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00106 BOOL run_pusharge(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00107 
00108 BOOL run_add(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00109 BOOL run_sub(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00110 BOOL run_mul(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00111 BOOL run_div(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00112 BOOL run_mod(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00113 
00114 BOOL run_eq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00115 BOOL run_neq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00116 BOOL run_leq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00117 BOOL run_geq(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00118 BOOL run_less(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00119 BOOL run_greater(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00120 
00121 BOOL run_bitand(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00122 BOOL run_bitor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00123 BOOL run_bitxor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00124 BOOL run_booland(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00125 BOOL run_boolor(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00126 
00127 BOOL run_shl(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00128 BOOL run_shr(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00129 
00130 BOOL run_neg(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00131 BOOL run_bitnot(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00132 BOOL run_boolnot(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00133 
00134 BOOL run_jump(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00135 BOOL run_jumpif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00136 BOOL run_jumpnif(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00137 
00138 BOOL run_state(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00139 BOOL run_call(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00140 BOOL run_return(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00141 BOOL run_cast(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00142 BOOL run_stacktos(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00143 BOOL run_stacktol(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00144 
00145 BOOL run_print(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00146 
00147 BOOL run_calllib(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00148 BOOL run_calllib_two_byte(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00149 
00150 void unknown_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00151 void integer_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00152 void integer_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00153 void integer_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00154 void float_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00155 void float_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00156 void float_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00157 void string_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00158 void string_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00159 void key_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00160 void key_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00161 void vector_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00162 void vector_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00163 void vector_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00164 void vector_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00165 void quaternion_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00166 
00167 
00168 void integer_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00169 void float_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00170 void string_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00171 void key_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00172 void vector_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00173 void quaternion_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00174 void list_integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00175 void list_float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00176 void list_string_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00177 void list_key_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00178 void list_vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00179 void list_quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00180 void list_list_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00181 
00182 void integer_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00183 void float_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00184 void vector_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00185 void quaternion_operation(U8 *buffer, LSCRIPTOpCodesEnum opcode);
00186 
00187 class LLScriptDataCollection
00188 {
00189 public:
00190         LLScriptDataCollection(LSCRIPTStateEventType type, LLScriptLibData *data)
00191                 : mType(type), mData(data)
00192         {
00193         }
00194         LLScriptDataCollection(U8 *src, S32 &offset)
00195         {
00196                 S32 i, number;
00197                 mType = (LSCRIPTStateEventType)bytestream2integer(src, offset);
00198                 number = bytestream2integer(src,  offset);
00199 
00200                 mData = new LLScriptLibData[number];
00201 
00202                 for (i = 0; i < number; i++)
00203                 {
00204                         mData[i].set(src, offset);
00205                 }
00206 
00207         }
00208 
00209         ~LLScriptDataCollection()
00210         {
00211                 delete [] mData;
00212                 mData = NULL;
00213         }
00214 
00215         S32  getSavedSize()
00216         {
00217                 S32 size = 0;
00218                 // mTyoe
00219                 size += 4;
00220                 // number of entries
00221                 size += 4;
00222 
00223                 S32 i = 0;
00224                 do
00225                 {
00226                         size += mData[i].getSavedSize();;
00227                 }
00228                 while (mData[i++].mType != LST_NULL);
00229                 return size;
00230         }
00231 
00232         S32      write2bytestream(U8 *dest)
00233         {
00234                 S32 offset = 0;
00235                 // mTyoe
00236                 integer2bytestream(dest, offset, mType);
00237                 // count number of entries
00238                 S32 number = 0;
00239                 while (mData[number++].mType != LST_NULL)
00240                         ;
00241                 integer2bytestream(dest, offset, number);
00242 
00243                 // now the entries themselves
00244                 number = 0;
00245                 do
00246                 {
00247                         offset += mData[number].write2bytestream(dest + offset);
00248                 }
00249                 while (mData[number++].mType != LST_NULL);
00250                 return offset;
00251         }
00252 
00253 
00254         LSCRIPTStateEventType   mType;
00255         LLScriptLibData                 *mData;
00256 };
00257 const S32 MAX_EVENTS_IN_QUEUE = 64;
00258 
00259 class LLScriptEventData
00260 {
00261 public:
00262         LLScriptEventData()             {}
00263         LLScriptEventData(U8 *src, S32 &offset)
00264         {
00265                 S32 i, number = bytestream2integer(src, offset);
00266                 for (i = 0; i < number; i++)
00267                 {
00268                         mEventDataList.addData(new LLScriptDataCollection(src, offset));
00269                 }
00270         }
00271 
00272         void set(U8 *src, S32 &offset)
00273         {
00274                 S32 i, number = bytestream2integer(src, offset);
00275                 for (i = 0; i < number; i++)
00276                 {
00277                         mEventDataList.addData(new LLScriptDataCollection(src, offset));
00278                 }
00279         }
00280 
00281         ~LLScriptEventData()    
00282         {
00283                 mEventDataList.deleteAllData();
00284         }
00285 
00286         void addEventData(LLScriptDataCollection *data)
00287         {
00288                 if (mEventDataList.getLength() < MAX_EVENTS_IN_QUEUE)
00289                         mEventDataList.addDataAtEnd(data);
00290                 else
00291                         delete data;
00292         }
00293         LLScriptDataCollection *getNextEvent(LSCRIPTStateEventType type)
00294         {
00295                 LLScriptDataCollection *temp;
00296                 for (temp = mEventDataList.getFirstData();
00297                          temp;
00298                          temp = mEventDataList.getNextData())
00299                 {
00300                         if (temp->mType == type)
00301                         {
00302                                 mEventDataList.removeCurrentData();
00303                                 return temp;
00304                         }
00305                 }
00306                 return NULL;
00307         }
00308         LLScriptDataCollection *getNextEvent()
00309         {
00310                 LLScriptDataCollection *temp;
00311                 temp = mEventDataList.getFirstData();
00312                 if (temp)
00313                 {
00314                         mEventDataList.removeCurrentData();
00315                         return temp;
00316                 }
00317                 return NULL;
00318         }
00319         void removeEventType(LSCRIPTStateEventType type)
00320         {
00321                 LLScriptDataCollection *temp;
00322                 for (temp = mEventDataList.getFirstData();
00323                          temp;
00324                          temp = mEventDataList.getNextData())
00325                 {
00326                         if (temp->mType == type)
00327                         {
00328                                 mEventDataList.deleteCurrentData();
00329                         }
00330                 }
00331         }
00332 
00333         S32  getSavedSize()
00334         {
00335                 S32 size = 0;
00336                 // number in linked list
00337                 size += 4;
00338                 LLScriptDataCollection *temp;
00339                 for (temp = mEventDataList.getFirstData();
00340                          temp;
00341                          temp = mEventDataList.getNextData())
00342                 {
00343                         size += temp->getSavedSize();
00344                 }
00345                 return size;
00346         }
00347 
00348         S32      write2bytestream(U8 *dest)
00349         {
00350                 S32 offset = 0;
00351                 // number in linked list
00352                 S32 number = mEventDataList.getLength();
00353                 integer2bytestream(dest, offset, number);
00354                 LLScriptDataCollection *temp;
00355                 for (temp = mEventDataList.getFirstData();
00356                          temp;
00357                          temp = mEventDataList.getNextData())
00358                 {
00359                         offset += temp->write2bytestream(dest + offset);
00360                 }
00361                 return offset;
00362         }
00363 
00364         LLLinkedList<LLScriptDataCollection>    mEventDataList;
00365 };
00366 
00367 class LLScriptExecute
00368 {
00369 public:
00370         LLScriptExecute(FILE *fp);
00371         LLScriptExecute(U8 *buffer);
00372         ~LLScriptExecute();
00373 
00374         void init();
00375         U32 run(BOOL b_print, const LLUUID &id, char **errorstr, BOOL &state_transition);
00376 
00377         BOOL (*mExecuteFuncs[0x100])(U8 *buffer, S32 &offset, BOOL b_print, const LLUUID &id);
00378 
00379         U32                                             mInstructionCount;
00380         U8                                              *mBuffer;
00381         LLScriptEventData               mEventData;
00382 
00383         static S64 sGlobalInstructionCount;
00384 
00385 private:
00386         void            recordBoundaryError( const LLUUID &id );
00387         void            setStateEventOpcoodeStartSafely( S32 state, LSCRIPTStateEventType event, const LLUUID &id );
00388 };
00389 
00390 #endif

Generated on Thu Jul 1 06:09:51 2010 for Second Life Viewer by  doxygen 1.4.7