# LS2IL:Instruction Reference

From ismods.com: dedicated to promoting white hat, EULA-compliant Inner Space and LavishScript mods

LS2IL instructions have the opcode and up to 3 Operands.

## Contents

## Miscellaneous

- NOP - do nothing
- NULLIFY a,b - sets registers #a through #b to Null
- DUPLICATE a,b - duplicates b into register #a (generates a new object)
- REFERENCE a,b - re-references b into register #a.
- LEN a,b - retrieves the length of b into register #a (supported by string, table, array, binary to indicate number of elements)

## Boxing and Unboxing

- REREFERENCE a,b - boxes b into a Reference object in register #a, or into an existing Reference object a (value a may also be a Reference object, in which case the existing Reference object will now reference b)
- DEREFERENCE a,b - unboxes value in the Reference object b into register #a

## Some conversions

- TYPEOF a,b - retrieves the Type object describing b, into register #a
- BOOLVAL a,b - retrieves a Boolean value interpretation of b, into register #a
- INTVAL a,b - retrieves an Integer value interpretation of b, into register #a
- FLOATVAL a,b - retrieves a Float value interpretation of b, into register #a
- STRINGVAL a,b - retrieves a String value interpretation of b, into register #a
- BINARYVAL a,b - retrieves a Binary value interpretation of b, into register #a
- IS a,b,c - determines if object b can be described by type c, placing the boolean result into register #a
- AS a,b,c - if object b can be described by type c, places the object into register #a. if not, register #a will be null.

## Math

- where a is always a register #, b and c are values, and the result object (depending on value b) goes into register #a

- ADD a,b,c - a = b + c
- Note: In addition to Integer and Decimal types, the ADD instruction is also implemented by Array and String types

- SUB a,b,c - a = b - c
- MUL a,b,c - a = b * c
- DIV a,b,c - a = b / c
- MOD a,b,c - a = b % c
- POW a,b,c - a = b to the power of c
- NEGATE a,b - a = -b (sign flip)

### Logical operations

- where a is always a register #, b and c are values, and the result (1 or 0) goes into register #a

- LAND a,b,c - a == b && c
- LOR a,b,c - a == b || c
- LNOT a,b - a = !b
- LEQUAL a,b,c - a = (b==c)
- LNOTEQUAL a,b,c - a = (b!=c)
- LLESS a,b,c - a = (b<c)
- LLESSEQUAL a,b,c - a = (b<=c)
- LGREATER a,b,c - a = (b>c)
- LGREATEREQUAL a,b,c - a = (b>=c)

### Bitwise operations

- where a is always a register #, b and c are values, and the result integer goes into register #a

- SHL a,b,c - a = b << c
- SHR a,b,c - a = b >> c
- AND a,b,c - a = b & c
- OR a,b,c - a = b | c
- NOT a,b - a = ~b
- XOR a,b,c - a = b ^ c

## Tables

- NEWTABLE a - generates an empty table into register #a (note that you can also generate a non-empty table as part of a value or operand)
- TABLESET a,b,c - a[b]=c sets value c into table a, at string key b
- TABLEGET a,b,c - retrieves value from table b, at string key c, into register #a

## Arrays

- NEWARRAY a,b - generates an array of size b into register #a (note that you can also generate an array as part of a value or operand)
- NEWARRAY a,b,c - generates an array of size b into register #a, with using type c to initialize the default<t> elements
- ARRAYSET a,b,c - a[b]=c sets value c into array a, at integer key b
- ARRAYGET a,b,c - retrieves value from array b, at integer key c, into register #a
- ARRAYRESIZE a,b - resizes array a to size b
- ARRAYCONCAT a,b - appends the elements from array b to the end of array a

## Object resolvers

- RESOLVETYPE a,b - resolves Type by name b into register #a
- RESOLVEMETHOD a,b,c - resolves method of type b, by name c, into register #a
- RESOLVESTATICMETHOD a,b,c - resolves static method of type b, by name c, into register #a
- RESOLVEPROPERTY a,b,c - resolves property of type b, by name c, into register #a
- RESOLVESTATICPROPERTY a,b,c - resolves static property of type b, by name c, into register #a
- RESOLVEFIELD a,b,c - resolves field of type b, by runtime field index #c, into register #a
- RESOLVESTATICFIELD a,b,c - resolves static field of type b, by name c, into register #a

## Object consumers

- NEWOBJECT a,b,c - uses constructor method b to construct an object (determining the object's type from method b's metadata), with inputs in array c, into register #a
- CALLMETHOD a,b,c - calls method a, on object b, with inputs in array c
- CALLSTATICMETHOD a,b - calls static method a, with inputs in array b
- FASTCALLMETHOD a,b - calls method a, on object b
- FASTCALLMETHOD a,b,c - calls method a, on object b, with single input c
- FASTCALLSTATICMETHOD a - calls static method a
- FASTCALLSTATICMETHOD a,b - calls static method a, with single input b
- FASTCALLSTATICMETHOD a,b,c - calls static method a, with inputs b and c
- GETPROPERTY a,b,c - retrieves value of property b, from object c, into register #a
- SETPROPERTY a,b,c - sets value of property a, from object b, to c
- GETSTATICPROPERTY a,b - retrieves value of static property b, into register #a
- SETSTATICPROPERTY a,b - set value of static property a to b
- GETFIELD a,b,c - retrieves value of field b, from object c, into register #a
- SETFIELD a,b,c - set value of field a, from object b, to c
- GETSTATICFIELD a,b - retrieves value of static field b, into register #a
- SETSTATICFIELD a,b - sets the value of static field to b

## Jumps

- JMP a - jump ahead #a instructions
- JE a,b,c - jump ahead #a instructions, if b==c
- JNE a,b,c - jump ahead #a instructions, if b!=c
- JGE a,b,c - jump ahead #a instructions, if b>=c
- JG a,b,c - jump ahead #a instructions, if b>c
- JL a,b,c - jump ahead #a instructions, if b<c
- JLE a,b,c - jump ahead #a instructions, if b<=c
- JZ a,b - jump ahead #a instructions, if b as a boolean value is false (zero)
- JNZ a,b - jump ahead #a instructions, if b as a boolean value is true (non-zero)
- SWITCH a,b - with an Array or Table "a", looks up an instruction number with integer or string key b. jumps if found.

## Function calls

- RETURN - end execution of the current function, returning to the caller
- CALL a,b - call function a, with inputs in array b
- FASTCALL a - call function a
- FASTCALL a,b - call function a with one input b
- FASTCALL a,b,c - call function a with two inputs b and c

## Yielding and scheduling control

- YIELD - yields execution to the host environment. invalid during atomic state
- ATOMIZE - enables atomic behavior for the current function (and anything it calls)
- DEATOMIZE - disables atomic behavior that was enabled in the current function by ATOMIZE

## Exception handling

- THROW a - throws an object as an exception
- UNTHROW - unthrows the currently stored exception, releasing its reference and resetting the "exception" operand..
- TRY a - sets an exception handler at instruction #a in the current function
- TRY a b - sets an exception handler at instruction #a in the current function, with 'finally' at instruction #b
- LEAVE - leaves a protected TRY region. if a FINALLY was declared by TRY, saves the instruction and jumps to FINALLY
- ENDFINALLY - leaves a FINALLY region. if processed due to LEAVE, jumps back to the saved instruction. if processed due to THROW, rethrows the exception.