# Difference between revisions of "LS2IL:Instruction Reference"

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

(→Exception handling) |
(→Math) |
||

Line 23: | Line 23: | ||

== Math == | == Math == | ||

− | ; where a is always a register #, and | + | ; where a is always a register #, b and c are values, and the result goes into register #a |

− | * ADD a,b - a | + | * ADD a,b,c - a = b + c |

− | * SUB a,b - a | + | * SUB a,b,c - a = b - c |

− | * MUL a,b - a | + | * MUL a,b,c - a = b * c |

− | * DIV a,b - a | + | * DIV a,b,c - a = b / c |

− | * MOD a,b - a | + | * MOD a,b,c - a = b % c |

− | * POW a,b - a = | + | * POW a,b,c - a = b to the power of c |

− | * NEGATE a - a = - | + | * NEGATE a,b - a = -b (sign flip) |

=== Logical operations === | === Logical operations === | ||

− | ; where a is always a register #, and | + | ; where a is always a register #, b and c are values, and the result goes into register #a |

− | * LAND a,b - a == | + | * LAND a,b,c - a == b && c |

− | * LOR a,b - a == | + | * LOR a,b,c - a == b || c |

− | * LNOT a - a = ! | + | * LNOT a,b - a = !b |

− | * LEQUAL a,b - a = ( | + | * LEQUAL a,b,c - a = (b==c) |

− | * LNOTEQUAL a,b - a = ( | + | * LNOTEQUAL a,b,c - a = (b!=c) |

− | * LLESS a,b - a = ( | + | * LLESS a,b,c - a = (b<c) |

− | * LLESSEQUAL a,b - a = ( | + | * LLESSEQUAL a,b,c - a = (b<=c) |

− | * LGREATER a,b - a = ( | + | * LGREATER a,b,c - a = (b>c) |

− | * LGREATEREQUAL a,b - a = ( | + | * LGREATEREQUAL a,b,c - a = (b>=c) |

=== Bitwise operations === | === Bitwise operations === | ||

− | ; where a is always a register #, and | + | ; where a is always a register #, b and c are values, and the result goes into register #a |

− | * SHL a,b - a = | + | * SHL a,b,c - a = b << c |

− | * SHR a,b - a = | + | * SHR a,b,c - a = b >> c |

− | * AND a,b - a | + | * AND a,b,c - a = b & c |

− | * OR a,b - a | + | * OR a,b,c - a = b | c |

− | * NOT a - a = ~ | + | * NOT a,b - a = ~b |

− | * XOR a,b - a | + | * XOR a,b,c - a = b ^ c |

== Tables == | == Tables == |

## Revision as of 14:10, 4 October 2012

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
- 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

## Math

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

- ADD a,b,c - a = b + c
- 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 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 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)
- 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

## Object consumers

- 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 property b, into register #a
- SETSTATICPROPERTY a,b - set value of property a 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)

## 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.