LSO

From Second Life Wiki
Jump to navigation Jump to search

The compiled form of LSL scripts - a mostly stack-based language with a reference-counted heap and a very odd function calling convention in which the caller allocates storage for the callee's local variables. All the gory details can be found at http://www.libsecondlife.org/wiki/LSO, including some opcodes that are implemented in the interpreter but never outputted by the compiler (such as the handy DUP family of instructions for Forth-style programming, and PUSHIP/POPIP for implementing custom function calls/function pointers, jumptable-based switch statements and the like).

It's actually a reasonably powerful instruction set in some ways, but the compiler doesn't make use of it very well. Of course, with the planned switch to Mono, it's probably really not sensible to do anything with it. Besides, rumor has it that script compilation will move server-side in the near future.

Bytecodes

Argument Types Variable type codes
Type Size
dword 4
short 2
byte 1
type 1 upper 4 bits are type.Left
lower 4 bits are type.Right
Value Type Size
0 void ?
1 integer 4
2 float 4
3 string 4
Value Type Size
4 key 4
5 vector 12
6 rotation 16
7 list 4

By Task

Value Pop

These bytecodes remove values from the stack.

|- | POP | 0x01 | Pops a dword from the stack. | |- | POPS | 0x02 | Pops a dword from the stack and deallocates it from the heap as a string | |- | POPL | 0x03 | Pops a dword from the stack and deallocates it from the heap as a list | |- | POPV | 0x04 | Pops 3 dwords from the stack. | |- | POPQ | 0x05 | Pops 4 dwords from the stack. | |- | POPARG | 0x06 | Pops arg0 bytes from the stack. | dword


Operators

Name Value Description arg0 size
CAST 0xA0 Pop type.Left, convert Left to type.Right and push the result onto the stack. type
NEG 0x80 Pop type.Right, push result of (-Right) onto the stack. type
ADD 0x70 Pop type.Right then type.Left, push result of (Left + Right) onto the stack. type
SUB 0x71 Pop type.Right then type.Left, push result of (Left - Right) onto the stack. type
MUL 0x72 Pop type.Right then type.Left, push result of (Left * Right) onto the stack. type
DIV 0x73 Pop type.Right then type.Left, push result of (Left / Right) onto the stack. type
MOD 0x74 Pop type.Right then type.Left, push result of (Left % Right) onto the stack. type
EQ 0x75 Pop type.Right then type.Left, push result of (Left == Right) onto the stack. type
NEQ 0x76 Pop type.Right then type.Left, push result of (Left != Right) onto the stack. type
LEQ 0x77 Pop type.Right then type.Left, push result of (Left <= Right) onto the stack. type
GEQ 0x78 Pop type.Right then type.Left, push result of (Left >= Right) onto the stack. type
LESS 0x79 Pop type.Right then type.Left, push result of (Left < Right) onto the stack. type
GREATER 0x7A Pop type.Right then type.Left, push result of (Left > Right) onto the stack. type
BITAND 0x7B Pop dword (Right) then dword (Left), push result of (Left & Right) onto the stack.
BITOR 0x7C Pop dword (Right) then dword (Left), push result of (Left | Right) onto the stack.
BITXOR 0x7D Pop dword (Right) then dword (Left), push result of (Left ^ Right) onto the stack.
BOOLAND 0x7E Pop dword (Right) then dword (Left), push result of (Left && Right) onto the stack.
BOOLOR 0x7F Pop dword (Right) then dword (Left), push result of (Left || Right) onto the stack.
BITNOT 0x81 Pop dword (Right), push result of (~Right) onto the stack.
BOOLNOT 0x82 Pop dword (Right), push result of (!Right) onto the stack.
SHL 0xE0 Pop dword (Right) then dword (Left), push result of (Left << Right) onto the stack.
SHR 0xE1 Pop dword (Right) then dword (Left), push result of (Left >> Right) onto the stack.

Jumps

Name Value Description arg0 size arg1 size
JUMP 0x90 Jump to offset arg0 local to this instruction. arg0 is signed. dword
JUMPIF 0x91 Pop type.Right, if Right is executes to true jump to offset arg1 local to this instruction. arg1 is signed. type dword
JUMPNIF 0x92 Pop type.Right, if Right is executes to false jump to offset arg1 local to this instruction. arg1 is signed. type dword

Duplicate Value

Name Value Description arg0 size
DUP 0x20 Copy dword from stack and push the copy onto the stack.
DUPS 0x21 Copy string from stack and push the copy onto the stack.
DUPL 0x22 Copy list from stack and push the copy onto the stack.
DUPV 0x23 Copy 3 dwrods from stack and push the copy onto the stack.
DUPQ 0x24 Copy 4 dwrods from stack and push the copy onto the stack.

Return

Name Value Description arg0 size
STATE 0x93 Change state to arg0 and return (see RETURN) dword
RETURN 0x95 Revert the Instruction and Stack pointers.

Functions

Name Value Description arg0 size
CALL 0x94 Execute user function arg0. dword
CALLLIB 0xD0 Execute built-in function arg0 byte
CALLLIB_TWO_BYTE 0xD1 Execute built-in function arg0 word