Skip to content
Snippets Groups Projects
Commit ca08bd5a authored by Cinder's avatar Cinder
Browse files

OPEN-292 - Remove lscript from project,

Remove legacy udp script upload methods,
Refactor script runtime perms from three arrays to one struct array so we don't have to juggle array order anymore.
parent ae6440ee
No related branches found
No related tags found
No related merge requests found
Showing
with 1 addition and 5888 deletions
...@@ -315,6 +315,7 @@ Cinder Roxley ...@@ -315,6 +315,7 @@ Cinder Roxley
BUG-3863 BUG-3863
OPEN-185 OPEN-185
OPEN-282 OPEN-282
OPEN-292
STORM-1703 STORM-1703
STORM-1948 STORM-1948
STORM-1831 STORM-1831
......
...@@ -39,8 +39,6 @@ add_subdirectory(${LIBS_OPEN_PREFIX}llvfs) ...@@ -39,8 +39,6 @@ add_subdirectory(${LIBS_OPEN_PREFIX}llvfs)
add_subdirectory(${LIBS_OPEN_PREFIX}llwindow) add_subdirectory(${LIBS_OPEN_PREFIX}llwindow)
add_subdirectory(${LIBS_OPEN_PREFIX}llxml) add_subdirectory(${LIBS_OPEN_PREFIX}llxml)
add_subdirectory(${LIBS_OPEN_PREFIX}lscript)
if (WINDOWS AND EXISTS ${LIBS_CLOSED_DIR}copy_win_scripts) if (WINDOWS AND EXISTS ${LIBS_CLOSED_DIR}copy_win_scripts)
add_subdirectory(${LIBS_CLOSED_PREFIX}copy_win_scripts) add_subdirectory(${LIBS_CLOSED_PREFIX}copy_win_scripts)
endif (WINDOWS AND EXISTS ${LIBS_CLOSED_DIR}copy_win_scripts) endif (WINDOWS AND EXISTS ${LIBS_CLOSED_DIR}copy_win_scripts)
......
...@@ -79,7 +79,6 @@ set(cmake_SOURCE_FILES ...@@ -79,7 +79,6 @@ set(cmake_SOURCE_FILES
LLVFS.cmake LLVFS.cmake
LLWindow.cmake LLWindow.cmake
LLXML.cmake LLXML.cmake
LScript.cmake
Linking.cmake Linking.cmake
## MediaPluginBase.cmake ## MediaPluginBase.cmake
NDOF.cmake NDOF.cmake
......
# -*- cmake -*-
set(LSCRIPT_INCLUDE_DIRS
${LIBS_OPEN_DIR}/lscript
${LIBS_OPEN_DIR}/lscript/lscript_compile
${LIBS_OPEN_DIR}/lscript/lscript_execute
${LIBS_OPEN_DIR}/lscript/lscript_execute_mono
)
set(LSCRIPT_LIBRARIES
lscript_compile
lscript_execute
lscript_library
)
set(LSCRIPT_EXECUTE_MONO_LIBRARIES lscript_execute_mono)
# -*- cmake -*-
set(lscript_HEADER_FILES
llscriptresource.h
llscriptresourceconsumer.h
llscriptresourcepool.h
lscript_alloc.h
lscript_byteconvert.h
lscript_byteformat.h
lscript_execute.h
lscript_export.h
lscript_http.h
lscript_library.h
lscript_rt_interface.h
)
add_subdirectory(lscript_compile)
add_subdirectory(lscript_execute)
add_subdirectory(lscript_library)
/**
* @file llscriptresource.h
* @brief LLScriptResource class definition
*
* $LicenseInfo:firstyear=2008&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#ifndef LL_LLSCRIPTRESOURCE_H
#define LL_LLSCRIPTRESOURCE_H
#include "stdtypes.h"
// An LLScriptResource is a limited resource per ID.
class LLScriptResource
{
public:
LLScriptResource();
// If amount resources are available will mark amount resouces
// used and returns true
// Otherwise returns false and doesn't mark any resources used.
bool request(S32 amount = 1);
// Release amount resources from use if at least amount resources are used and return true
// If amount is more than currently used no resources are released and return false
bool release(S32 amount = 1);
// Returns how many resources are available
S32 getAvailable() const;
// Sets the total amount of available resources
// It is possible to set the amount to less than currently used
// Most likely to happen on parcel ownership change
void setTotal(S32 amount);
// Get the total amount of available resources
S32 getTotal() const;
// Get the number of resources used
S32 getUsed() const;
// true if more resources used than total available
bool isOverLimit() const;
private:
S32 mTotal; // How many resources have been set aside
S32 mUsed; // How many resources are currently in use
};
#endif // LL_LLSCRIPTRESOURCE_H
/**
* @file llscriptresourceconsumer.h
* @brief An interface for a script resource consumer.
*
* $LicenseInfo:firstyear=2008&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#ifndef LL_LLSCRIPTRESOURCECONSUMER_H
#define LL_LLSCRIPTRESOURCECONSUMER_H
#include "linden_common.h"
class LLScriptResourcePool;
// Entities that use limited script resources
// should implement this interface
class LLScriptResourceConsumer
{
public:
LLScriptResourceConsumer();
virtual ~LLScriptResourceConsumer() { }
// Get the number of public urls used by this consumer.
virtual S32 getUsedPublicURLs() const = 0;
// Get the resource pool this consumer is currently using.
LLScriptResourcePool& getScriptResourcePool();
const LLScriptResourcePool& getScriptResourcePool() const;
bool switchScriptResourcePools(LLScriptResourcePool& new_pool);
bool canUseScriptResourcePool(const LLScriptResourcePool& resource_pool);
bool isInPool(const LLScriptResourcePool& resource_pool);
protected:
virtual void setScriptResourcePool(LLScriptResourcePool& pool);
LLScriptResourcePool* mScriptResourcePool;
};
#endif // LL_LLSCRIPTRESOURCECONSUMER_H
/**
* @file llscriptresourcepool.h
* @brief A collection of LLScriptResources
*
* $LicenseInfo:firstyear=2008&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#ifndef LL_LLSCRIPTRESOURCEPOOL_H
#define LL_LLSCRIPTRESOURCEPOOL_H
#include "llscriptresource.h"
// This is just a holder for LLSimResources
class LLScriptResourcePool
{
public:
LLScriptResourcePool();
// ~LLSimResourceMgr();
LLScriptResource& getPublicURLResource();
const LLScriptResource& getPublicURLResource() const;
// An empty resource pool.
static LLScriptResourcePool null;
private:
LLScriptResource mLSLPublicURLs;
};
#endif
/**
* @file lscript_alloc.h
* @brief General heap management for scripting system
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#ifndef LL_LSCRIPT_ALLOC_H
#define LL_LSCRIPT_ALLOC_H
// #define at top of file accelerates gcc compiles
// Under gcc 2.9, the manual is unclear if comments can appear above #ifndef
// Under gcc 3, the manual explicitly states comments can appear above the #ifndef
#include "lscript_byteconvert.h"
#include "lscript_library.h"
void reset_hp_to_safe_spot(const U8 *buffer);
// supported data types
// basic types
// integer 4 bytes of integer data
// float 4 bytes of float data
// string data null terminated 1 byte string
// key data null terminated 1 byte string
// vector data 12 bytes of 3 floats
// quaternion data 16 bytes of 4 floats
// list type
// list data 4 bytes of number of entries followed by followed by pointer
// string pointer 4 bytes of address of string data on the heap (only used in list data)
// key pointer 4 bytes of address of key data on the heap (only used in list data)
// heap format
//
// 4 byte offset to next block (in bytes)
// 1 byte of type of variable or empty
// 2 bytes of reference count
// nn bytes of data
const S32 MAX_HEAP_SIZE = TOP_OF_MEMORY;
class LLScriptAllocEntry
{
public:
LLScriptAllocEntry() : mSize(0), mType(LST_NULL), mReferenceCount(0) {}
LLScriptAllocEntry(S32 offset, U8 type) : mSize(offset), mType(type), mReferenceCount(1) {}
friend std::ostream& operator<<(std::ostream& s, const LLScriptAllocEntry &a)
{
s << "Size: " << a.mSize << " Type: " << LSCRIPTTypeNames[a.mType] << " Count: " << a.mReferenceCount;
return s;
}
S32 mSize;
U8 mType;
S16 mReferenceCount;
};
// this is only OK because we only load/save via accessors below
const S32 SIZEOF_SCRIPT_ALLOC_ENTRY = 7;
inline void alloc_entry2bytestream(U8 *buffer, S32 &offset, const LLScriptAllocEntry &entry)
{
if ( (offset < 0)
||(offset > MAX_HEAP_SIZE))
{
set_fault(buffer, LSRF_BOUND_CHECK_ERROR);
}
else
{
integer2bytestream(buffer, offset, entry.mSize);
byte2bytestream(buffer, offset, entry.mType);
s162bytestream(buffer, offset, entry.mReferenceCount);
}
}
inline void bytestream2alloc_entry(LLScriptAllocEntry &entry, U8 *buffer, S32 &offset)
{
if ( (offset < 0)
||(offset > MAX_HEAP_SIZE))
{
set_fault(buffer, LSRF_BOUND_CHECK_ERROR);
reset_hp_to_safe_spot(buffer);
}
else
{
entry.mSize = bytestream2integer(buffer, offset);
entry.mType = bytestream2byte(buffer, offset);
entry.mReferenceCount = bytestream2s16(buffer, offset);
}
}
// create a heap from the HR to TM
BOOL lsa_create_heap(U8 *heap_start, S32 size);
void lsa_fprint_heap(U8 *buffer, LLFILE *fp);
void lsa_print_heap(U8 *buffer);
// adding to heap
// if block is empty
// if block is at least block size + 4 larger than data
// split block
// insert data into first part
// return address
// else
// insert data into block
// return address
// else
// if next block is >= SP
// set Stack-Heap collision
// return NULL
// if next block is empty
// merge next block with current block
// go to start of algorithm
// else
// move to next block
// go to start of algorithm
S32 lsa_heap_add_data(U8 *buffer, LLScriptLibData *data, S32 heapsize, BOOL b_delete);
S32 lsa_heap_top(U8 *heap_start, S32 maxsize);
// split block
// set offset to point to new block
// set offset of new block to point to original offset - block size - data size
// set new block to empty
// set new block reference count to 0
void lsa_split_block(U8 *buffer, S32 &offset, S32 size, LLScriptAllocEntry &entry);
// insert data
// if data is non-list type
// set type to basic type, set reference count to 1, copy data, return address
// else
// set type to list data type, set reference count to 1
// for each list entry
// insert data
// return address
void lsa_insert_data(U8 *buffer, S32 &offset, LLScriptLibData *data, LLScriptAllocEntry &entry, S32 heapsize);
S32 lsa_create_data_block(U8 **buffer, LLScriptLibData *data, S32 base_offset);
// increase reference count
// increase reference count by 1
void lsa_increase_ref_count(U8 *buffer, S32 offset);
// decrease reference count
// decrease reference count by 1
// if reference count == 0
// set type to empty
void lsa_decrease_ref_count(U8 *buffer, S32 offset);
inline S32 get_max_heap_size(U8 *buffer)
{
return get_register(buffer, LREG_SP) - get_register(buffer, LREG_HR);
}
LLScriptLibData *lsa_get_data(U8 *buffer, S32 &offset, BOOL b_dec_ref);
LLScriptLibData *lsa_get_list_ptr(U8 *buffer, S32 &offset, BOOL b_dec_ref);
S32 lsa_cat_strings(U8 *buffer, S32 offset1, S32 offset2, S32 heapsize);
S32 lsa_cmp_strings(U8 *buffer, S32 offset1, S32 offset2);
S32 lsa_cat_lists(U8 *buffer, S32 offset1, S32 offset2, S32 heapsize);
S32 lsa_cmp_lists(U8 *buffer, S32 offset1, S32 offset2);
S32 lsa_preadd_lists(U8 *buffer, LLScriptLibData *data, S32 offset2, S32 heapsize);
S32 lsa_postadd_lists(U8 *buffer, S32 offset1, LLScriptLibData *data, S32 heapsize);
// modifying a list
// insert new list that is modified
// store returned address in original list's variable
// decrease reference count on old list
// list l1 = [10];
// list l2 = l1;
// l1 = [11];
// we want l2 == [10];
// more complicated example:
// list l1 = [10, 11];
// list l2 = l1;
// l1[0] = 12
// I think that we want l2 = [10, 11];
// one option would be to use syntax like:
// l1 = llSetList(l1, 0, 12);
// but this would require variable argument list matching
// which maybe is ok, but would be work
// the other option would be changes to lists that have multiple references causes a copy to occur
// popl @l1, 0, integer, 12
//
// would cause l1 to be copied, 12 to replace the 0th entry, and the address of the new list to be saved in l1
//
inline LLScriptLibData *lsa_bubble_sort(LLScriptLibData *src, S32 stride, S32 ascending)
{
S32 number = src->getListLength();
if (number <= 0)
{
return NULL;
}
if (stride <= 0)
{
stride = 1;
}
S32 i = 0;
if (number % stride)
{
LLScriptLibData *retval = src->mListp;
src->mListp = NULL;
return retval;
}
LLScriptLibData **sortarray = new LLScriptLibData*[number];
LLScriptLibData *temp = src->mListp;
while (temp)
{
sortarray[i] = temp;
i++;
temp = temp->mListp;
}
S32 j, s;
for (i = 0; i < number; i += stride)
{
for (j = i; j < number; j += stride)
{
if ( ((*sortarray[i]) <= (*sortarray[j]))
!= (ascending == TRUE))
{
for (s = 0; s < stride; s++)
{
temp = sortarray[i + s];
sortarray[i + s] = sortarray[j + s];
sortarray[j + s] = temp;
}
}
}
}
i = 1;
temp = sortarray[0];
while (i < number)
{
temp->mListp = sortarray[i++];
temp = temp->mListp;
}
temp->mListp = NULL;
src->mListp = NULL;
temp = sortarray[0];
delete[] sortarray;
return temp;
}
LLScriptLibData* lsa_randomize(LLScriptLibData* src, S32 stride);
#endif
This diff is collapsed.
/**
* @file lscript_byteformat.h
* @brief Shared code between compiler and assembler and LSL
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#ifndef LL_LSCRIPT_BYTEFORMAT_H
#define LL_LSCRIPT_BYTEFORMAT_H
// Data shared between compiler/assembler and lscript execution code
#include "stdtypes.h"
const S32 LSL2_VERSION_NUMBER = 0x0200;
const S32 LSL2_VERSION1_END_NUMBER = 0x0101;
const S32 LSL2_VERSION2_START_NUMBER = 0x0200;
const S32 LSL2_MAJOR_VERSION_ONE = 1;
const S32 LSL2_MAJOR_VERSION_TWO = 2;
const S32 LSL2_CURRENT_MAJOR_VERSION = LSL2_MAJOR_VERSION_TWO;
const S32 TOP_OF_MEMORY = 16384;
typedef enum e_lscript_registers
{
LREG_INVALID,
LREG_IP, // instruction pointer
LREG_VN, // version number
LREG_BP, // base pointer - what local variables are referenced from
LREG_SP, // stack pointer - where the top of the stack is
LREG_HR, // heap register - where in memory does the heap start
LREG_HP, // heap pointer - where is the top of the heap?
LREG_CS, // current state - what state are we currently in?
LREG_NS, // next state - what state are we currently in?
LREG_CE, // current events - what events are waiting to be handled?
LREG_IE, // in event - which event handler are we currently in?
LREG_ER, // event register - what events do we have active handlers for?
LREG_FR, // fault register - which errors are currently active?
LREG_SLR, // sleep register - are we sleeping?
LREG_GVR, // global variable register - where do global variables start
LREG_GFR, // global function register - where do global functions start
LREG_SR, // state register - where do states start
LREG_TM, // top of memory - where is the top of memory
LREG_PR, // parameter register - data passed to script from launcher
LREG_ESR, // energy supply register - how much energy do we have on board?
LREG_NCE, // 64 bit current envents - what events are waiting to be handled?
LREG_NIE, // 64 bit in event - which event handler are we currently in?
LREG_NER, // 64 bit event register - what events do we have active handlers for?
LREG_EOF
} LSCRIPTRegisters;
const S32 gLSCRIPTRegisterAddresses[LREG_EOF] = /* Flawfinder: ignore */
{
0, // LREG_INVALID
4, // LREG_IP
8, // LREG_VN
12, // LREG_BP
16, // LREG_SP
20, // LREG_HR
24, // LREG_HP
28, // LREG_CS
32, // LREG_NS
36, // LREG_CE
40, // LREG_IE
44, // LREG_ER
48, // LREG_FR
52, // LREG_SLR
56, // LREG_GVR
60, // LREG_GFR
72, // LREG_SR
0, // LREG_TM
64, // LREG_PR
68, // LREG_ESR
76, // LREG_NCE
84, // LREG_NIE
92, // LREG_NER
};
const char * const gLSCRIPTRegisterNames[LREG_EOF] =
{
"INVALID", // LREG_INVALID
"IP", // LREG_IP
"VN", // LREG_VN
"BP", // LREG_BP
"SP", // LREG_SP
"HR", // LREG_HR
"HP", // LREG_HP
"CS", // LREG_CS
"NS", // LREG_NS
"CE", // LREG_CE
"IE", // LREG_IE
"ER", // LREG_ER
"FR", // LREG_FR
"SLR", // LREG_SLR
"GVR", // LREG_GVR
"GFR", // LREG_GFR
"SR", // LREG_SR
"TM", // LREG_TM
"PR", // LREG_PR
"ESR", // LREG_ESR
"NCE", // LREG_NCE
"NIE", // LREG_NIE
"NER", // LREG_NER
};
typedef enum e_lscript_op_codes
{
LOPC_INVALID,
LOPC_NOOP,
LOPC_POP,
LOPC_POPS,
LOPC_POPL,
LOPC_POPV,
LOPC_POPQ,
LOPC_POPARG,
LOPC_POPIP,
LOPC_POPBP,
LOPC_POPSP,
LOPC_POPSLR,
LOPC_DUP,
LOPC_DUPS,
LOPC_DUPL,
LOPC_DUPV,
LOPC_DUPQ,
LOPC_STORE,
LOPC_STORES,
LOPC_STOREL,
LOPC_STOREV,
LOPC_STOREQ,
LOPC_STOREG,
LOPC_STOREGS,
LOPC_STOREGL,
LOPC_STOREGV,
LOPC_STOREGQ,
LOPC_LOADP,
LOPC_LOADSP,
LOPC_LOADLP,
LOPC_LOADVP,
LOPC_LOADQP,
LOPC_LOADGP,
LOPC_LOADGLP,
LOPC_LOADGSP,
LOPC_LOADGVP,
LOPC_LOADGQP,
LOPC_PUSH,
LOPC_PUSHS,
LOPC_PUSHL,
LOPC_PUSHV,
LOPC_PUSHQ,
LOPC_PUSHG,
LOPC_PUSHGS,
LOPC_PUSHGL,
LOPC_PUSHGV,
LOPC_PUSHGQ,
LOPC_PUSHIP,
LOPC_PUSHBP,
LOPC_PUSHSP,
LOPC_PUSHARGB,
LOPC_PUSHARGI,
LOPC_PUSHARGF,
LOPC_PUSHARGS,
LOPC_PUSHARGV,
LOPC_PUSHARGQ,
LOPC_PUSHE,
LOPC_PUSHEV,
LOPC_PUSHEQ,
LOPC_PUSHARGE,
LOPC_ADD,
LOPC_SUB,
LOPC_MUL,
LOPC_DIV,
LOPC_MOD,
LOPC_EQ,
LOPC_NEQ,
LOPC_LEQ,
LOPC_GEQ,
LOPC_LESS,
LOPC_GREATER,
LOPC_BITAND,
LOPC_BITOR,
LOPC_BITXOR,
LOPC_BOOLAND,
LOPC_BOOLOR,
LOPC_NEG,
LOPC_BITNOT,
LOPC_BOOLNOT,
LOPC_JUMP,
LOPC_JUMPIF,
LOPC_JUMPNIF,
LOPC_STATE,
LOPC_CALL,
LOPC_RETURN,
LOPC_CAST,
LOPC_STACKTOS,
LOPC_STACKTOL,
LOPC_PRINT,
LOPC_CALLLIB,
LOPC_CALLLIB_TWO_BYTE,
LOPC_SHL,
LOPC_SHR,
LOPC_EOF
} LSCRIPTOpCodesEnum;
const U8 LSCRIPTOpCodes[LOPC_EOF] =
{
0x00, // LOPC_INVALID
0x00, // LOPC_NOOP
0x01, // LOPC_POP
0x02, // LOPC_POPS
0x03, // LOPC_POPL
0x04, // LOPC_POPV
0x05, // LOPC_POPQ
0x06, // LOPC_POPARG
0x07, // LOPC_POPIP
0x08, // LOPC_POPBP
0x09, // LOPC_POPSP
0x0a, // LOPC_POPSLR
0x20, // LOPC_DUP
0x21, // LOPC_DUPS
0x22, // LOPC_DUPL
0x23, // LOPC_DUPV
0x24, // LOPC_DUPQ
0x30, // LOPC_STORE
0x31, // LOPC_STORES
0x32, // LOPC_STOREL
0x33, // LOPC_STOREV
0x34, // LOPC_STOREQ
0x35, // LOPC_STOREG
0x36, // LOPC_STOREGS
0x37, // LOPC_STOREGL
0x38, // LOPC_STOREGV
0x39, // LOPC_STOREGQ
0x3a, // LOPC_LOADP
0x3b, // LOPC_LOADSP
0x3c, // LOPC_LOADLP
0x3d, // LOPC_LOADVP
0x3e, // LOPC_LOADQP
0x3f, // LOPC_LOADGP
0x40, // LOPC_LOADGSP
0x41, // LOPC_LOADGLP
0x42, // LOPC_LOADGVP
0x43, // LOPC_LOADGQP
0x50, // LOPC_PUSH
0x51, // LOPC_PUSHS
0x52, // LOPC_PUSHL
0x53, // LOPC_PUSHV
0x54, // LOPC_PUSHQ
0x55, // LOPC_PUSHG
0x56, // LOPC_PUSHGS
0x57, // LOPC_PUSHGL
0x58, // LOPC_PUSHGV
0x59, // LOPC_PUSHGQ
0x5a, // LOPC_PUSHIP
0x5b, // LOPC_PUSHBP
0x5c, // LOPC_PUSHSP
0x5d, // LOPC_PUSHARGB
0x5e, // LOPC_PUSHARGI
0x5f, // LOPC_PUSHARGF
0x60, // LOPC_PUSHARGS
0x61, // LOPC_PUSHARGV
0x62, // LOPC_PUSHARGQ
0x63, // LOPC_PUSHE
0x64, // LOPC_PUSHEV
0x65, // LOPC_PUSHEQ
0x66, // LOPC_PUSHARGE
0x70, // LOPC_ADD
0x71, // LOPC_SUB
0x72, // LOPC_MUL
0x73, // LOPC_DIV
0x74, // LOPC_MOD
0x75, // LOPC_EQ
0x76, // LOPC_NEQ
0x77, // LOPC_LEQ
0x78, // LOPC_GEQ
0x79, // LOPC_LESS
0x7a, // LOPC_GREATER
0x7b, // LOPC_BITAND
0x7c, // LOPC_BITOR
0x7d, // LOPC_BITXOR
0x7e, // LOPC_BOOLAND
0x7f, // LOPC_BOOLOR
0x80, // LOPC_NEG
0x81, // LOPC_BITNOT
0x82, // LOPC_BOOLNOT
0x90, // LOPC_JUMP
0x91, // LOPC_JUMPIF
0x92, // LOPC_JUMPNIF
0x93, // LOPC_STATE
0x94, // LOPC_CALL
0x95, // LOPC_RETURN
0xa0, // LOPC_CAST
0xb0, // LOPC_STACKTOS
0xb1, // LOPC_STACKTOL
0xc0, // LOPC_PRINT
0xd0, // LOPC_CALLLIB
0xd1, // LOPC_CALLLIB_TWO_BYTE
0xe0, // LOPC_SHL
0xe1 // LOPC_SHR
};
typedef enum e_lscript_state_event_type
{
LSTT_NULL,
LSTT_STATE_ENTRY,
LSTT_STATE_EXIT,
LSTT_TOUCH_START,
LSTT_TOUCH,
LSTT_TOUCH_END,
LSTT_COLLISION_START,
LSTT_COLLISION,
LSTT_COLLISION_END,
LSTT_LAND_COLLISION_START,
LSTT_LAND_COLLISION,
LSTT_LAND_COLLISION_END,
LSTT_TIMER,
LSTT_CHAT,
LSTT_REZ,
LSTT_SENSOR,
LSTT_NO_SENSOR,
LSTT_CONTROL,
LSTT_MONEY,
LSTT_EMAIL,
LSTT_AT_TARGET,
LSTT_NOT_AT_TARGET,
LSTT_AT_ROT_TARGET,
LSTT_NOT_AT_ROT_TARGET,
LSTT_RTPERMISSIONS,
LSTT_INVENTORY,
LSTT_ATTACH,
LSTT_DATASERVER,
LSTT_LINK_MESSAGE,
LSTT_MOVING_START,
LSTT_MOVING_END,
LSTT_OBJECT_REZ,
LSTT_REMOTE_DATA,
LSTT_HTTP_RESPONSE,
LSTT_HTTP_REQUEST,
LSTT_EOF,
LSTT_STATE_BEGIN = LSTT_STATE_ENTRY,
LSTT_STATE_END = LSTT_EOF
} LSCRIPTStateEventType;
const U64 LSCRIPTStateBitField[LSTT_EOF] =
{
0x0000000000000000, // LSTT_NULL
0x0000000000000001, // LSTT_STATE_ENTRY
0x0000000000000002, // LSTT_STATE_EXIT
0x0000000000000004, // LSTT_TOUCH_START
0x0000000000000008, // LSTT_TOUCH
0x0000000000000010, // LSTT_TOUCH_END
0x0000000000000020, // LSTT_COLLISION_START
0x0000000000000040, // LSTT_COLLISION
0x0000000000000080, // LSTT_COLLISION_END
0x0000000000000100, // LSTT_LAND_COLLISION_START
0x0000000000000200, // LSTT_LAND_COLLISION
0x0000000000000400, // LSTT_LAND_COLLISION_END
0x0000000000000800, // LSTT_TIMER
0x0000000000001000, // LSTT_CHAT
0x0000000000002000, // LSTT_REZ
0x0000000000004000, // LSTT_SENSOR
0x0000000000008000, // LSTT_NO_SENSOR
0x0000000000010000, // LSTT_CONTROL
0x0000000000020000, // LSTT_MONEY
0x0000000000040000, // LSTT_EMAIL
0x0000000000080000, // LSTT_AT_TARGET
0x0000000000100000, // LSTT_NOT_AT_TARGET
0x0000000000200000, // LSTT_AT_ROT_TARGET
0x0000000000400000, // LSTT_NOT_AT_ROT_TARGET
0x0000000000800000, // LSTT_RTPERMISSIONS
0x0000000001000000, // LSTT_INVENTORY
0x0000000002000000, // LSTT_ATTACH
0x0000000004000000, // LSTT_DATASERVER
0x0000000008000000, // LSTT_LINK_MESSAGE
0x0000000010000000, // LSTT_MOVING_START
0x0000000020000000, // LSTT_MOVING_END
0x0000000040000000, // LSTT_OBJECT_REZ
0x0000000080000000, // LSTT_REMOTE_DATA
0x0000000100000000LL, // LSTT_HTTP_RESPOSE
0x0000000200000000LL // LSTT_HTTP_REQUEST
};
inline S32 get_event_handler_jump_position(U64 bit_field, LSCRIPTStateEventType type)
{
S32 count = 0, position = LSTT_STATE_ENTRY;
while (position < type)
{
if (bit_field & 0x1)
{
count++;
}
bit_field >>= 1;
position++;
}
return count;
}
inline S32 get_number_of_event_handlers(U64 bit_field)
{
S32 count = 0, position = 0;
while (position < LSTT_EOF)
{
if (bit_field & 0x1)
{
count++;
}
bit_field >>= 1;
position++;
}
return count;
}
typedef enum e_lscript_types
{
LST_NULL,
LST_INTEGER,
LST_FLOATINGPOINT,
LST_STRING,
LST_KEY,
LST_VECTOR,
LST_QUATERNION,
LST_LIST,
LST_UNDEFINED,
LST_EOF
} LSCRIPTType;
const U8 LSCRIPTTypeByte[LST_EOF] =
{
LST_NULL,
LST_INTEGER,
LST_FLOATINGPOINT,
LST_STRING,
LST_KEY,
LST_VECTOR,
LST_QUATERNION,
LST_LIST,
LST_NULL,
};
const U8 LSCRIPTTypeHi4Bits[LST_EOF] =
{
LST_NULL,
LST_INTEGER << 4,
LST_FLOATINGPOINT << 4,
LST_STRING << 4,
LST_KEY << 4,
LST_VECTOR << 4,
LST_QUATERNION << 4,
LST_LIST << 4,
LST_UNDEFINED << 4,
};
const char * const LSCRIPTTypeNames[LST_EOF] = /*Flawfinder: ignore*/
{
"VOID",
"integer",
"float",
"string",
"key",
"vector",
"quaternion",
"list",
"invalid"
};
const S32 LSCRIPTDataSize[LST_EOF] =
{
0, // VOID
4, // integer
4, // float
4, // string
4, // key
12, // vector
16, // quaternion
4, // list
0 // invalid
};
typedef enum e_lscript_runtime_faults
{
LSRF_INVALID,
LSRF_MATH,
LSRF_STACK_HEAP_COLLISION,
LSRF_BOUND_CHECK_ERROR,
LSRF_HEAP_ERROR,
LSRF_VERSION_MISMATCH,
LSRF_MISSING_INVENTORY,
LSRF_SANDBOX,
LSRF_CHAT_OVERRUN,
LSRF_TOO_MANY_LISTENS,
LSRF_NESTING_LISTS,
LSRF_CLI,
LSRF_EOF
} LSCRIPTRunTimeFaults;
extern const char* LSCRIPTRunTimeFaultStrings[LSRF_EOF]; /*Flawfinder: ignore*/
typedef enum e_lscript_runtime_permissions
{
SCRIPT_PERMISSION_DEBIT,
SCRIPT_PERMISSION_TAKE_CONTROLS,
SCRIPT_PERMISSION_REMAP_CONTROLS,
SCRIPT_PERMISSION_TRIGGER_ANIMATION,
SCRIPT_PERMISSION_ATTACH,
SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
SCRIPT_PERMISSION_CHANGE_LINKS,
SCRIPT_PERMISSION_CHANGE_JOINTS,
SCRIPT_PERMISSION_CHANGE_PERMISSIONS,
SCRIPT_PERMISSION_TRACK_CAMERA,
SCRIPT_PERMISSION_CONTROL_CAMERA,
SCRIPT_PERMISSION_TELEPORT,
SCRIPT_PERMISSION_EXPERIENCE,
SCRIPT_PERMISSION_SILENT_ESTATE_MANAGEMENT,
SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS,
SCRIPT_PERMISSION_RETURN_OBJECTS,
SCRIPT_PERMISSION_EOF
} LSCRIPTRunTimePermissions;
const U32 LSCRIPTRunTimePermissionBits[SCRIPT_PERMISSION_EOF] =
{
(0x1 << 1), // SCRIPT_PERMISSION_DEBIT,
(0x1 << 2), // SCRIPT_PERMISSION_TAKE_CONTROLS,
(0x1 << 3), // SCRIPT_PERMISSION_REMAP_CONTROLS,
(0x1 << 4), // SCRIPT_PERMISSION_TRIGGER_ANIMATION,
(0x1 << 5), // SCRIPT_PERMISSION_ATTACH,
(0x1 << 6), // SCRIPT_PERMISSION_RELEASE_OWNERSHIP,
(0x1 << 7), // SCRIPT_PERMISSION_CHANGE_LINKS,
(0x1 << 8), // SCRIPT_PERMISSION_CHANGE_JOINTS,
(0x1 << 9), // SCRIPT_PERMISSION_CHANGE_PERMISSIONS
(0x1 << 10),// SCRIPT_PERMISSION_TRACK_CAMERA
(0x1 << 11),// SCRIPT_PERMISSION_CONTROL_CAMERA
(0x1 << 12),// SCRIPT_PERMISSION_TELEPORT
(0x1 << 13),// SCRIPT_PERMISSION_EXPERIENCE,
(0x1 << 14),// SCRIPT_PERMISSION_SILENT_ESTATE_MANAGEMENT,
(0x1 << 15),// SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS,
(0x1 << 16),// SCRIPT_PERMISSION_RETURN_OBJECTS,
};
// http_request string constants
extern const char* URL_REQUEST_GRANTED;
extern const char* URL_REQUEST_DENIED;
extern const U64 LSL_HTTP_REQUEST_TIMEOUT_USEC;
#endif
# -*- cmake -*-
include(00-Common)
include(LLCommon)
include(LLMath)
include(LLMessage)
include(LLInventory)
include(LLPrimitive)
include(LScript)
include(FindCygwin)
find_program(FLEX flex
"C:/Program Files/GnuWin32/bin"
${CYGWIN_INSTALL_PATH}/bin
/bin
/usr/bin
/usr/local/bin
)
mark_as_advanced(FLEX)
find_program(BISON bison
"C:/Program Files/GnuWin32/bin"
${CYGWIN_INSTALL_PATH}/bin
/bin
/usr/bin
/usr/local/bin
)
mark_as_advanced(BISON)
find_program(M4 m4
"C:/Program Files/GnuWin32/bin"
${CYGWIN_INSTALL_PATH}/bin
/bin
/usr/bin
/usr/local/bin
)
mark_as_advanced(M4)
include_directories(
${LLCOMMON_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLMESSAGE_INCLUDE_DIRS}
${LLINVENTORY_INCLUDE_DIRS}
${LLPRIMITIVE_INCLUDE_DIRS}
${LSCRIPT_INCLUDE_DIRS}
)
include_directories(SYSTEM
${LLCOMMON_SYSTEM_INCLUDE_DIRS}
)
set(lscript_generated_SOURCE_FILES
indra.l.cpp
indra.y.cpp
)
set(lscript_compile_SOURCE_FILES
lscript_alloc.cpp
lscript_bytecode.cpp
lscript_error.cpp
lscript_heap.cpp
lscript_resource.cpp
lscript_scope.cpp
lscript_tree.cpp
lscript_typecheck.cpp
)
set(lscript_compile_HEADER_FILES
CMakeLists.txt
indra.l
indra.y
../lscript_alloc.h
../lscript_byteformat.h
../lscript_byteconvert.h
../lscript_http.h
lscript_error.h
lscript_bytecode.h
lscript_heap.h
lscript_resource.h
lscript_scope.h
lscript_tree.h
lscript_typecheck.h
)
set_source_files_properties(${lscript_compile_HEADER_FILES}
PROPERTIES HEADER_FILE_ONLY TRUE)
set_source_files_properties(${lscript_generated_SOURCE_FILES}
PROPERTIES HEADER_FILE_ONLY FALSE GENERATED TRUE)
list(APPEND lscript_compile_SOURCE_FILES ${lscript_generated_SOURCE_FILES} ${lscript_compile_HEADER_FILES})
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/indra.l.cpp
COMMAND ${FLEX}
ARGS
-P indra_
-o${CMAKE_CURRENT_BINARY_DIR}/indra.l.cpp
${CMAKE_CURRENT_SOURCE_DIR}/indra.l
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/indra.l
)
if (WINDOWS)
set_source_files_properties(indra.l.cpp
PROPERTIES COMPILE_FLAGS /DYY_NO_UNISTD_H)
endif (WINDOWS)
if (WINDOWS)
get_filename_component(M4_PATH ${M4} PATH)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/indra.y.cpp
${CMAKE_CURRENT_BINARY_DIR}/indra.y.hpp
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bison.bat
ARGS
${BISON} ${M4_PATH}
-p indra_
-d -o ${CMAKE_CURRENT_BINARY_DIR}/indra.y.cpp
${CMAKE_CURRENT_SOURCE_DIR}/indra.y
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/bison.bat
${CMAKE_CURRENT_SOURCE_DIR}/indra.y
)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/windows)
else (WINDOWS)
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/indra.y.cpp
${CMAKE_CURRENT_BINARY_DIR}/indra.y.hpp
COMMAND
${BISON}
ARGS
-p indra_
-d -o ${CMAKE_CURRENT_BINARY_DIR}/indra.y.cpp
${CMAKE_CURRENT_SOURCE_DIR}/indra.y
DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/indra.y
)
endif (WINDOWS)
if (DARWIN)
# Mac OS X 10.4 compatibility
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/indra.y.hpp
COMMAND
mv
${CMAKE_CURRENT_BINARY_DIR}/indra.y.cpp.h
${CMAKE_CURRENT_BINARY_DIR}/indra.y.hpp
)
endif (DARWIN)
add_library (lscript_compile ${lscript_compile_SOURCE_FILES})
@REM Run bison under Windows. This script is needed so that bison can
@REM find m4, even if neither program is present in PATH.
@set bison=%1
shift
set M4PATH=%1
shift
set M4=
set PATH=%M4PATH%;%PATH%
@REM %* does not work with shift...
%bison% %1 %2 %3 %4 %5 %6 %7 %8 %9
This diff is collapsed.
This diff is collapsed.
/**
* @file lscript_alloc.cpp
* @brief Allocation tracking
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
/**
* @file lscript_bytecode.cpp
* @brief classes to build actual bytecode
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#include "linden_common.h"
#include "lscript_bytecode.h"
#include "lscript_error.h"
#if defined(_MSC_VER)
# pragma warning(disable: 4102) // 'yy_more' : unreferenced label
# pragma warning(disable: 4702) // unreachable code
#endif
LLScriptJumpTable::LLScriptJumpTable()
{
}
LLScriptJumpTable::~LLScriptJumpTable()
{
delete_and_clear(mLabelMap);
delete_and_clear(mJumpMap);
}
void LLScriptJumpTable::addLabel(char *name, S32 offset)
{
char *temp = gScopeStringTable->addString(name);
mLabelMap[temp] = new S32(offset);
}
void LLScriptJumpTable::addJump(char *name, S32 offset)
{
char *temp = gScopeStringTable->addString(name);
mJumpMap[temp] = new S32(offset);
}
LLScriptByteCodeChunk::LLScriptByteCodeChunk(BOOL b_need_jumps)
: mCodeChunk(NULL), mCurrentOffset(0), mJumpTable(NULL)
{
if (b_need_jumps)
{
mJumpTable = new LLScriptJumpTable();
}
}
LLScriptByteCodeChunk::~LLScriptByteCodeChunk()
{
delete [] mCodeChunk;
delete mJumpTable;
}
void LLScriptByteCodeChunk::addByte(U8 byte)
{
if (mCodeChunk)
{
U8 *temp = new U8[mCurrentOffset + 1];
memcpy(temp, mCodeChunk, mCurrentOffset); /* Flawfinder: ignore */
delete [] mCodeChunk;
mCodeChunk = temp;
}
else
{
mCodeChunk = new U8[1];
}
*(mCodeChunk + mCurrentOffset++) = byte;
}
void LLScriptByteCodeChunk::addU16(U16 data)
{
U8 temp[2];
S32 offset = 0;
u162bytestream(temp, offset, data);
addBytes(temp, 2);
}
void LLScriptByteCodeChunk::addBytes(const U8 *bytes, S32 size)
{
if (mCodeChunk)
{
U8 *temp = new U8[mCurrentOffset + size];
memcpy(temp, mCodeChunk, mCurrentOffset); /* Flawfinder: ignore */
delete [] mCodeChunk;
mCodeChunk = temp;
}
else
{
mCodeChunk = new U8[size];
}
memcpy(mCodeChunk + mCurrentOffset, bytes, size);/* Flawfinder: ignore */
mCurrentOffset += size;
}
void LLScriptByteCodeChunk::addBytes(const char *bytes, S32 size)
{
if (mCodeChunk)
{
U8 *temp = new U8[mCurrentOffset + size];
memcpy(temp, mCodeChunk, mCurrentOffset); /*Flawfinder: ignore*/
delete [] mCodeChunk;
mCodeChunk = temp;
}
else
{
mCodeChunk = new U8[size];
}
memcpy(mCodeChunk + mCurrentOffset, bytes, size); /*Flawfinder: ignore*/
mCurrentOffset += size;
}
void LLScriptByteCodeChunk::addBytes(S32 size)
{
if (mCodeChunk)
{
U8 *temp = new U8[mCurrentOffset + size];
memcpy(temp, mCodeChunk, mCurrentOffset); /*Flawfinder: ignore*/
delete [] mCodeChunk;
mCodeChunk = temp;
}
else
{
mCodeChunk = new U8[size];
}
memset(mCodeChunk + mCurrentOffset, 0, size);
mCurrentOffset += size;
}
void LLScriptByteCodeChunk::addBytesDontInc(S32 size)
{
if (mCodeChunk)
{
U8 *temp = new U8[mCurrentOffset + size];
memcpy(temp, mCodeChunk, mCurrentOffset); /*Flawfinder: ignore*/
delete [] mCodeChunk;
mCodeChunk = temp;
}
else
{
mCodeChunk = new U8[size];
}
memset(mCodeChunk + mCurrentOffset, 0, size);
}
void LLScriptByteCodeChunk::addInteger(S32 value)
{
U8 temp[4];
S32 offset = 0;
integer2bytestream(temp, offset, value);
addBytes(temp, 4);
}
void LLScriptByteCodeChunk::addFloat(F32 value)
{
U8 temp[4];
S32 offset = 0;
float2bytestream(temp, offset, value);
addBytes(temp, 4);
}
void LLScriptByteCodeChunk::addLabel(char *name)
{
if (mJumpTable)
{
mJumpTable->addLabel(name, mCurrentOffset);
}
}
void LLScriptByteCodeChunk::addJump(char *name)
{
if (mJumpTable)
{
mJumpTable->addJump(name, mCurrentOffset);
}
}
// format is Byte 0: jump op code Byte 1 - 4: offset
// the jump position points to Byte 5, so we need to add the data at
// offset - 4, offset - 3, offset - 2, and offset - 1
// offset is label - jump
void LLScriptByteCodeChunk::connectJumps()
{
if (mJumpTable)
{
for(std::map<char *, S32 *>::iterator it = mJumpTable->mJumpMap.begin(), end_it = mJumpTable->mJumpMap.end();
it != end_it;
++it)
{
S32 jumppos = *it->second;
S32 offset = *mJumpTable->mLabelMap[it->first] - jumppos;
jumppos = jumppos - 4;
integer2bytestream(mCodeChunk, jumppos, offset);
}
}
}
LLScriptScriptCodeChunk::LLScriptScriptCodeChunk(S32 total_size)
: mTotalSize(total_size), mCompleteCode(NULL)
{
mRegisters = new LLScriptByteCodeChunk(FALSE);
mGlobalVariables = new LLScriptByteCodeChunk(FALSE);
mGlobalFunctions = new LLScriptByteCodeChunk(FALSE);
mStates = new LLScriptByteCodeChunk(FALSE);
mHeap = new LLScriptByteCodeChunk(FALSE);
}
LLScriptScriptCodeChunk::~LLScriptScriptCodeChunk()
{
delete mRegisters;
delete mGlobalVariables;
delete mGlobalFunctions;
delete mStates;
delete mHeap;
delete [] mCompleteCode;
}
void LLScriptScriptCodeChunk::build(LLFILE *efp, LLFILE *bcfp)
{
S32 code_data_size = mRegisters->mCurrentOffset +
mGlobalVariables->mCurrentOffset +
mGlobalFunctions->mCurrentOffset +
mStates->mCurrentOffset +
mHeap->mCurrentOffset;
S32 offset = 0;
if (code_data_size < mTotalSize)
{
mCompleteCode = new U8[mTotalSize];
memset(mCompleteCode, 0, mTotalSize);
memcpy(mCompleteCode, mRegisters->mCodeChunk, mRegisters->mCurrentOffset);
offset += mRegisters->mCurrentOffset;
set_register(mCompleteCode, LREG_IP, 0);
set_register(mCompleteCode, LREG_VN, LSL2_VERSION_NUMBER);
set_event_register(mCompleteCode, LREG_IE, 0, LSL2_CURRENT_MAJOR_VERSION);
set_register(mCompleteCode, LREG_BP, mTotalSize - 1);
set_register(mCompleteCode, LREG_SP, mTotalSize - 1);
set_register(mCompleteCode, LREG_GVR, offset);
memcpy(mCompleteCode + offset, mGlobalVariables->mCodeChunk, mGlobalVariables->mCurrentOffset); /*Flawfinder: ignore*/
offset += mGlobalVariables->mCurrentOffset;
set_register(mCompleteCode, LREG_GFR, offset);
memcpy(mCompleteCode + offset, mGlobalFunctions->mCodeChunk, mGlobalFunctions->mCurrentOffset); /*Flawfinder: ignore*/
offset += mGlobalFunctions->mCurrentOffset;
set_register(mCompleteCode, LREG_SR, offset);
// zero is, by definition the default state
set_register(mCompleteCode, LREG_CS, 0);
set_register(mCompleteCode, LREG_NS, 0);
set_event_register(mCompleteCode, LREG_CE, LSCRIPTStateBitField[LSTT_STATE_ENTRY], LSL2_CURRENT_MAJOR_VERSION);
S32 default_state_offset = 0;
if (LSL2_CURRENT_MAJOR_VERSION == LSL2_MAJOR_VERSION_TWO)
{
default_state_offset = 8;
}
else
{
default_state_offset = 4;
}
set_event_register(mCompleteCode, LREG_ER, bytestream2u64(mStates->mCodeChunk, default_state_offset), LSL2_CURRENT_MAJOR_VERSION);
memcpy(mCompleteCode + offset, mStates->mCodeChunk, mStates->mCurrentOffset); /*Flawfinder: ignore*/
offset += mStates->mCurrentOffset;
set_register(mCompleteCode, LREG_HR, offset);
memcpy(mCompleteCode + offset, mHeap->mCodeChunk, mHeap->mCurrentOffset); /*Flawfinder: ignore*/
offset += mHeap->mCurrentOffset;
set_register(mCompleteCode, LREG_HP, offset);
set_register(mCompleteCode, LREG_FR, 0);
set_register(mCompleteCode, LREG_SLR, 0);
set_register(mCompleteCode, LREG_ESR, 0);
set_register(mCompleteCode, LREG_PR, 0);
set_register(mCompleteCode, LREG_TM, mTotalSize);
if (fwrite(mCompleteCode, 1, mTotalSize, bcfp) != (size_t)mTotalSize)
{
LL_WARNS() << "Short write" << LL_ENDL;
}
}
else
{
gErrorToText.writeError(efp, 0, 0, LSERROR_ASSEMBLE_OUT_OF_MEMORY);
}
}
LLScriptScriptCodeChunk *gScriptCodeChunk;
/**
* @file lscript_error.cpp
* @brief error reporting class and strings
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#include "linden_common.h"
#include "lscript_error.h"
S32 gColumn = 0;
S32 gLine = 0;
S32 gInternalColumn = 0;
S32 gInternalLine = 0;
LLScriptGenerateErrorText gErrorToText;
void LLScriptFilePosition::fdotabs(LLFILE *fp, S32 tabs, S32 tabsize)
{
S32 i;
for (i = 0; i < tabs * tabsize; i++)
{
fprintf(fp, " ");
}
}
const char* gWarningText[LSWARN_EOF] = /*Flawfinder: ignore*/
{
"INVALID",
"Dead code found beyond return statement"
};
const char* gErrorText[LSERROR_EOF] = /*Flawfinder: ignore*/
{
"INVALID",
"Syntax error",
"Not all code paths return a value",
"Function returns a value but return statement doesn't",
"Return statement type doesn't match function return type",
"Global functions can't change state",
"Name previously declared within scope",
"Name not defined within scope",
"Type mismatch",
"Expression must act on LValue",
"Byte code assembly failed -- out of memory",
"Function call mismatches type or number of arguments",
"Use of vector or quaternion method on incorrect type",
"Lists can't be included in lists",
"Unitialized variables can't be included in lists",
"Declaration requires a new scope -- use { and }",
"CIL assembler failed",
"Bytecode transformer failed",
"Bytecode verification failed"
};
void LLScriptGenerateErrorText::writeWarning(LLFILE *fp, LLScriptFilePosition *pos, LSCRIPTWarnings warning)
{
fprintf(fp, "(%d, %d) : WARNING : %s\n", pos->mLineNumber, pos->mColumnNumber, gWarningText[warning]);
mTotalWarnings++;
}
void LLScriptGenerateErrorText::writeWarning(LLFILE *fp, S32 line, S32 col, LSCRIPTWarnings warning)
{
fprintf(fp, "(%d, %d) : WARNING : %s\n", line, col, gWarningText[warning]);
mTotalWarnings++;
}
void LLScriptGenerateErrorText::writeError(LLFILE *fp, LLScriptFilePosition *pos, LSCRIPTErrors error)
{
fprintf(fp, "(%d, %d) : ERROR : %s\n", pos->mLineNumber, pos->mColumnNumber, gErrorText[error]);
mTotalErrors++;
}
void LLScriptGenerateErrorText::writeError(LLFILE *fp, S32 line, S32 col, LSCRIPTErrors error)
{
fprintf(fp, "(%d, %d) : ERROR : %s\n", line, col, gErrorText[error]);
mTotalErrors++;
}
std::string getLScriptErrorString(LSCRIPTErrors error)
{
return gErrorText[error];
}
/**
* @file lscript_error.h
* @brief error reporting class and strings
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#ifndef LL_LSCRIPT_ERROR_H
#define LL_LSCRIPT_ERROR_H
#include "lscript_scope.h"
typedef enum e_lscript_compile_pass
{
LSCP_INVALID,
LSCP_PRETTY_PRINT,
LSCP_PRUNE,
LSCP_SCOPE_PASS1,
LSCP_SCOPE_PASS2,
LSCP_TYPE,
LSCP_RESOURCE,
LSCP_EMIT_ASSEMBLY,
LSCP_EMIT_BYTE_CODE,
LSCP_DETERMINE_HANDLERS,
LSCP_LIST_BUILD_SIMPLE,
LSCP_TO_STACK,
LSCP_BUILD_FUNCTION_ARGS,
LSCP_EMIT_CIL_ASSEMBLY,
LSCP_EOF
} LSCRIPTCompilePass;
typedef enum e_lscript_prune_type
{
LSPRUNE_INVALID,
LSPRUNE_GLOBAL_VOIDS,
LSPRUNE_GLOBAL_NON_VOIDS,
LSPRUNE_EVENTS,
LSPRUNE_DEAD_CODE,
LSPRUNE_EOF
} LSCRIPTPruneType;
extern S32 gColumn;
extern S32 gLine;
extern S32 gInternalColumn;
extern S32 gInternalLine;
// used to describe where in the file this piece is
class LLScriptByteCodeChunk;
class LLScriptLibData;
class LLScriptFilePosition
{
public:
LLScriptFilePosition(S32 line, S32 col)
: mLineNumber(line), mColumnNumber(col), mByteOffset(0), mByteSize(0)
{
}
virtual ~LLScriptFilePosition() {}
virtual void recurse(LLFILE *fp, S32 tabs, S32 tabsize,
LSCRIPTCompilePass pass, LSCRIPTPruneType ptype, BOOL &prunearg,
LLScriptScope *scope, LSCRIPTType &type, LSCRIPTType basetype, U64 &count,
LLScriptByteCodeChunk *chunk, LLScriptByteCodeChunk *heap, S32 stacksize, LLScriptScopeEntry *entry, S32 entrycount, LLScriptLibData **ldata) = 0;
virtual S32 getSize() = 0;
void fdotabs(LLFILE *fp, S32 tabs, S32 tabsize);
S32 mLineNumber;
S32 mColumnNumber;
S32 mByteOffset;
S32 mByteSize;
};
typedef enum e_lscript_warnings
{
LSWARN_INVALID,
LSWARN_DEAD_CODE,
LSWARN_EOF
} LSCRIPTWarnings;
typedef enum e_lscript_errors
{
LSERROR_INVALID,
LSERROR_SYNTAX_ERROR,
LSERROR_NO_RETURN,
LSERROR_INVALID_VOID_RETURN,
LSERROR_INVALID_RETURN,
LSERROR_STATE_CHANGE_IN_GLOBAL,
LSERROR_DUPLICATE_NAME,
LSERROR_UNDEFINED_NAME,
LSERROR_TYPE_MISMATCH,
LSERROR_EXPRESSION_ON_LVALUE,
LSERROR_ASSEMBLE_OUT_OF_MEMORY,
LSERROR_FUNCTION_TYPE_ERROR,
LSERROR_VECTOR_METHOD_ERROR,
LSERROR_NO_LISTS_IN_LISTS,
LSERROR_NO_UNITIALIZED_VARIABLES_IN_LISTS,
LSERROR_NEED_NEW_SCOPE,
LSERROR_CIL_ASSEMBLER_FAILED = 16, // Mono build error.
LSERROR_BYTECODE_TRANSFORM_FAILED = 17, // Mono build error.
LSERROR_BYTECODE_VERIFICATION_FAILED, // Mono build error.
LSERROR_EOF
} LSCRIPTErrors;
class LLScriptGenerateErrorText
{
public:
LLScriptGenerateErrorText() { init(); }
~LLScriptGenerateErrorText() {}
void init() { mTotalErrors = 0; mTotalWarnings = 0; }
void writeWarning(LLFILE *fp, LLScriptFilePosition *pos, LSCRIPTWarnings warning);
void writeWarning(LLFILE *fp, S32 line, S32 col, LSCRIPTWarnings warning);
void writeError(LLFILE *fp, LLScriptFilePosition *pos, LSCRIPTErrors error);
void writeError(LLFILE *fp, S32 line, S32 col, LSCRIPTErrors error);
BOOL getErrors() { return mTotalErrors; }
BOOL getWarnings() { return mTotalWarnings; }
S32 mTotalErrors;
S32 mTotalWarnings;
};
std::string getLScriptErrorString(LSCRIPTErrors error);
extern LLScriptGenerateErrorText gErrorToText;
#endif
/**
* @file lscript_heap.cpp
* @brief classes to manage script heap
*
* $LicenseInfo:firstyear=2002&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2010, Linden Research, Inc.
*
* 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.
*
* 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.
*
* 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$
*/
#if 0
#include "linden_common.h"
#include "lscript_heap.h"
LLScriptHeapEntry::LLScriptHeapEntry(U8 *entry)
: mEntry(entry)
{
S32 offset = 0;
mNext = bytestream2integer(entry, offset);
mRefCount = bytestream2integer(entry, offset);
mType = *(entry + offset);
mData = entry + offset;
mListOffset = offset;
}
LLScriptHeapEntry::LLScriptHeapEntry(U8 *heap, S32 offset)
: mNext(0x9), mType(0), mRefCount(0), mEntry(heap + offset), mData(heap + offset + 0x9), mListOffset(0x9)
{
}
LLScriptHeapEntry::~LLScriptHeapEntry()
{
}
void LLScriptHeapEntry::addString(char *string)
{
S32 size = strlen(string) + 1; /*Flawfinder: ignore*/
S32 offset = 0;
memcpy(mData, string, size); /*Flawfinder: ignore*/
mNext += size;
integer2bytestream(mEntry, offset, mNext);
mRefCount++;
integer2bytestream(mEntry, offset, mRefCount);
*(mEntry + offset) = LSCRIPTTypeByte[LST_STRING];
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment